Bug 1522659 - Cancel editing a pref with escape in about:config r=jaws,paolo
authorMark Striemer <mstriemer@mozilla.com>
Wed, 18 Sep 2019 17:50:12 +0000
changeset 493865 90984e8cdaec55e6664e9a177ea1085309fc20fd
parent 493864 50045e12742d61222a4ab8d6314b7fd06238963c
child 493866 2f97bd10d6da93caeec9727b6602f1d7e582048e
push id36589
push usernerli@mozilla.com
push dateWed, 18 Sep 2019 21:49:27 +0000
treeherdermozilla-central@21aff209f5a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, paolo
bugs1522659
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 1522659 - Cancel editing a pref with escape in about:config r=jaws,paolo Differential Revision: https://phabricator.services.mozilla.com/D45087
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
@@ -492,16 +492,22 @@ function loadPrefs() {
       pref.save();
     } else {
       // This is "button-reset" or "button-delete".
       pref.editing = false;
       Services.prefs.clearUserPref(pref.name);
       pref.editButton.focus();
     }
   });
+
+  window.addEventListener("keypress", event => {
+    if (event.target != search && event.key == "Escape" && gPrefInEdit) {
+      gPrefInEdit.endEdit();
+    }
+  });
 }
 
 function filterPrefs(options = {}) {
   if (gPrefInEdit) {
     gPrefInEdit.endEdit();
   }
   gDeletedPrefs.clear();
 
--- a/browser/components/aboutconfig/test/browser/browser_edit.js
+++ b/browser/components/aboutconfig/test/browser/browser_edit.js
@@ -265,8 +265,39 @@ add_task(async function test_edit_field_
       EventUtils.sendString(endValue, this.window);
 
       row.editColumnButton.click();
       Assert.equal(row.value, endValue);
       Assert.equal(Preferences.get(prefName), endValue);
     }
   });
 });
+
+add_task(async function test_escape_cancels_edit() {
+  await AboutConfigTest.withNewTab(async function() {
+    let row = this.getRow(PREF_MODIFY_STRING);
+    Preferences.set(PREF_MODIFY_STRING, "Edit me, maybe");
+
+    for (let blurInput of [false, true]) {
+      Assert.ok(!row.valueInput);
+      row.editColumnButton.click();
+
+      Assert.ok(row.valueInput);
+
+      Assert.equal(row.valueInput.value, "Edit me, maybe");
+      row.valueInput.value = "Edited";
+
+      // Test both cases of the input being focused and not being focused.
+      if (blurInput) {
+        row.valueInput.blur();
+        Assert.notEqual(this.document.activeElement, row.valueInput);
+      } else {
+        Assert.equal(this.document.activeElement, row.valueInput);
+      }
+
+      EventUtils.synthesizeKey("KEY_Escape", {}, this.window);
+
+      Assert.ok(!row.valueInput);
+      Assert.equal(row.value, "Edit me, maybe");
+      Assert.equal(row.value, Preferences.get(PREF_MODIFY_STRING));
+    }
+  });
+});