Bug 1122609 - Set marionette arguments per execute script call in chrome scope even if the sanbox is reused.;r=jgriffin
authorChris Manchester <cmanchester@mozilla.com>
Tue, 20 Jan 2015 20:35:15 -0500
changeset 242327 ffa9eece82875fb681722503aa78d66086391cfb
parent 242326 8f41739aee272a56835f072f23baec3535f4b438
child 242328 49c547ee2a1119f4f2780727b8a69c1b6add667d
push id7677
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 18:11:24 +0000
treeherdermozilla-aurora@f531d838c055 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs1122609
milestone38.0a1
Bug 1122609 - Set marionette arguments per execute script call in chrome scope even if the sanbox is reused.;r=jgriffin
testing/marionette/marionette-server.js
--- a/testing/marionette/marionette-server.js
+++ b/testing/marionette/marionette-server.js
@@ -764,30 +764,20 @@ MarionetteServerConnection.prototype = {
    *        Window in which we will execute code
    * @param Marionette marionette
    *        Marionette test instance
    * @param object args
    *        Client given args
    * @return Sandbox
    *        Returns the sandbox
    */
-  createExecuteSandbox: function MDA_createExecuteSandbox(aWindow, marionette, args, specialPowers, command_id) {
-    try {
-      args = this.curBrowser.elementManager.convertWrappedArguments(args, aWindow);
-    }
-    catch(e) {
-      this.sendError(e.message, e.code, e.stack, command_id);
-      return;
-    }
-
+  createExecuteSandbox: function MDA_createExecuteSandbox(aWindow, marionette, specialPowers, command_id) {
     let _chromeSandbox = new Cu.Sandbox(aWindow,
        { sandboxPrototype: aWindow, wantXrays: false, sandboxName: ''});
     _chromeSandbox.global = _chromeSandbox;
-    _chromeSandbox.__namedArgs = this.curBrowser.elementManager.applyNamedArgs(args);
-    _chromeSandbox.__marionetteParams = args;
     _chromeSandbox.testUtils = utils;
 
     marionette.exports.forEach(function(fn) {
       try {
         _chromeSandbox[fn] = marionette[fn].bind(marionette);
       }
       catch(e) {
         _chromeSandbox[fn] = marionette[fn];
@@ -805,16 +795,30 @@ MarionetteServerConnection.prototype = {
       loader.loadSubScript("chrome://specialpowers/content/ChromePowers.js",
                            _chromeSandbox);
     }
 
     return _chromeSandbox;
   },
 
   /**
+   * Apply arguments sent from the client to the current (possibly reused) execution
+   * sandbox.
+   */
+  applyArgumentsToSandbox: function MDA_applyArgumentsToSandbox(win, sandbox, args, command_id) {
+    try {
+      sandbox.__marionetteParams = this.curBrowser.elementManager.convertWrappedArguments(args, win);
+    }
+    catch(e) {
+      this.sendError(e.message, e.code, e.stack, command_id);
+    }
+    sandbox.__namedArgs = this.curBrowser.elementManager.applyNamedArgs(args);
+  },
+
+  /**
    * Executes a script in the given sandbox.
    *
    * @param Sandbox sandbox
    *        Sandbox in which the script will run
    * @param string script
    *        The script to run
    * @param boolean directInject
    *        If true, then the script will be run as is,
@@ -911,29 +915,30 @@ MarionetteServerConnection.prototype = {
      setTimer();
      this.heartbeatCallback = function resetInactivityTimer() {
       that.inactivityTimer.cancel();
       setTimer();
      }
     }
 
 
+    let curWindow = this.getCurrentWindow();
     if (!this.sandbox || newSandbox) {
-      let curWindow = this.getCurrentWindow();
       let marionette = new Marionette(this, curWindow, "chrome",
                                       this.marionetteLog,
                                       timeout, this.heartbeatCallback, this.testName);
       this.sandbox = this.createExecuteSandbox(curWindow,
                                                marionette,
-                                               aRequest.parameters.args,
                                                aRequest.parameters.specialPowers,
                                                command_id);
       if (!this.sandbox)
         return;
     }
+    this.applyArgumentsToSandbox(curWindow, this.sandbox, aRequest.parameters.args,
+                                 command_id)
 
     try {
       this.sandbox.finish = function chromeSandbox_finish() {
         if (that.inactivityTimer != null) {
           that.inactivityTimer.cancel();
         }
         return that.sandbox.generate_results();
       };
@@ -1133,22 +1138,23 @@ MarionetteServerConnection.prototype = {
     }
 
     if (!this.sandbox || newSandbox) {
       let marionette = new Marionette(this, curWindow, "chrome",
                                       this.marionetteLog,
                                       timeout, this.heartbeatCallback, this.testName);
       this.sandbox = this.createExecuteSandbox(curWindow,
                                                marionette,
-                                               aRequest.parameters.args,
                                                aRequest.parameters.specialPowers,
                                                command_id);
       if (!this.sandbox)
         return;
     }
+    this.applyArgumentsToSandbox(curWindow, this.sandbox, aRequest.parameters.args,
+                                 command_id)
 
     try {
 
       this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
       if (this.timer != null) {
         this.timer.initWithCallback(function() {
           chromeAsyncReturnFunc("timed out", 28);
         }, that.timeout, Ci.nsITimer.TYPE_ONE_SHOT);