blob: 390b3dd98098e99f1b1bdd998d36b2aed3ecff69 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
<script>
function createScripts(id) {
eval(
`
window.${id}_Inner = function ${id}_Inner(x) {
return x + 42;
};
//# sourceURL=${id}_Inner.js
`
);
eval(
`
window.${id}_Middle = function ${id}_Middle(x) {
return ${id}_Inner(x);
};
//# sourceURL=${id}_Middle.js
`
);
eval(
`
window.${id}_Outer = function ${id}_Outer(x) {
return ${id}_Middle(x);
};
//# sourceURL=${id}_Outer.js
`
);
}
function test()
{
let suite = ProtocolTest.createAsyncSuite("Debugger.setShouldBlackboxURL");
let sourceURLRegExpQueries = new Map;
let pausedFunctionNames = [];
let resumeCallback = null;
InspectorProtocol.sendCommand("Debugger.enable", {});
InspectorProtocol.sendCommand("Debugger.setBreakpointsActive", {active: true});
InspectorProtocol.eventHandler["Debugger.scriptParsed"] = function(message) {
let sourceURL = message.params.sourceURL;
for (let [regExp, callback] of sourceURLRegExpQueries) {
if (regExp.test(sourceURL)) {
sourceURLRegExpQueries.delete(regExp);
callback(sourceURL);
}
};
};
InspectorProtocol.eventHandler["Debugger.paused"] = function(message) {
ProtocolTest.newline();
let topCallFrame = message.params.callFrames[0];
let functionName = topCallFrame.functionName;
if (functionName === "global code") {
ProtocolTest.log("Resuming...");
InspectorProtocol.sendCommand(`Debugger.resume`, {}, InspectorProtocol.checkForError);
return;
}
ProtocolTest.log(`PAUSED: '${message.params.reason}' at '${functionName}:${topCallFrame.location.lineNumber}:${topCallFrame.location.columnNumber}'.`);
if (message.params.data)
ProtocolTest.json(message.params.data);
pausedFunctionNames.push(functionName);
ProtocolTest.log("Stepping over...");
InspectorProtocol.sendCommand(`Debugger.stepOver`, {}, InspectorProtocol.checkForError);
};
InspectorProtocol.eventHandler["Debugger.resumed"] = function(message) {
ProtocolTest.pass("Resumed.");
resumeCallback();
};
async function setBlackbox(url, options = {}) {
if (!options.caseSensitive)
url = url.toLowerCase();
ProtocolTest.log(`Blackboxing ${options.caseSensitive ? "(case sensitive) " : ""}${options.isRegex ? "(regex) " : ""}'${url}'...`);
await InspectorProtocol.awaitCommand({
method: "Debugger.setShouldBlackboxURL",
params: {url, shouldBlackbox: true, ...options},
});
}
async function setBreakpoint(url, lineNumber) {
ProtocolTest.log(`Setting breakpoint in '${url}'...`);
await InspectorProtocol.awaitCommand({
method: "Debugger.setBreakpointByUrl",
params: {url, lineNumber},
});
}
async function listenForSourceParsed(sourceURLRegExp) {
return new Promise((resolve, reject) => {
sourceURLRegExpQueries.set(sourceURLRegExp, resolve);
});
}
async function evaluate(expression) {
ProtocolTest.log(`Evaluating '${expression}'...`);
return InspectorProtocol.awaitCommand({
method: "Runtime.evaluate",
params: {expression},
});
}
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.String.stepOver",
description: "Check that stepping through a blackboxed script doesn't pause.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("String_StepOver_Middle"), "Should not pause in 'String_StepOver_Middle'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/String_StepOver_Inner\.js$/),
listenForSourceParsed(/String_StepOver_Middle\.js$/),
listenForSourceParsed(/String_StepOver_Outer\.js$/),
evaluate(`createScripts("String_StepOver")`),
]);
await setBlackbox(middleSourceURL);
await setBreakpoint(innerSourceURL, 3); // last line of function, so it only pauses once
await evaluate(`String_StepOver_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.String.PauseInCaller",
description: "Check that the debugger will pause in the caller if a breakpoint is set in a blackboxed script.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("String_PauseInCaller_Inner"), "Should not pause in 'String_PauseInCaller_Inner'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/String_PauseInCaller_Inner\.js$/),
listenForSourceParsed(/String_PauseInCaller_Middle\.js$/),
listenForSourceParsed(/String_PauseInCaller_Outer\.js$/),
evaluate(`createScripts("String_PauseInCaller")`),
]);
await setBlackbox(innerSourceURL);
await setBreakpoint(innerSourceURL, 2);
await evaluate(`String_PauseInCaller_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.String.PauseInCallee",
description: "Check that the debugger will pause in the callee if a breakpoint is set in a blackboxed script.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("String_PauseInCallee_Outer"), "Should not pause in 'String_PauseInCallee_Outer'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/String_PauseInCallee_Inner\.js$/),
listenForSourceParsed(/String_PauseInCallee_Middle\.js$/),
listenForSourceParsed(/String_PauseInCallee_Outer\.js$/),
evaluate(`createScripts("String_PauseInCallee")`),
]);
await setBlackbox(outerSourceURL);
await setBreakpoint(outerSourceURL, 2);
await evaluate(`String_PauseInCallee_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.CaseSensitiveString.stepOver",
description: "Check that stepping through a blackboxed script doesn't pause.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(pausedFunctionNames.includes("CaseSensitiveString_StepOver_Inner"), "Should pause in 'CaseSensitiveString_StepOver_Inner'.");
ProtocolTest.expectThat(!pausedFunctionNames.includes("CaseSensitiveString_StepOver_Middle"), "Should not pause in 'CaseSensitiveString_StepOver_Middle'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/CaseSensitiveString_StepOver_Inner\.js$/),
listenForSourceParsed(/CaseSensitiveString_StepOver_Middle\.js$/),
listenForSourceParsed(/CaseSensitiveString_StepOver_Outer\.js$/),
evaluate(`createScripts("CaseSensitiveString_StepOver")`),
]);
await setBlackbox(innerSourceURL.toLowerCase(), {caseSensitive: true});
await setBlackbox(middleSourceURL, {caseSensitive: true});
await setBreakpoint(innerSourceURL, 3); // last line of function, so it only pauses once
await evaluate(`CaseSensitiveString_StepOver_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.CaseSensitiveString.PauseInCaller",
description: "Check that the debugger will pause in the caller if a breakpoint is set in a blackboxed script.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("CaseSensitiveString_PauseInCaller_Inner"), "Should not pause in 'CaseSensitiveString_PauseInCaller_Inner'.");
ProtocolTest.expectThat(pausedFunctionNames.includes("CaseSensitiveString_PauseInCaller_Middle"), "Should pause in 'CaseSensitiveString_PauseInCaller_Middle'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/CaseSensitiveString_PauseInCaller_Inner\.js$/),
listenForSourceParsed(/CaseSensitiveString_PauseInCaller_Middle\.js$/),
listenForSourceParsed(/CaseSensitiveString_PauseInCaller_Outer\.js$/),
evaluate(`createScripts("CaseSensitiveString_PauseInCaller")`),
]);
await setBlackbox(innerSourceURL, {caseSensitive: true});
await setBlackbox(middleSourceURL.toLowerCase(), {caseSensitive: true});
await setBreakpoint(innerSourceURL, 2);
await evaluate(`CaseSensitiveString_PauseInCaller_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.CaseSensitiveString.PauseInCallee",
description: "Check that the debugger will pause in the callee if a breakpoint is set in a blackboxed script.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(pausedFunctionNames.includes("CaseSensitiveString_PauseInCallee_Middle"), "Should pause in 'CaseSensitiveString_PauseInCallee_Middle'.");
ProtocolTest.expectThat(!pausedFunctionNames.includes("CaseSensitiveString_PauseInCallee_Outer"), "Should not pause in 'CaseSensitiveString_PauseInCallee_Outer'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/CaseSensitiveString_PauseInCallee_Inner\.js$/),
listenForSourceParsed(/CaseSensitiveString_PauseInCallee_Middle\.js$/),
listenForSourceParsed(/CaseSensitiveString_PauseInCallee_Outer\.js$/),
evaluate(`createScripts("CaseSensitiveString_PauseInCallee")`),
]);
await setBlackbox(middleSourceURL.toLowerCase(), {caseSensitive: true});
await setBlackbox(outerSourceURL, {caseSensitive: true});
await setBreakpoint(outerSourceURL, 2);
await evaluate(`CaseSensitiveString_PauseInCallee_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.Regex.stepOver",
description: "Check that stepping through a blackboxed script doesn't pause.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("Regex_StepOver_Middle"), "Should not pause in 'Regex_StepOver_Middle'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/Regex_StepOver_Inner\.js$/),
listenForSourceParsed(/Regex_StepOver_Middle\.js$/),
listenForSourceParsed(/Regex_StepOver_Outer\.js$/),
evaluate(`createScripts("Regex_StepOver")`),
]);
await setBlackbox("Regex[ -_]StepOver[ -_]Middle\\.js$", {isRegex: true});
await setBreakpoint(innerSourceURL, 3); // last line of function, so it only pauses once
await evaluate(`Regex_StepOver_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.Regex.PauseInCaller",
description: "Check that the debugger will pause in the caller if a breakpoint is set in a blackboxed script.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("Regex_PauseInCaller_Inner"), "Should not pause in 'Regex_PauseInCaller_Inner'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/Regex_PauseInCaller_Inner\.js$/),
listenForSourceParsed(/Regex_PauseInCaller_Middle\.js$/),
listenForSourceParsed(/Regex_PauseInCaller_Outer\.js$/),
evaluate(`createScripts("Regex_PauseInCaller")`),
]);
await setBlackbox("Regex[ -_]PauseInCaller[ -_]Inner\\.js$", {isRegex: true});
await setBreakpoint(innerSourceURL, 2);
await evaluate(`Regex_PauseInCaller_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.Regex.PauseInCallee",
description: "Check that the debugger will pause in the callee if a breakpoint is set in a blackboxed script.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("Regex_PauseInCallee_Outer"), "Should not pause in 'Regex_PauseInCallee_Outer'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/Regex_PauseInCallee_Inner\.js$/),
listenForSourceParsed(/Regex_PauseInCallee_Middle\.js$/),
listenForSourceParsed(/Regex_PauseInCallee_Outer\.js$/),
evaluate(`createScripts("Regex_PauseInCallee")`),
]);
await setBlackbox("Regex[ -_]PauseInCallee[ -_]Outer\\.js$", {isRegex: true});
await setBreakpoint(outerSourceURL, 2);
await evaluate(`Regex_PauseInCallee_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.CaseSensitiveRegex.stepOver",
description: "Check that stepping through a blackboxed script doesn't pause.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(pausedFunctionNames.includes("CaseSensitiveRegex_StepOver_Inner"), "Should pause in 'CaseSensitiveRegex_StepOver_Inner'.");
ProtocolTest.expectThat(!pausedFunctionNames.includes("CaseSensitiveRegex_StepOver_Middle"), "Should not pause in 'CaseSensitiveRegex_StepOver_Middle'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/CaseSensitiveRegex_StepOver_Inner\.js$/),
listenForSourceParsed(/CaseSensitiveRegex_StepOver_Middle\.js$/),
listenForSourceParsed(/CaseSensitiveRegex_StepOver_Outer\.js$/),
evaluate(`createScripts("CaseSensitiveRegex_StepOver")`),
]);
await setBlackbox("casesensitiveregex_stepover_inner\\.js$", {caseSensitive: true, isRegex: true});
await setBlackbox("CaseSensitiveRegex_StepOver_Middle\\.js$", {caseSensitive: true, isRegex: true});
await setBreakpoint(innerSourceURL, 3); // last line of function, so it only pauses once
await evaluate(`CaseSensitiveRegex_StepOver_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.CaseSensitiveRegex.PauseInCaller",
description: "Check that the debugger will pause in the caller if a breakpoint is set in a blackboxed script.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("CaseSensitiveRegex_PauseInCaller_Inner"), "Should not pause in 'CaseSensitiveRegex_PauseInCaller_Inner'.");
ProtocolTest.expectThat(pausedFunctionNames.includes("CaseSensitiveRegex_PauseInCaller_Middle"), "Should pause in 'CaseSensitiveRegex_PauseInCaller_Middle'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/CaseSensitiveRegex_PauseInCaller_Inner\.js$/),
listenForSourceParsed(/CaseSensitiveRegex_PauseInCaller_Middle\.js$/),
listenForSourceParsed(/CaseSensitiveRegex_PauseInCaller_Outer\.js$/),
evaluate(`createScripts("CaseSensitiveRegex_PauseInCaller")`),
]);
await setBlackbox("casesensitiveregex_pauseincaller_inner\\.js$", {caseSensitive: true, isRegex: true});
await setBlackbox("CaseSensitiveRegex_PauseInCaller_middle\\.js$", {caseSensitive: true, isRegex: true});
await setBreakpoint(innerSourceURL, 2);
await evaluate(`CaseSensitiveRegex_PauseInCaller_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.CaseSensitiveRegex.PauseInCallee",
description: "Check that the debugger will pause in the callee if a breakpoint is set in a blackboxed script.",
async test() {
let resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(pausedFunctionNames.includes("CaseSensitiveRegex_PauseInCallee_Middle"), "Should pause in 'CaseSensitiveRegex_PauseInCallee_Middle'.");
ProtocolTest.expectThat(!pausedFunctionNames.includes("CaseSensitiveRegex_PauseInCallee_Outer"), "Should not pause in 'CaseSensitiveRegex_PauseInCallee_Outer'.");
resolve();
};
});
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/CaseSensitiveRegex_PauseInCallee_Inner\.js$/),
listenForSourceParsed(/CaseSensitiveRegex_PauseInCallee_Middle\.js$/),
listenForSourceParsed(/CaseSensitiveRegex_PauseInCallee_Outer\.js$/),
evaluate(`createScripts("CaseSensitiveRegex_PauseInCallee")`),
]);
await setBlackbox("casesensitiveregex_pauseincallee_middle\\.js$", {caseSensitive: true, isRegex: true});
await setBlackbox("CaseSensitiveRegex_PauseInCallee_Outer\\.js$", {caseSensitive: true, isRegex: true});
await setBreakpoint(outerSourceURL, 2);
await evaluate(`CaseSensitiveRegex_PauseInCallee_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.Toggle",
description: "Check that the URL does not remain blackboxed if it's blackboxed state is toggled on and then off.",
async test() {
let resumePromise = null;
let [innerSourceURL, middleSourceURL, outerSourceURL] = await Promise.all([
listenForSourceParsed(/Toggle_Inner\.js$/),
listenForSourceParsed(/Toggle_Middle\.js$/),
listenForSourceParsed(/Toggle_Outer\.js$/),
evaluate(`createScripts("Toggle")`),
]);
await setBreakpoint(innerSourceURL, 3); // last line of function, so it only pauses once
ProtocolTest.newline();
resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(!pausedFunctionNames.includes("Toggle_Middle"), "Should not pause in 'Toggle_Middle'.");
resolve();
};
});
await setBlackbox(middleSourceURL);
await evaluate(`Toggle_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
resumePromise = new Promise((resolve, reject) => {
resumeCallback = function() {
ProtocolTest.expectThat(pausedFunctionNames.includes("Toggle_Middle"), "Should pause in 'Toggle_Middle'.");
resolve();
};
});
ProtocolTest.log(`Removing blackbox for '${middleSourceURL.toLowerCase()}'...`);
await InspectorProtocol.awaitCommand({
method: "Debugger.setShouldBlackboxURL",
params: {url: middleSourceURL.toLowerCase(), shouldBlackbox: false},
});
await evaluate(`Toggle_Outer(10)`);
ProtocolTest.newline();
await resumePromise;
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.Invalid.emptyURL",
description: "Check that an error is thrown if the given url is empty.",
async test() {
await ProtocolTest.expectException(async () => {
await InspectorProtocol.awaitCommand({
method: "Debugger.setShouldBlackboxURL",
params: {url: "", shouldBlackbox: true},
});
});
},
});
suite.addTestCase({
name: "Debugger.setShouldBlackboxURL.Invalid.injectedScript",
description: "Check that an error is thrown if the given url matches an injected script url.",
async test() {
await ProtocolTest.expectException(async () => {
await InspectorProtocol.awaitCommand({
method: "Debugger.setShouldBlackboxURL",
params: {url: "__InjectedScript__test.js", shouldBlackbox: true},
});
});
},
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Tests Debugger.setShouldBlackboxURL.</p>
</body>
</html>