3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
6 function testFunction()
8 var timerId = setTimeout(function()
10 evaluateInFrontend("InspectorTest.testFunctionTimerFired(" + timerId + ", " + timerId2 + ")");
13 var timerId2 = setTimeout(function() { }, 0);
14 clearTimeout(timerId2);
20 InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
21 InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
22 InspectorTest.sendCommand("Tracing.start", { "categories" : "disabled-by-default-devtools.timeline", "type": "" }, onStart);
26 InspectorTest.testFunctionTimerFired = function(timerId1, timerId2)
28 firedTimerId = timerId1;
29 removedTimerId = timerId2;
30 InspectorTest.log("SUCCESS: testFunctionTimerFired");
31 InspectorTest.sendCommand("Tracing.end", { }, onStop);
34 function onStart(response)
36 InspectorTest.log("Recording started");
37 InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" });
40 var devtoolsEvents = [];
41 function dataCollected(reply)
43 var allEvents = reply.params.value;
44 devtoolsEvents = devtoolsEvents.concat(allEvents.filter(function(e)
46 return e.cat === "disabled-by-default-devtools.timeline";
50 function tracingComplete(event)
52 InspectorTest.log("Tracing complete");
54 function hasTimerId(id, e) { return e.args.data.timerId === id}
56 var installTimer1 = findEvent("TimerInstall", "I", hasTimerId.bind(this, firedTimerId));
57 var installTimer2 = findEvent("TimerInstall", "I", hasTimerId.bind(this, removedTimerId));
59 InspectorTest.assert(!!installTimer1.args.data.frame, "TimerInstall frame");
60 InspectorTest.assertEquals(installTimer1.args.data.frame, installTimer2.args.data.frame, "TimerInstall frame match");
62 findEvent("TimerRemove", "I", hasTimerId.bind(this, removedTimerId));
63 findEvent("TimerFire", "X", hasTimerId.bind(this, firedTimerId));
65 InspectorTest.log("SUCCESS: found all expected events.");
66 InspectorTest.completeTest();
69 function findEvent(name, ph, condition)
71 for (var i = 0; i < devtoolsEvents.length; i++) {
72 var e = devtoolsEvents[i];
73 if (e.name === name && e.ph === ph && (!condition || condition(e)))
76 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(devtoolsEvents, null, 2));
79 function onStop(response)
81 InspectorTest.log("Recording stopped");
86 <body onLoad="runTest();">
87 <div id="myDiv">DIV</div>