Bug 1363829 P9 Make docshell chrome tests wait for next paint to avoid races. r=smaug
authorBen Kelly <ben@wanderview.com>
Wed, 31 May 2017 17:13:19 -0700
changeset 361745 a70379a2937c31f7fe612318498e49e5a18b5075
parent 361744 bd452eda2e83eea0cabb28259106a854d8dcf847
child 361746 cd8ae8487d00ef620b705980c77c8c793e0a8653
push id31940
push usercbook@mozilla.com
push dateThu, 01 Jun 2017 11:51:11 +0000
treeherdermozilla-central@0bcea6bac179 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1363829
milestone55.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 1363829 P9 Make docshell chrome tests wait for next paint to avoid races. r=smaug
docshell/test/chrome/bug360511_window.xul
docshell/test/chrome/docshell_helpers.js
--- a/docshell/test/chrome/bug360511_window.xul
+++ b/docshell/test/chrome/bug360511_window.xul
@@ -53,17 +53,17 @@
       
         // Click the on the fragment link in the browser, and use setTimeout 
         // to give the event a chance to be processed.
         var event = TestWindow.getDocument().createEvent('MouseEvent');
         event.initMouseEvent("click", true, true, TestWindow.getWindow(), 0,
           0, 0, 0, 0,
           false, false, false, false, 0, null);
         TestWindow.getDocument().getElementById("link1").dispatchEvent(event);
-        setTimeout(nextTest, 0);
+        waitForNextPaint(nextTest);
         yield undefined;
 
         // Store the fragment url for later comparison.
         var fragmentUrl = TestWindow.getBrowser().currentURI.spec;
         var fragDocLocation = TestWindow.getDocument().location.href;
         
         // Verify we're no longer at the top of the page.
         ok(TestWindow.getWindow().scrollY > 0,
--- a/docshell/test/chrome/docshell_helpers.js
+++ b/docshell/test/chrome/docshell_helpers.js
@@ -278,17 +278,17 @@ function pageEventListener(event) {
        "Should not get unexpected event " + event.type);
   }  
 
   // If no expected events were specified, mark the final event as having been 
   // triggered when a pageshow event is fired; this will allow 
   // doPageNavigation() to return.
   if ((typeof(gExpectedEvents) == "undefined") && event.type == "pageshow")
   {
-    setTimeout(function() { gFinalEvent = true; }, 0);
+    waitForNextPaint(function() { gFinalEvent = true; });
     return;
   }
   
   // If there are explicitly no expected events, but we receive one, it's an 
   // error.
   if (gExpectedEvents.length == 0) {
     ok(false, "Unexpected event (" + event.type + ") occurred");
     return;
@@ -327,17 +327,17 @@ function pageEventListener(event) {
   if ("hidden" in expected) {
     is(event.originalTarget.hidden, expected.hidden,
        "The hidden property of the document on page " +
        event.originalTarget.location + " had an unexpected value");
   }
 
   // If we're out of expected events, let doPageNavigation() return.
   if (gExpectedEvents.length == 0)
-    setTimeout(function() { gFinalEvent = true; }, 0);
+    waitForNextPaint(function() { gFinalEvent = true; });
 }
 
 /**
  * End a test.  
  */
 function finish() {
   // Work around bug 467960.
   var history = TestWindow.getBrowser().webNavigation.sessionHistory;
@@ -412,16 +412,20 @@ function waitForTrue(fn, onWaitComplete,
         if (timeoutHit || fn.call()) {
           // Stop calling the test function and notify the callback.
           clearInterval(intervalid);
           onWaitComplete.call();          
         } 
       }, 20);
 }
 
+function waitForNextPaint(cb) {
+  requestAnimationFrame(_ => requestAnimationFrame(cb));
+}
+
 /**
  * Enable or disable the bfcache.
  *
  * Parameters:
  *
  *   enable: if true, set max_total_viewers to -1 (the default); if false, set 
  *           to 0 (disabled), if a number, set it to that specific number
  */