42c4f86e01d4771bb0dd9a8d6f6263e296cb3cca
[WebKit-https.git] / LayoutTests / inspector / timeline / setInstruments-programmatic-capture.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/protocol-test.js"></script>
5 <script>
6 function triggerProgrammaticCapture(message) {
7     console.profile();
8     console.log(`Inside ${message} profile`);
9     console.profileEnd();
10 }
11
12 function test()
13 {
14     let suite = ProtocolTest.createAsyncSuite("Timeline.setInstruments.programmatic-capture");
15
16     let heapExpected = false;
17     let programmaticCaptureStopped = null;
18
19     InspectorProtocol.eventHandler["Timeline.programmaticCaptureStarted"] = () => {
20         ProtocolTest.pass("Timeline.programmaticCaptureStarted");
21     };
22     InspectorProtocol.eventHandler["Timeline.programmaticCaptureStopped"] = () => {
23         ProtocolTest.pass("Timeline.programmaticCaptureStopped");
24         programmaticCaptureStopped();
25     };
26
27     InspectorProtocol.eventHandler["ScriptProfiler.trackingStart"] = () => {
28         ProtocolTest.pass("ScriptProfiler.startTracking");
29     };
30
31     InspectorProtocol.eventHandler["Heap.trackingStart"] = () => {
32         if (heapExpected)
33             ProtocolTest.pass("Heap.trackingStart");
34         else
35             ProtocolTest.fail("Unexpected Heap.trackingStart");
36     };
37
38     suite.addTestCase({
39         name: "NoInstrumentsProgrammaticCapture",
40         test(resolve, reject) {
41             heapExpected = false;
42             programmaticCaptureStopped = resolve;
43
44             InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: []}, (messageObject) => {
45                 ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
46             });
47             ProtocolTest.evaluateInPage("triggerProgrammaticCapture('NoInstrumentsProgrammaticCapture')");
48         }
49     });
50
51     suite.addTestCase({
52         name: "MultipleInstrumentsProgrammaticCapture",
53         test(resolve, reject) {
54             heapExpected = true;
55             programmaticCaptureStopped = resolve;
56
57             InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: ["ScriptProfiler", "Heap"]}, (messageObject) => {
58                 ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
59             });
60             ProtocolTest.evaluateInPage("triggerProgrammaticCapture('MultipleInstrumentsProgrammaticCapture')");
61         }
62     });
63
64     suite.addTestCase({
65         name: "NoInstrumentsProgrammaticCaptureAgain",
66         test(resolve, reject) {
67             heapExpected = true;
68             programmaticCaptureStopped = resolve;
69
70             InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: []}, (messageObject) => {
71                 ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
72             });
73             ProtocolTest.evaluateInPage("triggerProgrammaticCapture('NoInstrumentsProgrammaticCaptureAgain')");
74         }
75     });
76
77     suite.runTestCasesAndFinish();
78 }
79 </script>
80 </head>
81 <body onload="runTest()">
82 <p>Tests programmatic capture (console.profile/profileEnd) automatically starts instruments set via Timeline.setInstruments.</p>
83 </body>
84 </html>