Bug 1254136 - Fix double registration for sessionstore-windows-restored. r=automatedtester

A missing break statement caused a double execution of the code in
"profile-after-change", which leads to two instantiations of the
Marionette server colliding due to the same port.

MozReview-Commit-ID: Dp6fncj463j

--HG--
extra : rebase_source : dd4301c2fb797da228c0011e6bd90afa9171fb54
This commit is contained in:
Henrik Skupin 2017-08-10 18:04:47 +02:00
parent f5ae03f271
commit f901b6658a
2 changed files with 52 additions and 19 deletions

View File

@ -195,30 +195,27 @@ MarionetteComponent.prototype.observe = function(subject, topic, data) {
this.logger.debug(`Received observer notification "${topic}"`);
switch (topic) {
case "profile-after-change":
Services.obs.addObserver(this, "command-line-startup");
Services.obs.addObserver(this, "sessionstore-windows-restored");
prefs.readFromEnvironment(ENV_PRESERVE_PREFS);
break;
// In safe mode the command line handlers are getting parsed after the
// safe mode dialog has been closed. To allow Marionette to start
// earlier, use the CLI startup observer notification for
// special-cased handlers, which gets fired before the dialog appears.
case "command-line-startup":
Services.obs.removeObserver(this, topic);
this.handle(subject);
case "profile-after-change":
// Using sessionstore-windows-restored as the xpcom category doesn't
// seem to work, so we wait for that by adding an observer here.
Services.obs.addObserver(this, "sessionstore-windows-restored");
// In safe mode the command line handlers are getting parsed after the
// safe mode dialog has been closed. To allow Marionette to start
// earlier, register the CLI startup observer notification for
// special-cased handlers, which gets fired before the dialog appears.
Services.obs.addObserver(this, "command-line-startup");
prefs.readFromEnvironment(ENV_PRESERVE_PREFS);
if (this.enabled) {
// We want to suppress the modal dialog that's shown
// when starting up in safe-mode to enable testing.
if (Services.appinfo.inSafeMode) {
Services.obs.addObserver(this, "domwindowopened");
}
// We want to suppress the modal dialog that's shown
// when starting up in safe-mode to enable testing.
if (this.enabled && Services.appinfo.inSafeMode) {
Services.obs.addObserver(this, "domwindowopened");
}
break;
case "domwindowclosed":

View File

@ -2,6 +2,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import unittest
from marionette_driver import errors
from marionette_harness import MarionetteTestCase, skip
@ -88,6 +90,14 @@ class TestQuitRestart(MarionetteTestCase):
MarionetteTestCase.tearDown(self)
@property
def is_safe_mode(self):
with self.marionette.using_context("chrome"):
return self.marionette.execute_script("""
Cu.import("resource://gre/modules/Services.jsm");
return Services.appinfo.inSafeMode;
""")
def shutdown(self, restart=False):
self.marionette.set_context("chrome")
self.marionette.execute_script("""
@ -187,6 +197,32 @@ class TestQuitRestart(MarionetteTestCase):
self.assertNotEqual(self.marionette.get_pref("startup.homepage_welcome_url"),
"about:")
def test_in_app_restart_safe_mode(self):
if self.marionette.session_capabilities["moz:headless"]:
raise unittest.SkipTest("Bug 1390848 - Hang of Marionette client after the restart.")
def restart_in_safe_mode():
with self.marionette.using_context("chrome"):
self.marionette.execute_script("""
Components.utils.import("resource://gre/modules/Services.jsm");
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
.createInstance(Ci.nsISupportsPRBool);
Services.obs.notifyObservers(cancelQuit,
"quit-application-requested", null);
if (!cancelQuit.data) {
Services.startup.restartInSafeMode(Ci.nsIAppStartup.eAttemptQuit);
}
""")
try:
self.assertFalse(self.is_safe_mode, "Safe Mode is unexpectedly enabled")
self.marionette.restart(in_app=True, callback=restart_in_safe_mode)
self.assertTrue(self.is_safe_mode, "Safe Mode is not enabled")
finally:
self.marionette.quit(clean=True)
def test_in_app_restart_with_callback_no_shutdown(self):
try:
timeout_startup = self.marionette.DEFAULT_STARTUP_TIMEOUT