forked from mirrors/gecko-dev
This does a few things: * Unify the view implementations of rich suggestions, Firefox Suggest sponsored results, and best match. I did this by using the best match implementation and extending it to rich suggestions and Suggest sponsored. * Use the unified implementation for Pocket suggestions too. * Add a bottom-text concept since Pocket suggestions shown as top picks need to show both a description and some text below it. (The actual bottom text per result is added in D182632 since I didn't want to make this patch bigger than necessary) I have a couple motivations for these changes: * I'm implementing Pocket suggestions, which need to show some text below the suggestion title as well as the URL. I was going to just use the Firefox Suggest sponsored approach, where the action text is wrapped below the title, but that doesn't work because it can't show both the wrapped action text and the URL. * IMO we should use rich suggestions as the basis for all rows going forward, i.e., unify the different row implementations around rich suggestions. The reason I chose the best match implementation instead of the rich suggestions implementation is because the grid-based approach of rich suggestions doesn't work well when the URL also needs to be shown. The URL should be baseline-aligned with the row title, which isn't easy to do when the URL is outside the grid. The rich suggestions implementation also doesn't wrap the URL. Other details: * The `rich-suggestion=no-icon` attribute value is only used for styling, so we can replace it with `@supports -moz-bool-pref()`. That lets us make the `rich-suggestion` attribute a simple boolean. * I kept the `isBestMatch` property for results since `searchEngagementTelemetryGroup()` uses it to return "top_pick", and the view also uses it to create the "Top pick" row/group label. It still has semantic meaning so I think that's OK. It's no longer used by the view to create different DOM or styling. * Move `isRichSuggestion` from the payload to the result itself, since it's no longer used for only one type of result. It's like `isBestMatch`, which is also on the result. * Add `richSuggestionIconSize` to the result too. The best match icon size is 52. The Pocket best match icon size is 24 (but will have added padding and a background color to make it appear 52px). IMO this is better than adding rules for each type of suggestion to the CSS. It's cleaner and also indicates what the "standard" icon sizes are. Depends on D182580 Differential Revision: https://phabricator.services.mozilla.com/D182537
198 lines
6.2 KiB
JavaScript
198 lines
6.2 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
ChromeUtils.defineESModuleGetters(this, {
|
|
QuickSuggest: "resource:///modules/QuickSuggest.sys.mjs",
|
|
UrlbarProviderQuickSuggest:
|
|
"resource:///modules/UrlbarProviderQuickSuggest.sys.mjs",
|
|
});
|
|
|
|
// Tests that registering an exposureResults pref and triggering a match causes
|
|
// the exposure event to be recorded on the UrlbarResults.
|
|
const REMOTE_SETTINGS_RESULTS = [
|
|
{
|
|
id: 1,
|
|
url: "http://test.com/q=frabbits",
|
|
title: "frabbits",
|
|
keywords: ["test"],
|
|
click_url: "http://click.reporting.test.com/",
|
|
impression_url: "http://impression.reporting.test.com/",
|
|
advertiser: "TestAdvertiser",
|
|
},
|
|
{
|
|
id: 2,
|
|
url: "http://test.com/q=frabbits",
|
|
title: "frabbits",
|
|
keywords: ["non_sponsored"],
|
|
click_url: "http://click.reporting.test.com/",
|
|
impression_url: "http://impression.reporting.test.com/",
|
|
advertiser: "wikipedia",
|
|
iab_category: "5 - Education",
|
|
},
|
|
];
|
|
|
|
const EXPECTED_REMOTE_SETTINGS_URLBAR_RESULT = {
|
|
type: UrlbarUtils.RESULT_TYPE.URL,
|
|
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
|
|
heuristic: false,
|
|
payload: {
|
|
telemetryType: "adm_sponsored",
|
|
qsSuggestion: "test",
|
|
title: "frabbits",
|
|
url: "http://test.com/q=frabbits",
|
|
originalUrl: "http://test.com/q=frabbits",
|
|
icon: null,
|
|
sponsoredImpressionUrl: "http://impression.reporting.test.com/",
|
|
sponsoredClickUrl: "http://click.reporting.test.com/",
|
|
sponsoredBlockId: 1,
|
|
sponsoredAdvertiser: "TestAdvertiser",
|
|
isSponsored: true,
|
|
descriptionL10n: { id: "urlbar-result-action-sponsored" },
|
|
helpUrl: QuickSuggest.HELP_URL,
|
|
helpL10n: {
|
|
id: UrlbarPrefs.get("resultMenu")
|
|
? "urlbar-result-menu-learn-more-about-firefox-suggest"
|
|
: "firefox-suggest-urlbar-learn-more",
|
|
},
|
|
isBlockable: UrlbarPrefs.get("quickSuggestBlockingEnabled"),
|
|
blockL10n: {
|
|
id: UrlbarPrefs.get("resultMenu")
|
|
? "urlbar-result-menu-dismiss-firefox-suggest"
|
|
: "firefox-suggest-urlbar-block",
|
|
},
|
|
displayUrl: "http://test.com/q=frabbits",
|
|
source: "remote-settings",
|
|
provider: "AdmWikipedia",
|
|
},
|
|
};
|
|
|
|
const EXPECTED_NON_SPONSORED_REMOTE_SETTINGS_RESULT = {
|
|
type: UrlbarUtils.RESULT_TYPE.URL,
|
|
source: UrlbarUtils.RESULT_SOURCE.SEARCH,
|
|
heuristic: false,
|
|
payload: {
|
|
telemetryType: "adm_nonsponsored",
|
|
qsSuggestion: "non_sponsored",
|
|
title: "frabbits",
|
|
url: "http://test.com/q=frabbits",
|
|
originalUrl: "http://test.com/q=frabbits",
|
|
icon: null,
|
|
sponsoredImpressionUrl: "http://impression.reporting.test.com/",
|
|
sponsoredClickUrl: "http://click.reporting.test.com/",
|
|
sponsoredBlockId: 2,
|
|
sponsoredAdvertiser: "wikipedia",
|
|
sponsoredIabCategory: "5 - Education",
|
|
isSponsored: false,
|
|
helpUrl: QuickSuggest.HELP_URL,
|
|
helpL10n: {
|
|
id: UrlbarPrefs.get("resultMenu")
|
|
? "urlbar-result-menu-learn-more-about-firefox-suggest"
|
|
: "firefox-suggest-urlbar-learn-more",
|
|
},
|
|
isBlockable: UrlbarPrefs.get("quickSuggestBlockingEnabled"),
|
|
blockL10n: {
|
|
id: UrlbarPrefs.get("resultMenu")
|
|
? "urlbar-result-menu-dismiss-firefox-suggest"
|
|
: "firefox-suggest-urlbar-block",
|
|
},
|
|
displayUrl: "http://test.com/q=frabbits",
|
|
source: "remote-settings",
|
|
provider: "AdmWikipedia",
|
|
},
|
|
};
|
|
|
|
add_setup(async function test_setup() {
|
|
// FOG needs a profile directory to put its data in.
|
|
do_get_profile();
|
|
|
|
// FOG needs to be initialized in order for data to flow.
|
|
Services.fog.initializeFOG();
|
|
|
|
UrlbarPrefs.set("quicksuggest.enabled", true);
|
|
UrlbarPrefs.set("suggest.quicksuggest.nonsponsored", true);
|
|
UrlbarPrefs.set("suggest.quicksuggest.sponsored", true);
|
|
UrlbarPrefs.set("quicksuggest.shouldShowOnboardingDialog", false);
|
|
|
|
await MerinoTestUtils.server.start();
|
|
|
|
// Set up the remote settings client with the test data.
|
|
await QuickSuggestTestUtils.ensureQuickSuggestInit({
|
|
remoteSettingsResults: [
|
|
{
|
|
type: "data",
|
|
attachment: REMOTE_SETTINGS_RESULTS,
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
add_task(async function testExposureCheck() {
|
|
UrlbarPrefs.set("quicksuggest.remoteSettings.enabled", true);
|
|
UrlbarPrefs.set("exposureResults", "rs_adm_sponsored");
|
|
UrlbarPrefs.set("showExposureResults", true);
|
|
|
|
let context = createContext("test", {
|
|
providers: [UrlbarProviderQuickSuggest.name],
|
|
isPrivate: false,
|
|
});
|
|
|
|
await check_results({
|
|
context,
|
|
matches: [EXPECTED_REMOTE_SETTINGS_URLBAR_RESULT],
|
|
});
|
|
|
|
Assert.equal(context.results[0].exposureResultType, "rs_adm_sponsored");
|
|
Assert.equal(context.results[0].exposureResultHidden, false);
|
|
});
|
|
|
|
add_task(async function testExposureCheckMultiple() {
|
|
UrlbarPrefs.set("quicksuggest.remoteSettings.enabled", true);
|
|
UrlbarPrefs.set("exposureResults", "rs_adm_sponsored,rs_adm_nonsponsored");
|
|
UrlbarPrefs.set("showExposureResults", true);
|
|
|
|
let context = createContext("test", {
|
|
providers: [UrlbarProviderQuickSuggest.name],
|
|
isPrivate: false,
|
|
});
|
|
|
|
await check_results({
|
|
context,
|
|
matches: [EXPECTED_REMOTE_SETTINGS_URLBAR_RESULT],
|
|
});
|
|
|
|
Assert.equal(context.results[0].exposureResultType, "rs_adm_sponsored");
|
|
Assert.equal(context.results[0].exposureResultHidden, false);
|
|
|
|
context = createContext("non_sponsored", {
|
|
providers: [UrlbarProviderQuickSuggest.name],
|
|
isPrivate: false,
|
|
});
|
|
|
|
await check_results({
|
|
context,
|
|
matches: [EXPECTED_NON_SPONSORED_REMOTE_SETTINGS_RESULT],
|
|
});
|
|
|
|
Assert.equal(context.results[0].exposureResultType, "rs_adm_nonsponsored");
|
|
Assert.equal(context.results[0].exposureResultHidden, false);
|
|
});
|
|
|
|
add_task(async function exposureDisplayFiltering() {
|
|
UrlbarPrefs.set("quicksuggest.remoteSettings.enabled", true);
|
|
UrlbarPrefs.set("exposureResults", "rs_adm_sponsored");
|
|
UrlbarPrefs.set("showExposureResults", false);
|
|
|
|
let context = createContext("test", {
|
|
providers: [UrlbarProviderQuickSuggest.name],
|
|
isPrivate: false,
|
|
});
|
|
|
|
await check_results({
|
|
context,
|
|
matches: [EXPECTED_REMOTE_SETTINGS_URLBAR_RESULT],
|
|
});
|
|
|
|
Assert.equal(context.results[0].exposureResultType, "rs_adm_sponsored");
|
|
Assert.equal(context.results[0].exposureResultHidden, true);
|
|
});
|