commit 7217cfb61c46e0f306d35d4219a08d677b7fb761
parent 85ebe91247342b638c5c655eb594e0d5589300c2
Author: kpatenio <kpatenio@mozilla.com>
Date: Wed, 5 Nov 2025 05:19:56 +0000
Bug 1998059 — use IPPEnrollAndEntitleManager to determine if variant is Alpha r=ip-protection-reviewers,fchasen
Differential Revision: https://phabricator.services.mozilla.com/D271164
Diffstat:
3 files changed, 64 insertions(+), 16 deletions(-)
diff --git a/browser/components/ipprotection/IPPEnrollAndEntitleManager.sys.mjs b/browser/components/ipprotection/IPPEnrollAndEntitleManager.sys.mjs
@@ -224,6 +224,18 @@ class IPPEnrollAndEntitleManagerSingleton extends EventTarget {
return !!this.#entitlement;
}
+ /**
+ * Checks if we're running the Alpha variant based on
+ * available features
+ */
+ get isAlpha() {
+ return (
+ !this.#entitlement?.autostart &&
+ !this.#entitlement?.website_inclusion &&
+ !this.#entitlement?.location_controls
+ );
+ }
+
async refetchEntitlement() {
this.#setEntitlement(null);
await this.maybeEnrollAndEntitle();
diff --git a/browser/components/ipprotection/IPProtectionPanel.sys.mjs b/browser/components/ipprotection/IPProtectionPanel.sys.mjs
@@ -74,8 +74,8 @@ export class IPProtectionPanel {
* The location country code
* @property {"generic" | ""} error
* The error type as a string if an error occurred, or empty string if there are no errors.
- * @property {"alpha"} variant
- * The feature variant type as a string.
+ * @property {boolean} isAlpha
+ * True if we're running the Alpha variant, else false.
* @property {boolean} hasUpgraded
* True if a Mozilla VPN subscription is linked to the user's Mozilla account.
*/
@@ -106,10 +106,8 @@ export class IPProtectionPanel {
*
* @param {Window} window
* Window containing the panelView to manage.
- * @param {string} variant
- * Variant of the panel that should be used.
*/
- constructor(window, variant = "") {
+ constructor(window) {
this.handleEvent = this.#handleEvent.bind(this);
let { activatedAt: protectionEnabledSince } = lazy.IPProtectionService;
@@ -123,7 +121,7 @@ export class IPProtectionPanel {
code: "us",
},
error: "",
- variant,
+ isAlpha: lazy.IPPEnrollAndEntitleManager.isAlpha,
hasUpgraded: lazy.IPPEnrollAndEntitleManager.hasUpgraded,
};
diff --git a/browser/components/ipprotection/tests/xpcshell/test_IPProtectionPanel.js b/browser/components/ipprotection/tests/xpcshell/test_IPProtectionPanel.js
@@ -301,25 +301,63 @@ add_task(async function test_IPProtectionPanel_started_stopped() {
});
/**
- * Tests that the variant argument is set in the state.
+ * Tests that IPProtectionPanel state isAlpha property is correct
+ * when IPPEnrollAndEntitleManager.isAlpha is true.
*/
-add_task(async function test_IPProtectionPanel_variant() {
- let ipProtectionPanel = new IPProtectionPanel(null, "alpha");
+add_task(async function test_IPProtectionPanel_isAlpha_true() {
+ let sandbox = sinon.createSandbox();
+
+ sandbox
+ .stub(IPPEnrollAndEntitleManager, "isEnrolledAndEntitled")
+ .get(() => true);
+ sandbox.stub(IPPEnrollAndEntitleManager, "isAlpha").get(() => true);
+ sandbox
+ .stub(IPProtectionService.guardian, "isLinkedToGuardian")
+ .resolves(true);
+
+ let ipProtectionPanel = new IPProtectionPanel();
let fakeElement = new FakeIPProtectionPanelElement();
ipProtectionPanel.panel = fakeElement;
+ fakeElement.isConnected = true;
+
+ IPProtectionService.updateState();
Assert.equal(
- ipProtectionPanel.state.variant,
- "alpha",
- "variant should be set in the IPProtectionPanel state"
+ ipProtectionPanel.state.isAlpha,
+ true,
+ "isAlpha should be true in the IPProtectionPanel state"
);
+ sandbox.restore();
+});
+
+/**
+ * Tests that IPProtectionPanel state isAlpha property is correct
+ * when IPPEnrollAndEntitleManager.isAlpha is false.
+ */
+add_task(async function test_IPProtectionPanel_isAlpha_false() {
+ let sandbox = sinon.createSandbox();
+
+ sandbox
+ .stub(IPPEnrollAndEntitleManager, "isEnrolledAndEntitled")
+ .get(() => true);
+ sandbox.stub(IPPEnrollAndEntitleManager, "isAlpha").get(() => false);
+ sandbox
+ .stub(IPProtectionService.guardian, "isLinkedToGuardian")
+ .resolves(true);
+
+ let ipProtectionPanel = new IPProtectionPanel();
+ let fakeElement = new FakeIPProtectionPanelElement();
+ ipProtectionPanel.panel = fakeElement;
fakeElement.isConnected = true;
- ipProtectionPanel.updateState();
+
+ IPProtectionService.updateState();
Assert.equal(
- fakeElement.state.variant,
- "alpha",
- "variant should be set in the fake elements state"
+ ipProtectionPanel.state.isAlpha,
+ false,
+ "isAlpha should be false in the IPProtectionPanel state"
);
+
+ sandbox.restore();
});