Bug 1360846 - Make the prefs restore to default value before run the tests. r=jaws
authorEvan Tseng <evan@tseng.io>
Mon, 08 May 2017 10:28:32 -0400
changeset 357533 8e7840392d2e
parent 357532 d9cb7e835d4c
child 357534 a5a5759c9547
push id90142
push userryanvm@gmail.com
push date2017-05-10 17:22 +0000
treeherdermozilla-inbound@a5a5759c9547 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1360846
milestone55.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 1360846 - Make the prefs restore to default value before run the tests. r=jaws MozReview-Commit-ID: 8a8gwTE5F9D
browser/components/preferences/in-content/tests/browser_performance.js
--- a/browser/components/preferences/in-content/tests/browser_performance.js
+++ b/browser/components/preferences/in-content/tests/browser_performance.js
@@ -1,13 +1,18 @@
-SpecialPowers.pushPrefEnv({set: [
-  ["browser.preferences.defaultPerformanceSettings.enabled", true],
-  ["dom.ipc.processCount", 4],
-  ["layers.acceleration.disabled", false],
-]});
+const DEFAULT_HW_ACCEL_PREF = Services.prefs.getDefaultBranch(null).getBoolPref("layers.acceleration.disabled");
+const DEFAULT_PROCESS_COUNT = Services.prefs.getDefaultBranch(null).getIntPref("dom.ipc.processCount");
+
+add_task(function*() {
+  yield SpecialPowers.pushPrefEnv({set: [
+    ["layers.acceleration.disabled", DEFAULT_HW_ACCEL_PREF],
+    ["dom.ipc.processCount", DEFAULT_PROCESS_COUNT],
+    ["browser.preferences.defaultPerformanceSettings.enabled", true],
+  ]});
+});
 
 add_task(function*() {
   let prefs = yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
   is(prefs.selectedPane, "paneGeneral", "General pane was selected");
 
   let doc = gBrowser.contentDocument;
   let useRecommendedPerformanceSettings = doc.querySelector("#useRecommendedPerformanceSettings");
 
@@ -20,43 +25,46 @@ add_task(function*() {
   let performanceSettings = doc.querySelector("#performanceSettings");
   is(performanceSettings.hidden, false, "performance settings section is shown");
 
   is(Services.prefs.getBoolPref("browser.preferences.defaultPerformanceSettings.enabled"), false,
      "pref value should be false after clicking on checkbox");
   ok(!useRecommendedPerformanceSettings.checked, "checkbox should not be checked after clicking on checkbox");
 
   let allowHWAccel = doc.querySelector("#allowHWAccel");
-  is(Services.prefs.getBoolPref("layers.acceleration.disabled"), false,
-    "pref value should be false before clicking on checkbox");
-  ok(allowHWAccel.checked, "checkbox should be checked");
+  let allowHWAccelPref = Services.prefs.getBoolPref("layers.acceleration.disabled");
+  is(allowHWAccelPref, DEFAULT_HW_ACCEL_PREF,
+    "pref value should be the default value before clicking on checkbox");
+  is(allowHWAccel.checked, !DEFAULT_HW_ACCEL_PREF, "checkbox should show the invert of the default value");
 
   let contentProcessCount = doc.querySelector("#contentProcessCount");
-  is(Services.prefs.getIntPref("dom.ipc.processCount"), 4, "default pref value should be default value");
-  is(contentProcessCount.selectedItem.value, 4, "selected item should be the default one");
+  is(Services.prefs.getIntPref("dom.ipc.processCount"), DEFAULT_PROCESS_COUNT, "default pref value should be default value");
+  is(contentProcessCount.selectedItem.value, DEFAULT_PROCESS_COUNT, "selected item should be the default one");
 
   allowHWAccel.click();
-  is(Services.prefs.getBoolPref("layers.acceleration.disabled"), true,
-    "pref value should be true after clicking on checkbox");
-  ok(!allowHWAccel.checked, "checkbox should not be checked");
+  allowHWAccelPref = Services.prefs.getBoolPref("layers.acceleration.disabled");
+  is(allowHWAccelPref, !DEFAULT_HW_ACCEL_PREF,
+    "pref value should be opposite of the default value after clicking on checkbox");
+  is(allowHWAccel.checked, !allowHWAccelPref, "checkbox should show the invert of the current value");
 
   contentProcessCount.value = 7;
   contentProcessCount.doCommand();
   is(Services.prefs.getIntPref("dom.ipc.processCount"), 7, "pref value should be 7");
   is(contentProcessCount.selectedItem.value, 7, "selected item should be 7");
 
   allowHWAccel.click();
-  is(Services.prefs.getBoolPref("layers.acceleration.disabled"), false,
-    "pref value should be false after clicking on checkbox");
-  ok(allowHWAccel.checked, "checkbox should not be checked");
+  allowHWAccelPref = Services.prefs.getBoolPref("layers.acceleration.disabled");
+  is(allowHWAccelPref, DEFAULT_HW_ACCEL_PREF,
+    "pref value should be the default value after clicking on checkbox");
+  is(allowHWAccel.checked, !allowHWAccelPref, "checkbox should show the invert of the current value");
 
-  contentProcessCount.value = 4;
+  contentProcessCount.value = DEFAULT_PROCESS_COUNT;
   contentProcessCount.doCommand();
-  is(Services.prefs.getIntPref("dom.ipc.processCount"), 4, "pref value should be default value");
-  is(contentProcessCount.selectedItem.value, 4, "selected item should be default one");
+  is(Services.prefs.getIntPref("dom.ipc.processCount"), DEFAULT_PROCESS_COUNT, "pref value should be default value");
+  is(contentProcessCount.selectedItem.value, DEFAULT_PROCESS_COUNT, "selected item should be default one");
 
   is(performanceSettings.hidden, false, "performance settings section should be still shown");
 
   Services.prefs.setBoolPref("browser.preferences.defaultPerformanceSettings.enabled", true);
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 add_task(function*() {