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

Side by Side Diff: test/codegen/lib/html/event_test.dart

Issue 1930043002: Add all dart:html tests from the sdk to test/codegen. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: ptal Created 4 years, 7 months 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library EventTest;
6 import "package:expect/expect.dart";
7 import 'package:unittest/unittest.dart';
8 import 'package:unittest/html_config.dart';
9 import 'dart:html';
10
11 // TODO(nweiz): Make this private to testEvents when Frog supports closures with
12 // optional arguments.
13 eventTest(String name, Event eventFn(), void validate(Event),
14 [String type = 'foo']) {
15 test(name, () {
16 final el = new Element.tag('div');
17 var fired = false;
18 el.on[type].listen((ev) {
19 fired = true;
20 validate(ev);
21 });
22 el.dispatchEvent(eventFn());
23 expect(fired, isTrue, reason: 'Expected event to be dispatched.');
24 });
25 }
26
27 main() {
28 useHtmlConfiguration();
29
30 // Issue 1005.
31 // eventTest('AnimationEvent', () => new AnimationEvent('foo', 'color', 0.5),
32 // (ev) {
33 // expect(ev.animationName, 'color');
34 // expect(ev.elapsedTime, 0.5);
35 // });
36
37 // Issue 1005.
38 // eventTest('BeforeLoadEvent',
39 // () => new BeforeLoadEvent('foo', 'http://example.url'),
40 // (ev) { expect(ev.url, 'http://example.url'); });
41
42 // Issue 1005.
43 // eventTest('CloseEvent',
44 // () => new CloseEvent('foo', 5, 'reason', wasClean: true),
45 // (ev) {
46 // expect(ev.code, 5);
47 // expect(ev.reason, 'reason');
48 // expect(ev.wasClean, isTrue);
49 // });
50
51 eventTest('CompositionEvent',
52 () => new CompositionEvent('compositionstart', view: window, data: 'data') ,
53 (ev) { expect(ev.data, 'data'); },
54 'compositionstart');
55
56 // initCustomEvent is not yet implemented
57 // eventTest('CustomEvent',
58 // () => new CustomEvent('foo', false, false, 'detail'),
59 // (ev) { expect(ev.detail, 'detail'); });
60
61 // DeviceMotionEvent has no properties to itself, so just test that it doesn't
62 // error out on creation and can be dispatched.
63 // Suppress. DeviceMotion has no constructor, and I don't think it can be
64 // created on a non-mobile device. Issue 23321
65 // eventTest('DeviceMotionEvent', () => new DeviceMotionEvent('foo'), (ev) {}) ;
66
67 // initDeviceOrientationEvent is not yet implemented
68 // eventTest('DeviceOrientationEvent',
69 // () => new DeviceOrientationEvent('foo', 0.1, 0.2, 0.3),
70 // (ev) {
71 // expect(ev.alpha, 0.1);
72 // expect(ev.beta, 0.2);
73 // expect(ev.gamma, 0.3);
74 // });
75
76 // Issue 1005.
77 // eventTest('ErrorEvent',
78 // () => new ErrorEvent('foo', 'message', 'filename', 10),
79 // (ev) {
80 // expect('message', ev.message);
81 // expect('filename', ev.filename);
82 // expect(ev.lineno, 10);
83 // });
84
85 eventTest('Event',
86 () => new Event('foo', canBubble: false, cancelable: false),
87 (ev) {
88 expect(ev.type, equals('foo'));
89 expect(ev.bubbles, isFalse);
90 expect(ev.cancelable, isFalse);
91 });
92
93 eventTest('HashChangeEvent',
94 () => new HashChangeEvent('foo', oldUrl: 'http://old.url',
95 newUrl: 'http://new.url'), (ev) {
96 expect(ev.oldUrl, equals('http://old.url'));
97 expect(ev.newUrl, equals('http://new.url'));
98 });
99
100 // KeyboardEvent has its own test file, and has cross-browser issues.
101
102 eventTest('MouseEvent',
103 () => new MouseEvent('foo', view: window, detail: 1, screenX: 2,
104 screenY: 3, clientX: 4, clientY: 5, button: 6,
105 ctrlKey: true, altKey: true, shiftKey: true,
106 metaKey: true, relatedTarget: document.body),
107 (ev) {
108 expect(ev.detail, 1);
109 expect(ev.screen.x, 2);
110 expect(ev.screen.y, 3);
111 expect(ev.client.x, 4);
112 expect(ev.client.y, 5);
113 expect(ev.offset.x, 4); // Same as clientX.
114 expect(ev.offset.y, 5); // Same as clientY.
115 expect(ev.button, 6);
116 expect(ev.ctrlKey, isTrue);
117 expect(ev.altKey, isTrue);
118 expect(ev.shiftKey, isTrue);
119 expect(ev.metaKey, isTrue);
120 // TODO(alanknight): The target does not seem to get correctly set.
121 // Issue 23438
122 // expect(ev.relatedTarget, document.body);
123 });
124
125 // Issue 1005.
126 // eventTest('OverflowEvent',
127 // () => new OverflowEvent(OverflowEvent.BOTH, true, true),
128 // (ev) {
129 // expect(ev.orient, OverflowEvent.BOTH);
130 // expect(ev.horizontalOverflow, isTrue);
131 // expect(ev.verticalOverflow, isTrue);
132 // }, type: 'overflowchanged');
133
134 // Issue 1005.
135 // eventTest('PageTransitionEvent',
136 // () => new PageTransitionEvent('foo', persisted: true),
137 // (ev) { expect(ev.persisted, isTrue); });
138
139 // initPopStateEvent is not yet implemented
140 // eventTest('PopStateEvent', () => new PopStateEvent('foo', 'state'),
141 // (ev) { expect(ev.state, 'state'); }
142
143 // Issue 1005.
144 // eventTest('ProgressEvent',
145 // // canBubble and cancelable are currently required to avoid dartc
146 // // complaining about the types of the named arguments.
147 // () => new ProgressEvent('foo', 5, canBubble: true, cancelable: true,
148 // lengthComputable: true, total: 10),
149 // (ev) {
150 // expect(ev.loaded, 5);
151 // expect(ev.lengthComputable, isTrue);
152 // expect(ev.total, 10);
153 // });
154
155 eventTest('StorageEvent',
156 () => new StorageEvent('foo', key: 'key', url: 'http://example.url',
157 storageArea: window.localStorage, canBubble: true, cancelable: true,
158 oldValue: 'old', newValue: 'new'),
159 (ev) {
160 expect(ev.key, 'key');
161 expect(ev.url, 'http://example.url');
162 // Equality isn't preserved for storageArea
163 expect(ev.storageArea, isNotNull);
164 expect(ev.oldValue, 'old');
165 expect(ev.newValue, 'new');
166 });
167
168 // Issue 1005.
169 // eventTest('TransitionEvent', () => new TransitionEvent('foo', 'color', 0.5) ,
170 // (ev) {
171 // expect(ev.propertyName, 'color');
172 // expect(ev.elapsedTime, 0.5);
173 // });
174
175 eventTest('UIEvent', () => new UIEvent('foo', view: window, detail: 12),
176 (ev) {
177 expect(window, ev.view);
178 expect(12, ev.detail);
179 });
180
181 eventTest('WheelEvent',
182 // TODO(alanknight): Can't pass window on Dartium. Add view: window
183 // once going through JS.
184 () => new WheelEvent("mousewheel", deltaX: 1, deltaY: 0,
185 detail: 4, screenX: 3, screenY: 4, clientX: 5, clientY: 6,
186 ctrlKey: true, altKey: true, shiftKey: true, metaKey: true),
187 (ev) {
188 expect(ev.deltaX, 1);
189 expect(ev.deltaY, 0);
190 expect(ev.screen.x, 3);
191 expect(ev.screen.y, 4);
192 expect(ev.client.x, 5);
193 expect(ev.client.y, 6);
194 expect(ev.ctrlKey, isTrue);
195 expect(ev.altKey, isTrue);
196 expect(ev.shiftKey, isTrue);
197 expect(ev.metaKey, isTrue);
198 }, 'mousewheel');
199 }
OLDNEW
« no previous file with comments | « test/codegen/lib/html/event_customevent_test.dart ('k') | test/codegen/lib/html/events_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698