Bug 1252135 - Convert some tests in dom/events to use pushPrefEnv, r=Andrew McCreight
authorMartijn Wargers <mwargers@mozilla.com>
Tue, 01 Mar 2016 09:27:15 -0500
changeset 322628 6422ab4c6fb4ae306cfbe579d035b3ef9c41f917
parent 322627 13f5670eac32e38a5d9bcd8d5e222ba40cd2d66c
child 322629 f5e475aff6f0f527365894889421b79a4c5d1308
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersAndrew
bugs1252135
milestone47.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 1252135 - Convert some tests in dom/events to use pushPrefEnv, r=Andrew McCreight
dom/events/test/test_bug238987.html
dom/events/test/test_bug409604.html
dom/events/test/test_bug457672.html
dom/events/test/test_moz_mouse_pixel_scroll_event.html
dom/events/test/window_bug659071.html
--- a/dom/events/test/test_bug238987.html
+++ b/dom/events/test/test_bug238987.html
@@ -26,26 +26,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   var backwardFocusArray = expectedResult.split(",");
   var forwardBlurArray = expectedResult.split(",");
   var backwardBlurArray = expectedResult.split(",");
   // Adding 3 for "begin", "end", "begin" and one for the <a> in the Mochitest template,
   var expectedWindowFocusCount = forwardFocusArray.length + backwardFocusArray.length + 4;
   // but the last blur event goes to i1, not "begin".
   var expectedWindowBlurCount = forwardFocusArray.length + backwardFocusArray.length + 3;
 
-  // accessibility.tabfocus must be set to value 7 before running test also
-  // on a mac.
-  function setOrRestoreTabFocus(newValue) {
-    if (!newValue) {
-      SpecialPowers.clearUserPref("accessibility.tabfocus");
-    } else {
-      SpecialPowers.setIntPref("accessibility.tabfocus", newValue);
-    }
-  }
-
   function handleFocus(e) {
     if (e.target.id == "begin") {
       // if the modifier is set, the test is coming back from the end.
       if (modifier) {
         shouldStop = true;
       }
     } else if (e.target.id == "end") {
       modifier = Components.interfaces.nsIDOMEvent.SHIFT_MASK;
@@ -123,17 +113,16 @@ https://bugzilla.mozilla.org/show_bug.cg
          forwardBlurArray.toString());
       is(backwardBlurArray.length, 0,
          "Not all backward tabbing blur tests were run, " +
          backwardBlurArray.toString());
       is(expectedWindowBlurCount, 0,
          "|window| didn't get the right amount of blur events");
 
       // Cleanup
-      setOrRestoreTabFocus(0);
       window.removeEventListener("focus", handleWindowFocus, true);
       window.removeEventListener("focus", handleWindowFocus, false);
       window.removeEventListener("blur", handleWindowBlur, true);
       window.removeEventListener("blur", handleWindowBlur, false);
       var elements = document.getElementsByTagName("*");
       for (var i = 0; i < elements.length; ++i) {
         if (elements[i].hasAttribute("id")) {
           elements[i].removeEventListener("focus", handleFocus, false);
@@ -161,19 +150,20 @@ https://bugzilla.mozilla.org/show_bug.cg
       }
       if (elements[i].getAttribute("tabindex") == "1") {
         elements[i].setAttribute("tabindex", "-1");
       }
     }
     tab();
   }
 
+  // accessibility.tabfocus must be set to value 7 before running test also
+  // on a mac.
   function doTest() {
-    setOrRestoreTabFocus(7);
-    setTimeout(start, 0);
+    SpecialPowers.pushPrefEnv({"set": [["accessibility.tabfocus", 7]]}, start);
   }
 
   SimpleTest.waitForExplicitFinish();
   addLoadEvent(doTest);
 
 </script>
 </pre>
   <h4 tabindex="0" id="begin">Test:</h4>
--- a/dom/events/test/test_bug409604.html
+++ b/dom/events/test/test_bug409604.html
@@ -85,25 +85,16 @@ https://bugzilla.mozilla.org/show_bug.cg
       "tbody",
       "td",
       "tfoot",
       "th",
       "thead",
       "tr"
     ];
 
