Bug 1271758 - Ensure that execute_script does not fail on closed chrome windows. r=ato a=test-only
authorHenrik Skupin <mail@hskupin.info>
Wed, 11 May 2016 22:10:51 +0200
changeset 333240 d9a268310116151364c10b7f2d91c3bef687ffe5
parent 333239 18e0dc8fa500281dc7fb9864b2954190b356a5de
child 333241 fa7b938306444925723b7f53dae21608c3a7ae41
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1271758
milestone48.0a2
Bug 1271758 - Ensure that execute_script does not fail on closed chrome windows. r=ato a=test-only MozReview-Commit-ID: 7SMV36KuFCe
testing/marionette/evaluate.js
testing/marionette/harness/marionette/tests/unit/test_execute_script.py
--- a/testing/marionette/evaluate.js
+++ b/testing/marionette/evaluate.js
@@ -3,16 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
+Cu.import("resource://gre/modules/Timer.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 Cu.import("chrome://marionette/content/error.js");
 
 const logger = Log.repository.getLogger("Marionette");
 
 this.EXPORTED_SYMBOLS = ["evaluate", "sandbox", "Sandboxes"];
 
@@ -128,17 +129,17 @@ evaluate.sandbox = function(sb, script, 
     if (opts.debug) {
       sb.window.onerror = (msg, url, line) => {
         let err = new JavaScriptError(`${msg} at: ${url} line: ${line}`);
         reject(err);
       };
     }
 
     // timeout and unload handlers
-    timeoutId = sb.window.setTimeout(
+    timeoutId = setTimeout(
         timeoutHandler, opts.timeout || DEFAULT_TIMEOUT);
     sb.window.addEventListener("unload", unloadHandler);
 
     let res;
     try {
       res = Cu.evalInSandbox(
           script, sb, "1.8", opts.filename || "dummy file", 0);
     } catch (e) {
--- a/testing/marionette/harness/marionette/tests/unit/test_execute_script.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_execute_script.py
@@ -261,8 +261,19 @@ class TestExecuteChrome(TestExecuteConte
         self.assertEqual(expected, actual)
 
     def test_async_script_timeout(self):
         with self.assertRaises(errors.ScriptTimeoutException):
             self.marionette.execute_async_script("""
                 var cb = arguments[arguments.length - 1];
                 setTimeout(function() { cb() }, 250);
                 """, script_timeout=100)
+
+    def test_invalid_chrome_handle(self):
+        # Close second chrome window and don't switch back to the original one
+        self.marionette.close_chrome_window()
+        self.assertEqual(len(self.marionette.chrome_window_handles), 1)
+
+        # Call execute_script on an invalid chrome handle
+        with self.marionette.using_context('chrome'):
+            self.marionette.execute_script("""
+                return true;
+            """)