Bug 1148220 - Marionette's in_app restart has to send 'quit-application-requested' observer notification. draft
authorHenrik Skupin <mail@hskupin.info>
Mon, 26 Sep 2016 15:25:05 +0200
changeset 417585 92061e433e073a92120c3624b2a506357ca99cc3
parent 417383 29beaebdfaccbdaeb4c1ee5a43a9795ab015ef49
child 532124 b7bec7a953dd21133df0d34710d10b46481a7229
push id30438
push userbmo:hskupin@gmail.com
push dateMon, 26 Sep 2016 13:25:44 +0000
bugs1148220
milestone52.0a1
Bug 1148220 - Marionette's in_app restart has to send 'quit-application-requested' observer notification. MozReview-Commit-ID: 3IAtFFeyJWa
testing/marionette/client/marionette_driver/marionette.py
testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -1032,21 +1032,34 @@ class Marionette(object):
 
     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(["eForceQuit"])
+        flags = set([])
         if shutdown_flags:
             flags.add(shutdown_flags)
+
+        # Trigger a 'quit-application-requested' observer notification so that
+        # components can safely shutdown before quitting the application.
+        with self.using_context("chrome"):
+            canceled = self.execute_script("""
+                Components.utils.import("resource://gre/modules/Services.jsm");
+                let cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"].
+                                 createInstance(Components.interfaces.nsISupportsPRBool);
+                Services.obs.notifyObservers(cancelQuit, "quit-application-requested", null);
+                return cancelQuit.data;
+                """)
+            if canceled:
+                raise errors.MarionetteException("Something canceled the quit application request")
+
         self._send_message("quitApplication", {"flags": list(flags)})
-
         self.delete_session(in_app=True)
 
     @do_process_check
     def quit(self, in_app=False, callback=None):
         """Terminate the currently running instance.
 
         This command will delete the active marionette session. It also allows
         manipulation of eg. the profile data while the application is not running.
--- a/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
@@ -66,26 +66,16 @@ class BaseFirefoxTestCase(unittest.TestC
             self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]])
             self.browser.tabbar.tabs[0].switch_to()
 
     def restart(self, **kwargs):
         """Restart Firefox and re-initialize data.
 
         :param flags: Specific restart flags for Firefox
         """
-
-        # TODO: Bug 1148220 Marionette's in_app restart has to send 'quit-application-requested'
-        # observer notification before an in_app restart
-        with self.marionette.using_context('chrome'):
-            self.marionette.execute_script("""
-                Components.utils.import("resource://gre/modules/Services.jsm");
-                let cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
-                                         .createInstance(Components.interfaces.nsISupportsPRBool);
-                Services.obs.notifyObservers(cancelQuit, "quit-application-requested", null);
-                """)
         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')