blob: 0de0478ad135eb9b800e68aac038722f5f64076a [file] [edit]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="./resources/exceptions.js"></script>
<script>
// We expect uncaught exceptions, so avoid logs for them.
window.onerror = function(){};
function test()
{
WebInspector.debuggerManager.allExceptionsBreakpoint.disabled = false;
let suite = InspectorTest.createAsyncSuite("CommandLineAPI.$exception");
function addNoExceptionTest(name) {
suite.addTestCase({
name, description: "Without exceptions, $exception should be undefined",
test: (resolve, reject) => {
WebInspector.runtimeManager.evaluateInInspectedWindow("$exception", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, (result, wasThrown) => {
InspectorTest.expectThat(result.description === "undefined", "$exception should be undefined if there is no exception.");
resolve();
});
}
});
}
function addUncaughtExceptionTest(name, testFunction) {
suite.addTestCase({
name, description: "Trigger an uncaught exception and check $exception.",
test: (resolve, reject) => {
InspectorTest.evaluateInPage(`setTimeout(${testFunction})`);
WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Paused, (event) => {
WebInspector.runtimeManager.evaluateInInspectedWindow("$exception", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, (result, wasThrown) => {
InspectorTest.log("$exception => " + result.description);
WebInspector.debuggerManager.resume().then(resolve, reject);
});
});
}
});
}
function addCaughtExceptionTest(name, expression) {
suite.addTestCase({
name, description: "Trigger a caught exception and check $exception.",
test: (resolve, reject) => {
InspectorTest.evaluateInPage(expression);
let didStep = false;
let didEvaluate = false;
let listener = WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, (event) => {
if (!WebInspector.debuggerManager.activeCallFrame)
return;
if (!didStep) {
didStep = true;
InspectorTest.pass("Paused, stepping out to catch block...");
WebInspector.debuggerManager.stepOut();
return;
}
if (!didEvaluate) {
didEvaluate = true;
WebInspector.runtimeManager.evaluateInInspectedWindow("$exception === e", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, (result, wasThrown) => {
InspectorTest.expectThat(result.description === "true", "`$exception` should be equal to `e`.");
});
WebInspector.runtimeManager.evaluateInInspectedWindow("$exception", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, (result, wasThrown) => {
InspectorTest.log("$exception => " + result.description);
WebInspector.debuggerManager.resume().then(() => {
WebInspector.debuggerManager.removeEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, listener);
resolve();
}, reject);
});
return;
}
});
}
});
}
addNoExceptionTest("BeforeExceptions");
addUncaughtExceptionTest("UncaughtTypeException", "triggerUncaughtTypeException");
addUncaughtExceptionTest("UncaughtReferenceException", "triggerUncaughtReferenceException");
addUncaughtExceptionTest("UncaughtSyntaxException", "triggerUncaughtSyntaxException");
addUncaughtExceptionTest("UncaughtDOMException", "triggerUncaughtDOMException");
addUncaughtExceptionTest("UncaughtString", "throwString");
addUncaughtExceptionTest("UncaughtNumber", "throwNumber");
addUncaughtExceptionTest("UncaughtNull", "throwNull");
addUncaughtExceptionTest("UncaughtObject", "throwObject");
addUncaughtExceptionTest("UncaughtNode", "throwNode");
addCaughtExceptionTest("CatchTypeException", "setTimeout(function() { catcher(triggerUncaughtTypeException); })");
addCaughtExceptionTest("CatchThrownString", "setTimeout(function() { catcher(throwString); })");
addCaughtExceptionTest("CatchThrownObject", "setTimeout(function() { catcher(throwObject); })");
addNoExceptionTest("AfterExceptions");
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Checks that <code>$exception</code> is available and accurate in evaluations when paused on an exception.</p>
</body>
</html>