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>
8 // Save references to the worker objects to make sure they are not GC'ed.
12 // The function ensures call stack for the current frame is captured.
13 function makeDOMEvent()
15 var e
= document
.createElement("div");
16 e
.innerHTML
= "<p>test</p>";
17 return e
.lastChild
.textContents
;
20 function startWorkerAndRunTest()
22 worker1
= new Worker("resources/worker.js");
23 worker1
.postMessage("");
25 if (window
.testRunner
) {
26 testRunner
.dumpAsText();
27 testRunner
.waitUntilDone();
30 worker1
.onmessage = function(event
)
32 worker1
.onmessage
= null;
37 function startSecondWorker(onActionComplete
)
39 worker2
= new Worker("resources/worker.js");
40 worker2
.postMessage("");
42 worker2
.onmessage = function(event
)
44 worker2
.onmessage
= null;
52 InspectorTest
.invokeWithTracing("startSecondWorker", processTracingEvents
,
53 "disabled-by-default-devtools.timeline.stack", true);
55 function processTracingEvents()
57 var mainThread
= { name
: "Main Thread", events
: InspectorTest
.tracingTimelineModel()._mainThreadEvents
};
58 processThread(new Set(["startSecondWorker", "worker2.onmessage"]), mainThread
);
59 var workers
= InspectorTest
.tracingTimelineModel()._virtualThreads
.filter(function(thread
) { return thread
.isWorker(); });
60 workers
.forEach(processThread
.bind(null, new Set(["onmessage"])));
61 InspectorTest
.completeTest();
64 function processThread(expectedFunctions
, thread
)
66 InspectorTest
.addResult(thread
.name
);
67 var missingFunctions
= thread
.events
.reduce(processEvent
, expectedFunctions
);
68 if (missingFunctions
.size
) {
69 InspectorTest
.addResult("FAIL: missing functions:");
70 missingFunctions
.forEach(InspectorTest
.addResult
);
74 function processEvent(expectedFunctions
, event
)
76 if (event
.name
=== WebInspector
.TimelineModel
.RecordType
.JSFrame
)
77 expectedFunctions
.delete(event
.args
.data
.functionName
);
78 return expectedFunctions
;
85 <body onload=
"startWorkerAndRunTest()">
87 Tests js cpu profile in timeline.