blob: 48c77aa58b4c62e95a55e63ab034eac403890a9c [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
TestPage.allowUncaughtExceptions = true;
TestPage.needToSanitizeUncaughtExceptionURLs = true;
function triggerCSPExceptionInsideScript() {
eval("console.log('CSP should prevent this')");
}
function triggerCSPExceptionOutsideScript() {
let iframe = document.createElement("iframe");
iframe.src = "resources/csp-exception-iframe.html";
document.body.appendChild(iframe);
}
function test()
{
let suite = InspectorTest.createAsyncSuite("PauseOnCSPExceptionDoesNotCrash");
suite.addTestCase({
name: "TriggerCSPExceptionInsideOfScript",
description: "Trigger a CSP Exception inside of script should pause.",
test: (resolve, reject) => {
InspectorTest.evaluateInPage("setTimeout(triggerCSPExceptionInsideScript)");
WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Paused, (event) => {
InspectorTest.pass("CSP Exception caused by script evaluation should pause.");
WebInspector.debuggerManager.resume();
});
WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Resumed, (event) => {
resolve();
});
}
});
suite.addTestCase({
name: "TriggerCSPExceptionOutsideOfScript",
description: "Trigger a CSP Exception outside of script should not pause or crash.",
test: (resolve, reject) => {
InspectorTest.evaluateInPage("setTimeout(triggerCSPExceptionOutsideScript)");
let tempPauseFailListener = WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Paused, (event) => {
InspectorTest.fail("CSP Exception caused outside of script evaluation should not pause, but did.");
WebInspector.debuggerManager.resume();
reject();
});
WebInspector.logManager.addEventListener(WebInspector.LogManager.Event.MessageAdded, (event) => {
WebInspector.debuggerManager.removeEventListener(WebInspector.DebuggerManager.Event.Paused, tempPauseFailListener, null);
InspectorTest.pass("CSP Exception caused outside of script evaluation should not pause.");
resolve();
});
}
});
DebuggerAgent.setPauseOnExceptions("all");
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Test for the CSP exception handling when pause on all exceptions is enabled.</p>
</body>
</html>