Backed out changeset e5655c6b1c5f (bug 1658646) for failures on browser_oneOffs_searchSuggestions.js. CLOSED TREE

This commit is contained in:
Csoregi Natalia 2020-08-14 06:30:46 +03:00
Родитель a59efd3c0a
Коммит 764a7a6ede
11 изменённых файлов: 50 добавлений и 130 удалений

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

@ -1096,9 +1096,7 @@ class UrlbarInput {
if (this.searchMode) { if (this.searchMode) {
options.searchMode = this.searchMode; options.searchMode = this.searchMode;
if (this.searchMode.source) { options.sources = [this.searchMode.source];
options.sources = [this.searchMode.source];
}
} }
// TODO (Bug 1522902): This promise is necessary for tests, because some // TODO (Bug 1522902): This promise is necessary for tests, because some
@ -1195,15 +1193,10 @@ class UrlbarInput {
this._searchModeLabel.removeAttribute("data-l10n-id"); this._searchModeLabel.removeAttribute("data-l10n-id");
if (engineName) { if (engineName) {
this.searchMode = { engineName }; this.searchMode = {
if (source) { source: UrlbarUtils.RESULT_SOURCE.SEARCH,
this.searchMode.source = source; engineName,
} else if (UrlbarUtils.WEB_ENGINE_NAMES.has(engineName)) { };
// History results for general-purpose search engines are often not
// useful, so we hide them in search mode. See bug 1658646 for
// discussion.
this.searchMode.source = UrlbarUtils.RESULT_SOURCE.SEARCH;
}
this._searchModeIndicatorTitle.textContent = engineName; this._searchModeIndicatorTitle.textContent = engineName;
this._searchModeLabel.textContent = engineName; this._searchModeLabel.textContent = engineName;
this.document.l10n.setAttributes( this.document.l10n.setAttributes(
@ -1260,12 +1253,7 @@ class UrlbarInput {
*/ */
searchModeShortcut() { searchModeShortcut() {
if (this.view.oneOffsRefresh) { if (this.view.oneOffsRefresh) {
// We restrict to search results when entering search mode from this this.setSearchMode({ engineName: Services.search.defaultEngine.name });
// shortcut to honor historical behaviour.
this.setSearchMode({
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: Services.search.defaultEngine.name,
});
this.search(""); this.search("");
} else { } else {
this.search(UrlbarTokenizer.RESTRICT.SEARCH); this.search(UrlbarTokenizer.RESTRICT.SEARCH);

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

@ -102,9 +102,9 @@ class ProviderSearchSuggestions extends UrlbarProvider {
} }
/** /**
* Returns whether the user typed a token alias or restriction token, or is in * Returns whether the user typed a token alias or a restriction token. We use
* search mode. We use this value to override the pref to disable search * this value to override the pref to disable search suggestions in the
* suggestions in the Urlbar. * Urlbar.
* @param {UrlbarQueryContext} queryContext The query context object. * @param {UrlbarQueryContext} queryContext The query context object.
* @returns {boolean} True if the user typed a token alias or search * @returns {boolean} True if the user typed a token alias or search
* restriction token. * restriction token.
@ -116,9 +116,7 @@ class ProviderSearchSuggestions extends UrlbarProvider {
queryContext.restrictSource == UrlbarUtils.RESULT_SOURCE.SEARCH) || queryContext.restrictSource == UrlbarUtils.RESULT_SOURCE.SEARCH) ||
queryContext.tokens.some( queryContext.tokens.some(
t => t.type == UrlbarTokenizer.TYPE.RESTRICT_SEARCH t => t.type == UrlbarTokenizer.TYPE.RESTRICT_SEARCH
) || )
(queryContext.searchMode &&
queryContext.sources.includes(UrlbarUtils.RESULT_SOURCE.SEARCH))
); );
} }

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

@ -64,11 +64,7 @@ class ProviderTopSites extends UrlbarProvider {
* @returns {boolean} Whether this provider should be invoked for the search. * @returns {boolean} Whether this provider should be invoked for the search.
*/ */
isActive(queryContext) { isActive(queryContext) {
return ( return !queryContext.restrictSource && !queryContext.searchString;
!queryContext.restrictSource &&
!queryContext.searchString &&
!queryContext.searchMode
);
} }
/** /**

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

@ -491,13 +491,10 @@ var UrlbarTestUtils = {
); );
let buttons = oneOffs.getSelectableButtons(true); let buttons = oneOffs.getSelectableButtons(true);
if (!searchMode) { searchMode = searchMode || {
searchMode = { engineName: buttons[0].engine.name }; source: UrlbarUtils.RESULT_SOURCE.SEARCH,
if (UrlbarUtils.WEB_ENGINE_NAMES.has(searchMode.engineName)) { engineName: buttons[0].engine.name,
searchMode.source = UrlbarUtils.RESULT_SOURCE.SEARCH; };
}
}
let oneOff = buttons.find(o => let oneOff = buttons.find(o =>
searchMode.engineName searchMode.engineName
? o.engine.name == searchMode.engineName ? o.engine.name == searchMode.engineName

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

@ -484,6 +484,7 @@ add_task(async function oneOffClick() {
"Urlbar view is still open." "Urlbar view is still open."
); );
UrlbarTestUtils.assertSearchMode(window, { UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: oneOffs[0].engine.name, engineName: oneOffs[0].engine.name,
}); });
window.gURLBar.setSearchMode({}); window.gURLBar.setSearchMode({});
@ -534,6 +535,7 @@ add_task(async function oneOffReturn() {
"Urlbar view is still open." "Urlbar view is still open."
); );
UrlbarTestUtils.assertSearchMode(window, { UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: oneOffs[0].engine.name, engineName: oneOffs[0].engine.name,
}); });
window.gURLBar.setSearchMode({}); window.gURLBar.setSearchMode({});

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

@ -230,7 +230,10 @@ add_task(async function test_search_mode_engine_web() {
add_task(async function test_search_mode_engine_other() { add_task(async function test_search_mode_engine_other() {
await doSearchModeTest( await doSearchModeTest(
{ engineName: extraEngine.name }, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: extraEngine.name,
},
{ id: "urlbar-placeholder-search-mode-other", args: null } { id: "urlbar-placeholder-search-mode-other", args: null }
); );
}); });

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

@ -197,6 +197,7 @@ add_task(async function escape() {
window window
).getSelectableButtons(true); ).getSelectableButtons(true);
UrlbarTestUtils.assertSearchMode(window, { UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: oneOffs[0].engine.name, engineName: oneOffs[0].engine.name,
}); });
@ -372,6 +373,7 @@ add_task(async function tab_switch() {
window window
).getSelectableButtons(true); ).getSelectableButtons(true);
UrlbarTestUtils.assertSearchMode(window, { UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: oneOffs[0].engine.name, engineName: oneOffs[0].engine.name,
}); });
@ -409,6 +411,7 @@ add_task(async function tab_switch() {
await BrowserTestUtils.switchTab(gBrowser, tabs[0]); await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await searchPromise; await searchPromise;
UrlbarTestUtils.assertSearchMode(window, { UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: oneOffs[0].engine.name, engineName: oneOffs[0].engine.name,
}); });
@ -432,6 +435,7 @@ add_task(async function tab_switch() {
await BrowserTestUtils.switchTab(gBrowser, tabs[0]); await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await searchPromise; await searchPromise;
UrlbarTestUtils.assertSearchMode(window, { UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: oneOffs[0].engine.name, engineName: oneOffs[0].engine.name,
}); });
@ -447,6 +451,7 @@ add_task(async function tab_switch() {
await BrowserTestUtils.switchTab(gBrowser, tabs[0]); await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
await searchPromise; await searchPromise;
UrlbarTestUtils.assertSearchMode(window, { UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: oneOffs[0].engine.name, engineName: oneOffs[0].engine.name,
}); });

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

@ -82,6 +82,7 @@ add_task(async function replaced_on_space() {
await searchPromise; await searchPromise;
UrlbarTestUtils.assertSearchMode(window, { UrlbarTestUtils.assertSearchMode(window, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: aliasEngine.name, engineName: aliasEngine.name,
}); });
Assert.ok(!gURLBar.value, "The Urlbar value should be cleared."); Assert.ok(!gURLBar.value, "The Urlbar value should be cleared.");

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

@ -261,6 +261,7 @@ add_task(async function spaceToEnterSearchMode() {
"Panel has no results, therefore should have noresults attribute" "Panel has no results, therefore should have noresults attribute"
); );
UrlbarTestUtils.assertSearchMode(win, { UrlbarTestUtils.assertSearchMode(win, {
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
engineName: engine.name, engineName: engine.name,
}); });
this.Assert.equal( this.Assert.equal(

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

@ -142,52 +142,6 @@ add_task(async function nonEmptySearch_nonMatching() {
}); });
}); });
add_task(async function nonEmptySearch_withHistory() {
// URLs with the same host as the search engine.
await PlacesTestUtils.addVisits([
"http://mochi.test/ciao",
"http://mochi.test/ciao1",
]);
await BrowserTestUtils.withNewTab("about:robots", async function(browser) {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "ciao",
});
await UrlbarTestUtils.enterSearchMode(window);
Assert.equal(gURLBar.value, "ciao", "Urlbar value should be set.");
await checkResults([
{
isSearchHistory: false,
suggestion: undefined,
},
{
isSearchHistory: false,
suggestion: "ciaofoo",
},
{
isSearchHistory: false,
suggestion: "ciaobar",
},
{
isSearchHistory: false,
suggestion: undefined,
historyUrl: "http://mochi.test/ciao1",
},
{
isSearchHistory: false,
suggestion: undefined,
historyUrl: "http://mochi.test/ciao",
},
]);
await UrlbarTestUtils.exitSearchMode(window, { clickClose: true });
});
await PlacesUtils.history.clear();
});
async function checkResults(resultsDetails) { async function checkResults(resultsDetails) {
Assert.equal( Assert.equal(
UrlbarTestUtils.getResultCount(window), UrlbarTestUtils.getResultCount(window),
@ -196,29 +150,20 @@ async function checkResults(resultsDetails) {
); );
for (let i = 0; i < resultsDetails.length; ++i) { for (let i = 0; i < resultsDetails.length; ++i) {
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i); let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
if (result.searchParams) { Assert.equal(
Assert.equal( result.searchParams.engine,
result.searchParams?.engine, suggestionsEngine.name,
suggestionsEngine.name, "It should be a search result for our suggestion engine."
"It should be a search result for our suggestion engine." );
); Assert.equal(
Assert.equal( result.searchParams.isSearchHistory,
result.searchParams?.isSearchHistory, resultsDetails[i].isSearchHistory,
resultsDetails[i].isSearchHistory, "Check if it should be a local suggestion result."
"Check if it should be a local suggestion result." );
); Assert.equal(
Assert.equal( result.searchParams.suggestion,
result.searchParams?.suggestion, resultsDetails[i].suggestion,
resultsDetails[i].suggestion, "Check the suggestion value"
"Check the suggestion value" );
);
}
if (resultsDetails[i].historyUrl) {
Assert.equal(
result.url,
resultsDetails[i].historyUrl,
"The history result should have the correct URL."
);
}
} }
} }

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

@ -492,7 +492,6 @@ function Search(
this._maxResults = queryContext.maxResults; this._maxResults = queryContext.maxResults;
this._userContextId = queryContext.userContextId; this._userContextId = queryContext.userContextId;
this._currentPage = queryContext.currentPage; this._currentPage = queryContext.currentPage;
this._engineName = queryContext.searchMode?.engineName;
} else { } else {
let params = new Set(searchParam.split(" ")); let params = new Set(searchParam.split(" "));
this._enableActions = params.has("enable-actions"); this._enableActions = params.has("enable-actions");
@ -550,6 +549,10 @@ function Search(
let behavior = sourceToBehaviorMap.get(queryContext.restrictSource); let behavior = sourceToBehaviorMap.get(queryContext.restrictSource);
this.setBehavior(behavior); this.setBehavior(behavior);
if (behavior == "search" && queryContext.engineName) {
this._engineName = queryContext.engineName;
}
// When we are in restrict mode, all the tokens are valid for searching, so // When we are in restrict mode, all the tokens are valid for searching, so
// there is no _heuristicToken. // there is no _heuristicToken.
this._heuristicToken = null; this._heuristicToken = null;
@ -787,16 +790,6 @@ Search.prototype = {
return; return;
} }
// this._engineName 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);
this._keywordSubstitute = {
host: engine.getResultDomain(),
keyword: null,
};
}
// Add the first heuristic result, if any. Set _addingHeuristicResult // Add the first heuristic result, if any. Set _addingHeuristicResult
// to true so that when the result is added, "heuristic" can be included in // to true so that when the result is added, "heuristic" can be included in
// its style. // its style.
@ -1092,10 +1085,7 @@ Search.prototype = {
this._addMatch(match); this._addMatch(match);
if (!this._keywordSubstitute) { if (!this._keywordSubstitute) {
this._keywordSubstitute = { this._keywordSubstitute = entry.url.host;
host: entry.url.host,
keyword,
};
} }
return true; return true;
}, },
@ -1114,10 +1104,7 @@ Search.prototype = {
}; };
this._addSearchEngineMatch(this._searchEngineAliasMatch); this._addSearchEngineMatch(this._searchEngineAliasMatch);
if (!this._keywordSubstitute) { if (!this._keywordSubstitute) {
this._keywordSubstitute = { this._keywordSubstitute = engine.getResultDomain();
host: engine.getResultDomain(),
keyword: alias,
};
} }
return true; return true;
}, },
@ -1708,10 +1695,7 @@ Search.prototype = {
get _keywordSubstitutedSearchString() { get _keywordSubstitutedSearchString() {
let tokens = this._searchTokens.map(t => t.value); let tokens = this._searchTokens.map(t => t.value);
if (this._keywordSubstitute) { if (this._keywordSubstitute) {
tokens = [ tokens = [this._keywordSubstitute, ...tokens.slice(1)];
this._keywordSubstitute.host,
...tokens.slice(this._keywordSubstitute.keyword ? 1 : 0),
];
} }
return tokens.join(" "); return tokens.join(" ");
}, },