OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import "/sky/framework/shell.dart" as shell; |
| 6 import "dart:async"; |
| 7 import "dart:sky"; |
| 8 import "dart:sky.internals" as internals; |
| 9 import "package:mojo/services/input_events/public/interfaces/input_event_constan
ts.mojom.dart" as constants; |
| 10 import "package:mojo/services/input_events/public/interfaces/input_events.mojom.
dart" as events; |
| 11 import "package:mojo/services/input_events/public/interfaces/input_key_codes.moj
om.dart" as codes; |
| 12 import "package:sky/services/testing/test_harness.mojom.dart" as harness; |
| 13 |
| 14 bool _isDone = false; |
| 15 int _keyPressesRemaining = 0; |
| 16 |
| 17 final Set<int> _chars = new Set.from([ |
| 18 codes.KeyboardCode_A, |
| 19 codes.KeyboardCode_B, |
| 20 codes.KeyboardCode_C, |
| 21 codes.KeyboardCode_D, |
| 22 codes.KeyboardCode_E, |
| 23 codes.KeyboardCode_F, |
| 24 codes.KeyboardCode_G, |
| 25 codes.KeyboardCode_H, |
| 26 codes.KeyboardCode_I, |
| 27 codes.KeyboardCode_J, |
| 28 codes.KeyboardCode_K, |
| 29 codes.KeyboardCode_L, |
| 30 codes.KeyboardCode_M, |
| 31 codes.KeyboardCode_N, |
| 32 codes.KeyboardCode_O, |
| 33 codes.KeyboardCode_P, |
| 34 codes.KeyboardCode_Q, |
| 35 codes.KeyboardCode_R, |
| 36 codes.KeyboardCode_S, |
| 37 codes.KeyboardCode_T, |
| 38 codes.KeyboardCode_U, |
| 39 codes.KeyboardCode_V, |
| 40 codes.KeyboardCode_W, |
| 41 codes.KeyboardCode_X, |
| 42 codes.KeyboardCode_Y, |
| 43 codes.KeyboardCode_Z, |
| 44 ]); |
| 45 |
| 46 void _checkComplete() { |
| 47 if (!_isDone) |
| 48 return; |
| 49 if (_keyPressesRemaining != 0) |
| 50 return; |
| 51 new Timer(Duration.ZERO, () { |
| 52 internals.notifyTestComplete(internals.contentAsText()); |
| 53 }); |
| 54 } |
| 55 |
| 56 void handleKeyPress_(Event event) { |
| 57 --_keyPressesRemaining; |
| 58 _checkComplete(); |
| 59 } |
| 60 |
| 61 harness.TestHarnessProxy _init() { |
| 62 document.addEventListener('keypress', handleKeyPress_); |
| 63 |
| 64 var harnessProxy = new harness.TestHarnessProxy.unbound(); |
| 65 shell.connectToService("mojo:sky_tester", harnessProxy); |
| 66 return harnessProxy; |
| 67 } |
| 68 |
| 69 final harness.TestHarnessProxy _harness = _init(); |
| 70 |
| 71 // |0| should be EventFlags_NONE once its a compile-time constant. |
| 72 void keyDown(int keyCode, [int eventFlags = 0]) { |
| 73 if (!_chars.contains(keyCode)) { |
| 74 _harness.dispatchInputEvent( |
| 75 new events.Event() |
| 76 ..action = constants.EventType_KEY_PRESSED |
| 77 ..flags = eventFlags |
| 78 ..keyData = (new events.KeyData() |
| 79 ..keyCode = keyCode |
| 80 ..windowsKeyCode = keyCode)); |
| 81 |
| 82 _harness.dispatchInputEvent( |
| 83 new events.Event() |
| 84 ..action = constants.EventType_KEY_PRESSED |
| 85 ..flags = eventFlags |
| 86 ..keyData = (new events.KeyData() |
| 87 ..isChar = true |
| 88 ..windowsKeyCode = keyCode)); |
| 89 } else { |
| 90 ++_keyPressesRemaining; |
| 91 _harness.dispatchInputEvent( |
| 92 new events.Event() |
| 93 ..action = constants.EventType_KEY_PRESSED |
| 94 ..flags = eventFlags |
| 95 ..keyData = (new events.KeyData() |
| 96 ..keyCode = keyCode |
| 97 ..isChar = true |
| 98 ..character = keyCode |
| 99 ..text = keyCode |
| 100 ..unmodifiedText = keyCode)); |
| 101 } |
| 102 } |
| 103 |
| 104 void done() { |
| 105 if (_isDone) |
| 106 throw "Already done."; |
| 107 _isDone = true; |
| 108 _checkComplete(); |
| 109 } |
OLD | NEW |