commit 334149f5b472dd951036c624c99fb84e5de54ea4
parent cd8497d076d6e13db9b345c27ed1232195d3f017
Author: Emily McMinn <emcminn@mozilla.com>
Date: Mon, 8 Dec 2025 21:23:40 +0000
Bug 1997180 - Add tests for currentProfileId && ProfileGroupProfileCount r=omc-reviewers,mviar
Differential Revision: https://phabricator.services.mozilla.com/D274012
Diffstat:
1 file changed, 59 insertions(+), 0 deletions(-)
diff --git a/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js b/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js
@@ -24,6 +24,8 @@ ChromeUtils.defineESModuleGetters(this, {
ProfileAge: "resource://gre/modules/ProfileAge.sys.mjs",
QueryCache: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
Region: "resource://gre/modules/Region.sys.mjs",
+ SelectableProfileService:
+ "resource:///modules/profiles/SelectableProfileService.sys.mjs",
ShellService: "moz-src:///browser/components/shell/ShellService.sys.mjs",
sinon: "resource://testing-common/Sinon.sys.mjs",
Spotlight: "resource:///modules/asrouter/Spotlight.sys.mjs",
@@ -2374,6 +2376,63 @@ add_task(async function check_profileGroupIdTargeting() {
);
});
+add_task(async function check_currentProfileIdTargeting() {
+ is(
+ typeof ASRouterTargeting.Environment.currentProfileId,
+ "string",
+ "Should return a string"
+ );
+
+ const message = {
+ id: "foo",
+ targeting: `currentProfileId == "test-profile-id"`,
+ };
+
+ const result = await ASRouterTargeting.findMatchingMessage({
+ messages: [message],
+ context: { currentProfileId: "test-profile-id" },
+ });
+
+ is(result, message, "should select correct item by profile id");
+});
+
+add_task(async function check_profileGroupProfileCountTargeting() {
+ await pushPrefs(
+ ["browser.profiles.enabled", false],
+ ["browser.profiles.created", false]
+ );
+ const resultFalse =
+ await ASRouterTargeting.Environment.profileGroupProfileCount;
+
+ is(typeof resultFalse, "number", "Should return a number");
+
+ is(resultFalse, 0, "should be zero because profiles are disabled");
+
+ await pushPrefs(
+ ["browser.profiles.enabled", true],
+ ["browser.profiles.created", true]
+ );
+
+ const expected = await SelectableProfileService.getProfileCount();
+ const resultTrue =
+ await ASRouterTargeting.Environment.profileGroupProfileCount;
+
+ is(resultTrue, expected, "it should be equal to the profile group count");
+
+ const message = {
+ id: "foo",
+ targeting: `profileGroupProfileCount == "${expected}"`,
+ };
+ is(
+ await ASRouterTargeting.findMatchingMessage({ messages: [message] }),
+ message,
+ "should select correct item by number of profiles in the group"
+ );
+
+ //Clean up the prefs
+ await SpecialPowers.popPrefEnv();
+});
+
add_task(async function test_buildId() {
is(
typeof ASRouterTargeting.Environment.buildId,