Bug 1516957 - Part 4 - Share the search function. r=bgrins
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 31 Dec 2018 12:15:50 +0000
changeset 509342 c1a87fe81d16a114e8df100a1ee9ce29a90f275d
parent 509341 dda920bc62ddcb484abc9622e1c47f3fb0f47b0e
child 509343 9781b1970089c2186ab5b3ffa79532f2e0bc0a0f
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
bugs1516957
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 1516957 - Part 4 - Share the search function. r=bgrins Differential Revision: https://phabricator.services.mozilla.com/D15516
browser/components/aboutconfig/test/browser/browser_edit.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
@@ -15,52 +15,42 @@ add_task(async function setup() {
     Services.prefs.clearUserPref("accessibility.typeaheadfind.soundURL");
     Services.prefs.clearUserPref("accessibility.typeaheadfind.casesensitive");
   });
 });
 
 add_task(async function test_add_user_pref() {
   await AboutConfigTest.withNewTab(async function() {
     Assert.ok(!Services.prefs.getChildList("").find(pref => pref == "testPref"));
-    let search = this.document.getElementById("search");
-    search.value = "testPref";
-    search.focus();
 
     for (let [buttonSelector, expectedValue] of [
       [".add-true", true],
       [".add-false", false],
       [".add-Number", 0],
       [".add-String", ""],
     ]) {
-      EventUtils.sendKey("return");
-
+      this.search("testPref");
       this.document.querySelector("#prefs button" + buttonSelector).click();
       Assert.ok(Services.prefs.getChildList("").find(pref => pref == "testPref"));
       Assert.ok(Preferences.get("testPref") === expectedValue);
       this.document.querySelector("#prefs button[data-l10n-id='about-config-pref-delete']").click();
-      search = this.document.getElementById("search");
-      search.value = "testPref";
-      search.focus();
     }
   });
 });
 
 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();
     Assert.ok(!this.getRow("userAddedPref"));
     Assert.ok(!Services.prefs.getChildList("").includes("userAddedPref"));
 
     // Search for nothing to test gPrefArray
-    let search = this.document.getElementById("search");
-    search.focus();
-    EventUtils.sendKey("return");
-
+    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() {
@@ -70,21 +60,17 @@ add_task(async function test_reset_user_
     row.element.lastChild.lastChild.click();
     // Check new layout and reset.
     Assert.ok(!row.hasClass("has-user-value"));
     Assert.equal(row.element.lastChild.childNodes.length, 0);
     Assert.ok(!Services.prefs.prefHasUserValue(testPref));
     Assert.equal(this.getRow(testPref).value, "" + Preferences.get(testPref));
 
     // Search for nothing to test gPrefArray
-    let search = this.document.getElementById("search");
-    search.focus();
-    EventUtils.sendKey("return");
-
-    // Check new layout and reset.
+    this.search();
     row = this.getRow(testPref);
     Assert.ok(!row.hasClass("has-user-value"));
     Assert.equal(row.element.lastChild.childNodes.length, 0);
     Assert.equal(this.getRow(testPref).value, "" + Preferences.get(testPref));
   });
 });
 
 add_task(async function test_modify() {
--- a/browser/components/aboutconfig/test/browser/browser_search.js
+++ b/browser/components/aboutconfig/test/browser/browser_search.js
@@ -21,48 +21,37 @@ add_task(async function test_search() {
     // 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);
 
     // Filter a subset of preferences. The "browser.download." branch is
     // chosen because it is very unlikely that its preferences would be
     // modified by other code during the execution of this test.
-    let search = this.document.getElementById("search");
-    search.value = "wser.down   ";
-    search.focus();
-    EventUtils.sendKey("return");
+    this.search("wser.down   ");
 
     let filteredPrefArray =
         prefArray.filter(pref => pref.includes("wser.down"));
     // Adding +1 to the list since button does not match an exact
     // preference name then a row is added for the user to add a
     // new button preference if desired
     Assert.equal(this.rows.length, filteredPrefArray.length + 1);
 
     // Test empty search returns all preferences.
-    search.value = "";
-    search.focus();
-    EventUtils.sendKey("return");
+    this.search();
 
     // 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);
 
     // Test invalid search returns no preferences.
-    search.value = "aJunkValueasdf";
-    search.focus();
-    EventUtils.sendKey("return");
-
-    // Expecting 1 row to be returned since it offers the ability to add
+    // Expecting 1 row to be returned since it offers the ability to add.
+    this.search("aJunkValueasdf");
     Assert.equal(this.rows.length, 1);
 
     // Test added preferences search returns 2 preferences.
-    search.value = "test.aboutconfig.a";
-    search.focus();
-    EventUtils.sendKey("return");
-
+    this.search("test.aboutconfig.a");
     Assert.equal(this.rows.length, 2);
   });
 });
--- a/browser/components/aboutconfig/test/browser/head.js
+++ b/browser/components/aboutconfig/test/browser/head.js
@@ -65,9 +65,20 @@ class AboutConfigTest {
 
   /**
    * Returns the AboutConfigRowTest object for the row in the main table which
    * corresponds to the given preference name, or undefined if none is present.
    */
   getRow(name) {
     return this.rows.find(row => row.name == name);
   }
+
+  /**
+   * Performs a new search using the dedicated textbox. This also makes sure
+   * that the list of preferences displayed is up to date.
+   */
+  search(value = "") {
+    let search = this.document.getElementById("search");
+    search.value = value;
+    search.focus();
+    EventUtils.sendKey("return");
+  }
 }