Bug 1925532: Enter search mode without preview mode by key if there is single result r=daleharvey
Differential Revision: https://phabricator.services.mozilla.com/D226865
This commit is contained in:
@@ -455,6 +455,7 @@ export class UrlbarController {
|
||||
case KeyEvent.DOM_VK_END:
|
||||
this.input.maybeConfirmSearchModeFromResult({
|
||||
entry: "typed",
|
||||
startQuery: true,
|
||||
});
|
||||
// Fall through.
|
||||
case KeyEvent.DOM_VK_LEFT:
|
||||
|
||||
@@ -1511,11 +1511,17 @@ export class UrlbarInput {
|
||||
let enteredSearchMode;
|
||||
// Only preview search mode if the result is selected.
|
||||
if (this.view.resultIsSelected(result)) {
|
||||
// Not starting a query means we will only preview search mode.
|
||||
// For ScotchBonnet, As Tab and Arrow Down/Up, Page Down/Up key are used
|
||||
// for selection of the urlbar results, keep the search mode as preview
|
||||
// mode if there are multiple results.
|
||||
// If ScotchBonnet is disabled, not starting a query means we will only
|
||||
// preview search mode.
|
||||
enteredSearchMode = this.maybeConfirmSearchModeFromResult({
|
||||
result,
|
||||
checkValue: false,
|
||||
startQuery: false,
|
||||
startQuery:
|
||||
lazy.UrlbarPrefs.get("scotchBonnet.enableOverride") &&
|
||||
this.view.visibleResults.length == 1,
|
||||
});
|
||||
}
|
||||
if (!enteredSearchMode) {
|
||||
|
||||
@@ -616,50 +616,121 @@ add_task(async function open_engine_page_directly() {
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_urlbar_text_after_previewed_search_mode() {
|
||||
info("Open urlbar with a query that shows DuckDuckGo search engine");
|
||||
add_task(async function test_enter_searchmode_by_key_if_single_result() {
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: "https://example.com/",
|
||||
title: "BOOKMARK",
|
||||
});
|
||||
|
||||
const TEST_DATA = [
|
||||
{
|
||||
key: "KEY_Enter",
|
||||
expectedEntry: "keywordoffer",
|
||||
},
|
||||
{
|
||||
key: "KEY_Tab",
|
||||
expectedEntry: "keywordoffer",
|
||||
},
|
||||
{
|
||||
key: "VK_RIGHT",
|
||||
expectedEntry: "typed",
|
||||
},
|
||||
{
|
||||
key: "VK_DOWN",
|
||||
expectedEntry: "keywordoffer",
|
||||
},
|
||||
];
|
||||
for (let { key, expectedEntry } of TEST_DATA) {
|
||||
info(`Test for entering search mode by ${key}`);
|
||||
|
||||
info("Open urlbar with a query that shows bookmarks");
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: "@duck",
|
||||
value: "@book",
|
||||
});
|
||||
|
||||
// Sanity check.
|
||||
const target = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(target.result.payload.engine, "DuckDuckGo");
|
||||
Assert.ok(target.result.payload.providesSearchMode);
|
||||
const autofill = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(autofill.result.providerName, "RestrictKeywordsAutofill");
|
||||
Assert.equal(autofill.result.payload.autofillKeyword, "@bookmarks");
|
||||
|
||||
info("Choose the search mode suggestion");
|
||||
EventUtils.synthesizeKey("KEY_Tab", {});
|
||||
EventUtils.synthesizeKey(key, {});
|
||||
await UrlbarTestUtils.promiseSearchComplete(window);
|
||||
await UrlbarTestUtils.assertSearchMode(window, {
|
||||
engineName: "DuckDuckGo",
|
||||
entry: "keywordoffer",
|
||||
source: 3,
|
||||
isPreview: true,
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
entry: expectedEntry,
|
||||
restrictType: "keyword",
|
||||
});
|
||||
|
||||
info("Click on the content area");
|
||||
// We intentionally turn off this a11y check, because the following click is
|
||||
// purposefully sent on an arbitrary web content that is not expected to be
|
||||
// tested by itself with the browser mochitests, therefore this rule check
|
||||
// shall be ignored by a11y_checks suite.
|
||||
AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false });
|
||||
EventUtils.synthesizeMouseAtCenter(gBrowser.selectedBrowser, {});
|
||||
AccessibilityUtils.resetEnv();
|
||||
await UrlbarTestUtils.assertSearchMode(window, null);
|
||||
info("Check the suggestions");
|
||||
Assert.equal(UrlbarTestUtils.getResultCount(window), 1);
|
||||
const bookmark = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
Assert.equal(bookmark.result.source, UrlbarUtils.RESULT_SOURCE.BOOKMARKS);
|
||||
Assert.equal(bookmark.result.type, UrlbarUtils.RESULT_TYPE.URL);
|
||||
Assert.equal(bookmark.result.payload.url, "https://example.com/");
|
||||
Assert.equal(bookmark.result.payload.title, "BOOKMARK");
|
||||
|
||||
info("Choose any search engine from the switcher");
|
||||
let popup = await UrlbarTestUtils.openSearchModeSwitcher(window);
|
||||
let popupHidden = UrlbarTestUtils.searchModeSwitcherPopupClosed(window);
|
||||
popup.querySelector("toolbarbutton[label=Bing]").click();
|
||||
await popupHidden;
|
||||
|
||||
Assert.equal(gURLBar.value, "", "The value of urlbar should be empty");
|
||||
|
||||
// Clean up.
|
||||
window.document.querySelector("#searchmode-switcher-close").click();
|
||||
await UrlbarTestUtils.assertSearchMode(window, null);
|
||||
}
|
||||
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
|
||||
add_task(
|
||||
async function test_enter_searchmode_as_preview_by_key_if_multiple_results() {
|
||||
await PlacesTestUtils.addBookmarkWithDetails({
|
||||
uri: "https://example.com/",
|
||||
title: "BOOKMARK",
|
||||
});
|
||||
|
||||
for (let key of ["KEY_Tab", "VK_DOWN"]) {
|
||||
info(`Test for entering search mode by ${key}`);
|
||||
|
||||
info("Open urlbar with a query that shows bookmarks");
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: "@",
|
||||
});
|
||||
|
||||
info("Choose the bookmark search mode");
|
||||
let resultCount = UrlbarTestUtils.getResultCount(window);
|
||||
for (let i = 0; i < resultCount; i++) {
|
||||
EventUtils.synthesizeKey(key, {});
|
||||
|
||||
let { result } = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
|
||||
if (
|
||||
result.providerName == "RestrictKeywords" &&
|
||||
result.payload.keyword == "*"
|
||||
) {
|
||||
await UrlbarTestUtils.assertSearchMode(window, {
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
entry: "keywordoffer",
|
||||
restrictType: "keyword",
|
||||
isPreview: true,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
window.document.querySelector("#searchmode-switcher-close").click();
|
||||
await UrlbarTestUtils.assertSearchMode(window, null);
|
||||
}
|
||||
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
}
|
||||
);
|
||||
|
||||
add_task(async function test_open_state() {
|
||||
let popup = UrlbarTestUtils.searchModeSwitcherPopup(window);
|
||||
let switcher = document.getElementById("urlbar-searchmode-switcher");
|
||||
|
||||
Reference in New Issue
Block a user