Bug 1909565 - Move Fakespot suggestions to the bottom of the Firefox Suggest section, r=daisuke

This also adds a Nimbus variable so we can easily change the index for
experiments.

Depends on D217510

Differential Revision: https://phabricator.services.mozilla.com/D217524
This commit is contained in:
Drew Willcoxon 2024-07-24 00:18:11 +00:00
parent 7ae020ff8a
commit 61754b1086
5 changed files with 51 additions and 10 deletions

View File

@ -657,6 +657,10 @@ pref("browser.urlbar.fakespot.featureGate", false);
// the suggestion. 0 means the min length should be taken from Nimbus.
pref("browser.urlbar.fakespot.minKeywordLength", 4);
// The index of Fakespot results within the Firefox Suggest section. A negative
// index is relative to the end of the section.
pref("browser.urlbar.fakespot.suggestedIndex", -1);
// If `browser.urlbar.fakespot.featureGate` is true, this controls whether
// Fakespot suggestions are turned on.
pref("browser.urlbar.suggest.fakespot", true);

View File

@ -139,6 +139,10 @@ const PREF_URLBAR_DEFAULTS = new Map([
// for Fakespot suggestions.
["fakespot.showLessFrequentlyCount", 0],
// The index of Fakespot results within the Firefox Suggest section. A
// negative index is relative to the end of the section.
["fakespot.suggestedIndex", -1],
// When true, `javascript:` URLs are not included in search results.
["filter.javascript", true],

View File

@ -134,16 +134,20 @@ export class FakespotSuggestions extends BaseFeature {
dynamicType: "fakespot",
};
const result = new lazy.UrlbarResult(
lazy.UrlbarUtils.RESULT_TYPE.DYNAMIC,
lazy.UrlbarUtils.RESULT_SOURCE.SEARCH,
...lazy.UrlbarResult.payloadAndSimpleHighlights(
queryContext.tokens,
payload
)
return Object.assign(
new lazy.UrlbarResult(
lazy.UrlbarUtils.RESULT_TYPE.DYNAMIC,
lazy.UrlbarUtils.RESULT_SOURCE.SEARCH,
...lazy.UrlbarResult.payloadAndSimpleHighlights(
queryContext.tokens,
payload
)
),
{
isSuggestedIndexRelativeToGroup: true,
suggestedIndex: lazy.UrlbarPrefs.get("fakespotSuggestedIndex"),
}
);
return result;
}
getViewUpdate(result) {

View File

@ -792,10 +792,33 @@ async function doMinKeywordLengthTest({
}
}
// Tests the `fakespotSuggestedIndex` Nimbus variable.
add_task(async function suggestedIndex() {
// If this fails, please update this task. Otherwise it's not actually testing
// a non-default suggested index.
Assert.notEqual(
UrlbarPrefs.get("fakespotSuggestedIndex"),
0,
"Sanity check: Default value of fakespotSuggestedIndex is not 0"
);
let cleanUpNimbusEnable = await UrlbarTestUtils.initNimbusFeature({
fakespotSuggestedIndex: 0,
});
await check_results({
context: createContext(PRIMARY_SEARCH_STRING, {
providers: [UrlbarProviderQuickSuggest.name],
isPrivate: false,
}),
matches: [makeExpectedResult({ suggestedIndex: 0 })],
});
await cleanUpNimbusEnable();
});
function makeExpectedResult({
url = PRIMARY_URL,
title = PRIMARY_TITLE,
suggestedIndex = 0,
suggestedIndex = -1,
isSuggestedIndexRelativeToGroup = true,
originalUrl = undefined,
displayUrl = undefined,

View File

@ -243,6 +243,12 @@ urlbar:
will be able to click the "Show less frequently" command for Fakespot
suggestions. If undefined or zero, the user will be able to click the
command without any limit.
fakespotSuggestedIndex:
type: int
fallbackPref: browser.urlbar.fakespot.suggestedIndex
description: >-
The index of Fakespot results within the Firefox Suggest section. A
negative index is relative to the end of the section.
mdnFeatureGate:
type: boolean
setPref: