Bug 1273654 - Extract a helper to check if APZ is enabled or not. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 25 May 2016 15:31:52 -0400
changeset 371085 90341d286f4dcff8ab6d8bc21d5d888bc3bab328
parent 371084 dcb15e7ac2e212df7e200e6256eced56e149422f
child 371086 f163ba08afc61c44fc1b2cacab7df37d8097b1a8
push id19232
push userbmo:gps@mozilla.com
push dateWed, 25 May 2016 22:36:54 +0000
reviewersbotond
bugs1273654
milestone49.0a1
Bug 1273654 - Extract a helper to check if APZ is enabled or not. r=botond MozReview-Commit-ID: EkhZpfT3UFs
gfx/layers/apz/test/mochitest/apz_test_utils.js
gfx/layers/apz/test/mochitest/test_bug1151663.html
gfx/layers/apz/test/mochitest/test_bug982141.html
gfx/layers/apz/test/mochitest/test_frame_reconstruction.html
gfx/layers/apz/test/mochitest/test_group_mouseevents.html
gfx/layers/apz/test/mochitest/test_group_touchevents.html
gfx/layers/apz/test/mochitest/test_group_wheelevents.html
gfx/layers/apz/test/mochitest/test_layerization.html
--- a/gfx/layers/apz/test/mochitest/apz_test_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js
@@ -217,8 +217,19 @@ function waitUntilApzStable() {
   return new Promise(function(resolve, reject) {
     SimpleTest.waitForFocus(function() {
       waitForAllPaints(function() {
         flushApzRepaints(resolve);
       });
     }, window);
   });
 }
+
+function isApzEnabled() {
+  var enabled = SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled;
+  if (!enabled) {
+    // All tests are required to have at least one assertion. Since APZ is
+    // disabled, and the main test is presumably not going to run, we stick in
+    // a dummy assertion here to keep the test passing.
+    SimpleTest.ok(true, "APZ is not enabled; this test will be skipped");
+  }
+  return enabled;
+}
--- a/gfx/layers/apz/test/mochitest/test_bug1151663.html
+++ b/gfx/layers/apz/test/mochitest/test_bug1151663.html
@@ -2,35 +2,33 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=1151663
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 1151663</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="apz_test_utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
-    SimpleTest.waitForExplicitFinish();
+    if (isApzEnabled()) {
+      SimpleTest.waitForExplicitFinish();
 
-    // Run the actual test in its own window, because it requires that the
-    // root APZC be scrollable. Mochitest pages themselves often run
-    // inside an iframe which means we have no control over the root APZC.
-    var w = null;
-    window.onload = function() {
-      if (!SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled) {
-        ok(true, "APZ is not enabled, this test is not relevant, sorry!\n");
-        SimpleTest.finish();
-        return;
-      }
-      SpecialPowers.pushPrefEnv({"set": [["apz.test.logging_enabled", true]]}, function() {
-        w = window.open("helper_bug1151663.html", "_blank");
-      });
-    };
+      // Run the actual test in its own window, because it requires that the
+      // root APZC be scrollable. Mochitest pages themselves often run
+      // inside an iframe which means we have no control over the root APZC.
+      var w = null;
+      window.onload = function() {
+        SpecialPowers.pushPrefEnv({"set": [["apz.test.logging_enabled", true]]}, function() {
+          w = window.open("helper_bug1151663.html", "_blank");
+        });
+      };
+    }
 
     function finishTest() {
       w.close();
       SimpleTest.finish();
     };
 
   </script>
 </head>
--- a/gfx/layers/apz/test/mochitest/test_bug982141.html
+++ b/gfx/layers/apz/test/mochitest/test_bug982141.html
@@ -2,35 +2,33 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=982141
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 982141</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="apz_test_utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
-    SimpleTest.waitForExplicitFinish();
+    if (isApzEnabled()) {
+      SimpleTest.waitForExplicitFinish();
 
-    // Run the actual test in its own window, because it requires that the
-    // root APZC not be scrollable. Mochitest pages themselves often run
-    // inside an iframe which means we have no control over the root APZC.
-    var w = null;
-    window.onload = function() {
-      if (!SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled) {
-        ok(true, "APZ is not enabled, this test is not relevant, sorry!\n");
-        SimpleTest.finish();
-        return;
-      }
-      SpecialPowers.pushPrefEnv({"set": [["apz.test.logging_enabled", true]]}, function() {
-        w = window.open("helper_bug982141.html", "_blank");
-      });
-    };
+      // Run the actual test in its own window, because it requires that the
+      // root APZC not be scrollable. Mochitest pages themselves often run
+      // inside an iframe which means we have no control over the root APZC.
+      var w = null;
+      window.onload = function() {
+        SpecialPowers.pushPrefEnv({"set": [["apz.test.logging_enabled", true]]}, function() {
+          w = window.open("helper_bug982141.html", "_blank");
+        });
+      };
+    }
 
     function finishTest() {
       w.close();
       SimpleTest.finish();
     };
 
   </script>
 </head>
