Bug 1135091 - Convert remaining SpecialPowers.setBoolPref to pushPrefEnv. r=jmaher, r=mwargers, a=test-only
authorAnish <anishchandran94@gmail.com>
Tue, 03 Mar 2015 08:46:35 -0500
changeset 258365 8d23b1e2cc0f
parent 258364 a1c4c4d43776
child 258366 a7535132fe8e
push id4654
push userryanvm@gmail.com
push date2015-04-08 19:02 +0000
treeherdermozilla-beta@01cf08a90d44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher, mwargers, test-only
bugs1135091
milestone38.0
Bug 1135091 - Convert remaining SpecialPowers.setBoolPref to pushPrefEnv. r=jmaher, r=mwargers, a=test-only
layout/base/tests/chrome/test_bug458898.html
layout/base/tests/chrome/transformed_scrolling_repaints_3_window.html
layout/base/tests/test_scroll_event_ordering.html
layout/forms/test/test_bug345267.html
layout/forms/test/test_bug365410.html
layout/forms/test/test_bug563642.html
layout/forms/test/test_select_prevent_default.html
layout/generic/test/page_scroll_with_fixed_pos_window.html
layout/generic/test/test_bug633762.html
layout/generic/test/test_bug784410.html
layout/generic/test/test_bug791616.html
layout/style/test/test_position_sticky.html
layout/style/test/test_visited_pref.html
--- a/layout/base/tests/chrome/test_bug458898.html
+++ b/layout/base/tests/chrome/test_bug458898.html
@@ -17,24 +17,23 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
 var win = window.openDialog("data:text/html,<div style='height:200px; width:100px;'>");
 
 function loaded() {
   var disableWindowResizePref = "dom.disable_window_move_resize";
-  var oldPrefValue = SpecialPowers.getBoolPref(disableWindowResizePref);
-  SpecialPowers.setBoolPref(disableWindowResizePref, false);
-  win.sizeToContent();
-  ok(win.innerWidth >= 100, "innerWidth: " + win.innerWidth + " >= 100 ?");
-  ok(win.innerHeight >= 200, "innerHeight: " + win.innerHeight + " >= 200 ?");
-  win.close();
-  SpecialPowers.setBoolPref(disableWindowResizePref, oldPrefValue);
-  SimpleTest.finish();
+  SpecialPowers.pushPrefEnv({"set":[[disableWindowResizePref, false]]}, function() {
+    win.sizeToContent();
+    ok(win.innerWidth >= 100, "innerWidth: " + win.innerWidth + " >= 100 ?");
+    ok(win.innerHeight >= 200, "innerHeight: " + win.innerHeight + " >= 200 ?");
+    win.close();
+    SimpleTest.finish();
+ });
 }
 
 win.addEventListener("load", loaded, false);
 
 </script>
 </pre>
 </body>
 </html>
--- a/layout/base/tests/chrome/transformed_scrolling_repaints_3_window.html
+++ b/layout/base/tests/chrome/transformed_scrolling_repaints_3_window.html
@@ -34,51 +34,51 @@ person I've ever had the joy of dealing 
 there are some real dicks out there, and some of them happen to be 
 scientists.
 </body>"></iframe>
 <pre id="test">
 <script type="application/javascript">
 var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
 var SpecialPowers = window.opener.wrappedJSObject.SpecialPowers;
 var is = window.opener.wrappedJSObject.is;
-
+var t, e, utils, iterations;
 var smoothScrollPref = "general.smoothScroll";
