Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector-protocol / timeline / timeline-timer.html
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script>
5
6 function testFunction()
7 {
8     var timerId = setTimeout(function()
9     {
10         evaluateInFrontend("InspectorTest.testFunctionTimerFired(" + timerId + ", " + timerId2 + ")");
11     }, 0);
12
13     var timerId2 = setTimeout(function() { }, 0);
14     clearTimeout(timerId2);
15     return timerId;
16 }
17
18 function test()
19 {
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);
23
24     var firedTimerId;
25     var removedTimerId;
26     InspectorTest.testFunctionTimerFired = function(timerId1, timerId2)
27     {
28         firedTimerId = timerId1;
29         removedTimerId = timerId2;
30         InspectorTest.log("SUCCESS: testFunctionTimerFired");
31         InspectorTest.sendCommand("Tracing.end", { }, onStop);
32     }
33
34     function onStart(response)
35     {
36         InspectorTest.log("Recording started");
37         InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" });
38     }
39
40     var devtoolsEvents = [];
41     function dataCollected(reply)
42     {
43         var allEvents = reply.params.value;
44         devtoolsEvents = devtoolsEvents.concat(allEvents.filter(function(e)
45         {
46             return e.cat === "disabled-by-default-devtools.timeline";
47         }));
48     }
49
50     function tracingComplete(event)
51     {
52         InspectorTest.log("Tracing complete");
53
54         function hasTimerId(id, e) { return e.args.data.timerId === id}
55
56         var installTimer1 = findEvent("TimerInstall", "I", hasTimerId.bind(this, firedTimerId));
57         var installTimer2 = findEvent("TimerInstall", "I", hasTimerId.bind(this, removedTimerId));
58
59         InspectorTest.assert(!!installTimer1.args.data.frame, "TimerInstall frame");
60         InspectorTest.assertEquals(installTimer1.args.data.frame, installTimer2.args.data.frame, "TimerInstall frame match");
61
62         findEvent("TimerRemove", "I", hasTimerId.bind(this, removedTimerId));
63         findEvent("TimerFire", "X", hasTimerId.bind(this, firedTimerId));
64
65         InspectorTest.log("SUCCESS: found all expected events.");
66         InspectorTest.completeTest();
67     }
68
69     function findEvent(name, ph, condition)
70     {
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)))
74                 return e;
75         }
76         throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(devtoolsEvents, null, 2));
77     }
78
79     function onStop(response)
80     {
81         InspectorTest.log("Recording stopped");
82     }
83 }
84 </script>
85 </head>
86 <body onLoad="runTest();">
87 <div id="myDiv">DIV</div>
88 </body>
89 </html>