diff --git a/toolkit/components/telemetry/TelemetrySession.jsm b/toolkit/components/telemetry/TelemetrySession.jsm index a15cc33f8a53..0f55d1387077 100644 --- a/toolkit/components/telemetry/TelemetrySession.jsm +++ b/toolkit/components/telemetry/TelemetrySession.jsm @@ -809,7 +809,7 @@ var Impl = { } if (clearSubsession) { - this._subsessionStartActiveTicks = activeTicks; + this._subsessionStartActiveTicks = this._sessionActiveTicks; } ret.activeTicks = activeTicks; diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js b/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js index 1f5ca5f683b6..2f78b151f229 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js @@ -5,6 +5,27 @@ ChromeUtils.import("resource://gre/modules/TelemetryController.jsm", this); ChromeUtils.import("resource://gre/modules/TelemetrySession.jsm", this); +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(); @@ -49,3 +70,33 @@ add_task(async function test_record_activeTicks() { 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(); +});