-SpecialPowers.setBoolPref(smoothScrollPref, false);
 
 function startTest() {
-  var t = document.getElementById("t");
-  var e = t.contentDocument.getElementById("e");
-  t.contentWindow.scrollTo(0,0);
-  var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                 getInterface(Components.interfaces.nsIDOMWindowUtils);
-  var iterations = 0;
+  SpecialPowers.pushPrefEnv({"set":[[smoothScrollPref, false]]}, runTest);
+}
+function runTest() {
+    t = document.getElementById("t");
+    e = t.contentDocument.getElementById("e");
+    t.contentWindow.scrollTo(0,0);
+    utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
+                   getInterface(Components.interfaces.nsIDOMWindowUtils);
+    iterations = 0;
 
-  function nextIteration() {
-    var painted = utils.checkAndClearPaintedState(e);
-    is(painted, false, "Fully-visible scrolled element should not have been painted");
-    if (++iterations == 10) {
-      SpecialPowers.clearUserPref(smoothScrollPref);
-      SimpleTest.finish();
-      window.close();
-    } else {
-      t.contentWindow.scrollByLines(1);
-      waitForAllPaintsFlushed(nextIteration);
-    }
-  }
-  
   // Do a couple of scrolls to ensure we've triggered activity heuristics.
-  waitForAllPaintsFlushed(function () {
-    t.contentWindow.scrollByLines(1);
     waitForAllPaintsFlushed(function () {
       t.contentWindow.scrollByLines(1);
       waitForAllPaintsFlushed(function () {
-        // Clear paint state now and scroll again.
-        utils.checkAndClearPaintedState(e);
         t.contentWindow.scrollByLines(1);
-        waitForAllPaintsFlushed(nextIteration);
+        waitForAllPaintsFlushed(function () {
+          // Clear paint state now and scroll again.
+          utils.checkAndClearPaintedState(e);
+          t.contentWindow.scrollByLines(1);
+          waitForAllPaintsFlushed(nextIteration);
+        });
       });
     });
-  });
+}
+function nextIteration() {
+  var painted = utils.checkAndClearPaintedState(e);
+  is(painted, false, "Fully-visible scrolled element should not have been painted");
+  if (++iterations == 10) {
+    SimpleTest.finish();
+    window.close();
+  } else {
+    t.contentWindow.scrollByLines(1);
+    waitForAllPaintsFlushed(nextIteration);
+  }
 }
 </script>
 </pre>
 </body>
 </html>
--- a/layout/base/tests/test_scroll_event_ordering.html
+++ b/layout/base/tests/test_scroll_event_ordering.html
@@ -16,41 +16,41 @@ https://bugzilla.mozilla.org/show_bug.cg
     <div id="inner" style="height:200px;">Hello</div>
   </div>
 </div>
 <pre id="test">
 <script>
 SimpleTest.waitForExplicitFinish();
 
 var smoothScrollPref = "general.smoothScroll";
-SpecialPowers.setBoolPref(smoothScrollPref, false);
 
 var d = document.getElementById("d");
 d.scrollTop = 0;
 var inner = document.getElementById("inner");
 
 var state = "initial";
 
 function onFrame() {
   is(state, "initial", "Must be in initial state");
   ok(d.scrollTop > 0, "Must have scrolled by some amount (got " + d.scrollTop + ")");
   state = "didOnFrame";
 }
 
 function onScroll() {
   is(state, "didOnFrame", "Must have got requestAnimationFrame callback already");
   ok(d.scrollTop > 0, "Must have scrolled by some amount (got " + d.scrollTop + ")");
-  SpecialPowers.clearUserPref(smoothScrollPref);
   SimpleTest.finish();
 }
 
 function doTest() {
   window.getSelection().collapse(inner.firstChild, 0);
   window.mozRequestAnimationFrame(onFrame);
   d.onscroll = onScroll;
   sendKey("DOWN");
 }
 
-SimpleTest.waitForFocus(doTest);
+SimpleTest.waitForFocus(function() {
+  SpecialPowers.pushPrefEnv({"set":[[smoothScrollPref, false]]}, doTest);
+});
 </script>
 </pre>
 </body>
 </html>
--- a/layout/forms/test/test_bug345267.html
+++ b/layout/forms/test/test_bug345267.html
@@ -23,74 +23,76 @@ https://bugzilla.mozilla.org/show_bug.cg
  <input id="u2" maxlength="3">
  <input id="u3" maxlength="3">
  <input id="u4" value="abcdefghijkl">
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 345267 **/
-
+SimpleTest.waitForExplicitFinish();
 // Turn off Spatial Navigation to stop if from hijacking "left" keypress event.
-SpecialPowers.setBoolPref('snav.enabled', false);
+SpecialPowers.pushPrefEnv({"set":[['snav.enabled', false]]}, runTest);
 
