Bug 1107706: Part 7: Add timeout test for async scripts

This commit is contained in:
Andreas Tolfsen 2015-02-26 17:41:54 +00:00
parent 8b1e3107f2
commit 13f8a26edc

View File

@ -4,15 +4,17 @@
import urllib import urllib
from marionette_driver.by import By from marionette_driver import By, errors
from marionette_driver.errors import JavascriptException
from marionette import MarionetteTestCase from marionette import MarionetteTestCase
def inline(doc): def inline(doc):
return "data:text/html;charset=utf-8,%s" % urllib.quote(doc) return "data:text/html;charset=utf-8,%s" % urllib.quote(doc)
elements = inline("<p>foo</p> <p>bar</p>") elements = inline("<p>foo</p> <p>bar</p>")
class TestExecuteContent(MarionetteTestCase): class TestExecuteContent(MarionetteTestCase):
def test_stack_trace(self): def test_stack_trace(self):
try: try:
@ -21,7 +23,7 @@ class TestExecuteContent(MarionetteTestCase):
return b; return b;
""") """)
self.assertFalse(True) self.assertFalse(True)
except JavascriptException, inst: except errors.JavascriptException as inst:
self.assertTrue('return b' in inst.stacktrace) self.assertTrue('return b' in inst.stacktrace)
def test_execute_simple(self): def test_execute_simple(self):
@ -34,11 +36,11 @@ class TestExecuteContent(MarionetteTestCase):
self.assertEqual(self.marionette.execute_script("1;"), None) self.assertEqual(self.marionette.execute_script("1;"), None)
def test_execute_js_exception(self): def test_execute_js_exception(self):
self.assertRaises(JavascriptException, self.assertRaises(errors.JavascriptException,
self.marionette.execute_script, "return foo(bar);") self.marionette.execute_script, "return foo(bar);")
def test_execute_permission(self): def test_execute_permission(self):
self.assertRaises(JavascriptException, self.assertRaises(errors.JavascriptException,
self.marionette.execute_script, self.marionette.execute_script,
""" """
let prefs = Components.classes["@mozilla.org/preferences-service;1"] let prefs = Components.classes["@mozilla.org/preferences-service;1"]
@ -96,6 +98,7 @@ let prefs = Components.classes["@mozilla.org/preferences-service;1"]
[None]) [None])
self.assertIs(result, None) self.assertIs(result, None)
class TestExecuteChrome(TestExecuteContent): class TestExecuteChrome(TestExecuteContent):
def setUp(self): def setUp(self):
super(TestExecuteChrome, self).setUp() super(TestExecuteChrome, self).setUp()
@ -121,3 +124,10 @@ class TestExecuteChrome(TestExecuteContent):
actual = self.marionette.execute_script( actual = self.marionette.execute_script(
"return document.querySelectorAll('textbox')") "return document.querySelectorAll('textbox')")
self.assertEqual(expected, actual) 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)