diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/components/pocket/test/unit/browser_pocket_pktTelemetry.js | |
parent | Initial commit. (diff) | |
download | firefox-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/components/pocket/test/unit/browser_pocket_pktTelemetry.js')
-rw-r--r-- | browser/components/pocket/test/unit/browser_pocket_pktTelemetry.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/browser/components/pocket/test/unit/browser_pocket_pktTelemetry.js b/browser/components/pocket/test/unit/browser_pocket_pktTelemetry.js new file mode 100644 index 0000000000..197a152ee5 --- /dev/null +++ b/browser/components/pocket/test/unit/browser_pocket_pktTelemetry.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +ChromeUtils.defineESModuleGetters(this, { + pktTelemetry: "chrome://pocket/content/pktTelemetry.sys.mjs", +}); + +function test_runner(test) { + let testTask = async () => { + // Before each + const sandbox = sinon.createSandbox(); + try { + await test({ sandbox }); + } finally { + // After each + sandbox.restore(); + } + }; + + // Copy the name of the test function to identify the test + Object.defineProperty(testTask, "name", { value: test.name }); + add_task(testTask); +} + +test_runner(async function test_createPingPayload({ sandbox }) { + const impressionId = "{7fd5a1ac-6089-4212-91a7-fcdec1d2f533}"; + const creationDate = "18578"; + await SpecialPowers.pushPrefEnv({ + set: [["browser.newtabpage.activity-stream.impressionId", impressionId]], + }); + sandbox.stub(pktTelemetry, "_profileCreationDate").returns(creationDate); + const result = pktTelemetry.createPingPayload({ test: "test" }); + + Assert.deepEqual(result, { + test: "test", + pocket_logged_in_status: false, + profile_creation_date: creationDate, + impression_id: impressionId, + }); +}); + +test_runner(async function test_generateStructuredIngestionEndpoint({ + sandbox, +}) { + sandbox + .stub(pktTelemetry, "_generateUUID") + .returns("{7fd5a1ac-6089-4212-91a7-fcdec1d2f533}"); + const endpoint = pktTelemetry._generateStructuredIngestionEndpoint(); + Assert.equal( + endpoint, + "https://incoming.telemetry.mozilla.org/submit/activity-stream/pocket-button/1/7fd5a1ac-6089-4212-91a7-fcdec1d2f533" + ); +}); |