Bug 1148220 - Marionette's in_app restart has to send 'quit-application-requested' observer notification.
MozReview-Commit-ID: 3IAtFFeyJWa
--- 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')