Bug 1073859 - Store/restore original pref values rather than resetting them rs=jseup
authorAdam Roach [:abr] <adam@nostrum.com>
Tue, 07 Oct 2014 16:20:03 -0500
changeset 209208 c90e0b3556b87d0235cdc16f679061184ff51cc8
parent 209207 1198bd62f42a8b2a2d0fcf584bb4b273d2cf8d3e
child 209209 4b203cdd7d7d902617d2595e17f224b466b42ec1
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjseup
bugs1073859
milestone35.0a1
Bug 1073859 - Store/restore original pref values rather than resetting them rs=jseup
browser/components/loop/test/mochitest/browser_mozLoop_softStart.js
--- a/browser/components/loop/test/mochitest/browser_mozLoop_softStart.js
+++ b/browser/components/loop/test/mochitest/browser_mozLoop_softStart.js
@@ -51,26 +51,27 @@ let runCheck = function(expectError) {
       } else {
         resolve(error);
       }
     })
   });
 }
 
 add_task(function* test_mozLoop_softStart() {
+  let orig_throttled = Services.prefs.getBoolPref("loop.throttled");
+
   // Set associated variables to proper values
   Services.prefs.setBoolPref("loop.throttled", true);
   Services.prefs.setCharPref("loop.soft_start_hostname", SOFT_START_HOSTNAME);
   Services.prefs.setIntPref("loop.soft_start_ticket_number", -1);
 
   registerCleanupFunction(function () {
-    Services.prefs.clearUserPref("loop.throttled");
-    Services.prefs.clearUserPref("loop.soft_start");
+    Services.prefs.setBoolPref("loop.throttled", orig_throttled);
+    Services.prefs.clearUserPref("loop.soft_start_ticket_number");
     Services.prefs.clearUserPref("loop.soft_start_hostname");
-    Services.prefs.clearUserPref("loop.soft_start_ticket_number");
   });
 
   let throttled;
   let ticket;
 
   info("Ensure that we pick a valid ticket number.");
   yield runCheck();
   throttled = Services.prefs.getBoolPref("loop.throttled");
@@ -79,17 +80,16 @@ add_task(function* test_mozLoop_softStar
   Assert.equal(throttled, true, "Feature should still be throttled");
   Assert.notEqual(ticket, -1, "Ticket should be changed");
   Assert.ok((ticket < 16777214 && ticket > 0), "Ticket should be in range");
 
   // Try some "interesting" ticket numbers
   for (ticket of [1, 256, 65535, 10000000, 16777214]) {
     MockButton.hidden = true;
     Services.prefs.setBoolPref("loop.throttled", true);
-    Services.prefs.setBoolPref("loop.soft_start", true);
     Services.prefs.setIntPref("loop.soft_start_ticket_number", ticket);
 
     info("Ensure that we don't activate when the now serving " +
          "number is less than our value.");
     MockDNSService.nowServing = ticket - 1;
     yield runCheck();
     throttled = Services.prefs.getBoolPref("loop.throttled");
     Assert.equal(MockButton.hidden, true, "Button should still be hidden");
@@ -111,27 +111,25 @@ add_task(function* test_mozLoop_softStar
     Assert.equal(MockButton.hidden, false, "Button should not be hidden");
     Assert.equal(throttled, false, "Feature should be unthrottled");
   }
 
   info("Check DNS error behavior");
   MockDNSService.nowServing = 0;
   MockDNSService.resultCode = 0x80000000;
   Services.prefs.setBoolPref("loop.throttled", true);
-  Services.prefs.setBoolPref("loop.soft_start", true);
   MockButton.hidden = true;
   yield runCheck(true);
   throttled = Services.prefs.getBoolPref("loop.throttled");
   Assert.equal(MockButton.hidden, true, "Button should be hidden");
   Assert.equal(throttled, true, "Feature should be throttled");
 
   info("Check DNS misconfiguration behavior");
   MockDNSService.nowServing = ticket + 1;
   MockDNSService.resultCode = 0;
   MockDNSService.ipFirstOctet = 6;
   Services.prefs.setBoolPref("loop.throttled", true);
-  Services.prefs.setBoolPref("loop.soft_start", true);
   MockButton.hidden = true;
   yield runCheck(true);
   throttled = Services.prefs.getBoolPref("loop.throttled");
   Assert.equal(MockButton.hidden, true, "Button should be hidden");
   Assert.equal(throttled, true, "Feature should be throttled");
 });