Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector-protocol / timeline / timeline-dispatchEvent.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 div = document.querySelector("#my-div");
9     div.addEventListener("click", function(e) {  }, false);
10     div.click();
11
12     var iframe = document.createElement("iframe");
13     div.appendChild(iframe);
14 }
15
16 function test()
17 {
18     InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
19     InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
20     InspectorTest.sendCommand("Tracing.start", { "categories" : "disabled-by-default-devtools.timeline", "type": "" }, onStart);
21
22     function onStart(response)
23     {
24         InspectorTest.log("Recording started");
25         InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" }, didEvaluate);
26     }
27
28     function didEvaluate(response)
29     {
30         InspectorTest.sendCommand("Tracing.end", { }, onStop);
31     }
32
33     var devtoolsEvents = [];
34     function dataCollected(reply)
35     {
36         var allEvents = reply.params.value;
37         devtoolsEvents = devtoolsEvents.concat(allEvents.filter(function(e)
38         {
39             return e.cat === "disabled-by-default-devtools.timeline";
40         }));
41     }
42
43     function tracingComplete(event)
44     {
45         InspectorTest.log("Tracing complete");
46
47         function windowEventFilter(type, e)
48         {
49             return e.name === "EventDispatch" && e.args.type === type;
50         };
51
52         var windowEventNames = [ "click", "beforeunload", "unload", "load" ];
53         for (var i = 0; i < windowEventNames.length; i++) {
54             var eventName = windowEventNames[i];
55             var events = devtoolsEvents.filter(windowEventFilter.bind(this, eventName));
56             if (events.length >= 1) {
57                 InspectorTest.log("SUCCESS: found " + eventName + " event");
58             } else {
59                 fail(eventName + " event is missing");
60             }
61         }
62
63         InspectorTest.completeTest();
64     }
65
66
67     function fail(message)
68     {
69         var formattedEvents = devtoolsEvents.map(function(e)
70         {
71             return e.name + "(" + e.args.type + ")";
72         });
73         InspectorTest.log("FAIL: " + message + " devtools.timeline events: " + JSON.stringify(formattedEvents, null, 2));
74     }
75
76     function onStop(response)
77     {
78         InspectorTest.log("Recording stopped");
79     }
80 }
81 </script>
82 </head>
83 <body onLoad="runTest();">
84 <div id="my-div"></div>
85 </body>
86 </html>