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 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"
32 InspectorTest.timelinePresentationModel = function()
34 return WebInspector.panels.timeline._currentViews[0]._presentationModel;
37 InspectorTest.startTimeline = function(callback)
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)
45 InspectorTest._timelineRecords.push(record);
46 for (var i = 0; record.children && i < record.children.length; ++i)
47 addRecord(record.children[i]);
49 InspectorTest._addTimelineEvent = function(event)
51 addRecord(event.data);
53 WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, InspectorTest._addTimelineEvent);
57 InspectorTest.waitForRecordType = function(recordType, callback)
59 WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, addEvent);
61 function addEvent(event)
63 addRecord(event.data);
65 function addRecord(record)
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]);
72 WebInspector.timelineManager.removeEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, addEvent);
77 InspectorTest.stopTimeline = function(callback)
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);
86 TimelineAgent.stop(didStop);
89 InspectorTest.evaluateWithTimeline = function(actions, doneCallback)
91 InspectorTest.startTimeline(step1);
94 InspectorTest.evaluateInPage(actions, step2);
99 InspectorTest.stopTimeline(doneCallback);
103 InspectorTest.loadTimelineRecords = function(records)
105 var model = WebInspector.showPanel("timeline")._model;
107 records.forEach(model._addRecord, model);
110 InspectorTest.performActionsAndPrint = function(actions, typeName, includeTimeStamps)
114 InspectorTest.printTimelineRecords(typeName);
115 if (includeTimeStamps) {
116 InspectorTest.addResult("Timestamp records: ");
117 InspectorTest.printTimestampRecords(typeName);
119 InspectorTest.completeTest();
121 InspectorTest.evaluateWithTimeline(actions, callback)
124 InspectorTest.printTimelineRecords = function(typeName, formatter)
126 InspectorTest.innerPrintTimelineRecords(InspectorTest._timelineRecords, typeName, formatter);
129 InspectorTest.printTimestampRecords = function(typeName, formatter)
131 InspectorTest.innerPrintTimelineRecords(InspectorTest.timelinePresentationModel().eventDividerRecords().select("_record"), typeName, formatter);
134 InspectorTest.innerPrintTimelineRecords = function(records, typeName, formatter)
136 for (var i = 0; i < records.length; ++i) {
137 if (typeName && records[i].type === WebInspector.TimelineModel.RecordType[typeName])
138 InspectorTest.printTimelineRecordProperties(records[i]);
140 formatter(records[i]);
144 // Dump just the record name, indenting output on separate lines for subrecords
145 InspectorTest.dumpTimelineRecord = function(record, detailsCallback, level)
147 if (typeof level !== "number")
151 for (var i = 0; i < level ; ++i)
152 prefix = "----" + prefix;
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;
163 suffix += " " + detailsCallback(record);
164 InspectorTest.addResult(prefix + InspectorTest._timelineAgentTypeToString(record.type) + suffix);
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);
171 InspectorTest.dumpTimelineRecords = function(timelineRecords)
173 for (var i = 0; i < timelineRecords.length; ++i)
174 InspectorTest.dumpTimelineRecord(timelineRecords[i], 0);
177 InspectorTest.printTimelineRecordProperties = function(record)
179 InspectorTest.addResult(InspectorTest._timelineAgentTypeToString(record.type) + " Properties:");
180 // Use this recursive routine to print the properties
181 InspectorTest.addObject(record, InspectorTest.timelinePropertyFormatters);
184 InspectorTest._timelineAgentTypeToString = function(numericType)
186 for (var prop in WebInspector.TimelineModel.RecordType) {
187 if (WebInspector.TimelineModel.RecordType[prop] === numericType)
193 InspectorTest.findPresentationRecord = function(type)
196 function findByType(record)
198 if (record.type !== type)
203 var records = WebInspector.panel("timeline")._currentViews[0]._rootRecord().children;
204 WebInspector.TimelinePresentationModel.forAllRecords(records, findByType);
208 InspectorTest.FakeFileReader = function(input, delegate, callback)
210 this._delegate = delegate;
211 this._callback = callback;
213 this._loadedSize = 0;
214 this._fileSize = input.length;
217 InspectorTest.FakeFileReader.prototype = {
218 start: function(output)
220 this._delegate.onTransferStarted(this);
222 var length = this._input.length;
223 var half = (length + 1) >> 1;
225 var chunk = this._input.substring(0, half);
226 this._loadedSize += chunk.length;
228 this._delegate.onChunkTransferred(this);
230 chunk = this._input.substring(half);
231 this._loadedSize += chunk.length;
233 this._delegate.onChunkTransferred(this);
236 this._delegate.onTransferFinished(this);
241 cancel: function() { },
243 loadedSize: function()
245 return this._loadedSize;
250 return this._fileSize;