Bug 1273654 - Extract a waitUntilApzStable helper function for tests. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 25 May 2016 10:00:07 -0400
changeset 370877 9fc02af795018131079ad0258061dac02c0a2cb3
parent 370876 8d050dbb52d7564f039fc6acc8b2bbc51b8a1d47
child 370878 3aa9ce0bab3484a0cbc1713b5cdefc3916519351
push id19168
push userkgupta@mozilla.com
push dateWed, 25 May 2016 14:24:41 +0000
reviewersbotond
bugs1273654
milestone49.0a1
Bug 1273654 - Extract a waitUntilApzStable helper function for tests. r?botond MozReview-Commit-ID: ArUbWuD74Y3
gfx/layers/apz/test/mochitest/apz_test_utils.js
gfx/layers/apz/test/mochitest/helper_basic_pan.html
gfx/layers/apz/test/mochitest/helper_bug1271432.html
gfx/layers/apz/test/mochitest/helper_click.html
gfx/layers/apz/test/mochitest/helper_div_pan.html
gfx/layers/apz/test/mochitest/helper_drag_click.html
gfx/layers/apz/test/mochitest/helper_iframe_pan.html
gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
gfx/layers/apz/test/mochitest/helper_scrollto_tap.html
gfx/layers/apz/test/mochitest/helper_tap.html
gfx/layers/apz/test/mochitest/test_bug1151667.html
gfx/layers/apz/test/mochitest/test_frame_reconstruction.html
--- a/gfx/layers/apz/test/mochitest/apz_test_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js
@@ -203,8 +203,18 @@ function runSubtestsSeriallyInFreshWindo
       } else {
         w = spawnTest(test.file);
       }
     }
 
     advanceSubtestExecution();
   });
 }
+
+function waitUntilApzStable() {
+  return new Promise(function(resolve, reject) {
+    SimpleTest.waitForFocus(function() {
+      waitForAllPaints(function() {
+        flushApzRepaints(resolve);
+      });
+    }, window);
+  });
+}
--- a/gfx/layers/apz/test/mochitest/helper_basic_pan.html
+++ b/gfx/layers/apz/test/mochitest/helper_basic_pan.html
@@ -22,21 +22,17 @@ function scrollPage() {
   dump("Finished native drag, waiting for transform-end observer...\n");
 }
 
 function checkScroll() {
   is(window.scrollY, 50, "check that the window scrolled");
   subtestDone();
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(scrollPage);
-  });
-}
+waitUntilApzStable().then(scrollPage);
 
   </script>
 </head>
 <body>
  <div style="height: 5000px; background-color: lightgreen;">
   This div makes the page scrollable.
  </div>
 </body>
--- a/gfx/layers/apz/test/mochitest/helper_bug1271432.html
+++ b/gfx/layers/apz/test/mochitest/helper_bug1271432.html
@@ -38,21 +38,18 @@ function driveTest() {
     gTestContinuation = runTest();
   }
   var ret = gTestContinuation.next();
   if (ret.done) {
     subtestDone();
   }
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(driveTest);
-  });
-}
+waitUntilApzStable().then(driveTest);
+
 </script>
 <style>
 a#with_after_content {
     background-color: #F16725;
     opacity: 0.8;
     display: inline-block;
     margin-top: 40px;
     margin-left: 40px;
--- a/gfx/layers/apz/test/mochitest/helper_click.html
+++ b/gfx/layers/apz/test/mochitest/helper_click.html
@@ -17,20 +17,16 @@ function clickButton() {
   });
 }
 
 function clicked(e) {
   is(e.target, document.getElementById('b'), "Clicked on button, yay! (at " + e.clientX + "," + e.clientY + ")");
   subtestDone();
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(clickButton);
-  });
-}
+waitUntilApzStable().then(clickButton);
 
   </script>
 </head>
 <body>
  <button id="b" style="width: 10px; height: 10px"></button>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/helper_div_pan.html
+++ b/gfx/layers/apz/test/mochitest/helper_div_pan.html
@@ -23,21 +23,17 @@ function scrollOuter() {
 }
 
 function checkScroll() {
   var outerScroll = document.getElementById('outer').scrollTop;
   is(outerScroll, 50, "check that the div scrolled");
   subtestDone();
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(scrollOuter);
-  });
-}
+waitUntilApzStable().then(scrollOuter);
 
   </script>
 </head>
 <body>
  <div id="outer" style="height: 250px; border: solid 1px black; overflow:scroll">
   <div style="height: 5000px; background-color: lightblue">
     This div makes the |outer| div scrollable.
   </div>
