Web Inspector: ES6: Show Symbol properties on Objects
[WebKit-https.git] / LayoutTests / inspector / event-listener-set.html
1 <!doctype html>
2 <html>
3 <head>
4 <script type="text/javascript" src="../http/tests/inspector/inspector-test.js"></script>
5 <script>
6 function test()
7 {
8     const FooEvent = "foo";
9     const BarEvent = "bar";
10     const BazEvent = "baz";
11     var emitter1 = new WebInspector.Object();
12     var emitter2 = new WebInspector.Object();
13     var context1 = new WebInspector.Object();
14     var context2 = new WebInspector.Object();
15     var data1 = [1, 2, 3];
16     var data2 = [4, 6, 8];
17
18     function fooCallback(event)
19     {
20         InspectorTest.assert(this === context1, "Callback invoked with wrong |this| binding.");
21         InspectorTest.assert(event.target === emitter1, "Callback invoked with wrong event emitter.");
22         InspectorTest.assert(event.data === data1, "Callback invoked with wrong event data.");
23
24         InspectorTest.log("Invoked callback for foo event.");
25     }
26
27     function barCallback(event)
28     {
29         InspectorTest.assert(this === context1, "Callback invoked with wrong |this| binding.");
30         InspectorTest.assert(event.target === emitter1, "Callback invoked with wrong event emitter.");
31         InspectorTest.assert(event.data === data2, "Callback invoked with wrong event data.");
32
33         InspectorTest.log("Invoked callback for bar event.");
34     }
35
36     function bazCallback(event)
37     {
38         InspectorTest.assert(this === context2, "Callback invoked with wrong |this| binding.");
39         InspectorTest.assert(event.target === emitter2, "Callback invoked with wrong event emitter.");
40         InspectorTest.assert(event.data === data2, "Callback invoked with wrong event data.");
41
42         InspectorTest.log("Invoked callback for baz event.");
43     }
44
45     // Test for multiple firings of listeners in the set.
46
47     var listenerSet = new WebInspector.EventListenerSet(context1);
48     InspectorTest.assert(!emitter1.hasEventListeners(FooEvent), "Emitter should not have any listeners.");
49     emitter1.dispatchEventToListeners(FooEvent, data1); // Should not fire anything.
50
51     InspectorTest.log("Registering listeners.");
52     listenerSet.register(emitter1, FooEvent, fooCallback);
53     listenerSet.register(emitter1, BarEvent, barCallback);
54     listenerSet.register(emitter2, BazEvent, bazCallback, context2);
55     InspectorTest.assert(!emitter1.hasEventListeners(FooEvent), "Emitter should not have a listener.");
56     InspectorTest.assert(!emitter1.hasEventListeners(BarEvent), "Emitter should not have a listener.");
57     InspectorTest.assert(!emitter2.hasEventListeners(BazEvent), "Emitter should not have a listener.");
58
59     InspectorTest.log("Installing listeners.");
60     listenerSet.install();
61     InspectorTest.assert(emitter1.hasEventListeners(FooEvent), "Emitter should have a listener.");
62     InspectorTest.assert(emitter1.hasEventListeners(BarEvent), "Emitter should have a listener.");
63     InspectorTest.assert(emitter2.hasEventListeners(BazEvent), "Emitter should have a listener.");
64
65     InspectorTest.log("Dispatching events.");
66     emitter1.dispatchEventToListeners(FooEvent, data1); // Should fire.
67     emitter1.dispatchEventToListeners(BarEvent, data2); // Should fire.
68     emitter2.dispatchEventToListeners(BazEvent, data2); // Should fire.
69     InspectorTest.log("Uninstalling and disconnecting listeners.");
70     listenerSet.uninstall(true);
71
72     InspectorTest.log("Registering listeners.");
73     listenerSet.register(emitter1, FooEvent, fooCallback);
74     listenerSet.register(emitter1, BarEvent, barCallback);
75     listenerSet.register(emitter2, BazEvent, bazCallback, context2);
76
77     listenerSet.install();
78     InspectorTest.log("Dispatching events.");
79     emitter1.dispatchEventToListeners(FooEvent, data1); // Should fire.
80     emitter1.dispatchEventToListeners(BarEvent, data2); // Should fire.
81     emitter2.dispatchEventToListeners(BazEvent, data2); // Should fire.
82     InspectorTest.log("Uninstalling listeners.");
83     listenerSet.uninstall();
84
85     InspectorTest.log("Installing listeners.");
86     listenerSet.install();
87     InspectorTest.log("Dispatching events.");
88     emitter1.dispatchEventToListeners(FooEvent, data1); // Should fire.
89     emitter1.dispatchEventToListeners(BarEvent, data2); // Should fire.
90     emitter2.dispatchEventToListeners(BazEvent, data2); // Should fire.
91
92     InspectorTest.log("Unregistering everything.");
93     listenerSet.unregister();
94     InspectorTest.log("Dispatching events.");
95     emitter1.dispatchEventToListeners(FooEvent, data1); // Should not fire.
96     emitter1.dispatchEventToListeners(BarEvent, data2); // Should not fire.
97     emitter2.dispatchEventToListeners(BazEvent, data2); // Should not fire.
98
99     InspectorTest.log("Unintalling and disconnecting listeners.");
100     listenerSet.uninstall(true);
101     InspectorTest.log("Dispatching events.");
102     emitter1.dispatchEventToListeners(FooEvent, data1); // Should not fire.
103     emitter1.dispatchEventToListeners(BarEvent, data2); // Should not fire.
104     emitter2.dispatchEventToListeners(BazEvent, data2); // Should not fire.
105
106     InspectorTest.assert(!emitter1.hasEventListeners(FooEvent), "Emitter should not have a listener.");
107     InspectorTest.assert(!emitter1.hasEventListeners(BarEvent), "Emitter should not have a listener.");
108     InspectorTest.assert(!emitter2.hasEventListeners(BazEvent), "Emitter should not have a listener.");
109
110     InspectorTest.completeTest();
111 }
112 </script>
113 </head>
114 <body onload="runTest()">
115     <p>Testing basic functionality of WebInspector.EventListenerSet.</p>
116 </body>
117 </html>