Bug 1517213 - Part 2 - Unify which preferences are used for tests. r=bgrins
☠☠ backed out by 39d6e47b5bf4 ☠ ☠
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Wed, 02 Jan 2019 11:53:39 +0000
changeset 509537 8dcd5d5e815ddea060c89a7cffd2d075aadf8ab2
parent 509536 f0489fc1ef50db55b5af0e3d0a741ed1ab23b3e3
child 509538 798c09311606328e8c7374468b16859113ab883c
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1517213
milestone66.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 1517213 - Part 2 - Unify which preferences are used for tests. r=bgrins Differential Revision: https://phabricator.services.mozilla.com/D15570
browser/components/aboutconfig/test/browser/browser_basic.js
browser/components/aboutconfig/test/browser/browser_edit.js
browser/components/aboutconfig/test/browser/browser_locked.js
browser/components/aboutconfig/test/browser/head.js
--- a/browser/components/aboutconfig/test/browser/browser_basic.js
+++ b/browser/components/aboutconfig/test/browser/browser_basic.js
@@ -1,51 +1,49 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 add_task(async function setup() {
   await SpecialPowers.pushPrefEnv({
     set: [
-      ["random.user.pref", "chrome://test/locale/testing.properties"],
+      ["test.aboutconfig.userValueLikeLocalized",
+       "chrome://test/locale/testing.properties"],
     ],
   });
 });
 
 add_task(async function test_load_title() {
   await AboutConfigTest.withNewTab(async function() {
     Assert.equal(this.document.title, "about:config");
   });
 });
 
 add_task(async function test_load_settings() {
   await AboutConfigTest.withNewTab(async function() {
     // Test if page contains elements.
-    Assert.ok(this.getRow("plugins.testmode"));
-    Assert.ok(this.getRow("dom.vr.enabled"));
-    Assert.ok(this.getRow("accessibility.AOM.enabled"));
+    Assert.equal(this.getRow(PREF_NUMBER_DEFAULT_ZERO).value, 0);
+    Assert.equal(this.getRow(PREF_STRING_DEFAULT_EMPTY).value, "");
 
     // Test if the modified state is displayed for the right prefs.
-    let prefArray = Services.prefs.getChildList("");
-    let nameOfEdited = prefArray.find(
-      name => Services.prefs.prefHasUserValue(name));
-    let nameOfDefault = prefArray.find(
-      name => !Services.prefs.prefHasUserValue(name));
-    Assert.ok(!this.getRow(nameOfDefault).hasClass("has-user-value"));
-    Assert.ok(this.getRow(nameOfEdited).hasClass("has-user-value"));
+    Assert.ok(!this.getRow(PREF_BOOLEAN_DEFAULT_TRUE)
+                   .hasClass("has-user-value"));
+    Assert.ok(this.getRow(PREF_BOOLEAN_USERVALUE_TRUE)
+                  .hasClass("has-user-value"));
 
-    // Test to see if values are localized.
+    // Test to see if values are localized, sampling from different files. If
+    // any of these are removed or their value changes, just update the value
+    // here or point to a different preference in the same file.
     Assert.equal(this.getRow("font.language.group").value, "x-western");
     Assert.equal(this.getRow("intl.ellipsis").value, "\u2026");
     Assert.equal(
       this.getRow("gecko.handlerService.schemes.mailto.1.uriTemplate").value,
       "https://mail.google.com/mail/?extsrc=mailto&url=%s");
 
     // Test to see if user created value is not empty string when it matches
     // /^chrome:\/\/.+\/locale\/.+\.properties/.
-    Assert.equal(this.getRow("random.user.pref").value,
+    Assert.equal(this.getRow("test.aboutconfig.userValueLikeLocalized").value,
       "chrome://test/locale/testing.properties");
 
     // Test to see if empty string when value matches
     // /^chrome:\/\/.+\/locale\/.+\.properties/ and an exception is thrown.
-    Assert.equal(this.getRow("gecko.handlerService.schemes.irc.1.name").value,
-      "");
+    Assert.equal(this.getRow(PREF_STRING_LOCALIZED_MISSING).value, "");
   });
 });
--- a/browser/components/aboutconfig/test/browser/browser_edit.js
+++ b/browser/components/aboutconfig/test/browser/browser_edit.js
@@ -6,19 +6,19 @@ add_task(async function setup() {
     set: [
       ["test.aboutconfig.modify.boolean", true],
       ["test.aboutconfig.modify.number", 1337],
       ["test.aboutconfig.modify.string", "the answer to the life the universe and everything"],
     ],
   });
 
   registerCleanupFunction(() => {
-    Services.prefs.clearUserPref("accessibility.typeaheadfind.autostart");
-    Services.prefs.clearUserPref("accessibility.typeaheadfind.soundURL");
-    Services.prefs.clearUserPref("accessibility.typeaheadfind.casesensitive");
+    Services.prefs.clearUserPref(PREF_BOOLEAN_DEFAULT_TRUE);
+    Services.prefs.clearUserPref(PREF_NUMBER_DEFAULT_ZERO);
+    Services.prefs.clearUserPref(PREF_STRING_DEFAULT_EMPTY);
   });
 });
 
 add_task(async function test_add_user_pref() {
   await AboutConfigTest.withNewTab(async function() {
     Assert.ok(!Services.prefs.getChildList("").find(pref => pref == "testPref"));
 
     for (let [buttonSelector, expectedValue] of [
@@ -46,44 +46,48 @@ add_task(async function test_delete_user
 
     // Search for nothing to test gPrefArray
     this.search();
     Assert.ok(!this.getRow("userAddedPref"));
   });
 });
 
 add_task(async function test_reset_user_pref() {
-  await SpecialPowers.pushPrefEnv({"set": [["browser.autofocus", false]]});
+  await SpecialPowers.pushPrefEnv({
+    "set": [
+      [PREF_BOOLEAN_DEFAULT_TRUE, false],
+    ],
+  });
 
   await AboutConfigTest.withNewTab(async function() {
     let testPref = "browser.autofocus";
     // Click reset.
-    let row = this.getRow(testPref);
+    let row = this.getRow(PREF_BOOLEAN_DEFAULT_TRUE);
     row.resetColumnButton.click();
     // Check new layout and reset.
     Assert.ok(!row.hasClass("has-user-value"));
     Assert.ok(!row.resetColumnButton);
-    Assert.ok(!Services.prefs.prefHasUserValue(testPref));
-    Assert.equal(this.getRow(testPref).value, "" + Preferences.get(testPref));
+    Assert.ok(!Services.prefs.prefHasUserValue(PREF_BOOLEAN_DEFAULT_TRUE));
+    Assert.equal(this.getRow(PREF_BOOLEAN_DEFAULT_TRUE).value, "true");
 
     // Search for nothing to test gPrefArray
     this.search();
-    row = this.getRow(testPref);
+    row = this.getRow(PREF_BOOLEAN_DEFAULT_TRUE);
     Assert.ok(!row.hasClass("has-user-value"));
     Assert.ok(!row.resetColumnButton);
-    Assert.equal(this.getRow(testPref).value, "" + Preferences.get(testPref));
+    Assert.equal(this.getRow(PREF_BOOLEAN_DEFAULT_TRUE).value, "true");
   });
 });
 
 add_task(async function test_modify() {
   await AboutConfigTest.withNewTab(async function() {
     // Test toggle for boolean prefs.
     for (let nameOfBoolPref of [
       "test.aboutconfig.modify.boolean",
-      "accessibility.typeaheadfind.autostart",
+      PREF_BOOLEAN_DEFAULT_TRUE,
     ]) {
       let row = this.getRow(nameOfBoolPref);
       // Do this a two times to reset the pref.
       for (let i = 0; i < 2; i++) {
         row.editColumnButton.click();
         // Check new layout and saving in backend.
         Assert.equal(this.getRow(nameOfBoolPref).value,
           "" + Preferences.get(nameOfBoolPref));
@@ -108,18 +112,18 @@ add_task(async function test_modify() {
     intRow.valueInput.value += "a";
     intRow.editColumnButton.click();
     Assert.ok(!intRow.valueInput.checkValidity());
 
     // Test correct saving and DOM-update.
     for (let prefName of [
       "test.aboutconfig.modify.string",
       "test.aboutconfig.modify.number",
-      "accessibility.typeaheadfind.soundURL",
-      "accessibility.typeaheadfind.casesensitive",
+      PREF_NUMBER_DEFAULT_ZERO,
+      PREF_STRING_DEFAULT_EMPTY,
     ]) {
       row = this.getRow(prefName);
       // Activate edit and check displaying.
       row.editColumnButton.click();
       Assert.equal(row.valueInput.value, Preferences.get(prefName));
       row.valueInput.value = "42";
       // Save and check saving.
       row.editColumnButton.click();
--- a/browser/components/aboutconfig/test/browser/browser_locked.js
+++ b/browser/components/aboutconfig/test/browser/browser_locked.js
@@ -1,51 +1,54 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
+const PREF_STRING_NO_DEFAULT = "test.aboutconfig.a";
+
 add_task(async function setup() {
   await SpecialPowers.pushPrefEnv({
     set: [
-      ["test.aboutconfig.a", "some value"],
+      [PREF_STRING_NO_DEFAULT, "some value"],
     ],
   });
 });
 
 add_task(async function test_locked() {
   registerCleanupFunction(() => {
-    Services.prefs.unlockPref("browser.search.searchEnginesURL");
-    Services.prefs.unlockPref("test.aboutconfig.a");
-    Services.prefs.unlockPref("accessibility.AOM.enabled");
+    Services.prefs.unlockPref(PREF_STRING_DEFAULT_NOTEMPTY);
+    Services.prefs.unlockPref(PREF_BOOLEAN_DEFAULT_TRUE);
+    Services.prefs.unlockPref(PREF_STRING_NO_DEFAULT);
   });
 
-  Services.prefs.lockPref("browser.search.searchEnginesURL");
-  Services.prefs.lockPref("test.aboutconfig.a");
-  Services.prefs.lockPref("accessibility.AOM.enabled");
+  Services.prefs.lockPref(PREF_STRING_DEFAULT_NOTEMPTY);
+  Services.prefs.lockPref(PREF_BOOLEAN_DEFAULT_TRUE);
+  Services.prefs.lockPref(PREF_STRING_NO_DEFAULT);
+
   await AboutConfigTest.withNewTab(async function() {
     // Test locked default string pref.
-    let lockedPref = this.getRow("browser.search.searchEnginesURL");
+    let lockedPref = this.getRow(PREF_STRING_DEFAULT_NOTEMPTY);
     Assert.ok(lockedPref.hasClass("locked"));
-    Assert.equal(lockedPref.value, "https://addons.mozilla.org/%LOCALE%/firefox/search-engines/");
+    Assert.equal(lockedPref.value, PREF_STRING_DEFAULT_NOTEMPTY_VALUE);
     Assert.ok(lockedPref.editColumnButton.classList.contains("button-edit"));
     Assert.ok(lockedPref.editColumnButton.disabled);
 
     // Test locked default boolean pref.
-    lockedPref = this.getRow("accessibility.AOM.enabled");
+    lockedPref = this.getRow(PREF_BOOLEAN_DEFAULT_TRUE);
     Assert.ok(lockedPref.hasClass("locked"));
-    Assert.equal(lockedPref.value, "false");
+    Assert.equal(lockedPref.value, "true");
     Assert.ok(lockedPref.editColumnButton.classList.contains("button-toggle"));
     Assert.ok(lockedPref.editColumnButton.disabled);
 
     // Test locked user added pref.
-    lockedPref = this.getRow("test.aboutconfig.a");
+    lockedPref = this.getRow(PREF_STRING_NO_DEFAULT);
     Assert.ok(lockedPref.hasClass("locked"));
     Assert.equal(lockedPref.value, "");
     Assert.ok(lockedPref.editColumnButton.classList.contains("button-edit"));
     Assert.ok(lockedPref.editColumnButton.disabled);
 
-    // Test pref not locked
-    let unlockedPref = this.getRow("accessibility.indicator.enabled");
+    // Test pref not locked.
+    let unlockedPref = this.getRow(PREF_BOOLEAN_USERVALUE_TRUE);
     Assert.ok(!unlockedPref.hasClass("locked"));
-    Assert.equal(unlockedPref.value, "false");
+    Assert.equal(unlockedPref.value, "true");
     Assert.ok(unlockedPref.editColumnButton.classList.contains("button-toggle"));
     Assert.ok(!unlockedPref.editColumnButton.disabled);
   });
 });
--- a/browser/components/aboutconfig/test/browser/head.js
+++ b/browser/components/aboutconfig/test/browser/head.js
@@ -1,15 +1,27 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/Preferences.jsm", this);
 
+// List of default preferences that can be used for tests, chosen because they
+// have little or no side-effects when they are modified for a brief time. If
+// any of these preferences are removed or their default state changes, just
+// update the constant to point to a different preference with the same default.
+const PREF_BOOLEAN_DEFAULT_TRUE = "accessibility.typeaheadfind.manual";
+const PREF_BOOLEAN_USERVALUE_TRUE = "browser.dom.window.dump.enabled";
+const PREF_NUMBER_DEFAULT_ZERO = "accessibility.typeaheadfind.casesensitive";
+const PREF_STRING_DEFAULT_EMPTY = "browser.helperApps.neverAsk.openFile";
+const PREF_STRING_DEFAULT_NOTEMPTY = "accessibility.typeaheadfind.soundURL";
+const PREF_STRING_DEFAULT_NOTEMPTY_VALUE = "beep";
+const PREF_STRING_LOCALIZED_MISSING = "gecko.handlerService.schemes.irc.1.name";
+
 class AboutConfigRowTest {
   constructor(element) {
     this.element = element;
   }
 
   querySelector(selector) {
     return this.element.querySelector(selector);
   }