| <html> | |
| <head> | |
| <script src="../../http/tests/inspector/resources/protocol-test.js"></script> | |
| <script src="resources/assert.js"></script> | |
| <script> | |
| function test() | |
| { | |
| InspectorProtocol.sendCommand("Debugger.enable", {}); | |
| InspectorProtocol.sendCommand("Debugger.setBreakpointsActive", {active: true}); | |
| InspectorProtocol.sendCommand("Debugger.setPauseOnExceptions", {state: "all"}, InspectorProtocol.checkForError); | |
| InspectorProtocol.sendCommand("Debugger.setPauseOnAssertions", {enabled: true}, InspectorProtocol.checkForError); | |
| var step = null; | |
| var steps = [ | |
| { | |
| message: "Should not pause on passing assert.", | |
| evaluate: "assertTrue()", | |
| pause: false, | |
| }, | |
| { | |
| message: "Should pause on failing assert.", | |
| evaluate: "assertFalse()", | |
| pause: true, | |
| }, | |
| { | |
| message: "Should not pause on passing assert.", | |
| evaluate: "assertCondition(window)", | |
| pause: false, | |
| }, | |
| { | |
| message: "Should pause on failing assert.", | |
| evaluate: "assertCondition(window === null)", | |
| pause: true, | |
| }, | |
| { | |
| message: "Should not pause on passing assert.", | |
| evaluate: "assertConditionWithMessage(window, 'Should not happen')", | |
| pause: false, | |
| }, | |
| { | |
| message: "Should pause on failing assert and include a message.", | |
| evaluate: "assertConditionWithMessage(window === null, 'ASSERT message')", | |
| pause: true, | |
| }, | |
| ]; | |
| InspectorProtocol.eventHandler["Debugger.paused"] = function(messageObject) | |
| { | |
| if (step.pause) | |
| ProtocolTest.log("PASS: Paused!"); | |
| else | |
| ProtocolTest.log("FAIL: Paused when unexpected"); | |
| InspectorProtocol.sendCommand("Debugger.resume", {}, runNextStep); | |
| } | |
| async function runNextStep() { | |
| step = steps.shift(); | |
| if (!step) { | |
| ProtocolTest.completeTest(); | |
| return; | |
| } | |
| ProtocolTest.log(step.message); | |
| // Evaluate the command inside a setTimeout so that we can hit exceptions and break. | |
| // Otherwise, evaluating through RuntimeAgent will not trigger a pause. | |
| // | |
| // That setTimeout also means Runtime.evaluate returns before the step has run, so a step | |
| // that does not pause has to signal its own completion; otherwise the next step's message | |
| // can be logged before this step's output arrives. | |
| let expression = `${step.evaluate};`; | |
| if (!step.pause) | |
| expression = `try { ${step.evaluate}; } finally { TestPage.dispatchEventToFrontend("StepComplete"); }`; | |
| expression = `setTimeout(function() { ${expression} }, 0)`; | |
| let didStepComplete = step.pause ? null : ProtocolTest.awaitEvent("StepComplete"); | |
| InspectorProtocol.sendCommand("Runtime.evaluate", {expression}, InspectorProtocol.checkForError); | |
| if (didStepComplete) { | |
| await didStepComplete; | |
| await runNextStep(); | |
| } | |
| } | |
| runNextStep(); | |
| } | |
| </script> | |
| </head> | |
| <body onload="runTest()"> | |
| <p>Test that a failing console.assert will pause in the debugger with an optional message.</p> | |
| </body> | |
| </html> |