Bug 1107706: Part 7: Add timeout test for async scripts
☠☠ backed out by c44d46087f59 ☠ ☠
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 26 Feb 2015 17:41:54 +0000
changeset 264047 7bc309f733fa896e75f42e190f5f56f59bb74e05
parent 264046 69669d0e6ddcaa2b16d69f96750c50f694247271
child 264048 eeb3d39874b17e02888427afb9709f35abc95120
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 7: Add timeout test for async scripts
testing/marionette/client/marionette/tests/unit/test_execute_script.py
--- a/testing/marionette/client/marionette/tests/unit/test_execute_script.py
+++ b/testing/marionette/client/marionette/tests/unit/test_execute_script.py
@@ -1,49 +1,51 @@
 # 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/.
 
 import urllib
 
-from marionette_driver.by import By
-from marionette_driver.errors import JavascriptException
+from marionette_driver import By, errors
 from marionette import MarionetteTestCase
 
+
 def inline(doc):
     return "data:text/html;charset=utf-8,%s" % urllib.quote(doc)
 
+
 elements = inline("<p>foo</p> <p>bar</p>")
 
+
 class TestExecuteContent(MarionetteTestCase):
     def test_stack_trace(self):
         try:
             self.marionette.execute_script("""
                 let a = 1;
                 return b;
                 """)
             self.assertFalse(True)
-        except JavascriptException, inst:
+        except errors.JavascriptException as inst:
             self.assertTrue('return b' in inst.stacktrace)
 
     def test_execute_simple(self):
         self.assertEqual(1, self.marionette.execute_script("return 1;"))
 
     def test_check_window(self):
         self.assertTrue(self.marionette.execute_script("return (window !=null && window != undefined);"))
 
     def test_execute_no_return(self):
         self.assertEqual(self.marionette.execute_script("1;"), None)
 
     def test_execute_js_exception(self):
-        self.assertRaises(JavascriptException,
+        self.assertRaises(errors.JavascriptException,
             self.marionette.execute_script, "return foo(bar);")
 
     def test_execute_permission(self):
-        self.assertRaises(JavascriptException,
+        self.assertRaises(errors.JavascriptException,
                           self.marionette.execute_script,
                           """
 let prefs = Components.classes["@mozilla.org/preferences-service;1"]
                               .getService(Components.interfaces.nsIPrefBranch);
 """)
 
     def test_complex_return_values(self):
         self.assertEqual(self.marionette.execute_script("return [1, 2];"), [1, 2])
@@ -91,16 +93,17 @@ let prefs = Components.classes["@mozilla
         self.assertTrue(isinstance(result, float))
         self.assertEqual(result, expected_result)
 
     def test_null_argument(self):
         result = self.marionette.execute_script("return arguments[0]",
                                                 [None])
         self.assertIs(result, None)
 
+
 class TestExecuteChrome(TestExecuteContent):
     def setUp(self):
         super(TestExecuteChrome, self).setUp()
         self.win = self.marionette.current_window_handle
         self.marionette.set_context("chrome")
         self.marionette.execute_script(
             "window.open('chrome://marionette/content/test.xul', 'xul', 'chrome')")
         self.marionette.switch_to_window("xul")
@@ -116,8 +119,15 @@ class TestExecuteChrome(TestExecuteConte
         self.assertEqual(1, self.marionette.execute_script(
             "var c = Components.classes; return 1;"))
 
     def test_unmarshal_element_collection(self):
         expected = self.marionette.find_elements(By.TAG_NAME, "textbox")
         actual = self.marionette.execute_script(
             "return document.querySelectorAll('textbox')")
         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)