blob: c745c806c1063629e7f415220cbbdd3d2865a8a8 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="../debugger/resources/log-pause-location.js"></script>
<script>
TestPage.allowUncaughtExceptions = true;
TestPage.needToSanitizeUncaughtExceptionURLs = true;
let worker = new Worker("resources/worker-debugger-pause.js");
function test()
{
let workerTarget = Array.from(WI.targets).find((target) => target.type === WI.Target.Type.Worker);
let workerDebuggerData = WI.debuggerManager.dataForTarget(workerTarget);
if (!workerTarget) {
InspectorTest.fail("Missing Worker Target");
InspectorTest.completeTest();
return;
}
// In each test, the Worker pauses and the Main Thread is waiting to
// pause on the next statement. Do an InspectorTest.log, which evaluates
// JavaScript in the page and should pause. Then later run work.
// In WebKit1, because the VM is shared between the inspector and
// inspected page we need to put an artificial break between our
// Inspector JavaScript, the Page JavaScript, and back to the Inspector.
function pauseTheMainThread() {
return new Promise((resolve, reject) => {
setTimeout(() => {
InspectorTest.log("");
setTimeout(resolve);
});
});
}
WI.debuggerManager.allUncaughtExceptionsBreakpoint.disabled = false;
WI.debuggerManager.assertionsBreakpoint.disabled = false;
let suite = InspectorTest.createAsyncSuite("Worker.Debugger.Pause");
suite.addTestCase({
name: "Worker.Debugger.Pause.DebuggerStatement",
description: "Worker should pause on debugger statement.",
test(resolve, reject) {
InspectorTest.evaluateInPage(`worker.postMessage("triggerDebuggerStatement")`);
WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
pauseTheMainThread().then(() => {
InspectorTest.pass("Paused");
InspectorTest.expectEqual(WI.debuggerManager.activeCallFrame.target, workerTarget, "Should be paused in a Worker CallFrame.");
InspectorTest.expectEqual(workerDebuggerData.pauseReason, WI.DebuggerManager.PauseReason.DebuggerStatement, "Pause reason should be a debugger statement.");
logPauseLocation();
WI.debuggerManager.resume().then(resolve, reject);
});
});
}
});
suite.addTestCase({
name: "Worker.Debugger.Pause.Breakpoint",
description: "Worker should pause on breakpoint.",
test(resolve, reject) {
let location = workerTarget.mainResource.createSourceCodeLocation(8, 0);
let breakpoint = new WI.Breakpoint(location);
WI.debuggerManager.addBreakpoint(breakpoint);
InspectorTest.evaluateInPage(`worker.postMessage("triggerBreakpoint")`);
WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
pauseTheMainThread().then(() => {
InspectorTest.pass("Paused");
InspectorTest.expectEqual(WI.debuggerManager.activeCallFrame.target, workerTarget, "Should be paused in a Worker CallFrame.");
InspectorTest.expectEqual(workerDebuggerData.pauseReason, WI.DebuggerManager.PauseReason.Breakpoint, "Pause reason should be a breakpoint.");
logPauseLocation();
WI.debuggerManager.resume().then(resolve, reject);
});
});
}
});
suite.addTestCase({
name: "Worker.Debugger.Pause.Exception",
description: "Worker should pause on exception.",
test(resolve, reject) {
InspectorTest.evaluateInPage(`worker.postMessage("triggerException")`);
WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
pauseTheMainThread().then(() => {
InspectorTest.pass("Paused");
InspectorTest.expectEqual(WI.debuggerManager.activeCallFrame.target, workerTarget, "Should be paused in a Worker CallFrame.");
InspectorTest.expectEqual(workerDebuggerData.pauseReason, WI.DebuggerManager.PauseReason.Exception, "Pause reason should be an exception.");
logPauseLocation();
WI.debuggerManager.resume().then(resolve, reject);
});
});
}
});
suite.addTestCase({
name: "Worker.Debugger.Pause.Assert",
description: "Worker should pause on assert.",
test(resolve, reject) {
InspectorTest.evaluateInPage(`worker.postMessage("triggerAssertion")`);
WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
pauseTheMainThread().then(() => {
InspectorTest.pass("Paused");
InspectorTest.expectEqual(WI.debuggerManager.activeCallFrame.target, workerTarget, "Should be paused in a Worker CallFrame.");
InspectorTest.expectEqual(workerDebuggerData.pauseReason, WI.DebuggerManager.PauseReason.Assertion, "Pause reason should be an exception.");
logPauseLocation();
WI.debuggerManager.resume().then(resolve, reject);
});
});
}
});
window.loadLinesFromSourceCode(workerTarget.mainResource).then(() => {
suite.runTestCasesAndFinish();
});
}
</script>
</head>
<body onload="runTest()">
<p>Ensure we can pause in Workers.</p>
</body>
</html>