Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / chrome / test / data / webui / event_target_test.html
blobf023916bf618787fb03c809111fc1e1a2b953fc0
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script>
6 /* @const */ var EventTarget;
8 function setUp(){
9 EventTarget = cr.EventTarget;
12 function testFunctionListener() {
13 var fi = 0;
14 function f(e) {
15 fi++;
18 var gi = 0;
19 function g(e) {
20 gi++;
23 var et = new EventTarget;
24 et.addEventListener('f', f);
25 et.addEventListener('g', g);
27 // Adding again should not cause it to be called twice
28 et.addEventListener('f', f);
29 et.dispatchEvent(new Event('f'));
30 assertEquals(1, fi, 'Should have been called once');
31 assertEquals(0, gi);
33 et.removeEventListener('f', f);
34 et.dispatchEvent(new Event('f'));
35 assertEquals(1, fi, 'Should not have been called again');
37 et.dispatchEvent(new Event('g'));
38 assertEquals(1, gi, 'Should have been called once');
41 function testHandleEvent() {
42 var fi = 0;
43 var f = {
44 handleEvent: function(e) {
45 fi++;
49 var gi = 0;
50 var g = {
51 handleEvent: function(e) {
52 gi++;
56 var et = new EventTarget;
57 et.addEventListener('f', f);
58 et.addEventListener('g', g);
60 // Adding again should not cause it to be called twice
61 et.addEventListener('f', f);
62 et.dispatchEvent(new Event('f'));
63 assertEquals(1, fi, 'Should have been called once');
64 assertEquals(0, gi);
66 et.removeEventListener('f', f);
67 et.dispatchEvent(new Event('f'));
68 assertEquals(1, fi, 'Should not have been called again');
70 et.dispatchEvent(new Event('g'));
71 assertEquals(1, gi, 'Should have been called once');
74 function testPreventDefault() {
75 var i = 0;
76 function prevent(e) {
77 i++;
78 e.preventDefault();
81 var j = 0;
82 function pass(e) {
83 j++;
86 var et = new EventTarget;
87 et.addEventListener('test', pass);
89 assertTrue(et.dispatchEvent(new Event('test', {cancelable: true})));
90 assertEquals(1, j);
92 et.addEventListener('test', prevent);
94 console.log('NOW');
95 assertFalse(et.dispatchEvent(new Event('test', {cancelable: true})));
96 assertEquals(2, j);
97 assertEquals(1, i);
101 function testReturnFalse() {
102 var i = 0;
103 function prevent(e) {
104 i++;
105 return false;
108 var j = 0;
109 function pass(e) {
110 j++;
113 var et = new EventTarget;
114 et.addEventListener('test', pass);
116 assertTrue(et.dispatchEvent(new Event('test', {cancelable: true})));
117 assertEquals(1, j);
119 et.addEventListener('test', prevent);
121 assertFalse(et.dispatchEvent(new Event('test', {cancelable: true})));
122 assertEquals(2, j);
123 assertEquals(1, i);
126 </script>
127 </body>
128 </html>