summaryrefslogtreecommitdiffstats
path: root/dom/base/test/browser_page_load_event_telemetry.js
blob: 839e333d617fc8fcee0d3e588c6b6e40314ff91a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use strict";

const { TelemetryTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/TelemetryTestUtils.sys.mjs"
);

const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;

add_task(async function () {
  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    waitForLoad: true,
  });

  let browser = tab.linkedBrowser;

  // Reset event counts.
  Services.telemetry.clearEvents();
  TelemetryTestUtils.assertNumberOfEvents(0);

  // Add checks for pageload ping and pageload event
  let pingSubmitted = false;
  GleanPings.pageload.testBeforeNextSubmit(reason => {
    pingSubmitted = true;
    Assert.equal(reason, "threshold");
    let record = Glean.perf.pageLoad.testGetValue();
    Assert.greaterOrEqual(
      record.length,
      30,
      "Should have at least 30 page load events"
    );
  });

  // Perform page load 30 times to trigger the ping being sent
  for (let i = 0; i < 30; i++) {
    BrowserTestUtils.loadURIString(browser, "https://example.com");
    await BrowserTestUtils.browserLoaded(browser);
  }

  await BrowserTestUtils.waitForCondition(
    () => pingSubmitted,
    "Page load ping should have been submitted."
  );

  BrowserTestUtils.removeTab(tab);
});