Bug 1915766 - Add a Nimbus variable that hides the Suggest UI. r=daisuke,settings-reviewers,mossop
This makes `browser_search_firefoxSuggest.js` more realistic by installing a Nimbus experiment to change the Suggest scenario instead of manually setting the scenario via the helper function. (The "scenario" just means whether Suggest is enabled or not, basically. "history" means it's not enabled; "offline" and "online" mean it's enabled. The difference between the latter two is that in "online" the user has opted in to the Merino server, and that only means one of the Suggest prefs is true instead of false.) I noticed `browser_privacy_firefoxSuggest.js` does not check the visibility of its Suggest section at all, so I added similar tasks to it and factored out the common helpers into `head.js`. Depends on D221097 Differential Revision: https://phabricator.services.mozilla.com/D221099
This commit is contained in:
@@ -2737,7 +2737,10 @@ var gPrivacyPane = {
|
||||
_updateFirefoxSuggestToggle(onInit = false) {
|
||||
let container = document.getElementById("firefoxSuggestPrivacyContainer");
|
||||
|
||||
if (UrlbarPrefs.get("quickSuggestEnabled")) {
|
||||
if (
|
||||
UrlbarPrefs.get("quickSuggestEnabled") &&
|
||||
!UrlbarPrefs.get("quickSuggestHideSettingsUI")
|
||||
) {
|
||||
container.removeAttribute("hidden");
|
||||
} else if (!onInit) {
|
||||
container.setAttribute("hidden", "true");
|
||||
|
||||
@@ -345,7 +345,10 @@ var gSearchPane = {
|
||||
_updateFirefoxSuggestSection(onInit = false) {
|
||||
let container = document.getElementById("firefoxSuggestContainer");
|
||||
|
||||
if (UrlbarPrefs.get("quickSuggestEnabled")) {
|
||||
if (
|
||||
UrlbarPrefs.get("quickSuggestEnabled") &&
|
||||
!UrlbarPrefs.get("quickSuggestHideSettingsUI")
|
||||
) {
|
||||
// Update the l10n IDs of text elements.
|
||||
let l10nIdByElementId = {
|
||||
locationBarGroupHeader: "addressbar-header-firefox-suggest",
|
||||
|
||||
@@ -9,7 +9,7 @@ ChromeUtils.defineESModuleGetters(this, {
|
||||
QuickSuggest: "resource:///modules/QuickSuggest.sys.mjs",
|
||||
});
|
||||
|
||||
const CONTAINER_ID = "dataCollectionGroup";
|
||||
const CONTAINER_ID = "firefoxSuggestPrivacyContainer";
|
||||
const DATA_COLLECTION_TOGGLE_ID = "firefoxSuggestDataCollectionPrivacyToggle";
|
||||
const LEARN_MORE_CLASS = "firefoxSuggestLearnMore";
|
||||
|
||||
@@ -17,6 +17,158 @@ const LEARN_MORE_CLASS = "firefoxSuggestLearnMore";
|
||||
// run through, so request a longer timeout.
|
||||
requestLongerTimeout(10);
|
||||
|
||||
// The following tasks check the initial visibility of the Firefox Suggest UI
|
||||
// and the visibility after installing a Nimbus experiment.
|
||||
|
||||
add_task(async function history_suggestDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["history"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function history_suggestEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["history"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function history_suggestEnabled_hideSettingsUIDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["history"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
quickSuggestHideSettingsUI: false,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function history_suggestEnabled_hideSettingsUIEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["history"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
quickSuggestHideSettingsUI: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function offlineOnline_suggestDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: false,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function offlineOnline_suggestEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function offlineOnline_hideSettingsUIDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestHideSettingsUI: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function offlineOnline_hideSettingsUIEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestHideSettingsUI: true,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function offlineOnline_suggestEnabled_hideSettingsUIDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
quickSuggestHideSettingsUI: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function offlineOnline_suggestEnabled_hideSettingsUIEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
pane: "privacy",
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
quickSuggestHideSettingsUI: true,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Clicks each of the checkboxes and toggles and makes sure the prefs and info box are updated.
|
||||
add_task(async function clickCheckboxesOrToggle() {
|
||||
await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
|
||||
|
||||
@@ -9,14 +9,6 @@ ChromeUtils.defineESModuleGetters(this, {
|
||||
QuickSuggest: "resource:///modules/QuickSuggest.sys.mjs",
|
||||
});
|
||||
|
||||
ChromeUtils.defineLazyGetter(this, "QuickSuggestTestUtils", () => {
|
||||
const { QuickSuggestTestUtils: module } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/QuickSuggestTestUtils.sys.mjs"
|
||||
);
|
||||
module.init(this);
|
||||
return module;
|
||||
});
|
||||
|
||||
const CONTAINER_ID = "firefoxSuggestContainer";
|
||||
const NONSPONSORED_CHECKBOX_ID = "firefoxSuggestNonsponsored";
|
||||
const SPONSORED_CHECKBOX_ID = "firefoxSuggestSponsored";
|
||||
@@ -29,172 +21,250 @@ const PREF_URLBAR_QUICKSUGGEST_BLOCKLIST =
|
||||
"browser.urlbar.quicksuggest.blockedDigests";
|
||||
const PREF_URLBAR_WEATHER_USER_ENABLED = "browser.urlbar.suggest.weather";
|
||||
|
||||
// Maps text element IDs to `{ enabled, disabled }`, where `enabled` is the
|
||||
// expected l10n ID when the Firefox Suggest feature is enabled, and `disabled`
|
||||
// is when disabled.
|
||||
const EXPECTED_L10N_IDS = {
|
||||
locationBarGroupHeader: {
|
||||
enabled: "addressbar-header-firefox-suggest",
|
||||
disabled: "addressbar-header",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
enabled: "addressbar-suggest-firefox-suggest",
|
||||
disabled: "addressbar-suggest",
|
||||
},
|
||||
};
|
||||
|
||||
// This test can take a while due to the many permutations some of these tasks
|
||||
// run through, so request a longer timeout.
|
||||
requestLongerTimeout(10);
|
||||
|
||||
// The following tasks check the visibility of the Firefox Suggest UI based on
|
||||
// the value of the feature pref. See doVisibilityTest().
|
||||
// The following tasks check the initial visibility of the Firefox Suggest UI
|
||||
// and the visibility after installing a Nimbus experiment.
|
||||
|
||||
add_task(async function historyToOffline() {
|
||||
await doVisibilityTest({
|
||||
initialScenario: "history",
|
||||
initialExpectedVisibility: false,
|
||||
newScenario: "offline",
|
||||
newExpectedVisibility: true,
|
||||
add_task(async function history_suggestDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["history"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
locationBarGroupHeader: { isVisible: true, l10nId: "addressbar-header" },
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function historyToOnline() {
|
||||
await doVisibilityTest({
|
||||
initialScenario: "history",
|
||||
initialExpectedVisibility: false,
|
||||
newScenario: "online",
|
||||
newExpectedVisibility: true,
|
||||
add_task(async function history_suggestEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["history"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
locationBarGroupHeader: { isVisible: true, l10nId: "addressbar-header" },
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
locationBarGroupHeader: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-header-firefox-suggest",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest-firefox-suggest",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function offlineToHistory() {
|
||||
await doVisibilityTest({
|
||||
initialScenario: "offline",
|
||||
initialExpectedVisibility: true,
|
||||
newScenario: "history",
|
||||
newExpectedVisibility: false,
|
||||
add_task(async function history_suggestEnabled_hideSettingsUIDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["history"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
locationBarGroupHeader: { isVisible: true, l10nId: "addressbar-header" },
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
quickSuggestHideSettingsUI: false,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
locationBarGroupHeader: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-header-firefox-suggest",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest-firefox-suggest",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function offlineToOnline() {
|
||||
await doVisibilityTest({
|
||||
initialScenario: "offline",
|
||||
initialExpectedVisibility: true,
|
||||
newScenario: "online",
|
||||
newExpectedVisibility: true,
|
||||
add_task(async function history_suggestEnabled_hideSettingsUIEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["history"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
locationBarGroupHeader: { isVisible: true, l10nId: "addressbar-header" },
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
quickSuggestHideSettingsUI: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function onlineToHistory() {
|
||||
await doVisibilityTest({
|
||||
initialScenario: "online",
|
||||
initialExpectedVisibility: true,
|
||||
newScenario: "history",
|
||||
newExpectedVisibility: false,
|
||||
add_task(async function offlineOnline_suggestDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
locationBarGroupHeader: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-header-firefox-suggest",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest-firefox-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: false,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
locationBarGroupHeader: { isVisible: true, l10nId: "addressbar-header" },
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function onlineToOffline() {
|
||||
await doVisibilityTest({
|
||||
initialScenario: "online",
|
||||
initialExpectedVisibility: true,
|
||||
newScenario: "offline",
|
||||
newExpectedVisibility: true,
|
||||
add_task(async function offlineOnline_suggestEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
locationBarGroupHeader: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-header-firefox-suggest",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest-firefox-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Runs a test that checks the visibility of the Firefox Suggest preferences UI
|
||||
* based on scenario pref.
|
||||
*
|
||||
* @param {string} initialScenario
|
||||
* The initial scenario.
|
||||
* @param {boolean} initialExpectedVisibility
|
||||
* Whether the UI should be visible with the initial scenario.
|
||||
* @param {string} newScenario
|
||||
* The updated scenario.
|
||||
* @param {boolean} newExpectedVisibility
|
||||
* Whether the UI should be visible after setting the new scenario.
|
||||
*/
|
||||
async function doVisibilityTest({
|
||||
initialScenario,
|
||||
initialExpectedVisibility,
|
||||
newScenario,
|
||||
newExpectedVisibility,
|
||||
}) {
|
||||
info(
|
||||
"Running visibility test: " +
|
||||
JSON.stringify(
|
||||
{
|
||||
initialScenario,
|
||||
initialExpectedVisibility,
|
||||
newScenario,
|
||||
newExpectedVisibility,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
add_task(async function offlineOnline_hideSettingsUIDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
locationBarGroupHeader: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-header-firefox-suggest",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest-firefox-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestHideSettingsUI: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Set the initial scenario.
|
||||
await QuickSuggestTestUtils.setScenario(initialScenario);
|
||||
add_task(async function offlineOnline_hideSettingsUIEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
locationBarGroupHeader: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-header-firefox-suggest",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest-firefox-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestHideSettingsUI: true,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
locationBarGroupHeader: { isVisible: true, l10nId: "addressbar-header" },
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Assert.equal(
|
||||
Services.prefs.getBoolPref("browser.urlbar.quicksuggest.enabled"),
|
||||
initialExpectedVisibility,
|
||||
`quicksuggest.enabled is correct after setting initial scenario, initialExpectedVisibility=${initialExpectedVisibility}`
|
||||
);
|
||||
add_task(async function offlineOnline_suggestEnabled_hideSettingsUIDisabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
locationBarGroupHeader: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-header-firefox-suggest",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest-firefox-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
quickSuggestHideSettingsUI: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Open prefs and check the initial visibility.
|
||||
await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
|
||||
|
||||
let doc = gBrowser.selectedBrowser.contentDocument;
|
||||
let container = doc.getElementById(CONTAINER_ID);
|
||||
Assert.equal(
|
||||
BrowserTestUtils.isVisible(container),
|
||||
initialExpectedVisibility,
|
||||
`The container has the expected initial visibility, initialExpectedVisibility=${initialExpectedVisibility}`
|
||||
);
|
||||
|
||||
// Check the text elements' l10n IDs.
|
||||
for (let [id, { enabled, disabled }] of Object.entries(EXPECTED_L10N_IDS)) {
|
||||
Assert.equal(
|
||||
doc.getElementById(id).dataset.l10nId,
|
||||
initialExpectedVisibility ? enabled : disabled,
|
||||
`Initial l10n ID for element with ID ${id}, initialExpectedVisibility=${initialExpectedVisibility}`
|
||||
);
|
||||
}
|
||||
|
||||
// Set the new scenario.
|
||||
await QuickSuggestTestUtils.setScenario(newScenario);
|
||||
|
||||
Assert.equal(
|
||||
Services.prefs.getBoolPref("browser.urlbar.quicksuggest.enabled"),
|
||||
newExpectedVisibility,
|
||||
`quicksuggest.enabled is correct after setting new scenario, newExpectedVisibility=${newExpectedVisibility}`
|
||||
);
|
||||
|
||||
// Check visibility again.
|
||||
Assert.equal(
|
||||
BrowserTestUtils.isVisible(container),
|
||||
newExpectedVisibility,
|
||||
`The container has the expected visibility after setting new scenario, newExpectedVisibility=${newExpectedVisibility}`
|
||||
);
|
||||
|
||||
// Check the text elements' l10n IDs again.
|
||||
for (let [id, { enabled, disabled }] of Object.entries(EXPECTED_L10N_IDS)) {
|
||||
Assert.equal(
|
||||
doc.getElementById(id).dataset.l10nId,
|
||||
newExpectedVisibility ? enabled : disabled,
|
||||
`New l10n ID for element with ID ${id}, newExpectedVisibility=${newExpectedVisibility}`
|
||||
);
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
gBrowser.removeCurrentTab();
|
||||
await QuickSuggestTestUtils.setScenario(null);
|
||||
}
|
||||
add_task(async function offlineOnline_suggestEnabled_hideSettingsUIEnabled() {
|
||||
await doSuggestVisibilityTest({
|
||||
initialScenarios: ["offline", "online"],
|
||||
initialExpected: {
|
||||
[CONTAINER_ID]: { isVisible: true },
|
||||
locationBarGroupHeader: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-header-firefox-suggest",
|
||||
},
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest-firefox-suggest",
|
||||
},
|
||||
},
|
||||
nimbusVariables: {
|
||||
quickSuggestEnabled: true,
|
||||
quickSuggestHideSettingsUI: true,
|
||||
},
|
||||
newExpected: {
|
||||
[CONTAINER_ID]: { isVisible: false },
|
||||
locationBarGroupHeader: { isVisible: true, l10nId: "addressbar-header" },
|
||||
locationBarSuggestionLabel: {
|
||||
isVisible: true,
|
||||
l10nId: "addressbar-suggest",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Verifies all 8 states of the 3 checkboxes and their related info box states.
|
||||
add_task(async function checkboxesAndInfoBox() {
|
||||
|
||||
@@ -5,6 +5,14 @@ const { PermissionTestUtils } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/PermissionTestUtils.sys.mjs"
|
||||
);
|
||||
|
||||
ChromeUtils.defineLazyGetter(this, "QuickSuggestTestUtils", () => {
|
||||
const { QuickSuggestTestUtils: module } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/QuickSuggestTestUtils.sys.mjs"
|
||||
);
|
||||
module.init(this);
|
||||
return module;
|
||||
});
|
||||
|
||||
const kDefaultWait = 2000;
|
||||
|
||||
function is_element_visible(aElement, aMsg) {
|
||||
@@ -333,3 +341,106 @@ async function mockDefaultFxAInstance() {
|
||||
|
||||
return { mock, unmock };
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a test that checks the visibility of the Firefox Suggest preferences UI.
|
||||
* An initial Suggest scenario is set and visibility is checked. Then a Nimbus
|
||||
* experiment is installed and visibility is checked again. Finally the page is
|
||||
* reopened and visibility is checked again.
|
||||
*
|
||||
* @param {array} initialScenarios
|
||||
* Array of Suggest scenario names. The test will be run once per scenario,
|
||||
* with each test starting with a given scenario.
|
||||
* @param {object} initialExpected
|
||||
* The expected visibility after setting the initial scenario. It should be an
|
||||
* object that can be passed to `assertSuggestVisibility()`.
|
||||
* @param {object} nimbusVariables
|
||||
* An object mapping Nimbus variable names to values.
|
||||
* @param {object} newExpected
|
||||
* The expected visibility after installing the Nimbus experiment. It should
|
||||
* be an object that can be passed to `assertSuggestVisibility()`.
|
||||
* @param {string} pane
|
||||
* The pref pane to open.
|
||||
*/
|
||||
async function doSuggestVisibilityTest({
|
||||
initialScenarios,
|
||||
initialExpected,
|
||||
nimbusVariables,
|
||||
newExpected = initialExpected,
|
||||
pane = "search",
|
||||
}) {
|
||||
for (let scenario of initialScenarios) {
|
||||
info(
|
||||
"Running Suggest visibility test: " +
|
||||
JSON.stringify(
|
||||
{
|
||||
scenario,
|
||||
initialExpected,
|
||||
nimbusVariables,
|
||||
newExpected,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
|
||||
// Set the initial scenario.
|
||||
await QuickSuggestTestUtils.setScenario(scenario);
|
||||
|
||||
// Open prefs and check the initial visibility.
|
||||
await openPreferencesViaOpenPreferencesAPI(pane, { leaveOpen: true });
|
||||
assertSuggestVisibility(initialExpected);
|
||||
|
||||
// Install a Nimbus experiment.
|
||||
await QuickSuggestTestUtils.withExperiment({
|
||||
valueOverrides: nimbusVariables,
|
||||
callback: async () => {
|
||||
// Check visibility again.
|
||||
assertSuggestVisibility(newExpected);
|
||||
|
||||
// To make sure visibility is properly updated on load, close the tab,
|
||||
// open the prefs again, and check visibility.
|
||||
gBrowser.removeCurrentTab();
|
||||
await openPreferencesViaOpenPreferencesAPI(pane, { leaveOpen: true });
|
||||
assertSuggestVisibility(newExpected);
|
||||
},
|
||||
});
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
}
|
||||
|
||||
await QuickSuggestTestUtils.setScenario(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the visibility of the Suggest UI.
|
||||
*
|
||||
* @param {object} expectedByElementId
|
||||
* An object that maps IDs of elements in the current tab to objects with the
|
||||
* following properties:
|
||||
*
|
||||
* {bool} isVisible
|
||||
* Whether the element is expected to be visible.
|
||||
* {string} l10nId
|
||||
* The expected l10n ID of the element. Optional.
|
||||
*/
|
||||
function assertSuggestVisibility(expectedByElementId) {
|
||||
let doc = gBrowser.selectedBrowser.contentDocument;
|
||||
for (let [elementId, { isVisible, l10nId }] of Object.entries(
|
||||
expectedByElementId
|
||||
)) {
|
||||
let element = doc.getElementById(elementId);
|
||||
Assert.strictEqual(
|
||||
BrowserTestUtils.isVisible(element),
|
||||
isVisible,
|
||||
"The element should be visible as expected"
|
||||
);
|
||||
if (l10nId) {
|
||||
Assert.equal(
|
||||
element.dataset.l10nId,
|
||||
l10nId,
|
||||
"The l10n ID should be correct for element " + elementId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user