tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 593496a2ef5a27e969b7faae43a012b9de19a976
parent 71353cfaee7124e39e4bf3f545a16dc1efed5ebd
Author: Serban Stanca <sstanca@mozilla.com>
Date:   Thu, 23 Oct 2025 13:55:47 +0300

Revert "Bug 1994887 - Get rid of IPProtectionStates.ENROLLING, r=ip-protection-reviewers,fchasen" for casuing mochitests failures.

This reverts commit c953259f177f0e22966fab94048559c894ceda3b.

Diffstat:
Mbrowser/components/ipprotection/IPPAutoStart.sys.mjs | 1+
Dbrowser/components/ipprotection/IPPEnrollHelper.sys.mjs | 134-------------------------------------------------------------------------------
Mbrowser/components/ipprotection/IPPSignInWatcher.sys.mjs | 9+--------
Mbrowser/components/ipprotection/IPProtection.sys.mjs | 2++
Mbrowser/components/ipprotection/IPProtectionHelpers.sys.mjs | 2--
Mbrowser/components/ipprotection/IPProtectionService.sys.mjs | 97++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Mbrowser/components/ipprotection/docs/Components.rst | 7+------
Mbrowser/components/ipprotection/docs/StateMachine.rst | 7++++---
Mbrowser/components/ipprotection/moz.build | 1-
Mbrowser/components/ipprotection/tests/browser/browser_IPProtectionService.js | 4++--
Mbrowser/components/ipprotection/tests/browser/head.js | 13++++++-------
Mbrowser/components/ipprotection/tests/xpcshell/head.js | 8+++-----
Mbrowser/components/ipprotection/tests/xpcshell/test_IPProtectionPanel.js | 9++++-----
Mbrowser/components/ipprotection/tests/xpcshell/test_IPProtectionService.js | 34+++++++++-------------------------
Mbrowser/components/ipprotection/tests/xpcshell/test_IPProtectionStates.js | 21+++++----------------
15 files changed, 124 insertions(+), 225 deletions(-)

