2012-08-06 13:32:00 +04:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2016-06-04 01:20:45 +03:00
|
|
|
"use strict";
|
2012-08-06 13:32:00 +04:00
|
|
|
|
2016-06-04 01:20:45 +03:00
|
|
|
// Test the functionality of the BreakpointActorMap object.
|
2014-05-15 18:36:03 +04:00
|
|
|
|
2018-02-02 11:57:00 +03:00
|
|
|
const {
|
|
|
|
BreakpointActorMap,
|
|
|
|
} = require("devtools/server/actors/utils/breakpoint-actor-map");
|
2012-08-06 13:32:00 +04:00
|
|
|
|
2016-06-04 01:20:45 +03:00
|
|
|
function run_test() {
|
2014-12-10 18:33:37 +03:00
|
|
|
test_get_actor();
|
|
|
|
test_set_actor();
|
|
|
|
test_delete_actor();
|
|
|
|
test_find_actors();
|
|
|
|
test_duplicate_actors();
|
2013-07-30 02:52:35 +04:00
|
|
|
}
|
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
function test_get_actor() {
|
2018-06-01 13:36:09 +03:00
|
|
|
const bpStore = new BreakpointActorMap();
|
|
|
|
const location = {
|
2018-12-15 02:31:14 +03:00
|
|
|
generatedSourceActor: { actor: "actor1" },
|
|
|
|
generatedLine: 3,
|
2013-07-31 06:34:10 +04:00
|
|
|
};
|
2018-06-01 13:36:09 +03:00
|
|
|
const columnLocation = {
|
2018-12-15 02:31:14 +03:00
|
|
|
generatedSourceActor: { actor: "actor2" },
|
|
|
|
generatedLine: 5,
|
|
|
|
generatedColumn: 15,
|
2013-07-31 06:34:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Shouldn't have breakpoint
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(
|
|
|
|
null,
|
|
|
|
bpStore.getActor(location),
|
|
|
|
"Breakpoint not added and shouldn't exist."
|
|
|
|
);
|
2013-07-31 06:34:10 +04:00
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(location, {});
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(
|
|
|
|
!!bpStore.getActor(location),
|
|
|
|
"Breakpoint added but not found in Breakpoint Store."
|
|
|
|
);
|
2013-07-31 06:34:10 +04:00
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.deleteActor(location);
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(
|
|
|
|
null,
|
|
|
|
bpStore.getActor(location),
|
|
|
|
"Breakpoint removed but still exists."
|
|
|
|
);
|
2013-07-31 06:34:10 +04:00
|
|
|
|
|
|
|
// Same checks for breakpoint with a column
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(
|
|
|
|
null,
|
|
|
|
bpStore.getActor(columnLocation),
|
|
|
|
"Breakpoint with column not added and shouldn't exist."
|
|
|
|
);
|
2013-07-31 06:34:10 +04:00
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(columnLocation, {});
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(
|
|
|
|
!!bpStore.getActor(columnLocation),
|
|
|
|
"Breakpoint with column added but not found in Breakpoint Store."
|
|
|
|
);
|
2013-07-31 06:34:10 +04:00
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.deleteActor(columnLocation);
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(
|
|
|
|
null,
|
|
|
|
bpStore.getActor(columnLocation),
|
|
|
|
"Breakpoint with column removed but still exists in Breakpoint Store."
|
|
|
|
);
|
2013-07-31 06:34:10 +04:00
|
|
|
}
|
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
function test_set_actor() {
|
2013-07-30 02:52:35 +04:00
|
|
|
// Breakpoint with column
|
2018-06-01 13:36:09 +03:00
|
|
|
const bpStore = new BreakpointActorMap();
|
2013-07-30 02:52:35 +04:00
|
|
|
let location = {
|
2018-12-15 02:31:14 +03:00
|
|
|
generatedSourceActor: { actor: "actor1" },
|
|
|
|
generatedLine: 10,
|
|
|
|
generatedColumn: 9,
|
2013-07-30 02:52:35 +04:00
|
|
|
};
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(location, {});
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(
|
|
|
|
!!bpStore.getActor(location),
|
|
|
|
"We should have the column breakpoint we just added"
|
|
|
|
);
|
2013-07-30 02:52:35 +04:00
|
|
|
|
|
|
|
// Breakpoint without column (whole line breakpoint)
|
|
|
|
location = {
|
2018-12-15 02:31:14 +03:00
|
|
|
generatedSourceActor: { actor: "actor2" },
|
|
|
|
generatedLine: 103,
|
2013-07-30 02:52:35 +04:00
|
|
|
};
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(location, {});
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(
|
|
|
|
!!bpStore.getActor(location),
|
|
|
|
"We should have the whole line breakpoint we just added"
|
|
|
|
);
|
2013-07-30 02:52:35 +04:00
|
|
|
}
|
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
function test_delete_actor() {
|
2013-07-30 02:52:35 +04:00
|
|
|
// Breakpoint with column
|
2018-06-01 13:36:09 +03:00
|
|
|
const bpStore = new BreakpointActorMap();
|
2013-07-30 02:52:35 +04:00
|
|
|
let location = {
|
2018-12-15 02:31:14 +03:00
|
|
|
generatedSourceActor: { actor: "actor1" },
|
|
|
|
generatedLine: 10,
|
|
|
|
generatedColumn: 9,
|
2013-07-30 02:52:35 +04:00
|
|
|
};
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(location, {});
|
|
|
|
bpStore.deleteActor(location);
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(
|
|
|
|
bpStore.getActor(location),
|
|
|
|
null,
|
|
|
|
"We should not have the column breakpoint anymore"
|
|
|
|
);
|
2013-07-30 02:52:35 +04:00
|
|
|
|
|
|
|
// Breakpoint without column (whole line breakpoint)
|
|
|
|
location = {
|
2018-12-15 02:31:14 +03:00
|
|
|
generatedSourceActor: { actor: "actor2" },
|
|
|
|
generatedLine: 103,
|
2013-07-30 02:52:35 +04:00
|
|
|
};
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(location, {});
|
|
|
|
bpStore.deleteActor(location);
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(
|
|
|
|
bpStore.getActor(location),
|
|
|
|
null,
|
|
|
|
"We should not have the whole line breakpoint anymore"
|
|
|
|
);
|
2013-07-30 02:52:35 +04:00
|
|
|
}
|
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
function test_find_actors() {
|
2018-06-01 13:36:09 +03:00
|
|
|
const bps = [
|
2018-12-15 02:31:14 +03:00
|
|
|
{ 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,
|
2019-07-05 12:26:00 +03:00
|
|
|
},
|
2013-07-30 02:52:35 +04:00
|
|
|
];
|
|
|
|
|
2018-06-01 13:36:09 +03:00
|
|
|
const bpStore = new BreakpointActorMap();
|
2013-07-30 02:52:35 +04:00
|
|
|
|
2018-06-01 13:36:09 +03:00
|
|
|
for (const bp of bps) {
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(bp, bp);
|
2013-07-30 02:52:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// All breakpoints
|
|
|
|
|
2015-02-04 18:59:15 +03:00
|
|
|
let bpSet = new Set(bps);
|
2018-06-01 13:36:09 +03:00
|
|
|
for (const bp of bpStore.findActors()) {
|
2013-07-30 02:52:35 +04:00
|
|
|
bpSet.delete(bp);
|
|
|
|
}
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(bpSet.size, 0, "Should be able to iterate over all breakpoints");
|
2013-07-30 02:52:35 +04:00
|
|
|
|
|
|
|
// Breakpoints by URL
|
|
|
|
|
2017-03-18 14:26:05 +03:00
|
|
|
bpSet = new Set(
|
|
|
|
bps.filter(bp => {
|
2018-12-15 02:31:14 +03:00
|
|
|
return bp.generatedSourceActor.actorID === "actor1";
|
2017-03-18 14:26:05 +03:00
|
|
|
})
|
|
|
|
);
|
2018-12-15 02:31:14 +03:00
|
|
|
for (const bp of bpStore.findActors({
|
|
|
|
generatedSourceActor: { actorID: "actor1" },
|
|
|
|
})) {
|
2013-07-30 02:52:35 +04:00
|
|
|
bpSet.delete(bp);
|
|
|
|
}
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(bpSet.size, 0, "Should be able to filter the iteration by url");
|
2013-07-30 02:52:35 +04:00
|
|
|
|
|
|
|
// Breakpoints by URL and line
|
|
|
|
|
2017-03-18 14:26:05 +03:00
|
|
|
bpSet = new Set(
|
|
|
|
bps.filter(bp => {
|
2018-12-15 02:31:14 +03:00
|
|
|
return (
|
|
|
|
bp.generatedSourceActor.actorID === "actor1" && bp.generatedLine === 10
|
2017-03-18 14:26:05 +03:00
|
|
|
);
|
|
|
|
})
|
2019-07-05 12:26:00 +03:00
|
|
|
);
|
2013-07-30 02:52:35 +04:00
|
|
|
let first = true;
|
2018-12-15 02:31:14 +03:00
|
|
|
for (const bp of bpStore.findActors({
|
|
|
|
generatedSourceActor: { actorID: "actor1" },
|
|
|
|
generatedLine: 10,
|
|
|
|
})) {
|
2013-07-30 02:52:35 +04:00
|
|
|
if (first) {
|
2018-12-15 02:31:14 +03:00
|
|
|
Assert.equal(
|
|
|
|
bp.generatedColumn,
|
|
|
|
undefined,
|
2017-12-21 13:08:17 +03:00
|
|
|
"Should always get the whole line breakpoint first"
|
|
|
|
);
|
2013-07-30 02:52:35 +04:00
|
|
|
first = false;
|
|
|
|
} else {
|
2018-12-15 02:31:14 +03:00
|
|
|
Assert.notEqual(
|
|
|
|
bp.generatedColumn,
|
|
|
|
undefined,
|
2017-12-21 13:08:19 +03:00
|
|
|
"Should not get the whole line breakpoint any time other than first."
|
|
|
|
);
|
2013-07-30 02:52:35 +04:00
|
|
|
}
|
|
|
|
bpSet.delete(bp);
|
|
|
|
}
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(
|
|
|
|
bpSet.size,
|
|
|
|
0,
|
|
|
|
"Should be able to filter the iteration by url and line"
|
|
|
|
);
|
2012-08-06 13:32:00 +04:00
|
|
|
}
|
2014-07-17 01:56:01 +04:00
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
function test_duplicate_actors() {
|
2018-06-01 13:36:09 +03:00
|
|
|
const bpStore = new BreakpointActorMap();
|
2014-07-17 01:56:01 +04:00
|
|
|
|
|
|
|
// Breakpoint with column
|
|
|
|
let location = {
|
2018-12-15 02:31:14 +03:00
|
|
|
generatedSourceActor: { actorID: "foo-actor" },
|
|
|
|
generatedLine: 10,
|
|
|
|
generatedColumn: 9,
|
2014-07-17 01:56:01 +04:00
|
|
|
};
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(location, {});
|
|
|
|
bpStore.setActor(location, {});
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(bpStore.size, 1, "We should have only 1 column breakpoint");
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.deleteActor(location);
|
2014-07-17 01:56:01 +04:00
|
|
|
|
|
|
|
// Breakpoint without column (whole line breakpoint)
|
|
|
|
location = {
|
2018-12-15 02:31:14 +03:00
|
|
|
generatedSourceActor: { actorID: "foo-actor" },
|
|
|
|
generatedLine: 15,
|
2014-07-17 01:56:01 +04:00
|
|
|
};
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.setActor(location, {});
|
|
|
|
bpStore.setActor(location, {});
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(bpStore.size, 1, "We should have only 1 whole line breakpoint");
|
2014-12-10 18:33:37 +03:00
|
|
|
bpStore.deleteActor(location);
|
2014-07-17 01:56:01 +04:00
|
|
|
}
|