Bug 1723149 - Enable Firefox Suggest address bar labels for all en-* locales. r=mak,nanj,andreio

Differential Revision: https://phabricator.services.mozilla.com/D121437
This commit is contained in:
Drew Willcoxon 2021-08-06 00:18:33 +00:00
parent cc1d110aaa
commit ad27e5fa12
8 changed files with 271 additions and 219 deletions

View File

@ -446,8 +446,8 @@ pref("browser.urlbar.dnsResolveSingleWordsAfterSearch", 1);
// for everyone.
pref("browser.urlbar.keepPanelOpenDuringImeComposition", false);
// Whether Firefox Suggest labels are shown in the urlbar view.
pref("browser.urlbar.experimental.firefoxSuggestLabels.enabled", false);
// Whether Firefox Suggest group labels are shown in the urlbar view.
pref("browser.urlbar.groupLabels.enabled", true);
pref("browser.altClickSave", false);

View File

@ -101,6 +101,11 @@ const PREF_URLBAR_DEFAULTS = new Map([
// Applies URL highlighting and other styling to the text in the urlbar input.
["formatting.enabled", true],
// Whether Firefox Suggest group labels are shown in the urlbar view in en-*
// locales. Labels are not shown in other locales but likely will be in the
// future.
["groupLabels.enabled", true],
// Whether the results panel should be kept open during IME composition.
["keepPanelOpenDuringImeComposition", false],

View File

@ -1703,10 +1703,11 @@ class UrlbarView {
}
_rowLabel(row, currentLabel) {
// We only show Firefox Suggest-related labels if the feature is enabled and
// we're not showing top sites.
// We only show Firefox Suggest-related group labels if the locale is en-*
// and we're not showing top sites.
if (
UrlbarPrefs.get("firefoxSuggestLabelsEnabled") &&
UrlbarPrefs.get("groupLabels.enabled") &&
Services.locale.appLocaleAsBCP47.substring(0, 2) == "en" &&
this._queryContext?.searchString &&
!row.result.heuristic
) {

View File

@ -40,7 +40,6 @@ XPCOMUtils.defineLazyServiceGetter(
// throw an "unknown pref" error if a test enrolls in a mock experiment and hits
// a code path that accesses a Nimbus feature variable not defined here.
const DEFAULT_EXPERIMENT_FEATURE_VARIABLES = {
firefoxSuggestLabelsEnabled: false,
quickSuggestEnabled: false,
quickSuggestNonSponsoredIndex: -1,
quickSuggestShouldShowOnboardingDialog: true,

View File

@ -95,12 +95,11 @@ support-files =
[browser_engagement.js]
[browser_enter.js]
[browser_enterAfterMouseOver.js]
[browser_firefoxSuggestLabels.js]
[browser_focusedCmdK.js]
[browser_groupLabels.js]
support-files =
searchSuggestionEngine.xml
searchSuggestionEngine.sjs
skip-if = asan # Bug 1701321
[browser_focusedCmdK.js]
[browser_handleCommand_fallback.js]
[browser_hashChangeProxyState.js]
[browser_helpUrl.js]

View File

@ -74,10 +74,12 @@ add_task(async function switchToTab() {
window,
index
);
// The a11y text will include the "Firefox Suggest" pseudo-element label shown
// before the result.
await getResultText(
element,
"about: robots— Switch to Tab",
"Result a11y label should be: <title>— Switch to Tab"
"Firefox Suggest about: robots— Switch to Tab",
"Result a11y text is correct"
);
await UrlbarTestUtils.promisePopupClose(window);

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests Firefox Suggest group labels in the view.
// Tests group labels in the view.
"use strict";
@ -22,11 +22,21 @@ const FIREFOX_SUGGEST_LABEL = "Firefox Suggest";
// %s is replaced with the engine name.
const ENGINE_SUGGESTIONS_LABEL = "%s Suggestions";
// Allow more time for Mac machines so they don't time out in verify mode.
if (AppConstants.platform == "macosx") {
requestLongerTimeout(3);
}
add_task(async function init() {
Assert.ok(
UrlbarPrefs.get("showSearchSuggestionsFirst"),
"Precondition: Search suggestions shown first by default"
);
Assert.equal(
Services.locale.appLocaleAsBCP47,
"en-US",
"Precondition: App locale is en-US"
);
// Add some history.
await PlacesUtils.history.clear();
@ -57,22 +67,22 @@ add_task(async function init() {
});
});
// The Firefox Suggest label should not appear when the view shows top sites.
add_task(async function topSites() {
await withExperiment(async () => {
// The Firefox Suggest label should not appear when the locale is not en-*.
add_task(async function unsupportedLocale() {
await withLocales(["de"], async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "",
value: "test",
});
await checkLabels(-1, {});
await checkLabels(MAX_RESULTS, {});
await UrlbarTestUtils.promisePopupClose(window);
});
});
// The Firefox Suggest label should appear when the search string is non-empty
// and there are only general results.
add_task(async function general() {
await withExperiment(async () => {
// The Firefox Suggest label should appear when the locale is en-* but not
// en-US.
add_task(async function supportedLocaleNonUS() {
await withLocales(["en-GB"], async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
@ -84,20 +94,55 @@ add_task(async function general() {
});
});
// The Firefox Suggest label should not appear when the labels pref is disabled.
add_task(async function prefDisabled() {
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.groupLabels.enabled", false]],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {});
await UrlbarTestUtils.promisePopupClose(window);
await SpecialPowers.popPrefEnv();
});
// The Firefox Suggest label should not appear when the view shows top sites.
add_task(async function topSites() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "",
});
await checkLabels(-1, {});
await UrlbarTestUtils.promisePopupClose(window);
});
// The Firefox Suggest label should appear when the search string is non-empty
// and there are only general results.
add_task(async function general() {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
});
// The Firefox Suggest label should appear when the search string is non-empty
// and there are suggestions followed by general results.
add_task(async function suggestionsBeforeGeneral() {
await withExperiment(async () => {
await withSuggestions(async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
3: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
await withSuggestions(async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
3: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
});
});
@ -105,22 +150,20 @@ add_task(async function suggestionsBeforeGeneral() {
// string is non-empty, general results are shown before suggestions, and there
// are general and suggestion results.
add_task(async function generalBeforeSuggestions() {
await withExperiment(async () => {
await withSuggestions(async engine => {
Assert.ok(engine.name, "Engine name is non-empty");
await SpecialPowers.pushPrefEnv({
set: [[SUGGESTIONS_FIRST_PREF, false]],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
[MAX_RESULTS - 2]: engineSuggestionsLabel(engine.name),
});
await UrlbarTestUtils.promisePopupClose(window);
await withSuggestions(async engine => {
Assert.ok(engine.name, "Engine name is non-empty");
await SpecialPowers.pushPrefEnv({
set: [[SUGGESTIONS_FIRST_PREF, false]],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
[MAX_RESULTS - 2]: engineSuggestionsLabel(engine.name),
});
await UrlbarTestUtils.promisePopupClose(window);
});
});
@ -130,18 +173,16 @@ add_task(async function generalBeforeSuggestions() {
add_task(async function generalBeforeSuggestions_suggestionsOnly() {
await PlacesUtils.history.clear();
await withExperiment(async () => {
await withSuggestions(async engine => {
await SpecialPowers.pushPrefEnv({
set: [[SUGGESTIONS_FIRST_PREF, false]],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(3, {});
await UrlbarTestUtils.promisePopupClose(window);
await withSuggestions(async engine => {
await SpecialPowers.pushPrefEnv({
set: [[SUGGESTIONS_FIRST_PREF, false]],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(3, {});
await UrlbarTestUtils.promisePopupClose(window);
});
// Add back history so subsequent tasks run with this test's initial state.
@ -160,23 +201,21 @@ add_task(async function suggestedIndex_only() {
let provider = new SuggestedIndexProvider(index);
UrlbarProvidersManager.registerProvider(provider);
await withExperiment(async () => {
await withSuggestions(async engine => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 3);
Assert.equal(
result.element.row.result.suggestedIndex,
index,
"Sanity check: Our suggested-index result is present"
);
await checkLabels(4, {
3: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
await withSuggestions(async engine => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 3);
Assert.equal(
result.element.row.result.suggestedIndex,
index,
"Sanity check: Our suggested-index result is present"
);
await checkLabels(4, {
3: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
});
UrlbarProvidersManager.unregisterProvider(provider);
@ -192,22 +231,20 @@ add_task(async function suggestedIndex_first() {
let provider = new SuggestedIndexProvider(index);
UrlbarProvidersManager.registerProvider(provider);
await withExperiment(async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, index);
Assert.equal(
result.element.row.result.suggestedIndex,
index,
"Sanity check: Our suggested-index result is present"
);
await checkLabels(MAX_RESULTS, {
[index]: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, index);
Assert.equal(
result.element.row.result.suggestedIndex,
index,
"Sanity check: Our suggested-index result is present"
);
await checkLabels(MAX_RESULTS, {
[index]: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
UrlbarProvidersManager.unregisterProvider(provider);
});
@ -219,25 +256,23 @@ add_task(async function suggestedIndex_notFirst() {
let provider = new SuggestedIndexProvider(index);
UrlbarProvidersManager.registerProvider(provider);
await withExperiment(async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
let result = await UrlbarTestUtils.getDetailsOfResultAt(
window,
MAX_RESULTS + index
);
Assert.equal(
result.element.row.result.suggestedIndex,
index,
"Sanity check: Our suggested-index result is present"
);
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
let result = await UrlbarTestUtils.getDetailsOfResultAt(
window,
MAX_RESULTS + index
);
Assert.equal(
result.element.row.result.suggestedIndex,
index,
"Sanity check: Our suggested-index result is present"
);
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
});
await UrlbarTestUtils.promisePopupClose(window);
UrlbarProvidersManager.unregisterProvider(provider);
});
@ -278,19 +313,17 @@ add_task(async function repeatLabels() {
});
UrlbarProvidersManager.registerProvider(provider);
await withExperiment(async () => {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(results.length, {
0: FIREFOX_SUGGEST_LABEL,
1: engineSuggestionsLabel(engineName),
2: FIREFOX_SUGGEST_LABEL,
3: engineSuggestionsLabel(engineName),
});
await UrlbarTestUtils.promisePopupClose(window);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(results.length, {
0: FIREFOX_SUGGEST_LABEL,
1: engineSuggestionsLabel(engineName),
2: FIREFOX_SUGGEST_LABEL,
3: engineSuggestionsLabel(engineName),
});
await UrlbarTestUtils.promisePopupClose(window);
UrlbarProvidersManager.unregisterProvider(provider);
});
@ -298,88 +331,84 @@ add_task(async function repeatLabels() {
// Clicking a row label shouldn't do anything.
add_task(async function clickLabel() {
await BrowserTestUtils.withNewTab("about:blank", async () => {
await withExperiment(async () => {
// Do a search. The mock history added in init() should appear with the
// Firefox Suggest label at index 1.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
});
// Check the result at index 2.
let result2 = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
Assert.ok(result2.url, "Result at index 2 has a URL");
let url2 = result2.url;
Assert.ok(
url2.startsWith("http://example.com/"),
"Result at index 2 is one of our mock history results"
);
// Get the row at index 3 and click above it. The click should hit the row
// at index 2 and load its URL. We do this to make sure our click code
// here in the test works properly and that performing a similar click
// relative to index 1 (see below) would hit the row at index 0 if not for
// the label at index 1.
let result3 = await UrlbarTestUtils.getDetailsOfResultAt(window, 3);
let loadPromise = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser
);
info("Performing click relative to index 3");
await UrlbarTestUtils.promisePopupClose(window, () =>
click(result3.element.row, { y: -2 })
);
info("Waiting for load after performing click relative to index 3");
await loadPromise;
Assert.equal(gBrowser.currentURI.spec, url2, "Loaded URL at index 2");
// Now do the search again.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
});
// Check the result at index 1, the one with the label.
let result1 = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
Assert.ok(result1.url, "Result at index 1 has a URL");
let url1 = result1.url;
Assert.ok(
url1.startsWith("http://example.com/"),
"Result at index 1 is one of our mock history results"
);
Assert.notEqual(url1, url2, "URLs at indexes 1 and 2 are different");
// Do a click on the row at index 1 in the same way as before. This time
// nothing should happen because the click should hit the label, not the
// row at index 0.
info("Clicking row label at index 1");
click(result1.element.row, { y: -2 });
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(r => setTimeout(r, 500));
Assert.ok(UrlbarTestUtils.isPopupOpen(window), "View remains open");
Assert.equal(
gBrowser.currentURI.spec,
url2,
"Current URL is still URL from index 2"
);
// Now click the main part of the row at index 1. Its URL should load.
loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
let { height } = result1.element.row.getBoundingClientRect();
info(`Clicking main part of the row at index 1, height=${height}`);
await UrlbarTestUtils.promisePopupClose(window, () =>
click(result1.element.row)
);
info("Waiting for load after clicking row at index 1");
await loadPromise;
Assert.equal(gBrowser.currentURI.spec, url1, "Loaded URL at index 1");
// Do a search. The mock history added in init() should appear with the
// Firefox Suggest label at index 1.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
});
// Check the result at index 2.
let result2 = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
Assert.ok(result2.url, "Result at index 2 has a URL");
let url2 = result2.url;
Assert.ok(
url2.startsWith("http://example.com/"),
"Result at index 2 is one of our mock history results"
);
// Get the row at index 3 and click above it. The click should hit the row
// at index 2 and load its URL. We do this to make sure our click code
// here in the test works properly and that performing a similar click
// relative to index 1 (see below) would hit the row at index 0 if not for
// the label at index 1.
let result3 = await UrlbarTestUtils.getDetailsOfResultAt(window, 3);
let loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
info("Performing click relative to index 3");
await UrlbarTestUtils.promisePopupClose(window, () =>
click(result3.element.row, { y: -2 })
);
info("Waiting for load after performing click relative to index 3");
await loadPromise;
Assert.equal(gBrowser.currentURI.spec, url2, "Loaded URL at index 2");
// Now do the search again.
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "test",
});
await checkLabels(MAX_RESULTS, {
1: FIREFOX_SUGGEST_LABEL,
});
// Check the result at index 1, the one with the label.
let result1 = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
Assert.ok(result1.url, "Result at index 1 has a URL");
let url1 = result1.url;
Assert.ok(
url1.startsWith("http://example.com/"),
"Result at index 1 is one of our mock history results"
);
Assert.notEqual(url1, url2, "URLs at indexes 1 and 2 are different");
// Do a click on the row at index 1 in the same way as before. This time
// nothing should happen because the click should hit the label, not the
// row at index 0.
info("Clicking row label at index 1");
click(result1.element.row, { y: -2 });
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(r => setTimeout(r, 500));
Assert.ok(UrlbarTestUtils.isPopupOpen(window), "View remains open");
Assert.equal(
gBrowser.currentURI.spec,
url2,
"Current URL is still URL from index 2"
);
// Now click the main part of the row at index 1. Its URL should load.
loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
let { height } = result1.element.row.getBoundingClientRect();
info(`Clicking main part of the row at index 1, height=${height}`);
await UrlbarTestUtils.promisePopupClose(window, () =>
click(result1.element.row)
);
info("Waiting for load after clicking row at index 1");
await loadPromise;
Assert.equal(gBrowser.currentURI.spec, url1, "Loaded URL at index 1");
});
});
@ -471,19 +500,6 @@ function engineSuggestionsLabel(engineName) {
return ENGINE_SUGGESTIONS_LABEL.replace("%s", engineName);
}
/**
* Calls a callback while enrolled in a mock experiment that enables bucket
* titles.
*
* @param {function} callback
*/
async function withExperiment(callback) {
await UrlbarTestUtils.withExperiment({
callback,
valueOverrides: { firefoxSuggestLabelsEnabled: true },
});
}
/**
* Adds a search engine that provides suggestions, calls your callback, and then
* remove the engine.
@ -509,6 +525,43 @@ async function withSuggestions(callback) {
}
}
/**
* Sets the app's locales, calls your callback, and resets locales.
*
* @param {array} locales
* An array of locale strings. The entire array will be set as the available
* locales, and the first locale in the array will be set as the requested
* locale.
* @param {function} callback
*/
async function withLocales(locales, callback) {
let available = Services.locale.availableLocales;
let requested = Services.locale.requestedLocales;
// Wait for engines to reload after changing locales. Otherwise there are TV
// failures.
let enginesPromise = SearchTestUtils.promiseSearchNotification(
"engines-reloaded"
);
Services.locale.availableLocales = locales;
Services.locale.requestedLocales = locales.slice(0, 1);
await enginesPromise;
Assert.equal(
Services.locale.appLocaleAsBCP47,
locales[0],
"App locale is now " + locales[0]
);
await callback();
enginesPromise = SearchTestUtils.promiseSearchNotification(
"engines-reloaded"
);
Services.locale.availableLocales = available;
Services.locale.requestedLocales = requested;
await enginesPromise;
}
function click(element, { x = undefined, y = undefined } = {}) {
let { width, height } = element.getBoundingClientRect();
if (typeof x != "number") {

View File

@ -14,13 +14,6 @@ const FeatureManifest = {
urlbar: {
description: "The Address Bar",
variables: {
firefoxSuggestLabelsEnabled: {
type: "boolean",
fallbackPref:
"browser.urlbar.experimental.firefoxSuggestLabels.enabled",
description:
"Whether to show the Firefox Suggest label above the general group in the urlbar view",
},
quickSuggestEnabled: {
type: "boolean",
fallbackPref: "browser.urlbar.quicksuggest.enabled",