Bug 1273654 - Update a new test to use the new helpers. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 25 May 2016 15:31:52 -0400
changeset 371088 e096709134afdeae68afb26f999dc1c0a2f4de39
parent 371087 1ac523b371f2408d9dc3c403390387564d811962
child 371089 a50249d48b1e86a3749bccc51ece4d1a827a621c
push id19232
push userbmo:gps@mozilla.com
push dateWed, 25 May 2016 22:36:54 +0000
reviewersbotond
bugs1273654
milestone49.0a1
Bug 1273654 - Update a new test to use the new helpers. r=botond MozReview-Commit-ID: Br5jlOQ12wy
gfx/layers/apz/test/mochitest/test_touch_listeners_impacting_wheel.html
--- a/gfx/layers/apz/test/mochitest/test_touch_listeners_impacting_wheel.html
+++ b/gfx/layers/apz/test/mochitest/test_touch_listeners_impacting_wheel.html
@@ -84,76 +84,53 @@ function takeSnapshots(e) {
   // Until now, no scroll events will have been dispatched to content. That's
   // because scroll events are dispatched on the main thread, which we've been
   // hogging with the code above. At this point we restore the normal refresh
   // behaviour and let the main thread go back to C++ code, so the scroll events
   // fire and we unwind from the main test continuation.
   SpecialPowers.DOMWindowUtils.restoreNormalRefresh();
 }
 
-function* runTest() {
+function* test(testDriver) {
   var box = document.getElementById('box');
   box.addEventListener('touchstart', function(e) {
     ok(false, "This should never be run");
   }, false);
   box.addEventListener('wheel', takeSnapshots, { capture: false, passive: true });
 
   // Let the event regions propagate to the APZ
   yield waitForAllPaints(function() {
-    flushApzRepaints(driveTest);
+    flushApzRepaints(testDriver);
   });
 
   // Take over control of the refresh driver and compositor
   var utils = SpecialPowers.DOMWindowUtils;
   utils.advanceTimeAndRefresh(0);
 
   // Trigger an APZ scroll using a wheel event. If APZ is waiting for a
   // content response, it will wait for takeSnapshots to finish running before
   // it starts scrolling, which will cause the checks in takeSnapshots to fail.
-  yield synthesizeNativeMouseMoveAndWaitForMoveEvent(box, 10, 10, driveTest);
-  yield synthesizeNativeWheelAndWaitForScrollEvent(box, 10, 10, 0, -50, driveTest);
-}
-
-var gTestContinuation = null;
-function driveTest() {
-  if (!gTestContinuation) {
-    gTestContinuation = runTest();
-  }
-  var ret = gTestContinuation.next();
-  if (ret.done) {
-    SimpleTest.finish();
-  }
+  yield synthesizeNativeMouseMoveAndWaitForMoveEvent(box, 10, 10, testDriver);
+  yield synthesizeNativeWheelAndWaitForScrollEvent(box, 10, 10, 0, -50, testDriver);
 }
 
-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);
-  })
+if (isApzEnabled()) {
+  SimpleTest.waitForExplicitFinish();
+  // Disable touch events, so that APZ knows not to wait for touch listeners.
+  // Also explicitly set the content response timeout, so we know how long it
+  // is (see comment in takeSnapshots).
+  // Finally, enable smooth scrolling, so that the wheel-scroll we do as part
+  // of the test triggers an APZ animation rather than doing an instant scroll.
+  // Note that this pref doesn't work for the synthesized wheel events on OS X,
+  // those are hard-coded to be instant scrolls.
+  pushPrefs([["dom.w3c_touch_events.enabled", 0],
+             ["apz.content_response_timeout", kResponseTimeoutMs],
+             ["general.smoothscroll", true]])
+  .then(waitUntilApzStable)
+  .then(runContinuation(test))
+  .then(SimpleTest.finish);
 }
 
-SimpleTest.waitForExplicitFinish();
-
-// Disable touch events, so that APZ knows not to wait for touch listeners.
-// Also explicitly set the content response timeout, so we know how long it
-// is (see comment in takeSnapshots).
-// Finally, enable smooth scrolling, so that the wheel-scroll we do as part
-// of the test triggers an APZ animation rather than doing an instant scroll.
-// Note that this pref doesn't work for the synthesized wheel events on OS X,
-// those are hard-coded to be instant scrolls.
-SpecialPowers.pushPrefEnv({"set": [["dom.w3c_touch_events.enabled", 0],
-                                   ["apz.content_response_timeout", kResponseTimeoutMs],
-                                   ["general.smoothscroll", true]]},
-                          function() {
-                            SimpleTest.waitForFocus(startTest, window);
-                          });
 </script>
 </pre>
 
 </body>
 </html>