diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/components/newtab/test/unit/lib/UTEventReporting.test.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/newtab/test/unit/lib/UTEventReporting.test.js')
-rw-r--r-- | browser/components/newtab/test/unit/lib/UTEventReporting.test.js | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/browser/components/newtab/test/unit/lib/UTEventReporting.test.js b/browser/components/newtab/test/unit/lib/UTEventReporting.test.js new file mode 100644 index 0000000000..ad0e3063a1 --- /dev/null +++ b/browser/components/newtab/test/unit/lib/UTEventReporting.test.js @@ -0,0 +1,115 @@ +import { UTSessionPing, UTUserEventPing } from "test/schemas/pings"; +import { GlobalOverrider } from "test/unit/utils"; +import { UTEventReporting } from "lib/UTEventReporting.jsm"; + +const FAKE_EVENT_PING_PC = { + event: "CLICK", + source: "TOP_SITES", + addon_version: "123", + user_prefs: 63, + session_id: "abc", + page: "about:newtab", + action_position: 5, + locale: "en-US", +}; +const FAKE_SESSION_PING_PC = { + session_duration: 1234, + addon_version: "123", + user_prefs: 63, + session_id: "abc", + page: "about:newtab", + locale: "en-US", +}; +const FAKE_EVENT_PING_UT = [ + "activity_stream", + "event", + "CLICK", + "TOP_SITES", + { + addon_version: "123", + user_prefs: "63", + session_id: "abc", + page: "about:newtab", + action_position: "5", + }, +]; +const FAKE_SESSION_PING_UT = [ + "activity_stream", + "end", + "session", + "1234", + { + addon_version: "123", + user_prefs: "63", + session_id: "abc", + page: "about:newtab", + }, +]; + +describe("UTEventReporting", () => { + let globals; + let sandbox; + let utEvents; + + beforeEach(() => { + globals = new GlobalOverrider(); + sandbox = globals.sandbox; + sandbox.stub(global.Services.telemetry, "setEventRecordingEnabled"); + sandbox.stub(global.Services.telemetry, "recordEvent"); + + utEvents = new UTEventReporting(); + }); + + afterEach(() => { + globals.restore(); + }); + + describe("#sendUserEvent()", () => { + it("should queue up the correct data to send to Events Telemetry", async () => { + utEvents.sendUserEvent(FAKE_EVENT_PING_PC); + assert.calledWithExactly( + global.Services.telemetry.recordEvent, + ...FAKE_EVENT_PING_UT + ); + + let ping = global.Services.telemetry.recordEvent.firstCall.args; + assert.validate(ping, UTUserEventPing); + }); + }); + + describe("#sendSessionEndEvent()", () => { + it("should queue up the correct data to send to Events Telemetry", async () => { + utEvents.sendSessionEndEvent(FAKE_SESSION_PING_PC); + assert.calledWithExactly( + global.Services.telemetry.recordEvent, + ...FAKE_SESSION_PING_UT + ); + + let ping = global.Services.telemetry.recordEvent.firstCall.args; + assert.validate(ping, UTSessionPing); + }); + }); + + describe("#uninit()", () => { + it("should call setEventRecordingEnabled with a false value", () => { + assert.equal( + global.Services.telemetry.setEventRecordingEnabled.firstCall.args[0], + "activity_stream" + ); + assert.equal( + global.Services.telemetry.setEventRecordingEnabled.firstCall.args[1], + true + ); + + utEvents.uninit(); + assert.equal( + global.Services.telemetry.setEventRecordingEnabled.secondCall.args[0], + "activity_stream" + ); + assert.equal( + global.Services.telemetry.setEventRecordingEnabled.secondCall.args[1], + false + ); + }); + }); +}); |