Bug 940955: Allow marionette to restart the browser and create a new session; r=jgriffin

This gives us the ability to restart a session from the client side, say for testing Firefox updates,
and then carry on the test. To do this it is just self.marionette.restart()

--HG--
extra : rebase_source : db352f88ebfc455ed8105eefac54fec6a0b0c40b
This commit is contained in:
David Burns 2014-11-17 11:38:37 +00:00
parent 9ff47dee0b
commit fdae0e16ae
3 changed files with 33 additions and 19 deletions

View File

@ -30,12 +30,13 @@ class GeckoInstance(object):
"browser.tabs.remote.autostart.1": False,
"browser.tabs.remote.autostart.2": False}
def __init__(self, host, port, bin, profile, app_args=None, symbols_path=None,
gecko_log=None, prefs=None):
def __init__(self, host, port, bin, profile_path=None, app_args=None, symbols_path=None,
gecko_log=None, prefs=None, profile=None):
self.marionette_host = host
self.marionette_port = port
self.bin = bin
self.profile_path = profile
self.profile_path = profile_path
self.profile = None
self.prefs = prefs
self.app_args = app_args or []
self.runner = None
@ -46,12 +47,14 @@ class GeckoInstance(object):
profile_args = {"preferences": deepcopy(self.required_prefs)}
if self.prefs:
profile_args["preferences"].update(self.prefs)
if not self.profile_path:
profile_args["restore"] = False
profile = Profile(**profile_args)
else:
profile_args["path_from"] = self.profile_path
profile = Profile.clone(**profile_args)
if not self.profile:
if not self.profile_path:
profile_args["restore"] = False
self.profile = Profile(**profile_args)
else:
profile_args["path_from"] = self.profile_path
self.profile = Profile.clone(**profile_args)
if self.gecko_log is None:
self.gecko_log = 'gecko.log'
@ -91,7 +94,7 @@ class GeckoInstance(object):
'MOZ_CRASHREPORTER_NO_REPORT': '1', })
self.runner = Runner(
binary=self.bin,
profile=profile,
profile=self.profile,
cmdargs=['-no-remote', '-marionette'] + self.app_args,
env=env,
symbols_path=self.symbols_path,
@ -105,7 +108,11 @@ class GeckoInstance(object):
self.runner.stop()
self.runner.cleanup()
def restart(self, prefs=None):
def restart(self, prefs=None, clean=True):
if clean:
self.profile.cleanup()
self.profile = None
self.close()
if prefs:
self.prefs = prefs

View File

@ -477,6 +477,7 @@ class Marionette(object):
self.host = host
self.port = self.local_port = port
self.bin = bin
self.profile = profile
self.instance = None
self.session = None
self.session_id = None
@ -514,7 +515,7 @@ class Marionette(object):
KeyError):
instance_class = geckoinstance.GeckoInstance
self.instance = instance_class(host=self.host, port=self.port,
bin=self.bin, profile=profile,
bin=self.bin, profile=self.profile,
app_args=app_args, symbols_path=symbols_path,
gecko_log=gecko_log)
self.instance.start()
@ -530,7 +531,7 @@ class Marionette(object):
binary=emulator_binary,
userdata=emulator_img,
resolution=emulator_res,
profile=profile,
profile=self.profile,
adb_path=adb_path,
process_args=process_args)
self.emulator = self.runner.device
@ -790,20 +791,20 @@ class Marionette(object):
self.start_session()
self._reset_timeouts()
def restart_with_clean_profile(self):
def restart(self, clean=False):
"""
This will terminate the currently running instance, and spawn a new instance
with a clean profile.
with the same profile and then reuse the session id when creating a session again.
: param prefs: A dictionary whose keys are preference names.
"""
if not self.instance:
raise errors.MarionetteException("enforce_gecko_prefs can only be called " \
raise errors.MarionetteException("restart can only be called " \
"on gecko instances launched by Marionette")
self.delete_session()
self.instance.restart()
self.instance.restart(clean=clean)
assert(self.wait_for_port()), "Timed out waiting for port!"
self.start_session()
self.start_session(session_id=self.session_id)
self._reset_timeouts()
def absolute_url(self, relative_url):

View File

@ -27,6 +27,12 @@ class TestLog(MarionetteTestCase):
self.assertFalse(bool_value)
def test_clean_profile(self):
self.marionette.restart_with_clean_profile()
self.marionette.restart(clean=True)
with self.assertRaisesRegexp(JavascriptException, "Error getting pref"):
bool_value = self.marionette.execute_script("return SpecialPowers.getBoolPref('marionette.test.bool');")
def test_can_restart_the_browser(self):
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)