Skip to content

Commit 4a2e7ad

Browse files
iain-mozillaHarshitSohaney
authored andcommitted
Bug 2053447: Part 2 - Port the existing LaunchOnLogin code.r=hsohaney
Port the WindowsDefaultLaunchOnLogin to use the new generic LaunchOnLogin interface Differential Revision: https://phabricator.services.mozilla.com/D313483
1 parent 2f90071 commit 4a2e7ad

8 files changed

Lines changed: 64 additions & 79 deletions

File tree

‎browser/app/profile/firefox.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,14 @@ pref("browser.startup.couldRestoreSession.count", 0);
351351
// users as it is not implemented anywhere else.
352352
#if defined(XP_WIN)
353353
pref("browser.startup.preXulSkeletonUI", true);
354+
#endif
355+
356+
// These are called browser.startup.windowsLaunchOnLogin.* because they originated
357+
// on Windows, but they now operate on macOS as well.
358+
// They can't be changed until there are no experiments running that are using the
359+
// old name - https://bugzilla.mozilla.org/show_bug.cgi?id=2059749
354360

355-
// Whether the checkbox to enable Windows launch on login is shown
361+
// Whether the checkbox to enable Launch on login is shown
356362
pref("browser.startup.windowsLaunchOnLogin.enabled", true);
357363
// Whether to show the launch on login infobar notification
358364
pref("browser.startup.windowsLaunchOnLogin.disableLaunchOnLoginPrompt", false);
@@ -363,7 +369,6 @@ pref("browser.startup.windowsLaunchOnLogin.disableLaunchOnLoginPrompt", false);
363369
// direction.
364370
pref("browser.startup.windowsLaunchOnLogin.defaultEnabled", false);
365371
pref("browser.startup.windowsLaunchOnLogin.alreadyApplied", false);
366-
#endif
367372

368373
// Show an upgrade dialog on major upgrades.
369374
pref("browser.startup.upgradeDialog.enabled", false);

‎browser/components/BrowserComponents.manifest‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ category browser-idle-startup resource:///modules/UpdatePolicyEnforcer.sys.mjs U
186186
#endif
187187
#ifdef XP_WIN
188188
category browser-idle-startup resource:///modules/WindowsJumpLists.sys.mjs WinTaskbarJumpList.startup
189-
category browser-idle-startup resource:///modules/DefaultWindowsLaunchOnLogin.sys.mjs DefaultWindowsLaunchOnLogin.maybeEnableOnFirstRun
190189
#endif
191190
#if defined(XP_WIN) || defined(XP_MACOSX)
191+
category browser-idle-startup resource:///modules/DefaultLaunchOnLogin.sys.mjs DefaultLaunchOnLogin.maybeEnableOnFirstRun
192192
category browser-idle-startup moz-src:///browser/components/shell/StartupOSIntegration.sys.mjs StartupOSIntegration.onStartupIdle
193193
#endif
194194

browser/components/defaultwindowslaunchonlogin/DefaultWindowsLaunchOnLogin.sys.mjs renamed to browser/components/defaultlaunchonlogin/DefaultLaunchOnLogin.sys.mjs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@
44

55
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
66

7-
export const DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_NIMBUS_FEATURE_ID =
7+
// These IDs and preferences contain Windows in their name as legacy
8+
// and changing them to be OS agnostic would break existing installs.
9+
export const DEFAULT_LAUNCH_ON_LOGIN_NIMBUS_FEATURE_ID =
810
"defaultWindowsLaunchOnLogin";
911

10-
export const DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_PREF =
12+
export const DEFAULT_LAUNCH_ON_LOGIN_PREF =
1113
"browser.startup.windowsLaunchOnLogin.defaultEnabled";
12-
export const DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_ALREADY_APPLIED_PREF =
14+
export const DEFAULT_LAUNCH_ON_LOGIN_ALREADY_APPLIED_PREF =
1315
"browser.startup.windowsLaunchOnLogin.alreadyApplied";
1416

1517
const lazy = XPCOMUtils.declareLazy({
1618
AppConstants: "resource://gre/modules/AppConstants.sys.mjs",
1719
ExperimentAPI: "resource://nimbus/ExperimentAPI.sys.mjs",
18-
WindowsLaunchOnLogin: "resource://gre/modules/WindowsLaunchOnLogin.sys.mjs",
20+
LaunchOnLogin: "resource://gre/modules/LaunchOnLogin.sys.mjs",
1921
profileService: {
2022
service: "@mozilla.org/toolkit/profile-service;1",
2123
iid: Ci.nsIToolkitProfileService,
2224
},
2325
});
2426

