Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: tests/html/event_test.dart

Issue 11275054: Modified unittest to use new argument syntax. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library('EventTest'); 5 #library('EventTest');
6 #import('../../pkg/unittest/unittest.dart'); 6 #import('../../pkg/unittest/unittest.dart');
7 #import('../../pkg/unittest/html_config.dart'); 7 #import('../../pkg/unittest/html_config.dart');
8 #import('dart:html'); 8 #import('dart:html');
9 9
10 // TODO(nweiz): Make this private to testEvents when Frog supports closures with 10 // TODO(nweiz): Make this private to testEvents when Frog supports closures with
11 // optional arguments. 11 // optional arguments.
12 eventTest(String name, Event eventFn(), void validate(Event), 12 eventTest(String name, Event eventFn(), void validate(Event),
13 [String type = 'foo']) { 13 [String type = 'foo']) {
14 test(name, () { 14 test(name, () {
15 final el = new Element.tag('div'); 15 final el = new Element.tag('div');
16 var fired = false; 16 var fired = false;
17 el.on[type].add((ev) { 17 el.on[type].add((ev) {
18 fired = true; 18 fired = true;
19 validate(ev); 19 validate(ev);
20 }); 20 });
21 el.on[type].dispatch(eventFn()); 21 el.on[type].dispatch(eventFn());
22 Expect.isTrue(fired, 'Expected event to be dispatched.'); 22 expect(fired, isTrue, reason: 'Expected event to be dispatched.');
23 }); 23 });
24 } 24 }
25 25
26 main() { 26 main() {
27 useHtmlConfiguration(); 27 useHtmlConfiguration();
28 28
29 // Issue 1005. 29 // Issue 1005.
30 // eventTest('AnimationEvent', () => new AnimationEvent('foo', 'color', 0.5), 30 // eventTest('AnimationEvent', () => new AnimationEvent('foo', 'color', 0.5),
31 // (ev) { 31 // (ev) {
32 // Expect.equals('color', ev.animationName); 32 // expect(ev.animationName, 'color');
33 // Expect.equals(0.5, ev.elapsedTime); 33 // expect(ev.elapsedTime, 0.5);
34 // }); 34 // });
35 35
36 // Issue 1005. 36 // Issue 1005.
37 // eventTest('BeforeLoadEvent', 37 // eventTest('BeforeLoadEvent',
38 // () => new BeforeLoadEvent('foo', 'http://example.url'), 38 // () => new BeforeLoadEvent('foo', 'http://example.url'),
39 // (ev) { Expect.equals('http://example.url', ev.url); }); 39 // (ev) { expect(ev.url, 'http://example.url'); });
40 40
41 // Issue 1005. 41 // Issue 1005.
42 // eventTest('CloseEvent', 42 // eventTest('CloseEvent',
43 // () => new CloseEvent('foo', 5, 'reason', wasClean: true), 43 // () => new CloseEvent('foo', 5, 'reason', wasClean: true),
44 // (ev) { 44 // (ev) {
45 // Expect.equals(5, ev.code); 45 // expect(ev.code, 5);
46 // Expect.equals('reason', ev.reason); 46 // expect(ev.reason, 'reason');
47 // Expect.isTrue(ev.wasClean); 47 // expect(ev.wasClean, isTrue);
48 // }); 48 // });
49 49
50 eventTest('CompositionEvent', 50 eventTest('CompositionEvent',
51 () => new CompositionEvent('compositionstart', window, 'data'), 51 () => new CompositionEvent('compositionstart', window, 'data'),
52 (ev) { Expect.equals('data', ev.data); }, 52 (ev) { expect(ev.data, 'data'); },
53 type: 'compositionstart'); 53 type: 'compositionstart');
54 54
55 // initCustomEvent is not yet implemented 55 // initCustomEvent is not yet implemented
56 // eventTest('CustomEvent', 56 // eventTest('CustomEvent',
57 // () => new CustomEvent('foo', false, false, 'detail'), 57 // () => new CustomEvent('foo', false, false, 'detail'),
58 // (ev) { Expect.equals('detail', ev.detail); }); 58 // (ev) { expect(ev.detail, 'detail'); });
59 59
60 // DeviceMotionEvent has no properties to itself, so just test that it doesn't 60 // DeviceMotionEvent has no properties to itself, so just test that it doesn't
61 // error out on creation and can be dispatched. 61 // error out on creation and can be dispatched.
62 eventTest('DeviceMotionEvent', () => new DeviceMotionEvent('foo'), (ev) {}); 62 eventTest('DeviceMotionEvent', () => new DeviceMotionEvent('foo'), (ev) {});
63 63
64 // initDeviceOrientationEvent is not yet implemented 64 // initDeviceOrientationEvent is not yet implemented
65 // eventTest('DeviceOrientationEvent', 65 // eventTest('DeviceOrientationEvent',
66 // () => new DeviceOrientationEvent('foo', 0.1, 0.2, 0.3), 66 // () => new DeviceOrientationEvent('foo', 0.1, 0.2, 0.3),
67 // (ev) { 67 // (ev) {
68 // Expect.equals(0.1, ev.alpha); 68 // expect(ev.alpha, 0.1);
69 // Expect.equals(0.2, ev.beta); 69 // expect(ev.beta, 0.2);
70 // Expect.equals(0.3, ev.gamma); 70 // expect(ev.gamma, 0.3);
71 // }); 71 // });
72 72
73 // Issue 1005. 73 // Issue 1005.
74 // eventTest('ErrorEvent', 74 // eventTest('ErrorEvent',
75 // () => new ErrorEvent('foo', 'message', 'filename', 10), 75 // () => new ErrorEvent('foo', 'message', 'filename', 10),
76 // (ev) { 76 // (ev) {
77 // Expect.equals('message', ev.message); 77 // expect('message', ev.message);
78 // Expect.equals('filename', ev.filename); 78 // expect('filename', ev.filename);
79 // Expect.equals(10, ev.lineno); 79 // expect(ev.lineno, 10);
80 // }); 80 // });
81 81
82 eventTest('Event', 82 eventTest('Event',
83 () => new Event('foo', canBubble: false, cancelable: false), 83 () => new Event('foo', canBubble: false, cancelable: false),
84 (ev) { 84 (ev) {
85 Expect.equals('foo', ev.type); 85 expect(ev.type, equals('foo'));
86 Expect.isFalse(ev.bubbles); 86 expect(ev.bubbles, isFalse);
87 Expect.isFalse(ev.cancelable); 87 expect(ev.cancelable, isFalse);
88 }); 88 });
89 89
90 eventTest('HashChangeEvent', 90 eventTest('HashChangeEvent',
91 () => new HashChangeEvent('foo', 'http://old.url', 'http://new.url'), 91 () => new HashChangeEvent('foo', 'http://old.url', 'http://new.url'),
92 (ev) { 92 (ev) {
93 Expect.equals('http://old.url', ev.oldURL); 93 expect(ev.oldURL, equals('http//old.url'));
94 Expect.equals('http://new.url', ev.newURL); 94 expect(ev.newURL, equals('http://new.url'));
95 }); 95 });
96 96
97 eventTest('KeyboardEvent', 97 eventTest('KeyboardEvent',
98 () => new KeyboardEvent('foo', window, 'key', 10, ctrlKey: true, 98 () => new KeyboardEvent('foo', window, 'key', 10, ctrlKey: true,
99 altKey: true, shiftKey: true, metaKey: true, altGraphKey: true), 99 altKey: true, shiftKey: true, metaKey: true, altGraphKey: true),
100 (ev) { 100 (ev) {
101 Expect.equals('key', ev.keyIdentifier); 101 expect.equals(ev.keyIdentifier, equals('key'));
102 Expect.equals(10, ev.keyLocation); 102 expect.equals(ev.keyLocation, equals(10));
103 Expect.isTrue(ev.ctrlKey); 103 expect(ev.ctrlKey, isTrue);
104 Expect.isTrue(ev.altKey); 104 expect(ev.altKey, isTrue);
105 Expect.isTrue(ev.shiftKey); 105 expect(ev.shiftKey, isTrue);
106 Expect.isTrue(ev.metaKey); 106 expect(ev.metaKey, isTrue);
107 Expect.isTrue(ev.altGraphKey); 107 expect(ev.altGraphKey, isTrue);
108 }); 108 });
109 109
110 eventTest('MouseEvent', 110 eventTest('MouseEvent',
111 // canBubble and cancelable are currently required to avoid dartc 111 // canBubble and cancelable are currently required to avoid dartc
112 // complaining about the types of the named arguments. 112 // complaining about the types of the named arguments.
113 () => new MouseEvent('foo', window, 1, 2, 3, 4, 5, 6, canBubble: true, 113 () => new MouseEvent('foo', window, 1, 2, 3, 4, 5, 6, canBubble: true,
114 cancelable: true, ctrlKey: true, altKey: true, shiftKey: true, 114 cancelable: true, ctrlKey: true, altKey: true, shiftKey: true,
115 metaKey: true, relatedTarget: new Element.tag('div')), 115 metaKey: true, relatedTarget: new Element.tag('div')),
116 (ev) { 116 (ev) {
117 Expect.equals(1, ev.detail); 117 expect(ev.detail, 1);
118 Expect.equals(2, ev.screenX); 118 expect(ev.screenX, 2);
119 Expect.equals(3, ev.screenY); 119 expect(ev.screenYi, 3);
120 Expect.equals(4, ev.clientX); 120 expect(ev.clientX, 4);
121 Expect.equals(5, ev.clientY); 121 expect(ev.clientY, 5);
122 Expect.equals(4, ev.offsetX); // Same as clientX. 122 expect(ev.offsetX, 4); // Same as clientX.
123 Expect.equals(5, ev.offsetY); // Same as clientY. 123 expect(ev.offsetY, 5); // Same as clientY.
124 Expect.equals(6, ev.button); 124 expect(ev.button, 6);
125 Expect.isTrue(ev.ctrlKey); 125 expect(ev.ctrlKey, isTrue);
126 Expect.isTrue(ev.altKey); 126 expect(ev.altKey, isTrue);
127 Expect.isTrue(ev.shiftKey); 127 expect(ev.shiftKey, isTrue);
128 Expect.isTrue(ev.metaKey); 128 expect(ev.metaKey, isTrue);
129 Expect.equals('DIV', ev.relatedTarget.tagName); 129 expect(ev.relatedTarget.tagName, 'DIV');
130 }); 130 });
131 131
132 eventTest('MutationEvent', 132 eventTest('MutationEvent',
133 () => new MutationEvent('foo', new Element.tag('div'), 'red', 'blue', 133 () => new MutationEvent('foo', new Element.tag('div'), 'red', 'blue',
134 'color', MutationEvent.MODIFICATION), 134 'color', MutationEvent.MODIFICATION),
135 (ev) { 135 (ev) {
136 Expect.equals('DIV', ev.relatedNode.tagName); 136 expect(ev.relatedNode.tagName, 'DIV');
137 Expect.equals('red', ev.prevValue); 137 expect.equals(ev.prevValue, 'red');
138 Expect.equals('blue', ev.newValue); 138 expect.equals(ev.newValue, 'blue');
139 Expect.equals('color', ev.attrName); 139 expect.equals(ev.attrName, 'color');
140 Expect.equals(MutationEvent.MODIFICATION, ev.attrChange); 140 expect.equals(ev.attrChange, equals(MutationEvent.MODIFICATION));
141 }); 141 });
142 142
143 test('DOMMutationEvent', () { 143 test('DOMMutationEvent', () {
144 var div = new DivElement(); 144 var div = new DivElement();
145 div.on['DOMSubtreeModified'].add(expectAsync1((DOMMutationEvent e) {})); 145 div.on['DOMSubtreeModified'].add(expectAsync1((DOMMutationEvent e) {}));
146 div.nodes.add(new SpanElement()); 146 div.nodes.add(new SpanElement());
147 }); 147 });
148 148
149 // Issue 1005. 149 // Issue 1005.
150 // eventTest('OverflowEvent', 150 // eventTest('OverflowEvent',
151 // () => new OverflowEvent(OverflowEvent.BOTH, true, true), 151 // () => new OverflowEvent(OverflowEvent.BOTH, true, true),
152 // (ev) { 152 // (ev) {
153 // Expect.equals(OverflowEvent.BOTH, ev.orient); 153 // expect(ev.orient, OverflowEvent.BOTH);
154 // Expect.isTrue(ev.horizontalOverflow); 154 // expect(ev.horizontalOverflow, isTrue);
155 // Expect.isTrue(ev.verticalOverflow); 155 // expect(ev.verticalOverflow, isTrue);
156 // }, type: 'overflowchanged'); 156 // }, type: 'overflowchanged');
157 157
158 // Issue 1005. 158 // Issue 1005.
159 // eventTest('PageTransitionEvent', 159 // eventTest('PageTransitionEvent',
160 // () => new PageTransitionEvent('foo', persisted: true), 160 // () => new PageTransitionEvent('foo', persisted: true),
161 // (ev) { Expect.isTrue(ev.persisted); }); 161 // (ev) { expect(ev.persisted, isTrue); });
162 162
163 // initPopStateEvent is not yet implemented 163 // initPopStateEvent is not yet implemented
164 // eventTest('PopStateEvent', () => new PopStateEvent('foo', 'state'), 164 // eventTest('PopStateEvent', () => new PopStateEvent('foo', 'state'),
165 // (ev) { Expect.equals('state', ev.state); } 165 // (ev) { expect(ev.state, 'state'); }
166 166
167 // Issue 1005. 167 // Issue 1005.
168 // eventTest('ProgressEvent', 168 // eventTest('ProgressEvent',
169 // // canBubble and cancelable are currently required to avoid dartc 169 // // canBubble and cancelable are currently required to avoid dartc
170 // // complaining about the types of the named arguments. 170 // // complaining about the types of the named arguments.
171 // () => new ProgressEvent('foo', 5, canBubble: true, cancelable: true, 171 // () => new ProgressEvent('foo', 5, canBubble: true, cancelable: true,
172 // lengthComputable: true, total: 10), 172 // lengthComputable: true, total: 10),
173 // (ev) { 173 // (ev) {
174 // Expect.equals(5, ev.loaded); 174 // expect(ev.loaded, 5);
175 // Expect.isTrue(ev.lengthComputable); 175 // expect(ev.lengthComputable, isTrue);
176 // Expect.equals(10, ev.total); 176 // expect(ev.total, 10);
177 // }); 177 // });
178 178
179 eventTest('StorageEvent', 179 eventTest('StorageEvent',
180 () => new StorageEvent('foo', 'key', 'http://example.url', 180 () => new StorageEvent('foo', 'key', 'http://example.url',
181 window.localStorage, canBubble: true, cancelable: true, 181 window.localStorage, canBubble: true, cancelable: true,
182 oldValue: 'old', newValue: 'new'), 182 oldValue: 'old', newValue: 'new'),
183 (ev) { 183 (ev) {
184 Expect.equals('key', ev.key); 184 expect(ev.key, 'key');
185 Expect.equals('http://example.url', ev.url); 185 expect(ev.url, 'http://example.url');
186 // Equality isn't preserved for storageArea 186 // Equality isn't preserved for storageArea
187 Expect.isNotNull(ev.storageArea); 187 expect.isNotNull(ev.storageArea);
188 Expect.equals('old', ev.oldValue); 188 expect(ev.oldValue, 'old');
189 Expect.equals('new', ev.newValue); 189 expect(ev.newValue, 'new');
190 }); 190 });
191 191
192 eventTest('TextEvent', () => new TextEvent('foo', window, 'data'), 192 eventTest('TextEvent', () => new TextEvent('foo', window, 'data'),
193 (ev) { Expect.equals('data', ev.data); }); 193 (ev) { expect(ev.data, 'data'); });
194 194
195 // Issue 1005. 195 // Issue 1005.
196 // eventTest('TransitionEvent', () => new TransitionEvent('foo', 'color', 0.5) , 196 // eventTest('TransitionEvent', () => new TransitionEvent('foo', 'color', 0.5) ,
197 // (ev) { 197 // (ev) {
198 // Expect.equals('color', ev.propertyName); 198 // expect(ev.propertyName, 'color');
199 // Expect.equals(0.5, ev.elapsedTime); 199 // expect(ev.elapsedTime, 0.5);
200 // }); 200 // });
201 201
202 eventTest('UIEvent', () => new UIEvent('foo', window, 12), 202 eventTest('UIEvent', () => new UIEvent('foo', window, 12),
203 (ev) { 203 (ev) {
204 Expect.equals(window, ev.view); 204 expect(window, ev.view, window);
205 Expect.equals(12, ev.detail); 205 expect(12, ev.detail, 12);
206 }); 206 });
207 207
208 eventTest('WheelEvent', 208 eventTest('WheelEvent',
209 () => new WheelEvent(1, 2, window, 3, 4, 5, 6, ctrlKey: true, 209 () => new WheelEvent(1, 2, window, 3, 4, 5, 6, ctrlKey: true,
210 altKey: true, shiftKey: true, metaKey: true), 210 altKey: true, shiftKey: true, metaKey: true),
211 (ev) { 211 (ev) {
212 // wheelDelta* properties are multiplied by 120 for some reason 212 // wheelDelta* properties are multiplied by 120 for some reason
213 Expect.equals(120, ev.wheelDeltaX); 213 expect(ev.wheelDeltaX, 120);
214 Expect.equals(240, ev.wheelDeltaY); 214 expect(ev.wheelDeltaY, 240);
215 Expect.equals(3, ev.screenX); 215 expect(ev.screenX, 3);
216 Expect.equals(4, ev.screenY); 216 expect(ev.screenY, 4);
217 Expect.equals(5, ev.clientX); 217 expect(ev.clientX, 5);
218 Expect.equals(6, ev.clientY); 218 expect(ev.clientY, 6);
219 Expect.isTrue(ev.ctrlKey); 219 expect(ev.ctrlKey, isTrue);
220 Expect.isTrue(ev.altKey); 220 expect(ev.altKey, isTrue);
221 Expect.isTrue(ev.shiftKey); 221 expect(ev.shiftKey, isTrue);
222 Expect.isTrue(ev.metaKey); 222 expect(ev.metaKey, isTrue);
223 }, type: 'mousewheel'); 223 }, type: 'mousewheel');
224 224
225 // HttpRequestProgressEvent has no properties to itself, so just test that 225 // HttpRequestProgressEvent has no properties to itself, so just test that
226 // it doesn't error out on creation and can be dispatched. 226 // it doesn't error out on creation and can be dispatched.
227 // Issue 1005. 227 // Issue 1005.
228 // eventTest('HttpRequestProgressEvent', 228 // eventTest('HttpRequestProgressEvent',
229 // () => new HttpRequestProgressEvent('foo', 5), 229 // () => new HttpRequestProgressEvent('foo', 5),
230 // (ev) {}); 230 // (ev) {});
231 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698