diff --git a/testing/marionette/driver/marionette_driver/marionette.py b/testing/marionette/driver/marionette_driver/marionette.py index f2c591ae5e17..436b89e12656 100644 --- a/testing/marionette/driver/marionette_driver/marionette.py +++ b/testing/marionette/driver/marionette_driver/marionette.py @@ -677,8 +677,7 @@ class Marionette(object): timeout=timeout) @do_crash_check - def _send_message(self, command, response_key="ok", ignore_response=False, - **kwargs): + def _send_message(self, command, response_key="ok", **kwargs): if not self.session_id and command != "newSession": raise errors.MarionetteException("Please start a session") @@ -689,7 +688,7 @@ class Marionette(object): message["parameters"] = kwargs try: - response = self.client.send(message, ignore_response=ignore_response) + response = self.client.send(message) except socket.timeout: self.session = None self.window = None @@ -909,7 +908,7 @@ class Marionette(object): "eForceQuit", "eRestart", ] - self._send_message('quitApplication', flags=restart_flags, ignore_response=True) + self._send_message('quitApplication', flags=restart_flags) self.client.close() else: self.delete_session() diff --git a/testing/marionette/marionette-server.js b/testing/marionette/marionette-server.js index c597011289e4..255303f04f7f 100644 --- a/testing/marionette/marionette-server.js +++ b/testing/marionette/marionette-server.js @@ -189,6 +189,7 @@ function MarionetteServerConnection(aPrefix, aTransport, aServer) this.observing = null; this._browserIds = new WeakMap(); + this.quitFlags = null; } MarionetteServerConnection.prototype = { @@ -228,6 +229,12 @@ MarionetteServerConnection.prototype = { onClosed: function MSC_onClosed(aStatus) { this.server._connectionClosed(this); this.sessionTearDown(); + + if (this.quitFlags !== null) { + let flags = this.quitFlags; + this.quitFlags = null; + Services.startup.quit(flags); + } }, /** @@ -2637,7 +2644,7 @@ MarionetteServerConnection.prototype = { * current session. */ quitApplication: function MDA_quitApplication (aRequest) { - let command_id = this.getCommandId(); + let command_id = this.command_id = this.getCommandId(); if (appName != "Firefox") { this.sendError("In app initiated quit only supported on Firefox", 500, null, command_id); } @@ -2648,8 +2655,13 @@ MarionetteServerConnection.prototype = { flags |= Ci.nsIAppStartup[k]; } - this.sessionTearDown(); - Services.startup.quit(flags); + // Close the listener so we can't re-connect until after the restart. + this.server.closeListener(); + this.quitFlags = flags; + + // This notifies the client it's safe to begin attempting to reconnect. + // The actual quit will happen when the current socket connection is closed. + this.sendOk(command_id); }, /** diff --git a/testing/marionette/transport/marionette_transport/transport.py b/testing/marionette/transport/marionette_transport/transport.py index be6723583a1e..a72c0cb61c49 100644 --- a/testing/marionette/transport/marionette_transport/transport.py +++ b/testing/marionette/transport/marionette_transport/transport.py @@ -80,10 +80,8 @@ class MarionetteTransport(object): response = self.send({'to': 'root', 'name': 'getMarionetteID'}) self.actor = response['id'] - def send(self, msg, ignore_response=False): + def send(self, msg): """ Send a message on the socket, prepending it with len(msg) + ':'. - The ignore_response parameter indicates no response is expected from - the remote end, for instance when the client requests a quit. """ if not self.sock: self.connect() @@ -102,10 +100,7 @@ class MarionetteTransport(object): else: raise e - if not ignore_response: - response = self.receive() - else: - response = {'ok': True} + response = self.receive() return response def close(self):