diff --git a/browser/components/ipprotection/IPPAutoStart.sys.mjs b/browser/components/ipprotection/IPPAutoStart.sys.mjs @@ -70,6 +70,7 @@ class IPPAutoStart { case lazy.IPProtectionStates.UNINITIALIZED: case lazy.IPProtectionStates.UNAVAILABLE: case lazy.IPProtectionStates.UNAUTHENTICATED: + case lazy.IPProtectionStates.ENROLLING: case lazy.IPProtectionStates.ERROR: this.#shouldStartWhenReady = true; break; diff --git a/browser/components/ipprotection/IPPEnrollHelper.sys.mjs b/browser/components/ipprotection/IPPEnrollHelper.sys.mjs @@ -1,134 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const lazy = {}; - -ChromeUtils.defineESModuleGetters(lazy, { - IPProtectionService: - "resource:///modules/ipprotection/IPProtectionService.sys.mjs", - IPPSignInWatcher: "resource:///modules/ipprotection/IPPSignInWatcher.sys.mjs", -}); - -const LOG_PREF = "browser.ipProtection.log"; - -ChromeUtils.defineLazyGetter(lazy, "logConsole", function () { - return console.createInstance({ - prefix: "IPPEnrollHelper", - maxLogLevel: Services.prefs.getBoolPref(LOG_PREF, false) ? "Debug" : "Warn", - }); -}); - -/** - * - */ -class IPPEnrollHelperSingleton { - #isEnrolled = false; - #enrolling = null; - - constructor() { - this.handleEvent = this.#handleEvent.bind(this); - } - - init() { - lazy.IPPSignInWatcher.addEventListener( - "IPPSignInWatcher:StateChanged", - this.handleEvent - ); - } - - initOnStartupCompleted() { - if (!lazy.IPPSignInWatcher.isSignedIn) { - return; - } - - try { - // This bit must be async because we want to trigger the updateState at - // the end of the rest of the initialization. - lazy.IPProtectionService.guardian - .isLinkedToGuardian(/* only cache: */ true) - .then(isEnrolled => this.#setEnrolled(isEnrolled)); - } catch (_) { - // If we are not enrolled. It's not a big deal. - } - } - - uninit() { - lazy.IPPSignInWatcher.removeEventListener( - "IPPSignInWatcher:StateChanged", - this.handleEvent - ); - } - - #handleEvent(_event) { - if (!lazy.IPPSignInWatcher.isSignedIn) { - this.#setEnrolled(false); - return; - } - - this.maybeEnroll(); - } - - async maybeEnroll() { - if (this.#isEnrolled) { - return Promise.resolve({ isEnrolled: true }); - } - - try { - this.#setEnrolled( - await lazy.IPProtectionService.guardian.isLinkedToGuardian( - /* only cache: */ false - ) - ); - } catch (error) { - return Promise.resolve({ isEnrolled: false, error: error?.message }); - } - - if (this.#isEnrolled) { - return Promise.resolve({ isEnrolled: true }); - } - - if (this.#enrolling) { - return this.#enrolling; - } - - this.#enrolling = lazy.IPProtectionService.guardian - .enroll() - .then(enrollment => { - let isEnrolled = enrollment?.ok; - - lazy.logConsole.debug( - "Guardian:", - isEnrolled ? "Enrolled" : "Enrollment Failed" - ); - - this.#setEnrolled(isEnrolled); - return { isEnrolled, error: enrollment?.error }; - }) - .catch(error => { - return { isEnrolled: false, error: error?.message }; - }) - .finally(() => { - this.#enrolling = null; - }); - - return this.#enrolling; - } - - get isEnrolled() { - return this.#isEnrolled; - } - - #setEnrolled(isEnrolled) { - if (this.#isEnrolled === isEnrolled) { - return; - } - - this.#isEnrolled = isEnrolled; - lazy.IPProtectionService.updateState(); - } -} - -const IPPEnrollHelper = new IPPEnrollHelperSingleton(); - -export { IPPEnrollHelper }; diff --git a/browser/components/ipprotection/IPPSignInWatcher.sys.mjs b/browser/components/ipprotection/IPPSignInWatcher.sys.mjs @@ -14,7 +14,7 @@ ChromeUtils.defineESModuleGetters(lazy, { * This class monitors the Sign-In state and triggers the update of the service * if needed. */ -class IPPSignInWatcherSingleton extends EventTarget { +class IPPSignInWatcherSingleton { #signedIn = false; get isSignedIn() { @@ -45,13 +45,6 @@ class IPPSignInWatcherSingleton extends EventTarget { if (signedIn !== IPPSignInWatcher.isSignedIn) { IPPSignInWatcher.isSignedIn = signedIn; lazy.IPProtectionService.updateState(); - - IPPSignInWatcher.dispatchEvent( - new CustomEvent("IPPSignInWatcher:StateChanged", { - bubbles: true, - composed: true, - }) - ); } }, }; diff --git a/browser/components/ipprotection/IPProtection.sys.mjs b/browser/components/ipprotection/IPProtection.sys.mjs @@ -232,6 +232,8 @@ class IPProtectionWidget { * @param {Event} event - the panel shown. */ #onViewShowing(event) { + lazy.IPProtectionService.maybeEnroll(); + let { ownerGlobal } = event.target; if (this.#panels.has(ownerGlobal)) { let panel = this.#panels.get(ownerGlobal); diff --git a/browser/components/ipprotection/IPProtectionHelpers.sys.mjs b/browser/components/ipprotection/IPProtectionHelpers.sys.mjs @@ -24,7 +24,6 @@ ChromeUtils.defineESModuleGetters(lazy, { }); import { IPPAutoStartHelpers } from "resource:///modules/ipprotection/IPPAutoStart.sys.mjs"; -import { IPPEnrollHelper } from "resource:///modules/ipprotection/IPPEnrollHelper.sys.mjs"; import { IPPNimbusHelper } from "resource:///modules/ipprotection/IPPNimbusHelper.sys.mjs"; import { IPPSignInWatcher } from "resource:///modules/ipprotection/IPPSignInWatcher.sys.mjs"; import { IPPStartupCache } from "resource:///modules/ipprotection/IPPStartupCache.sys.mjs"; @@ -149,7 +148,6 @@ class VPNAddonHelper { const IPPHelpers = [ IPPStartupCache, IPPSignInWatcher, - IPPEnrollHelper, new UIHelper(), new AccountResetHelper(), new VPNAddonHelper(), diff --git a/browser/components/ipprotection/IPProtectionService.sys.mjs b/browser/components/ipprotection/IPProtectionService.sys.mjs @@ -8,7 +8,6 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { GuardianClient: "resource:///modules/ipprotection/GuardianClient.sys.mjs", - IPPEnrollHelper: "resource:///modules/ipprotection/IPPEnrollHelper.sys.mjs", IPPHelpers: "resource:///modules/ipprotection/IPProtectionHelpers.sys.mjs", IPPNimbusHelper: "resource:///modules/ipprotection/IPPNimbusHelper.sys.mjs", IPPProxyManager: "resource:///modules/ipprotection/IPPProxyManager.sys.mjs", @@ -43,6 +42,9 @@ ChromeUtils.defineLazyGetter(lazy, "logConsole", function () { * The user is not eligible (via nimbus) or still not signed in. No UI is available. * @property {string} UNAUTHENTICATED * The user is signed out but eligible (via nimbus). The panel should show the login view. + * @property {string} ENROLLING + * The user is signed in and eligible (via nimbus). The UI should show the main view, + * but not allow activation until enrollment has finished. * @property {string} READY * Ready to be activated. * @property {string} ACTIVE @@ -57,6 +59,7 @@ export const IPProtectionStates = Object.freeze({ UNINITIALIZED: "uninitialized", UNAVAILABLE: "unavailable", UNAUTHENTICATED: "unauthenticated", + ENROLLING: "enrolling", READY: "ready", ACTIVE: "active", ERROR: "error", @@ -76,6 +79,7 @@ class IPProtectionServiceSingleton extends EventTarget { #updating = false; errors = []; + enrolling = null; guardian = null; proxyManager = null; @@ -181,6 +185,7 @@ class IPProtectionServiceSingleton extends EventTarget { this.#entitlement = null; this.errors = []; + this.enrolling = null; this.#helpers.forEach(helper => helper.uninit()); @@ -201,11 +206,7 @@ class IPProtectionServiceSingleton extends EventTarget { */ async start(userAction = true) { // Wait for enrollment to finish. - const enrollData = await lazy.IPPEnrollHelper.maybeEnroll(); - if (!enrollData || !enrollData.isEnrolled) { - this.setErrorState(enrollData.error || ERRORS.GENERIC); - return; - } + await this.enrolling; // Retry getting state if the previous attempt failed. if (this.#state === IPProtectionStates.ERROR) { @@ -279,6 +280,18 @@ class IPProtectionServiceSingleton extends EventTarget { } /** + * Enroll the current account if it meets all the criteria. + * + * @returns {Promise<void>} + */ + async maybeEnroll() { + if (this.#state !== IPProtectionStates.ENROLLING) { + return null; + } + return this.#enroll(); + } + + /** * Reset the statuses that are set based on a FxA account. */ resetAccount() { @@ -292,6 +305,23 @@ class IPProtectionServiceSingleton extends EventTarget { } /** + * Checks if the user has enrolled with FxA to use the proxy. + * + * @param { boolean } onlyCached - if true only the cached clients will be checked. + * @returns {Promise<boolean>} + */ + async #isEnrolled(onlyCached) { + let isEnrolled; + try { + isEnrolled = await this.guardian.isLinkedToGuardian(onlyCached); + } catch (error) { + this.#setErrorState(error?.message); + } + + return isEnrolled; + } + + /** * Clear the current entitlement and requests a state update to dispatch * the current hasUpgraded status. * @@ -310,6 +340,47 @@ class IPProtectionServiceSingleton extends EventTarget { } /** + * Enrolls a users FxA account to use the proxy and updates the state. + * + * @returns {Promise<void>} + */ + async #enroll() { + if (this.#state !== IPProtectionStates.ENROLLING) { + return null; + } + + if (this.enrolling) { + return this.enrolling; + } + + this.enrolling = this.guardian + .enroll() + .then(enrollment => { + let ok = enrollment?.ok; + + lazy.logConsole.debug( + "Guardian:", + ok ? "Enrolled" : "Enrollment Failed" + ); + + if (!ok) { + this.#setErrorState(enrollment?.error || ERRORS.GENERIC); + return null; + } + + return this.#updateState(); + }) + .catch(error => { + this.#setErrorState(error?.message); + }) + .finally(() => { + this.enrolling = null; + }); + + return this.enrolling; + } + + /** * Gets the entitlement information for the user. */ async #getEntitlement() { @@ -389,15 +460,19 @@ class IPProtectionServiceSingleton extends EventTarget { return IPProtectionStates.READY; } - if (!lazy.IPPEnrollHelper.isEnrolled) { + // The following are remote authentication checks and should be avoided + // whenever possible. + + // Check if the current account is enrolled with Guardian. + let enrolled = await this.#isEnrolled( + this.#state !== IPProtectionStates.ENROLLING /*onlyCached*/ + ); + if (!enrolled) { return !eligible ? IPProtectionStates.UNAVAILABLE - : IPProtectionStates.READY; + : IPProtectionStates.ENROLLING; } - // The following are remote authentication checks and should be avoided - // whenever possible. - // Check if the current account can get an entitlement. let entitled = await this.#getEntitlement(); if (!entitled && !eligible) { diff --git a/browser/components/ipprotection/docs/Components.rst b/browser/components/ipprotection/docs/Components.rst @@ -32,10 +32,9 @@ A diagram of all the main components is the following: UIHelper["UI Helper"] AccountResetHelper["Account Reset Helper"] VPNAddonHelper["VPN Add-on Helper"] - IPPNimbusHelper["Nimbus Eligibility Helper"] + IPPNimbusHelper["Nimbus Eligibility Helper"] IPPAutoStart["Auto-Start Helper"] IPPEarlyStartupFilter["Early Startup Filter Helper"] - IPPEnrollHelper["Enrollment Helper"] end %% Proxy stack @@ -137,10 +136,6 @@ IPPNimbusHelper Monitors the Nimbus feature (``NimbusFeatures.ipProtection``) and triggers a state recomputation on updates. -IPPEnrollHelper - Orchestrates the user enrollment flow with Guardian and updates the service - when enrollment status changes. - How to implement new components ------------------------------- diff --git a/browser/components/ipprotection/docs/StateMachine.rst b/browser/components/ipprotection/docs/StateMachine.rst @@ -12,6 +12,7 @@ The service transitions across the following states: - ``UNINITIALIZED``: Service not initialized or feature disabled. - ``UNAVAILABLE``: User not eligible (Nimbus) or signed out with no eligibility; UI hidden. - ``UNAUTHENTICATED``: User signed out but eligible; UI shows login. +- ``ENROLLING``: User signed in and eligible; enrollment in progress. - ``READY``: Ready to activate the proxy. - ``ACTIVE``: Proxy is active. - ``ERROR``: An error occurred (see ``IPProtectionService.errors``). @@ -24,8 +25,8 @@ High‑level transitions - Not signed in → ``UNAVAILABLE`` if not eligible, otherwise ``UNAUTHENTICATED``. - Proxy already active → ``ACTIVE``. - If an entitlement is cached/valid → ``READY``. -- Otherwise, check enrollment with Guardian (via ``IPPErollHelper``): - - Not enrolled → ``UNAVAILABLE`` (not eligible). +- Otherwise, check enrollment with Guardian: + - Not enrolled → ``UNAVAILABLE`` (not eligible) or ``ENROLLING`` (eligible). - Enrolled → fetch entitlement; if successful → ``READY``, else ``UNAVAILABLE`` when not eligible. Events and integration points @@ -34,5 +35,5 @@ Events and integration points - ``IPProtectionService:StateChanged`` is dispatched on state changes with ``detail.state`` and ``detail.prevState``. - Helpers can call ``IPProtectionService.updateState()`` to request a recomputation. -- Public actions: ``start(userAction)``, ``stop(userAction)``, +- Public actions: ``start(userAction)``, ``stop(userAction)``, ``maybeEnroll()``, ``resetAccount()``, and ``startLoginFlow(browser)``. diff --git a/browser/components/ipprotection/moz.build b/browser/components/ipprotection/moz.build @@ -13,7 +13,6 @@ EXTRA_JS_MODULES.ipprotection += [ "GuardianClient.sys.mjs", "IPPAutoStart.sys.mjs", "IPPChannelFilter.sys.mjs", - "IPPEnrollHelper.sys.mjs", "IPPExceptionsManager.sys.mjs", "IPPNetworkErrorObserver.sys.mjs", "IPPNimbusHelper.sys.mjs", diff --git a/browser/components/ipprotection/tests/browser/browser_IPProtectionService.js b/browser/components/ipprotection/tests/browser/browser_IPProtectionService.js @@ -106,7 +106,7 @@ add_task(async function test_IPProtectionService_enroll() { await IPProtectionService.updateState(); Assert.equal( IPProtectionService.state, - IPProtectionStates.READY, + IPProtectionStates.ENROLLING, "User should now be enrolling" ); @@ -519,7 +519,7 @@ add_task(async function test_IPProtectionService_addon() { }, }, }); - await IPProtectionService.refetchEntitlement(); + await IPProtectionService.updateState(); const extension = ExtensionTestUtils.loadExtension({ useAddonManager: "permanent", diff --git a/browser/components/ipprotection/tests/browser/head.js b/browser/components/ipprotection/tests/browser/head.js @@ -17,10 +17,6 @@ const { IPPSignInWatcher } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPPSignInWatcher.sys.mjs" ); -const { IPPEnrollHelper } = ChromeUtils.importESModule( - "resource:///modules/ipprotection/IPPEnrollHelper.sys.mjs" -); - const { HttpServer, HTTP_403 } = ChromeUtils.importESModule( "resource://testing-common/httpd.sys.mjs" ); @@ -243,7 +239,7 @@ let DEFAULT_SERVICE_STATUS = { /* exported DEFAULT_SERVICE_STATUS */ let STUBS = { - isEnrolled: undefined, + isLinkedToGuardian: undefined, enroll: undefined, fetchUserInfo: undefined, fetchProxyPass: undefined, @@ -275,7 +271,10 @@ add_setup(async function setupVPN() { function setupStubs(stubs = STUBS) { stubs.isSignedIn = setupSandbox.stub(IPPSignInWatcher, "isSignedIn"); - stubs.isEnrolled = setupSandbox.stub(IPPEnrollHelper, "isEnrolled"); + stubs.isLinkedToGuardian = setupSandbox.stub( + IPProtectionService.guardian, + "isLinkedToGuardian" + ); stubs.enroll = setupSandbox.stub(IPProtectionService.guardian, "enroll"); stubs.fetchUserInfo = setupSandbox.stub( IPProtectionService.guardian, @@ -303,7 +302,7 @@ function setupService( } if (typeof isEnrolled != "undefined") { - stubs.isEnrolled.get(() => isEnrolled); + stubs.isLinkedToGuardian.resolves(isEnrolled); } if (typeof canEnroll != "undefined") { diff --git a/browser/components/ipprotection/tests/xpcshell/head.js b/browser/components/ipprotection/tests/xpcshell/head.js @@ -15,13 +15,11 @@ const { sinon } = ChromeUtils.importESModule( "resource://testing-common/Sinon.sys.mjs" ); -function waitForEvent(target, eventName, callback = () => true) { +function waitForEvent(target, eventName) { return new Promise(resolve => { let listener = event => { - if (callback()) { - target.removeEventListener(eventName, listener); - resolve(event); - } + target.removeEventListener(eventName, listener); + resolve(event); }; target.addEventListener(eventName, listener); }); diff --git a/browser/components/ipprotection/tests/xpcshell/test_IPProtectionPanel.js b/browser/components/ipprotection/tests/xpcshell/test_IPProtectionPanel.js @@ -12,9 +12,6 @@ const { IPProtectionService, IPProtectionStates } = ChromeUtils.importESModule( const { IPPSignInWatcher } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPPSignInWatcher.sys.mjs" ); -const { IPPEnrollHelper } = ChromeUtils.importESModule( - "resource:///modules/ipprotection/IPPEnrollHelper.sys.mjs" -); /** * A class that mocks the IP Protection panel. @@ -135,7 +132,6 @@ add_task(async function test_updateState() { add_task(async function test_IPProtectionPanel_signedIn() { let sandbox = sinon.createSandbox(); sandbox.stub(IPPSignInWatcher, "isSignedIn").get(() => true); - sandbox.stub(IPPEnrollHelper, "isEnrolled").get(() => true); sandbox .stub(IPProtectionService.guardian, "isLinkedToGuardian") .resolves(true); @@ -157,6 +153,7 @@ add_task(async function test_IPProtectionPanel_signedIn() { let signedInEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.state === IPProtectionStates.READY ); await IPProtectionService.updateState(); @@ -194,6 +191,7 @@ add_task(async function test_IPProtectionPanel_signedOut() { let signedOutEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.state === IPProtectionStates.UNAVAILABLE ); await IPProtectionService.updateState(); @@ -226,7 +224,6 @@ add_task(async function test_IPProtectionPanel_started_stopped() { let sandbox = sinon.createSandbox(); sandbox.stub(IPPSignInWatcher, "isSignedIn").get(() => true); - sandbox.stub(IPPEnrollHelper, "isEnrolled").get(() => true); sandbox .stub(IPProtectionService.guardian, "isLinkedToGuardian") .resolves(true); @@ -253,6 +250,7 @@ add_task(async function test_IPProtectionPanel_started_stopped() { let startedEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.state === IPProtectionStates.ACTIVE ); @@ -275,6 +273,7 @@ add_task(async function test_IPProtectionPanel_started_stopped() { let stoppedEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.state !== IPProtectionStates.ACTIVE ); diff --git a/browser/components/ipprotection/tests/xpcshell/test_IPProtectionService.js b/browser/components/ipprotection/tests/xpcshell/test_IPProtectionService.js @@ -15,9 +15,6 @@ const { IPProtectionService, IPProtectionStates } = ChromeUtils.importESModule( const { IPPSignInWatcher } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPPSignInWatcher.sys.mjs" ); -const { IPPEnrollHelper } = ChromeUtils.importESModule( - "resource:///modules/ipprotection/IPPEnrollHelper.sys.mjs" -); do_get_profile(); @@ -69,6 +66,7 @@ add_setup(async function () { registerCleanupFunction(async () => { await IPProtectionService.init(); + await IPProtectionService.init(); }); }); @@ -79,13 +77,7 @@ add_task(async function test_IPProtectionService_start() { let sandbox = sinon.createSandbox(); setupStubs(sandbox); - IPProtectionService.init(); - - await waitForEvent( - IPProtectionService, - "IPProtectionService:StateChanged", - () => IPProtectionService.state === IPProtectionStates.READY - ); + await IPProtectionService.init(); Assert.ok( !IPProtectionService.activatedAt, @@ -95,6 +87,7 @@ add_task(async function test_IPProtectionService_start() { let startedEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.state === IPProtectionStates.ACTIVE ); @@ -127,19 +120,14 @@ add_task(async function test_IPProtectionService_stop() { let sandbox = sinon.createSandbox(); setupStubs(sandbox); - IPProtectionService.init(); - - await waitForEvent( - IPProtectionService, - "IPProtectionService:StateChanged", - () => IPProtectionService.state === IPProtectionStates.READY - ); + await IPProtectionService.init(); await IPProtectionService.start(); let stoppedEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.state !== IPProtectionStates.ACTIVE ); IPProtectionService.stop(); @@ -168,7 +156,6 @@ add_task(async function test_IPProtectionService_stop() { */ add_task(async function test_IPProtectionService_updateState_signedIn() { let sandbox = sinon.createSandbox(); - sandbox.stub(IPPEnrollHelper, "isEnrolled").get(() => true); await IPProtectionService.init(); @@ -177,6 +164,7 @@ add_task(async function test_IPProtectionService_updateState_signedIn() { let signedInEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.state === IPProtectionStates.READY ); @@ -204,6 +192,7 @@ add_task(async function test_IPProtectionService_updateState_signedOut() { let signedOutEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.state === IPProtectionStates.UNAVAILABLE ); @@ -229,13 +218,7 @@ add_task( const sandbox = sinon.createSandbox(); setupStubs(sandbox); - IPProtectionService.init(); - - await waitForEvent( - IPProtectionService, - "IPProtectionService:StateChanged", - () => IPProtectionService.state === IPProtectionStates.READY - ); + await IPProtectionService.init(); IPProtectionService.guardian.fetchUserInfo.resolves({ status: 200, @@ -250,6 +233,7 @@ add_task( let hasUpgradedEventPromise = waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", + false, () => IPProtectionService.hasUpgraded ); diff --git a/browser/components/ipprotection/tests/xpcshell/test_IPProtectionStates.js b/browser/components/ipprotection/tests/xpcshell/test_IPProtectionStates.js @@ -12,9 +12,6 @@ const { IPPNimbusHelper } = ChromeUtils.importESModule( const { IPPSignInWatcher } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPPSignInWatcher.sys.mjs" ); -const { IPPEnrollHelper } = ChromeUtils.importESModule( - "resource:///modules/ipprotection/IPPEnrollHelper.sys.mjs" -); do_get_profile(); @@ -95,7 +92,6 @@ add_task(async function test_IPProtectionStates_unauthenticated() { sandbox .stub(IPProtectionService.guardian, "isLinkedToGuardian") .resolves(false); - sandbox.stub(IPProtectionService.guardian, "enroll").resolves({ ok: true }); await IPProtectionService.init(); @@ -111,7 +107,7 @@ add_task(async function test_IPProtectionStates_unauthenticated() { Assert.equal( IPProtectionService.state, - IPProtectionStates.READY, + IPProtectionStates.ENROLLING, "IP Protection service should no longer be unauthenticated" ); @@ -150,14 +146,13 @@ add_task(async function test_IPProtectionStates_enrolling() { Assert.equal( IPProtectionService.state, - IPProtectionStates.READY, - "IP Protection service should be ready" + IPProtectionStates.ENROLLING, + "IP Protection service should be enrolling" ); IPProtectionService.guardian.isLinkedToGuardian.resolves(true); - const enrollData = await IPPEnrollHelper.maybeEnroll(); - Assert.ok(enrollData.isEnrolled, "Fully enrolled"); + await IPProtectionService.maybeEnroll(); Assert.equal( IPProtectionService.state, @@ -229,13 +224,7 @@ add_task(async function test_IPProtectionStates_active() { }, }); - IPProtectionService.init(); - - await waitForEvent( - IPProtectionService, - "IPProtectionService:StateChanged", - () => IPProtectionService.state === IPProtectionStates.READY - ); + await IPProtectionService.init(); Assert.equal( IPProtectionService.state,