-is($("d1").value, "abcde",
-   "Displayed initial value should not be truncated by maxlength");
-is($("u1").value, "abcdef",
-   "Undisplayed initial value should not be truncated by maxlength");
+function runTest() {
+  is($("d1").value, "abcde",
+     "Displayed initial value should not be truncated by maxlength");
+  is($("u1").value, "abcdef",
+     "Undisplayed initial value should not be truncated by maxlength");
 
-$("d2").value = "abcdefg";
-is($("d2").value, "abcdefg",
-   "Displayed set value should not be truncated by maxlength");
+  $("d2").value = "abcdefg";
+  is($("d2").value, "abcdefg",
+     "Displayed set value should not be truncated by maxlength");
 
-$("u2").value = "abcdefgh";
-is($("u2").value, "abcdefgh",
-   "Undisplayed set value should not be truncated by maxlength");
+  $("u2").value = "abcdefgh";
+  is($("u2").value, "abcdefgh",
+     "Undisplayed set value should not be truncated by maxlength");
 
-$("d3").defaultValue = "abcdefghi";
-is($("d3").value, "abcdefghi",
-   "Displayed set defaultValue should not be truncated by maxlength");
+  $("d3").defaultValue = "abcdefghi";
+  is($("d3").value, "abcdefghi",
+     "Displayed set defaultValue should not be truncated by maxlength");
 
-$("u3").defaultValue = "abcdefghij";
-is($("u3").value, "abcdefghij",
-   "Undisplayed set defaultValue should not be truncated by maxlength");
+  $("u3").defaultValue = "abcdefghij";
+  is($("u3").value, "abcdefghij",
+     "Undisplayed set defaultValue should not be truncated by maxlength");
 
-$("d4").maxLength = "3";
-is($("d4").value, "abcdefghijk",
-   "Displayed: setting maxLength should not truncate existing value");
+  $("d4").maxLength = "3";
+  is($("d4").value, "abcdefghijk",
+     "Displayed: setting maxLength should not truncate existing value");
 
-$("u4").maxLength = "3";
-is($("u4").value, "abcdefghijkl",
-   "Undisplayed: setting maxLength should not truncate existing value");
+  $("u4").maxLength = "3";
+  is($("u4").value, "abcdefghijkl",
+     "Undisplayed: setting maxLength should not truncate existing value");
 
-// Now start the editing tests
-is($("target").value, "abcdefghijklm", "Test starting state incorrect");
-$("target").focus();
-$("target").selectionStart = $("target").selectionEnd = 13;
-sendKey("back_space");
-is($("target").value, "abcdefghijkl", "Should only delete one char");
-sendKey("back_space");
-is($("target").value, "abcdefghijk", "Should only delete one char again");
-(function () {
-  SpecialPowers.wrap($("target")).controllers.getControllerForCommand('cmd_undo')
+  // Now start the editing tests
+  is($("target").value, "abcdefghijklm", "Test starting state incorrect");
+  $("target").focus();
+  $("target").selectionStart = $("target").selectionEnd = 13;
+  sendKey("back_space");
+  is($("target").value, "abcdefghijkl", "Should only delete one char");
+  sendKey("back_space");
+  is($("target").value, "abcdefghijk", "Should only delete one char again");
+  (function () {
+    SpecialPowers.wrap($("target")).controllers.getControllerForCommand('cmd_undo')
                          .doCommand('cmd_undo');
-})();
-is($("target").value, "abcdefghijklm",
-   "Should be able to undo deletion in the face of maxlength");
-sendString("nopq");
-is($("target").value, "abcdefghijklm",
-   "Typing should have no effect when already past maxlength");
+  })();
+  is($("target").value, "abcdefghijklm",
+     "Should be able to undo deletion in the face of maxlength");
+  sendString("nopq");
+  is($("target").value, "abcdefghijklm",
+     "Typing should have no effect when already past maxlength");
 
-$("target").value = "";
-sendString("abcde");
-is($("target").value, "abc", "Typing should be limited by maxlength");
+  $("target").value = "";
+  sendString("abcde");
+  is($("target").value, "abc", "Typing should be limited by maxlength");
 
-$("target").value = "";
-sendString("ad");
-sendKey("left");
-sendString("bc");
-is($("target").value, "abd", "Typing should be limited by maxlength again");
-
+  $("target").value = "";
+  sendString("ad");
+  sendKey("left");
+  sendString("bc");
+  is($("target").value, "abd", "Typing should be limited by maxlength again");
+  SimpleTest.finish();
+}
 </script>
 </pre>
 </body>
 </html>
 
