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

Unified 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, 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/lib/html/keyboard_event_test.dart
diff --git a/test/codegen/lib/html/keyboard_event_test.dart b/test/codegen/lib/html/keyboard_event_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8fca79351d611c1cba8ecbb642b5b21ae97e9773
--- /dev/null
+++ b/test/codegen/lib/html/keyboard_event_test.dart
@@ -0,0 +1,95 @@
+library KeyboardEventTest;
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
+import 'dart:html';
+
+// Test that we are correctly determining keyCode and charCode uniformly across
+// browsers.
+
+main() {
+
+ useHtmlConfiguration();
+
+ keydownHandlerTest(KeyEvent e) {
+ expect(e.charCode, 0);
+ }
+
+ test('keyboardEvent constructor', () {
+ var event = new KeyboardEvent('keyup');
+ });
+ test('keys', () {
+ var subscription = KeyboardEventStream.onKeyDown(document.body).listen(
+ keydownHandlerTest);
+ var subscription2 = KeyEvent.keyDownEvent.forTarget(document.body).listen(
+ keydownHandlerTest);
+ var subscription3 = document.body.onKeyDown.listen(
+ (e) => print('regular listener'));
+ subscription.cancel();
+ subscription2.cancel();
+ subscription3.cancel();
+ });
+
+ test('constructKeyEvent', () {
+ var stream = KeyEvent.keyPressEvent.forTarget(document.body);
+ var subscription = stream.listen(expectAsync((keyEvent) {
+ expect(keyEvent.charCode, 97);
+ expect(keyEvent.keyCode, 65);
+ }));
+ var k = new KeyEvent('keypress', keyCode: 65, charCode: 97);
+ stream.add(k);
+ subscription.cancel();
+ // Capital "A":
+ stream.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
+
+ subscription = stream.listen(expectAsync((keyEvent) {
+ expect(keyEvent.charCode, 65);
+ expect(keyEvent.keyCode, 65);
+ }));
+ stream.add(new KeyEvent('keypress', keyCode: 65, charCode: 65));
+ subscription.cancel();
+ });
+
+ test('KeyEventSequence', () {
+ // Press "?" by simulating "shift" and then the key that has "/" and "?" on
+ // it.
+ var streamDown = KeyEvent.keyDownEvent.forTarget(document.body);
+ var streamPress = KeyEvent.keyPressEvent.forTarget(document.body);
+ var streamUp = KeyEvent.keyUpEvent.forTarget(document.body);
+
+ var subscription = streamDown.listen(expectAsync((keyEvent) {
+ expect(keyEvent.keyCode, isIn([16, 191]));
+ expect(keyEvent.charCode, 0);
+ }, count: 2));
+
+ var subscription2 = streamPress.listen(expectAsync((keyEvent) {
+ expect(keyEvent.keyCode, 23);
+ expect(keyEvent.charCode, 63);
+ }));
+
+ var subscription3 = streamUp.listen(expectAsync((keyEvent) {
+ expect(keyEvent.keyCode, isIn([16, 191]));
+ expect(keyEvent.charCode, 0);
+ }, count: 2));
+
+ streamDown.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
+ streamDown.add(new KeyEvent('keydown', keyCode: 191, charCode: 0));
+
+ streamPress.add(new KeyEvent('keypress', keyCode: 23, charCode: 63));
+
+ streamUp.add(new KeyEvent('keyup', keyCode: 191, charCode: 0));
+ streamUp.add(new KeyEvent('keyup', keyCode: 16, charCode: 0));
+ subscription.cancel();
+ subscription2.cancel();
+ subscription3.cancel();
+ });
+
+ test('KeyEventKeyboardEvent', () {
+ window.onKeyDown.listen(expectAsync((KeyboardEvent event) {
+ expect(event.keyCode, 16);
+ }));
+ var streamDown = KeyEvent.keyDownEvent.forTarget(document.body);
+ streamDown.add(new KeyEvent('keydown', keyCode: 16, charCode: 0));
+ });
+}
+
+
« 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