Bug 1316622 - Move Marionette unit tests to new timeouts API; r=automatedtester,whimboo
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 10 Nov 2016 21:03:21 +0000
changeset 323984 97f78abeb92c70190d1f0947b271bf9bb67d7dbe
parent 323983 3aedb0ff7fe74226e421065ad31511ad3ace4c23
child 323985 e3acbc950e1ca302f02a1ac058ff633e0c5a1d5a
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersautomatedtester, whimboo
bugs1316622
milestone53.0a1
Bug 1316622 - Move Marionette unit tests to new timeouts API; r=automatedtester,whimboo MozReview-Commit-ID: D6AmUsqMHQv
testing/marionette/harness/marionette/marionette_test/testcases.py
testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
testing/marionette/harness/marionette/tests/unit/test_element_retrieval.py
testing/marionette/harness/marionette/tests/unit/test_execute_async_script.py
testing/marionette/harness/marionette/tests/unit/test_execute_isolate.py
testing/marionette/harness/marionette/tests/unit/test_findelement_chrome.py
testing/marionette/harness/marionette/tests/unit/test_implicit_waits.py
testing/marionette/harness/marionette/tests/unit/test_navigation.py
testing/marionette/harness/marionette/tests/unit/test_simpletest_sanity.py
--- a/testing/marionette/harness/marionette/marionette_test/testcases.py
+++ b/testing/marionette/harness/marionette/marionette_test/testcases.py
@@ -349,18 +349,18 @@ if (!testUtils.hasOwnProperty("specialPo
 
         marionette.set_context(context)
 
         if context != 'chrome':
             marionette.navigate('data:text/html,<html>test page</html>')
 
         timeout = JSTest.timeout_re.search(js)
         if timeout:
-            timeout = timeout.group(3)
-            marionette.set_script_timeout(int(timeout))
+            ms = timeout.group(3)
+            marionette.timeout.script = int(ms) / 1000.0
 
         inactivity_timeout = JSTest.inactivity_timeout_re.search(js)
         if inactivity_timeout:
             inactivity_timeout = int(inactivity_timeout.group(3))
 
         try:
             results = marionette.execute_js_script(
                 js,
--- a/testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
+++ b/testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
@@ -42,17 +42,17 @@ def move_element_offset(marionette, wait
     action.press(ele).move_by_offset(0,150).move_by_offset(0, 150).release()
     action.perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
     wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button2').innerHTML;")
 
 def chain(marionette, wait_for_condition, expected1, expected2):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    marionette.set_search_timeout(15000)
+    marionette.timeout.implicit = 15
     action = Actions(marionette)
     button1 = marionette.find_element(By.ID, "button1")
     action.press(button1).perform()
     button2 = marionette.find_element(By.ID, "delayed")
     wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
     action.move(button2).release().perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('delayed').innerHTML;")
 
--- a/testing/marionette/harness/marionette/tests/unit/test_element_retrieval.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_element_retrieval.py
@@ -42,17 +42,17 @@ name_xhtml = inline('<p name="foo"></p>'
 link_html = inline("<p><a href=#>foo bar</a>", doctype="html")
 link_html_with_trailing_space = inline("<p><a href=#>a link with a trailing space </a>")
 link_xhtml = inline('<p><a href="#">foo bar</a></p>', doctype="xhtml")
 
 
 class TestFindElementHTML(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
-        self.marionette.set_search_timeout(0)
+        self.marionette.timeout.implicit = 0
 
     def test_id(self):
         self.marionette.navigate(id_html)
         expected = self.marionette.execute_script("return document.querySelector('p')")
         found = self.marionette.find_element(By.ID, "foo")
         self.assertIsInstance(found, HTMLElement)
         self.assertEqual(expected, found)
 
@@ -121,52 +121,52 @@ class TestFindElementHTML(MarionetteTest
     def test_xpath(self):
         self.marionette.navigate(id_html)
         el = self.marionette.execute_script("return document.querySelector('#foo')")
         found = self.marionette.find_element(By.XPATH, "id('foo')")
         self.assertIsInstance(found, HTMLElement)
         self.assertEqual(el, found)
 
     def test_not_found(self):
-        self.marionette.set_search_timeout(0)
+        self.marionette.timeout.implicit = 0
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CLASS_NAME, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CSS_SELECTOR, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.LINK_TEXT, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.NAME, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.PARTIAL_LINK_TEXT, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.TAG_NAME, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.XPATH, "cheese")
 
     def test_not_found_implicit_wait(self):
-        self.marionette.set_search_timeout(50)
+        self.marionette.timeout.implicit = 0.5
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CLASS_NAME, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CSS_SELECTOR, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.LINK_TEXT, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.NAME, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.PARTIAL_LINK_TEXT, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.TAG_NAME, "cheese")
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.XPATH, "cheese")
 
     def test_not_found_from_element(self):
-        self.marionette.set_search_timeout(0)
+        self.marionette.timeout.implicit = 0
         self.marionette.navigate(id_html)
         el = self.marionette.find_element(By.ID, "foo")
         self.assertRaises(NoSuchElementException, el.find_element, By.CLASS_NAME, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.CSS_SELECTOR, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.ID, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.LINK_TEXT, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.NAME, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.PARTIAL_LINK_TEXT, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.TAG_NAME, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.XPATH, "cheese")
 
     def test_not_found_implicit_wait_from_element(self):
-        self.marionette.set_search_timeout(50)
+        self.marionette.timeout.implicit = 0.5
         self.marionette.navigate(id_html)
         el = self.marionette.find_element(By.ID, "foo")
         self.assertRaises(NoSuchElementException, el.find_element, By.CLASS_NAME, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.CSS_SELECTOR, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.ID, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.LINK_TEXT, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.NAME, "cheese")
         self.assertRaises(NoSuchElementException, el.find_element, By.PARTIAL_LINK_TEXT, "cheese")
@@ -210,17 +210,17 @@ class TestFindElementHTML(MarionetteTest
         self.marionette.navigate(id_html)
         active = self.marionette.execute_script("return document.activeElement")
         self.assertEqual(active, self.marionette.get_active_element())
 
 
 class TestFindElementXHTML(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
-        self.marionette.set_search_timeout(0)
+        self.marionette.timeout.implicit = 0
 
     def test_id(self):
         self.marionette.navigate(id_xhtml)
         expected = self.marionette.execute_script("return document.querySelector('p')")
         found = self.marionette.find_element(By.ID, "foo")
         self.assertIsInstance(found, HTMLElement)
         self.assertEqual(expected, found)
 
@@ -293,17 +293,17 @@ class TestFindElementXHTML(MarionetteTes
         self.marionette.navigate(id_xhtml)
         active = self.marionette.execute_script("return document.activeElement")
         self.assertEqual(active, self.marionette.get_active_element())
 
 
 class TestFindElementsHTML(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
-        self.marionette.set_search_timeout(0)
+        self.marionette.timeout.implicit = 0
 
     def assertItemsIsInstance(self, items, typ):
         for item in items:
             self.assertIsInstance(item, typ)
 
     def test_child_elements(self):
         self.marionette.navigate(children_html)
         parent = self.marionette.find_element(By.TAG_NAME, "div")
@@ -405,17 +405,17 @@ class TestFindElementsHTML(MarionetteTes
         with self.assertRaises(InvalidSelectorException):
             parent = self.marionette.execute_script("return document.documentElement")
             parent.find_elements(By.CSS_SELECTOR, "")
 
 
 class TestFindElementsXHTML(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
-        self.marionette.set_search_timeout(0)
+        self.marionette.timeout.implicit = 0
 
     def assertItemsIsInstance(self, items, typ):
         for item in items:
             self.assertIsInstance(item, typ)
 
     def test_child_elements(self):
         self.marionette.navigate(children_xhtml)
         parent = self.marionette.find_element(By.TAG_NAME, "div")
--- a/testing/marionette/harness/marionette/tests/unit/test_execute_async_script.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_execute_async_script.py
@@ -6,40 +6,40 @@ from marionette import MarionetteTestCas
 from marionette_driver.errors import ( JavascriptException,
                                        MarionetteException,
                                        ScriptTimeoutException )
 
 
 class TestExecuteAsyncContent(MarionetteTestCase):
     def setUp(self):
         super(TestExecuteAsyncContent, self).setUp()
-        self.marionette.set_script_timeout(1000)
+        self.marionette.timeout.script = 1
 
     def test_execute_async_simple(self):
         self.assertEqual(1, self.marionette.execute_async_script("arguments[arguments.length-1](1);"))
 
     def test_execute_async_ours(self):
         self.assertEqual(1, self.marionette.execute_async_script("marionetteScriptFinished(1);"))
 
     def test_execute_async_timeout(self):
         self.assertRaises(ScriptTimeoutException, self.marionette.execute_async_script, "var x = 1;")
 
     def test_execute_async_unique_timeout(self):
         self.assertEqual(2, self.marionette.execute_async_script("setTimeout(function() {marionetteScriptFinished(2);}, 2000);", script_timeout=5000))
         self.assertRaises(ScriptTimeoutException, self.marionette.execute_async_script, "setTimeout(function() {marionetteScriptFinished(3);}, 2000);")
 
     def test_no_timeout(self):
-        self.marionette.set_script_timeout(10000)
+        self.marionette.timeout.script = 10
         self.assertTrue(self.marionette.execute_async_script("""
             var callback = arguments[arguments.length - 1];
             setTimeout(function() { callback(true); }, 500);
             """))
 
     def test_execute_async_unload(self):
-        self.marionette.set_script_timeout(5000)
+        self.marionette.timeout.script = 5
         unload = """
                 window.location.href = "about:blank";
                  """
         self.assertRaises(JavascriptException, self.marionette.execute_async_script, unload)
 
     def test_check_window(self):
         self.assertTrue(self.marionette.execute_async_script("marionetteScriptFinished(window !=null && window != undefined);"))
 
@@ -136,17 +136,17 @@ class TestExecuteAsyncChrome(TestExecute
     def test_execute_permission(self):
         self.assertEqual(5, self.marionette.execute_async_script("""
 var c = Components.classes;
 marionetteScriptFinished(5);
 """))
 
     def test_execute_async_js_exception(self):
         # Javascript exceptions are not propagated in chrome code
-        self.marionette.set_script_timeout(200)
+        self.marionette.timeout.script = 0.2
         self.assertRaises(ScriptTimeoutException,
             self.marionette.execute_async_script, """
             var callback = arguments[arguments.length - 1];
             setTimeout("callback(foo())", 50);
             """)
         self.assertRaises(JavascriptException,
             self.marionette.execute_async_script, """
             var callback = arguments[arguments.length - 1];
--- a/testing/marionette/harness/marionette/tests/unit/test_execute_isolate.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_execute_isolate.py
@@ -10,23 +10,23 @@ class TestExecuteIsolationContent(Marion
     def setUp(self):
         super(TestExecuteIsolationContent, self).setUp()
         self.content = True
 
     def test_execute_async_isolate(self):
         # Results from one execute call that has timed out should not
         # contaminate a future call.
         multiplier = "*3" if self.content else "*1"
-        self.marionette.set_script_timeout(500)
+        self.marionette.timeout.script = 0.5
         self.assertRaises(ScriptTimeoutException,
                           self.marionette.execute_async_script,
                           ("setTimeout(function() {{ marionetteScriptFinished(5{}); }}, 3000);"
                               .format(multiplier)))
 
-        self.marionette.set_script_timeout(6000)
+        self.marionette.timeout.script = 6
         result = self.marionette.execute_async_script("""
         setTimeout(function() {{ marionetteScriptFinished(10{}); }}, 5000);
         """.format(multiplier))
         self.assertEqual(result, 30 if self.content else 10)
 
 class TestExecuteIsolationChrome(TestExecuteIsolationContent):
     def setUp(self):
         super(TestExecuteIsolationChrome, self).setUp()
--- a/testing/marionette/harness/marionette/tests/unit/test_findelement_chrome.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_findelement_chrome.py
@@ -63,19 +63,19 @@ class TestElementsChrome(MarionetteTestC
 
     def test_xpath(self):
         el = self.marionette.execute_script("return window.document.getElementById('testBox');")
         found_el = self.marionette.find_element(By.XPATH, "id('testBox')")
         self.assertEqual(HTMLElement, type(found_el))
         self.assertEqual(el, found_el)
 
     def test_not_found(self):
-        self.marionette.set_search_timeout(1000)
+        self.marionette.timeout.implicit = 1
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
-        self.marionette.set_search_timeout(0)
+        self.marionette.timeout.implicit = 0
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
 
     def test_timeout(self):
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "myid")
-        self.assertTrue(True, self.marionette.set_search_timeout(4000))
+        self.marionette.timeout.implicit = 4
         self.marionette.execute_script("window.setTimeout(function() {var b = window.document.createElement('button'); b.id = 'myid'; document.getElementById('things').appendChild(b);}, 1000)")
         self.assertEqual(HTMLElement, type(self.marionette.find_element(By.ID, "myid")))
         self.marionette.execute_script("window.document.getElementById('things').removeChild(window.document.getElementById('myid'));")
--- a/testing/marionette/harness/marionette/tests/unit/test_implicit_waits.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_implicit_waits.py
@@ -3,28 +3,23 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.errors import NoSuchElementException
 from marionette_driver.by import By
 
 
 class TestImplicitWaits(MarionetteTestCase):
-    def testShouldImplicitlyWaitForASingleElement(self):
+    def test_implicitly_wait_for_single_element(self):
         test_html = self.marionette.absolute_url("test_dynamic.html")
         self.marionette.navigate(test_html)
         add = self.marionette.find_element(By.ID, "adder")
-        self.marionette.set_search_timeout(30000)
+        self.marionette.timeout.implicit = 30
         add.click()
-        # All is well if this doesnt throw
+        # all is well if this does not throw
         self.marionette.find_element(By.ID, "box0")
 
-    def testShouldStillFailToFindAnElementWhenImplicitWaitsAreEnabled(self):
+    def test_implicit_wait_reaches_timeout(self):
         test_html = self.marionette.absolute_url("test_dynamic.html")
         self.marionette.navigate(test_html)
-        self.marionette.set_search_timeout(3000)
-        try:
+        self.marionette.timeout.implicit = 3
+        with self.assertRaises(NoSuchElementException):
             self.marionette.find_element(By.ID, "box0")
-            self.fail("Should have thrown a a NoSuchElementException")
-        except NoSuchElementException:
-            pass
-        except Exception:
-            self.fail("Should have thrown a NoSuchElementException")
--- a/testing/marionette/harness/marionette/tests/unit/test_navigation.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_navigation.py
@@ -119,17 +119,17 @@ class TestNavigate(MarionetteTestCase):
     def test_find_element_state_complete(self):
         self.marionette.navigate(self.test_doc)
         state = self.marionette.execute_script("return window.document.readyState")
         self.assertEqual("complete", state)
         self.assertTrue(self.marionette.find_element(By.ID, "mozLink"))
 
     def test_error_when_exceeding_page_load_timeout(self):
         with self.assertRaises(TimeoutException):
-            self.marionette.set_page_load_timeout(0)
+            self.marionette.timeout.page_load = 0
             self.marionette.navigate(self.marionette.absolute_url("slow"))
             self.marionette.find_element(By.TAG_NAME, "p")
 
     def test_navigate_iframe(self):
         self.marionette.navigate(self.iframe_doc)
         self.assertTrue('test_iframe.html' in self.marionette.get_url())
         self.assertTrue(self.marionette.find_element(By.ID, "test_iframe"))
 
--- a/testing/marionette/harness/marionette/tests/unit/test_simpletest_sanity.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_simpletest_sanity.py
@@ -20,17 +20,17 @@ class SimpletestSanityTest(MarionetteTes
             sentPass1 = "is(true, true, 'isTest3');" + self.callFinish
             sentPass2 = "is(true, true, 'isTest4');" + self.callFinish
 
             self.assertEqual(1, len(self.run_sync(sentFail1)["failures"]))
             self.assertEqual(0, self.run_sync(sentFail2)["passed"])
             self.assertEqual(1, self.run_sync(sentPass1)["passed"])
             self.assertEqual(0, len(self.run_sync(sentPass2)["failures"]))
 
-            self.marionette.set_script_timeout(1000)
+            self.marionette.timeout.script = 1
             self.assertEqual(1, len(self.run_async(sentFail1)["failures"]))
             self.assertEqual(0, self.run_async(sentFail2)["passed"])
             self.assertEqual(1, self.run_async(sentPass1)["passed"])
             self.assertEqual(0, len(self.run_async(sentPass2)["failures"]))
 
         self.marionette.set_context("content")
         runtests()
         self.marionette.set_context("chrome")
@@ -43,17 +43,17 @@ class SimpletestSanityTest(MarionetteTes
            sentPass1 = "isnot(true, false, 'isnotTest1');" + self.callFinish
            sentPass2 = "isnot(true, false, 'isnotTest2');" + self.callFinish
 
            self.assertEqual(1, len(self.run_sync(sentFail1)["failures"]));
            self.assertEqual(0, self.run_sync(sentFail2)["passed"]);
            self.assertEqual(0, len(self.run_sync(sentPass1)["failures"]));
            self.assertEqual(1, self.run_sync(sentPass2)["passed"]);
 
-           self.marionette.set_script_timeout(1000)
+           self.marionette.timeout.script = 1
            self.assertEqual(1, len(self.run_async(sentFail1)["failures"]));
            self.assertEqual(0, self.run_async(sentFail2)["passed"]);
            self.assertEqual(0, len(self.run_async(sentPass1)["failures"]));
            self.assertEqual(1, self.run_async(sentPass2)["passed"]);
 
         self.marionette.set_context("content")
         runtests()
         self.marionette.set_context("chrome")
@@ -66,17 +66,17 @@ class SimpletestSanityTest(MarionetteTes
             sentPass1 = "ok(1==1, 'testOk3');" + self.callFinish
             sentPass2 = "ok(1==1, 'testOk4');" + self.callFinish
 
             self.assertEqual(1, len(self.run_sync(sentFail1)["failures"]));
             self.assertEqual(0, self.run_sync(sentFail2)["passed"]);
             self.assertEqual(0, len(self.run_sync(sentPass1)["failures"]));
             self.assertEqual(1, self.run_sync(sentPass2)["passed"]);
 
-            self.marionette.set_script_timeout(1000)
+            self.marionette.timeout.script = 1
             self.assertEqual(1, len(self.run_async(sentFail1)["failures"]));
             self.assertEqual(0, self.run_async(sentFail2)["passed"]);
             self.assertEqual(0, len(self.run_async(sentPass1)["failures"]));
             self.assertEqual(1, self.run_async(sentPass2)["passed"]);
 
         self.marionette.set_context("content")
         runtests()
         self.marionette.set_context("chrome")
@@ -89,17 +89,17 @@ class SimpletestSanityTest(MarionetteTes
             sentPass1 = "todo(1==2, 'testTodo3');" + self.callFinish
             sentPass2 = "todo(1==2, 'testTodo4');" + self.callFinish
 
             self.assertEqual(1, len(self.run_sync(sentFail1)["unexpectedSuccesses"]));
             self.assertEqual(0, len(self.run_sync(sentFail2)["expectedFailures"]));
             self.assertEqual(0, len(self.run_sync(sentPass1)["unexpectedSuccesses"]));
             self.assertEqual(1, len(self.run_sync(sentPass2)["expectedFailures"]));
 
-            self.marionette.set_script_timeout(1000)
+            self.marionette.timeout.script = 1
             self.assertEqual(1, len(self.run_async(sentFail1)["unexpectedSuccesses"]));
             self.assertEqual(0, len(self.run_async(sentFail2)["expectedFailures"]));
             self.assertEqual(0, len(self.run_async(sentPass1)["unexpectedSuccesses"]));
             self.assertEqual(1, len(self.run_async(sentPass2)["expectedFailures"]));
 
         self.marionette.set_context("content")
         runtests()
         self.marionette.set_context("chrome")