Bug 1273654 - Extract a pushPrefs helper function to simplify test setup. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 25 May 2016 15:31:52 -0400
changeset 338018 dcb15e7ac2e212df7e200e6256eced56e149422f
parent 338017 f40e481b93488d8868ae01ae4c5f35a832d2b414
child 338019 90341d286f4dcff8ab6d8bc21d5d888bc3bab328
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1273654
milestone49.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 1273654 - Extract a pushPrefs helper function to simplify test setup. r=botond The set of changes in this patch removes all waitForFocus calls in the test folder, except for the one in apz_test_utils.js. This results in less boilerplate and more consistent test state initialization. MozReview-Commit-ID: IYlTKDx7Xx2
gfx/layers/apz/test/mochitest/apz_test_utils.js
gfx/layers/apz/test/mochitest/test_layerization.html
gfx/layers/apz/test/mochitest/test_scroll_inactive_bug1190112.html
gfx/layers/apz/test/mochitest/test_scroll_inactive_flattened_frame.html
gfx/layers/apz/test/mochitest/test_scroll_subframe_scrollbar.html
gfx/layers/apz/test/mochitest/test_wheel_scroll.html
gfx/layers/apz/test/mochitest/test_wheel_transactions.html
--- a/gfx/layers/apz/test/mochitest/apz_test_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js
@@ -204,16 +204,20 @@ function runSubtestsSeriallyInFreshWindo
         w = spawnTest(test.file);
       }
     }
 
     advanceSubtestExecution();
   });
 }
 
+function pushPrefs(prefs) {
+  return SpecialPowers.pushPrefEnv({'set': prefs});
+}
+
 function waitUntilApzStable() {
   return new Promise(function(resolve, reject) {
     SimpleTest.waitForFocus(function() {
       waitForAllPaints(function() {
         flushApzRepaints(resolve);
       });
     }, window);
   });
--- a/gfx/layers/apz/test/mochitest/test_layerization.html
+++ b/gfx/layers/apz/test/mochitest/test_layerization.html
@@ -224,32 +224,30 @@ function startTest() {
   // This test requires APZ - if it's not enabled, skip it.
   var apzEnabled = SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled;
   if (!apzEnabled) {
     ok(true, "APZ not enabled, skipping test");
     SimpleTest.finish();
     return;
   }
 
-  waitForAllPaints(function() {
-    flushApzRepaints(driveTest);
-  })
+  driveTest();
 }
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestFlakyTimeout("we are testing code that measures an actual timeout");
 SimpleTest.expectAssertions(0, 8); // we get a bunch of "ASSERTION: Bounds computation mismatch" sometimes (bug 1232856)
 
 // Disable smooth scrolling, because it results in long-running scroll
 // animations that can result in a 'scroll' event triggered by an earlier
 // wheel event as corresponding to a later wheel event.
 // Also enable APZ test logging, since we use that data to determine whether
 // a scroll frame was layerized.
-SpecialPowers.pushPrefEnv({"set": [["general.smoothScroll", false],
-                                   ["apz.displayport_expiry_ms", 0],
-                                   ["apz.test.logging_enabled", true]]},
-                          function() {
-                            SimpleTest.waitForFocus(startTest, window);
-                          });
+pushPrefs([["general.smoothScroll", false],
+           ["apz.displayport_expiry_ms", 0],
+           ["apz.test.logging_enabled", true]])
+.then(waitUntilApzStable)
+.then(startTest);
+
 </script>
 </pre>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_scroll_inactive_bug1190112.html
+++ b/gfx/layers/apz/test/mochitest/test_scroll_inactive_bug1190112.html
@@ -1,15 +1,16 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test scrolling flattened inactive frames</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
+  <script type="application/javascript" src="apz_test_utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 <style>
 p {
   width:200px;
   height:200px;
   border:solid 1px black;
   overflow:auto;
 }
@@ -521,23 +522,20 @@ function doInnerScrollAgain(subframe, ol
   sendWheelAndPaint(subframe, 10, 10, DefaultEvent, function () {
     var newpos = new ScrollTops();
     ok(oldpos.outerScrollTop == newpos.outerScrollTop, "viewport should not have scrolled");
     ok(oldpos.innerScrollTop != newpos.innerScrollTop, "subframe should have scrolled");
     SimpleTest.finish();
   });
 }
 
-window.onload = function() {
-  SpecialPowers.pushPrefEnv({
-    'set': [['general.smoothScroll', false],
-            ['mousewheel.transaction.timeout', 0],
-            ['mousewheel.transaction.ignoremovedelay', 0]]
-  }, function () {
-    SimpleTest.waitForFocus(test);
-  });
-}
-
 SimpleTest.testInChaosMode();
 SimpleTest.waitForExplicitFinish();
+
+pushPrefs([['general.smoothScroll', false],
+           ['mousewheel.transaction.timeout', 0],
+           ['mousewheel.transaction.ignoremovedelay', 0]])
+.then(waitUntilApzStable)
+.then(test);
+
 </script>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_scroll_inactive_flattened_frame.html
+++ b/gfx/layers/apz/test/mochitest/test_scroll_inactive_flattened_frame.html
@@ -31,28 +31,19 @@ function test() {
   };
   sendWheelAndPaint(inner, 20, 30, event, function () {
     ok(container.scrollTop == containerScrollTop, "container scrollframe should not have scrolled");
     ok(outer.scrollTop > outerScrollTop, "nested scrollframe should have scrolled");
     SimpleTest.finish();
   });
 }
 
