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

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

Issue 218273002: Upgrading tests with unittest deprecations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 library KeyboardEventTest; 1 library KeyboardEventTest;
2 import '../../pkg/unittest/lib/unittest.dart'; 2 import '../../pkg/unittest/lib/unittest.dart';
3 import '../../pkg/unittest/lib/html_config.dart'; 3 import '../../pkg/unittest/lib/html_config.dart';
4 import 'dart:html'; 4 import 'dart:html';
5 5
6 // Test that we are correctly determining keyCode and charCode uniformly across 6 // Test that we are correctly determining keyCode and charCode uniformly across
7 // browsers. 7 // browsers.
8 8
9 main() { 9 main() {
10 10
(...skipping 13 matching lines...) Expand all
24 keydownHandlerTest); 24 keydownHandlerTest);
25 var subscription3 = document.body.onKeyDown.listen( 25 var subscription3 = document.body.onKeyDown.listen(
26 (e) => print('regular listener')); 26 (e) => print('regular listener'));
27 subscription.cancel(); 27 subscription.cancel();
28 subscription2.cancel(); 28 subscription2.cancel();
29 subscription3.cancel(); 29 subscription3.cancel();
30 }); 30 });
31 31
32 test('constructKeyEvent', () { 32 test('constructKeyEvent', () {
33 var stream = KeyEvent.keyPressEvent.forTarget(document.body); 33 var stream = KeyEvent.keyPressEvent.forTarget(document.body);
34 var subscription = stream.listen(expectAsync1((keyEvent) { 34 var subscription = stream.listen(expectAsync((keyEvent) {
35 expect(keyEvent.charCode, 97); 35 expect(keyEvent.charCode, 97);
36 expect(keyEvent.keyCode, 65); 36 expect(keyEvent.keyCode, 65);
37 })); 37 }));
38 var k = new KeyEvent('keypress', keyCode: 65, charCode: 97); 38 var k = new KeyEvent('keypress', keyCode: 65, charCode: 97);
39 stream.add(k); 39 stream.add(k);
40 subscription.cancel(); 40 subscription.cancel();
41 // Capital "A": 41 // Capital "A":
42 stream.add(new KeyEvent('keydown', keyCode: 16, charCode: 0)); 42 stream.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
43 43
44 subscription = stream.listen(expectAsync1((keyEvent) { 44 subscription = stream.listen(expectAsync((keyEvent) {
45 expect(keyEvent.charCode, 65); 45 expect(keyEvent.charCode, 65);
46 expect(keyEvent.keyCode, 65); 46 expect(keyEvent.keyCode, 65);
47 })); 47 }));
48 stream.add(new KeyEvent('keypress', keyCode: 65, charCode: 65)); 48 stream.add(new KeyEvent('keypress', keyCode: 65, charCode: 65));
49 subscription.cancel(); 49 subscription.cancel();
50 }); 50 });
51 51
52 test('KeyEventSequence', () { 52 test('KeyEventSequence', () {
53 // Press "?" by simulating "shift" and then the key that has "/" and "?" on 53 // Press "?" by simulating "shift" and then the key that has "/" and "?" on
54 // it. 54 // it.
55 var streamDown = KeyEvent.keyDownEvent.forTarget(document.body); 55 var streamDown = KeyEvent.keyDownEvent.forTarget(document.body);
56 var streamPress = KeyEvent.keyPressEvent.forTarget(document.body); 56 var streamPress = KeyEvent.keyPressEvent.forTarget(document.body);
57 var streamUp = KeyEvent.keyUpEvent.forTarget(document.body); 57 var streamUp = KeyEvent.keyUpEvent.forTarget(document.body);
58 58
59 var subscription = streamDown.listen(expectAsync1((keyEvent) { 59 var subscription = streamDown.listen(expectAsync((keyEvent) {
60 expect(keyEvent.keyCode, isIn([16, 191])); 60 expect(keyEvent.keyCode, isIn([16, 191]));
61 expect(keyEvent.charCode, 0); 61 expect(keyEvent.charCode, 0);
62 }, count: 2)); 62 }, count: 2));
63 63
64 var subscription2 = streamPress.listen(expectAsync1((keyEvent) { 64 var subscription2 = streamPress.listen(expectAsync((keyEvent) {
65 expect(keyEvent.keyCode, 23); 65 expect(keyEvent.keyCode, 23);
66 expect(keyEvent.charCode, 63); 66 expect(keyEvent.charCode, 63);
67 })); 67 }));
68 68
69 var subscription3 = streamUp.listen(expectAsync1((keyEvent) { 69 var subscription3 = streamUp.listen(expectAsync((keyEvent) {
70 expect(keyEvent.keyCode, isIn([16, 191])); 70 expect(keyEvent.keyCode, isIn([16, 191]));
71 expect(keyEvent.charCode, 0); 71 expect(keyEvent.charCode, 0);
72 }, count: 2)); 72 }, count: 2));
73 73
74 streamDown.add(new KeyEvent('keydown', keyCode: 16, charCode: 0)); 74 streamDown.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
75 streamDown.add(new KeyEvent('keydown', keyCode: 191, charCode: 0)); 75 streamDown.add(new KeyEvent('keydown', keyCode: 191, charCode: 0));
76 76
77 streamPress.add(new KeyEvent('keypress', keyCode: 23, charCode: 63)); 77 streamPress.add(new KeyEvent('keypress', keyCode: 23, charCode: 63));
78 78
79 streamUp.add(new KeyEvent('keyup', keyCode: 191, charCode: 0)); 79 streamUp.add(new KeyEvent('keyup', keyCode: 191, charCode: 0));
80 streamUp.add(new KeyEvent('keyup', keyCode: 16, charCode: 0)); 80 streamUp.add(new KeyEvent('keyup', keyCode: 16, charCode: 0));
81 subscription.cancel(); 81 subscription.cancel();
82 subscription2.cancel(); 82 subscription2.cancel();
83 subscription3.cancel(); 83 subscription3.cancel();
84 }); 84 });
85 85
86 test('KeyEventKeyboardEvent', () { 86 test('KeyEventKeyboardEvent', () {
87 window.onKeyDown.listen(expectAsync1((KeyboardEvent event) { 87 window.onKeyDown.listen(expectAsync((KeyboardEvent event) {
88 expect(event.keyCode, 16); 88 expect(event.keyCode, 16);
89 })); 89 }));
90 var streamDown = KeyEvent.keyDownEvent.forTarget(document.body); 90 var streamDown = KeyEvent.keyDownEvent.forTarget(document.body);
91 streamDown.add(new KeyEvent('keydown', keyCode: 16, charCode: 0)); 91 streamDown.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
92 }); 92 });
93 } 93 }
94 94
95 95
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698