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

Differential Revision: https://phabricator.services.mozilla.com/D136712
This commit is contained in:
Daisuke Akatsuka 2022-02-01 03:02:05 +00:00
parent a924c2a84c
commit 5f5ac64ea3
3 changed files with 53 additions and 3 deletions

View File

@ -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 &&

View File

@ -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]

View File

@ -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);
});