Bug 1107706: Part 7: Add timeout test for async scripts
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 26 Feb 2015 17:41:54 +0000
changeset 266312 853e7da581097725fa815a95bb92172ef6f5dcce
parent 266311 8b695334df946117685f9f942884c965c022c979
child 266313 4ef84ad178b563d452e5561b91e119705d987163
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [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)