Merge autoland to mozilla-central. a=merge
[gecko.git] / widget / tests / test_native_key_bindings_mac.html
blob81a13aea0e32f390e9e1f4b3dfda8e0d98be172f
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset='utf-8'/>
5 <title>Native Key Bindings for Cocoa Test</title>
6 <!-- Any copyright is dedicated to the Public Domain.
7 http://creativecommons.org/publicdomain/zero/1.0/ -->
8 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
9 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
10 <script src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script>
11 </head>
12 <body>
13 <div id="editable" contenteditable>
14 <p>Stretching attack nullam stuck in a tree zzz, suspendisse cras nec
15 suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the
16 curtains biting I don't like that food tristique biting sleep on your
17 keyboard non. Lay down in your way cras nec tempus chase the red dot cras
18 nec, pharetra pharetra eat the grass leap run orci turpis attack.
19 Consectetur sleep in the sink eat I don't like that food, knock over the
20 lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed
21 everywhere kittens rhoncus, attack your ankles zzz iaculis kittens. Nullam
22 pellentesque rip the couch iaculis rhoncus nibh, give me fish orci turpis
23 purr sleep on your face quis nunc bibendum.</p>
25 <p>Neque jump on the table bat iaculis, adipiscing sleep on your keyboard
26 jump vel justo shed everywhere suspendisse lick. Zzz enim faucibus
27 hairball faucibus, pharetra sunbathe biting bat leap rip the couch attack.
28 Tortor nibh in viverra quis hairball nam, vulputate adipiscing sleep on
29 your keyboard purr knock over the lamp orci turpis. Vestibulum I don't
30 like that food et chase the red dot, adipiscing neque bibendum rutrum
31 accumsan quis rhoncus claw. Leap accumsan vehicula enim biting sleep on
32 your face, pharetra nam accumsan egestas kittens sunbathe. Pharetra chase
33 the red dot sniff non eat the grass, vulputate fluffy fur aliquam puking
34 judging you.</p>
36 <p>Claw purr sollicitudin sollicitudin lay down in your way consectetur,
37 pellentesque vehicula zzz orci turpis consectetur. I don't like that food
38 rhoncus pellentesque sniff attack, rhoncus tortor attack your ankles
39 iaculis scratched hiss vel. Tortor zzz tortor nullam rip the couch rutrum,
40 bat enim ut leap hairball iaculis. Bibendum sunbathe elit suspendisse
41 nibh, puking adipiscing sleep on your face sleep on your face zzz catnip.
42 Judging you rutrum bat sunbathe sleep on your face, jump on the table leap
43 tincidunt a faucibus sleep in the sink. Stuck in a tree tristique zzz hiss
44 in viverra nullam, quis tortor pharetra attack.</p>
45 </div>
47 <textarea id="textarea" cols="80">
48 Stretching attack nullam stuck in a tree zzz, suspendisse cras nec
49 suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the
50 curtains biting I don't like that food tristique biting sleep on your
51 keyboard non. Lay down in your way cras nec tempus chase the red dot cras
52 nec, pharetra pharetra eat the grass leap run orci turpis attack.
53 Consectetur sleep in the sink eat I don't like that food, knock over the
54 lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed
55 everywhere kittens rhoncus, attack your ankles zzz iaculis kittens. Nullam
56 pellentesque rip the couch iaculis rhoncus nibh, give me fish orci turpis
57 purr sleep on your face quis nunc bibendum.
59 Neque jump on the table bat iaculis, adipiscing sleep on your keyboard
60 jump vel justo shed everywhere suspendisse lick. Zzz enim faucibus
61 hairball faucibus, pharetra sunbathe biting bat leap rip the couch attack.
62 Tortor nibh in viverra quis hairball nam, vulputate adipiscing sleep on
63 your keyboard purr knock over the lamp orci turpis. Vestibulum I don't
64 like that food et chase the red dot, adipiscing neque bibendum rutrum
65 accumsan quis rhoncus claw. Leap accumsan vehicula enim biting sleep on
66 your face, pharetra nam accumsan egestas kittens sunbathe. Pharetra chase
67 the red dot sniff non eat the grass, vulputate fluffy fur aliquam puking
68 judging you.
70 Claw purr sollicitudin sollicitudin lay down in your way consectetur,
71 pellentesque vehicula zzz orci turpis consectetur. I don't like that food
72 rhoncus pellentesque sniff attack, rhoncus tortor attack your ankles
73 iaculis scratched hiss vel. Tortor zzz tortor nullam rip the couch rutrum,
74 bat enim ut leap hairball iaculis. Bibendum sunbathe elit suspendisse
75 nibh, puking adipiscing sleep on your face sleep on your face zzz catnip.
76 Judging you rutrum bat sunbathe sleep on your face, jump on the table leap
77 tincidunt a faucibus sleep in the sink. Stuck in a tree tristique zzz hiss
78 in viverra nullam, quis tortor pharetra attack.
79 </textarea>
81 <input id="input" type="text"
82 value="Stretching attack nullam stuck in a tree zzz, suspendisse cras nec
83 suspendisse lick suscipit. Nunc egestas amet litter box, nullam climb the
84 curtains biting I don't like that food tristique biting sleep on your
85 keyboard non. Lay down in your way cras nec tempus chase the red dot cras
86 nec, pharetra pharetra eat the grass leap run orci turpis attack.
87 Consectetur sleep in the sink eat I don't like that food, knock over the
88 lamp catnip in viverra tail flick zzz meow etiam enim. Ac ac hiss shed
89 everywhere kittens rhoncus, attack your ankles zzz iaculis kittens.
90 Nullam pellentesque rip the couch iaculis rhoncus nibh, give me fish orci
91 turpis purr sleep on your face quis nunc bibendum.">
93 <script type="text/javascript">
94 SimpleTest.waitForExplicitFinish();
96 let synthesizedKeys = [];
97 let expectations = [];
99 // Move to beginning of line
100 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_LeftArrow,
101 {ctrlKey: true}, "\uf702", "\uf702"]);
102 expectations.push({
103 editable: [0, 0],
104 textarea: [0, 0],
105 input: [0, 0],
108 // Move to end of line
109 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
110 {ctrlKey: true}, "\uf703", "\uf703"]);
111 expectations.push({
112 editable: [73, 73],
113 textarea: [72, 72],
114 input: [732, 732],
117 // Move down
118 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_N,
119 {ctrlKey: true}, "\u000e", "n"]);
120 expectations.push({
121 editable: [140, 140],
122 textarea: [145, 145],
123 input: [732, 732],
126 // Move to beginning of line
127 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_LeftArrow,
128 {ctrlKey: true}, "\uf702", "\uf702"]);
129 expectations.push({
130 editable: [73, 73],
131 textarea: [73, 73],
132 input: [0, 0],
135 // Move word right and modify selection
136 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
137 {altKey: true, shiftKey: true}, "\uf703", "\uf703"]);
138 expectations.push({
139 editable: [73, 84],
140 textarea: [73, 90],
141 input: [0, 10],
144 // Move word right
145 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
146 {altKey: true}, "\uf703", "\uf703"]);
147 expectations.push({
148 editable: [84, 84],
149 textarea: [90, 90],
150 input: [10, 10],
153 // Move word right
154 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
155 {altKey: true}, "\uf703", "\uf703"]);
156 expectations.push({
157 editable: [89, 89],
158 textarea: [95, 95],
159 input: [17, 17],
162 // Move down and modify selection
163 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_DownArrow,
164 {shiftKey: true}, "\uf701", "\uf701"]);
165 expectations.push({
166 editable: [89, 171],
167 textarea: [95, 175],
168 input: [17, 732],
171 // Move backward and modify selection
172 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B,
173 {ctrlKey: true, shiftKey: true}, "\u0002", "B"]);
174 expectations.push({
175 editable: [89, 170],
176 textarea: [95, 174],
177 input: [17, 731],
180 // Delete forward
181 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_D,
182 {ctrlKey: true}, "\u0004", "d"]);
183 expectations.push({
184 editable: [89, 89],
185 textarea: [95, 95],
186 input: [17, 17],
189 // Delete backward
190 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_H,
191 {ctrlKey: true}, "\u0008", "h"]);
192 expectations.push({
193 editable: [88, 88],
194 textarea: [94, 94],
195 input: [16, 16],
198 // Move backward
199 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B,
200 {ctrlKey: true}, "\u0002", "b"]);
201 expectations.push({
202 editable: [87, 87],
203 textarea: [93, 93],
204 input: [15, 15],
207 // Move to beginning of paragraph (line for now)
208 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A,
209 {ctrlKey: true}, "\u0001", "a"]);
210 expectations.push({
211 editable: [73, 73],
212 textarea: [73, 73],
213 input: [0, 0],
216 // Move forward
217 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_F,
218 {ctrlKey: true}, "\u0006", "f"]);
219 expectations.push({
220 editable: [74, 74],
221 textarea: [74, 74],
222 input: [1, 1],
225 // Move word right
226 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
227 {altKey: true}, "\uf703", "\uf703"]);
228 expectations.push({
229 editable: [84, 84],
230 textarea: [90, 90],
231 input: [10, 10],
234 // Move word right
235 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_RightArrow,
236 {altKey: true}, "\uf703", "\uf703"]);
237 expectations.push({
238 editable: [88, 88],
239 textarea: [94, 94],
240 input: [17, 17],
243 // Delete to end of paragraph (line for now)
244 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_K,
245 {ctrlKey: true}, "\u000b", "k"]);
246 expectations.push({
247 editable: [88, 88],
248 textarea: [94, 94],
249 input: [17, 17],
252 // Move backward and modify selection
253 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_B,
254 {ctrlKey: true, shiftKey: true}, "\u0002", "B"]);
255 expectations.push({
256 editable: [88, 87],
257 textarea: [93, 94],
258 input: [16, 17],
261 // Move to end of paragraph (line for now)
262 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_E,
263 {ctrlKey: true}, "\u0005", "e"]);
264 expectations.push({
265 editable: [139, 139],
266 textarea: [94, 94],
267 input: [17, 17],
270 // Move up
271 synthesizedKeys.push([KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_P,
272 {ctrlKey: true}, "\u0010", "p"]);
273 expectations.push({
274 editable: [73, 73],
275 textarea: [21, 21],
276 input: [0, 0],
279 function checkWindowSelection(aElement, aSelection) {
280 let selection = window.getSelection();
282 is(selection.anchorOffset, aSelection[aElement.id][0],
283 aElement.id + ": Incorrect anchor offset");
284 is(selection.focusOffset, aSelection[aElement.id][1],
285 aElement.id + ": Incorrect focus offset");
288 function checkElementSelection(aElement, aSelection) {
289 is(aElement.selectionStart, aSelection[aElement.id][0],
290 aElement.id + ": Incorrect selection start");
291 is(aElement.selectionEnd, aSelection[aElement.id][1],
292 aElement.id + ": Incorrect selection end");
295 function* testRun(aElement, aSelectionCheck) {
296 if (document.activeElement) {
297 document.activeElement.blur();
300 aElement.focus();
302 for (let i = 0; i < synthesizedKeys.length; i++) {
303 synthesizedKeys[i].push(function() {
304 aSelectionCheck(aElement, expectations[i]);
305 continueTest();
307 var synthOk = synthesizeNativeKey.apply(null, synthesizedKeys[i]);
308 synthesizedKeys[i].pop();
309 yield synthOk;
313 function* doTest() {
314 yield* testRun(document.getElementById("editable"), checkWindowSelection);
315 yield* testRun(document.getElementById("textarea"), checkElementSelection);
316 yield* testRun(document.getElementById("input"), checkElementSelection);
319 let gTestContinuation = null;
321 function continueTest() {
322 if (!gTestContinuation) {
323 gTestContinuation = doTest();
325 var ret = gTestContinuation.next();
326 if (ret.done) {
327 SimpleTest.finish();
328 } else {
329 is(ret.value, true, "Successfully synthesized key");
333 SimpleTest.waitForFocus(continueTest);
334 </script>
335 </body>
336 </html>