Commit 5f5ac64e authored by Daisuke Akatsuka's avatar Daisuke Akatsuka
Browse files

Bug 1751819: Ignore char key input while processing enter key on searchbar. r=adw, a=RyanVM

parent a924c2a8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -799,6 +799,13 @@
        this.handleSearchCommand(event, engine);
      };

      this.textbox.onbeforeinput = event => {
        if (event.data && this._needBrowserFocusAtEnterKeyUp) {
          // Ignore char key input while processing enter key.
          event.preventDefault();
        }
      };

      this.textbox.onkeyup = event => {
        if (
          event.keyCode === KeyEvent.DOM_VK_RETURN &&
+1 −1
Original line number Diff line number Diff line
@@ -68,8 +68,8 @@ support-files =
  searchTelemetryAd.html
[browser_searchbar_addEngine.js]
[browser_searchbar_context.js]
[browser_searchbar_enter.js]
[browser_searchbar_default.js]
[browser_searchbar_focus_timing.js]
[browser_searchbar_openpopup.js]
skip-if = os == "linux" # Linux has different focus behaviours.
[browser_searchbar_keyboard_navigation.js]
+45 −2
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@

"use strict";

// Test the focus timing for the search bar.
// Test the behavior for enter key.

add_task(async function setup() {
  await gCUITestUtils.addSearchBar();
@@ -19,7 +19,8 @@ add_task(async function setup() {
  });
});

add_task(async function() {
add_task(async function searchOnEnterSoon() {
  info("Search on Enter as soon as typing a char");
  const win = await BrowserTestUtils.openNewBrowserWindow();
  const browser = win.gBrowser.selectedBrowser;
  const browserSearch = win.BrowserSearch;
@@ -76,3 +77,45 @@ add_task(async function() {

  await BrowserTestUtils.closeWindow(win);
});

add_task(async function typeCharWhileProcessingEnter() {
  info("Typing a char while processing enter key");
  const win = await BrowserTestUtils.openNewBrowserWindow();
  const browser = win.gBrowser.selectedBrowser;
  const searchBar = win.BrowserSearch.searchBar;

  const SEARCH_WORD = "test";
  const onLoad = BrowserTestUtils.browserLoaded(
    browser,
    false,
    `https://example.com/?q=${SEARCH_WORD}`
  );
  searchBar.textbox.focus();
  searchBar.textbox.value = SEARCH_WORD;

  info("Keydown Enter");
  EventUtils.synthesizeKey("KEY_Enter", { type: "keydown" }, win);
  await TestUtils.waitForCondition(
    () => searchBar._needBrowserFocusAtEnterKeyUp,
    "Wait for starting process for the enter key"
  );

  info("Keydown a char");
  EventUtils.synthesizeKey("x", { type: "keydown" }, win);

  info("Keyup both");
  EventUtils.synthesizeKey("x", { type: "keyup" }, win);
  EventUtils.synthesizeKey("KEY_Enter", { type: "keyup" }, win);

  Assert.equal(
    searchBar.textbox.value,
    SEARCH_WORD,
    "The value of searchbar is correct"
  );

  await onLoad;
  Assert.ok("Browser loaded the correct url");

  // Cleanup.
  await BrowserTestUtils.closeWindow(win);
});