summaryrefslogtreecommitdiffstats
path: root/dom/base/test/browser_page_load_event_telemetry.js
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/test/browser_page_load_event_telemetry.js')
-rw-r--r--dom/base/test/browser_page_load_event_telemetry.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/dom/base/test/browser_page_load_event_telemetry.js b/dom/base/test/browser_page_load_event_telemetry.js
new file mode 100644
index 0000000000..839e333d61
--- /dev/null
+++ b/dom/base/test/browser_page_load_event_telemetry.js
@@ -0,0 +1,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);
+});