-function startTest() {
-  waitForAllPaints(function() {
-    flushApzRepaints(test);
-  });
-}
-
-window.onload = function() {
-  SpecialPowers.pushPrefEnv({
-    'set': [['general.smoothScroll', false],
-            ['mousewheel.transaction.timeout', 1000000]],
-  }, function () {
-    SimpleTest.waitForFocus(startTest);
-  });
-}
-
 SimpleTest.testInChaosMode();
 SimpleTest.waitForExplicitFinish();
+
+pushPrefs([['general.smoothScroll', false],
+           ['mousewheel.transaction.timeout', 1000000]])
+.then(waitUntilApzStable)
+.then(test);
+
 </script>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_scroll_subframe_scrollbar.html
+++ b/gfx/layers/apz/test/mochitest/test_scroll_subframe_scrollbar.html
@@ -99,28 +99,19 @@ function testScrolling(subframe) {
   var oldScrollTop = subframe.scrollTop;
 
   sendWheelAndPaint(subframe, posX, posY, DefaultEvent, function () {
     ok(subframe.scrollTop > oldScrollTop, "subframe should have scrolled");
     SimpleTest.finish();
   });
 }
 
-function startTest() {
-  waitForAllPaints(function() {
-    flushApzRepaints(test);
-  });
-}
+SimpleTest.waitForExplicitFinish();
 
-window.onload = function() {
-  SpecialPowers.pushPrefEnv({
-    'set': [['general.smoothScroll', false],
-            ['mousewheel.transaction.timeout', 0],
-            ['mousewheel.transaction.ignoremovedelay', 0]]
-  }, function () {
-    SimpleTest.waitForFocus(startTest);
-  });
-}
+pushPrefs([['general.smoothScroll', false],
+           ['mousewheel.transaction.timeout', 0],
+           ['mousewheel.transaction.ignoremovedelay', 0]])
+.then(waitUntilApzStable)
+.then(test);
 
-SimpleTest.waitForExplicitFinish();
 </script>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_wheel_scroll.html
+++ b/gfx/layers/apz/test/mochitest/test_wheel_scroll.html
@@ -1,17 +1,19 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=1013412
 -->
 <head>
   <title>Test for Bug 1013412</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
+  <script type="application/javascript" src="apz_test_utils.js"></script>
   <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <style>
   #content {
     height: 800px;
     overflow: scroll;
   }
 
@@ -94,24 +96,23 @@ function continueTest() {
   var ret = gTestContinuation.next();
   if (ret.done) {
     SimpleTest.finish();
   } else {
     is(ret.value, true, "Wheel event successfully synthesized");
   }
 }
 
-function startTest() {
-  // If we allow smooth scrolling the "smooth" scrolling may cause the page to
-  // glide past the scrollbox (which is supposed to stop the scrolling) and so
-  // we might end up at the bottom of the page.
-  SpecialPowers.pushPrefEnv({"set": [["general.smoothScroll", false]]}, continueTest);
-}
-
 SimpleTest.testInChaosMode();
 SimpleTest.waitForExplicitFinish();
-SimpleTest.waitForFocus(startTest, window);
+
+// If we allow smooth scrolling the "smooth" scrolling may cause the page to
+// glide past the scrollbox (which is supposed to stop the scrolling) and so
+// we might end up at the bottom of the page.
+pushPrefs([["general.smoothScroll", false]])
+.then(waitUntilApzStable)
+.then(continueTest);
 
 </script>
 </pre>
 
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_wheel_transactions.html
+++ b/gfx/layers/apz/test/mochitest/test_wheel_transactions.html
@@ -127,28 +127,21 @@ function driveTest() {
     gTestContinuation = runTest();
   }
   var ret = gTestContinuation.next();
   if (ret.done) {
     SimpleTest.finish();
   }
 }
 
-function startTest() {
-  waitForAllPaints(function() {
-    flushApzRepaints(driveTest);
-  });
-}
+SimpleTest.waitForExplicitFinish();
 
 // Disable smooth scrolling because it makes the test flaky (we don't have a good
 // way of detecting when the scrolling is finished).
-SpecialPowers.pushPrefEnv({"set": [["general.smoothScroll", false]]},
-                          function() {
-                            SimpleTest.waitForFocus(startTest, window);
-                          });
-
-SimpleTest.waitForExplicitFinish();
+pushPrefs([["general.smoothScroll", false]])
+.then(waitUntilApzStable)
+.then(driveTest);
 
 </script>
 </pre>
 
 </body>
 </html>