Bug 1350897 - Tested quit shutdown/restart cause in Marionette Python client. r=whimboo draft bug_1350897
authorVedant Chakravadhanula <vedantc98@gmail.com>
Tue, 26 Sep 2017 19:07:00 +0530
branchbug_1350897
changeset 670514 413112984e08e1dd2cb0a3ae814c77f76d3c733a
parent 670513 91d75d117de13b6147169050978d607a4b6d7960
child 733246 ea973377a99b57e48d105e1800c29704fcd9967a
push id81644
push userbmo:vedantc98@gmail.com
push dateTue, 26 Sep 2017 13:38:30 +0000
reviewerswhimboo
bugs1350897
milestone57.0a1
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
testing/marionette/client/marionette_driver/marionette.py
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -1074,17 +1074,18 @@ class Marionette(object):
             if canceled:
                 raise errors.MarionetteException(
                     "Something cancelled the quit application request")
 
         body = None
         if len(flags) > 0:
             body = {"flags": list(flags)}
 
-        self._send_message("quitApplication", body)
+        resp = self._send_message("quitApplication", body)
+        return resp
 
     @do_process_check
     def quit(self, clean=False, 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.
         To start the application again, :func:`start_session` has to be called.
@@ -1099,21 +1100,25 @@ class Marionette(object):
                          be used to trigger the shutdown.
         """
         if not self.instance:
             raise errors.MarionetteException("quit() can only be called "
                                              "on Gecko instances launched by Marionette")
 
         if in_app:
             if callable(callback):
-                self._send_message("acceptConnections", {"value": False})
+                causeJSON = self._send_message("acceptConnections", {"value": False})
                 callback()
             else:
-                self._request_in_app_shutdown()
+                causeJSON = self._request_in_app_shutdown()
 
+            if causeJSON:
+                if causeJSON["cause"] is not "shutdown":
+                    raise errors.MarionetteException("The Marionette server returned an unexpected "
+                                                     "cause of shutdown.")
             # Ensure to explicitely mark the session as deleted
             self.delete_session(send_request=False, reset_session_id=True)
 
             # Give the application some time to shutdown
             returncode = self.instance.runner.wait(timeout=self.DEFAULT_SHUTDOWN_TIMEOUT)
             if returncode is None:
                 # This will force-close the application without sending any other message.
                 self.cleanup()
@@ -1145,20 +1150,25 @@ class Marionette(object):
             raise errors.MarionetteException("restart() can only be called "
                                              "on Gecko instances launched by Marionette")
         context = self._send_message("getContext", key="value")
         if in_app:
             if clean:
                 raise ValueError("An in_app restart cannot be triggered with the clean flag set")
 
             if callable(callback):
-                self._send_message("acceptConnections", {"value": False})
+                causeJSON = self._send_message("acceptConnections", {"value": False})
                 callback()
             else:
-                self._request_in_app_shutdown("eRestart")
+                causeJSON = self._request_in_app_shutdown("eRestart")
+
+            if causeJSON:
+                if causeJSON["cause"] is not "restart":
+                    raise errors.MarionetteException("The Marionette server returned an unexpected "
+                                                     "cause of shutdown.")
 
             # Ensure to explicitely mark the session as deleted
             self.delete_session(send_request=False, reset_session_id=True)
 
             try:
                 timeout = self.DEFAULT_SHUTDOWN_TIMEOUT + self.DEFAULT_STARTUP_TIMEOUT
                 self.raise_for_port(timeout=timeout)
             except socket.timeout: