Bug 1107706: Part 14: Fix quitApplication
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 20 Mar 2015 20:44:17 +0000
changeset 264857 b4606044035729b11d0a5f4a8fbe4db18d8434db
parent 264856 800504a8ac36598fd48706efb720f728e2fe7e1b
child 264858 0736c222ecb9873a5d96727d03425710bb81961a
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1107706
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1107706: Part 14: Fix quitApplication
testing/marionette/dispatcher.js
testing/marionette/server.js
--- a/testing/marionette/dispatcher.js
+++ b/testing/marionette/dispatcher.js
@@ -26,18 +26,20 @@ const uuidGen = Cc["@mozilla.org/uuid-ge
  *
  * @param {number} connId
  *     Unique identifier of the connection this dispatcher should handle.
  * @param {DebuggerTransport} transport
  *     Debugger transport connection to the client.
  * @param {function(Emulator): GeckoDriver} driverFactory
  *     A factory function that takes an Emulator as argument and produces
  *     a GeckoDriver.
+ * @param {function()} stopSignal
+ *     Signal to stop the Marionette server.
  */
-this.Dispatcher = function(connId, transport, driverFactory) {
+this.Dispatcher = function(connId, transport, driverFactory, stopSignal) {
   this.id = connId;
   this.conn = transport;
 
   // Marionette uses a protocol based on the debugger server, which
   // requires passing back actor ID's with responses.  Unlike the debugger
   // server, we don't actually have multiple actors, so just use a dummy
   // value of "0".
   this.actorId = "0";
@@ -47,16 +49,18 @@ this.Dispatcher = function(connId, trans
 
   // transport hooks are Dispatcher.prototype.onPacket
   // and Dispatcher.prototype.onClosed
   this.conn.hooks = this;
 
   this.emulator = new Emulator(msg => this.sendResponse(msg, -1));
   this.driver = driverFactory(this.emulator);
   this.commandProcessor = new CommandProcessor(this.driver);
+
+  this.stopSignal_ = stopSignal;
 };
 
 /**
  * Debugger transport callback that dispatches the request.
  * Request handlers defined in this.requests take presedence
  * over those defined in this.driver.commands.
  */
 Dispatcher.prototype.onPacket = function(packet) {
@@ -120,16 +124,19 @@ Dispatcher.prototype.quitApplication = f
     return;
   }
 
   let flags = Ci.nsIAppStartup.eAttemptQuit;
   for (let k of msg.parameters.flags) {
     flags |= Ci.nsIAppStartup[k];
   }
 
+  this.stopSignal_();
+  this.sendOk(id);
+
   this.driver.sessionTearDown();
   Services.startup.quit(flags);
 };
 
 // Convenience methods:
 
 Dispatcher.prototype.sayHello = function() {
   let id = this.beginNewCommand();
--- a/testing/marionette/server.js
+++ b/testing/marionette/server.js
@@ -140,17 +140,18 @@ MarionetteServer.prototype.closeListener
 
 MarionetteServer.prototype.onSocketAccepted = function(
     serverSocket, clientSocket) {
   let input = clientSocket.openInputStream(0, 0, 0);
   let output = clientSocket.openOutputStream(0, 0, 0);
   let transport = new DebuggerTransport(input, output);
   let connId = "conn" + this.nextConnId++;
 
-  let dispatcher = new Dispatcher(connId, transport, this.driverFactory);
+  let stopSignal = () => this.stop();
+  let dispatcher = new Dispatcher(connId, transport, this.driverFactory, stopSignal);
   dispatcher.onclose = this.onConnectionClosed.bind(this);
   this.conns[connId] = dispatcher;
 
   logger.info(`Accepted connection ${connId} from ${clientSocket.host}:${clientSocket.port}`);
 
   // Create a root actor for the connection and send the hello packet
   dispatcher.sayHello();
   transport.ready();