OLD | NEW |
---|---|
(Empty) | |
1 <import src="/mojo/services/public/interfaces/input_events/input_event_constants .mojom.sky" as="constants" /> | |
2 <import src="/mojo/services/public/interfaces/input_events/input_events.mojom.sk y" as="events" /> | |
3 <import src="/mojo/services/public/interfaces/input_events/input_key_codes.mojom .sky" as="codes" /> | |
4 <import src="/sky/framework/shell.sky" as="shell" /> | |
5 <import src="/sky/services/testing/test_harness.mojom.sky" as="harness" /> | |
6 <script> | |
7 var harness = shell.connectToService("mojo:sky_tester", harness.TestHarness); | |
8 | |
9 var g_done = false; | |
rafaelw
2014/11/13 00:57:25
no need for g_ prefix
abarth-chromium
2014/11/13 01:00:50
Done.
| |
10 var g_keyDownCount = 0; | |
11 | |
12 function keyDown(key, flag) { | |
13 var eventFlags = constants.EventFlags.NONE; | |
14 // TODO(abarth): Support more than one flag. | |
15 if (constants.EventFlags.hasOwnProperty(flag)) | |
16 eventFlags = constants.EventFlags[flag]; | |
17 | |
18 if (key.length != 1 && codes.KeyboardCode.hasOwnProperty(key)) { | |
19 var keyCode = codes.KeyboardCode[key]; | |
20 | |
21 harness.dispatchInputEvent(new events.Event({ | |
22 action: constants.EventType.KEY_PRESSED, | |
23 flags: eventFlags, | |
24 key_data: new events.KeyData({ | |
25 key_code: keyCode, | |
26 windows_key_code: keyCode, | |
27 })})); | |
28 | |
29 harness.dispatchInputEvent(new events.Event({ | |
30 action: constants.EventType.KEY_PRESSED, | |
31 flags: eventFlags, | |
32 key_data: new events.KeyData({ | |
33 is_char: true, | |
34 windows_key_code: keyCode, | |
35 })})); | |
36 } else { | |
37 ++g_keyDownCount; | |
38 var keyCode = key.charCodeAt(0); | |
39 harness.dispatchInputEvent(new events.Event({ | |
40 action: constants.EventType.KEY_PRESSED, | |
41 flags: eventFlags, | |
42 key_data: new events.KeyData({ | |
43 key_code: keyCode, | |
44 is_char: true, | |
45 character: keyCode, | |
46 text: keyCode, | |
47 unmodified_text: keyCode, | |
48 })})); | |
49 } | |
50 } | |
51 | |
52 function done() { | |
53 g_done = true; | |
rafaelw
2014/11/13 00:57:25
it's a little wierd this module is unusable after
abarth-chromium
2014/11/13 01:00:50
Done.
abarth-chromium
2014/11/13 01:00:50
Done.
| |
54 checkComplete(); | |
55 } | |
56 | |
57 function checkComplete() { | |
58 if (!g_done) | |
59 return; | |
60 if (g_keyDownCount != 0) | |
rafaelw
2014/11/13 00:57:25
indent
abarth-chromium
2014/11/13 01:00:50
Fixed.
| |
61 return; | |
62 setTimeout(function() { | |
63 internals.notifyTestComplete(internals.contentAsText()); | |
64 }); | |
65 } | |
66 | |
67 document.addEventListener('keypress', function() { | |
68 --g_keyDownCount; | |
69 checkComplete(); | |
70 }); | |
71 | |
72 module.exports = { | |
73 keyDown: keyDown, | |
74 done: done, | |
75 }; | |
76 </script> | |
77 </sky> | |
OLD | NEW |