-  // ui.key.contentAccess must be set to value 5 before running the test.
-  function setOrRestoreContentAccess(newValue) {
-    if (!newValue) {
-      SpecialPowers.clearUserPref("ui.key.contentAccess");
-    } else {
-      SpecialPowers.setIntPref("ui.key.contentAccess", newValue);
-    }
-  }
-
   function handleFocus(e) {
     ok("accessKey" in e, "(focus) accesskey property not found on element");
     var expected = focusArray.shift();
     // "k" and "n" are a special cases because the element receiving the focus
     // is not the element which has the accesskey.
     if (expected == "k" || expected == "n") {
       ok(e.value == "test for label", "(focus) unexpected element: " + e.value +
          " expected: " + "test for label");
@@ -213,27 +204,24 @@ https://bugzilla.mozilla.org/show_bug.cg
       e.removeAttribute("onclick");
       e.removeAttribute("onfocus");
     }
   }
 
   function start() {
     testFocusableElements();
     testUnfocusableElements();
-    setOrRestoreContentAccess(0);
     SimpleTest.finish();
   }
 
   function doTest() {
-    setOrRestoreContentAccess(5);
-    setTimeout(start, 100);
+    SpecialPowers.pushPrefEnv({"set": [["ui.key.contentAccess", 5]]}, start);
   }
 
   SimpleTest.waitForExplicitFinish();
-  SimpleTest.requestFlakyTimeout("untriaged");
   addLoadEvent(doTest);
 
 </script>
 </pre>
   <table id="table">
     <thead id="thead">
       <tr id="tr"><th id="th">Test header</th><th></th></tr>
     </thead>
--- a/dom/events/test/test_bug457672.html
+++ b/dom/events/test/test_bug457672.html
@@ -16,45 +16,37 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 457672 **/
 
 var windowBlurCount = 0;
 
-function setUserPref(reset) {
-  if (reset) {
-    SpecialPowers.clearUserPref("browser.link.open_newwindow");
-  } else {
-    SpecialPowers.setIntPref("browser.link.open_newwindow", 3);
-  }
-}
-
 function listener(evt) {
   if (evt.type == "focus") {
     is(windowBlurCount, 1,
        "Window should have got blur event when opening a new tab!");
-    setUserPref(true);
     document.getElementsByTagName("a")[0].focus();
     SimpleTest.finish();
   } else if (evt.type == "blur") {
     ++windowBlurCount;
   }
   document.getElementById('log').textContent += evt.target + ":" + evt.type + "\n";
 }
 
 function startTest() {
-  setUserPref(false);
-  document.getElementsByTagName("a")[0].focus();
-  // Note, focus/blur don't bubble
-  window.addEventListener("focus", listener, false);
-  window.addEventListener("blur", listener, false);
-  var subwin = window.open("about:blank", "", "");
-  subwin.addEventListener("focus", function(e) { subwin.close(); }, false);
+  SpecialPowers.pushPrefEnv({"set": [["browser.link.open_newwindow", 3]]}, function() {
+    document.getElementsByTagName("a")[0].focus();
+    // Note, focus/blur don't bubble
+    window.addEventListener("focus", listener, false);
+    window.addEventListener("blur", listener, false);
+    var subwin = window.open("about:blank", "", "");
+    subwin.addEventListener("focus", function(e) { subwin.close(); }, false);
+  });
 }
 
 addLoadEvent(startTest);
 SimpleTest.waitForExplicitFinish();
 
 </script>
 </pre>
 <pre id="log">
--- a/dom/events/test/test_moz_mouse_pixel_scroll_event.html
+++ b/dom/events/test/test_moz_mouse_pixel_scroll_event.html
@@ -40,17 +40,17 @@
 </div>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 SimpleTest.waitForExplicitFinish();
-SimpleTest.waitForFocus(runTest, window);
+SimpleTest.waitForFocus(startTest, window);
 
 var gScrollable128 = document.getElementById("Scrollable128");
 var gScrollable96 = document.getElementById("Scrollable96");
 var gScrollable64 = document.getElementById("Scrollable64");
 var gScrollable32 = document.getElementById("Scrollable32");
 var gRoot = document.documentElement;
 
 function* prepareScrollUnits()
