dd9c5aea5034773ee8fed332565eb692b343f723
[WebKit-https.git] / LayoutTests / inspector / timeline / line-column.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/protocol-test.js"></script>
5 <script>
6
7 function bar(x)
8 {
9     return x * 10;
10 }
11
12 function foo() {
13     bar(42);
14 }
15
16 function load() {
17     document.querySelector("#button").addEventListener("click", (event) => {
18         foo();
19     });
20
21     runTest();
22 }
23
24 function willCallFunctionTest() {
25     console.profile();
26     document.querySelector("#button").click();
27     console.profileEnd();
28 }
29
30 function willEvaluateScriptTest() {
31     console.profile();
32     foo();
33     console.profileEnd();
34 }
35
36 function test() {
37     ProtocolTest.debug();
38
39     let suite = ProtocolTest.createAsyncSuite("Timeline.LineColumn");
40
41     function replacer(key, value) {
42         if (key === "startTime" || key === "endTime" || key === "scriptId" || key === "frameId")
43             return "<filtered>";
44         if (key === "url" || key === "scriptName")
45             return value.replace(/^.+LayoutTests\/inspector\//, "");
46         return value;
47     }
48
49     const tests = [
50         {
51             name: "Timeline.LineColumn.willCallFunction",
52             description: "Test that column numbers are passed through the willCallFunction instrumentation point.",
53             expression: `willCallFunctionTest()`,
54         },
55         {
56             name: "Timeline.LineColumn.willEvaluateScript",
57             description: "Test that column numbers are passed through the willEvaluateScript instrumentation point.",
58             expression: `willEvaluateScriptTest()`,
59         },
60     ];
61
62     for (let {name, description, expression} of tests) {
63         suite.addTestCase({
64             name,
65             description,
66             test(resolve, reject) {
67                 let eventNames = [];
68
69                 function handleEvent(eventName, handler) {
70                     eventNames.push(eventName);
71                     InspectorProtocol.eventHandler[eventName] = handler;
72                 }
73
74                 handleEvent("Timeline.eventRecorded", (event) => {
75                     ProtocolTest.log(JSON.stringify(event.params.record, replacer, 2));
76                 });
77
78                 handleEvent("Timeline.programmaticCaptureStarted", () => {
79                     ProtocolTest.pass("Capturing started.");
80                 });
81
82                 handleEvent("Timeline.programmaticCaptureStopped", () => {
83                     ProtocolTest.pass("Capturing stopped.");
84
85                     for (let eventName of eventNames)
86                         delete InspectorProtocol.eventHandler[eventName];
87
88                     resolve();
89                 });
90
91                 ProtocolTest.log("Evaluating in page...");
92                 ProtocolTest.evaluateInPage(expression)
93                 .catch(reject);
94             },
95         });
96     }
97
98     suite.runTestCasesAndFinish();
99 }
100
101 </script>
102 </head>
103 <body onload="load()">
104     <p>Test that script Timeline records have column numbers.</p>
105     <button id="button"></button>
106 </body>
107 </html>