summaryrefslogtreecommitdiffstats
path: root/toolkit/components/crashmonitor/test
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/crashmonitor/test
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/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.ini10
8 files changed, 157 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.ini b/toolkit/components/crashmonitor/test/unit/xpcshell.ini
new file mode 100644
index 0000000000..263fd13e55
--- /dev/null
+++ b/toolkit/components/crashmonitor/test/unit/xpcshell.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+head = head.js
+skip-if = toolkit == 'android'
+
+[test_init.js]
+[test_valid_file.js]
+[test_invalid_file.js]
+[test_invalid_json.js]
+[test_missing_file.js]
+[test_register.js]