Bug 1350897 - Tested quit shutdown/restart cause in Marionette Python client. r=whimboo

The Marionette server now returns a JSON containing the cause of shutdown which isn't included in previous Firefoxen. We needed to test this JSON in the quit and restart methods in the python client.

MozReview-Commit-ID: 8uL9tbNszcm

--HG--
extra : rebase_source : 7f01fe55444b034a5f07e42acac0224a981be881
This commit is contained in:
Vedant Chakravadhanula 2017-10-03 10:48:30 +05:30
Родитель 1a723a8e5b
Коммит d8b5c6edce
1 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -1048,6 +1048,7 @@ class Marionette(object):
:throws InvalidArgumentException: If there are multiple :throws InvalidArgumentException: If there are multiple
`shutdown_flags` ending with `"Quit"`. `shutdown_flags` ending with `"Quit"`.
:returns: The cause of shutdown.
""" """
# The vast majority of this function was implemented inside # The vast majority of this function was implemented inside
@ -1080,7 +1081,7 @@ class Marionette(object):
if len(flags) > 0: if len(flags) > 0:
body = {"flags": list(flags)} body = {"flags": list(flags)}
self._send_message("quitApplication", body) return self._send_message("quitApplication", body, key="cause")
@do_process_check @do_process_check
def quit(self, clean=False, in_app=False, callback=None): def quit(self, clean=False, in_app=False, callback=None):
@ -1103,12 +1104,13 @@ class Marionette(object):
raise errors.MarionetteException("quit() can only be called " raise errors.MarionetteException("quit() can only be called "
"on Gecko instances launched by Marionette") "on Gecko instances launched by Marionette")
cause = None
if in_app: if in_app:
if callable(callback): if callable(callback):
self._send_message("acceptConnections", {"value": False}) self._send_message("acceptConnections", {"value": False})
callback() callback()
else: else:
self._request_in_app_shutdown() cause = self._request_in_app_shutdown()
# Ensure to explicitely mark the session as deleted # Ensure to explicitely mark the session as deleted
self.delete_session(send_request=False, reset_session_id=True) self.delete_session(send_request=False, reset_session_id=True)
@ -1127,6 +1129,10 @@ class Marionette(object):
self.delete_session(reset_session_id=True) self.delete_session(reset_session_id=True)
self.instance.close(clean=clean) self.instance.close(clean=clean)
if cause not in (None, "shutdown"):
raise errors.MarionetteException("Unexpected shutdown reason '{}' for "
"quitting the process.".format(cause))
@do_process_check @do_process_check
def restart(self, clean=False, in_app=False, callback=None): def restart(self, clean=False, in_app=False, callback=None):
""" """
@ -1146,6 +1152,8 @@ class Marionette(object):
raise errors.MarionetteException("restart() can only be called " raise errors.MarionetteException("restart() can only be called "
"on Gecko instances launched by Marionette") "on Gecko instances launched by Marionette")
context = self._send_message("getContext", key="value") context = self._send_message("getContext", key="value")
cause = None
if in_app: if in_app:
if clean: if clean:
raise ValueError("An in_app restart cannot be triggered with the clean flag set") raise ValueError("An in_app restart cannot be triggered with the clean flag set")
@ -1154,7 +1162,7 @@ class Marionette(object):
self._send_message("acceptConnections", {"value": False}) self._send_message("acceptConnections", {"value": False})
callback() callback()
else: else:
self._request_in_app_shutdown("eRestart") cause = self._request_in_app_shutdown("eRestart")
# Ensure to explicitely mark the session as deleted # Ensure to explicitely mark the session as deleted
self.delete_session(send_request=False, reset_session_id=True) self.delete_session(send_request=False, reset_session_id=True)
@ -1172,6 +1180,11 @@ class Marionette(object):
self.delete_session() self.delete_session()
self.instance.restart(clean=clean) self.instance.restart(clean=clean)
self.raise_for_port(timeout=self.DEFAULT_STARTUP_TIMEOUT) self.raise_for_port(timeout=self.DEFAULT_STARTUP_TIMEOUT)
if cause not in (None, "restart"):
raise errors.MarionetteException("Unexpected shutdown reason '{}' for "
"restarting the process".format(cause))
self.start_session() self.start_session()
# Restore the context as used before the restart # Restore the context as used before the restart
self.set_context(context) self.set_context(context)