1 var initialize_Timeline = function() {
3 InspectorTest
.preloadPanel("timeline");
4 WebInspector
.TempFile
= InspectorTest
.TempFileMock
;
6 // Scrub values when printing out these properties in the record or data field.
7 InspectorTest
.timelinePropertyFormatters
= {
8 children
: "formatAsTypeName",
9 endTime
: "formatAsTypeName",
10 requestId
: "formatAsTypeName",
11 startTime
: "formatAsTypeName",
12 stackTrace
: "formatAsTypeName",
14 scriptName
: "formatAsTypeName",
15 scriptId
: "formatAsTypeName",
16 usedHeapSizeDelta
: "skip",
17 mimeType
: "formatAsTypeName",
18 id
: "formatAsTypeName",
19 timerId
: "formatAsTypeName",
20 scriptLine
: "formatAsTypeName",
21 layerId
: "formatAsTypeName",
22 lineNumber
: "formatAsTypeName",
23 columnNumber
: "formatAsTypeName",
24 frameId
: "formatAsTypeName",
25 frame
: "formatAsTypeName",
26 page
: "formatAsTypeName",
27 encodedDataLength
: "formatAsTypeName",
28 identifier
: "formatAsTypeName",
29 clip
: "formatAsTypeName",
30 root
: "formatAsTypeName",
31 backendNodeId
: "formatAsTypeName",
32 nodeId
: "formatAsTypeName",
33 rootNode
: "formatAsTypeName",
34 networkTime
: "formatAsTypeName",
35 thread
: "formatAsTypeName"
38 InspectorTest
.InvalidationFormatters
= {
39 _tracingEvent
: "skip",
40 cause
: "formatAsInvalidationCause",
42 invalidatedSelectorId
: "skip",
43 invalidationList
: "skip",
44 invalidationSet
: "skip",
45 linkedRecalcStyleEvent
: "skip",
46 linkedLayoutEvent
: "skip",
52 InspectorTest
.formatters
.formatAsInvalidationCause = function(cause
)
57 if (cause
.stackTrace
&& cause
.stackTrace
.length
)
58 stackTrace
= InspectorTest
.formatters
.formatAsURL(cause
.stackTrace
[0].url
) + ":" + cause
.stackTrace
[0].lineNumber
;
59 return "{reason: " + cause
.reason
+ ", stackTrace: " + stackTrace
+ "}";
62 InspectorTest
.switchTimelineToWaterfallMode = function()
64 if (WebInspector
.panels
.timeline
._flameChartToggleButton
.toggled())
65 WebInspector
.panels
.timeline
._flameChartToggleButton
.element
.click();
68 InspectorTest
.timelinePresentationModel = function()
70 InspectorTest
.switchTimelineToWaterfallMode();
71 return WebInspector
.panels
.timeline
._currentViews
[0]._presentationModel
;
74 InspectorTest
.timelineModel = function()
76 return WebInspector
.panels
.timeline
._model
;
79 InspectorTest
.timelineFrameModel = function()
81 return WebInspector
.panels
.timeline
._frameModel();
84 InspectorTest
.startTimeline = function(callback
)
86 var panel
= WebInspector
.panels
.timeline
;
87 function onRecordingStarted()
89 panel
._model
.removeEventListener(WebInspector
.TimelineModel
.Events
.RecordingStarted
, onRecordingStarted
, this)
92 panel
._model
.addEventListener(WebInspector
.TimelineModel
.Events
.RecordingStarted
, onRecordingStarted
, this)
93 panel
._enableJSSamplingSettingSetting
.set(false);
94 panel
.toggleTimelineButton
.element
.click();
97 InspectorTest
.stopTimeline = function(callback
)
99 var panel
= WebInspector
.panels
.timeline
;
102 panel
._model
.removeEventListener(WebInspector
.TimelineModel
.Events
.RecordingStopped
, didStop
, this)
103 InspectorTest
.runAfterPendingDispatches(callback
);
105 panel
._model
.addEventListener(WebInspector
.TimelineModel
.Events
.RecordingStopped
, didStop
, this)
106 panel
.toggleTimelineButton
.element
.click();
109 InspectorTest
.evaluateWithTimeline = function(actions
, doneCallback
)
111 InspectorTest
.startTimeline(step1
);
114 InspectorTest
.evaluateInPage(actions
, step2
);
119 InspectorTest
.stopTimeline(doneCallback
);
123 InspectorTest
.invokeAsyncWithTimeline = function(functionName
, doneCallback
)
125 InspectorTest
.startTimeline(step1
);
128 InspectorTest
.invokePageFunctionAsync(functionName
, step2
);
133 InspectorTest
.stopTimeline(InspectorTest
.safeWrap(doneCallback
));
137 InspectorTest
.loadTimelineRecords = function(records
)
139 var model
= WebInspector
.panels
.timeline
._model
;
141 records
.forEach(model
._addRecord
, model
);
144 InspectorTest
.performActionsAndPrint = function(actions
, typeName
, includeTimeStamps
)
148 InspectorTest
.printTimelineRecords(typeName
);
149 if (includeTimeStamps
) {
150 InspectorTest
.addResult("Timestamp records: ");
151 InspectorTest
.printTimestampRecords(typeName
);
153 InspectorTest
.completeTest();
155 InspectorTest
.evaluateWithTimeline(actions
, callback
);
158 InspectorTest
.printTimelineRecords = function(typeName
, formatter
)
160 InspectorTest
.timelineModel().forAllRecords(InspectorTest
._printTimlineRecord
.bind(InspectorTest
, typeName
, formatter
));
163 InspectorTest
.printTimelinePresentationRecords = function(typeName
, formatter
)
165 InspectorTest
.innerPrintTimelinePresentationRecords(WebInspector
.panels
.timeline
._model
.records(), typeName
, formatter
);
168 InspectorTest
.printTimestampRecords = function(typeName
, formatter
)
170 InspectorTest
.innerPrintTimelineRecords(InspectorTest
.timelineModel().eventDividerRecords(), typeName
, formatter
);
173 InspectorTest
.innerPrintTimelineRecords = function(records
, typeName
, formatter
)
175 for (var i
= 0; i
< records
.length
; ++i
)
176 InspectorTest
._printTimlineRecord(typeName
, formatter
, records
[i
]);
179 InspectorTest
._printTimlineRecord = function(typeName
, formatter
, record
)
181 if (typeName
&& record
.type() === typeName
)
182 InspectorTest
.printTimelineRecordProperties(record
);
188 InspectorTest
.innerPrintTimelinePresentationRecords = function(records
, typeName
, formatter
)
190 for (var i
= 0; i
< records
.length
; ++i
) {
191 if (typeName
&& records
[i
].type() === typeName
)
192 InspectorTest
.printTimelineRecordProperties(records
[i
]);
194 formatter(records
[i
]);
195 InspectorTest
.innerPrintTimelinePresentationRecords(records
[i
].children(), typeName
, formatter
);
199 // Dump just the record name, indenting output on separate lines for subrecords
200 InspectorTest
.dumpTimelineRecord = function(record
, detailsCallback
, level
, filterTypes
)
202 if (typeof level
!== "number")
205 for (var i
= 0; i
< level
; ++i
)
206 message
= "----" + message
;
208 message
= message
+ "> ";
209 if (record
.type() === WebInspector
.TimelineModel
.RecordType
.TimeStamp
210 || record
.type() === WebInspector
.TimelineModel
.RecordType
.ConsoleTime
) {
211 message
+= WebInspector
.TimelineUIUtils
.eventTitle(record
.traceEvent());
213 message
+= record
.type();
216 message
+= " " + detailsCallback(record
);
217 InspectorTest
.addResult(message
);
219 var children
= record
.children();
220 var numChildren
= children
.length
;
221 for (var i
= 0; i
< numChildren
; ++i
) {
222 if (filterTypes
&& filterTypes
.indexOf(children
[i
].type()) == -1)
224 InspectorTest
.dumpTimelineRecord(children
[i
], detailsCallback
, level
+ 1, filterTypes
);
228 InspectorTest
.dumpTimelineModelRecord = function(record
, level
)
230 if (typeof level
!== "number")
233 for (var i
= 0; i
< level
; ++i
)
234 prefix
= "----" + prefix
;
236 prefix
= prefix
+ "> ";
237 InspectorTest
.addResult(prefix
+ record
.type() + ": " + (WebInspector
.TimelineUIUtils
.buildDetailsTextForTraceEvent(record
.traceEvent(), null) || ""));
239 var numChildren
= record
.children() ? record
.children().length
: 0;
240 for (var i
= 0; i
< numChildren
; ++i
)
241 InspectorTest
.dumpTimelineModelRecord(record
.children()[i
], level
+ 1);
244 // Dump just the record name, indenting output on separate lines for subrecords
245 InspectorTest
.dumpPresentationRecord = function(presentationRecord
, detailsCallback
, level
, filterTypes
)
247 var record
= !presentationRecord
.presentationParent() ? null : presentationRecord
.record();
248 if (typeof level
!== "number")
251 for (var i
= 0; i
< level
; ++i
)
252 message
= "----" + message
;
254 message
= message
+ "> ";
257 } else if (presentationRecord
.coalesced()) {
258 message
+= record
.type() + " x " + presentationRecord
.presentationChildren().length
;
259 } else if (record
.type() === WebInspector
.TimelineModel
.RecordType
.TimeStamp
260 || record
.type() === WebInspector
.TimelineModel
.RecordType
.ConsoleTime
) {
261 message
+= WebInspector
.TimelineUIUtils
.eventTitle(record
.traceEvent());
263 message
+= record
.type();
266 message
+= " " + detailsCallback(presentationRecord
);
267 InspectorTest
.addResult(message
);
269 var numChildren
= presentationRecord
.presentationChildren() ? presentationRecord
.presentationChildren().length
: 0;
270 for (var i
= 0; i
< numChildren
; ++i
) {
271 if (filterTypes
&& filterTypes
.indexOf(presentationRecord
.presentationChildren()[i
].record().type()) == -1)
273 InspectorTest
.dumpPresentationRecord(presentationRecord
.presentationChildren()[i
], detailsCallback
, level
+ 1, filterTypes
);
277 InspectorTest
.dumpTimelineRecords = function(timelineRecords
)
279 for (var i
= 0; i
< timelineRecords
.length
; ++i
)
280 InspectorTest
.dumpTimelineRecord(timelineRecords
[i
], 0);
283 InspectorTest
.printTimelineRecordProperties = function(record
)
285 InspectorTest
.addResult(record
.type() + " Properties:");
286 var traceEvent
= record
.traceEvent();
287 var data
= traceEvent
.args
["beginData"] || traceEvent
.args
["data"];
288 var frameId
= data
&& data
["frame"];
290 data
: traceEvent
.args
["data"] || traceEvent
.args
,
291 endTime
: record
.endTime(),
293 stackTrace
: traceEvent
.stackTrace
,
294 startTime
: record
.startTime(),
295 thread
: record
.thread(),
298 for (var field
in object
) {
299 if (object
[field
] === null || object
[field
] === undefined)
300 delete object
[field
];
302 if (record
.children().length
)
303 object
["children"] = [];
304 InspectorTest
.addObject(object
, InspectorTest
.timelinePropertyFormatters
);
307 InspectorTest
.findFirstTimelineRecord = function(type
)
309 return InspectorTest
.findTimelineRecord(type
, 0);
312 // Find the (n+1)th timeline record of a specific type.
313 InspectorTest
.findTimelineRecord = function(type
, n
)
316 function findByType(record
)
318 if (record
.type() !== type
)
327 InspectorTest
.timelineModel().forAllRecords(findByType
);
331 InspectorTest
.FakeFileReader = function(input
, delegate
, callback
)
333 this._delegate
= delegate
;
334 this._callback
= callback
;
336 this._loadedSize
= 0;
337 this._fileSize
= input
.length
;
340 InspectorTest
.dumpFrame = function(frame
)
342 var fieldsToDump
= ["cpuTime", "duration", "startTime", "endTime", "id", "mainThreadFrameId", "timeByCategory", "other", "scripting", "painting", "rendering", "committedFrom", "idle"];
343 function formatFields(object
)
346 for (var key
in object
) {
347 if (fieldsToDump
.indexOf(key
) < 0)
349 var value
= object
[key
];
350 if (typeof value
=== "number")
351 value
= Number(value
.toFixed(7));
352 else if (typeof value
=== "object" && value
)
353 value
= formatFields(value
);
358 InspectorTest
.addObject(formatFields(frame
));
361 InspectorTest
.FakeFileReader
.prototype = {
362 start: function(output
)
364 this._delegate
.onTransferStarted(this);
366 var length
= this._input
.length
;
367 var half
= (length
+ 1) >> 1;
369 var chunk
= this._input
.substring(0, half
);
370 this._loadedSize
+= chunk
.length
;
372 this._delegate
.onChunkTransferred(this);
374 chunk
= this._input
.substring(half
);
375 this._loadedSize
+= chunk
.length
;
377 this._delegate
.onChunkTransferred(this);
380 this._delegate
.onTransferFinished(this);
385 cancel: function() { },
387 loadedSize: function()
389 return this._loadedSize
;
394 return this._fileSize
;
405 function generateFrames(count
, callback
)
410 document
.body
.style
.backgroundColor
= count
& 1 ? "rgb(200, 200, 200)" : "rgb(240, 240, 240)";
415 if (window
.testRunner
)
416 testRunner
.capturePixelsAsyncThen(requestAnimationFrame
.bind(window
, makeFrame
));
418 window
.requestAnimationFrame(makeFrame
);