1 var initialize_Timeline = function() {
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",
11 scriptName: "formatAsTypeName",
12 scriptId: "formatAsTypeName",
13 usedHeapSizeDelta: "skip",
14 mimeType: "formatAsTypeName",
15 id: "formatAsTypeName",
16 timerId: "formatAsTypeName",
17 scriptLine: "formatAsTypeName",
18 layerId: "formatAsTypeName",
19 lineNumber: "formatAsTypeName",
20 columnNumber: "formatAsTypeName",
21 frameId: "formatAsTypeName",
22 encodedDataLength: "formatAsTypeName",
23 identifier: "formatAsTypeName",
24 clip: "formatAsTypeName",
25 root: "formatAsTypeName",
26 backendNodeId: "formatAsTypeName",
27 networkTime: "formatAsTypeName",
28 thread: "formatAsTypeName"
31 InspectorTest.timelinePresentationModel = function()
33 return WebInspector.panels.timeline._currentViews[0]._presentationModel;
36 InspectorTest.timelineModel = function()
38 return WebInspector.panels.timeline._model;
41 InspectorTest.startTimeline = function(callback)
43 var panel = WebInspector.inspectorView.panel("timeline");
44 panel.toggleTimelineButton.toggled = true;
45 panel._model._collectionEnabled = true;
46 panel._userInitiatedRecording = true;
47 panel._model._currentTarget = WebInspector.targetManager.mainTarget();
48 TimelineAgent.start(5, true, undefined, true, false, callback);
51 InspectorTest.stopTimeline = function(callback)
53 function didStop(error)
56 testRunner.logToStderr("error: " + error);
57 var panel = WebInspector.inspectorView.panel("timeline");
58 panel.toggleTimelineButton.toggled = false;
59 panel._userInitiatedRecording = false;
62 TimelineAgent.stop(didStop);
65 InspectorTest.evaluateWithTimeline = function(actions, doneCallback)
67 InspectorTest.startTimeline(step1);
70 InspectorTest.evaluateInPage(actions, step2);
75 InspectorTest.stopTimeline(doneCallback);
79 InspectorTest.invokeAsyncWithTimeline = function(functionName, doneCallback)
81 InspectorTest.startTimeline(step1);
84 InspectorTest.invokePageFunctionAsync(functionName, step2);
89 InspectorTest.stopTimeline(doneCallback);
93 InspectorTest.loadTimelineRecords = function(records)
95 var model = WebInspector.inspectorView.showPanel("timeline")._model;
97 records.forEach(model._addRecord, model);
100 InspectorTest.performActionsAndPrint = function(actions, typeName, includeTimeStamps)
104 InspectorTest.printTimelineRecords(typeName);
105 if (includeTimeStamps) {
106 InspectorTest.addResult("Timestamp records: ");
107 InspectorTest.printTimestampRecords(typeName);
109 InspectorTest.completeTest();
111 InspectorTest.evaluateWithTimeline(actions, callback);
114 InspectorTest.printTimelineRecords = function(typeName, formatter)
116 InspectorTest.timelineModel().forAllRecords(InspectorTest._printTimlineRecord.bind(InspectorTest, typeName, formatter));
119 InspectorTest.printTimelinePresentationRecords = function(typeName, formatter)
121 InspectorTest.innerPrintTimelinePresentationRecords(WebInspector.panels.timeline._model.records(), typeName, formatter);
124 InspectorTest.printTimestampRecords = function(typeName, formatter)
126 InspectorTest.innerPrintTimelineRecords(InspectorTest.timelineModel().eventDividerRecords(), typeName, formatter);
129 InspectorTest.innerPrintTimelineRecords = function(records, typeName, formatter)
131 for (var i = 0; i < records.length; ++i)
132 InspectorTest._printTimlineRecord(typeName, formatter, records[i]);
135 InspectorTest._printTimlineRecord = function(typeName, formatter, record)
137 if (typeName && record.type() === WebInspector.TimelineModel.RecordType[typeName])
138 InspectorTest.printTimelineRecordProperties(record);
144 InspectorTest.innerPrintTimelinePresentationRecords = function(records, typeName, formatter)
146 for (var i = 0; i < records.length; ++i) {
147 if (typeName && records[i].type() === WebInspector.TimelineModel.RecordType[typeName])
148 InspectorTest.printTimelineRecordProperties(records[i]);
150 formatter(records[i]);
151 InspectorTest.innerPrintTimelinePresentationRecords(records[i].children(), typeName, formatter);
155 // Dump just the record name, indenting output on separate lines for subrecords
156 InspectorTest.dumpTimelineRecord = function(record, detailsCallback, level, filterTypes)
158 if (typeof level !== "number")
162 for (var i = 0; i < level ; ++i)
163 prefix = "----" + prefix;
165 prefix = prefix + "> ";
166 if (record.type() === WebInspector.TimelineModel.RecordType.TimeStamp
167 || record.type() === WebInspector.TimelineModel.RecordType.ConsoleTime) {
168 suffix = " : " + record.data().message;
171 suffix += " " + detailsCallback(record);
172 InspectorTest.addResult(prefix + InspectorTest._timelineAgentTypeToString(record.type()) + suffix);
174 var children = record.children();
175 var numChildren = children.length;
176 for (var i = 0; i < numChildren; ++i) {
177 if (filterTypes && filterTypes.indexOf(children[i].type()) == -1)
179 InspectorTest.dumpTimelineRecord(children[i], detailsCallback, level + 1, filterTypes);
183 InspectorTest.dumpTimelineModelRecord = function(record, level)
185 if (typeof level !== "number")
188 for (var i = 0; i < level ; ++i)
189 prefix = "----" + prefix;
191 prefix = prefix + "> ";
192 InspectorTest.addResult(prefix + record.type());
194 var numChildren = record.children() ? record.children().length : 0;
195 for (var i = 0; i < numChildren; ++i)
196 InspectorTest.dumpTimelineModelRecord(record.children()[i], level + 1);
199 // Dump just the record name, indenting output on separate lines for subrecords
200 InspectorTest.dumpPresentationRecord = function(presentationRecord, detailsCallback, level, filterTypes)
202 var record = !presentationRecord.presentationParent() ? null : presentationRecord.record();
203 if (typeof level !== "number")
207 for (var i = 0; i < level ; ++i)
208 prefix = "----" + prefix;
210 prefix = prefix + "> ";
211 if (presentationRecord.coalesced()) {
212 suffix = " x " + presentationRecord.presentationChildren().length;
213 } else if (record && (record.type() === WebInspector.TimelineModel.RecordType.TimeStamp
214 || record.type() === WebInspector.TimelineModel.RecordType.ConsoleTime)) {
215 suffix = " : " + record.data().message;
218 suffix += " " + detailsCallback(presentationRecord);
219 var typeString = record ? InspectorTest._timelineAgentTypeToString(record.type()) : "Root";
220 InspectorTest.addResult(prefix + typeString + suffix);
222 var numChildren = presentationRecord.presentationChildren() ? presentationRecord.presentationChildren().length : 0;
223 for (var i = 0; i < numChildren; ++i) {
224 if (filterTypes && filterTypes.indexOf(presentationRecord.presentationChildren()[i].record().type()) == -1)
226 InspectorTest.dumpPresentationRecord(presentationRecord.presentationChildren()[i], detailsCallback, level + 1, filterTypes);
230 InspectorTest.dumpTimelineRecords = function(timelineRecords)
232 for (var i = 0; i < timelineRecords.length; ++i)
233 InspectorTest.dumpTimelineRecord(timelineRecords[i], 0);
236 InspectorTest.printTimelineRecordProperties = function(record)
238 var recordType = (typeof record.type === "string") ? record.type : record.type();
239 InspectorTest.addResult(InspectorTest._timelineAgentTypeToString(recordType) + " Properties:");
240 // Use this recursive routine to print the properties
241 if (record instanceof WebInspector.TimelineModel.RecordImpl)
242 record = record._record;
243 InspectorTest.addObject(record, InspectorTest.timelinePropertyFormatters);
246 InspectorTest._timelineAgentTypeToString = function(numericType)
248 for (var prop in WebInspector.TimelineModel.RecordType) {
249 if (WebInspector.TimelineModel.RecordType[prop] === numericType)
255 InspectorTest.findFirstTimelineRecord = function(type)
258 function findByType(record)
260 if (record.type() !== type)
265 InspectorTest.timelineModel().forAllRecords(findByType);
269 InspectorTest.FakeFileReader = function(input, delegate, callback)
271 this._delegate = delegate;
272 this._callback = callback;
274 this._loadedSize = 0;
275 this._fileSize = input.length;
278 InspectorTest.dumpFrame = function(frame)
280 var fieldsToDump = ["cpuTime", "duration", "startTime", "endTime", "id", "mainThreadFrameId", "timeByCategory", "other", "scripting", "painting", "rendering", "committedFrom"];
281 function formatFields(object)
284 for (var key in object) {
285 if (fieldsToDump.indexOf(key) < 0)
287 var value = object[key];
288 if (typeof value === "number")
289 value = Number(value.toFixed(7));
290 else if (typeof value === "object" && value)
291 value = formatFields(value);
296 InspectorTest.addObject(formatFields(frame));
299 InspectorTest.FakeFileReader.prototype = {
300 start: function(output)
302 this._delegate.onTransferStarted(this);
304 var length = this._input.length;
305 var half = (length + 1) >> 1;
307 var chunk = this._input.substring(0, half);
308 this._loadedSize += chunk.length;
310 this._delegate.onChunkTransferred(this);
312 chunk = this._input.substring(half);
313 this._loadedSize += chunk.length;
315 this._delegate.onChunkTransferred(this);
318 this._delegate.onTransferFinished(this);
323 cancel: function() { },
325 loadedSize: function()
327 return this._loadedSize;
332 return this._fileSize;