Bug 1734461 - Also check and reset newtab pref from "Firefox Home" upgrade spotlight checkbox r=pdahiya

Add newtab pref checks and record events for when checkbox button is handled. Split up trigger tests to own file and share telemetry helpers from head.js.

Differential Revision: https://phabricator.services.mozilla.com/D127722
This commit is contained in:
Ed Lee 2021-10-07 03:59:56 +00:00
Родитель 64a7cbcd6a
Коммит b951e6a2f2
5 изменённых файлов: 186 добавлений и 132 удалений

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

@ -13,6 +13,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
});
const HOMEPAGE_PREF = "browser.startup.homepage";
const NEWTAB_PREF = "browser.newtabpage.enabled";
// Strings for various elements with matching ids on each screen.
const SCREEN_STRINGS = [
@ -250,12 +251,16 @@ function onLoad(ready) {
colorways.classList.remove("hidden");
adjustModalBackdrop();
// Show checkbox to revert homepage if customized.
if (Services.prefs.prefHasUserValue(HOMEPAGE_PREF)) {
// Show checkbox to revert homepage or newtab if customized.
if (
Services.prefs.prefHasUserValue(HOMEPAGE_PREF) ||
Services.prefs.prefHasUserValue(NEWTAB_PREF)
) {
checkbox.classList.remove("hidden");
recordEvent("show", "revert-home");
recordEvent("show", checkbox.lastElementChild.dataset.l10nId);
} else {
checkbox.remove();
checkbox.firstElementChild.checked = false;
}
return selected;
@ -268,9 +273,12 @@ function onLoad(ready) {
colorways.remove();
checkbox.remove();
// Revert homepage if still checked.
// Revert both homepage and newtab if still checked (potentially doing
// nothing if each pref is already the default value).
if (checkbox.firstElementChild.checked) {
Services.prefs.clearUserPref(HOMEPAGE_PREF);
Services.prefs.clearUserPref(NEWTAB_PREF);
recordEvent("button", checkbox.lastElementChild.dataset.l10nId);
}
}

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

@ -4,6 +4,7 @@ support-files =
[browser_browserGlue_telemetry.js]
[browser_browserGlue_upgradeDialog.js]
[browser_browserGlue_upgradeDialog_trigger.js]
[browser_bug538331.js]
skip-if = !updater
reason = test depends on update channel

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

@ -3,21 +3,6 @@ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { ExperimentFakes } = ChromeUtils.import(
"resource://testing-common/NimbusTestUtils.jsm"
);
const { NimbusFeatures, ExperimentFeature, ExperimentAPI } = ChromeUtils.import(
"resource://nimbus/ExperimentAPI.jsm"
);
function AssertEvents(message, ...events) {
info(`Checking telemetry events: ${message}`);
TelemetryTestUtils.assertEvents(
events.map(event => ["upgrade_dialog", ...event]),
{ category: "upgrade_dialog" }
);
}
add_task(async function open_close_dialog() {
mockShell();
@ -82,6 +67,8 @@ add_task(async function keep_home() {
await BrowserTestUtils.waitForEvent(win, "ready");
win.document.getElementById("primary").click();
await BrowserTestUtils.waitForEvent(win, "ready");
// Click the pre-selected checkbox to keep custom homepage.
win.document.getElementById("checkbox").click();
win.document.getElementById("secondary").click();
await BrowserTestUtils.waitForEvent(win, "ready");
@ -104,16 +91,48 @@ add_task(async function revert_home() {
win.close();
});
Assert.equal(
Services.prefs.prefHasUserValue("browser.startup.homepage"),
false,
Assert.ok(
!Services.prefs.prefHasUserValue("browser.startup.homepage"),
"Homepage reverted"
);
});
add_task(async function skip_screens() {
add_task(async function revert_newtab() {
Services.telemetry.clearEvents();
Services.prefs.setBoolPref("browser.newtabpage.enabled", false);
await showAndWaitForDialog(async win => {
// Always "randomly" select the first colorway.
win.Math.random = () => 0;
await BrowserTestUtils.waitForEvent(win, "ready");
win.document.getElementById("primary").click();
await BrowserTestUtils.waitForEvent(win, "ready");
win.document.getElementById("secondary").click();
await BrowserTestUtils.waitForEvent(win, "ready");
win.close();
});
Assert.ok(
!Services.prefs.prefHasUserValue("browser.newtabpage.enabled"),
"New tab reverted"
);
AssertEvents(
"Checkbox shown and kept checked",
["content", "show", "3-screens"],
["content", "show", "upgrade-dialog-start-primary-button"],
["content", "button", "upgrade-dialog-start-primary-button"],
["content", "show", "random-1"],
["content", "show", "upgrade-dialog-colorway-home-checkbox"],
["content", "show", "upgrade-dialog-colorway-primary-button"],
["content", "button", "upgrade-dialog-colorway-secondary-button"],
["content", "button", "upgrade-dialog-colorway-home-checkbox"],
["content", "show", "upgrade-dialog-thankyou-primary-button"],
["content", "close", "external"]
);
});
add_task(async function skip_screens() {
await showAndWaitForDialog(async win => {
await BrowserTestUtils.waitForEvent(win, "ready");
win.document.getElementById("secondary").click();
@ -201,112 +220,3 @@ add_task(async function window_warning() {
["content", "close", "external"]
);
});
add_task(async function not_major_upgrade() {
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Not major upgrade for upgrade dialog requirements", [
"trigger",
"reason",
"not-major",
]);
});
add_task(async function remote_disabled() {
mockWin7(false);
await ExperimentAPI.ready();
await ExperimentFakes.remoteDefaultsHelper({
feature: NimbusFeatures.upgradeDialog,
configuration: {
slug: "upgradeDialog_remoteDisabled",
variables: { enabled: false },
targeting: "true",
},
});
// Simulate starting from a previous version.
await SpecialPowers.pushPrefEnv({
set: [["browser.startup.homepage_override.mstone", "88.0"]],
});
Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler).defaultArgs;
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Feature disabled for upgrade dialog requirements", [
"trigger",
"reason",
"disabled",
]);
// Re-enable back
await ExperimentFakes.remoteDefaultsHelper({
feature: NimbusFeatures.upgradeDialog,
configuration: {
slug: "upgradeDialog_remoteEnabled",
variables: { enabled: true },
targeting: "true",
},
});
});
add_task(async function enterprise_disabled() {
const defaultPrefs = Services.prefs.getDefaultBranch("");
const pref = "browser.aboutwelcome.enabled";
const orig = defaultPrefs.getBoolPref(pref, true);
defaultPrefs.setBoolPref(pref, false);
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Welcome disabled like enterprise policy", [
"trigger",
"reason",
"no-welcome",
]);
defaultPrefs.setBoolPref(pref, orig);
});
add_task(async function win7_excluded() {
mockWin7(true);
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Not showing dialog for win7", ["trigger", "reason", "win7"]);
});
add_task(async function show_major_upgrade() {
mockWin7(false);
const promise = waitForDialog(async win => {
await BrowserTestUtils.waitForEvent(win, "ready");
win.close();
});
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
await promise;
AssertEvents(
"Upgrade dialog opened and closed from major upgrade",
["trigger", "reason", "satisfied"],
["content", "show", "3-screens"],
["content", "show", "upgrade-dialog-start-primary-button"],
["content", "close", "external"]
);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
add_task(async function dont_reshow() {
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Shouldn't reshow for upgrade dialog requirements", [
"trigger",
"reason",
"already-shown",
]);
});
registerCleanupFunction(() => {
Cc["@mozilla.org/browser/clh;1"].getService(
Ci.nsIBrowserHandler
).majorUpgrade = false;
Services.prefs.clearUserPref("browser.startup.upgradeDialog.version");
});

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

@ -0,0 +1,122 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { ExperimentFakes } = ChromeUtils.import(
"resource://testing-common/NimbusTestUtils.jsm"
);
const { NimbusFeatures, ExperimentAPI } = ChromeUtils.import(
"resource://nimbus/ExperimentAPI.jsm"
);
add_task(async function not_major_upgrade() {
Services.telemetry.clearEvents();
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Not major upgrade for upgrade dialog requirements", [
"trigger",
"reason",
"not-major",
]);
});
add_task(async function remote_disabled() {
mockWin7(false);
await ExperimentAPI.ready();
await ExperimentFakes.remoteDefaultsHelper({
feature: NimbusFeatures.upgradeDialog,
configuration: {
slug: "upgradeDialog_remoteDisabled",
variables: { enabled: false },
targeting: "true",
},
});
// Simulate starting from a previous version.
await SpecialPowers.pushPrefEnv({
set: [["browser.startup.homepage_override.mstone", "88.0"]],
});
Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler).defaultArgs;
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Feature disabled for upgrade dialog requirements", [
"trigger",
"reason",
"disabled",
]);
// Re-enable back
await ExperimentFakes.remoteDefaultsHelper({
feature: NimbusFeatures.upgradeDialog,
configuration: {
slug: "upgradeDialog_remoteEnabled",
variables: { enabled: true },
targeting: "true",
},
});
});
add_task(async function enterprise_disabled() {
const defaultPrefs = Services.prefs.getDefaultBranch("");
const pref = "browser.aboutwelcome.enabled";
const orig = defaultPrefs.getBoolPref(pref, true);
defaultPrefs.setBoolPref(pref, false);
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Welcome disabled like enterprise policy", [
"trigger",
"reason",
"no-welcome",
]);
defaultPrefs.setBoolPref(pref, orig);
});
add_task(async function win7_excluded() {
mockWin7(true);
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Not showing dialog for win7", ["trigger", "reason", "win7"]);
});
add_task(async function show_major_upgrade() {
mockWin7(false);
const promise = waitForDialog(async win => {
await BrowserTestUtils.waitForEvent(win, "ready");
win.close();
});
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
await promise;
AssertEvents(
"Upgrade dialog opened and closed from major upgrade",
["trigger", "reason", "satisfied"],
["content", "show", "3-screens"],
["content", "show", "upgrade-dialog-start-primary-button"],
["content", "close", "external"]
);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
add_task(async function dont_reshow() {
await BROWSER_GLUE._maybeShowDefaultBrowserPrompt();
AssertEvents("Shouldn't reshow for upgrade dialog requirements", [
"trigger",
"reason",
"already-shown",
]);
});
registerCleanupFunction(() => {
Cc["@mozilla.org/browser/clh;1"].getService(
Ci.nsIBrowserHandler
).majorUpgrade = false;
Services.prefs.clearUserPref("browser.startup.upgradeDialog.version");
});

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

@ -8,6 +8,19 @@ XPCOMUtils.defineLazyModuleGetters(this, {
TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.jsm",
});
// Helpers for testing telemetry events.
// Tests can change the category to filter for different events.
var gTelemetryCategory = "upgrade_dialog";
function AssertEvents(message, ...events) {
info(`Checking telemetry events: ${message}`);
TelemetryTestUtils.assertEvents(
events.map(event => [gTelemetryCategory, ...event]),
{ category: gTelemetryCategory }
);
}
const BROWSER_GLUE = Cc["@mozilla.org/browser/browserglue;1"].getService()
.wrappedJSObject;