@@ -1310,71 +1310,54 @@ function* doTests()
     currentTest.cleanup();
   }
 
   window.removeEventListener("MozMousePixelScroll", handler, true);
 }
 
 function* testBody()
 {
-  SpecialPowers.setIntPref("mousewheel.default.delta_multiplier_x", 100);
-  SpecialPowers.setIntPref("mousewheel.default.delta_multiplier_y", 100);
-  SpecialPowers.setIntPref("mousewheel.default.delta_multiplier_z", 100);
-  SpecialPowers.setIntPref("mousewheel.with_alt.delta_multiplier_x", 100);
-  SpecialPowers.setIntPref("mousewheel.with_alt.delta_multiplier_y", 100);
-  SpecialPowers.setIntPref("mousewheel.with_alt.delta_multiplier_z", 100);
-  SpecialPowers.setIntPref("mousewheel.with_control.delta_multiplier_x", 100);
-  SpecialPowers.setIntPref("mousewheel.with_control.delta_multiplier_y", 100);
-  SpecialPowers.setIntPref("mousewheel.with_control.delta_multiplier_z", 100);
-  SpecialPowers.setIntPref("mousewheel.with_meta.delta_multiplier_x", 100);
-  SpecialPowers.setIntPref("mousewheel.with_meta.delta_multiplier_y", 100);
-  SpecialPowers.setIntPref("mousewheel.with_meta.delta_multiplier_z", 100);
-  SpecialPowers.setIntPref("mousewheel.with_shift.delta_multiplier_x", 100);
-  SpecialPowers.setIntPref("mousewheel.with_shift.delta_multiplier_y", 100);
-  SpecialPowers.setIntPref("mousewheel.with_shift.delta_multiplier_z", 100);
-  SpecialPowers.setIntPref("mousewheel.with_win.delta_multiplier_x", 100);
-  SpecialPowers.setIntPref("mousewheel.with_win.delta_multiplier_y", 100);
-  SpecialPowers.setIntPref("mousewheel.with_win.delta_multiplier_z", 100);
-  // If APZ is enabled we should ensure the preventDefault calls work even
-  // if the test is running slowly.
-  SpecialPowers.setIntPref("apz.content_response_timeout", 2000);
-
   yield* prepareScrollUnits();
   yield* doTests();
-
-  SpecialPowers.clearUserPref("mousewheel.default.delta_multiplier_x");
-  SpecialPowers.clearUserPref("mousewheel.default.delta_multiplier_y");
-  SpecialPowers.clearUserPref("mousewheel.default.delta_multiplier_z");
-  SpecialPowers.clearUserPref("mousewheel.with_alt.delta_multiplier_x");
-  SpecialPowers.clearUserPref("mousewheel.with_alt.delta_multiplier_y");
-  SpecialPowers.clearUserPref("mousewheel.with_alt.delta_multiplier_z");
-  SpecialPowers.clearUserPref("mousewheel.with_control.delta_multiplier_x");
-  SpecialPowers.clearUserPref("mousewheel.with_control.delta_multiplier_y");
-  SpecialPowers.clearUserPref("mousewheel.with_control.delta_multiplier_z");
-  SpecialPowers.clearUserPref("mousewheel.with_meta.delta_multiplier_x");
-  SpecialPowers.clearUserPref("mousewheel.with_meta.delta_multiplier_y");
-  SpecialPowers.clearUserPref("mousewheel.with_meta.delta_multiplier_z");
-  SpecialPowers.clearUserPref("mousewheel.with_shift.delta_multiplier_x");
-  SpecialPowers.clearUserPref("mousewheel.with_shift.delta_multiplier_y");
-  SpecialPowers.clearUserPref("mousewheel.with_shift.delta_multiplier_z");
-  SpecialPowers.clearUserPref("mousewheel.with_win.delta_multiplier_x");
-  SpecialPowers.clearUserPref("mousewheel.with_win.delta_multiplier_y");
-  SpecialPowers.clearUserPref("mousewheel.with_win.delta_multiplier_z");
-  SpecialPowers.clearUserPref("apz.content_response_timeout");
 }
 
 var gTestContinuation = null;
 
 function runTest()
 {
   if (!gTestContinuation) {
     gTestContinuation = testBody();
   }
   var ret = gTestContinuation.next();
   if (ret.done) {
     SimpleTest.finish();
   }
 }
 
