Merge m-c to autoland
authorPhil Ringnalda <philringnalda@gmail.com>
Thu, 29 Sep 2016 07:39:46 -0700
changeset 315769 d19b41ff1f18b530145742b0d11abbd482082f86
parent 315768 9c1d4bb7c4ee3b75b5a2c08f5bd1a213320ff335 (current diff)
parent 315731 9baec74b3db1bf005c66ae2f50bafbdb02c3be38 (diff)
child 315770 67cd8ab2f98e0521741df7eda542d0f677b99ed5
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone52.0a1
Merge m-c to autoland
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -994,51 +994,47 @@ class Marionette(object):
         instance with the requested preferences.
 
         : param prefs: A dictionary whose keys are preference names.
         """
         if not self.instance:
             raise errors.MarionetteException("enforce_gecko_prefs() can only be called "
                                              "on Gecko instances launched by Marionette")
         pref_exists = True
-        with self.using_context(self.CONTEXT_CHROME):
-            for pref, value in prefs.iteritems():
-                if type(value) is not str:
-                    value = json.dumps(value)
-                pref_exists = self.execute_script("""
-                let prefInterface = Components.classes["@mozilla.org/preferences-service;1"]
-                                              .getService(Components.interfaces.nsIPrefBranch);
-                let pref = '%s';
-                let value = '%s';
-                let type = prefInterface.getPrefType(pref);
-                switch(type) {
-                    case prefInterface.PREF_STRING:
-                        return value == prefInterface.getCharPref(pref).toString();
-                    case prefInterface.PREF_BOOL:
-                        return value == prefInterface.getBoolPref(pref).toString();
-                    case prefInterface.PREF_INT:
-                        return value == prefInterface.getIntPref(pref).toString();
-                    case prefInterface.PREF_INVALID:
-                        return false;
-                }
-                """ % (pref, value))
-                if not pref_exists:
-                    break
-
+        self.set_context(self.CONTEXT_CHROME)
+        for pref, value in prefs.iteritems():
+            if type(value) is not str:
+                value = json.dumps(value)
+            pref_exists = self.execute_script("""
+            let prefInterface = Components.classes["@mozilla.org/preferences-service;1"]
+                                          .getService(Components.interfaces.nsIPrefBranch);
+            let pref = '%s';
+            let value = '%s';
+            let type = prefInterface.getPrefType(pref);
+            switch(type) {
+                case prefInterface.PREF_STRING:
+                    return value == prefInterface.getCharPref(pref).toString();
+                case prefInterface.PREF_BOOL:
+                    return value == prefInterface.getBoolPref(pref).toString();
+                case prefInterface.PREF_INT:
+                    return value == prefInterface.getIntPref(pref).toString();
+                case prefInterface.PREF_INVALID:
+                    return false;
+            }
+            """ % (pref, value))
+            if not pref_exists:
+                break
+        self.set_context(self.CONTEXT_CONTENT)
         if not pref_exists:
-            context = self._send_message("getContext", key="value")
             self.delete_session()
             self.instance.restart(prefs)
             self.raise_for_port(self.wait_for_port())
             self.start_session()
             self.reset_timeouts()
 
-            # Restore the context as used before the restart
-            self.set_context(context)
-
     def _request_in_app_shutdown(self, shutdown_flags=None):
         """Terminate the currently running instance from inside the application.
 
         :param shutdown_flags: If specified use additional flags for the shutdown
                                of the application. Possible values here correspond
                                to constants in nsIAppStartup: http://mzl.la/1X0JZsC.
         """
         flags = set([])
@@ -1106,18 +1102,16 @@ class Marionette(object):
                        browser. Otherwise the browser will be restarted immediately
                        by killing the process.
         :param callback: If provided and `in_app` is True, the callback will be
                          used to trigger the restart.
         """
         if not self.instance:
             raise errors.MarionetteException("restart() can only be called "
                                              "on Gecko instances launched by Marionette")
-
-        context = self._send_message("getContext", key="value")
         session_id = self.session_id
 
         if in_app:
             if clean:
                 raise ValueError("An in_app restart cannot be triggered with the clean flag set")
 
             if callable(callback):
                 callback()
@@ -1135,19 +1129,16 @@ class Marionette(object):
         else:
             self.delete_session()
             self.instance.restart(clean=clean)
             self.raise_for_port(self.wait_for_port())
 
         self.start_session(session_id=session_id)
         self.reset_timeouts()
 
