blob: e1cfc99c3b8d1cc34e116d0cdd8559274964c572 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
<script>
function triggerProgrammaticCapture(message) {
console.profile();
console.log(`Inside ${message} profile`);
console.profileEnd();
}
function test()
{
let suite = ProtocolTest.createAsyncSuite("Timeline.setInstruments.programmatic-capture");
let heapExpected = false;
let captureStopped = null;
InspectorProtocol.sendCommand("Heap.enable");
InspectorProtocol.sendCommand("Timeline.enable");
InspectorProtocol.eventHandler["Timeline.recordingStarted"] = () => {
ProtocolTest.pass("Timeline.recordingStarted");
};
InspectorProtocol.eventHandler["Timeline.recordingStopped"] = () => {
ProtocolTest.pass("Timeline.recordingStopped");
captureStopped();
};
InspectorProtocol.eventHandler["ScriptProfiler.trackingStart"] = () => {
ProtocolTest.pass("ScriptProfiler.startTracking");
};
InspectorProtocol.eventHandler["Heap.trackingStart"] = () => {
if (heapExpected)
ProtocolTest.pass("Heap.trackingStart");
else
ProtocolTest.fail("Unexpected Heap.trackingStart");
};
suite.addTestCase({
name: "NoInstrumentsProgrammaticCapture",
test(resolve, reject) {
heapExpected = false;
captureStopped = resolve;
InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: []}, (messageObject) => {
ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
});
ProtocolTest.evaluateInPage("triggerProgrammaticCapture('NoInstrumentsProgrammaticCapture')");
}
});
suite.addTestCase({
name: "MultipleInstrumentsProgrammaticCapture",
test(resolve, reject) {
heapExpected = true;
captureStopped = resolve;
InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: ["ScriptProfiler", "Heap"]}, (messageObject) => {
ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
});
ProtocolTest.evaluateInPage("triggerProgrammaticCapture('MultipleInstrumentsProgrammaticCapture')");
}
});
suite.addTestCase({
name: "NoInstrumentsProgrammaticCaptureAgain",
test(resolve, reject) {
heapExpected = true;
captureStopped = resolve;
InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: []}, (messageObject) => {
ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
});
ProtocolTest.evaluateInPage("triggerProgrammaticCapture('NoInstrumentsProgrammaticCaptureAgain')");
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Tests programmatic capture (console.profile/profileEnd) automatically starts instruments set via Timeline.setInstruments.</p>
</body>
</html>