+function startTest() {
+  SpecialPowers.pushPrefEnv({"set": [["mousewheel.default.delta_multiplier_x", 100],
+                                     ["mousewheel.default.delta_multiplier_y", 100],
+                                     ["mousewheel.default.delta_multiplier_z", 100],
+                                     ["mousewheel.with_alt.delta_multiplier_x", 100],
+                                     ["mousewheel.with_alt.delta_multiplier_y", 100],
+                                     ["mousewheel.with_alt.delta_multiplier_z", 100],
+                                     ["mousewheel.with_control.delta_multiplier_x", 100],
+                                     ["mousewheel.with_control.delta_multiplier_y", 100],
+                                     ["mousewheel.with_control.delta_multiplier_z", 100],
+                                     ["mousewheel.with_meta.delta_multiplier_x", 100],
+                                     ["mousewheel.with_meta.delta_multiplier_y", 100],
+                                     ["mousewheel.with_meta.delta_multiplier_z", 100],
+                                     ["mousewheel.with_shift.delta_multiplier_x", 100],
+                                     ["mousewheel.with_shift.delta_multiplier_y", 100],
+                                     ["mousewheel.with_shift.delta_multiplier_z", 100],
+                                     ["mousewheel.with_win.delta_multiplier_x", 100],
+                                     ["mousewheel.with_win.delta_multiplier_y", 100],
+                                     ["mousewheel.with_win.delta_multiplier_z", 100],
+  // If APZ is enabled we should ensure the preventDefault calls work even
+  // if the test is running slowly.
+                                     ["apz.content_response_timeout", 2000],
+                                    ]}, runTest);
+}
+
 </script>
 </pre>
 </body>
 </html>
--- a/dom/events/test/window_bug659071.html
+++ b/dom/events/test/window_bug659071.html
@@ -5,17 +5,17 @@
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <video id="v" controls></video>
 <script type="application/javascript">
 
-SimpleTest.waitForFocus(runTests, window);
+SimpleTest.waitForFocus(startTests, window);
 SimpleTest.requestFlakyTimeout("untriaged");
 
 function is()
 {
   window.opener.is.apply(window.opener, arguments);
 }
 
 function isnot()
@@ -27,19 +27,22 @@ function hitEventLoop(aFunc, aTimes)
 {
   if (--aTimes) {
     setTimeout(hitEventLoop, 0, aFunc, aTimes);
   } else {
     setTimeout(aFunc, 20);
   }
 }
 
+function startTests() {
+  SpecialPowers.pushPrefEnv({"set": [["mousewheel.with_control.action", 3]]}, runTests);
+}
+
 function runTests()
 {
-  SpecialPowers.setIntPref("mousewheel.with_control.action", 3);
   synthesizeKey("0", { accelKey: true });
 
   var video = document.getElementById("v");
   hitEventLoop(function () {
     is(SpecialPowers.getFullZoom(window), 1.0,
        "failed to reset zoom");
     synthesizeWheel(video, 10, 10,
       { deltaMode: WheelEvent.DOM_DELTA_LINE, ctrlKey: true,
@@ -50,18 +53,16 @@ function runTests()
 
       synthesizeWheel(video, 10, 10,
         { deltaMode: WheelEvent.DOM_DELTA_LINE, ctrlKey: true,
           deltaX: 0, deltaY: 1.0, lineOrPageDeltaX: 0, lineOrPageDeltaY: -1 });
       hitEventLoop(function () {
         is(SpecialPowers.getFullZoom(window), 1.0,
            "failed to reset zoom");
 
-        SpecialPowers.clearUserPref("mousewheel.with_control.action");
-
         hitEventLoop(window.opener.finish, 20);
       }, 20);
     }, 20);
   }, 20);
 }
 
 </script>
 </body>