|
| 1 | +/* Any copyright is dedicated to the Public Domain. |
| 2 | + * http://creativecommons.org/publicdomain/zero/1.0/ */ |
| 3 | + |
| 4 | +"use strict"; |
| 5 | + |
| 6 | +ChromeUtils.defineESModuleGetters(this, { |
| 7 | + WindowsLaunchOnLogin: "resource://gre/modules/WindowsLaunchOnLogin.sys.mjs", |
| 8 | +}); |
| 9 | + |
| 10 | +const { MockRegistry } = ChromeUtils.importESModule( |
| 11 | + "resource://testing-common/MockRegistry.sys.mjs" |
| 12 | +); |
| 13 | + |
| 14 | +const ENABLED_PREF = "browser.startup.windowsLaunchOnLogin.enabled"; |
| 15 | +const isMSIX = Services.sysinfo.getProperty("hasWinPackageId"); |
| 16 | + |
| 17 | +let registry = null; |
| 18 | + |
| 19 | +add_setup(async function () { |
| 20 | + registry = new MockRegistry(); |
| 21 | + registry.setValue( |
| 22 | + Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
| 23 | + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", |
| 24 | + "", |
| 25 | + "" |
| 26 | + ); |
| 27 | + registry.setValue( |
| 28 | + Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
| 29 | + "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run", |
| 30 | + "", |
| 31 | + "" |
| 32 | + ); |
| 33 | + registerCleanupFunction(async () => { |
| 34 | + registry.shutdown(); |
| 35 | + await setupPolicyEngineWithJson(""); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
| 39 | +async function hasRegistryKey() { |
| 40 | + let exists = false; |
| 41 | + await WindowsLaunchOnLogin.withLaunchOnLoginRegistryKey(wrk => { |
| 42 | + exists = wrk.hasValue(WindowsLaunchOnLogin.getLaunchOnLoginRegistryName()); |
| 43 | + }); |
| 44 | + return exists; |
| 45 | +} |
| 46 | + |
| 47 | +add_task(async function test_disable_launch_on_login() { |
| 48 | + // Simulate the user having previously enabled launch on login. |
| 49 | + if (!isMSIX) { |
| 50 | + await WindowsLaunchOnLogin.createLaunchOnLogin(); |
| 51 | + ok(await hasRegistryKey(), "Registry key exists before the policy applies"); |
| 52 | + } |
| 53 | + |
| 54 | + await setupPolicyEngineWithJson({ |
| 55 | + policies: { |
| 56 | + DisableLaunchOnLogin: true, |
| 57 | + }, |
| 58 | + }); |
| 59 | + |
| 60 | + is( |
| 61 | + Services.prefs.getBoolPref(ENABLED_PREF), |
| 62 | + false, |
| 63 | + "Launch on login enabled pref is forced to false" |
| 64 | + ); |
| 65 | + ok(Services.prefs.prefIsLocked(ENABLED_PREF), "Enabled pref is locked"); |
| 66 | + |
| 67 | + if (!isMSIX) { |
| 68 | + await TestUtils.waitForCondition( |
| 69 | + async () => !(await hasRegistryKey()), |
| 70 | + "Waiting for the launch on login registry key to be removed" |
| 71 | + ); |
| 72 | + |
| 73 | + await WindowsLaunchOnLogin.createLaunchOnLogin(); |
| 74 | + ok( |
| 75 | + !(await hasRegistryKey()), |
| 76 | + "createLaunchOnLogin is blocked while the policy is active" |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + await BrowserTestUtils.withNewTab("about:preferences", async browser => { |
| 81 | + let doc = browser.contentDocument; |
| 82 | + await TestUtils.waitForCondition( |
| 83 | + () => doc.getElementById("windowsLaunchOnLogin"), |
| 84 | + "windowsLaunchOnLogin checkbox rendered" |
| 85 | + ); |
| 86 | + ok( |
| 87 | + doc.getElementById("windowsLaunchOnLogin").parentElement.hidden, |
| 88 | + "Checkbox is hidden by policy" |
| 89 | + ); |
| 90 | + }); |
| 91 | +}); |
| 92 | + |
| 93 | +add_task(async function test_policy_false_is_noop() { |
| 94 | + await setupPolicyEngineWithJson({ |
| 95 | + policies: { |
| 96 | + DisableLaunchOnLogin: false, |
| 97 | + }, |
| 98 | + }); |
| 99 | + |
| 100 | + ok( |
| 101 | + !Services.prefs.prefIsLocked(ENABLED_PREF), |
| 102 | + "Enabled pref is not locked when the policy is false" |
| 103 | + ); |
| 104 | +}); |
0 commit comments