Bug 1659775 - Restrict adaptive history from appearing in search mode. r=adw

Differential Revision: https://phabricator.services.mozilla.com/D87796
This commit is contained in:
Harry Twyford 2020-08-20 20:12:01 +00:00
Родитель 09c938e9e8
Коммит 7f48f83bec
15 изменённых файлов: 142 добавлений и 56 удалений

Просмотреть файл

@ -378,7 +378,7 @@ var UrlbarTestUtils = {
* The expected search mode object.
* @note Can only be used if UrlbarTestUtils has been initialized with init().
*/
assertSearchMode(window, expectedSearchMode) {
async assertSearchMode(window, expectedSearchMode) {
this.Assert.equal(
!!window.gURLBar.searchMode,
window.gURLBar.hasAttribute("searchmode"),
@ -464,6 +464,33 @@ var UrlbarTestUtils = {
expectedPlaceholderL10n,
"Expected placeholder l10n when search mode is active"
);
// If this is an engine search mode, check that all results are either
// search results with the same engine or have the same host as the engine.
if (expectedSearchMode.engineName && this.isPopupOpen(window)) {
let resultCount = this.getResultCount(window);
for (let i = 0; i < resultCount; i++) {
let result = await this.getDetailsOfResultAt(window, i);
if (result.source == UrlbarUtils.RESULT_SOURCE.SEARCH) {
this.Assert.equal(
expectedSearchMode.engineName,
result.searchParams.engine,
"Search mode result matches engine name."
);
} else {
let engine = Services.search.getEngineByName(
expectedSearchMode.engineName
);
let engineHost = engine.getResultDomain();
let resultUrl = new URL(result.url);
// Use `includes` to allow results from engine subdomains.
this.Assert.ok(
resultUrl.host.includes(engineHost),
"Search mode result matches engine host."
);
}
}
}
},
/**
@ -508,7 +535,7 @@ var UrlbarTestUtils = {
this.EventUtils.synthesizeMouseAtCenter(oneOff, {}, window);
await this.promiseSearchComplete(window);
this.Assert.ok(this.isPopupOpen(window), "Urlbar view is still open.");
this.assertSearchMode(window, searchMode);
await this.assertSearchMode(window, searchMode);
},
/**
@ -580,7 +607,7 @@ var UrlbarTestUtils = {
} else {
this.EventUtils.synthesizeMouseAtCenter(closeButton, {}, window);
}
this.assertSearchMode(window, null);
await this.assertSearchMode(window, null);
}
},

Просмотреть файл

@ -73,6 +73,9 @@ support-files =
[browser_heuristicNotAddedFirst.js]
[browser_ime_composition.js]
[browser_inputHistory.js]
support-files =
searchSuggestionEngine.xml
searchSuggestionEngine.sjs
[browser_inputHistory_emptystring.js]
[browser_keepStateAcrossTabSwitches.js]
[browser_keywordBookmarklets.js]

Просмотреть файл

@ -329,3 +329,41 @@ add_task(async function test_adaptive_mouse() {
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
Assert.equal(result.url, url1, "Check second result");
});
add_task(async function test_adaptive_searchmode() {
info("Check adaptive history is not shown in search mode.");
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.update2", true],
["browser.urlbar.update2.oneOffsRefresh", true],
],
});
let suggestionsEngine = await SearchTestUtils.promiseNewSearchEngine(
getRootDirectory(gTestPath) + "searchSuggestionEngine.xml"
);
let url1 = "http://site.tld/1";
let url2 = "http://site.tld/2";
info("Sanity check: adaptive history is shown for a normal search.");
await PlacesUtils.history.clear();
await bumpScore(url1, "site", { visits: 3, picks: 3 }, true);
await bumpScore(url2, "site", { visits: 3, picks: 1 }, true);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "si",
});
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
Assert.equal(result.url, url1, "Check first result");
result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
Assert.equal(result.url, url2, "Check second result");
info("Entering search mode.");
// enterSearchMode checks internally that our site.tld URLs are not shown.
await UrlbarTestUtils.enterSearchMode(window, {
engineName: suggestionsEngine.name,
});
await SpecialPowers.popPrefEnv();
});

Просмотреть файл

@ -478,15 +478,17 @@ add_task(async function oneOffClick() {
let oneOffs = oneOffSearchButtons.getSelectableButtons(true);
if (refresh) {
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeMouseAtCenter(oneOffs[0], {});
await searchPromise;
Assert.ok(
UrlbarTestUtils.isPopupOpen(window),
"Urlbar view is still open."
);
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: oneOffs[0].engine.name,
});
window.gURLBar.setSearchMode({});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
} else {
let resultsPromise = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
@ -528,15 +530,17 @@ add_task(async function oneOffReturn() {
assertState(0, 0, typedValue);
if (refresh) {
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeKey("KEY_Enter");
await searchPromise;
Assert.ok(
UrlbarTestUtils.isPopupOpen(window),
"Urlbar view is still open."
);
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: oneOffs[0].engine.name,
});
window.gURLBar.setSearchMode({});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
} else {
let resultsPromise = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
@ -695,18 +699,19 @@ add_task(async function localOneOffClick() {
for (let button of buttons) {
Assert.ok(button.source, "Sanity check: Button has a source");
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeMouseAtCenter(button, {});
await searchPromise;
Assert.ok(
UrlbarTestUtils.isPopupOpen(window),
"Urlbar view is still open."
);
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: button.source,
});
}
window.gURLBar.setSearchMode({});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
await hidePopup();
await SpecialPowers.popPrefEnv();
});
@ -760,18 +765,19 @@ add_task(async function localOneOffReturn() {
assertState(0, index, typedValue);
Assert.ok(button.source, "Sanity check: Button has a source");
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeKey("KEY_Enter");
await searchPromise;
Assert.ok(
UrlbarTestUtils.isPopupOpen(window),
"Urlbar view is still open."
);
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: button.source,
});
}
window.gURLBar.setSearchMode({});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
await hidePopup();
await SpecialPowers.popPrefEnv();
});
@ -823,7 +829,7 @@ add_task(async function localOneOffEmptySearchString() {
true,
"One-offs are visible"
);
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: button.source,
});

Просмотреть файл

@ -186,7 +186,7 @@ add_task(async function test_returnAfterSuggestion() {
let resultsPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeKey("KEY_Enter");
await resultsPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: gEngine.name,
});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
@ -257,7 +257,7 @@ add_task(async function test_returnAfterSuggestion_nonDefault() {
let resultsPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeKey("KEY_Enter");
await resultsPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: gEngine2.name,
});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
@ -308,7 +308,7 @@ add_task(async function test_clickAfterSuggestion() {
let resultsPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeMouseAtCenter(oneOffs[1], {});
await resultsPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: gEngine2.name,
});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
@ -359,7 +359,7 @@ add_task(async function test_clickAfterSuggestion_nonDefault() {
let resultsPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeMouseAtCenter(oneOffs[1], {});
await resultsPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: gEngine2.name,
});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });

Просмотреть файл

@ -196,14 +196,14 @@ add_task(async function escape() {
let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(
window
).getSelectableButtons(true);
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: oneOffs[0].engine.name,
});
EventUtils.synthesizeKey("KEY_Escape");
Assert.ok(!UrlbarTestUtils.isPopupOpen(window, "UrlbarView is closed."));
Assert.ok(!gURLBar.value, "Urlbar value is empty.");
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
});
// Tests that the indicator is removed when its close button is clicked.
@ -265,9 +265,9 @@ add_task(async function click_close() {
// Tests that Accel+K enters search mode with the default engine.
add_task(async function keyboard_shortcut() {
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
EventUtils.synthesizeKey("k", { accelKey: true });
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: defaultEngine.name,
});
@ -280,10 +280,10 @@ add_task(async function keyboard_shortcut() {
// Tests that the Tools:Search menu item enters search mode with the default
// engine.
add_task(async function menubar_item() {
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
let command = window.document.getElementById("Tools:Search");
command.doCommand();
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: defaultEngine.name,
});
@ -329,6 +329,6 @@ add_task(async function pref_flip_while_enabled() {
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.update2", false]],
});
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
await SpecialPowers.popPrefEnv();
});

Просмотреть файл

@ -46,7 +46,7 @@ add_task(async function replaced_on_space() {
EventUtils.synthesizeKey("VK_SPACE");
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
Assert.equal(
gURLBar.value,
ALIAS.slice(0, -1),
@ -81,7 +81,7 @@ add_task(async function replaced_on_space() {
UrlbarTestUtils.fireInputEvent(window);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: aliasEngine.name,
});
Assert.ok(!gURLBar.value, "The Urlbar value should be cleared.");
@ -130,5 +130,5 @@ add_task(async function not_replaced_for_alt_tab() {
UrlbarTestUtils.fireInputEvent(window);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
});

Просмотреть файл

@ -78,7 +78,7 @@ async function doClickLinkTest(searchString, href) {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
await UrlbarTestUtils.promisePopupClose(window);
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
@ -98,6 +98,6 @@ async function doClickLinkTest(searchString, href) {
"Should have loaded the href URL"
);
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
});
}

Просмотреть файл

@ -132,7 +132,7 @@ add_task(async function autoOpen() {
// Blur the urlbar.
win.gURLBar.blur();
UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(win, {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
@ -210,7 +210,7 @@ add_task(async function backspaceRemainOpen() {
EventUtils.synthesizeKey("KEY_Backspace", {}, win);
await searchPromise;
Assert.ok(UrlbarTestUtils.isPopupOpen(win), "View remains open");
UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(win, {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
Assert.equal(
@ -264,7 +264,7 @@ add_task(async function spaceToEnterSearchMode() {
"true",
"Panel has no results, therefore should have noresults attribute"
);
UrlbarTestUtils.assertSearchMode(win, {
await UrlbarTestUtils.assertSearchMode(win, {
engineName: engine.name,
});
this.Assert.equal(

Просмотреть файл

@ -91,6 +91,6 @@ async function doPickResultTest(initialURL, searchString) {
"Should have loaded the bookmarked URL"
);
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
});
}

Просмотреть файл

@ -113,7 +113,7 @@ async function doSetURITest(initialURL, searchString, url, expectSearchMode) {
let uri = url ? Services.io.newURI(url) : null;
gURLBar.setURI(uri);
UrlbarTestUtils.assertSearchMode(
await UrlbarTestUtils.assertSearchMode(
window,
!expectSearchMode
? null
@ -123,6 +123,6 @@ async function doSetURITest(initialURL, searchString, url, expectSearchMode) {
);
gURLBar.handleRevert();
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
});
}

Просмотреть файл

@ -46,20 +46,20 @@ add_task(async function switchTabs() {
// Switch to tab 1. Search mode should be exited.
await BrowserTestUtils.switchTab(gBrowser, tabs[1]);
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
// Switch back to tab 0. We should do a search (for "test") and re-enter
// search mode.
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
// Switch to tab 2. Search mode should be exited.
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
// Do another search (in tab 2) and enter search mode. Use a different source
// from tab 0 just to use something different.
@ -76,19 +76,19 @@ add_task(async function switchTabs() {
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
// Switch to tab 1. Search mode should be exited.
await BrowserTestUtils.switchTab(gBrowser, tabs[1]);
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
// Switch back to tab 2. We should do a search and re-enter search mode.
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.TABS,
});
@ -99,7 +99,7 @@ add_task(async function switchTabs() {
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
@ -108,13 +108,13 @@ add_task(async function switchTabs() {
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
// Switch back to tab 0. We should do a search and re-enter search mode.
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
});
@ -126,14 +126,14 @@ add_task(async function switchTabs() {
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
// Switch back to tab 0. We should do a search but search mode should be
// inactive.
searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.assertSearchMode(window, null);
await UrlbarTestUtils.promisePopupClose(window);
for (let tab of tabs) {

Просмотреть файл

@ -297,9 +297,11 @@ add_task(async function clickAndFillAlias() {
}
// Click it.
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeMouseAtCenter(testEngineItem, {});
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: testEngineItem.result.payload.engine,
});
@ -389,9 +391,11 @@ add_task(async function enterAndFillAlias() {
// Key down to it and press enter.
EventUtils.synthesizeKey("KEY_ArrowDown", { repeat: index });
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeKey("KEY_Enter");
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: details.searchParams.engine,
});
@ -456,9 +460,11 @@ add_task(async function enterAutofillsAlias() {
);
// Press Enter.
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeKey("KEY_Enter");
await searchPromise;
UrlbarTestUtils.assertSearchMode(window, {
await UrlbarTestUtils.assertSearchMode(window, {
engineName: testEngineItem.result.payload.engine,
});

Просмотреть файл

@ -212,11 +212,13 @@ add_task(async function selectSearchTopSite() {
"First result should have the Amazon keyword."
);
let searchPromise = UrlbarTestUtils.promiseSearchComplete(window);
EventUtils.synthesizeMouseAtCenter(amazonSearch, {});
UrlbarTestUtils.assertSearchMode(window, {
await searchPromise;
await UrlbarTestUtils.assertSearchMode(window, {
engineName: amazonSearch.result.payload.engine,
});
gURLBar.setSearchMode({});
await UrlbarTestUtils.exitSearchMode(window, { backspace: true });
await UrlbarTestUtils.promisePopupClose(window, () => {
gURLBar.blur();

Просмотреть файл

@ -492,7 +492,7 @@ function Search(
this._maxResults = queryContext.maxResults;
this._userContextId = queryContext.userContextId;
this._currentPage = queryContext.currentPage;
this._engineName = queryContext.searchMode?.engineName;
this._searchModeEngine = queryContext.searchMode?.engineName;
} else {
let params = new Set(searchParam.split(" "));
this._enableActions = params.has("enable-actions");
@ -787,10 +787,10 @@ Search.prototype = {
return;
}
// this._engineName is set if the user is in search mode. We fetch only
// this._searchModeEngine is set if the user is in search mode. We fetch only
// local results with the same host as the search mode engine.
if (this._engineName && !this._keywordSubstitute) {
let engine = Services.search.getEngineByName(this._engineName);
if (this._searchModeEngine && !this._keywordSubstitute) {
let engine = Services.search.getEngineByName(this._searchModeEngine);
this._keywordSubstitute = {
host: engine.getResultDomain(),
keyword: null,
@ -1587,6 +1587,10 @@ Search.prototype = {
// results, caching the others. If at the end we don't find other results, we
// can add these.
_addAdaptiveQueryMatch(row) {
// We should only show filtered results in search mode.
if (this._searchModeEngine) {
return;
}
// Allow one quarter of the results to be adaptive results.
// Note: ideally adaptive results should have their own provider and the
// results muxer should decide what to show. But that's too complex to