blob: 1b52bc02a649858aaeb4adb6f071cd35f10f1133 [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 src="./resources/timeline-helper.js"></script>
<script>
function installTimer()
{
setTimeout(function() {
callFunction(mul, add(1, 3), 3);
hook();
});
}
function add(a, b)
{
TestPage.addResult("Calling add(): " + a + " + " + b);
return a + b;
}
function mul(a, b)
{
TestPage.addResult("Calling mul(): " + a + " * " + b);
return a * b;
}
function test()
{
// First, set up the breakpoint, start timeline capturing, and trigger execution of installTimer().
WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ScriptAdded, function(event) {
var scriptObject = event.data.script;
if (!/timeline-helper\.js$/.test(scriptObject.url))
return;
var location = scriptObject.createSourceCodeLocation(17, 0); // Inside timeline-helper.js:hook()
var breakpoint = new WI.Breakpoint(location);
WI.debuggerManager.addBreakpoint(breakpoint);
InspectorTest.addResult("Added a breakpoint inside hook().")
WI.timelineManager.startCapturing();
InspectorTest.evaluateInPage("installTimer()");
});
// Second, the debugger will pause during timeline capturing. Resume, then stop timeline capturing.
WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, function(event) {
InspectorTest.addResult("Debugger paused;");
checkIfExceptionLoopsForever();
});
function checkIfExceptionLoopsForever() {
WI.runtimeManager.evaluateInInspectedWindow("({}).x.x", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, function(result, wasThrown) {
InspectorTest.addResult("An exception was " + (wasThrown ? "" : "not ") + "thrown from the injected script.");
WI.debuggerManager.resume().then(function() {
InspectorTest.addResult("Debugger resumed; stopping timeline capture.");
WI.timelineManager.stopCapturing();
});
});
}
// When timeline capturing stops, inspect the resulting timeline records for a profile.
WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStateChanged, (event) => {
if (WI.timelineManager.capturingState !== WI.TimelineManager.CapturingState.Inactive)
return;
var recording = WI.timelineManager.activeRecording;
var scriptTimeline = recording.timelines.get(WI.TimelineRecord.Type.Script);
console.assert(scriptTimeline);
InspectorTest.addResult("Timeline capturing stopped. Inspecting the active recording....");
for (var record of scriptTimeline.records) {
if (record.eventType !== WI.ScriptTimelineRecord.EventType.TimerFired)
continue;
var result = record.profile ? "TRUE" : "FALSE";
InspectorTest.addResult("TimerFired timeline record has profile attached: " + result);
}
InspectorTest.completeTest();
});
InspectorTest.reloadPage();
}
</script>
</head>
<body onload="runTest()">
<p>Testing that an injected script, run while the debugger is paused and the timeline profiler is enabled, should not loop forever if it has an exception thrown.</p>
</body>
</html>