| <!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('Inside Script - 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)"); |
| WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => { |
| InspectorTest.pass("CSP Exception caused by script evaluation should pause."); |
| WI.debuggerManager.resume(); |
| }); |
| |
| WI.consoleManager.singleFireEventListener(WI.ConsoleManager.Event.MessageAdded, (event) => { |
| let {message} = event.data; |
| InspectorTest.assert(message.level === WI.ConsoleMessage.MessageLevel.Error); |
| InspectorTest.assert(message.line > 0); |
| InspectorTest.assert(message.column > 0); |
| InspectorTest.pass("CSP Exception Console Message: " + message.messageText); |
| 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 didPause = false; |
| let tempPauseFailListener = WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => { |
| didPause = true; |
| InspectorTest.fail("CSP Exception caused outside of script evaluation should not pause, but did."); |
| WI.debuggerManager.resume(); |
| reject(); |
| }); |
| WI.consoleManager.singleFireEventListener(WI.ConsoleManager.Event.MessageAdded, (event) => { |
| WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, tempPauseFailListener, null); |
| |
| let {message} = event.data; |
| InspectorTest.assert(message.level === WI.ConsoleMessage.MessageLevel.Error); |
| InspectorTest.assert(message.line > 0); |
| InspectorTest.assert(message.column > 0); |
| InspectorTest.expectFalse(didPause, "CSP Exception caused outside of script evaluation should not pause."); |
| InspectorTest.pass("CSP Exception Console Message: " + message.messageText); |
| 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> |