Rubber-stamped by Brady Eidson.
[webbrowser.git] / LayoutTests / inspector / timeline-test.js
blobbf159ce1b2ff42c0b3080ce91331b6eac1cdc3be
1 var timelineAgentRecordType = {};
3 // Scrub values when printing out these properties in the record or data field.
4 var timelineNonDeterministicProps = { 
5     children : 1,
6     endTime : 1, 
7     height : 1,
8     identifier : 1,
9     startTime : 1,
10     width : 1,
11     url : 1
14 function printTimelineRecords(performActions, typeName, formatter)
16     if (performActions) {
17         if (window.layoutTestController)
18             layoutTestController.setTimelineProfilingEnabled(true);
19         performActions();
20     }
22     evaluateInWebInspector("WebInspector.TimelineAgent.RecordType", function(result) {
23         timelineAgentRecordType = result;
24     });
26     evaluateInWebInspector("frontend_getTimelineResults", function(timelineRecords) {
27         if (typeof(timelineRecords) === "string")
28             output("Error fetching Timeline results: " + timelineRecords);
29         else {
30             for (var i = 0; i < timelineRecords.length; ++i) {
31                 var record = timelineRecords[i];
32                 if (typeName && record.type === timelineAgentRecordType[typeName])
33                     printTimelineRecordProperties(record);
34                 if (formatter)
35                     formatter(record);
36             }
37         }
38         if (window.layoutTestController)
39             layoutTestController.setTimelineProfilingEnabled(false);
40         notifyDone();
41     });
44 // Dump just the record name, indenting output on separate lines for subrecords
45 function dumpTimelineRecord(record, level) 
47     if (typeof level !== "number")
48         level = 0;
49     var prefix = "";
50     var suffix = "";
51     for (var i = 0; i < level ; ++i)
52         prefix = "----" + prefix;
53     if (level > 0)
54         prefix = prefix + "> ";
55     if (record.type === timelineAgentRecordType.MarkTimeline) {
56         suffix = " : " + record.data.message;
57     }
58     output(prefix + timelineAgentTypeToString(record.type) + suffix);
60     var numChildren = record.children ? record.children.length : 0;
61     for (var i = 0; i < numChildren; ++i)
62         dumpTimelineRecord(record.children[i], level + 1);
65 function dumpTimelineRecords(timelineRecords) {
66     for (var i = 0; i < timelineRecords.length; ++i)
67         dumpTimelineRecord(timelineRecords[i], 0);
70 function printTimelineRecordProperties(record)
72     output(timelineAgentTypeToString(record.type) + " Properties:");
73     // Use this recursive routine to print the properties
74     printProps(record, 0);
77 function isNonDeterministicProp(propName)
79     if (timelineNonDeterministicProps[propName])
80         return true;
81     return false;
84 function printProps(record, level)
86     var props = new Array();
87     for (var prop in record) {
88         props.push(prop);
89     }
91     var prefix = "+";
92     for (var i = 0; i < level ; i++) {
93         prefix = prefix + "-";
94     }
96     prefix = prefix + " ";
97     for (var prop in props) {
98         var propName = props[prop];
99         var propValue = record[propName];
100         if (isNonDeterministicProp(propName))
101             output(prefix + propName + " : " + (propValue === undefined ? "<undefined>" : " * DEFINED *"));
102         else if (typeof propValue === "object") {
103             output(prefix + propName + " : {");
104             printProps(propValue, level + 1);
105             output(prefix + "}");
106         } else
107             output(prefix + propName + " : " + propValue);
108     }
111 function timelineAgentTypeToString(numericType)
113     for (var prop in timelineAgentRecordType) {
114         if (timelineAgentRecordType[prop] === numericType)
115             return prop;
116     }
117     return undefined;
120 // Injected into Inspector window
121 function frontend_getTimelineResults() {
122     var result = [];
123     function addRecords(records)
124     {
125         if (!records)
126             return;
127         for (var i = 0; i < records.length; ++i) {
128             result.push(records[i].record);
129             addRecords(records[i].children);
130         }
131     }
132     addRecords(WebInspector.panels.timeline._records);
133     return result;