--- a/gfx/layers/apz/test/mochitest/helper_drag_click.html
+++ b/gfx/layers/apz/test/mochitest/helper_drag_click.html
@@ -34,20 +34,16 @@ var gTestContinuation = null;
 
 function driveTest() {
   if (!gTestContinuation) {
     gTestContinuation = runTest();
   }
   gTestContinuation.next();
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(driveTest);
-  });
-}
+waitUntilApzStable().then(driveTest);
 
   </script>
 </head>
 <body>
  <button id="b" style="width: 10px; height: 10px"></button>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/helper_iframe_pan.html
+++ b/gfx/layers/apz/test/mochitest/helper_iframe_pan.html
@@ -24,21 +24,17 @@ function scrollOuter() {
 }
 
 function checkScroll() {
   var outerScroll = document.getElementById('outer').contentWindow.scrollY;
   is(outerScroll, 50, "check that the iframe scrolled");
   subtestDone();
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(scrollOuter);
-  });
-}
+waitUntilApzStable().then(scrollOuter);
 
   </script>
 </head>
 <body>
  <iframe id="outer" style="height: 250px; border: solid 1px black" src="data:text/html,<body style='height:5000px'>"></iframe>
  <div style="height: 5000px; background-color: lightgreen;">
   This div makes the top-level page scrollable.
  </div>
--- a/gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
+++ b/gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
@@ -67,21 +67,18 @@ function driveTest() {
     gTestContinuation = runTest();
   }
   var ret = gTestContinuation.next();
   if (ret.done) {
     subtestDone();
   }
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(driveTest);
-  });
-}
+waitUntilApzStable().then(driveTest);
+
   </script>
 </head>
 <body style="height:5000px; margin:0">
   <div style="position:sticky; width: 100px; height: 300px; top: 0; background-color:red">sticky</div>
   <div style="position:fixed; width: 100px; height: 300px; top: 0; left: 200px; background-color: green">fixed</div>
   <iframe id='iframe' width="300" height="400" src="data:text/html,<body style='height:5000px; margin:0'><div style='position:sticky; width:100px; height:300px; top: 0; background-color:red'>sticky</div><div style='position:fixed; right:0; top: 0; width:100px; height:300px; background-color:green'>fixed</div>"></iframe>
 
   <div id="fpos_scrollable" style="position:fixed; width: 100px; height: 300px; top: 0; left: 400px; background-color: red; overflow:scroll">
--- a/gfx/layers/apz/test/mochitest/helper_scrollto_tap.html
+++ b/gfx/layers/apz/test/mochitest/helper_scrollto_tap.html
@@ -51,20 +51,17 @@ function clickButton() {
   });
 }
 
 function clicked(e) {
   is(e.target, document.getElementById('b'), "Clicked on button, yay! (at " + e.clientX + "," + e.clientY + ")");
   subtestDone();
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(startTest);
-  });
-}
+waitUntilApzStable().then(startTest);
+
   </script>
 </head>
 <body style="height: 5000px">
  <div style="height: 50px">spacer</div>
  <button id="b" style="width: 10px; height: 10px"></button>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/helper_tap.html
+++ b/gfx/layers/apz/test/mochitest/helper_tap.html
@@ -23,20 +23,16 @@ function clickButton() {
   });
 }
 
 function clicked(e) {
   is(e.target, document.getElementById('b'), "Clicked on button, yay! (at " + e.clientX + "," + e.clientY + ")");
   subtestDone();
 }
 
-window.onload = function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(clickButton);
-  });
-}
+waitUntilApzStable().then(clickButton);
 
   </script>
 </head>
 <body>
  <button id="b" style="width: 10px; height: 10px"></button>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_bug1151667.html
+++ b/gfx/layers/apz/test/mochitest/test_bug1151667.html
@@ -52,18 +52,14 @@ function startTest() {
 function continueTest() {
   var subframe = document.getElementById('subframe');
   is(subframe.scrollTop > 0, true, "We should have scrolled the subframe down");
   is(document.documentElement.scrollTop, 0, "We should not have scrolled the page");
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
-SimpleTest.waitForFocus(function() {
-  waitForAllPaints(function() {
-    flushApzRepaints(startTest);
-  })
-}, window);
+waitUntilApzStable().then(startTest);
 
 </script>
 </pre>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_frame_reconstruction.html
+++ b/gfx/layers/apz/test/mochitest/test_frame_reconstruction.html
@@ -218,14 +218,14 @@ function driveTest() {
 
 SimpleTest.waitForExplicitFinish();
 var apzEnabled = SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled;
 if (!apzEnabled) {
   ok(true, "APZ not enabled, skipping test");
   SimpleTest.finish();
 } else {
   SimpleTest.expectAssertions(0, 1); // this test triggers an assertion, see bug 1247050
-  SimpleTest.waitForFocus(driveTest, window);
+  waitUntilApzStable().then(driveTest);
 }
 
 </script>
 </body>
 </html>