Bug 1517213 - Part 1 - Share more selectors in tests. r=bgrins
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Wed, 02 Jan 2019 09:57:59 +0000
changeset 509543 30a9b6900d37b20ecab168bc88ebbf3c48ee133c
parent 509542 5a87bebb7cffffe9556ad541766a884743b505cd
child 509544 64f0c0341dc8933fc888636426dc2b27f99cf720
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 1 - Share more selectors in tests. r=bgrins Differential Revision: https://phabricator.services.mozilla.com/D15569
browser/components/aboutconfig/test/browser/browser_edit.js
browser/components/aboutconfig/test/browser/browser_locked.js
browser/components/aboutconfig/test/browser/browser_search.js
browser/components/aboutconfig/test/browser/head.js
--- a/browser/components/aboutconfig/test/browser/browser_edit.js
+++ b/browser/components/aboutconfig/test/browser/browser_edit.js
@@ -35,101 +35,98 @@ add_task(async function test_add_user_pr
     }
   });
 });
 
 add_task(async function test_delete_user_pref() {
   Services.prefs.setBoolPref("userAddedPref", true);
   await AboutConfigTest.withNewTab(async function() {
     let row = this.getRow("userAddedPref");
-    row.element.lastChild.lastChild.click();
+    row.resetColumnButton.click();
     Assert.ok(!this.getRow("userAddedPref"));
     Assert.ok(!Services.prefs.getChildList("").includes("userAddedPref"));
 
     // 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 AboutConfigTest.withNewTab(async function() {
     let testPref = "browser.autofocus";
     // Click reset.
     let row = this.getRow(testPref);
-    row.element.lastChild.lastChild.click();
+    row.resetColumnButton.click();
     // Check new layout and reset.
     Assert.ok(!row.hasClass("has-user-value"));
-    Assert.equal(row.element.lastChild.childNodes.length, 0);
+    Assert.ok(!row.resetColumnButton);
     Assert.ok(!Services.prefs.prefHasUserValue(testPref));
     Assert.equal(this.getRow(testPref).value, "" + Preferences.get(testPref));
 
     // Search for nothing to test gPrefArray
     this.search();
     row = this.getRow(testPref);
     Assert.ok(!row.hasClass("has-user-value"));
-    Assert.equal(row.element.lastChild.childNodes.length, 0);
+    Assert.ok(!row.resetColumnButton);
     Assert.equal(this.getRow(testPref).value, "" + Preferences.get(testPref));
   });
 });
 
 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",
     ]) {
       let row = this.getRow(nameOfBoolPref);
       // Do this a two times to reset the pref.
       for (let i = 0; i < 2; i++) {
-        row.querySelector("td.cell-edit").firstChild.click();
+        row.editColumnButton.click();
         // Check new layout and saving in backend.
         Assert.equal(this.getRow(nameOfBoolPref).value,
           "" + Preferences.get(nameOfBoolPref));
         let prefHasUserValue = Services.prefs.prefHasUserValue(nameOfBoolPref);
         Assert.equal(row.hasClass("has-user-value"), prefHasUserValue);
-        Assert.equal(row.element.lastChild.childNodes.length > 0, prefHasUserValue);
+        Assert.equal(!!row.resetColumnButton, prefHasUserValue);
       }
     }
 
     // Test abort of edit by starting with string and continuing with editing Int pref.
     let row = this.getRow("test.aboutconfig.modify.string");
-    row.querySelector("td.cell-edit").firstChild.click();
-    row.querySelector("td.cell-value").firstChild.firstChild.value = "test";
+    row.editColumnButton.click();
+    row.valueInput.value = "test";
     let intRow = this.getRow("test.aboutconfig.modify.number");
-    intRow.querySelector("td.cell-edit").firstChild.click();
-    Assert.equal(intRow.querySelector("td.cell-value").firstChild.firstChild.value,
+    intRow.editColumnButton.click();
+    Assert.equal(intRow.valueInput.value,
       Preferences.get("test.aboutconfig.modify.number"));
-    Assert.equal(this.getRow("test.aboutconfig.modify.string").value,
-      "" + Preferences.get("test.aboutconfig.modify.string"));
-    Assert.equal(row.querySelector("td.cell-value").textContent,
-      Preferences.get("test.aboutconfig.modify.string"));
+    Assert.ok(!row.valueInput);
+    Assert.equal(row.value, Preferences.get("test.aboutconfig.modify.string"));
 
     // Test regex check for Int pref.
-    intRow.querySelector("td.cell-value").firstChild.firstChild.value += "a";
-    intRow.querySelector("td.cell-edit").firstChild.click();
-    Assert.ok(!intRow.querySelector("td.cell-value").firstChild.firstChild.checkValidity());
+    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",
     ]) {
       row = this.getRow(prefName);
       // Activate edit and check displaying.
-      row.querySelector("td.cell-edit").firstChild.click();
-      Assert.equal(row.querySelector("td.cell-value").firstChild.firstChild.value,
-        Preferences.get(prefName));
-      row.querySelector("td.cell-value").firstChild.firstChild.value = "42";
+      row.editColumnButton.click();
+      Assert.equal(row.valueInput.value, Preferences.get(prefName));
+      row.valueInput.value = "42";
       // Save and check saving.
-      row.querySelector("td.cell-edit").firstChild.click();
+      row.editColumnButton.click();
       Assert.equal(row.value, "" + Preferences.get(prefName));
       let prefHasUserValue = Services.prefs.prefHasUserValue(prefName);
-      Assert.equal(row.element.lastChild.childNodes.length > 0, prefHasUserValue);
+      Assert.equal(!!row.resetColumnButton, prefHasUserValue);
       Assert.equal(row.hasClass("has-user-value"), prefHasUserValue);
     }
   });
 });