--- a/gfx/layers/apz/test/mochitest/test_frame_reconstruction.html
+++ b/gfx/layers/apz/test/mochitest/test_frame_reconstruction.html
@@ -211,21 +211,17 @@ function driveTest() {
     gTestContinuation = runTest();
   }
   var ret = gTestContinuation.next();
   if (ret.done) {
     SimpleTest.finish();
   }
 }
 
-SimpleTest.waitForExplicitFinish();
-var apzEnabled = SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled;
-if (!apzEnabled) {
-  ok(true, "APZ not enabled, skipping test");
-  SimpleTest.finish();
-} else {
+if (isApzEnabled()) {
+  SimpleTest.waitForExplicitFinish();
   SimpleTest.expectAssertions(0, 1); // this test triggers an assertion, see bug 1247050
   waitUntilApzStable().then(driveTest);
 }
 
 </script>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_group_mouseevents.html
+++ b/gfx/layers/apz/test/mochitest/test_group_mouseevents.html
@@ -10,24 +10,21 @@
 
 var subtests = [
   // Sanity test to synthesize a mouse click
   {'file': 'helper_click.html'},
   // Sanity test for click but with some mouse movement between the down and up
   {'file': 'helper_drag_click.html'}
 ];
 
-SimpleTest.waitForExplicitFinish();
-window.onload = function() {
-  if (!SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled) {
-    ok(true, "APZ is not enabled, this test is not relevant, sorry!\n");
-    SimpleTest.finish();
-    return;
-  }
-  runSubtestsSeriallyInFreshWindows(subtests)
+if (isApzEnabled()) {
+  SimpleTest.waitForExplicitFinish();
+  window.onload = function() {
+    runSubtestsSeriallyInFreshWindows(subtests)
     .then(SimpleTest.finish);
-};
+  };
+}
 
   </script>
 </head>
 <body>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_group_touchevents.html
+++ b/gfx/layers/apz/test/mochitest/test_group_touchevents.html
@@ -52,24 +52,21 @@ var subtests = [
 
   // For the following test, we want to make sure APZ doesn't wait for a content
   // response that is never going to arrive. To detect this we set the content response
   // timeout to a day, so that the entire test times out and fails if APZ does
   // end up waiting.
   {'file': 'helper_tap_passive.html', 'prefs': [["apz.content_response_timeout", 24 * 60 * 60 * 1000]]},
 ];
 
-SimpleTest.waitForExplicitFinish();
-window.onload = function() {
-  if (!SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled) {
-    ok(true, "APZ is not enabled, this test is not relevant, sorry!\n");
-    SimpleTest.finish();
-    return;
-  }
-  runSubtestsSeriallyInFreshWindows(subtests)
+if (isApzEnabled()) {
+  SimpleTest.waitForExplicitFinish();
+  window.onload = function() {
+    runSubtestsSeriallyInFreshWindows(subtests)
     .then(SimpleTest.finish);
-};
+  };
+}
 
   </script>
 </head>
 <body>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_group_wheelevents.html
+++ b/gfx/layers/apz/test/mochitest/test_group_wheelevents.html
@@ -20,24 +20,21 @@ var subtests = [
         ['mousewheel.transaction.timeout', 0]]},
   {'file': 'helper_bug1271432.html', 'prefs': [
         // same prefs as in the previous test, for the same reasons.
         ['general.smoothScroll', false],
         ['mousewheel.transaction.ignoremovedelay', 0],
         ['mousewheel.transaction.timeout', 0]]}
 ];
 
-SimpleTest.waitForExplicitFinish();
-window.onload = function() {
-  if (!SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled) {
-    ok(true, "APZ is not enabled, this test is not relevant, sorry!\n");
-    SimpleTest.finish();
-    return;
-  }
-  runSubtestsSeriallyInFreshWindows(subtests)
+if (isApzEnabled()) {
+  SimpleTest.waitForExplicitFinish();
+  window.onload = function() {
+    runSubtestsSeriallyInFreshWindows(subtests)
     .then(SimpleTest.finish);
-};
+  };
+}
 
   </script>
 </head>
 <body>
 </body>
 </html>
--- a/gfx/layers/apz/test/mochitest/test_layerization.html
+++ b/gfx/layers/apz/test/mochitest/test_layerization.html
@@ -215,39 +215,29 @@ function driveTest() {
     gTestContinuation = runTest();
   }
   var ret = gTestContinuation.next();
   if (ret.done) {
     SimpleTest.finish();
   }
 }
 
-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;
-  }
-
-  driveTest();
-}
+if (isApzEnabled()) {
+  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)
 
-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.
-pushPrefs([["general.smoothScroll", false],
-           ["apz.displayport_expiry_ms", 0],
-           ["apz.test.logging_enabled", true]])
-.then(waitUntilApzStable)
-.then(startTest);
+  // 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.
+  pushPrefs([["general.smoothScroll", false],
+             ["apz.displayport_expiry_ms", 0],
+             ["apz.test.logging_enabled", true]])
+  .then(waitUntilApzStable)
+  .then(driveTest);
+}
 
 </script>
 </pre>
 </body>
 </html>