mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1137388 - Add a facility to restart firefox from marionette from within the browser for update tests.;r=automatedtester
This commit is contained in:
parent
4c72753d2f
commit
72d3ec850e
@ -35,4 +35,30 @@ class TestLog(MarionetteTestCase):
|
||||
self.marionette.enforce_gecko_prefs({"marionette.test.restart": True})
|
||||
self.marionette.restart()
|
||||
bool_value = self.marionette.execute_script("return SpecialPowers.getBoolPref('marionette.test.restart');")
|
||||
self.assertTrue(bool_value)
|
||||
self.assertTrue(bool_value)
|
||||
|
||||
def test_in_app_restart_the_browser(self):
|
||||
self.marionette.execute_script("SpecialPowers.setBoolPref('marionette.test.restart', true);")
|
||||
|
||||
# A "soft" restart initiated inside the application should keep track of this pref.
|
||||
self.marionette.restart(in_app=True)
|
||||
bool_value = self.marionette.execute_script("""
|
||||
return SpecialPowers.getBoolPref('marionette.test.restart');
|
||||
""")
|
||||
self.assertTrue(bool_value)
|
||||
|
||||
bool_value = self.marionette.execute_script("""
|
||||
SpecialPowers.setBoolPref('marionette.test.restart', false);
|
||||
return SpecialPowers.getBoolPref('marionette.test.restart');
|
||||
""")
|
||||
self.assertFalse(bool_value)
|
||||
|
||||
# A "hard" restart is still possible (i.e., our instance is still able
|
||||
# to kill the browser).
|
||||
self.marionette.restart(in_app=False)
|
||||
|
||||
bool_value = self.marionette.execute_script("""
|
||||
return SpecialPowers.getBoolPref('marionette.test.restart');
|
||||
""")
|
||||
# The "hard" restart blows away the pref we set.
|
||||
self.assertTrue(bool_value)
|
||||
|
@ -883,18 +883,38 @@ class Marionette(object):
|
||||
self.start_session()
|
||||
self._reset_timeouts()
|
||||
|
||||
def restart(self, clean=False):
|
||||
def restart(self, clean=False, in_app=False):
|
||||
"""
|
||||
This will terminate the currently running instance, and spawn a new instance
|
||||
with the same profile and then reuse the session id when creating a session again.
|
||||
|
||||
: param prefs: A dictionary whose keys are preference names.
|
||||
: param clean: If False the same profile will be used after the restart. Note
|
||||
that the in app initiated restart always maintains the same
|
||||
profile.
|
||||
: param in_app: If True, marionette will cause a restart from within the
|
||||
browser. Otherwise the browser will be restarted immediately
|
||||
by killing the process.
|
||||
"""
|
||||
if not self.instance:
|
||||
raise errors.MarionetteException("restart can only be called " \
|
||||
"on gecko instances launched by Marionette")
|
||||
self.delete_session()
|
||||
self.instance.restart(clean=clean)
|
||||
|
||||
if in_app:
|
||||
if clean:
|
||||
raise ValueError
|
||||
# Values here correspond to constants in nsIAppStartup.
|
||||
# See https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIAppStartup
|
||||
restart_flags = [
|
||||
"eForceQuit",
|
||||
"eRestart",
|
||||
]
|
||||
try:
|
||||
self._send_message('quitApplication', flags=restart_flags)
|
||||
except IOError:
|
||||
self.client.close()
|
||||
else:
|
||||
self.delete_session()
|
||||
self.instance.restart(clean=clean)
|
||||
assert(self.wait_for_port()), "Timed out waiting for port!"
|
||||
self.start_session(session_id=self.session_id)
|
||||
self._reset_timeouts()
|
||||
|
@ -2617,6 +2617,26 @@ MarionetteServerConnection.prototype = {
|
||||
this.sendOk(command_id);
|
||||
},
|
||||
|
||||
/**
|
||||
* Quits the application with the provided flags and tears down the
|
||||
* current session.
|
||||
*/
|
||||
quitApplication: function MDA_quitApplication (aRequest) {
|
||||
let command_id = this.getCommandId();
|
||||
if (appName != "Firefox") {
|
||||
this.sendError("In app initiated quit only supported on Firefox", 500, null, command_id);
|
||||
}
|
||||
|
||||
let flagsArray = aRequest.parameters.flags;
|
||||
let flags = Ci.nsIAppStartup.eAttemptQuit;
|
||||
for (let k of flagsArray) {
|
||||
flags |= Ci.nsIAppStartup[k];
|
||||
}
|
||||
|
||||
this.sessionTearDown();
|
||||
Services.startup.quit(flags);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the current status of the Application Cache
|
||||
*/
|
||||
@ -3299,6 +3319,7 @@ MarionetteServerConnection.prototype.requestTypes = {
|
||||
"switchToFrame": MarionetteServerConnection.prototype.switchToFrame,
|
||||
"switchToWindow": MarionetteServerConnection.prototype.switchToWindow,
|
||||
"deleteSession": MarionetteServerConnection.prototype.deleteSession,
|
||||
"quitApplication": MarionetteServerConnection.prototype.quitApplication,
|
||||
"emulatorCmdResult": MarionetteServerConnection.prototype.emulatorCmdResult,
|
||||
"importScript": MarionetteServerConnection.prototype.importScript,
|
||||
"clearImportedScripts": MarionetteServerConnection.prototype.clearImportedScripts,
|
||||
|
Loading…
Reference in New Issue
Block a user