From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../xpcshell/test_ASRouterTargeting_attribution.js | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 browser/components/asrouter/tests/xpcshell/test_ASRouterTargeting_attribution.js (limited to 'browser/components/asrouter/tests/xpcshell/test_ASRouterTargeting_attribution.js') diff --git a/browser/components/asrouter/tests/xpcshell/test_ASRouterTargeting_attribution.js b/browser/components/asrouter/tests/xpcshell/test_ASRouterTargeting_attribution.js new file mode 100644 index 0000000000..a37cb6c793 --- /dev/null +++ b/browser/components/asrouter/tests/xpcshell/test_ASRouterTargeting_attribution.js @@ -0,0 +1,94 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +const { AttributionCode } = ChromeUtils.importESModule( + "resource:///modules/AttributionCode.sys.mjs" +); +const { ASRouterTargeting } = ChromeUtils.importESModule( + "resource:///modules/asrouter/ASRouterTargeting.sys.mjs" +); +const { MacAttribution } = ChromeUtils.importESModule( + "resource:///modules/MacAttribution.sys.mjs" +); +const { EnterprisePolicyTesting } = ChromeUtils.importESModule( + "resource://testing-common/EnterprisePolicyTesting.sys.mjs" +); + +add_task(async function check_attribution_data() { + // Some setup to fake the correct attribution data + const campaign = "non-fx-button"; + const source = "addons.mozilla.org"; + const attrStr = `campaign%3D${campaign}%26source%3D${source}`; + await MacAttribution.setAttributionString(attrStr); + AttributionCode._clearCache(); + await AttributionCode.getAttrDataAsync(); + + const { campaign: attributionCampain, source: attributionSource } = + ASRouterTargeting.Environment.attributionData; + equal( + attributionCampain, + campaign, + "should get the correct campaign out of attributionData" + ); + equal( + attributionSource, + source, + "should get the correct source out of attributionData" + ); + + const messages = [ + { + id: "foo1", + targeting: + "attributionData.campaign == 'back_to_school' && attributionData.source == 'addons.mozilla.org'", + }, + { + id: "foo2", + targeting: + "attributionData.campaign == 'non-fx-button' && attributionData.source == 'addons.mozilla.org'", + }, + ]; + + equal( + await ASRouterTargeting.findMatchingMessage({ messages }), + messages[1], + "should select the message with the correct campaign and source" + ); + AttributionCode._clearCache(); +}); + +add_task(async function check_enterprise_targeting() { + const messages = [ + { + id: "foo1", + targeting: "hasActiveEnterprisePolicies", + }, + { + id: "foo2", + targeting: "!hasActiveEnterprisePolicies", + }, + ]; + + equal( + await ASRouterTargeting.findMatchingMessage({ messages }), + messages[1], + "should select the message for policies turned off" + ); + + await EnterprisePolicyTesting.setupPolicyEngineWithJson({ + policies: { + DisableFirefoxStudies: { + Value: true, + }, + }, + }); + + equal( + await ASRouterTargeting.findMatchingMessage({ messages }), + messages[0], + "should select the message for policies turned on" + ); +}); -- cgit v1.2.3