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

Side by Side Diff: test/codegen/lib/html/keyboard_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
« no previous file with comments | « test/codegen/lib/html/json_helper.dart ('k') | test/codegen/lib/html/localstorage_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 library KeyboardEventTest;
2 import 'package:unittest/unittest.dart';
3 import 'package:unittest/html_config.dart';
4 import 'dart:html';
5
6 // Test that we are correctly determining keyCode and charCode uniformly across
7 // browsers.
8
9 main() {
10
11 useHtmlConfiguration();
12
13 keydownHandlerTest(KeyEvent e) {
14 expect(e.charCode, 0);
15 }
16
17 test('keyboardEvent constructor', () {
18 var event = new KeyboardEvent('keyup');
19 });
20 test('keys', () {
21 var subscription = KeyboardEventStream.onKeyDown(document.body).listen(
22 keydownHandlerTest);
23 var subscription2 = KeyEvent.keyDownEvent.forTarget(document.body).listen(
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(expectAsync((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(expectAsync((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(expectAsync((keyEvent) {
60 expect(keyEvent.keyCode, isIn([16, 191]));
61 expect(keyEvent.charCode, 0);
62 }, count: 2));
63
64 var subscription2 = streamPress.listen(expectAsync((keyEvent) {
65 expect(keyEvent.keyCode, 23);
66 expect(keyEvent.charCode, 63);
67 }));
68
69 var subscription3 = streamUp.listen(expectAsync((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(expectAsync((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));
92 });
93 }
94
95
OLDNEW
« no previous file with comments | « test/codegen/lib/html/json_helper.dart ('k') | test/codegen/lib/html/localstorage_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698