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

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

Issue 23455033: Fully polyfill KeyEvent so that you can programmatically create your own "keyboard" events. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 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
11 useHtmlConfiguration(); 11 useHtmlConfiguration();
12 12
13 keydownHandlerTest(KeyEvent e) { 13 keydownHandlerTest(KeyEvent e) {
14 expect(e.charCode, 0); 14 expect(e.charCode, 0);
15 } 15 }
16 16
17 test('keyboardEvent constructor', () { 17 test('keyboardEvent constructor', () {
18 var event = new KeyboardEvent('keyup'); 18 var event = new KeyboardEvent('keyup');
19 }); 19 });
20 test('keys', () { 20 test('keys', () {
21 // This test currently is pretty much a no-op because we 21 var subscription = KeyboardEventStream.onKeyDown(document.body).listen(
22 // can't (right now) construct KeyboardEvents with specific keycode/charcode
23 // values (a KeyboardEvent can be "init"-ed but not all the information can
24 // be programmatically populated. It exists as an example for how to use
25 // KeyboardEventController more than anything else.
26 KeyboardEventStream.onKeyDown(document.body).listen(
27 keydownHandlerTest); 22 keydownHandlerTest);
28 KeyEvent.keyDownEvent.forTarget(document.body).listen(keydownHandlerTest); 23 var subscription2 = KeyEvent.keyDownEvent.forTarget(document.body).listen(
29 document.body.onKeyDown.listen((e) => print('regular listener')); 24 keydownHandlerTest);
25 var subscription3 = document.body.onKeyDown.listen(
26 (e) => print('regular listener'));
27 subscription.cancel();
28 subscription2.cancel();
29 subscription3.cancel();
30 });
31
32 test('constructKeyEvent', () {
33 var stream = KeyEvent.keyPressEvent.forTarget(document.body);
34 var subscription = stream.listen(expectAsync1((keyEvent) {
35 expect(keyEvent.charCode, 97);
36 expect(keyEvent.keyCode, 65);
37 }));
38 var k = new KeyEvent('keypress', keyCode: 65, charCode: 97);
39 stream.add(k);
40 subscription.cancel();
41 // Capital "A":
42 stream.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
43
44 subscription = stream.listen(expectAsync1((keyEvent) {
45 expect(keyEvent.charCode, 65);
46 expect(keyEvent.keyCode, 65);
47 }));
48 stream.add(new KeyEvent('keypress', keyCode: 65, charCode: 65));
49 subscription.cancel();
50 });
51
52 test('KeyEventSequence', () {
53 // Press "?" by simulating "shift" and then the key that has "/" and "?" on
54 // it.
55 var streamDown = KeyEvent.keyDownEvent.forTarget(document.body);
56 var streamPress = KeyEvent.keyPressEvent.forTarget(document.body);
57 var streamUp = KeyEvent.keyUpEvent.forTarget(document.body);
58
59 var subscription = streamDown.listen(expectAsync1((keyEvent) {
60 expect(keyEvent.keyCode, isIn([16, 191]));
61 expect(keyEvent.charCode, 0);
62 }, count: 2));
63
64 var subscription2 = streamPress.listen(expectAsync1((keyEvent) {
65 expect(keyEvent.keyCode, 23);
66 expect(keyEvent.charCode, 63);
67 }));
68
69 var subscription3 = streamUp.listen(expectAsync1((keyEvent) {
70 expect(keyEvent.keyCode, isIn([16, 191]));
71 expect(keyEvent.charCode, 0);
72 }, count: 2));
73
74 streamDown.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
75 streamDown.add(new KeyEvent('keydown', keyCode: 191, charCode: 0));
76
77 streamPress.add(new KeyEvent('keypress', keyCode: 23, charCode: 63));
78
79 streamUp.add(new KeyEvent('keyup', keyCode: 191, charCode: 0));
80 streamUp.add(new KeyEvent('keyup', keyCode: 16, charCode: 0));
81 subscription.cancel();
82 subscription2.cancel();
83 subscription3.cancel();
84 });
85
86 test('KeyEventKeyboardEvent', () {
87 window.onKeyDown.listen(expectAsync1((KeyboardEvent event) {
88 expect(event.keyCode, 16);
89 }));
90 var streamDown = KeyEvent.keyDownEvent.forTarget(document.body);
91 streamDown.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
30 }); 92 });
31 } 93 }
32 94
33 95
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698