Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / timeline / timeline-coalescing.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/timeline-test.js"></script>
5 <script>
6
7 function initialize_TimelineCoalescing()
8 {
9
10 InspectorTest.dumpStats = function(presentationRecord)
11 {
12     if (!presentationRecord.presentationParent())
13         return "";
14
15     var aggregatedStats = {};
16     var uiUtils = WebInspector.panels.timeline._uiUtils;
17     if (presentationRecord.coalesced()) {
18         var presentationChildren = presentationRecord.presentationChildren();
19         for (var i = 0; i < presentationChildren.length; ++i)
20             uiUtils.aggregateTimeForRecord(aggregatedStats, presentationChildren[i].record());
21     } else {
22         uiUtils.aggregateTimeForRecord(aggregatedStats, presentationRecord.record());
23     }
24
25     var timeByCategory = "";
26
27     for (category in aggregatedStats) {
28         if (timeByCategory)
29             timeByCategory += ", ";
30         timeByCategory += category + ": " + aggregatedStats[category].toFixed(5);
31     }
32     var duration = (presentationRecord.endTime() - presentationRecord.startTime()).toFixed(5);
33     var durationTillLastChild = (presentationRecord.endTime() - presentationRecord.startTime()).toFixed(5);
34     return "duration: " + duration + ":" + durationTillLastChild + (timeByCategory ? " (" + timeByCategory + ")" : "");
35 }
36
37 }
38
39 function test()
40 {
41     var records = [
42         // Assure we coalesce records with sort interval and don't coalesce records that stand apart.
43         {"startTime": 1000.000,"data":{},"endTime":1099.999,"type":"Program","children":[
44             {"startTime":1000.001, "endTime":1099.9,"type":"Layout","frameId":"2","data":{},
45             "stackTrace": [
46                 {"functionName":"func","url":"http://example.com","lineNumber":42,"columnNumber":1}
47             ]}
48         ]},
49         {"startTime":1100.000,"data":{},"endTime":1199.999,"type":"Program","children":[
50             {"startTime":1100.001, "endTime":1199.9,"type":"Layout","frameId":"2","data":{}}
51         ]},
52         {"startTime":1200.000,"data":{},"endTime":1299.999,"type":"Program","children":[
53             {"startTime":1200.001, "endTime":1299.9,"type":"Layout","frameId":"2","data":{}}
54         ]},
55         {"startTime":1300.000,"data":{},"endTime":1399.999,"type":"Program","children":[
56             {"startTime":1305.001, "endTime":1399.9,"type":"Layout","frameId":"2","data":{}}
57         ]},
58
59         // Assure we do coalesce on levels lower than root, but do not coalesce between different parents.
60         {"startTime":2000.000,"data":{},"endTime":2399.999,"type":"Program","children":[
61             {"startTime":2000.001,"data":{},"endTime":2199.998,"type":"FunctionCall","children":[
62                 {"startTime":2000.002, "endTime":2099.9,"type":"DecodeImage","frameId":"2","data":{}},
63                 {"startTime":2100.000, "endTime":2199.9,"type":"DecodeImage","frameId":"2","data":{}}
64             ]},
65             {"startTime":2200.001,"data":{},"endTime":2399.998,"type":"FunctionCall","children":[
66                 {"startTime":2200.002, "endTime":2299.9,"type":"DecodeImage","frameId":"2","data":{}},
67                 {"startTime":2300.000, "endTime":2399.9,"type":"DecodeImage","frameId":"2","data":{}}
68             ]},
69         ]},
70
71         // Assure we only coalesce timestamp records with the same message.
72         {"startTime":3100.000,"data":{},"endTime":3199.999,"type":"Program","children":[
73             {"startTime":3100.001, "endTime":3199.9,"type":"Rasterize","frameId":"2","data":{ message: "foo" }}
74         ]},
75         {"startTime":3200.000,"data":{},"endTime":3299.999,"type":"Program","children":[
76             {"startTime":3200.001, "endTime":3299.9,"type":"Rasterize","frameId":"2","data":{ message: "foo" }}
77         ]},
78         {"startTime":3300.000,"data":{},"endTime":3399.999,"type":"Program","children":[
79             {"startTime":3300.001, "endTime":3399.9,"type":"Rasterize","frameId":"2","data":{ message: "bar" }}
80         ]},
81
82         // Assure we only coalesce event records with the same type.
83         {"startTime":4100.000,"data":{},"endTime":4199.999,"type":"Program","children":[
84             {"startTime":4100.001, "endTime":4199.9,"type":"Paint","frameId":"2","data":{ type: "mouseover" }}
85         ]},
86         {"startTime":4200.000,"data":{},"endTime":4299.999,"type":"Program","children":[
87             {"startTime":4200.001, "endTime":4299.9,"type":"Paint","frameId":"2","data":{ type: "mouseover" }}
88         ]},
89         {"startTime":4300.000,"data":{},"endTime":4399.999,"type":"Program","children":[
90             {"startTime":4300.001, "endTime":4399.9,"type":"Paint","frameId":"2","data":{ type: "keydown" }}
91         ]}
92     ];
93
94     InspectorTest.loadTimelineRecords(records);
95
96     var rootRecord = InspectorTest.timelinePresentationModel().rootRecord();
97     InspectorTest.dumpPresentationRecord(rootRecord, InspectorTest.dumpStats);
98     var coalesced = rootRecord.presentationChildren()[0];
99     InspectorTest.addResult("coalesced record's hasWarnings(): " + coalesced.hasWarnings());
100     InspectorTest.addResult("coalesced record's childHasWarnings(): " + coalesced.childHasWarnings());
101     InspectorTest.completeTest();
102 }
103
104 </script>
105 </head>
106
107 <body onload="runTest()">
108 <p>
109 Test timeline records coalescing
110 </p>
111
112 </body>
113 </html>