Bug 1553624 - Select current text when editing in about:config r=paolo,jaws
authorMark Striemer <mstriemer@mozilla.com>
Wed, 18 Sep 2019 17:49:44 +0000
changeset 493881 50045e12742d61222a4ab8d6314b7fd06238963c
parent 493880 d5dcfe3c0fe0c430df269537366a10ab51327b9c
child 493882 90984e8cdaec55e6664e9a177ea1085309fc20fd
push id95735
push usermstriemer@mozilla.com
push dateWed, 18 Sep 2019 17:51:10 +0000
treeherderautoland@90984e8cdaec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo, jaws
bugs1553624
milestone71.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 1553624 - Select current text when editing in about:config r=paolo,jaws Differential Revision: https://phabricator.services.mozilla.com/D45078
browser/components/aboutconfig/content/aboutconfig.js
browser/components/aboutconfig/test/browser/browser_edit.js
--- a/browser/components/aboutconfig/content/aboutconfig.js
+++ b/browser/components/aboutconfig/content/aboutconfig.js
@@ -346,17 +346,19 @@ class PrefRow {
 
   edit() {
     if (gPrefInEdit) {
       gPrefInEdit.endEdit();
     }
     gPrefInEdit = this;
     this.editing = true;
     this.refreshElement();
+    // The type=number input isn't selected unless it's focused first.
     this.inputField.focus();
+    this.inputField.select();
   }
 
   save() {
     if (this.type == "Number") {
       if (!this.inputField.reportValidity()) {
         return;
       }
       Services.prefs.setIntPref(this.name, parseInt(this.inputField.value));
--- a/browser/components/aboutconfig/test/browser/browser_edit.js
+++ b/browser/components/aboutconfig/test/browser/browser_edit.js
@@ -1,18 +1,22 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
+const PREF_MODIFY_BOOLEAN = "test.aboutconfig.modify.boolean";
+const PREF_MODIFY_NUMBER = "test.aboutconfig.modify.number";
+const PREF_MODIFY_STRING = "test.aboutconfig.modify.string";
+
 add_task(async function setup() {
   await SpecialPowers.pushPrefEnv({
     set: [
-      ["test.aboutconfig.modify.boolean", true],
-      ["test.aboutconfig.modify.number", 1337],
+      [PREF_MODIFY_BOOLEAN, true],
+      [PREF_MODIFY_NUMBER, 1337],
       [
-        "test.aboutconfig.modify.string",
+        PREF_MODIFY_STRING,
         "the answer to the life the universe and everything",
       ],
     ],
   });
 
   registerCleanupFunction(() => {
     Services.prefs.clearUserPref(PREF_BOOLEAN_DEFAULT_TRUE);
     Services.prefs.clearUserPref(PREF_NUMBER_DEFAULT_ZERO);
@@ -169,17 +173,17 @@ add_task(async function test_reset_user_
     Assert.equal(this.getRow(PREF_STRING_LOCALIZED_MISSING).value, "");
   });
 });
 
 add_task(async function test_modify() {
   await AboutConfigTest.withNewTab(async function() {
     // Test toggle for boolean prefs.
     for (let nameOfBoolPref of [
-      "test.aboutconfig.modify.boolean",
+      PREF_MODIFY_BOOLEAN,
       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(
@@ -188,27 +192,24 @@ add_task(async function test_modify() {
         );
         let prefHasUserValue = Services.prefs.prefHasUserValue(nameOfBoolPref);
         Assert.equal(row.hasClass("has-user-value"), 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");
+    let row = this.getRow(PREF_MODIFY_STRING);
     row.editColumnButton.click();
     row.valueInput.value = "test";
-    let intRow = this.getRow("test.aboutconfig.modify.number");
+    let intRow = this.getRow(PREF_MODIFY_NUMBER);
     intRow.editColumnButton.click();
-    Assert.equal(
-      intRow.valueInput.value,
-      Preferences.get("test.aboutconfig.modify.number")
-    );
+    Assert.equal(intRow.valueInput.value, Preferences.get(PREF_MODIFY_NUMBER));
     Assert.ok(!row.valueInput);
-    Assert.equal(row.value, Preferences.get("test.aboutconfig.modify.string"));
+    Assert.equal(row.value, Preferences.get(PREF_MODIFY_STRING));
 
     // Test validation of integer values.
     for (let invalidValue of [
       "",
       " ",
       "a",
       "1.5",
       "-2147483649",
@@ -217,18 +218,18 @@ add_task(async function test_modify() {
       intRow.valueInput.value = invalidValue;
       intRow.editColumnButton.click();
       // We should still be in edit mode.
       Assert.ok(intRow.valueInput);
     }
 
     // Test correct saving and DOM-update.
     for (let [prefName, willDelete] of [
-      ["test.aboutconfig.modify.string", true],
-      ["test.aboutconfig.modify.number", true],
+      [PREF_MODIFY_STRING, true],
+      [PREF_MODIFY_NUMBER, true],
       [PREF_NUMBER_DEFAULT_ZERO, false],
       [PREF_STRING_DEFAULT_EMPTY, false],
     ]) {
       row = this.getRow(prefName);
       // Activate edit and check displaying.
       row.editColumnButton.click();
       Assert.equal(row.valueInput.value, Preferences.get(prefName));
       row.valueInput.value = "42";
@@ -241,8 +242,31 @@ add_task(async function test_modify() {
       row.editColumnButton.click();
       Assert.equal(row.valueInput.value, Preferences.get(prefName));
       row.resetColumnButton.click();
       Assert.ok(!row.hasClass("has-user-value"));
       Assert.equal(row.hasClass("deleted"), willDelete);
     }
   });
 });
+
+add_task(async function test_edit_field_selected() {
+  let prefsToCheck = [
+    [PREF_MODIFY_STRING, "A string", "A new string"],
+    [PREF_MODIFY_NUMBER, "100", "500"],
+  ];
+  await AboutConfigTest.withNewTab(async function() {
+    for (let [prefName, startValue, endValue] of prefsToCheck) {
+      Preferences.set(prefName, startValue);
+      let row = this.getRow(prefName);
+
+      Assert.equal(row.value, startValue);
+      row.editColumnButton.click();
+      Assert.equal(row.valueInput.value, startValue);
+
+      EventUtils.sendString(endValue, this.window);
+
+      row.editColumnButton.click();
+      Assert.equal(row.value, endValue);
+      Assert.equal(Preferences.get(prefName), endValue);
+    }
+  });
+});