3 <script src=
"../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../../http/tests/inspector/timeline-test.js"></script>
5 <script src=
"../tracing-test.js"></script>
10 function runTestWithDataAndCheck(input
, expectedOutput
)
12 var model
= InspectorTest
.tracingTimelineModel();
13 var timeline
= WebInspector
.panels
.timeline
;
15 function createFileReader(file
, delegate
)
17 var stream
= new InspectorTest
.StringOutputStream(checkSaveData
);
18 var saver
= new WebInspector
.TracingTimelineSaver(stream
);
19 var storage
= timeline
._tracingModelBackingStorage
;
20 return new InspectorTest
.FakeFileReader(input
, delegate
, stream
.open
.bind(stream
, "", storage
.writeToStream
.bind(storage
, stream
, saver
)));
23 function checkSaveData(output
)
25 var saveData
= JSON
.parse(output
);
26 InspectorTest
.assertEquals(JSON
.stringify(expectedOutput
), JSON
.stringify(saveData
), "saved data is not equal to restored");
29 InspectorTest
.override(model
, "_createFileReader", createFileReader
);
31 model
.loadFromFile({}, new WebInspector
.Progress());
34 function runTestOnMalformedInput(input
)
36 InspectorTest
.tracingModel().reset();
37 var model
= InspectorTest
.tracingTimelineModel();
39 function createFileReader(file
, delegate
)
41 return new InspectorTest
.FakeFileReader(input
, delegate
, checkLoadedData
);
44 function checkLoadedData(data
)
46 InspectorTest
.assertTrue(model
.isEmpty());
49 InspectorTest
.override(model
, "_createFileReader", createFileReader
);
50 model
.loadFromFile({}, new WebInspector
.Progress());
53 var data
= [{"args":{"number":32},"cat":"__metadata","name":"num_cpus","ph":"M","pid":32127,"tid":0,"ts":0},
54 {"args":{"sort_index":-5},"cat":"__metadata","name":"process_sort_index","ph":"M","pid":32127,"tid":12,"ts":0},
55 {"args":{"name":"Renderer"},"cat":"__metadata","name":"process_name","ph":"M","pid":32127,"tid":12,"ts":0},
56 {"args":{"sort_index":-1},"cat":"__metadata","name":"thread_sort_index","ph":"M","pid":32127,"tid":11,"ts":0},
57 {"args":{},"cat":"disabled-by-default-devtools.timeline","name":"Program","ph":"B","pid":32120,"tid":9,"ts":95904702436,"tts":1161841},
58 {"args":{"number":32},"cat":"__metadata","name":"num_cpus","ph":"M","pid":32120,"tid":0,"ts":0},
59 {"args":{"sort_index":-5},"cat":"__metadata","name":"process_sort_index","ph":"M","pid":32120,"tid":10,"ts":0},
60 {"args":{"name":"Renderer"},"cat":"__metadata","name":"process_name","ph":"M","pid":32120,"tid":10,"ts":0},
61 {"args":{"sort_index":-1},"cat":"__metadata","name":"thread_sort_index","ph":"M","pid":32120,"tid":9,"ts":0},
62 {"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":32120,"tid":9,"ts":0},
63 {"args":{"data":{"frame":"0x1cfa1f6a4000","scriptId":"52","scriptLine":664,"scriptName":"http://example.com/foo.js"}},"cat":"disabled-by-default-devtools.timeline","dur":21,"name":"FunctionCall","ph":"X","pid":32169,"tdur":20,"tid":35,"ts":95904848776,"tts":2613659},
64 {"args":{"stack":[]},"cat":"disabled-by-default-devtools.timeline.stack","name":"CallStack","ph":"I","pid":32169,"s":"g","tid":35,"ts":95904848783,"tts":2613665},
65 {"args":{"data":{"frame":"0x1cfa1f6a4000","scriptId":"52","scriptLine":664,"scriptName":"http://example.com/foo.js"}},"cat":"disabled-by-default-devtools.timeline","dur":20,"name":"FunctionCall","ph":"X","pid":32169,"tdur":18,"tid":35,"ts":95904848821,"tts":2613704},
66 {"args":{"stack":[]},"cat":"disabled-by-default-devtools.timeline.stack","name":"CallStack","ph":"I","pid":32169,"s":"g","tid":35,"ts":95904848827,"tts":2613710},
67 {"args":{"data":{"frame":"0x1cfa1f6a4000","scriptId":"52","scriptLine":664,"scriptName":"http://example.com/foo.js"}},"cat":"disabled-by-default-devtools.timeline","dur":19,"name":"FunctionCall","ph":"X","pid":32169,"tdur":18,"tid":35,"ts":95904848866,"tts":2613749},
68 {"args":{"stack":[]},"cat":"disabled-by-default-devtools.timeline.stack","name":"CallStack","ph":"I","pid":32169,"s":"g","tid":35,"ts":95904848872,"tts":2613755},
69 {"args":{"data":{"frame":"0x1cfa1f6a4000","scriptId":"52","scriptLine":664,"scriptName":"http://example.com/foo.js"}},"cat":"disabled-by-default-devtools.timeline","dur":19,"name":"FunctionCall","ph":"X","pid":32169,"tdur":19,"tid":35,"ts":95904848909,"tts":2613791},
70 {"args":{"stack":[]},"cat":"disabled-by-default-devtools.timeline.stack","name":"CallStack","ph":"I","pid":32169,"s":"g","tid":35,"ts":95904848915,"tts":2613797},
71 {"args":{"data":{"frame":"0x1cfa1f6a4000","scriptId":"52","scriptLine":664,"scriptName":"http://example.com/foo.js"}},"cat":"disabled-by-default-devtools.timeline","dur":21,"name":"FunctionCall","ph":"X","pid":32169,"tdur":19,"tid":35,"ts":95904848954,"tts":2613837},
72 {"args":{"stack":[]},"cat":"disabled-by-default-devtools.timeline.stack","name":"CallStack","ph":"I","pid":32169,"s":"g","tid":35,"ts":95904848961,"tts":2613843},
73 {"args":{"sessionId":"26.5"},"cat":"disabled-by-default-devtools.timeline","name":"TracingStartedInPage","ph":"I","pid":32157,"s":"g","tid":26,"ts":95904694459,"tts":1432596},
74 {"args":{"layerTreeId":1,"sessionId":"26.5"},"cat":"disabled-by-default-devtools.timeline","name":"SetLayerTreeId","ph":"I","pid":32157,"s":"g","tid":26,"ts":95904694693,"tts":1432692},
75 {"args":{},"cat":"disabled-by-default-devtools.timeline","name":"Program","ph":"E","pid":32157,"tid":26,"ts":95904694731,"tts":1432729},
76 {"args":{},"cat":"disabled-by-default-devtools.timeline","name":"Program","ph":"B","pid":32157,"tid":26,"ts":95904694789,"tts":1432787},
77 {"args":{"data":{"type":"beforeunload"}},"cat":"disabled-by-default-devtools.timeline","dur":16,"name":"EventDispatch","ph":"X","pid":32157,"tdur":13,"tid":26,"ts":95904695027,"tts":1433025},
78 {"args":{"data":{"frame":"0x30acf4ca4000","requestId":"26.422","requestMethod":"GET","url":"http://localhost/bar.html?ws=E16865E8B9D1"}},"cat":"disabled-by-default-devtools.timeline","name":"ResourceSendRequest","ph":"I","pid":32157,"s":"g","tid":26,"ts":95904695434,"tts":1433433},
79 {"args":{"stack":null},"cat":"disabled-by-default-devtools.timeline.stack","name":"CallStack","ph":"I","pid":32157,"s":"g","tid":26,"ts":95904695455,"tts":1433453},
80 {"args":{},"cat":"disabled-by-default-devtools.timeline","name":"Program","ph":"E","pid":32157,"tid":26,"ts":95904695551,"tts":1433549},
81 {"args":{},"cat":"disabled-by-default-devtools.timeline","name":"Program","ph":"B","pid":32157,"tid":26,"ts":95904696695,"tts":1433692},
82 {"args":{},"cat":"disabled-by-default-devtools.timeline","name":"Program","ph":"E","pid":32157,"tid":26,"ts":95904696737,"tts":1433733},
83 {"args":{"data":{"frame":"0x30acf4ca4000","mimeType":"text/html","requestId":"26.422","statusCode":200}},"cat":"disabled-by-default-devtools.timeline","name":"ResourceReceiveResponse","ph":"I","pid":32157,"s":"g","tid":26,"ts":95904699823,"tts":1433961},
84 {"args":{"data":{"frame":"0x30acf4ca4000","identifier":406}},"cat":"disabled-by-default-devtools.timeline","name":"WebSocketDestroy","ph":"I","pid":32157,"s":"g","tid":26,"ts":95904701483,"tts":1435612},
85 {"args":{"stack":null},"cat":"disabled-by-default-devtools.timeline.stack","name":"CallStack","ph":"I","pid":32157,"s":"g","tid":26,"ts":95904701489,"tts":1435618},
86 {"args":{"number":32},"cat":"__metadata","name":"num_cpus","ph":"M","pid":32072,"tid":0,"ts":0},
87 {"args":{"sort_index":-6},"cat":"__metadata","name":"process_sort_index","ph":"M","pid":32072,"tid":32096,"ts":0},
88 {"args":{"name":"Browser"},"cat":"__metadata","name":"process_name","ph":"M","pid":32072,"tid":32096,"ts":0},
89 {"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":32072,"tid":32072,"ts":0}
92 InspectorTest
.runTestSuite([
93 function testNormal(next
)
95 var input
= JSON
.stringify(data
);
96 runTestWithDataAndCheck(input
, data
);
100 function testJSONObjectFormat(next
)
102 var json
= "{\"traceEvents\":" + data
+ "}";
103 var input
= JSON
.stringify(json
);
104 runTestWithDataAndCheck(input
, json
);
108 function testBroken(next
)
110 var data
= [{"args":{"number":32},"cat":"__metadata","name":"num_cpus","ph":"M","pid":32127,"tid":0,"ts":0,"t\"y}p}e\\":"UnknownRecordType"}];
111 runTestOnMalformedInput(JSON
.stringify(data
));
115 function testMalformedJSON(next
)
117 runTestOnMalformedInput("]");
126 <body onload=
"runTest()">
128 Tests tracing based Timeline save/load functionality.