summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/xpcshell/test_ASRouterTargeting_attribution.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/newtab/test/xpcshell/test_ASRouterTargeting_attribution.js')
-rw-r--r--browser/components/newtab/test/xpcshell/test_ASRouterTargeting_attribution.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/browser/components/newtab/test/xpcshell/test_ASRouterTargeting_attribution.js b/browser/components/newtab/test/xpcshell/test_ASRouterTargeting_attribution.js
new file mode 100644
index 0000000000..6962ca6aa3
--- /dev/null
+++ b/browser/components/newtab/test/xpcshell/test_ASRouterTargeting_attribution.js
@@ -0,0 +1,64 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+"use strict";
+
+const { AttributionCode } = ChromeUtils.import(
+ "resource:///modules/AttributionCode.jsm"
+);
+const { ASRouterTargeting } = ChromeUtils.import(
+ "resource://activity-stream/lib/ASRouterTargeting.jsm"
+);
+const { MacAttribution } = ChromeUtils.import(
+ "resource:///modules/MacAttribution.jsm"
+);
+
+add_task(async function check_attribution_data() {
+ // Some setup to fake the correct attribution data
+ const appPath = MacAttribution.applicationPath;
+ const attributionSvc = Cc["@mozilla.org/mac-attribution;1"].getService(
+ Ci.nsIMacAttributionService
+ );
+ const campaign = "non-fx-button";
+ const source = "addons.mozilla.org";
+ const referrer = `https://allizom.org/anything/?utm_campaign=${campaign}&utm_source=${source}`;
+ attributionSvc.setReferrerUrl(appPath, referrer, true);
+ 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();
+});