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:
|
case KeyEvent.DOM_VK_END:
|
||||||
this.input.maybeConfirmSearchModeFromResult({
|
this.input.maybeConfirmSearchModeFromResult({
|
||||||
entry: "typed",
|
entry: "typed",
|
||||||
|
startQuery: true,
|
||||||
});
|
});
|
||||||
// Fall through.
|
// Fall through.
|
||||||
case KeyEvent.DOM_VK_LEFT:
|
case KeyEvent.DOM_VK_LEFT:
|
||||||
|
|||||||
@@ -1511,11 +1511,17 @@ export class UrlbarInput {
|
|||||||
let enteredSearchMode;
|
let enteredSearchMode;
|
||||||
// Only preview search mode if the result is selected.
|
// Only preview search mode if the result is selected.
|
||||||
if (this.view.resultIsSelected(result)) {
|
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({
|
enteredSearchMode = this.maybeConfirmSearchModeFromResult({
|
||||||
result,
|
result,
|
||||||
checkValue: false,
|
checkValue: false,
|
||||||
startQuery: false,
|
startQuery:
|
||||||
|
lazy.UrlbarPrefs.get("scotchBonnet.enableOverride") &&
|
||||||
|
this.view.visibleResults.length == 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!enteredSearchMode) {
|
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() {
|
add_task(async function test_enter_searchmode_by_key_if_single_result() {
|
||||||
info("Open urlbar with a query that shows DuckDuckGo search engine");
|
await PlacesTestUtils.addBookmarkWithDetails({
|
||||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
uri: "https://example.com/",
|
||||||
window,
|
title: "BOOKMARK",
|
||||||
value: "@duck",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sanity check.
|
const TEST_DATA = [
|
||||||
const target = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
{
|
||||||
Assert.equal(target.result.payload.engine, "DuckDuckGo");
|
key: "KEY_Enter",
|
||||||
Assert.ok(target.result.payload.providesSearchMode);
|
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("Choose the search mode suggestion");
|
info("Open urlbar with a query that shows bookmarks");
|
||||||
EventUtils.synthesizeKey("KEY_Tab", {});
|
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||||
await UrlbarTestUtils.assertSearchMode(window, {
|
window,
|
||||||
engineName: "DuckDuckGo",
|
value: "@book",
|
||||||
entry: "keywordoffer",
|
});
|
||||||
source: 3,
|
|
||||||
isPreview: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
info("Click on the content area");
|
// Sanity check.
|
||||||
// We intentionally turn off this a11y check, because the following click is
|
const autofill = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||||
// purposefully sent on an arbitrary web content that is not expected to be
|
Assert.equal(autofill.result.providerName, "RestrictKeywordsAutofill");
|
||||||
// tested by itself with the browser mochitests, therefore this rule check
|
Assert.equal(autofill.result.payload.autofillKeyword, "@bookmarks");
|
||||||
// shall be ignored by a11y_checks suite.
|
|
||||||
AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false });
|
|
||||||
EventUtils.synthesizeMouseAtCenter(gBrowser.selectedBrowser, {});
|
|
||||||
AccessibilityUtils.resetEnv();
|
|
||||||
await UrlbarTestUtils.assertSearchMode(window, null);
|
|
||||||
|
|
||||||
info("Choose any search engine from the switcher");
|
info("Choose the search mode suggestion");
|
||||||
let popup = await UrlbarTestUtils.openSearchModeSwitcher(window);
|
EventUtils.synthesizeKey(key, {});
|
||||||
let popupHidden = UrlbarTestUtils.searchModeSwitcherPopupClosed(window);
|
await UrlbarTestUtils.promiseSearchComplete(window);
|
||||||
popup.querySelector("toolbarbutton[label=Bing]").click();
|
await UrlbarTestUtils.assertSearchMode(window, {
|
||||||
await popupHidden;
|
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||||
|
entry: expectedEntry,
|
||||||
|
restrictType: "keyword",
|
||||||
|
});
|
||||||
|
|
||||||
Assert.equal(gURLBar.value, "", "The value of urlbar should be empty");
|
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");
|
||||||
|
|
||||||
// Clean up.
|
info("Choose any search engine from the switcher");
|
||||||
window.document.querySelector("#searchmode-switcher-close").click();
|
let popup = await UrlbarTestUtils.openSearchModeSwitcher(window);
|
||||||
await UrlbarTestUtils.assertSearchMode(window, null);
|
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() {
|
add_task(async function test_open_state() {
|
||||||
let popup = UrlbarTestUtils.searchModeSwitcherPopup(window);
|
let popup = UrlbarTestUtils.searchModeSwitcherPopup(window);
|
||||||
let switcher = document.getElementById("urlbar-searchmode-switcher");
|
let switcher = document.getElementById("urlbar-searchmode-switcher");
|
||||||
|
|||||||
Reference in New Issue
Block a user