summaryrefslogtreecommitdiffstats
path: root/browser/modules/test/unit/test_PartnerLinkAttribution.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/modules/test/unit/test_PartnerLinkAttribution.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/modules/test/unit/test_PartnerLinkAttribution.js')
-rw-r--r--browser/modules/test/unit/test_PartnerLinkAttribution.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/browser/modules/test/unit/test_PartnerLinkAttribution.js b/browser/modules/test/unit/test_PartnerLinkAttribution.js
new file mode 100644
index 0000000000..79053fbb07
--- /dev/null
+++ b/browser/modules/test/unit/test_PartnerLinkAttribution.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+"use strict";
+
+const { PartnerLinkAttribution, CONTEXTUAL_SERVICES_PING_TYPES } =
+ ChromeUtils.importESModule(
+ "resource:///modules/PartnerLinkAttribution.sys.mjs"
+ );
+
+const { sinon } = ChromeUtils.importESModule(
+ "resource://testing-common/Sinon.sys.mjs"
+);
+
+const FAKE_PING = { tile_id: 1, position: 1 };
+
+let sandbox;
+let stub;
+
+add_task(function setup() {
+ sandbox = sinon.createSandbox();
+ stub = sandbox.stub(
+ PartnerLinkAttribution._pingCentre,
+ "sendStructuredIngestionPing"
+ );
+ stub.returns(200);
+
+ registerCleanupFunction(() => {
+ sandbox.restore();
+ });
+});
+
+add_task(function test_sendContextualService_success() {
+ for (const type of Object.values(CONTEXTUAL_SERVICES_PING_TYPES)) {
+ PartnerLinkAttribution.sendContextualServicesPing(FAKE_PING, type);
+
+ Assert.ok(stub.calledOnce, `Should send the ping for ${type}`);
+
+ const [payload, endpoint] = stub.firstCall.args;
+ Assert.ok(!!payload.context_id, "Should add context_id to the payload");
+ Assert.ok(
+ endpoint.includes(type),
+ "Should include the ping type in the endpoint URL"
+ );
+ stub.resetHistory();
+ }
+});
+
+add_task(function test_rejectUnknownPingType() {
+ PartnerLinkAttribution.sendContextualServicesPing(FAKE_PING, "unknown-type");
+
+ Assert.ok(stub.notCalled, "Should not send the ping with unknown ping type");
+});