Bug 1905379 - Clean up set default guidance notification check and update tests r=nrishel,negin

- Remove redundant check for `regRename` pref when deciding whether to show set default guidance notification
- Update guidance notification test helper to set `setDefaultBrowserUserChoice` to the same value as `...regRename` to make tests that include one-click being enabled more accurate.

These updates should not change the user experience.

Differential Revision: https://phabricator.services.mozilla.com/D215218
This commit is contained in:
Meg
2024-07-03 14:41:46 +00:00
parent b896d5abb7
commit 8f07351683
2 changed files with 29 additions and 36 deletions

View File

@@ -327,10 +327,6 @@ let ShellServiceInternal = {
lazy.NimbusFeatures.shellService.getVariable(
"setDefaultGuidanceNotifications"
) &&
// Do not show guidance if one-click set to default is enabled
!lazy.NimbusFeatures.shellService.getVariable(
"setDefaultBrowserUserChoiceRegRename"
) &&
// Disable showing toast notification from Firefox Background Tasks.
!lazy.BackgroundTasks?.isBackgroundTaskMode
) {

View File

@@ -29,11 +29,10 @@ const shellStub = sinon
.stub(ShellService, "shellService")
.value({ setDefaultBrowser: setDefaultStub });
const sendTriggerStub = sinon.stub(ASRouter, "sendTriggerMessage");
registerCleanupFunction(() => {
defaultAgentStub.restore();
_userChoiceImpossibleTelemetryResultStub.restore();
userChoiceStub.restore();
shellStub.restore();
sinon.restore();
ExperimentAPI._store._deleteForTests("shellService");
});
@@ -149,18 +148,13 @@ add_task(async function ensure_fallback() {
});
async function setUpNotificationTests(guidanceEnabled, oneClick) {
const sandbox = sinon.createSandbox();
const sendTriggerStub = sandbox.stub(ASRouter, "sendTriggerMessage");
const maybeShowSpy = sandbox.spy(
ShellService,
"_maybeShowSetDefaultGuidanceNotification"
);
const doCleanup = await ExperimentFakes.enrollWithFeatureConfig(
sinon.reset();
const experimentCleanup = await ExperimentFakes.enrollWithFeatureConfig(
{
featureId: NimbusFeatures.shellService.featureId,
value: {
setDefaultBrowserUserChoice: false,
setDefaultGuidanceNotifications: guidanceEnabled,
setDefaultBrowserUserChoice: oneClick,
setDefaultBrowserUserChoiceRegRename: oneClick,
enabled: true,
},
@@ -168,77 +162,80 @@ async function setUpNotificationTests(guidanceEnabled, oneClick) {
{ isRollout: true }
);
const doCleanup = async () => {
await experimentCleanup();
sinon.reset();
};
await ShellService.setDefaultBrowser();
// We don't await the return of _maybeShowSetDefaultGuidanceNotification when setting the default browser, so ensure it's been called before proceeding.
await TestUtils.waitForCondition(() => maybeShowSpy.callCount);
return { doCleanup, sandbox, sendTriggerStub };
return doCleanup;
}
add_task(
async function show_notification_when_set_to_default_guidance_enabled_and_one_click_disabled() {
if (AppConstants.isPlatformAndVersionAtLeast("win", 10)) {
info("Nothing to test on non-Windows");
if (!AppConstants.isPlatformAndVersionAtLeast("win", 10)) {
info("Nothing to test on non-Windows or older Windows versions");
return;
}
let { doCleanup, sandbox, sendTriggerStub } = await setUpNotificationTests(
const doCleanup = await setUpNotificationTests(
true, // guidance enabled
false // one-click disabled
);
Assert.ok(setDefaultStub.called, "Fallback method used to set default");
Assert.equal(
sendTriggerStub.firstCall.args[0].id,
"deeplinkedToWindowsSettingsUI",
`Set to default guidance message trigger was sent.`
`Set to default guidance message trigger was sent`
);
sandbox.restore();
await doCleanup();
}
);
add_task(
async function do_not_show_notification_when_set_to_default_guidance_disabled_and_one_click_enabled() {
if (AppConstants.isPlatformAndVersionAtLeast("win", 10)) {
info("Nothing to test on non-Windows");
if (!AppConstants.isPlatformAndVersionAtLeast("win", 10)) {
info("Nothing to test on non-Windows or older Windows versions");
return;
}
let { doCleanup, sandbox, sendTriggerStub } = await setUpNotificationTests(
const doCleanup = await setUpNotificationTests(
false, // guidance disabled
true // one-click enabled
);
Assert.ok(setDefaultStub.notCalled, "Fallback method not called");
Assert.equal(
sendTriggerStub.callCount,
0,
`Set to default guidance message trigger was not sent.`
`Set to default guidance message trigger was not sent`
);
sandbox.restore();
await doCleanup();
}
);
add_task(
async function do_not_show_notification_when_set_to_default_guidance_enabled_and_one_click_enabled() {
if (AppConstants.isPlatformAndVersionAtLeast("win", 10)) {
info("Nothing to test on non-Windows");
if (!AppConstants.isPlatformAndVersionAtLeast("win", 10)) {
info("Nothing to test on non-Windows or older Windows versions");
return;
}
let { doCleanup, sandbox, sendTriggerStub } = await setUpNotificationTests(
const doCleanup = await setUpNotificationTests(
true, // guidance enabled
true // one-click enabled
);
Assert.ok(setDefaultStub.notCalled, "Fallback method not called");
Assert.equal(
sendTriggerStub.callCount,
0,
`Set to default guidance message trigger was not sent.`
`Set to default guidance message trigger was not sent`
);
sandbox.restore();
await doCleanup();
}
);