2014-06-25 09:12:07 +04:00
|
|
|
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
|
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
|
|
|
|
2016-06-04 01:20:45 +03:00
|
|
|
const { BreakpointActorMap } = require("devtools/server/actors/script");
|
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() {
|
|
|
|
let bpStore = new BreakpointActorMap();
|
2013-07-31 06:34:10 +04:00
|
|
|
let location = {
|
2016-05-17 21:25:54 +03:00
|
|
|
originalSourceActor: { actor: "actor1" },
|
2015-02-23 18:14:57 +03:00
|
|
|
originalLine: 3
|
2013-07-31 06:34:10 +04:00
|
|
|
};
|
|
|
|
let columnLocation = {
|
2016-05-17 21:25:54 +03:00
|
|
|
originalSourceActor: { actor: "actor2" },
|
2015-02-23 18:14:57 +03:00
|
|
|
originalLine: 5,
|
|
|
|
originalColumn: 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
|
2014-12-10 18:33:37 +03:00
|
|
|
let bpStore = new BreakpointActorMap();
|
2013-07-30 02:52:35 +04:00
|
|
|
let location = {
|
2016-05-17 21:25:54 +03:00
|
|
|
originalSourceActor: { actor: "actor1" },
|
2015-02-23 18:14:57 +03:00
|
|
|
originalLine: 10,
|
|
|
|
originalColumn: 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 = {
|
2016-05-17 21:25:54 +03:00
|
|
|
originalSourceActor: { actor: "actor2" },
|
2015-02-23 18:14:57 +03:00
|
|
|
originalLine: 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
|
2014-12-10 18:33:37 +03:00
|
|
|
let bpStore = new BreakpointActorMap();
|
2013-07-30 02:52:35 +04:00
|
|
|
let location = {
|
2016-05-17 21:25:54 +03:00
|
|
|
originalSourceActor: { actor: "actor1" },
|
2015-02-23 18:14:57 +03:00
|
|
|
originalLine: 10,
|
|
|
|
originalColumn: 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 = {
|
2016-05-17 21:25:54 +03:00
|
|
|
originalSourceActor: { actor: "actor2" },
|
2015-02-23 18:14:57 +03:00
|
|
|
originalLine: 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() {
|
2013-07-30 02:52:35 +04:00
|
|
|
let bps = [
|
2015-02-23 18:14:57 +03:00
|
|
|
{ originalSourceActor: { actor: "actor1" }, originalLine: 10 },
|
|
|
|
{ originalSourceActor: { actor: "actor1" }, originalLine: 10, originalColumn: 3 },
|
|
|
|
{ originalSourceActor: { actor: "actor1" }, originalLine: 10, originalColumn: 10 },
|
|
|
|
{ originalSourceActor: { actor: "actor1" }, originalLine: 23, originalColumn: 89 },
|
|
|
|
{ originalSourceActor: { actor: "actor2" }, originalLine: 10, originalColumn: 1 },
|
|
|
|
{ originalSourceActor: { actor: "actor2" }, originalLine: 20, originalColumn: 5 },
|
|
|
|
{ originalSourceActor: { actor: "actor2" }, originalLine: 30, originalColumn: 34 },
|
|
|
|
{ originalSourceActor: { actor: "actor2" }, originalLine: 40, originalColumn: 56 }
|
2013-07-30 02:52:35 +04:00
|
|
|
];
|
|
|
|
|
2014-12-10 18:33:37 +03:00
|
|
|
let bpStore = new BreakpointActorMap();
|
2013-07-30 02:52:35 +04:00
|
|
|
|
|
|
|
for (let 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);
|
2014-12-10 18:33:37 +03:00
|
|
|
for (let 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 => {
|
|
|
|
return bp.originalSourceActor.actorID === "actor1";
|
|
|
|
}));
|
2015-02-23 18:14:57 +03:00
|
|
|
for (let bp of bpStore.findActors({ originalSourceActor: { 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 => {
|
|
|
|
return bp.originalSourceActor.actorID === "actor1" && bp.originalLine === 10;
|
|
|
|
}));
|
2013-07-30 02:52:35 +04:00
|
|
|
let first = true;
|
2017-03-18 14:26:05 +03:00
|
|
|
for (let bp of bpStore.findActors({ originalSourceActor: { actorID: "actor1" },
|
|
|
|
originalLine: 10 })) {
|
2013-07-30 02:52:35 +04:00
|
|
|
if (first) {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(bp.originalColumn, undefined,
|
|
|
|
"Should always get the whole line breakpoint first");
|
2013-07-30 02:52:35 +04:00
|
|
|
first = false;
|
|
|
|
} else {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.notEqual(bp.originalColumn, 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() {
|
|
|
|
let bpStore = new BreakpointActorMap();
|
2014-07-17 01:56:01 +04:00
|
|
|
|
|
|
|
// Breakpoint with column
|
|
|
|
let location = {
|
2015-02-23 18:14:57 +03:00
|
|
|
originalSourceActor: { actorID: "foo-actor" },
|
|
|
|
originalLine: 10,
|
|
|
|
originalColumn: 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 = {
|
2015-02-23 18:14:57 +03:00
|
|
|
originalSourceActor: { actorID: "foo-actor" },
|
|
|
|
originalLine: 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
|
|
|
}
|