Bug 1279243 - Add quit_in_app() to marionette driver; r=maja_zf draft
authorAndré Reinald <areinald@mozilla.com>
Tue, 19 Jul 2016 17:13:43 +0200
changeset 389503 230bd9d1e898c2c7470f0611bf40e93f6858ac5c
parent 389281 feaaf1af1065257b9178faca8b67eed9657b4a17
child 525785 283f47edef68dbe45f0879e03bccbefc0179b199
push id23442
push userareinald@mozilla.com
push dateTue, 19 Jul 2016 15:17:57 +0000
reviewersmaja_zf
bugs1279243
milestone50.0a1
Bug 1279243 - Add quit_in_app() to marionette driver; r=maja_zf MozReview-Commit-ID: 4O1hnYVsUWX
testing/marionette/client/marionette_driver/marionette.py
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -725,17 +725,17 @@ class Marionette(object):
 
         else:
             error = obj["error"]
             message = obj["message"]
             stacktrace = obj["stacktrace"]
 
         raise errors.lookup(error)(message, stacktrace=stacktrace)
 
-    def _reset_timeouts(self):
+    def reset_timeouts(self):
         if self.timeout is not None:
             self.timeouts(self.TIMEOUT_SEARCH, self.timeout)
             self.timeouts(self.TIMEOUT_SCRIPT, self.timeout)
             self.timeouts(self.TIMEOUT_PAGE, self.timeout)
         else:
             self.timeouts(self.TIMEOUT_PAGE, 30000)
 
     def check_for_crash(self):
@@ -1005,17 +1005,34 @@ class Marionette(object):
             if not pref_exists:
                 break
         self.set_context(self.CONTEXT_CONTENT)
         if not pref_exists:
             self.delete_session()
             self.instance.restart(prefs)
             self.raise_for_port(self.wait_for_port())
             self.start_session()
-            self._reset_timeouts()
+            self.reset_timeouts()
+
+    def quit_in_app(self):
+        """
+        This will terminate the currently running instance.
+        """
+        if not self.instance:
+            raise errors.MarionetteException("quit_in_app can only be called "
+                                             "on gecko instances launched by Marionette")
+        # Values here correspond to constants in nsIAppStartup.
+        # See http://mzl.la/1X0JZsC
+        restart_flags = [
+            "eForceQuit",
+            "eRestart",
+        ]
+        self._send_message("quitApplication", {"flags": restart_flags})
+        self.client.close()
+        self.raise_for_port(self.wait_for_port())
 
     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 clean: If False the same profile will be used after the restart. Note
                        that the in app initiated restart always maintains the same
@@ -1025,31 +1042,24 @@ class Marionette(object):
                         by killing the process.
         """
         if not self.instance:
             raise errors.MarionetteException("restart can only be called "
                                              "on gecko instances launched by Marionette")
         if in_app:
             if clean:
                 raise ValueError
-            # Values here correspond to constants in nsIAppStartup.
-            # See http://mzl.la/1X0JZsC
-            restart_flags = [
-                "eForceQuit",
-                "eRestart",
-            ]
-            self._send_message("quitApplication", {"flags": restart_flags})
-            self.client.close()
+            self.quit_in_app()
         else:
             self.delete_session()
             self.instance.restart(clean=clean)
+            self.raise_for_port(self.wait_for_port())
 
-        self.raise_for_port(self.wait_for_port())
         self.start_session(session_id=self.session_id)
-        self._reset_timeouts()
+        self.reset_timeouts()
 
         if in_app:
             # In some cases Firefox restarts itself by spawning into a new process group.
             # As long as mozprocess cannot track that behavior (bug 1284864) we assist by
             # informing about the new process id.
             self.instance.runner.process_handler.check_for_detached(self.session['processId'])
 
     def absolute_url(self, relative_url):