Bug 1793414 - Move paste and search handling for the search bar into the search bar code itself. r=jteow

Differential Revision: https://phabricator.services.mozilla.com/D158499
This commit is contained in:
Mark Banner
2022-10-07 07:12:18 +00:00
parent 64344b9d38
commit 97bfe28c29
3 changed files with 61 additions and 7 deletions

View File

@@ -876,7 +876,9 @@
this._menupopup.addEventListener("command", event => {
switch (event.originalTarget) {
case this._pasteAndSearchMenuItem:
BrowserSearch.pasteAndSearch(event);
this.select();
goDoCommand("cmd_paste");
this.handleSearchCommand(event);
break;
case clearHistoryItem:
let param = this.textbox.getAttribute("autocompletesearchparam");

View File

@@ -9,9 +9,21 @@
let win;
XPCOMUtils.defineLazyServiceGetter(
this,
"clipboardHelper",
"@mozilla.org/widget/clipboardhelper;1",
"nsIClipboardHelper"
);
add_setup(async function() {
await gCUITestUtils.addSearchBar();
await SearchTestUtils.installSearchExtension();
const defaultEngine = Services.search.defaultEngine;
Services.search.defaultEngine = Services.search.getEngineByName("Example");
win = await BrowserTestUtils.openNewBrowserWindow();
// Disable suggestions for this test, so that we are not attempting to hit
@@ -21,6 +33,7 @@ add_setup(async function() {
});
registerCleanupFunction(async function() {
Services.search.defaultEngine = defaultEngine;
await BrowserTestUtils.closeWindow(win);
gCUITestUtils.removeSearchBar();
});
@@ -190,3 +203,48 @@ add_task(async function test_text_in_unfocused_bar() {
contextMenu.hidePopup();
await popupHiddenPromise;
});
add_task(async function test_paste_and_go() {
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser: win.gBrowser,
});
const searchbar = win.BrowserSearch.searchBar;
searchbar.value = "";
searchbar.focus();
const searchString = "test";
await SimpleTest.promiseClipboardChange(searchString, () => {
clipboardHelper.copyString(searchString);
});
let contextMenu = searchbar.querySelector(".textbox-contextmenu");
let contextMenuPromise = BrowserTestUtils.waitForEvent(
contextMenu,
"popupshown"
);
await EventUtils.synthesizeMouseAtCenter(
searchbar,
{ type: "contextmenu", button: 2 },
win
);
await contextMenuPromise;
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
searchbar.querySelector(".searchbar-paste-and-search").click();
await p;
contextMenu.hidePopup();
await popupHiddenPromise;
Assert.equal(
tab.linkedBrowser.currentURI.spec,
`https://example.com/?q=${searchString}`,
"Should have loaded the expected search page."
);
});