summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_breakpoint-actor-map.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/server/tests/xpcshell/test_breakpoint-actor-map.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/xpcshell/test_breakpoint-actor-map.js')
-rw-r--r--devtools/server/tests/xpcshell/test_breakpoint-actor-map.js257
1 files changed, 257 insertions, 0 deletions
diff --git a/devtools/server/tests/xpcshell/test_breakpoint-actor-map.js b/devtools/server/tests/xpcshell/test_breakpoint-actor-map.js
new file mode 100644
index 0000000000..e45096095e
--- /dev/null
+++ b/devtools/server/tests/xpcshell/test_breakpoint-actor-map.js
@@ -0,0 +1,257 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test the functionality of the BreakpointActorMap object.
+
+const {
+ BreakpointActorMap,
+} = require("resource://devtools/server/actors/utils/breakpoint-actor-map.js");
+
+function run_test() {
+ test_get_actor();
+ test_set_actor();
+ test_delete_actor();
+ test_find_actors();
+ test_duplicate_actors();
+}
+
+function test_get_actor() {
+ const bpStore = new BreakpointActorMap();
+ const location = {
+ generatedSourceActor: { actor: "actor1" },
+ generatedLine: 3,
+ };
+ const columnLocation = {
+ generatedSourceActor: { actor: "actor2" },
+ generatedLine: 5,
+ generatedColumn: 15,
+ };
+
+ // Shouldn't have breakpoint
+ Assert.equal(
+ null,
+ bpStore.getActor(location),
+ "Breakpoint not added and shouldn't exist."
+ );
+
+ bpStore.setActor(location, {});
+ Assert.ok(
+ !!bpStore.getActor(location),
+ "Breakpoint added but not found in Breakpoint Store."
+ );
+
+ bpStore.deleteActor(location);
+ Assert.equal(
+ null,
+ bpStore.getActor(location),
+ "Breakpoint removed but still exists."
+ );
+
+ // Same checks for breakpoint with a column
+ Assert.equal(
+ null,
+ bpStore.getActor(columnLocation),
+ "Breakpoint with column not added and shouldn't exist."
+ );
+
+ bpStore.setActor(columnLocation, {});
+ Assert.ok(
+ !!bpStore.getActor(columnLocation),
+ "Breakpoint with column added but not found in Breakpoint Store."
+ );
+
+ bpStore.deleteActor(columnLocation);
+ Assert.equal(
+ null,
+ bpStore.getActor(columnLocation),
+ "Breakpoint with column removed but still exists in Breakpoint Store."
+ );
+}
+
+function test_set_actor() {
+ // Breakpoint with column
+ const bpStore = new BreakpointActorMap();
+ let location = {
+ generatedSourceActor: { actor: "actor1" },
+ generatedLine: 10,
+ generatedColumn: 9,
+ };
+ bpStore.setActor(location, {});
+ Assert.ok(
+ !!bpStore.getActor(location),
+ "We should have the column breakpoint we just added"
+ );
+
+ // Breakpoint without column (whole line breakpoint)
+ location = {
+ generatedSourceActor: { actor: "actor2" },
+ generatedLine: 103,
+ };
+ bpStore.setActor(location, {});
+ Assert.ok(
+ !!bpStore.getActor(location),
+ "We should have the whole line breakpoint we just added"
+ );
+}
+
+function test_delete_actor() {
+ // Breakpoint with column
+ const bpStore = new BreakpointActorMap();
+ let location = {
+ generatedSourceActor: { actor: "actor1" },
+ generatedLine: 10,
+ generatedColumn: 9,
+ };
+ bpStore.setActor(location, {});
+ bpStore.deleteActor(location);
+ Assert.equal(
+ bpStore.getActor(location),
+ null,
+ "We should not have the column breakpoint anymore"
+ );
+
+ // Breakpoint without column (whole line breakpoint)
+ location = {
+ generatedSourceActor: { actor: "actor2" },
+ generatedLine: 103,
+ };
+ bpStore.setActor(location, {});
+ bpStore.deleteActor(location);
+ Assert.equal(
+ bpStore.getActor(location),
+ null,
+ "We should not have the whole line breakpoint anymore"
+ );
+}
+
+function test_find_actors() {
+ const bps = [
+ { generatedSourceActor: { actor: "actor1" }, generatedLine: 10 },
+ {
+ generatedSourceActor: { actor: "actor1" },
+ generatedLine: 10,
+ generatedColumn: 3,
+ },
+ {
+ generatedSourceActor: { actor: "actor1" },
+ generatedLine: 10,
+ generatedColumn: 10,
+ },
+ {
+ generatedSourceActor: { actor: "actor1" },
+ generatedLine: 23,
+ generatedColumn: 89,
+ },
+ {
+ generatedSourceActor: { actor: "actor2" },
+ generatedLine: 10,
+ generatedColumn: 1,
+ },
+ {
+ generatedSourceActor: { actor: "actor2" },
+ generatedLine: 20,
+ generatedColumn: 5,
+ },
+ {
+ generatedSourceActor: { actor: "actor2" },
+ generatedLine: 30,
+ generatedColumn: 34,
+ },
+ {
+ generatedSourceActor: { actor: "actor2" },
+ generatedLine: 40,
+ generatedColumn: 56,
+ },
+ ];
+
+ const bpStore = new BreakpointActorMap();
+
+ for (const bp of bps) {
+ bpStore.setActor(bp, bp);
+ }
+
+ // All breakpoints
+
+ let bpSet = new Set(bps);
+ for (const bp of bpStore.findActors()) {
+ bpSet.delete(bp);
+ }
+ Assert.equal(bpSet.size, 0, "Should be able to iterate over all breakpoints");
+
+ // Breakpoints by URL
+
+ bpSet = new Set(
+ bps.filter(bp => {
+ return bp.generatedSourceActor.actorID === "actor1";
+ })
+ );
+ for (const bp of bpStore.findActors({
+ generatedSourceActor: { actorID: "actor1" },
+ })) {
+ bpSet.delete(bp);
+ }
+ Assert.equal(bpSet.size, 0, "Should be able to filter the iteration by url");
+
+ // Breakpoints by URL and line
+
+ bpSet = new Set(
+ bps.filter(bp => {
+ return (
+ bp.generatedSourceActor.actorID === "actor1" && bp.generatedLine === 10
+ );
+ })
+ );
+ let first = true;
+ for (const bp of bpStore.findActors({
+ generatedSourceActor: { actorID: "actor1" },
+ generatedLine: 10,
+ })) {
+ if (first) {
+ Assert.equal(
+ bp.generatedColumn,
+ undefined,
+ "Should always get the whole line breakpoint first"
+ );
+ first = false;
+ } else {
+ Assert.notEqual(
+ bp.generatedColumn,
+ undefined,
+ "Should not get the whole line breakpoint any time other than first."
+ );
+ }
+ bpSet.delete(bp);
+ }
+ Assert.equal(
+ bpSet.size,
+ 0,
+ "Should be able to filter the iteration by url and line"
+ );
+}
+
+function test_duplicate_actors() {
+ const bpStore = new BreakpointActorMap();
+
+ // Breakpoint with column
+ let location = {
+ generatedSourceActor: { actorID: "foo-actor" },
+ generatedLine: 10,
+ generatedColumn: 9,
+ };
+ bpStore.setActor(location, {});
+ bpStore.setActor(location, {});
+ Assert.equal(bpStore.size, 1, "We should have only 1 column breakpoint");
+ bpStore.deleteActor(location);
+
+ // Breakpoint without column (whole line breakpoint)
+ location = {
+ generatedSourceActor: { actorID: "foo-actor" },
+ generatedLine: 15,
+ };
+ bpStore.setActor(location, {});
+ bpStore.setActor(location, {});
+ Assert.equal(bpStore.size, 1, "We should have only 1 whole line breakpoint");
+ bpStore.deleteActor(location);
+}