2 <?xml-stylesheet href=
"chrome://global/skin" type=
"text/css"?>
3 <?xml-stylesheet href=
"chrome://mochikit/content/tests/SimpleTest/test.css"
5 <window title=
"Key event tests"
7 xmlns:
html=
"http://www.w3.org/1999/xhtml"
8 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
10 <title>Key event tests
</title>
11 <script type=
"application/javascript"
12 src=
"chrome://mochikit/content/MochiKit/packed.js"></script>
13 <script type=
"application/javascript"
14 src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
17 <key id=
"unshiftedKey" key=
";" modifiers=
"accel" oncommand=
"this.activeCount++"/>
18 <key id=
"shiftedKey" key=
":" modifiers=
"accel" oncommand=
"this.activeCount++"/>
19 <key id=
"commandOptionF" key='f'
modifiers=
"accel,alt" oncommand=
"this.activeCount++"/>
20 <key id=
"question" key='?'
modifiers=
"accel" oncommand=
"this.activeCount++"/>
21 <key id=
"unshiftedX" key=
"x" modifiers=
"accel" oncommand=
"this.activeCount++"/>
22 <key id=
"shiftedX" key=
"X" modifiers=
"accel,shift" oncommand=
"this.activeCount++"/>
23 <key id=
"unshiftedPlus" key=
"+" modifiers=
"accel" oncommand=
"this.activeCount++"/>
26 <body xmlns=
"http://www.w3.org/1999/xhtml">
28 <!-- for some reason, if we don't have 'accesskey' here, adding it dynamically later
30 <button id=
"button" accesskey=
"z">Hello
</button>
31 <input type=
"text" id=
"textbox" value=
""/>
33 <div id=
"content" style=
"display: none">
40 <script class=
"testbody" type=
"application/javascript">
43 SimpleTest.waitForExplicitFinish();
45 function synthesizeNativeKey(aLayout, aKeyCode, aModifiers, aSystemChars,
46 aSystemUnmodifiedChars, aWindow)
48 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
53 var utils = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
54 getInterface(Components.interfaces.nsIDOMWindowUtils);
58 if (aModifiers.capsLock) modifiers |=
0x01;
59 if (aModifiers.numLock) modifiers |=
0x02;
60 if (aModifiers.shift) modifiers |=
0x0100;
61 if (aModifiers.shiftRight) modifiers |=
0x0200;
62 if (aModifiers.ctrl) modifiers |=
0x0400;
63 if (aModifiers.ctrlRight) modifiers |=
0x0800;
64 if (aModifiers.alt) modifiers |=
0x1000;
65 if (aModifiers.altRight) modifiers |=
0x2000;
66 if (aModifiers.command) modifiers |=
0x4000;
67 if (aModifiers.commandRight) modifiers |=
0x8000;
68 if (aModifiers.help) modifiers |=
0x10000;
69 if (aModifiers.function) modifiers |=
0x100000;
70 if (aModifiers.numericKeyPad) modifiers |=
0x01000000;
72 utils.sendNativeKeyEvent(aLayout, aKeyCode, modifiers,
73 aSystemChars, aSystemUnmodifiedChars);
78 if (navigator.platform.indexOf(
"Mac") ==
0) {
79 // These constants can be found by inspecting files under
80 // /System/Library/Keyboard\ Layouts/Unicode.bundle/Contents/Resources/
81 // XXX if you need a new keyboard layout and that uses KCHR resource,
82 // you need to modify GetScriptFromKeyboardLayout of nsChildView.mm
89 } else if (navigator.platform.indexOf(
"Win") ==
0) {
90 // These constants can be found by inspecting registry keys under
91 // HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Keyboard Layouts
103 function eventToString(aEvent)
105 var name = aEvent.layout +
" '" + aEvent.chars +
"'";
109 if (aEvent.shiftRight) {
110 name +=
" [Right Shift]";
115 if (aEvent.ctrlRight) {
116 name +=
" [Right Ctrl]";
121 if (aEvent.altRight) {
122 name +=
" [Right Alt]";
124 if (aEvent.command) {
125 name +=
" [Command]";
127 if (aEvent.commandRight) {
128 name +=
" [Right Command]";
134 function synthesizeKey(aEvent, aFocusElementId)
136 document.getElementById(aFocusElementId).focus();
138 synthesizeNativeKey(keyboardLayouts[aEvent.layout],
139 aEvent.keyCode, aEvent, aEvent.chars, aEvent.unmodifiedChars);
142 // Test the charcodes and modifiers being delivered to keypress handlers and
143 // also keydown/keyup events too.
144 function runKeyEventTests()
146 var eventList, keyDownFlags, keyUpFlags, testingEvent;
147 const kShiftFlag =
0x1;
148 const kCtrlFlag =
0x2;
149 const kAltFlag =
0x4;
150 const kMetaFlag =
0x8;
151 const kNumLockFlag =
0x10;
152 const kCapsLockFlag =
0x20;
154 function onKeyEvent(e)
156 function removeFlag(e, aFlag)
158 if (e.type ==
"keydown") {
159 var oldValue = keyDownFlags;
160 keyDownFlags &= ~aFlag;
161 return oldValue != keyDownFlags;
162 } else if (e.type ==
"keyup") {
163 var oldValue = keyUpFlags;
164 keyUpFlags &= ~aFlag;
165 return oldValue != keyUpFlags;
170 function isStateChangingModifierKeyEvent(e)
174 return (testingEvent.shift || testingEvent.shiftRight) && removeFlag(e, kShiftFlag);
175 case e.DOM_VK_CONTROL:
176 return (testingEvent.ctrl || testingEvent.ctrlRight) && removeFlag(e, kCtrlFlag);
178 return (testingEvent.alt || testingEvent.altRight) && removeFlag(e, kAltFlag);
180 return testingEvent.command && removeFlag(e, kMetaFlag);
181 case e.DOM_VK_NUM_LOCK:
182 return testingEvent.numLock && removeFlag(e, kNumLockFlag);
183 case e.DOM_VK_CAPS_LOCK:
184 return testingEvent.capsLock && removeFlag(e, kCapsLockFlag);
189 // Ignore the state changing key events which is fired by the testing event.
190 if (!isStateChangingModifierKeyEvent(e))
195 const SHOULD_DELIVER_NONE =
0x0;
196 const SHOULD_DELIVER_KEYDOWN =
0x1;
197 const SHOULD_DELIVER_KEYPRESS =
0x2;
198 const SHOULD_DELIVER_KEYUP =
0x4;
199 const SHOULD_DELIVER_ALL = SHOULD_DELIVER_KEYDOWN |
200 SHOULD_DELIVER_KEYPRESS |
201 SHOULD_DELIVER_KEYUP;
202 const SHOULD_DELIVER_KEYDOWN_KEYUP = SHOULD_DELIVER_KEYDOWN |
203 SHOULD_DELIVER_KEYUP;
204 const SHOULD_DELIVER_KEYDOWN_KEYPRESS = SHOULD_DELIVER_KEYDOWN |
205 SHOULD_DELIVER_KEYPRESS;
207 // The first parameter is the complete input event. The second parameter is
208 // what to test against. The third parameter is which key events should be
209 // delived for the event.
210 function testKey(aEvent, aExpectGeckoChar, aShouldDelivedEvent)
214 // The modifier key events which are fired for state changing are har to
215 // test. We should ignore them for now.
216 keyDownFlags = keyUpFlags =
0;
217 if (navigator.platform.indexOf(
"Mac") !=
0) {
218 // On Mac, nsChildView doesn't generate modifier keydown/keyup events for
219 // state changing for synthesizeNativeKeyEvent.
220 if (aEvent.shift || aEvent.shiftRight)
221 keyDownFlags |= kShiftFlag;
222 if (aEvent.ctrl || aEvent.ctrlRight)
223 keyDownFlags |= kCtrlFlag;
224 if (aEvent.alt || aEvent.altRight)
225 keyDownFlags |= kAltFlag;
227 keyDownFlags |= kMetaFlag;
229 keyDownFlags |= kNumLockFlag;
231 keyDownFlags |= kCapsLockFlag;
232 keyUpFlags = keyDownFlags;
234 testingEvent = aEvent;
236 synthesizeKey(aEvent,
"button");
238 var name = eventToString(aEvent);
240 var expectEventTypeList = [];
241 if (aShouldDelivedEvent & SHOULD_DELIVER_KEYDOWN)
242 expectEventTypeList.push(
"keydown");
243 if (aShouldDelivedEvent & SHOULD_DELIVER_KEYPRESS)
244 expectEventTypeList.push(
"keypress");
245 if (aShouldDelivedEvent & SHOULD_DELIVER_KEYUP)
246 expectEventTypeList.push(
"keyup");
247 is(eventList.length, expectEventTypeList.length, name +
", wrong number of key events");
249 var longerLength = Math.max(eventList.length, expectEventTypeList.length);
250 for (var i =
0; i < longerLength; i++) {
251 var firedEventType = i < eventList.length ? eventList[i].type :
"";
252 var expectEventType = i < expectEventTypeList.length ? expectEventTypeList[i] :
"";
253 if (firedEventType !=
"")
254 is(firedEventType, expectEventType, name +
", wrong type event fired");
256 is(firedEventType, expectEventType, name +
", a needed event is not fired");
258 if (firedEventType !=
"") {
259 var e = eventList[i];
260 is(e.ctrlKey, aEvent.ctrl || aEvent.ctrlRight ||
0, name +
", Ctrl mismatch");
261 is(e.metaKey, aEvent.command || aEvent.commandRight ||
0, name +
", Command mismatch");
262 is(e.altKey, aEvent.alt || aEvent.altRight ||
0, name +
", Alt mismatch");
263 is(e.shiftKey, aEvent.shift || aEvent.shiftRight ||
0, name +
", Shift mismatch");
265 if (aExpectGeckoChar.length
> 0 && e.type ==
"keypress")
266 is(e.charCode, aExpectGeckoChar.charCodeAt(
0), name +
", charcode");
268 is(e.charCode,
0, name +
", no charcode");
273 // These tests have to be per-plaform.
274 document.addEventListener(
"keydown", onKeyEvent, false);
275 document.addEventListener(
"keypress", onKeyEvent, false);
276 document.addEventListener(
"keyup", onKeyEvent, false);
278 if (navigator.platform.indexOf(
"Mac") ==
0) {
279 // On Mac, you can produce event records for any desired keyboard input
280 // by running with NSPR_LOG_MODULES=nsCocoaWidgets:
5 and typing into the browser.
281 // We will dump the key event fields to the console. Use the International system
282 // preferences widget to enable other keyboard layouts and select them from the
283 // input menu to see what keyboard events they generate.
284 // Note that it's possible to send bogus key events here, e.g.
285 // {keyCode:
0, chars:
"z", unmodifiedChars:
"P"} --- sendNativeKeyEvent
286 // makes no attempt to verify that the keyCode matches the characters. So only
287 // test key event records that you saw Cocoa send.
290 testKey({layout:
"US", keyCode:
0, chars:
"a", unmodifiedChars:
"a"},
291 "a", SHOULD_DELIVER_ALL);
292 testKey({layout:
"US", keyCode:
11, chars:
"b", unmodifiedChars:
"b"},
293 "b", SHOULD_DELIVER_ALL);
294 testKey({layout:
"US", keyCode:
0, shift:
1, chars:
"A", unmodifiedChars:
"A"},
295 "A", SHOULD_DELIVER_ALL);
298 testKey({layout:
"US", keyCode:
0, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"a"},
299 "a", SHOULD_DELIVER_ALL);
300 testKey({layout:
"US", keyCode:
0, ctrl:
1, shift:
1, chars:
"\u0001", unmodifiedChars:
"A"},
301 "A", SHOULD_DELIVER_ALL);
304 testKey({layout:
"US", keyCode:
0, alt:
1, chars:
"\u00e5", unmodifiedChars:
"a"},
305 "\u00e5", SHOULD_DELIVER_ALL);
306 testKey({layout:
"US", keyCode:
0, alt:
1, shift:
1, chars:
"\u00c5", unmodifiedChars:
"A"},
307 "\u00c5", SHOULD_DELIVER_ALL);
310 testKey({layout:
"US", keyCode:
0, command:
1, chars:
"a", unmodifiedChars:
"a"},
311 "a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
312 // Shift-cmd gives us the shifted character
313 testKey({layout:
"US", keyCode:
0, command:
1, shift:
1, chars:
"a", unmodifiedChars:
"A"},
314 "A", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
315 // Ctrl-cmd gives us the unshifted character
316 testKey({layout:
"US", keyCode:
0, command:
1, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"a"},
317 "a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
318 // Alt-cmd gives us the shifted character
319 testKey({layout:
"US", keyCode:
0, command:
1, alt:
1, chars:
"\u00e5", unmodifiedChars:
"a"},
320 "\u00e5", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
321 testKey({layout:
"US", keyCode:
0, command:
1, alt:
1, shift:
1, chars:
"\u00c5", unmodifiedChars:
"a"},
322 "\u00c5", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
324 // Greek ctrl keys produce Latin charcodes
325 testKey({layout:
"Greek", keyCode:
0, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"\u03b1"},
326 "a", SHOULD_DELIVER_ALL);
327 testKey({layout:
"Greek", keyCode:
0, ctrl:
1, shift:
1, chars:
"\u0001", unmodifiedChars:
"\u0391"},
328 "A", SHOULD_DELIVER_ALL);
330 // Greek command keys
331 testKey({layout:
"Greek", keyCode:
0, command:
1, chars:
"a", unmodifiedChars:
"\u03b1"},
332 "a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
333 // Shift-cmd gives us the shifted character
334 testKey({layout:
"Greek", keyCode:
0, command:
1, shift:
1, chars:
"a", unmodifiedChars:
"\u391"},
335 "A", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
336 // Ctrl-cmd gives us the unshifted character
337 testKey({layout:
"Greek", keyCode:
0, command:
1, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"\u03b1"},
338 "a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
339 // Alt-cmd gives us the shifted character
340 testKey({layout:
"Greek", keyCode:
0, command:
1, alt:
1, chars:
"\u00a8", unmodifiedChars:
"\u03b1"},
341 "\u00a8", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
342 testKey({layout:
"Greek", keyCode:
0, command:
1, alt:
1, shift:
1, chars:
"\u00b9", unmodifiedChars:
"\u0391"},
343 "\u00b9", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
345 // German (KCHR/KeyTranslate case)
346 testKey({layout:
"German", keyCode:
0, chars:
"a", unmodifiedChars:
"a"},
347 "a", SHOULD_DELIVER_ALL);
348 testKey({layout:
"German", keyCode:
33, chars:
"\u00fc", unmodifiedChars:
"\u00fc"},
349 "\u00fc", SHOULD_DELIVER_ALL);
350 testKey({layout:
"German", keyCode:
27, chars:
"\u00df", unmodifiedChars:
"\u00df"},
351 "\u00df", SHOULD_DELIVER_ALL);
352 testKey({layout:
"German", keyCode:
27, shift:
1, chars:
"?", unmodifiedChars:
"?"},
353 "?", SHOULD_DELIVER_ALL);
354 testKey({layout:
"German", keyCode:
27, command:
1, chars:
"\u00df", unmodifiedChars:
"\u00df"},
355 "\u00df", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
356 // Shift+SS is '?' but Cmd+Shift+SS is '/' on German layout.
357 // XXX this test failed on
10.4
358 //testKey({layout:
"German", keyCode:
27, command:
1, shift:
1, chars:
"/", unmodifiedChars:
"?"},
359 //
"?", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
361 // Caps Lock key event
362 // XXX keyup event of Caps Lock key is not fired.
363 testKey({layout:
"US", keyCode:
57, capsLock:
1, chars:
"", unmodifiedChars:
""},
364 "", SHOULD_DELIVER_KEYDOWN);
365 testKey({layout:
"US", keyCode:
57, capsLock:
0, chars:
"", unmodifiedChars:
""},
366 "", SHOULD_DELIVER_KEYDOWN);
368 // Shift/RightShift key event
369 testKey({layout:
"US", keyCode:
56, shift:
1, chars:
"", unmodifiedChars:
""},
370 "", SHOULD_DELIVER_KEYDOWN);
371 testKey({layout:
"US", keyCode:
56, shift:
0, chars:
"", unmodifiedChars:
""},
372 "", SHOULD_DELIVER_KEYUP);
373 testKey({layout:
"US", keyCode:
60, shiftRight:
1, chars:
"", unmodifiedChars:
""},
374 "", SHOULD_DELIVER_KEYDOWN);
375 testKey({layout:
"US", keyCode:
60, shiftRight:
0, chars:
"", unmodifiedChars:
""},
376 "", SHOULD_DELIVER_KEYUP);
378 // Control/RightControl key event
379 testKey({layout:
"US", keyCode:
59, ctrl:
1, chars:
"", unmodifiedChars:
""},
380 "", SHOULD_DELIVER_KEYDOWN);
381 testKey({layout:
"US", keyCode:
59, ctrl:
0, chars:
"", unmodifiedChars:
""},
382 "", SHOULD_DELIVER_KEYUP);
383 testKey({layout:
"US", keyCode:
62, ctrlRight:
1, chars:
"", unmodifiedChars:
""},
384 "", SHOULD_DELIVER_KEYDOWN);
385 testKey({layout:
"US", keyCode:
62, ctrlRight:
0, chars:
"", unmodifiedChars:
""},
386 "", SHOULD_DELIVER_KEYUP);
388 // Option/RightOption key event
389 testKey({layout:
"US", keyCode:
58, alt:
1, chars:
"", unmodifiedChars:
""},
390 "", SHOULD_DELIVER_KEYDOWN);
391 testKey({layout:
"US", keyCode:
58, alt:
0, chars:
"", unmodifiedChars:
""},
392 "", SHOULD_DELIVER_KEYUP);
393 testKey({layout:
"US", keyCode:
61, altRight:
1, chars:
"", unmodifiedChars:
""},
394 "", SHOULD_DELIVER_KEYDOWN);
395 testKey({layout:
"US", keyCode:
61, altRight:
0, chars:
"", unmodifiedChars:
""},
396 "", SHOULD_DELIVER_KEYUP);
398 // Command/RightCommand key event
399 testKey({layout:
"US", keyCode:
55, command:
1, chars:
"", unmodifiedChars:
""},
400 "", SHOULD_DELIVER_KEYDOWN);
401 testKey({layout:
"US", keyCode:
55, command:
0, chars:
"", unmodifiedChars:
""},
402 "", SHOULD_DELIVER_KEYUP);
403 testKey({layout:
"US", keyCode:
54, commandRight:
1, chars:
"", unmodifiedChars:
""},
404 "", SHOULD_DELIVER_KEYDOWN);
405 testKey({layout:
"US", keyCode:
54, commandRight:
0, chars:
"", unmodifiedChars:
""},
406 "", SHOULD_DELIVER_KEYUP);
409 if (navigator.platform.indexOf(
"Win") ==
0) {
410 // On Windows, you can use Spy++ or Winspector (free) to watch window messages.
411 // The keyCode is given by the wParam of the last WM_KEYDOWN message. The
412 // chars string is given by the wParam of the WM_CHAR message. unmodifiedChars
413 // is not needed on Windows.
416 testKey({layout:
"US", keyCode:
65, chars:
"a"},
417 "a", SHOULD_DELIVER_ALL);
418 testKey({layout:
"US", keyCode:
66, chars:
"b"},
419 "b", SHOULD_DELIVER_ALL);
420 testKey({layout:
"US", keyCode:
65, shift:
1, chars:
"A"},
421 "A", SHOULD_DELIVER_ALL);
424 testKey({layout:
"US", keyCode:
65, ctrl:
1, chars:
"\u0001"},
425 "a", SHOULD_DELIVER_ALL);
426 testKey({layout:
"US", keyCode:
65, ctrl:
1, shift:
1, chars:
"\u0001"},
427 "A", SHOULD_DELIVER_ALL);
430 testKey({layout:
"US", keyCode:
65, alt:
1, chars:
"a"},
431 "a", SHOULD_DELIVER_ALL);
432 testKey({layout:
"US", keyCode:
65, alt:
1, shift:
1, chars:
"A"},
433 "A", SHOULD_DELIVER_ALL);
435 // Shift-ctrl-alt generates no WM_CHAR, but we still get a keypress
436 testKey({layout:
"US", keyCode:
65, alt:
1, ctrl:
1, shift:
1, chars:
""},
437 "A", SHOULD_DELIVER_ALL);
440 testKey({layout:
"Greek", keyCode:
65, chars:
"\u03b1"},
441 "\u03b1", SHOULD_DELIVER_ALL);
442 testKey({layout:
"Greek", keyCode:
65, shift:
1, chars:
"\u0391"},
443 "\u0391", SHOULD_DELIVER_ALL);
445 // Greek ctrl keys produce Latin charcodes
446 testKey({layout:
"Greek", keyCode:
65, ctrl:
1, chars:
"\u0001"},
447 "a", SHOULD_DELIVER_ALL);
448 testKey({layout:
"Greek", keyCode:
65, ctrl:
1, shift:
1, chars:
"\u0001"},
449 "A", SHOULD_DELIVER_ALL);
451 // Caps Lock key event
452 testKey({layout:
"US", keyCode:
20, capsLock:
1, chars:
""},
453 "", SHOULD_DELIVER_KEYDOWN_KEYUP);
454 testKey({layout:
"US", keyCode:
20, capsLock:
0, chars:
""},
455 "", SHOULD_DELIVER_KEYDOWN_KEYUP);
458 document.removeEventListener(
"keydown", onKeyEvent, false);
459 document.removeEventListener(
"keypress", onKeyEvent, false);
460 document.removeEventListener(
"keyup", onKeyEvent, false);
463 // Test the activation (or not) of an HTML accesskey
464 function runAccessKeyTests()
466 var button = document.getElementById(
"button");
474 // The first parameter is the complete input event. The second and third parameters are
475 // what to test against.
476 function testKey(aEvent, aAccessKey, aShouldActivate)
479 button.setAttribute(
"accesskey", aAccessKey);
481 synthesizeKey(aEvent,
"button");
483 var name = eventToString(aEvent);
485 is(activationCount, aShouldActivate ?
1 :
0, name +
", activating '" + aAccessKey +
"'");
488 button.addEventListener(
"click", onClick, false);
490 // These tests have to be per-plaform.
491 if (navigator.platform.indexOf(
"Mac") ==
0) {
492 // Basic sanity checks
493 testKey({layout:
"US", keyCode:
0, chars:
"a", unmodifiedChars:
"a"},
495 testKey({layout:
"US", keyCode:
0, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"a"},
497 testKey({layout:
"US", keyCode:
0, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"a"},
500 // Shift-ctrl does not activate accesskeys
501 testKey({layout:
"US", keyCode:
0, ctrl:
1, shift:
1, chars:
"\u0001", unmodifiedChars:
"A"},
503 testKey({layout:
"US", keyCode:
0, ctrl:
1, shift:
1, chars:
"\u0001", unmodifiedChars:
"A"},
505 // Alt-ctrl does not activate accesskeys
506 testKey({layout:
"US", keyCode:
0, ctrl:
1, alt:
1, chars:
"\u0001", unmodifiedChars:
"a"},
508 testKey({layout:
"US", keyCode:
0, ctrl:
1, alt:
1, chars:
"\u0001", unmodifiedChars:
"a"},
511 // Greek layout can activate a Latin accesskey
512 testKey({layout:
"Greek", keyCode:
0, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"\u03b1"},
514 testKey({layout:
"Greek", keyCode:
0, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"\u03b1"},
516 // ... and a Greek accesskey!
517 testKey({layout:
"Greek", keyCode:
0, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"\u03b1"},
519 testKey({layout:
"Greek", keyCode:
0, ctrl:
1, chars:
"\u0001", unmodifiedChars:
"\u03b1"},
523 testKey({layout:
"US", keyCode:
47, ctrl:
1, chars:
".", unmodifiedChars:
"."},
526 // German (KCHR/KeyTranslate case)
527 testKey({layout:
"German", keyCode:
0, ctrl:
1, chars:
"a", unmodifiedChars:
"a"},
529 testKey({layout:
"German", keyCode:
0, ctrl:
1, chars:
"a", unmodifiedChars:
"a"},
531 testKey({layout:
"German", keyCode:
33, ctrl:
1, chars:
"\u00fc", unmodifiedChars:
"\u00fc"},
533 testKey({layout:
"German", keyCode:
33, ctrl:
1, chars:
"\u00fc", unmodifiedChars:
"\u00fc"},
537 if (navigator.platform.indexOf(
"Win") ==
0) {
538 // Basic sanity checks
539 testKey({layout:
"US", keyCode:
65, chars:
"a"},
541 testKey({layout:
"US", keyCode:
65, shift:
1, alt:
1, chars:
"A"},
543 testKey({layout:
"US", keyCode:
65, shift:
1, alt:
1, chars:
"A"},
546 // shift-alt-ctrl does not activate accesskeys
547 testKey({layout:
"US", keyCode:
65, ctrl:
1, shift:
1, alt:
1, chars:
""},
549 testKey({layout:
"US", keyCode:
65, ctrl:
1, shift:
1, alt:
1, chars:
""},
552 // Greek layout can activate a Latin accesskey
553 testKey({layout:
"Greek", keyCode:
65, shift:
1, alt:
1, chars:
"A"},
555 testKey({layout:
"Greek", keyCode:
65, shift:
1, alt:
1, chars:
"A"},
557 // ... and a Greek accesskey!
558 testKey({layout:
"Greek", keyCode:
65, shift:
1, alt:
1, chars:
"A"},
560 testKey({layout:
"Greek", keyCode:
65, shift:
1, alt:
1, chars:
"A"},
564 testKey({layout:
"US", keyCode:
190, shift:
1, alt:
1, chars:
".", unmodifiedChars:
"."},
568 button.removeEventListener(
"click", onClick, false);
571 function runXULKeyTests()
573 function testKey(aEvent, aElem, aShouldActivate)
575 var elem = document.getElementById(aElem);
576 elem.activeCount =
0;
578 synthesizeKey(aEvent,
"button");
580 var name = eventToString(aEvent);
582 is(elem.activeCount, aShouldActivate ?
1 :
0,
583 name +
" activating " + aElem);
586 if (navigator.platform.indexOf(
"Mac") ==
0) {
587 testKey({layout:
"US", keyCode:
41, command:
1, chars:
";", unmodifiedChars:
";"},
588 "unshiftedKey", true);
589 testKey({layout:
"US", keyCode:
41, command:
1, chars:
";", unmodifiedChars:
";"},
590 "shiftedKey", false);
591 testKey({layout:
"US", keyCode:
41, command:
1, shift:
1, chars:
";", unmodifiedChars:
":"},
593 testKey({layout:
"US", keyCode:
41, command:
1, shift:
1, chars:
";", unmodifiedChars:
":"},
594 "unshiftedKey", false);
596 if (navigator.platform.indexOf(
"Win") ==
0) {
597 testKey({layout:
"US", keyCode:
186, ctrl:
1, chars:
";"},
598 "unshiftedKey", true);
599 testKey({layout:
"US", keyCode:
186, ctrl:
1, chars:
";"},
600 "shiftedKey", false);
601 testKey({layout:
"US", keyCode:
186, ctrl:
1, shift:
1, chars:
";"},
603 testKey({layout:
"US", keyCode:
186, ctrl:
1, shift:
1, chars:
";"},
604 "unshiftedKey", false);
607 keyElems = [
"commandOptionF"];
610 if (navigator.platform.indexOf(
"Mac") ==
0) {
611 testKey({layout:
"US", keyCode:
3, command:
1, alt:
1, chars:
"\u0192", unmodifiedChars:
"f"},
612 "commandOptionF", true);
614 if (navigator.platform.indexOf(
"Win") ==
0) {
615 testKey({layout:
"US", keyCode:
70, ctrl:
1, alt:
1, chars:
"\u0006"},
616 "commandOptionF", true);
620 if (navigator.platform.indexOf(
"Mac") ==
0) {
621 // test currently does not work, getting the Swedish layout fails
622 // testKey({layout:
"Swedish", keyCode:
27, command:
1, shift:
1, chars:
"+", unmodifiedChars:
"?"},
623 //
"question", true);
625 if (navigator.platform.indexOf(
"Win") ==
0) {
626 testKey({layout:
"Swedish", keyCode:
187, ctrl:
1, shift:
1, chars:
""},
628 testKey({layout:
"Swedish", keyCode:
187, ctrl:
1, chars:
""},
633 if (navigator.platform.indexOf(
"Win") ==
0) {
634 testKey({layout:
"US", keyCode:
88, ctrl:
1, chars:
"\u0018"},
636 testKey({layout:
"US", keyCode:
88, ctrl:
1, chars:
"\u0018"},
638 testKey({layout:
"US", keyCode:
88, ctrl:
1, shift:
1, chars:
"\u0018"},
639 "unshiftedX", false);
640 testKey({layout:
"US", keyCode:
88, ctrl:
1, shift:
1, chars:
"\u0018"},
642 testKey({layout:
"Arabic", keyCode:
88, ctrl:
1, chars:
"\u0018"},
644 testKey({layout:
"Arabic", keyCode:
88, ctrl:
1, chars:
"\u0018"},
646 testKey({layout:
"Arabic", keyCode:
88, ctrl:
1, shift:
1, chars:
"\u0018"},
647 "unshiftedX", false);
648 testKey({layout:
"Arabic", keyCode:
88, ctrl:
1, shift:
1, chars:
"\u0018"},
650 testKey({layout:
"Hebrew", keyCode:
88, ctrl:
1, chars:
"\u0018"},
652 testKey({layout:
"Hebrew", keyCode:
88, ctrl:
1, chars:
"\u0018"},
654 testKey({layout:
"Hebrew", keyCode:
88, ctrl:
1, shift:
1, chars:
"\u0018"},
655 "unshiftedX", false);
656 testKey({layout:
"Hebrew", keyCode:
88, ctrl:
1, shift:
1, chars:
"\u0018"},
658 testKey({layout:
"Japanese", keyCode:
187, ctrl:
1, chars:
""},
659 "unshiftedPlus", false);
660 testKey({layout:
"Japanese", keyCode:
187, ctrl:
1, shift:
1, chars:
""},
661 "unshiftedPlus", true);
665 function runTextInputTests()
667 var textbox = document.getElementById(
"textbox");
669 function testKey(aEvent, aExpectText) {
673 synthesizeKey(aEvent,
"textbox");
675 var name = eventToString(aEvent);
677 is(textbox.value, aExpectText, name +
" does not input correct text.");
680 if (navigator.platform.indexOf(
"Win") ==
0) {
681 // Basic sanity checks
682 testKey({layout:
"US", keyCode:
65, chars:
"a"},
684 testKey({layout:
"US", keyCode:
65, shift:
1, chars:
"A"},
686 // When Ctrl+Alt are pressed, any text should not be inputted.
687 testKey({layout:
"US", keyCode:
65, ctrl:
1, alt:
1, chars:
""},
690 // Lithuanian AltGr should be consumed at
9/
0 keys pressed
691 testKey({layout:
"Lithuanian", keyCode:
56, chars:
"\u016B"},
693 testKey({layout:
"Lithuanian", keyCode:
57, chars:
"9"},
695 testKey({layout:
"Lithuanian", keyCode:
48, chars:
"0"},
697 testKey({layout:
"Lithuanian", keyCode:
56, ctrl:
1, alt:
1, chars:
"8"},
699 testKey({layout:
"Lithuanian", keyCode:
57, ctrl:
1, alt:
1, chars:
"9"},
701 testKey({layout:
"Lithuanian", keyCode:
48, ctrl:
1, alt:
1, chars:
"0"},