diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js | |
parent | Initial commit. (diff) | |
download | firefox-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/terminator/tests/xpcshell/test_terminator_reload.js')
-rw-r--r-- | toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js b/toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js new file mode 100644 index 0000000000..79aecd818b --- /dev/null +++ b/toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js @@ -0,0 +1,88 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that the Shutdown Terminator reloads durations correctly + +const HISTOGRAMS = { + "quit-application": "SHUTDOWN_PHASE_DURATION_TICKS_QUIT_APPLICATION", + "profile-change-net-teardown": + "SHUTDOWN_PHASE_DURATION_TICKS_PROFILE_CHANGE_NET_TEARDOWN", + "profile-change-teardown": + "SHUTDOWN_PHASE_DURATION_TICKS_PROFILE_CHANGE_TEARDOWN", + "profile-before-change": + "SHUTDOWN_PHASE_DURATION_TICKS_PROFILE_BEFORE_CHANGE", + "profile-before-change-qm": + "SHUTDOWN_PHASE_DURATION_TICKS_PROFILE_BEFORE_CHANGE_QM", + "xpcom-will-shutdown": "SHUTDOWN_PHASE_DURATION_TICKS_XPCOM_WILL_SHUTDOWN", + "xpcom-shutdown": "SHUTDOWN_PHASE_DURATION_TICKS_XPCOM_SHUTDOWN", +}; + +let PATH; + +add_setup(async function init() { + do_get_profile(); + PATH = PathUtils.join(PathUtils.localProfileDir, "ShutdownDuration.json"); +}); + +add_task(async function test_reload() { + info("Forging data"); + let data = {}; + let telemetrySnapshots = Services.telemetry.getSnapshotForHistograms( + "main", + false /* clear */ + ).parent; + let i = 0; + for (let k of Object.keys(HISTOGRAMS)) { + let id = HISTOGRAMS[k]; + data[k] = i++; + Assert.equal( + telemetrySnapshots[id] || undefined, + undefined, + "Histogram " + id + " is empty" + ); + } + + // Extra fields that nsTerminator reports that we do not have histograms for. + data["xpcom-shutdown-threads"] = 123; + data.XPCOMShutdownFinal = 456; + data.CCPostLastCycleCollection = 789; + + await IOUtils.writeJSON(PATH, data); + + const TOPIC = "shutdown-terminator-telemetry-updated"; + + let wait = new Promise(resolve => + Services.obs.addObserver(function observer() { + info("Telemetry has been updated"); + Services.obs.removeObserver(observer, TOPIC); + resolve(); + }, TOPIC) + ); + + info("Starting nsTerminatorTelemetry"); + let tt = Cc[ + "@mozilla.org/toolkit/shutdown-terminator-telemetry;1" + ].createInstance(Ci.nsIObserver); + tt.observe(null, "profile-after-change", ""); + + info("Waiting until telemetry is updated"); + // Now wait until Telemetry is updated + await wait; + + telemetrySnapshots = Services.telemetry.getSnapshotForHistograms( + "main", + false /* clear */ + ).parent; + for (let k of Object.keys(HISTOGRAMS)) { + let id = HISTOGRAMS[k]; + info("Testing histogram " + id); + let snapshot = telemetrySnapshots[id]; + let count = 0; + for (let x of Object.values(snapshot.values)) { + count += x; + } + Assert.equal(count, 1, "We have added one item"); + } +}); |