summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js')
-rw-r--r--toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js b/toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js
new file mode 100644
index 0000000000..4af16405a2
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_telemetry.js
@@ -0,0 +1,119 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+const HISTOGRAM = "WEBEXT_BACKGROUND_PAGE_LOAD_MS";
+const HISTOGRAM_KEYED = "WEBEXT_BACKGROUND_PAGE_LOAD_MS_BY_ADDONID";
+
+add_task(async function test_telemetry() {
+ const { GleanTimingDistribution } = globalThis;
+
+ let extension1 = ExtensionTestUtils.loadExtension({
+ background() {
+ browser.test.sendMessage("loaded");
+ },
+ });
+
+ let extension2 = ExtensionTestUtils.loadExtension({
+ background() {
+ browser.test.sendMessage("loaded");
+ },
+ });
+
+ resetTelemetryData();
+
+ assertHistogramEmpty(HISTOGRAM);
+ assertKeyedHistogramEmpty(HISTOGRAM_KEYED);
+ assertGleanMetricsNoSamples({
+ metricId: "backgroundPageLoad",
+ gleanMetric: Glean.extensionsTiming.backgroundPageLoad,
+ gleanMetricConstructor: GleanTimingDistribution,
+ });
+
+ await extension1.startup();
+ await extension1.awaitMessage("loaded");
+
+ const processSnapshot = snapshot => {
+ return snapshot.sum > 0;
+ };
+
+ const processKeyedSnapshot = snapshot => {
+ let res = {};
+ for (let key of Object.keys(snapshot)) {
+ res[key] = snapshot[key].sum > 0;
+ }
+ return res;
+ };
+
+ assertHistogramSnapshot(
+ HISTOGRAM,
+ { processSnapshot, expectedValue: true },
+ `Data recorded for first extension for histogram: ${HISTOGRAM}.`
+ );
+
+ assertHistogramSnapshot(
+ HISTOGRAM_KEYED,
+ {
+ keyed: true,
+ processSnapshot: processKeyedSnapshot,
+ expectedValue: {
+ [extension1.extension.id]: true,
+ },
+ },
+ `Data recorded for first extension for histogram ${HISTOGRAM_KEYED}`
+ );
+
+ assertGleanMetricsSamplesCount({
+ metricId: "backgroundPageLoad",
+ gleanMetric: Glean.extensionsTiming.backgroundPageLoad,
+ gleanMetricConstructor: GleanTimingDistribution,
+ expectedSamplesCount: 1,
+ });
+
+ let histogram = Services.telemetry.getHistogramById(HISTOGRAM);
+ let histogramKeyed =
+ Services.telemetry.getKeyedHistogramById(HISTOGRAM_KEYED);
+ let histogramSum = histogram.snapshot().sum;
+ let histogramSumExt1 = histogramKeyed.snapshot()[extension1.extension.id].sum;
+
+ await extension2.startup();
+ await extension2.awaitMessage("loaded");
+
+ assertHistogramSnapshot(
+ HISTOGRAM,
+ {
+ processSnapshot: snapshot => snapshot.sum > histogramSum,
+ expectedValue: true,
+ },
+ `Data recorded for second extension for histogram: ${HISTOGRAM}.`
+ );
+
+ assertHistogramSnapshot(
+ HISTOGRAM_KEYED,
+ {
+ keyed: true,
+ processSnapshot: processKeyedSnapshot,
+ expectedValue: {
+ [extension1.extension.id]: true,
+ [extension2.extension.id]: true,
+ },
+ },
+ `Data recorded for second extension for histogram ${HISTOGRAM_KEYED}`
+ );
+
+ equal(
+ histogramKeyed.snapshot()[extension1.extension.id].sum,
+ histogramSumExt1,
+ `Data recorder for first extension is unchanged on the keyed histogram ${HISTOGRAM_KEYED}`
+ );
+
+ assertGleanMetricsSamplesCount({
+ metricId: "backgroundPageLoad",
+ gleanMetric: Glean.extensionsTiming.backgroundPageLoad,
+ gleanMetricConstructor: GleanTimingDistribution,
+ expectedSamplesCount: 2,
+ });
+
+ await extension1.unload();
+ await extension2.unload();
+});