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

Unified Diff: client/tests/client/html/EventTests.dart

Issue 8404013: Add constructors to all the event classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: client/tests/client/html/EventTests.dart
diff --git a/client/tests/client/html/EventTests.dart b/client/tests/client/html/EventTests.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a3a73371b44e4dd0cbbe165ea4473c0fc86c4783
--- /dev/null
+++ b/client/tests/client/html/EventTests.dart
@@ -0,0 +1,185 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+testEvents() {
+ test('AnimationEvent', () {
Jacob 2011/10/27 21:23:05 suggested additional tests: make sure that some of
nweiz 2011/10/27 22:23:54 Done. I figured out a moderately nice way of testi
+ var ev = new AnimationEvent('foo', 'color', 0.5);
+ Expect.equals('color', ev.animationName);
+ Expect.equals(0.5, ev.elapsedTime);
+ });
+
+ test('BeforeLoadEvent', () {
+ var ev = new BeforeLoadEvent('foo', 'http://example.url');
+ Expect.equals('http://example.url', ev.url);
+ });
+
+ test('CloseEvent', () {
+ var ev = new CloseEvent('foo', 5, 'reason', wasClean: true);
+ Expect.equals(5, ev.code);
+ Expect.equals('reason', ev.reason);
+ Expect.isTrue(ev.wasClean);
+ });
+
+ test('CompositionEvent', () {
+ var ev = new CompositionEvent('compositionstart', window, 'data');
+ Expect.equals('data', ev.data);
+ });
+
+ test('CustomEvent', () {
+ return; // initCustomEvent is not yet implemented
+ var ev = new CustomEvent('foo', false, false, 'detail');
+ Expect.equals('detail', ev.detail);
+ });
+
+ // DeviceMotionEvent has no properties to itself, so just test that it doesn't
+ // error out on creation.
+ test('DeviceMotionEvent', () => new DeviceMotionEvent('foo'));
+
+ test('DeviceOrientationEvent', () {
+ return; // initDeviceOrientationEvent is not yet implemented
+ var ev = new DeviceOrientationEvent('foo', 0.1, 0.2, 0.3);
+ Expect.equals(0.1, ev.alpha);
+ Expect.equals(0.2, ev.beta);
+ Expect.equals(0.3, ev.gamma);
+ });
+
+ test('ErrorEvent', () {
+ var ev = new ErrorEvent('foo', 'message', 'filename', 10);
+ Expect.equals('message', ev.message);
+ Expect.equals('filename', ev.filename);
+ Expect.equals(10, ev.lineno);
+ });
+
+ test('Event', () {
+ var ev = new Event('foo', canBubble: true, cancelable: true);
+ Expect.equals('foo', ev.type);
+ Expect.isTrue(ev.bubbles);
+ Expect.isTrue(ev.cancelable);
+ });
+
+ test('HashChangeEvent', () {
+ var ev = new HashChangeEvent('foo', 'http://old.url', 'http://new.url');
+ Expect.equals('http://old.url', ev.oldURL);
+ Expect.equals('http://new.url', ev.newURL);
+ });
+
+ test('KeyboardEvent', () {
+ var ev = new KeyboardEvent('foo', window, 'key', 10, ctrlKey: true,
+ altKey: true, shiftKey: true, metaKey: true, altGraphKey: true);
+ Expect.equals('key', ev.keyIdentifier);
+ Expect.equals(10, ev.keyLocation);
+ Expect.isTrue(ev.ctrlKey);
+ Expect.isTrue(ev.altKey);
+ Expect.isTrue(ev.shiftKey);
+ Expect.isTrue(ev.metaKey);
+ Expect.isTrue(ev.altGraphKey);
+ });
+
+ test('MouseEvent', () {
+ // canBubble and cancelable are currently required to avoid dartc
+ // complaining about the types of the named arguments.
+ var ev = new MouseEvent('foo', window, 1, 2, 3, 4, 5, 6, canBubble: false,
+ cancelable: false, ctrlKey: true, altKey: true, shiftKey: true,
+ metaKey: true, relatedTarget: new Element.tag('div'));
+ Expect.equals(1, ev.detail);
+ Expect.equals(2, ev.screenX);
+ Expect.equals(3, ev.screenY);
+ Expect.equals(4, ev.clientX);
+ Expect.equals(5, ev.clientY);
+ Expect.equals(6, ev.button);
+ Expect.isTrue(ev.ctrlKey);
+ Expect.isTrue(ev.altKey);
+ Expect.isTrue(ev.shiftKey);
+ Expect.isTrue(ev.metaKey);
+ Expect.equals('DIV', ev.relatedTarget.tagName);
+ });
+
+ test('MutationEvent', () {
+ var ev = new MutationEvent('foo', new Element.tag('div'), 'red', 'blue',
+ 'color', MutationEvent.MODIFICATION);
+ Expect.equals('DIV', ev.relatedNode.tagName);
+ Expect.equals('red', ev.prevValue);
+ Expect.equals('blue', ev.newValue);
+ Expect.equals('color', ev.attrName);
+ Expect.equals(MutationEvent.MODIFICATION, ev.attrChange);
+ });
+
+ test('OverflowEvent', () {
+ var ev = new OverflowEvent(OverflowEvent.BOTH, true, true);
+ Expect.equals(OverflowEvent.BOTH, ev.orient);
+ Expect.isTrue(ev.horizontalOverflow);
+ Expect.isTrue(ev.verticalOverflow);
+ });
+
+ test('PageTransitionEvent', () {
+ var ev = new PageTransitionEvent('foo', persisted: true);
+ Expect.isTrue(ev.persisted);
+ });
+
+ test('PopStateEvent', () {
+ return; // initPopStateEvent is not yet implemented
+ var ev = new PopStateEvent('foo', 'state');
+ Expect.equals('state', ev.state);
+ });
+
+ test('ProgressEvent', () {
+ // canBubble and cancelable are currently required to avoid dartc
+ // complaining about the types of the named arguments.
+ var ev = new ProgressEvent('foo', 5, canBubble: false, cancelable: false,
+ lengthComputable: true, total: 10);
+ Expect.equals(5, ev.loaded);
+ Expect.isTrue(ev.lengthComputable);
+ Expect.equals(10, ev.total);
+ });
+
+ test('StorageEvent', () {
+ var ev = new StorageEvent('foo', 'key', 'http://example.url',
+ window.localStorage, canBubble: false, cancelable: false,
+ oldValue: 'old', newValue: 'new');
+ Expect.equals('key', ev.key);
+ Expect.equals('http://example.url', ev.url);
+ // Equality isn't preserved for storageArea
+ Expect.isNotNull(ev.storageArea);
+ Expect.equals('old', ev.oldValue);
+ Expect.equals('new', ev.newValue);
+ });
+
+ test('TextEvent', () {
+ var ev = new TextEvent('foo', window, 'data');
+ Expect.equals('data', ev.data);
+ });
+
+ test('TransitionEvent', () {
+ var ev = new TransitionEvent('foo', 'color', 0.5);
+ Expect.equals('color', ev.propertyName);
+ Expect.equals(0.5, ev.elapsedTime);
+ });
+
+ test('UIEvent', () {
+ var ev = new UIEvent('foo', window, 12);
+ Expect.equals(window, ev.view);
+ Expect.equals(12, ev.detail);
+ });
+
+ test('WheelEvent', () {
+ var ev = new WheelEvent(1, 2, window, 3, 4, 5, 6, ctrlKey: true,
+ altKey: true, shiftKey: true, metaKey: true);
+ // wheelDelta* properties are multiplied by 120 for some reason
+ Expect.equals(120, ev.wheelDeltaX);
+ Expect.equals(240, ev.wheelDeltaY);
+ Expect.equals(3, ev.screenX);
+ Expect.equals(4, ev.screenY);
+ Expect.equals(5, ev.clientX);
+ Expect.equals(6, ev.clientY);
+ Expect.isTrue(ev.ctrlKey);
+ Expect.isTrue(ev.altKey);
+ Expect.isTrue(ev.shiftKey);
+ Expect.isTrue(ev.metaKey);
+ });
+
+ // XMLHttpRequestProgressEvent has no properties to itself, so just test that
+ // it doesn't error out on creation.
+ test('XMLHttpRequestProgressEvent', () =>
+ new XMLHttpRequestProgressEvent('foo', 5));
+}

Powered by Google App Engine
This is Rietveld 408576698