Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / timeline-test.js
1 var initialize_Timeline = function() {
2
3 // Scrub values when printing out these properties in the record or data field.
4 InspectorTest.timelinePropertyFormatters = {
5     children: "formatAsTypeName",
6     endTime: "formatAsTypeName",
7     requestId: "formatAsTypeName",
8     startTime: "formatAsTypeName",
9     stackTrace: "formatAsTypeName",
10     url: "formatAsURL",
11     scriptName: "formatAsTypeName",
12     usedHeapSizeDelta: "skip",
13     mimeType: "formatAsTypeName",
14     id: "formatAsTypeName",
15     counters: "formatAsTypeName",
16     timerId: "formatAsTypeName",
17     scriptLine: "formatAsTypeName",
18     layerId: "formatAsTypeName",
19     lineNumber: "formatAsTypeName",
20     frameId: "formatAsTypeName",
21     encodedDataLength: "formatAsTypeName",
22     identifier: "formatAsTypeName",
23     clip: "formatAsTypeName",
24     root: "formatAsTypeName",
25     rootNode: "formatAsTypeName",
26     layerRootNode: "formatAsTypeName",
27     elementId: "formatAsTypeName",
28     networkTime: "formatAsTypeName",
29     thread: "formatAsTypeName"
30 };
31
32 InspectorTest.timelinePresentationModel = function()
33 {
34     return WebInspector.panels.timeline._currentViews[0]._presentationModel;
35 }
36
37 InspectorTest.startTimeline = function(callback)
38 {
39     InspectorTest._timelineRecords = [];
40     WebInspector.panel("timeline").toggleTimelineButton.toggled = true;
41     WebInspector.panel("timeline")._model._collectionEnabled = true;
42     TimelineAgent.start(5, false, true, false, callback);
43     function addRecord(record)
44     {
45         InspectorTest._timelineRecords.push(record);
46         for (var i = 0; record.children && i < record.children.length; ++i)
47             addRecord(record.children[i]);
48     }
49     InspectorTest._addTimelineEvent = function(event)
50     {
51         addRecord(event.data);
52     }
53     WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, InspectorTest._addTimelineEvent);
54 };
55
56
57 InspectorTest.waitForRecordType = function(recordType, callback)
58 {
59     WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, addEvent);
60
61     function addEvent(event)
62     {
63         addRecord(event.data);
64     }
65     function addRecord(record)
66     {
67         if (record.type !== WebInspector.TimelineModel.RecordType[recordType]) {
68             for (var i = 0; record.children && i < record.children.length; ++i)
69                 addRecord(record.children[i]);
70             return;
71         }
72         WebInspector.timelineManager.removeEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, addEvent);
73         callback(record);
74     }
75 }
76
77 InspectorTest.stopTimeline = function(callback)
78 {
79     function didStop()
80     {
81         WebInspector.timelineManager.removeEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, InspectorTest._addTimelineEvent);
82         WebInspector.panel("timeline").toggleTimelineButton.toggled = false;
83         WebInspector.panel("timeline")._model._collectionEnabled = false;
84         callback(InspectorTest._timelineRecords);
85     }
86     TimelineAgent.stop(didStop);
87 };
88
89 InspectorTest.evaluateWithTimeline = function(actions, doneCallback)
90 {
91     InspectorTest.startTimeline(step1);
92     function step1()
93     {
94         InspectorTest.evaluateInPage(actions, step2);
95     }
96
97     function step2()
98     {
99         InspectorTest.stopTimeline(doneCallback);
100     }
101 }
102
103 InspectorTest.loadTimelineRecords = function(records)
104 {
105     var model = WebInspector.showPanel("timeline")._model;
106     model.reset();
107     records.forEach(model._addRecord, model);
108 }
109
110 InspectorTest.performActionsAndPrint = function(actions, typeName, includeTimeStamps)
111 {
112     function callback()
113     {
114         InspectorTest.printTimelineRecords(typeName);
115         if (includeTimeStamps) {
116             InspectorTest.addResult("Timestamp records: ");
117             InspectorTest.printTimestampRecords(typeName);
118         }
119         InspectorTest.completeTest();
120     }
121     InspectorTest.evaluateWithTimeline(actions, callback)
122 };
123
124 InspectorTest.printTimelineRecords = function(typeName, formatter)
125 {
126     InspectorTest.innerPrintTimelineRecords(InspectorTest._timelineRecords, typeName, formatter);
127 };
128
129 InspectorTest.printTimestampRecords = function(typeName, formatter)
130 {
131     InspectorTest.innerPrintTimelineRecords(InspectorTest.timelinePresentationModel().eventDividerRecords().select("_record"), typeName, formatter);
132 };
133
134 InspectorTest.innerPrintTimelineRecords = function(records, typeName, formatter)
135 {
136     for (var i = 0; i < records.length; ++i) {
137         if (typeName && records[i].type === WebInspector.TimelineModel.RecordType[typeName])
138             InspectorTest.printTimelineRecordProperties(records[i]);
139         if (formatter)
140             formatter(records[i]);
141     }
142 };
143
144 // Dump just the record name, indenting output on separate lines for subrecords
145 InspectorTest.dumpTimelineRecord = function(record, detailsCallback, level)
146 {
147     if (typeof level !== "number")
148         level = 0;
149     var prefix = "";
150     var suffix = "";
151     for (var i = 0; i < level ; ++i)
152         prefix = "----" + prefix;
153     if (level > 0)
154         prefix = prefix + "> ";
155     if (record.coalesced) {
156         suffix = " x " + record.children.length;
157     } else if (record.type === WebInspector.TimelineModel.RecordType.TimeStamp
158         || record.type === WebInspector.TimelineModel.RecordType.Time
159         || record.type === WebInspector.TimelineModel.RecordType.TimeEnd) {
160         suffix = " : " + record.data.message;
161     }
162     if (detailsCallback)
163         suffix += " " + detailsCallback(record);
164     InspectorTest.addResult(prefix + InspectorTest._timelineAgentTypeToString(record.type) + suffix);
165
166     var numChildren = record.children ? record.children.length : 0;
167     for (var i = 0; i < numChildren; ++i)
168         InspectorTest.dumpTimelineRecord(record.children[i], detailsCallback, level + 1);
169 }
170
171 InspectorTest.dumpTimelineRecords = function(timelineRecords)
172 {
173     for (var i = 0; i < timelineRecords.length; ++i)
174         InspectorTest.dumpTimelineRecord(timelineRecords[i], 0);
175 };
176
177 InspectorTest.printTimelineRecordProperties = function(record)
178 {
179     InspectorTest.addResult(InspectorTest._timelineAgentTypeToString(record.type) + " Properties:");
180     // Use this recursive routine to print the properties
181     InspectorTest.addObject(record, InspectorTest.timelinePropertyFormatters);
182 };
183
184 InspectorTest._timelineAgentTypeToString = function(numericType)
185 {
186     for (var prop in WebInspector.TimelineModel.RecordType) {
187         if (WebInspector.TimelineModel.RecordType[prop] === numericType)
188             return prop;
189     }
190     return undefined;
191 };
192
193 InspectorTest.findPresentationRecord = function(type)
194 {
195     var result;
196     function findByType(record)
197     {
198         if (record.type !== type)
199             return false;
200         result = record;
201         return true;
202     }
203     var records = WebInspector.panel("timeline")._currentViews[0]._rootRecord().children;
204     WebInspector.TimelinePresentationModel.forAllRecords(records, findByType);
205     return result;
206 }
207
208 InspectorTest.FakeFileReader = function(input, delegate, callback)
209 {
210     this._delegate = delegate;
211     this._callback = callback;
212     this._input = input;
213     this._loadedSize = 0;
214     this._fileSize = input.length;
215 };
216
217 InspectorTest.FakeFileReader.prototype = {
218     start: function(output)
219     {
220         this._delegate.onTransferStarted(this);
221
222         var length = this._input.length;
223         var half = (length + 1) >> 1;
224
225         var chunk = this._input.substring(0, half);
226         this._loadedSize += chunk.length;
227         output.write(chunk);
228         this._delegate.onChunkTransferred(this);
229
230         chunk = this._input.substring(half);
231         this._loadedSize += chunk.length;
232         output.write(chunk);
233         this._delegate.onChunkTransferred(this);
234
235         output.close();
236         this._delegate.onTransferFinished(this);
237
238         this._callback();
239     },
240
241     cancel: function() { },
242
243     loadedSize: function()
244     {
245         return this._loadedSize;
246     },
247
248     fileSize: function()
249     {
250         return this._fileSize;
251     },
252
253     fileName: function()
254     {
255         return "fakeFile";
256     }
257 };
258
259 };