--- a/layout/forms/test/test_bug365410.html
+++ b/layout/forms/test/test_bug365410.html
@@ -69,19 +69,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 365410 **/
 
-// Turn off spatial nav so that it does not hijack the up and down events.
-SpecialPowers.setBoolPref("snav.enabled", false);
-
 function pageUpDownTest(id,index) {
   var elm = document.getElementById(id);
   elm.focus();
   elm.selectedIndex = 0;
   sendKey("page_down");
   sendKey("page_down");
   sendKey("page_up");
   sendKey("page_down");
@@ -121,14 +118,17 @@ function runTest() {
   upDownTest("test2",2);
   upDownTest("test3",-1);
   upDownTest("test4",-1);
 
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
-SimpleTest.waitForFocus(runTest)
+// Turn off spatial nav so that it does not hijack the up and down events.
+SimpleTest.waitForFocus(function() {
+  SpecialPowers.pushPrefEnv({"set":[["snav.enabled", false]]}, runTest);
+});
 
 </script>
 </pre>
 </body>
 </html>
--- a/layout/forms/test/test_bug563642.html
+++ b/layout/forms/test/test_bug563642.html
@@ -32,19 +32,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 563642 **/
 
-// Turn off Spatial Navigation because it hijacks down and up key events.
-SpecialPowers.setBoolPref("snav.enabled", false);
-
 function pageUpDownTest(id,index) {
   var elm = document.getElementById(id);
   elm.focus();
   elm.selectedIndex = 0;
   sendKey("page_down");
   sendKey("page_down");
   sendKey("page_down");
   sendKey("page_up");
@@ -71,16 +68,18 @@ function runTest() {
   pageUpDownTest("test4",-1);
   upDownTest("test1",3);
   upDownTest("test2",4);
   upDownTest("test3",-1);
   upDownTest("test4",-1);
 
   SimpleTest.finish();
 }
-
 SimpleTest.waitForExplicitFinish();
-SimpleTest.waitForFocus(runTest)
+// Turn off Spatial Navigation because it hijacks down and up key events.
+SimpleTest.waitForFocus(function() {
+  SpecialPowers.pushPrefEnv({"set":[["snav.enabled", false]]}, runTest);
+})
 
 </script>
 </pre>
 </body>
 </html>
--- a/layout/forms/test/test_select_prevent_default.html
+++ b/layout/forms/test/test_select_prevent_default.html
@@ -8,26 +8,28 @@ https://bugzilla.mozilla.org/show_bug.cg
 <title>Test for Bug 291082</title>
 <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"/>
 <script type="application/javascript">
   /** Test for Bug 291082 **/
 
 
-  // Turn off Spatial Navigation because it hijacks arrow keydown events.
-  SpecialPowers.setBoolPref("snav.enabled", false);
-
   SimpleTest.waitForExplicitFinish();
 
   function preventDefault(event) {
     event.preventDefault();
   }
 
   function test() {
+    // Turn off Spatial Navigation because it hijacks arrow keydown events.
+    SpecialPowers.pushPrefEnv({"set":[["snav.enabled", false]]}, runTest);
+  }
+
+  function runTest() {
     document.getElementById("keydown").addEventListener("keydown", preventDefault);
     document.getElementById("keypress").addEventListener("keypress", preventDefault);
 
     SimpleTest.waitForFocus(function() {
       var testData = [ "one", "two", "three", "four", "keydown", "keypress" ];
 
       // The order of the keys in otherKeys is important for the test to function properly.
       var otherKeys = [ "DOWN", "UP", "RIGHT", "LEFT", "PAGE_DOWN", "PAGE_UP",
--- a/layout/generic/test/page_scroll_with_fixed_pos_window.html
+++ b/layout/generic/test/page_scroll_with_fixed_pos_window.html
@@ -47,18 +47,20 @@ function didScroll() {
 function scrollDownOnePageWithContinuation(cont) {
   document.documentElement.scrollTop = 0;
   nextCont = cont;
   window.scrollByPages(1);
 }
 
 function test() {
   var smoothScrollPref = "general.smoothScroll";
-  SpecialPowers.setBoolPref(smoothScrollPref, false);
+  SpecialPowers.pushPrefEnv({"set":[[smoothScrollPref, false]]}, runTest);
+}
 
+function runTest() {
   showFixedPosElements(false);
   showFixedPosElements2(false);
   scrollDownOnePageWithContinuation(function() {
     var fullPageScrollDown = document.documentElement.scrollTop;
 
     showFixedPosElements(true);
     scrollDownOnePageWithContinuation(function() {
       var fullPageScrollDownWithHeaderAndFooter = document.documentElement.scrollTop;
@@ -79,17 +81,16 @@ function test() {
 
           showFixedPosElements2(true);
           scrollDownOnePageWithContinuation(function() {
             is(document.documentElement.scrollTop, fullPageScrollDown - (10 + 11 + 9 + 12),
                "Combine multiple overlapping elements");
 
             // Scroll back up so test results are visible
             document.documentElement.scrollTop = 0;
-            SpecialPowers.clearUserPref(smoothScrollPref);
             SimpleTest.finish();
             window.close();
           });
         });
       });
     });
   });
 }
--- a/layout/generic/test/test_bug633762.html
+++ b/layout/generic/test/test_bug633762.html
@@ -37,21 +37,21 @@ function runTests() {
   sendKey("UP");
   
   window.requestAnimationFrame(finish);
 }
 
 function finish() {
   // assert that scroll top is now less than before
   ok(scrollTopBefore > doc.body.scrollTop, "pressing up arrow should scroll up");
-  SpecialPowers.clearUserPref(smoothScrollPref);
   SimpleTest.finish();
 }
 
 var smoothScrollPref = "general.smoothScroll";
-SpecialPowers.setBoolPref(smoothScrollPref, false);
 SimpleTest.waitForExplicitFinish();
-SimpleTest.waitForFocus(runTests);
+SimpleTest.waitForFocus(function() {
+  SpecialPowers.pushPrefEnv({"set":[[smoothScrollPref, false]]}, runTests);
+});
 </script>
 </pre>
 
 </body>
 </html>
--- a/layout/generic/test/test_bug784410.html
+++ b/layout/generic/test/test_bug784410.html
@@ -40,27 +40,26 @@ function doneScroll() {
   case 2:
     synthesizeWheel(inner, 4, 4,
       { deltaMode: WheelEvent.DOM_DELTA_LINE, deltaY: 1 });
     break;
   case 3:
     is(innerScrollOffset(), innerStartScrollOffset, "Inner element should not have scrolled down");
     ok(outer.scrollTop > 0, "Outer element should have scrolled down");
     
-    SpecialPowers.clearUserPref(smoothScrollPref);
     SimpleTest.finish();
     break;
   }
 }
 
 function test() {
-  SpecialPowers.setBoolPref(smoothScrollPref, false);
   sel.collapse(inner.firstChild, 2);
   synthesizeKey("VK_PAGE_DOWN", {});
 }
 
 SimpleTest.waitForExplicitFinish();
-SimpleTest.waitForFocus(test);
-
+SimpleTest.waitForFocus(function() {
+  SpecialPowers.pushPrefEnv({"set":[[smoothScrollPref, false]]}, test);
+});
 </script>
 </pre>
 </body>
 </html>
--- a/layout/generic/test/test_bug791616.html
+++ b/layout/generic/test/test_bug791616.html
@@ -25,41 +25,41 @@
 <pre id="test">
 <script class="testbody">
 var t = document.getElementById("t");
 var target = document.getElementById("target");
 var sel = window.getSelection();
 var smoothScrollPref = "general.smoothScroll";
 
 SimpleTest.waitForExplicitFinish();
-SpecialPowers.setBoolPref(smoothScrollPref, false);
 t.scrollTop = 0;
 var targetY = target.getBoundingClientRect().top;
 
 SimpleTest.waitForFocus(function() {
-  is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled due to waitForFocus");
-  t.focus();
-  is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled due to focus change");
+  SpecialPowers.pushPrefEnv({"set":[[smoothScrollPref, false]]}, runTest);
+});
+function runTest() {
+    is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled due to waitForFocus");
+    t.focus();
+    is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled due to focus change");
 
-  // Move the caret to scroll it into view
-  sel.collapse(target.firstChild, 2);
-  synthesizeKey("VK_LEFT", {});
+    // Move the caret to scroll it into view
+    sel.collapse(target.firstChild, 2);
+    synthesizeKey("VK_LEFT", {});
 
-  // Delay until next repaint in case stuff is asynchronous. Also
-  // take a trip through the event loop.
-  setTimeout(function() {
-    window.mozRequestAnimationFrame(function() {
-      is(sel.anchorNode, target.firstChild, "Should have selected 'target' text node");
-      is(sel.anchorOffset, 1, "Selection should have moved left one character");
-      // We should not have needed to scroll the caret into view
-      is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled");
-      SpecialPowers.clearUserPref(smoothScrollPref);
-      SimpleTest.finish();
+    // Delay until next repaint in case stuff is asynchronous. Also
+    // take a trip through the event loop.
+    setTimeout(function() {
+      window.mozRequestAnimationFrame(function() {
+        is(sel.anchorNode, target.firstChild, "Should have selected 'target' text node");
+        is(sel.anchorOffset, 1, "Selection should have moved left one character");
+        // We should not have needed to scroll the caret into view
+        is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled");
+        SimpleTest.finish();
+      });
+      // Make sure repainting actually happens.
+      target.style.background = "yellow";
     });
-    // Make sure repainting actually happens.
-    target.style.background = "yellow";
-  });
-});
-
+}
 </script>
 </pre>
 </body>
 </html>
--- a/layout/style/test/test_position_sticky.html
+++ b/layout/style/test/test_position_sticky.html
@@ -24,19 +24,19 @@ https://bugzilla.mozilla.org/show_bug.cg
  * sticky about:config pref before its document is instantiated.
  *
  * See the iframe's source ("file_position_sticky.html") for the actual
  * test code and for more documentation.
  */
 
 SimpleTest.waitForExplicitFinish();
 
-SpecialPowers.setBoolPref("layout.css.sticky.enabled", true);
-document.getElementById("iframe").src = "file_position_sticky.html";
+SpecialPowers.pushPrefEnv({"set":[["layout.css.sticky.enabled", true]]}, function() {
+  document.getElementById("iframe").src = "file_position_sticky.html";
+});
 
 function finish() {
-  SpecialPowers.clearUserPref("layout.css.sticky.enabled");
   SimpleTest.finish();
 }
 </script>
 </pre>
 </body>
 </html>
--- a/layout/style/test/test_visited_pref.html
+++ b/layout/style/test/test_visited_pref.html
@@ -16,36 +16,30 @@ https://bugzilla.mozilla.org/show_bug.cg
 
   </style>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=147777">Mozilla Bug 147777</a>
 <iframe id="iframe" src="visited-pref-iframe.html" style="width: 10em; height: 5em"></iframe>
 <pre id="test">
 <script type="application/javascript">
-
 /** Test for Bug 147777 **/
 
 function reinsert_node(e) {
   var sib = e.nextSibling;
   var par = e.parentNode;
   par.removeChild(e);
   par.insertBefore(e, sib);
 }
 
 function get_pref()
 {
     return SpecialPowers.getBoolPref("layout.css.visited_links_enabled");
 }
 
-function set_pref(val)
-{
-    SpecialPowers.setBoolPref("layout.css.visited_links_enabled", val);
-}
-
 function snapshotsEqual(snap1, snap2)
 {
   return compareSnapshots(snap1, snap2, true)[0];
 }
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestFlakyTimeout("untriaged");
 window.addEventListener("load", step1, false);
@@ -85,39 +79,34 @@ function poll_for_visited_style()
     // hasn't been styled yet
     setTimeout(poll_for_visited_style, 100);
 
     // If it never gets styled correctly, this test will fail because
     // this loop will never complete.
   } else {
     var end = Date.now();
     timeout = 3 * Math.max(end - start, 300);
-    step2();
+    SpecialPowers.pushPrefEnv({"set":[["layout.css.visited_links_enabled", false]]}, step2);
   }
 }
 
 function step2()
 {
-  set_pref(false);
-
   // we don't handle dynamic changes of this pref; it only takes effect
   // when a new page loads
   reinsert_node(link);
 
   setTimeout(step3, timeout);
 }
 
 function step3()
 {
   var snapshot = snapshotWindow(subwin, false);
   ok(snapshotsEqual(unvisref, snapshot),
      ":visited selector does not apply given false preference");
 
-  // Set the pref back for the rest of the tests.
-  set_pref(true);
-
   SimpleTest.finish();
 }
 
 </script>
 </pre>
 </body>
 </html>