Unreviewed, fix test failures after r243119.
[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.sendCommand("Heap.enable");
20
21     InspectorProtocol.eventHandler["Timeline.programmaticCaptureStarted"] = () => {
22         ProtocolTest.pass("Timeline.programmaticCaptureStarted");
23     };
24     InspectorProtocol.eventHandler["Timeline.programmaticCaptureStopped"] = () => {
25         ProtocolTest.pass("Timeline.programmaticCaptureStopped");
26         programmaticCaptureStopped();
27     };
28
29     InspectorProtocol.eventHandler["ScriptProfiler.trackingStart"] = () => {
30         ProtocolTest.pass("ScriptProfiler.startTracking");
31     };
32
33     InspectorProtocol.eventHandler["Heap.trackingStart"] = () => {
34         if (heapExpected)
35             ProtocolTest.pass("Heap.trackingStart");
36         else
37             ProtocolTest.fail("Unexpected Heap.trackingStart");
38     };
39
40     suite.addTestCase({
41         name: "NoInstrumentsProgrammaticCapture",
42         test(resolve, reject) {
43             heapExpected = false;
44             programmaticCaptureStopped = resolve;
45
46             InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: []}, (messageObject) => {
47                 ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
48             });
49             ProtocolTest.evaluateInPage("triggerProgrammaticCapture('NoInstrumentsProgrammaticCapture')");
50         }
51     });
52
53     suite.addTestCase({
54         name: "MultipleInstrumentsProgrammaticCapture",
55         test(resolve, reject) {
56             heapExpected = true;
57             programmaticCaptureStopped = resolve;
58
59             InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: ["ScriptProfiler", "Heap"]}, (messageObject) => {
60                 ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
61             });
62             ProtocolTest.evaluateInPage("triggerProgrammaticCapture('MultipleInstrumentsProgrammaticCapture')");
63         }
64     });
65
66     suite.addTestCase({
67         name: "NoInstrumentsProgrammaticCaptureAgain",
68         test(resolve, reject) {
69             heapExpected = true;
70             programmaticCaptureStopped = resolve;
71
72             InspectorProtocol.sendCommand("Timeline.setInstruments", {instruments: []}, (messageObject) => {
73                 ProtocolTest.expectThat(!messageObject.error, "Should not be an error setting valid instruments.");
74             });
75             ProtocolTest.evaluateInPage("triggerProgrammaticCapture('NoInstrumentsProgrammaticCaptureAgain')");
76         }
77     });
78
79     suite.runTestCasesAndFinish();
80 }
81 </script>
82 </head>
83 <body onload="runTest()">
84 <p>Tests programmatic capture (console.profile/profileEnd) automatically starts instruments set via Timeline.setInstruments.</p>
85 </body>
86 </html>