summaryrefslogtreecommitdiffstats
path: root/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js')
-rw-r--r--toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js b/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
new file mode 100644
index 0000000000..23e476a028
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
@@ -0,0 +1,126 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+*/
+
+const { TelemetryController } = ChromeUtils.importESModule(
+ "resource://gre/modules/TelemetryController.sys.mjs"
+);
+const { TelemetrySession } = ChromeUtils.importESModule(
+ "resource://gre/modules/TelemetrySession.sys.mjs"
+);
+
+function tick(aHowMany) {
+ for (let i = 0; i < aHowMany; i++) {
+ Services.obs.notifyObservers(null, "user-interaction-active");
+ }
+}
+
+function checkSessionTicks(aExpected) {
+ let payload = TelemetrySession.getPayload();
+ Assert.equal(
+ payload.simpleMeasurements.activeTicks,
+ aExpected,
+ "Should record the expected number of active ticks for the session."
+ );
+}
+
+function checkSubsessionTicks(aExpected, aClearSubsession) {
+ let payload = TelemetrySession.getPayload("main", aClearSubsession);
+ Assert.equal(
+ payload.simpleMeasurements.activeTicks,
+ aExpected,
+ "Should record the expected number of active ticks for the subsession."
+ );
+ if (aExpected > 0) {
+ Assert.equal(
+ payload.processes.parent.scalars["browser.engagement.active_ticks"],
+ aExpected,
+ "Should record the expected number of active ticks for the subsession, in a scalar."
+ );
+ }
+}
+
+add_task(async function test_setup() {
+ do_get_profile();
+ // Make sure we don't generate unexpected pings due to pref changes.
+ await setEmptyPrefWatchlist();
+ // Ensure FOG's init
+ Services.fog.initializeFOG();
+});
+
+add_task(async function test_record_activeTicks() {
+ await TelemetryController.testSetup();
+
+ let checkActiveTicks = expected => {
+ // Scalars are only present in subsession payloads.
+ let payload = TelemetrySession.getPayload("main");
+ Assert.equal(
+ payload.simpleMeasurements.activeTicks,
+ expected,
+ "TelemetrySession must record the expected number of active ticks (in simpleMeasurements)."
+ );
+ // Subsessions are not yet supported on Android.
+ if (!gIsAndroid) {
+ Assert.equal(
+ payload.processes.parent.scalars["browser.engagement.active_ticks"],
+ expected,
+ "TelemetrySession must record the expected number of active ticks (in scalars)."
+ );
+ }
+ Assert.equal(Glean.browserEngagement.activeTicks.testGetValue(), expected);
+ };
+
+ for (let i = 0; i < 3; i++) {
+ Services.obs.notifyObservers(null, "user-interaction-active");
+ }
+ checkActiveTicks(3);
+
+ // Now send inactive. This must not increment the active ticks.
+ Services.obs.notifyObservers(null, "user-interaction-inactive");
+ checkActiveTicks(3);
+
+ // If we send active again, this should be counted as inactive.
+ Services.obs.notifyObservers(null, "user-interaction-active");
+ checkActiveTicks(3);
+
+ // If we send active again, this should be counted as active.
+ Services.obs.notifyObservers(null, "user-interaction-active");
+ checkActiveTicks(4);
+
+ Services.obs.notifyObservers(null, "user-interaction-active");
+ checkActiveTicks(5);
+
+ await TelemetryController.testShutdown();
+});
+
+add_task(
+ {
+ skip_if: () => gIsAndroid,
+ },
+ async function test_subsession_activeTicks() {
+ await TelemetryController.testReset();
+ Telemetry.clearScalars();
+
+ tick(5);
+ checkSessionTicks(5);
+ checkSubsessionTicks(5, true);
+
+ // After clearing the subsession, subsession ticks should be 0 but session
+ // ticks should still be 5.
+ checkSubsessionTicks(0);
+ checkSessionTicks(5);
+
+ tick(1);
+ checkSessionTicks(6);
+ checkSubsessionTicks(1, true);
+
+ checkSubsessionTicks(0);
+ checkSessionTicks(6);
+
+ tick(2);
+ checkSessionTicks(8);
+ checkSubsessionTicks(2);
+
+ await TelemetryController.testShutdown();
+ }
+);