summaryrefslogtreecommitdiffstats
path: root/toolkit/components/crashmonitor/test
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/crashmonitor/test
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/crashmonitor/test')
-rw-r--r--toolkit/components/crashmonitor/test/unit/head.js26
-rw-r--r--toolkit/components/crashmonitor/test/unit/test_init.js17
-rw-r--r--toolkit/components/crashmonitor/test/unit/test_invalid_file.js23
-rw-r--r--toolkit/components/crashmonitor/test/unit/test_invalid_json.js19
-rw-r--r--toolkit/components/crashmonitor/test/unit/test_missing_file.js13
-rw-r--r--toolkit/components/crashmonitor/test/unit/test_register.js25
-rw-r--r--toolkit/components/crashmonitor/test/unit/test_valid_file.js24
-rw-r--r--toolkit/components/crashmonitor/test/unit/xpcshell.toml15
8 files changed, 162 insertions, 0 deletions
diff --git a/toolkit/components/crashmonitor/test/unit/head.js b/toolkit/components/crashmonitor/test/unit/head.js
new file mode 100644
index 0000000000..1d3be083de
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/head.js
@@ -0,0 +1,26 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+var sessionCheckpointsPath;
+var CrashMonitor;
+
+/**
+ * Start the tasks of the different tests
+ */
+function run_test() {
+ do_get_profile();
+ sessionCheckpointsPath = PathUtils.join(
+ PathUtils.profileDir,
+ "sessionCheckpoints.json"
+ );
+ ({ CrashMonitor } = ChromeUtils.importESModule(
+ "resource://gre/modules/CrashMonitor.sys.mjs"
+ ));
+ run_next_test();
+}
diff --git a/toolkit/components/crashmonitor/test/unit/test_init.js b/toolkit/components/crashmonitor/test/unit/test_init.js
new file mode 100644
index 0000000000..633a5701d6
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/test_init.js
@@ -0,0 +1,17 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Test that calling |init| twice throws an error
+ */
+add_task(function test_init() {
+ CrashMonitor.init();
+ try {
+ CrashMonitor.init();
+ Assert.ok(false);
+ } catch (ex) {
+ Assert.ok(true);
+ }
+});
diff --git a/toolkit/components/crashmonitor/test/unit/test_invalid_file.js b/toolkit/components/crashmonitor/test/unit/test_invalid_file.js
new file mode 100644
index 0000000000..f64fc9183c
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/test_invalid_file.js
@@ -0,0 +1,23 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Test with sessionCheckpoints.json containing invalid data
+ */
+add_task(async function test_invalid_file() {
+ // Write bogus data to checkpoint file
+ let data = "1234";
+ await IOUtils.writeUTF8(sessionCheckpointsPath, data, {
+ tmpPath: sessionCheckpointsPath + ".tmp",
+ });
+
+ // An invalid file will cause |init| to return null
+ let status = await CrashMonitor.init();
+ Assert.ok(!!(status === null));
+
+ // and |previousCheckpoints| will be null
+ let checkpoints = await CrashMonitor.previousCheckpoints;
+ Assert.ok(!!(checkpoints === null));
+});
diff --git a/toolkit/components/crashmonitor/test/unit/test_invalid_json.js b/toolkit/components/crashmonitor/test/unit/test_invalid_json.js
new file mode 100644
index 0000000000..d49852a280
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/test_invalid_json.js
@@ -0,0 +1,19 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Test with sessionCheckpoints.json containing invalid JSON data
+ */
+add_task(async function test_invalid_file() {
+ // Write bogus data to checkpoint file
+ let data = "[}";
+ await IOUtils.writeUTF8(sessionCheckpointsPath, data, {
+ tmpPath: sessionCheckpointsPath + ".tmp",
+ });
+
+ CrashMonitor.init();
+ let checkpoints = await CrashMonitor.previousCheckpoints;
+ Assert.equal(checkpoints, null);
+});
diff --git a/toolkit/components/crashmonitor/test/unit/test_missing_file.js b/toolkit/components/crashmonitor/test/unit/test_missing_file.js
new file mode 100644
index 0000000000..a8b86fe6c1
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/test_missing_file.js
@@ -0,0 +1,13 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Test with non-existing sessionCheckpoints.json
+ */
+add_task(async function test_missing_file() {
+ CrashMonitor.init();
+ let checkpoints = await CrashMonitor.previousCheckpoints;
+ Assert.equal(checkpoints, null);
+});
diff --git a/toolkit/components/crashmonitor/test/unit/test_register.js b/toolkit/components/crashmonitor/test/unit/test_register.js
new file mode 100644
index 0000000000..1957af4ee1
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/test_register.js
@@ -0,0 +1,25 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Test that CrashMonitor.jsm is correctly loaded from XPCOM component
+ */
+add_task(function test_register() {
+ let cm = Cc["@mozilla.org/toolkit/crashmonitor;1"].createInstance(
+ Ci.nsIObserver
+ );
+
+ // Send "profile-after-change" to trigger the initialization
+ cm.observe(null, "profile-after-change", null);
+
+ // If CrashMonitor was initialized properly a new call to |init|
+ // should fail
+ try {
+ CrashMonitor.init();
+ Assert.ok(false);
+ } catch (ex) {
+ Assert.ok(true);
+ }
+});
diff --git a/toolkit/components/crashmonitor/test/unit/test_valid_file.js b/toolkit/components/crashmonitor/test/unit/test_valid_file.js
new file mode 100644
index 0000000000..2a15d25a08
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/test_valid_file.js
@@ -0,0 +1,24 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Test with sessionCheckpoints.json containing valid data
+ */
+add_task(async function test_valid_file() {
+ // Write valid data to checkpoint file
+ await IOUtils.writeJSON(
+ sessionCheckpointsPath,
+ { "final-ui-startup": true },
+ {
+ tmpPath: sessionCheckpointsPath + ".tmp",
+ }
+ );
+
+ CrashMonitor.init();
+ let checkpoints = await CrashMonitor.previousCheckpoints;
+
+ Assert.ok(checkpoints["final-ui-startup"]);
+ Assert.equal(Object.keys(checkpoints).length, 1);
+});
diff --git a/toolkit/components/crashmonitor/test/unit/xpcshell.toml b/toolkit/components/crashmonitor/test/unit/xpcshell.toml
new file mode 100644
index 0000000000..87e09a0089
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/xpcshell.toml
@@ -0,0 +1,15 @@
+[DEFAULT]
+head = "head.js"
+skip-if = ["os == 'android'"]
+
+["test_init.js"]
+
+["test_invalid_file.js"]
+
+["test_invalid_json.js"]
+
+["test_missing_file.js"]
+
+["test_register.js"]
+
+["test_valid_file.js"]