blob: 915ab09bd93294c0b32da395ca53c85974621b28 [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; resuming...");
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 profiling data is correctly generated and attached to Timeline records when the debugger pauses and resumes while capturing timelines.</p>
</body>
</html>