tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

UTEventReporting.test.js (2202B)


      1 import { UTSessionPing, UTUserEventPing } from "test/schemas/pings";
      2 import { GlobalOverrider } from "test/unit/utils";
      3 import { UTEventReporting } from "lib/UTEventReporting.sys.mjs";
      4 
      5 const FAKE_EVENT_PING_PC = {
      6  event: "CLICK",
      7  source: "TOP_SITES",
      8  addon_version: "123",
      9  user_prefs: 63,
     10  session_id: "abc",
     11  page: "about:newtab",
     12  action_position: 5,
     13  locale: "en-US",
     14 };
     15 const FAKE_SESSION_PING_PC = {
     16  session_duration: 1234,
     17  addon_version: "123",
     18  user_prefs: 63,
     19  session_id: "abc",
     20  page: "about:newtab",
     21  locale: "en-US",
     22 };
     23 const FAKE_EVENT_PING_UT = [
     24  {
     25    value: "TOP_SITES",
     26    addon_version: "123",
     27    user_prefs: 63,
     28    session_id: "abc",
     29    page: "about:newtab",
     30    action_position: 5,
     31  },
     32 ];
     33 const FAKE_SESSION_PING_UT = [
     34  {
     35    value: 1234,
     36    addon_version: "123",
     37    user_prefs: 63,
     38    session_id: "abc",
     39    page: "about:newtab",
     40  },
     41 ];
     42 
     43 describe("UTEventReporting", () => {
     44  let globals;
     45  let sandbox;
     46  let utEvents;
     47 
     48  beforeEach(() => {
     49    globals = new GlobalOverrider();
     50    sandbox = globals.sandbox;
     51 
     52    utEvents = new UTEventReporting();
     53  });
     54 
     55  afterEach(() => {
     56    globals.restore();
     57  });
     58 
     59  describe("#sendUserEvent()", () => {
     60    it("should queue up the correct data to send to Events Telemetry", async () => {
     61      sandbox.stub(global.Glean.activityStream.eventClick, "record");
     62      utEvents.sendUserEvent(FAKE_EVENT_PING_PC);
     63      assert.calledWithExactly(
     64        global.Glean.activityStream.eventClick.record,
     65        ...FAKE_EVENT_PING_UT
     66      );
     67 
     68      let ping = global.Glean.activityStream.eventClick.record.firstCall.args;
     69      assert.validate(ping, UTUserEventPing);
     70    });
     71  });
     72 
     73  describe("#sendSessionEndEvent()", () => {
     74    it("should queue up the correct data to send to Events Telemetry", async () => {
     75      sandbox.stub(global.Glean.activityStream.endSession, "record");
     76      utEvents.sendSessionEndEvent(FAKE_SESSION_PING_PC);
     77      assert.calledWithExactly(
     78        global.Glean.activityStream.endSession.record,
     79        ...FAKE_SESSION_PING_UT
     80      );
     81 
     82      let ping = global.Glean.activityStream.endSession.record.firstCall.args;
     83      assert.validate(ping, UTSessionPing);
     84    });
     85  });
     86 });