Bug 1320629 - Increase timeout of test_window_set_timeout_is_not_cancelled; r=whimboo
☠☠ backed out by e27495348664 ☠ ☠
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 28 Nov 2016 11:11:31 +0000
changeset 369808 d2c1a3a02f40e4018338678889a6a66a4b6ba86f
parent 369807 601cde18dfb4dfa8034dd4ad470144b559b80453
child 369809 7ba1a4d296a14a632b85ad0a4146478c9b46c116
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhimboo
bugs1320629
milestone53.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 1320629 - Increase timeout of test_window_set_timeout_is_not_cancelled; r=whimboo As debug builds are inherently slow, we need to increase the wait time before triggering the `setTimeout` callback so that the next `marionette.execute_script` statement has time to run. MozReview-Commit-ID: IAgicNAmVA6
testing/marionette/harness/marionette/tests/unit/test_execute_script.py
--- a/testing/marionette/harness/marionette/tests/unit/test_execute_script.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_execute_script.py
@@ -1,19 +1,21 @@
 # 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 os
 import time
 import urllib
 
-from marionette import MarionetteTestCase, WindowManagerMixin
 from marionette_driver import By, errors
 from marionette_driver.marionette import HTMLElement
+from marionette_driver.wait import Wait
+
+from marionette import MarionetteTestCase, WindowManagerMixin
 
 
 def inline(doc):
     return "data:text/html;charset=utf-8,{}".format(urllib.quote(doc))
 
 
 elements = inline("<p>foo</p> <p>bar</p>")
 
@@ -234,37 +236,37 @@ class TestExecuteContent(MarionetteTestC
         self.assertTrue(
             send("return typeof window.wrappedJSObject == 'undefined'"))
 
     def test_no_callback(self):
         self.assertTrue(self.marionette.execute_script(
             "return typeof arguments[0] == 'undefined'"))
 
     def test_window_set_timeout_is_not_cancelled(self):
+        def content_timeout_triggered(mn):
+            return mn.execute_script("return window.n", sandbox=None) > 0
+
+        # subsequent call to execute_script after this
+        # should not cancel the setTimeout event
         self.marionette.navigate(inline("""
             <script>
-            window.contentTimeoutTriggered = 0;
-            window.contentTimeoutID = setTimeout(
-                () => window.contentTimeoutTriggered++, 1000);
+            window.n = 0;
+            setTimeout(() => ++window.n, 4000);
             </script>"""))
 
-        # first execute script call should not cancel event
+        # as debug builds are inherently slow,
+        # we need to assert the event did not already fire
         self.assertEqual(0, self.marionette.execute_script(
-            "return window.contentTimeoutTriggered", sandbox=None))
+            "return window.n", sandbox=None),
+            "setTimeout already fired")
 
-        # test that event was not cancelled
-        time.sleep(1)
-        self.assertEqual(1, self.marionette.execute_script(
-            "return window.contentTimeoutTriggered", sandbox=None))
-
-        # ../../../../evaluate.js:/scriptTimeoutID/
-        # sets the script timeout handler using the content frame script
-        # so the in-content setTimeout should always return 2
-        self.assertEqual(2, self.marionette.execute_script(
-            "return window.contentTimeoutID", sandbox=None))
+        # if event was cancelled, this will time out
+        Wait(self.marionette).until(content_timeout_triggered,
+                                    timeout=8,
+                                    message="Scheduled setTimeout event was cancelled by call to execute_script")
 
 
 class TestExecuteChrome(WindowManagerMixin, TestExecuteContent):
 
     def setUp(self):
         super(TestExecuteChrome, self).setUp()
 
         self.marionette.set_context("chrome")