25-
export var DefaultWindowsLaunchOnLogin = {
27+
export var DefaultLaunchOnLogin = {
2628
/**
2729
* `browser-idle-startup` category entry point.
2830
*
@@ -44,7 +46,7 @@ export var DefaultWindowsLaunchOnLogin = {
4446
let isFirstRun = lazy.profileService.isFirstRun;
4547
let isOfficialBuild = lazy.AppConstants.MOZILLA_OFFICIAL;
4648
let alreadyApplied = Services.prefs.getBoolPref(
47-
DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_ALREADY_APPLIED_PREF,
49+
DEFAULT_LAUNCH_ON_LOGIN_ALREADY_APPLIED_PREF,
4850
false
4951
);
5052

@@ -55,6 +57,7 @@ export var DefaultWindowsLaunchOnLogin = {
5557
) {
5658
isFirstRun = true;
5759
isOfficialBuild = true;
60+
alreadyApplied = false;
5861
}
5962

6063
await this.enableOnFirstRunIfNeeded(
@@ -79,7 +82,7 @@ export var DefaultWindowsLaunchOnLogin = {
7982
*/
8083
async enableOnFirstRunIfNeeded(isFirstRun, isOfficialBuild, alreadyApplied) {
8184
if (
82-
lazy.AppConstants.platform !== "win" ||
85+
!lazy.LaunchOnLogin.isSupported() ||
8386
!isOfficialBuild ||
8487
!isFirstRun ||
8588
alreadyApplied
@@ -91,23 +94,21 @@ export var DefaultWindowsLaunchOnLogin = {
9194
// applied its value before we read the pref below.
9295
await this.waitForNimbusReady();
9396

94-
if (
95-
!Services.prefs.getBoolPref(DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_PREF, false)
96-
) {
97+
if (!Services.prefs.getBoolPref(DEFAULT_LAUNCH_ON_LOGIN_PREF, false)) {
9798
return;
9899
}
99100

100101
// Mark the launch on login as applied so we don't do it again
101102
Services.prefs.setBoolPref(
102-
DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_ALREADY_APPLIED_PREF,
103+
DEFAULT_LAUNCH_ON_LOGIN_ALREADY_APPLIED_PREF,
103104
true
104105
);
105106

106-
if (!(await lazy.WindowsLaunchOnLogin.getLaunchOnLoginApproved())) {
107+
if (!(await lazy.LaunchOnLogin.isAllowed())) {
107108
return;
108109
}
109110

110-
await lazy.WindowsLaunchOnLogin.createLaunchOnLogin();
111+
await lazy.LaunchOnLogin.enable();
111112
},
112113

113114
/**

browser/components/defaultwindowslaunchonlogin/moz.build renamed to browser/components/defaultlaunchonlogin/moz.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ with Files("**"):
66
BUG_COMPONENT = ("Firefox", "Shell Integration")
77

88
EXTRA_JS_MODULES += [
9-
"DefaultWindowsLaunchOnLogin.sys.mjs",
9+
"DefaultLaunchOnLogin.sys.mjs",
1010
]
1111

1212
XPCSHELL_TESTS_MANIFESTS += ["tests/xpcshell.toml"]

browser/components/defaultwindowslaunchonlogin/tests/test_DefaultWindowsLaunchOnLogin.js renamed to browser/components/defaultlaunchonlogin/tests/test_DefaultLaunchOnLogin.js

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,24 @@ const { AppConstants } = ChromeUtils.importESModule(
1111
"resource://gre/modules/AppConstants.sys.mjs"
1212
);
1313
const {
14-
DefaultWindowsLaunchOnLogin,
15-
DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_NIMBUS_FEATURE_ID,
16-
DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_PREF,
14+
DefaultLaunchOnLogin,
15+
DEFAULT_LAUNCH_ON_LOGIN_NIMBUS_FEATURE_ID,
16+
DEFAULT_LAUNCH_ON_LOGIN_PREF,
1717
} = ChromeUtils.importESModule(
18-
"resource:///modules/DefaultWindowsLaunchOnLogin.sys.mjs"
18+
"resource:///modules/DefaultLaunchOnLogin.sys.mjs"
1919
);
20-
const { WindowsLaunchOnLogin } = ChromeUtils.importESModule(
21-
"resource://gre/modules/WindowsLaunchOnLogin.sys.mjs"
20+
const { LaunchOnLogin } = ChromeUtils.importESModule(
21+
"resource://gre/modules/LaunchOnLogin.sys.mjs"
2222
);
2323
const { NimbusTestUtils } = ChromeUtils.importESModule(
2424
"resource://testing-common/NimbusTestUtils.sys.mjs"
2525
);
2626
const { updateAppInfo } = ChromeUtils.importESModule(
2727
"resource://testing-common/AppInfo.sys.mjs"
2828
);
29-
const { MockRegistry } = ChromeUtils.importESModule(
30-
"resource://testing-common/MockRegistry.sys.mjs"
31-
);
3229

3330
const CATEGORY_NAME = "browser-idle-startup";
34-
const MODULE_URI = "resource:///modules/DefaultWindowsLaunchOnLogin.sys.mjs";
31+
const MODULE_URI = "resource:///modules/DefaultLaunchOnLogin.sys.mjs";
3532

3633
NimbusTestUtils.init(this);
3734

@@ -40,22 +37,6 @@ add_setup(async () => {
4037
// FOG needs a profile
4138
do_get_profile();
4239

43-
registry = new MockRegistry();
44-
45-
// It's expected that these keys exist
46-
registry.setValue(
47-
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
48-
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
49-
"",
50-
""
51-
);
52-
registry.setValue(
53-
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
54-
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run",
55-
"",
56-
""
57-
);
58-
5940
Services.fog.initializeFOG();
6041
Services.fog.testResetFOG();
6142
updateAppInfo();
@@ -64,12 +45,11 @@ add_setup(async () => {
6445

6546
registerCleanupFunction(() => {
6647
nimbusTestCleanup();
67-
registry.shutdown();
6848
});
6949
});
7050

7151
// Runs enableOnFirstRunIfNeeded with the Nimbus wait stubbed out and the
72-
// WindowsLaunchOnLogin side effects stubbed. Sets the defaultEnabled pref to
52+
// LaunchOnLogin side effects stubbed. Sets the defaultEnabled pref to
7353
// prefValue -- in production Nimbus writes that pref via setPref, so driving the
7454
// pref directly exercises the module's decision logic; the Nimbus -> pref
7555
// linkage is covered separately by test_nimbus_enrollment_sets_pref.
@@ -81,62 +61,60 @@ async function runWith(
8161
prefValue
8262
) {
8363
let sandbox = sinon.createSandbox();
84-
sandbox.stub(DefaultWindowsLaunchOnLogin, "waitForNimbusReady").resolves();
64+
sandbox.stub(DefaultLaunchOnLogin, "waitForNimbusReady").resolves();
8565
let approvedStub = sandbox
86-
.stub(WindowsLaunchOnLogin, "getLaunchOnLoginApproved")
66+
.stub(LaunchOnLogin, "isAllowed")
8767
.resolves(approved);
88-
let createStub = sandbox
89-
.stub(WindowsLaunchOnLogin, "createLaunchOnLogin")
90-
.resolves();
68+
let createStub = sandbox.stub(LaunchOnLogin, "enable").resolves();
9169

92-
Services.prefs.setBoolPref(DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_PREF, prefValue);
70+
Services.prefs.setBoolPref(DEFAULT_LAUNCH_ON_LOGIN_PREF, prefValue);
9371

9472
try {
95-
await DefaultWindowsLaunchOnLogin.enableOnFirstRunIfNeeded(
73+
await DefaultLaunchOnLogin.enableOnFirstRunIfNeeded(
9674
isFirstRun,
9775
isOfficialBuild,
9876
alreadyApplied
9977
);
10078
return { approvedStub, createStub };
10179
} finally {
10280
sandbox.restore();
103-
Services.prefs.clearUserPref(DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_PREF);
81+
Services.prefs.clearUserPref(DEFAULT_LAUNCH_ON_LOGIN_PREF);
10482
}
10583
}
10684

10785
add_task(async function test_is_registered_in_idle_startup() {
10886
const entry = Services.catMan.getCategoryEntry(CATEGORY_NAME, MODULE_URI);
10987
Assert.equal(
11088
entry,
111-
"DefaultWindowsLaunchOnLogin.maybeEnableOnFirstRun",
89+
"DefaultLaunchOnLogin.maybeEnableOnFirstRun",
11290
"Entry should point to `maybeEnableOnFirstRun` in `browser-idle-startup`"
11391
);
11492
});
11593

11694
add_task(
11795
{
11896
skip_if: () =>
119-
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "win",
97+
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "linux",
12098
},
12199
async function test_disabled_when_pref_off() {
122100
let { createStub } = await runWith(true, true, true, false, false);
123101
Assert.ok(
124102
!createStub.called,
125-
"createLaunchOnLogin should not be called when the pref is off"
103+
"LaunchOnLogin.enable should not be called when the pref is off"
126104
);
127105
}
128106
);
129107

130108
add_task(
131109
{
132110
skip_if: () =>
133-
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "win",
111+
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "linux",
134112
},
135113
async function test_enabled_when_pref_on() {
136114
let { createStub } = await runWith(true, true, true, false, true);
137115
Assert.ok(
138116
createStub.calledOnce,
139-
"createLaunchOnLogin should be called when the pref is on"
117+
"LaunchOnLogin.enable should be called when the pref is on"
140118
);
141119
}
142120
);
@@ -146,31 +124,31 @@ add_task(
146124
add_task(
147125
{
148126
skip_if: () =>
149-
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "win",
127+
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "linux",
150128
},
151129
async function test_nimbus_enrollment_sets_pref() {
152130
let cleanup = await NimbusTestUtils.enrollWithFeatureConfig(
153131
{
154-
featureId: DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_NIMBUS_FEATURE_ID,
132+
featureId: DEFAULT_LAUNCH_ON_LOGIN_NIMBUS_FEATURE_ID,
155133
value: { enabled: true },
156134
},
157135
{ isRollout: true }
158136
);
159137
Assert.ok(
160-
Services.prefs.getBoolPref(DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_PREF, false),
138+
Services.prefs.getBoolPref(DEFAULT_LAUNCH_ON_LOGIN_PREF, false),
161139
"enrolling with enabled:true sets the defaultEnabled pref to true"
162140
);
163141
await cleanup();
164142

165143
cleanup = await NimbusTestUtils.enrollWithFeatureConfig(
166144
{
167-
featureId: DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_NIMBUS_FEATURE_ID,
145+
featureId: DEFAULT_LAUNCH_ON_LOGIN_NIMBUS_FEATURE_ID,
168146
value: { enabled: false },
169147
},
170148
{ isRollout: true }
171149
);
172150
Assert.ok(
173-
!Services.prefs.getBoolPref(DEFAULT_WINDOWS_LAUNCH_ON_LOGIN_PREF, true),
151+
!Services.prefs.getBoolPref(DEFAULT_LAUNCH_ON_LOGIN_PREF, true),
174152
"enrolling with enabled:false sets the defaultEnabled pref to false"
175153
);
176154
await cleanup();
@@ -181,22 +159,22 @@ add_task(async function test_skips_when_not_first_run() {
181159
let { createStub } = await runWith(false, true, true, false, true);
182160
Assert.ok(
183161
!createStub.called,
184-
"createLaunchOnLogin should not be called when isFirstRun is false"
162+
"LaunchOnLogin.enable should not be called when isFirstRun is false"
185163
);
186164
});
187165

188166
add_task(async function test_skips_on_unofficial_build() {
189167
let { createStub } = await runWith(true, false, true, false, true);
190168
Assert.ok(
191169
!createStub.called,
192-
"createLaunchOnLogin should not be called on developer builds"
170+
"LaunchOnLogin.enable should not be called on developer builds"
193171
);
194172
});
195173

196174
add_task(
197175
{
198176
skip_if: () =>
199-
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "win",
177+
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "linux",
200178
},
201179
async function test_skips_when_windows_policy_denies() {
202180
let { createStub, approvedStub } = await runWith(
@@ -212,15 +190,15 @@ add_task(
212190
);
213191
Assert.ok(
214192
!createStub.called,
215-
"createLaunchOnLogin should not be called when Windows policy denies"
193+
"LaunchOnLogin should not be called when Windows policy denies"
216194
);
217195
}
218196
);
219197

220198
add_task(
221199
{
222200
skip_if: () =>
223-
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "win",
201+
!AppConstants.MOZ_NORMANDY || AppConstants.platform !== "linux",
224202
},
225203
async function test_skips_when_already_applied() {
226204
let { createStub, approvedStub } = await runWith(
@@ -237,7 +215,7 @@ add_task(
237215

238216
Assert.ok(
239217
!createStub.called,
240-
"createLaunchOnLogin should not be called when already applied is true"
218+
"LaunchOnLogin.enable should not be called when already applied is true"
241219
);
242220
}
243221
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[DEFAULT]
2+
skip-if = [
3+
"os == 'linux' && os_version == '22.04' && arch == 'x86_64' && display == 'wayland'",
4+
"os == 'linux' && os_version == '24.04' && arch == 'x86_64' && display == 'x11'",
5+
]
6+
7+
firefox-appdir = "browser"
8+
9+
["test_DefaultLaunchOnLogin.js"]

‎browser/components/defaultwindowslaunchonlogin/tests/xpcshell.toml‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎browser/components/moz.build‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ if CONFIG["MOZ_SELECTABLE_PROFILES"]:
8888
DIRS += ["profiles"]
8989

9090
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
91-
DIRS += ["touchbar"]
91+
DIRS += ["defaultlaunchonlogin", "touchbar"]
9292
elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
9393
DIRS += [
94-
"defaultwindowslaunchonlogin",
94+
"defaultlaunchonlogin",
9595
"installerprefs",
9696
]
9797

0 commit comments

Comments
 (0)