Skip to content

Commit

Permalink
Bug 1647893 - Enter search mode with default engine on Accel+K. r=adw
Browse files Browse the repository at this point in the history
  • Loading branch information
htwyford committed Aug 5, 2020
1 parent fad9416 commit 649526b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4241,7 +4241,7 @@ const BrowserSearch = {
let focusUrlBarIfSearchFieldIsNotActive = function(aSearchBar) {
if (!aSearchBar || document.activeElement != aSearchBar.textbox) {
// Limit the results to search suggestions, like the search bar.
gURLBar.search(UrlbarTokenizer.RESTRICT.SEARCH);
gURLBar.searchModeShortcut();
}
};

Expand Down
15 changes: 15 additions & 0 deletions browser/components/urlbar/UrlbarInput.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,21 @@ class UrlbarInput {
}
}

/**
* Enters search mode with the default engine.
* If update2 is not enabled, it searches with the SEARCH restriction token
* instead.
*/
searchModeShortcut() {
if (this.view.oneOffsRefresh) {
let defaultEngine = Services.search.defaultEngine;
this.setSearchMode(defaultEngine);
this.search("");
} else {
this.search(UrlbarTokenizer.RESTRICT.SEARCH);
}
}

// Getters and Setters below.

get editor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ async function exitSearchMode(
window,
{ backspace, clickClose, waitForSearch = true }
) {
// If the Urlbar is not extended, ignore the clickClose parameter. The close
// button is not clickable in this state. This state might be encountered on
// Linux, where prefers-reduced-motion is enabled in automation.
if (!gURLBar.hasAttribute("breakout-extend") && clickClose) {
if (waitForSearch) {
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
gURLBar.setSearchMode(null);
await searchPromise;
} else {
gURLBar.setSearchMode(null);
}
return;
}

if (backspace) {
let urlbarValue = gURLBar.value;
gURLBar.selectionStart = gURLBar.selectionEnd = 0;
Expand Down Expand Up @@ -251,15 +265,31 @@ add_task(async function click_close() {
});
await enterSearchMode(window);
UrlbarTestUtils.promisePopupClose(window);
if (gURLBar.hasAttribute("breakout-extend")) {
await exitSearchMode(window, { clickClose: true, waitForSearch: false });
} else {
// If the Urlbar is not extended when it is closed, do not finish this
// case. The close button is not clickable when the Urlbar is not
// extended. This scenario might be encountered on Linux, where
// prefers-reduced-motion is enabled in automation.
gURLBar.setSearchMode(null);
}
await exitSearchMode(window, { clickClose: true, waitForSearch: false });
});

// Tests that Accel+K enters search mode with the default engine.
add_task(async function keyboard_shortcut() {
UrlbarTestUtils.assertSearchMode(window, null);
EventUtils.synthesizeKey("k", { accelKey: true });
UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: defaultEngine.name,
});
await exitSearchMode(window, { clickClose: true, waitForSearch: false });
});

// Tests that the Tools:Search menu item enters search mode with the default
// engine.
add_task(async function menubar_item() {
UrlbarTestUtils.assertSearchMode(window, null);
let command = window.document.getElementById("Tools:Search");
command.doCommand();
UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: defaultEngine.name,
});
await exitSearchMode(window, { clickClose: true, waitForSearch: false });
});

// Tests that entering search mode invalidates pageproxystate and exits search
Expand Down

0 comments on commit 649526b

Please sign in to comment.