--- a/browser/components/aboutconfig/test/browser/browser_locked.js
+++ b/browser/components/aboutconfig/test/browser/browser_locked.js
@@ -19,33 +19,33 @@ add_task(async function test_locked() {
   Services.prefs.lockPref("browser.search.searchEnginesURL");
   Services.prefs.lockPref("test.aboutconfig.a");
   Services.prefs.lockPref("accessibility.AOM.enabled");
   await AboutConfigTest.withNewTab(async function() {
     // Test locked default string pref.
     let lockedPref = this.getRow("browser.search.searchEnginesURL");
     Assert.ok(lockedPref.hasClass("locked"));
     Assert.equal(lockedPref.value, "https://addons.mozilla.org/%LOCALE%/firefox/search-engines/");
-    Assert.ok(lockedPref.firstButton.classList.contains("button-edit"));
-    Assert.ok(lockedPref.firstButton.disabled);
+    Assert.ok(lockedPref.editColumnButton.classList.contains("button-edit"));
+    Assert.ok(lockedPref.editColumnButton.disabled);
 
     // Test locked default boolean pref.
     lockedPref = this.getRow("accessibility.AOM.enabled");
     Assert.ok(lockedPref.hasClass("locked"));
     Assert.equal(lockedPref.value, "false");
-    Assert.ok(lockedPref.firstButton.classList.contains("button-toggle"));
-    Assert.ok(lockedPref.firstButton.disabled);
+    Assert.ok(lockedPref.editColumnButton.classList.contains("button-toggle"));
+    Assert.ok(lockedPref.editColumnButton.disabled);
 
     // Test locked user added pref.
     lockedPref = this.getRow("test.aboutconfig.a");
     Assert.ok(lockedPref.hasClass("locked"));
     Assert.equal(lockedPref.value, "");
-    Assert.ok(lockedPref.firstButton.classList.contains("button-edit"));
-    Assert.ok(lockedPref.firstButton.disabled);
+    Assert.ok(lockedPref.editColumnButton.classList.contains("button-edit"));
+    Assert.ok(lockedPref.editColumnButton.disabled);
 
     // Test pref not locked
     let unlockedPref = this.getRow("accessibility.indicator.enabled");
     Assert.ok(!unlockedPref.hasClass("locked"));
     Assert.equal(unlockedPref.value, "false");
-    Assert.ok(unlockedPref.firstButton.classList.contains("button-toggle"));
-    Assert.ok(!unlockedPref.firstButton.disabled);
+    Assert.ok(unlockedPref.editColumnButton.classList.contains("button-toggle"));
+    Assert.ok(!unlockedPref.editColumnButton.disabled);
   });
 });
--- a/browser/components/aboutconfig/test/browser/browser_search.js
+++ b/browser/components/aboutconfig/test/browser/browser_search.js
@@ -9,17 +9,16 @@ add_task(async function setup() {
       ["test.aboutconfig.b", "test value 3"],
     ],
   });
 });
 
 add_task(async function test_search() {
   await AboutConfigTest.withNewTab(async function() {
     let prefArray = Services.prefs.getChildList("");
-    await this.document.querySelector("button").click();
 
     // The total number of preferences may change at any time because of
     // operations running in the background, so we only test approximately.
     // The change in count would be because of one or two added preferences,
     // but we tolerate a difference of up to 50 preferences just to be safe.
     // We want thousands of prefs instead of a few dozen that are filtered.
     Assert.greater(this.rows.length, prefArray.length - 50);
 
--- a/browser/components/aboutconfig/test/browser/head.js
+++ b/browser/components/aboutconfig/test/browser/head.js
@@ -17,18 +17,36 @@ class AboutConfigRowTest {
   get name() {
     return this.querySelector("td").textContent;
   }
 
   get value() {
     return this.querySelector("td.cell-value").textContent;
   }
 
-  get firstButton() {
-    return this.querySelector("button");
+  /**
+   * Text input field when the row is in edit mode.
+   */
+  get valueInput() {
+    return this.querySelector("td.cell-value input");
+  }
+
+  /**
+   * This is normally "edit" or "toggle" based on the preference type, or "save"
+   * when the row is in edit mode.
+   */
+  get editColumnButton() {
+    return this.querySelector("td.cell-edit > button");
+  }
+
+  /**
+   * This can be "reset" or "delete" based on whether a default exists.
+   */
+  get resetColumnButton() {
+    return this.querySelector("td:last-child > button");
   }
 
   hasClass(className) {
     return this.element.classList.contains(className);
   }
 }
 
 class AboutConfigTest {