Bug 1274408: Remove emulator support from Marionette in Gecko r?ato draft
authorDavid Burns <dburns@mozilla.com>
Tue, 24 May 2016 10:22:54 +0100
changeset 370533 0ad7fbdb608345fb15fb89f0f813b58ac419de4f
parent 370532 70c4a188d7dd9a7ab3b204f9b782c425ac774aa6
child 370534 9e4fcd6481ec1ab2240cdae0959ea281ebdd3498
push id19087
push userdburns@mozilla.com
push dateTue, 24 May 2016 22:03:13 +0000
reviewersato
bugs1274408
milestone49.0a1
Bug 1274408: Remove emulator support from Marionette in Gecko r?ato The emulator code was originally hacks to allow us to instrument the emulator from JavaScript in the B2G world. Since we no longer support this it is being removed. MozReview-Commit-ID: 3XDk21SFfUc
testing/marionette/dispatcher.js
testing/marionette/driver.js
testing/marionette/emulator.js
testing/marionette/frame.js
testing/marionette/jar.mn
testing/marionette/listener.js
testing/marionette/server.js
--- a/testing/marionette/dispatcher.js
+++ b/testing/marionette/dispatcher.js
@@ -6,17 +6,16 @@
 
 const {interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 
 Cu.import("chrome://marionette/content/driver.js");
-Cu.import("chrome://marionette/content/emulator.js");
 Cu.import("chrome://marionette/content/error.js");
 Cu.import("chrome://marionette/content/message.js");
 
 this.EXPORTED_SYMBOLS = ["Dispatcher"];
 
 const PROTOCOL_VERSION = 3;
 
 const logger = Log.repository.getLogger("Marionette");
@@ -24,36 +23,34 @@ const logger = Log.repository.getLogger(
 /**
  * Manages a Marionette connection, and dispatches packets received to
  * their correct destinations.
  *
  * @param {number} connId
  *     Unique identifier of the connection this dispatcher should handle.
  * @param {DebuggerTransport} transport
  *     Debugger transport connection to the client.
- * @param {function(EmulatorService): GeckoDriver} driverFactory
- *     A factory function that takes an EmulatorService and produces
- *     a GeckoDriver.
+ * @param {function(): GeckoDriver} driverFactory
+ *     A factory function that produces a GeckoDriver.
  */
 this.Dispatcher = function(connId, transport, driverFactory) {
   this.connId = connId;
   this.conn = transport;
 
   // transport hooks are Dispatcher#onPacket
   // and Dispatcher#onClosed
   this.conn.hooks = this;
 
   // callback for when connection is closed
   this.onclose = null;
 
   // last received/sent message ID
   this.lastId = 0;
 
-  this.emulator = new emulator.EmulatorService(this.sendEmulator.bind(this));
-  this.driver = driverFactory(this.emulator);
+  this.driver = driverFactory();
 
   // lookup of commands sent by server to client by message ID
   this.commands_ = new Map();
 };
 
 /**
  * Debugger transport callback that cleans up
  * after a connection is closed.
@@ -154,33 +151,26 @@ Dispatcher.prototype.sendError = functio
 Dispatcher.prototype.sayHello = function() {
   let whatHo = {
     applicationType: "gecko",
     marionetteProtocol: PROTOCOL_VERSION,
   };
   this.sendRaw(whatHo);
 };
 
-Dispatcher.prototype.sendEmulator = function(name, params, resCb, errCb) {
-  let cmd = new Command(++this.lastId, name, params);
-  cmd.onresult = resCb;
-  cmd.onerror = errCb;
-  this.send(cmd);
-};
 
 /**
- * Delegates message to client or emulator based on the provided
- * {@code cmdId}.  The message is sent over the debugger transport socket.
+ * Delegates message to client based on the provided  {@code cmdId}.
+ * The message is sent over the debugger transport socket.
  *
  * The command ID is a unique identifier assigned to the client's request
  * that is used to distinguish the asynchronous responses.
  *
  * Whilst responses to commands are synchronous and must be sent in the
- * correct order, emulator callbacks are more transparent and can be sent
- * at any time.  These callbacks won't change the current command state.
+ * correct order.
  *
  * @param {Command,Response} msg
  *     The command or response to send.
  */
 Dispatcher.prototype.send = function(msg) {
   msg.origin = MessageOrigin.Server;
   if (msg instanceof Command) {
     this.commands_.set(msg.id, msg);
@@ -188,26 +178,16 @@ Dispatcher.prototype.send = function(msg
   } else if (msg instanceof Response) {
     this.sendToClient(msg);
   }
 };
 
 // Low-level methods:
 
 /**
- * Send command to emulator over the debugger transport socket.
- *
- * @param {Command} cmd
- *     The command to issue to the emulator.
- */
-Dispatcher.prototype.sendToEmulator = function(cmd) {
-  this.sendMessage(cmd);
-};
-
-/**
  * Send given response to the client over the debugger transport socket.
  *
  * @param {Response} resp
  *     The response to send back to the client.
  */
 Dispatcher.prototype.sendToClient = function(resp) {
   this.driver.responseCompleted();
   this.sendMessage(resp);
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -16,17 +16,16 @@ Cu.import("resource://gre/modules/XPCOMU
 
 XPCOMUtils.defineLazyServiceGetter(
     this, "cookieManager", "@mozilla.org/cookiemanager;1", "nsICookieManager2");
 
 Cu.import("chrome://marionette/content/action.js");
 Cu.import("chrome://marionette/content/atom.js");
 Cu.import("chrome://marionette/content/browser.js");
 Cu.import("chrome://marionette/content/element.js");
-Cu.import("chrome://marionette/content/emulator.js");
 Cu.import("chrome://marionette/content/error.js");
 Cu.import("chrome://marionette/content/evaluate.js");
 Cu.import("chrome://marionette/content/event.js");
 Cu.import("chrome://marionette/content/interaction.js");
 Cu.import("chrome://marionette/content/logging.js");
 Cu.import("chrome://marionette/content/modal.js");
 Cu.import("chrome://marionette/content/proxy.js");
 Cu.import("chrome://marionette/content/simpletest.js");
@@ -81,26 +80,20 @@ this.Context.fromString = function(s) {
  * object.
  *
  * @param {string} appName
  *     Description of the product, for example "B2G" or "Firefox".
  * @param {string} device
  *     Device this driver should assume.
  * @param {function()} stopSignal
  *     Signal to stop the Marionette server.
- * @param {EmulatorService=} emulator
- *     Interface that allows instructing the emulator connected to the
- *     client to run commands and perform shell invocations.
  */
-this.GeckoDriver = function(appName, device, stopSignal, emulator) {
+this.GeckoDriver = function(appName, device, stopSignal) {
   this.appName = appName;
   this.stopSignal_ = stopSignal;
-  this.emulator = emulator;
-  // TODO(ato): hack
-  this.emulator.sendToListener = this.sendAsync.bind(this);
 
   this.sessionId = null;
   this.wins = new browser.Windows();
   this.browsers = {};
   // points to current browser
   this.curBrowser = null;
   this.context = Context.CONTENT;
   this.scriptTimeout = null;
@@ -867,17 +860,16 @@ GeckoDriver.prototype.execute_ = functio
         return this.listener.executeInSandbox(script, args, timeout, opts);
       }
 
     case Context.CHROME:
       let sb = this.sandboxes.get(opts.sandboxName, opts.newSandbox);
       if (opts.sandboxName) {
         sb = sandbox.augment(sb, new logging.Adapter(this.marionetteLog));
         sb = sandbox.augment(sb, {global: sb});
-        sb = sandbox.augment(sb, new emulator.Adapter(this.emulator));
       }
 
       opts.timeout = timeout;
       script = this.importedScripts.for(Context.CHROME).concat(script);
       let wargs = this.curBrowser.elementManager.convertWrappedArguments(args, {frame: sb.window});
       let evaluatePromise = evaluate.sandbox(sb, script, wargs, opts);
       return evaluatePromise.then(res => this.curBrowser.elementManager.wrapValue(res));
   }
deleted file mode 100644
--- a/testing/marionette/emulator.js
+++ /dev/null
@@ -1,166 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
-
-Cu.import("chrome://marionette/content/error.js");
-
-Cu.import("resource://gre/modules/Log.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/Task.jsm");
-
-const logger = Log.repository.getLogger("Marionette");
-
-this.EXPORTED_SYMBOLS = ["emulator"];
-
-this.emulator = {};
-
-/**
- * Provides a service for instructing the emulator attached to the
- * currently connected client to perform shell- and command instructions.
- */
-emulator.EmulatorService = class {
-  /*
-   * @param {function(Object)} sendToEmulatorFn
-   *     Callback function that sends a message to the emulator.
-   */
-  constructor(sendToEmulatorFn) {
-    this.sendToEmulator = sendToEmulatorFn;
-  }
-
-  /**
-   * Instruct the client to run an Android emulator command.
-   *
-   * @param {string} cmd
-   *     The command to run.
-   * @param {function(?)} resCb
-   *     Callback on a result response from the emulator.
-   * @param {function(?)} errCb
-   *     Callback on an error in running the command.
-   */
-  command(cmd, resCb, errCb) {
-    if (arguments.length < 1) {
-      throw new ValueError("Not enough arguments");
-    }
-    this.sendToEmulator(
-        "runEmulatorCmd", {emulator_cmd: cmd}, resCb, errCb);
-  }
-
-  /**
-   * Instruct the client to execute Android emulator shell arguments.
-   *
-   * @param {Array.<string>} args
-   *     The shell instruction for the emulator to execute.
-   * @param {function(?)} resCb
-   *     Callback on a result response from the emulator.
-   * @param {function(?)} errCb
-   *     Callback on an error in executing the shell arguments.
-   */
-  shell(args, resCb, errCb) {
-    if (arguments.length < 1) {
-      throw new ValueError("Not enough arguments");
-    }
-    this.sendToEmulator(
-        "runEmulatorShell", {emulator_shell: args}, resCb, errCb);
-  }
-
-  processMessage(msg) {
-    let resCb = this.resultCallback(msg.json.id);
-    let errCb = this.errorCallback(msg.json.id);
-
-    switch (msg.name) {
-      case "Marionette:runEmulatorCmd":
-        this.command(msg.json.arguments, resCb, errCb);
-        break;
-
-      case "Marionette:runEmulatorShell":
-        this.shell(msg.json.arguments, resCb, errCb);
-        break;
-    }
-  }
-
-  resultCallback(uuid) {
-    return res => this.sendResult({value: res, id: uuid});
-  }
-
-  errorCallback(uuid) {
-    return err => this.sendResult({error: err, id: uuid});
-  }
-
-  sendResult(msg) {
-    // sendToListener set explicitly in GeckoDriver's ctor
-    this.sendToListener("listenerResponse", msg);
-  }
-
-  /** Receives IPC messages from the listener. */
-  // TODO(ato): The idea of services in chrome space
-  // can be generalised at some later time.
-  receiveMessage(msg) {
-    let uuid = msg.json.id;
-    try {
-      this.processMessage(msg);
-    } catch (e) {
-      this.sendResult({error: `${e.name}: ${e.message}`, id: uuid});
-    }
-  }
-};
-
-emulator.EmulatorService.prototype.QueryInterface =
-    XPCOMUtils.generateQI([
-      Ci.nsIMessageListener,
-      Ci.nsISupportsWeakReference
-    ]);
-
-emulator.EmulatorServiceClient = class {
-  constructor(chromeProxy) {
-    this.chrome = chromeProxy;
-  }
-
-  *command(cmd, cb) {
-    let res = yield this.chrome.runEmulatorCmd(cmd);
-    if (cb) {
-      cb(res);
-    }
-  }
-
-  *shell(args, cb) {
-    let res = yield this.chrome.runEmulatorShell(args);
-    if (cb) {
-      cb(res);
-    }
-  }
-};
-
-/**
- * Adapts EmulatorService for use with sandboxes that scripts are
- * evaluated in.  Is consumed by sandbox.augment.
- */
-emulator.Adapter = class {
-  constructor(emulator) {
-    this.emulator = emulator;
-  }
-
-  get exports() {
-    return new Map([
-      ["runEmulatorCmd", this.runEmulatorCmd.bind(this)],
-      ["runEmulatorShell", this.runEmulatorShell.bind(this)],
-    ]);
-  }
-
-  runEmulatorCmd(cmd, cb) {
-    this.yield(this.emulator.command(cmd, cb));
-  }
-
-  runEmulatorShell(args, cb) {
-    this.yield(this.emulator.shell(args, cb));
-  }
-
-  yield(promise) {
-    Task.spawn(function() {
-      yield promise;
-    });
-  }
-};
--- a/testing/marionette/frame.js
+++ b/testing/marionette/frame.js
@@ -211,18 +211,16 @@ frame.Manager = class {
    *     ChromeMessageBroadcaster or ChromeMessageSender.
    */
   addMessageManagerListeners(mm) {
     mm.addWeakMessageListener("Marionette:ok", this.driver);
     mm.addWeakMessageListener("Marionette:done", this.driver);
     mm.addWeakMessageListener("Marionette:error", this.driver);
     mm.addWeakMessageListener("Marionette:emitTouchEvent", this.driver);
     mm.addWeakMessageListener("Marionette:log", this.driver);
-    mm.addWeakMessageListener("Marionette:runEmulatorCmd", this.driver.emulator);
-    mm.addWeakMessageListener("Marionette:runEmulatorShell", this.driver.emulator);
     mm.addWeakMessageListener("Marionette:shareData", this.driver);
     mm.addWeakMessageListener("Marionette:switchToModalOrigin", this.driver);
     mm.addWeakMessageListener("Marionette:switchedToFrame", this.driver);
     mm.addWeakMessageListener("Marionette:getVisibleCookies", this.driver);
     mm.addWeakMessageListener("Marionette:getImportedScripts", this.driver.importedScripts);
     mm.addWeakMessageListener("Marionette:register", this.driver);
     mm.addWeakMessageListener("Marionette:listenersAttached", this.driver);
     mm.addWeakMessageListener("Marionette:getFiles", this.driver);
@@ -244,18 +242,16 @@ frame.Manager = class {
    *     ChromeMessageBroadcaster or ChromeMessageSender.
    */
   removeMessageManagerListeners(mm) {
     mm.removeWeakMessageListener("Marionette:ok", this.driver);
     mm.removeWeakMessageListener("Marionette:done", this.driver);
     mm.removeWeakMessageListener("Marionette:error", this.driver);
     mm.removeWeakMessageListener("Marionette:log", this.driver);
     mm.removeWeakMessageListener("Marionette:shareData", this.driver);
-    mm.removeWeakMessageListener("Marionette:runEmulatorCmd", this.driver.emulator);
-    mm.removeWeakMessageListener("Marionette:runEmulatorShell", this.driver.emulator);
     mm.removeWeakMessageListener("Marionette:switchedToFrame", this.driver);
     mm.removeWeakMessageListener("Marionette:getVisibleCookies", this.driver);
     mm.removeWeakMessageListener("Marionette:getImportedScripts", this.driver.importedScripts);
     mm.removeWeakMessageListener("Marionette:listenersAttached", this.driver);
     mm.removeWeakMessageListener("Marionette:register", this.driver);
     mm.removeWeakMessageListener("Marionette:getFiles", this.driver);
     mm.removeWeakMessageListener("MarionetteFrame:handleModal", this);
     mm.removeWeakMessageListener("MarionetteFrame:getCurrentFrameId", this);
--- a/testing/marionette/jar.mn
+++ b/testing/marionette/jar.mn
@@ -13,17 +13,16 @@ marionette.jar:
   content/listener.js (listener.js)
   content/element.js (element.js)
   content/simpletest.js (simpletest.js)
   content/frame.js (frame.js)
   content/event.js  (event.js)
   content/error.js (error.js)
   content/message.js (message.js)
   content/dispatcher.js (dispatcher.js)
-  content/emulator.js (emulator.js)
   content/modal.js (modal.js)
   content/proxy.js (proxy.js)
   content/capture.js (capture.js)
   content/cookies.js (cookies.js)
   content/atom.js (atom.js)
   content/evaluate.js (evaluate.js)
   content/logging.js (logging.js)
 #ifdef ENABLE_TESTS
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -13,17 +13,16 @@ var loader = Cc["@mozilla.org/moz/jssubs
     .getService(Ci.mozIJSSubScriptLoader);
 
 Cu.import("chrome://marionette/content/accessibility.js");
 Cu.import("chrome://marionette/content/action.js");
 Cu.import("chrome://marionette/content/atom.js");
 Cu.import("chrome://marionette/content/capture.js");
 Cu.import("chrome://marionette/content/cookies.js");
 Cu.import("chrome://marionette/content/element.js");
-Cu.import("chrome://marionette/content/emulator.js");
 Cu.import("chrome://marionette/content/error.js");
 Cu.import("chrome://marionette/content/evaluate.js");
 Cu.import("chrome://marionette/content/event.js");
 Cu.import("chrome://marionette/content/interaction.js");
 Cu.import("chrome://marionette/content/logging.js");
 Cu.import("chrome://marionette/content/proxy.js");
 Cu.import("chrome://marionette/content/simpletest.js");
 
@@ -523,18 +522,16 @@ function* execute(script, args, timeout,
 function* executeInSandbox(script, args, timeout, opts) {
   opts.timeout = timeout;
   script = importedScripts.for("content").concat(script);
 
   let sb = sandboxes.get(opts.sandboxName, opts.newSandbox);
   if (opts.sandboxName) {
     sb = sandbox.augment(sb, {global: sb});
     sb = sandbox.augment(sb, new logging.Adapter(contentLog));
-    let emulatorClient = new emulator.EmulatorServiceClient(asyncChrome);
-    sb = sandbox.augment(sb, new emulator.Adapter(emulatorClient));
   }
 
   let wargs = elementManager.convertWrappedArguments(args, curContainer);
   let evaluatePromise = evaluate.sandbox(sb, script, wargs, opts);
 
   let res = yield evaluatePromise;
   sendSyncMessage("Marionette:shareData", {log: elementManager.wrapValue(contentLog.get())});
   return elementManager.wrapValue(res);
--- a/testing/marionette/server.js
+++ b/testing/marionette/server.js
@@ -45,58 +45,44 @@ this.MarionetteServer = function(port, f
   this.port = port;
   this.forceLocal = forceLocal;
   this.conns = {};
   this.nextConnId = 0;
   this.alive = false;
 };
 
 /**
- * Function that takes an Emulator and produces a GeckoDriver.
+ * Function produces a GeckoDriver.
  *
  * Determines application name and device type to initialise the driver
- * with.  Also bypasses offline status if the device is a qemu or panda
- * type device.
+ * with.
  *
  * @return {GeckoDriver}
  *     A driver instance.
  */
-MarionetteServer.prototype.driverFactory = function(emulator) {
+MarionetteServer.prototype.driverFactory = function() {
   let appName = isMulet() ? "B2G" : Services.appinfo.name;
-  let qemu = "0";
   let device = null;
   let bypassOffline = false;
 
-  try {
-    Cu.import("resource://gre/modules/systemlibs.js");
-    qemu = libcutils.property_get("ro.kernel.qemu");
-    logger.debug("B2G emulator: " + (qemu == "1" ? "yes" : "no"));
-    device = libcutils.property_get("ro.product.device");
-    logger.debug("Device detected is " + device);
-    bypassOffline = (qemu == "1" || device == "panda");
-  } catch (e) {}
-
-  if (qemu == "1") {
-    device = "qemu";
-  }
   if (!device) {
     device = "desktop";
   }
 
   Preferences.set(CONTENT_LISTENER_PREF, false);
 
   if (bypassOffline) {
-    logger.debug("Bypassing offline status");
-    Preferences.set(MANAGE_OFFLINE_STATUS_PREF, false);
-    Services.io.manageOfflineStatus = false;
-    Services.io.offline = false;
+      logger.debug("Bypassing offline status");
+      Preferences.set(MANAGE_OFFLINE_STATUS_PREF, false);
+      Services.io.manageOfflineStatus = false;
+      Services.io.offline = false;
   }
 
   let stopSignal = () => this.stop();
-  return new GeckoDriver(appName, device, stopSignal, emulator);
+  return new GeckoDriver(appName, device, stopSignal);
 };
 
 MarionetteServer.prototype.start = function() {
   if (this.alive) {
     return;
   }
   let flags = Ci.nsIServerSocket.KeepWhenOffline;
   if (this.forceLocal) {