Bug 1449018 - The bookmark panel should listen to keypress event at the system event group. r=mak, a=jcristau
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 27 Mar 2018 16:50:18 +0900
changeset 460437 294c100c1a17f2087ad712fab7861521ef4247ef
parent 460436 45de343ccebdb6b6c28ebf4dd9f4acef0bb92015
child 460438 2f2e601e1394cbe2965a65f0218708eec9d5b81d
push id8942
push userryanvm@gmail.com
push dateThu, 29 Mar 2018 14:09:55 +0000
treeherdermozilla-beta@75cefda36f28 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, jcristau
bugs1449018
milestone60.0
Bug 1449018 - The bookmark panel should listen to keypress event at the system event group. r=mak, a=jcristau The bookmark panel should handle keypress events at the system event group because it needs to handle keypress events after autocomplete module which handles keypress events at the system event group. MozReview-Commit-ID: 9KjBlQ59gHw
browser/base/content/browser-places.js
browser/base/content/test/general/browser_bookmark_popup.js
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -27,17 +27,17 @@ var StarUI = {
 
   // Edit-bookmark panel
   get panel() {
     delete this.panel;
     var element = this._element("editBookmarkPanel");
     // initially the panel is hidden
     // to avoid impacting startup / new window performance
     element.hidden = false;
-    element.addEventListener("keypress", this);
+    element.addEventListener("keypress", this, {mozSystemGroup: true});
     element.addEventListener("mousedown", this);
     element.addEventListener("mouseout", this);
     element.addEventListener("mousemove", this);
     element.addEventListener("compositionstart", this);
     element.addEventListener("compositionend", this);
     element.addEventListener("input", this);
     element.addEventListener("popuphidden", this);
     element.addEventListener("popupshown", this);
--- a/browser/base/content/test/general/browser_bookmark_popup.js
+++ b/browser/base/content/test/general/browser_bookmark_popup.js
@@ -437,11 +437,93 @@ add_task(async function ctrl_d_new_bookm
     shouldAutoClose: false,
     popupHideFn() {
       document.getElementById("editBookmarkPanelRemoveButton").click();
     },
     isBookmarkRemoved: true,
   });
 });
 
+add_task(async function enter_during_autocomplete_should_prevent_autoclose() {
+  await test_bookmarks_popup({
+    isNewBookmark: true,
+    async popupShowFn(browser) {
+      EventUtils.synthesizeKey("d", {accelKey: true}, window);
+    },
+    async popupEditFn() {
+      let tagsField = document.getElementById("editBMPanel_tagsField");
+      tagsField.value = "";
+      tagsField.focus();
+
+      // Register a tag into the DB.
+      EventUtils.sendString("Abc", window);
+      tagsField.blur();
+
+      // Start autocomplete with the registered tag.
+      tagsField.value = "";
+      let popup = document.getElementById("PopupAutoComplete");
+      let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
+      tagsField.focus();
+      EventUtils.sendString("a", window);
+      await promiseShown;
+      ok(promiseShown, "autocomplete shown");
+
+      // Select first candidate.
+      EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
+
+      // Type Enter key to choose the item.
+      EventUtils.synthesizeKey("KEY_Enter", {}, window);
+
+      Assert.equal(tagsField.value, "Abc",
+        "Autocomplete should've inserted the selected item");
+    },
+    shouldAutoClose: false,
+    popupHideFn() {
+      EventUtils.synthesizeKey("KEY_Escape", {}, window);
+    },
+    isBookmarkRemoved: false,
+  });
+});
+
+add_task(async function escape_during_autocomplete_should_prevent_autoclose() {
+  await test_bookmarks_popup({
+    isNewBookmark: true,
+    async popupShowFn(browser) {
+      EventUtils.synthesizeKey("d", {accelKey: true}, window);
+    },
+    async popupEditFn() {
+      let tagsField = document.getElementById("editBMPanel_tagsField");
+      tagsField.value = "";
+      tagsField.focus();
+
+      // Register a tag into the DB.
+      EventUtils.sendString("Abc", window);
+      tagsField.blur();
+
+      // Start autocomplete with the registered tag.
+      tagsField.value = "";
+      let popup = document.getElementById("PopupAutoComplete");
+      let promiseShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
+      tagsField.focus();
+      EventUtils.sendString("a", window);
+      await promiseShown;
+      ok(promiseShown, "autocomplete shown");
+
+      // Select first candidate.
+      EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
+
+      // Type Enter key to choose the item.
+      EventUtils.synthesizeKey("KEY_Escape", {}, window);
+
+      Assert.equal(tagsField.value, "Abc",
+        "Autocomplete should've inserted the selected item and shouldn't clear it");
+    },
+    shouldAutoClose: false,
+    popupHideFn() {
+      EventUtils.synthesizeKey("KEY_Escape", {}, window);
+    },
+    isBookmarkRemoved: false,
+  });
+});
+
 registerCleanupFunction(function() {
   delete StarUI._closePanelQuickForTesting;
 });