-        # Restore the context as used before the restart
-        self.set_context(context)
-
         if in_app and self.session.get("processId"):
             # In some cases Firefox restarts itself by spawning into a new process group.
             # As long as mozprocess cannot track that behavior (bug 1284864) we assist by
             # informing about the new process id.
             self.instance.runner.process_handler.check_for_detached(self.session["processId"])
 
     def absolute_url(self, relative_url):
         '''
--- a/testing/marionette/harness/marionette/tests/unit/test_profile_management.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_profile_management.py
@@ -20,15 +20,17 @@ class TestProfileManagement(MarionetteTe
         self.assertTrue(self.marionette.get_pref("marionette.test.bool"))
         self.assertEqual(self.marionette.get_pref("marionette.test.string"), "testing")
         self.assertEqual(self.marionette.get_pref("marionette.test.int"), 3)
 
     def test_change_preference(self):
         self.assertTrue(self.marionette.get_pref("marionette.test.bool"))
 
         self.marionette.enforce_gecko_prefs({"marionette.test.bool": False})
+        self.marionette.set_context('chrome')
 
         self.assertFalse(self.marionette.get_pref("marionette.test.bool"))
 
     def test_clean_profile(self):
         self.marionette.restart(clean=True)
+        self.marionette.set_context('chrome')
 
         self.assertEqual(self.marionette.get_pref("marionette.test.bool"), None)
--- a/testing/marionette/harness/marionette/tests/unit/test_quit_restart.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_quit_restart.py
@@ -96,56 +96,8 @@ class TestQuitRestart(MarionetteTestCase
                              callback=self.marionette._request_in_app_shutdown)
         self.assertEqual(self.marionette.session, None)
         with self.assertRaisesRegexp(MarionetteException, "Please start a session"):
             self.marionette.get_url()
 
         self.marionette.start_session()
         self.assertNotEqual(self.marionette.session_id, self.session_id)
         self.assertNotEqual(self.marionette.get_pref("browser.startup.page"), 3)
-
-    def test_reset_context_after_quit_by_set_context(self):
-        # Check that we are in content context which is used by default in Marionette
-        self.assertNotIn('chrome://', self.marionette.get_url(),
-                         "Context doesn't default to content")
-
-        self.marionette.set_context('chrome')
-        self.marionette.quit()
-        self.assertEqual(self.marionette.session, None)
-        self.marionette.start_session()
-        self.assertNotIn('chrome://', self.marionette.get_url(),
-                         "Not in content context after quit with using_context")
-
-    def test_reset_context_after_quit_by_using_context(self):
-        # Check that we are in content context which is used by default in Marionette
-        self.assertNotIn('chrome://', self.marionette.get_url(),
-                         "Context doesn't default to content")
-
-        with self.marionette.using_context('chrome'):
-            self.marionette.quit()
-            self.assertEqual(self.marionette.session, None)
-            self.marionette.start_session()
-            self.assertNotIn('chrome://', self.marionette.get_url(),
-                             "Not in content context after quit with using_context")
-
-    def test_keep_context_after_restart_by_set_context(self):
-        # Check that we are in content context which is used by default in Marionette
-        self.assertNotIn('chrome://', self.marionette.get_url(),
-                         "Context doesn't default to content")
-
-        # restart while we are in chrome context
-        self.marionette.set_context('chrome')
-        self.marionette.restart()
-        self.assertNotEqual(self.marionette.session["processId"], self.pid)
-        self.assertIn('chrome://', self.marionette.get_url(),
-                      "Not in chrome context after a restart with set_context")
-
-    def test_keep_context_after_restart_by_using_context(self):
-        # Check that we are in content context which is used by default in Marionette
-        self.assertNotIn('chrome://', self.marionette.get_url(),
-                         "Context doesn't default to content")
-
-        # restart while we are in chrome context
-        with self.marionette.using_context('chrome'):
-            self.marionette.restart()
-            self.assertNotEqual(self.marionette.session["processId"], self.pid)
-            self.assertIn('chrome://', self.marionette.get_url(),
-                          "Not in chrome context after a restart with using_context")
--- a/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
@@ -71,16 +71,19 @@ class BaseFirefoxTestCase(unittest.TestC
 
         :param flags: Specific restart flags for Firefox
         """
         if kwargs.get('clean'):
             self.marionette.restart(clean=True)
         else:
             self.marionette.restart(in_app=True)
 
+        # Marionette doesn't keep the former context, so restore to chrome
+        self.marionette.set_context('chrome')
+
         # Ensure that we always have a valid browser instance available
         self.browser = self.windows.switch_to(lambda win: type(win) is BrowserWindow)
 
     def setUp(self, *args, **kwargs):
         super(BaseFirefoxTestCase, self).setUp(*args, **kwargs)
 
         self._start_handle_count = len(self.marionette.window_handles)
         self._init_tab_handles = self.marionette.window_handles