summaryrefslogtreecommitdiffstats
path: root/toolkit/components/telemetry/tests/unit/test_SyncPingIntegration.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/telemetry/tests/unit/test_SyncPingIntegration.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/telemetry/tests/unit/test_SyncPingIntegration.js')
-rw-r--r--toolkit/components/telemetry/tests/unit/test_SyncPingIntegration.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/toolkit/components/telemetry/tests/unit/test_SyncPingIntegration.js b/toolkit/components/telemetry/tests/unit/test_SyncPingIntegration.js
new file mode 100644
index 0000000000..16a18644e9
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/test_SyncPingIntegration.js
@@ -0,0 +1,65 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+*/
+
+// Enable the collection (during test) for all products so even products
+// that don't collect the data will be able to run the test without failure.
+Services.prefs.setBoolPref(
+ "toolkit.telemetry.testing.overrideProductsCheck",
+ true
+);
+
+add_setup(async function test_setup() {
+ // Addon manager needs a profile directory
+ do_get_profile();
+});
+
+add_task(async function test_register_twice_fails() {
+ TelemetryController.registerSyncPingShutdown(() => {});
+ Assert.throws(
+ () => TelemetryController.registerSyncPingShutdown(() => {}),
+ /The sync ping shutdown handler is already registered./
+ );
+ await TelemetryController.testReset();
+});
+
+add_task(async function test_reset_clears_handler() {
+ await TelemetryController.testSetup();
+ TelemetryController.registerSyncPingShutdown(() => {});
+ await TelemetryController.testReset();
+ // If this works the reset must have cleared it.
+ TelemetryController.registerSyncPingShutdown(() => {});
+ await TelemetryController.testReset();
+});
+
+add_task(async function test_shutdown_handler_submits() {
+ let handlerCalled = false;
+ await TelemetryController.testSetup();
+ TelemetryController.registerSyncPingShutdown(() => {
+ handlerCalled = true;
+ // and submit a ping.
+ let ping = {
+ why: "shutdown",
+ };
+ TelemetryController.submitExternalPing("sync", ping);
+ });
+
+ await TelemetryController.testShutdown();
+ Assert.ok(handlerCalled);
+ await TelemetryController.testReset();
+});
+
+add_task(async function test_shutdown_handler_no_submit() {
+ let handlerCalled = false;
+ await TelemetryController.testSetup();
+ TelemetryController.registerSyncPingShutdown(() => {
+ handlerCalled = true;
+ // but don't submit a ping.
+ });
+
+ await TelemetryController.testShutdown();
+ Assert.ok(handlerCalled);
+});
+
+// NB: The last test in this file *must not* restart TelemetryController, or it
+// will cause intermittent timeouts for this test.