2008-05-05 16:01:07 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
|
|
|
type="text/css"?>
|
|
|
|
<window title="Key event tests"
|
|
|
|
onload="runTest()"
|
|
|
|
xmlns:html="http://www.w3.org/1999/xhtml"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
|
|
|
|
|
|
<title>Key event tests</title>
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
|
|
|
|
|
2008-05-08 15:41:13 -07:00
|
|
|
<keyset>
|
|
|
|
<key id="unshiftedKey" key=";" modifiers="accel" oncommand="this.activeCount++"/>
|
|
|
|
<key id="shiftedKey" key=":" modifiers="accel" oncommand="this.activeCount++"/>
|
|
|
|
<key id="commandOptionF" key='f' modifiers="accel,alt" oncommand="this.activeCount++"/>
|
|
|
|
<key id="question" key='?' modifiers="accel" oncommand="this.activeCount++"/>
|
2008-05-11 17:39:29 -07:00
|
|
|
<key id="unshiftedX" key="x" modifiers="accel" oncommand="this.activeCount++"/>
|
|
|
|
<key id="shiftedX" key="X" modifiers="accel,shift" oncommand="this.activeCount++"/>
|
|
|
|
<key id="unshiftedPlus" key="+" modifiers="accel" oncommand="this.activeCount++"/>
|
2008-05-08 15:41:13 -07:00
|
|
|
</keyset>
|
|
|
|
|
2008-05-05 16:01:07 -07:00
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<p id="display">
|
|
|
|
<!-- for some reason, if we don't have 'accesskey' here, adding it dynamically later
|
|
|
|
doesn't work! -->
|
|
|
|
<button id="button" accesskey="z">Hello</button>
|
2008-10-13 23:01:51 -07:00
|
|
|
<input type="text" id="textbox" value=""/>
|
2008-05-05 16:01:07 -07:00
|
|
|
</p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
<script class="testbody" type="application/javascript">
|
|
|
|
<![CDATA[
|
|
|
|
|
2009-03-30 14:42:11 -07:00
|
|
|
const IS_MAC = navigator.platform.indexOf("Mac") == 0;
|
|
|
|
const IS_WIN = navigator.platform.indexOf("Win") == 0;
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
function synthesizeNativeKey(aLayout, aKeyCode, aModifiers, aSystemChars,
|
|
|
|
aSystemUnmodifiedChars, aWindow)
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
|
|
|
if (!aWindow)
|
|
|
|
aWindow = window;
|
|
|
|
|
|
|
|
var utils = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
|
|
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
|
|
|
|
|
|
|
if (utils) {
|
|
|
|
var modifiers = 0;
|
|
|
|
if (aModifiers.capsLock) modifiers |= 0x01;
|
|
|
|
if (aModifiers.numLock) modifiers |= 0x02;
|
|
|
|
if (aModifiers.shift) modifiers |= 0x0100;
|
|
|
|
if (aModifiers.shiftRight) modifiers |= 0x0200;
|
|
|
|
if (aModifiers.ctrl) modifiers |= 0x0400;
|
|
|
|
if (aModifiers.ctrlRight) modifiers |= 0x0800;
|
|
|
|
if (aModifiers.alt) modifiers |= 0x1000;
|
|
|
|
if (aModifiers.altRight) modifiers |= 0x2000;
|
|
|
|
if (aModifiers.command) modifiers |= 0x4000;
|
2008-10-18 01:37:59 -07:00
|
|
|
if (aModifiers.commandRight) modifiers |= 0x8000;
|
|
|
|
if (aModifiers.help) modifiers |= 0x10000;
|
|
|
|
if (aModifiers.function) modifiers |= 0x100000;
|
2008-05-05 16:01:07 -07:00
|
|
|
if (aModifiers.numericKeyPad) modifiers |= 0x01000000;
|
2008-10-18 01:37:59 -07:00
|
|
|
|
2008-05-05 16:01:07 -07:00
|
|
|
utils.sendNativeKeyEvent(aLayout, aKeyCode, modifiers,
|
|
|
|
aSystemChars, aSystemUnmodifiedChars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var keyboardLayouts;
|
2009-03-30 14:42:11 -07:00
|
|
|
if (IS_MAC) {
|
2008-05-05 16:01:07 -07:00
|
|
|
// These constants can be found by inspecting files under
|
|
|
|
// /System/Library/Keyboard\ Layouts/Unicode.bundle/Contents/Resources/
|
2008-05-07 14:54:21 -07:00
|
|
|
// XXX if you need a new keyboard layout and that uses KCHR resource,
|
|
|
|
// you need to modify GetScriptFromKeyboardLayout of nsChildView.mm
|
2008-05-05 16:01:07 -07:00
|
|
|
keyboardLayouts = {
|
2008-05-08 15:41:13 -07:00
|
|
|
"US":0,
|
2008-05-07 14:54:21 -07:00
|
|
|
"Greek":-18944,
|
2008-05-08 15:41:13 -07:00
|
|
|
"German":3,
|
|
|
|
"Swedish":224
|
2008-05-05 16:01:07 -07:00
|
|
|
};
|
2009-03-30 14:42:11 -07:00
|
|
|
} else if (IS_WIN) {
|
2008-05-05 16:01:07 -07:00
|
|
|
// These constants can be found by inspecting registry keys under
|
|
|
|
// HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Keyboard Layouts
|
|
|
|
keyboardLayouts = {
|
|
|
|
"US":0x409,
|
2008-05-08 15:41:13 -07:00
|
|
|
"Greek":0x408,
|
2008-05-11 17:39:29 -07:00
|
|
|
"Swedish":0x41d,
|
|
|
|
"Arabic":0x401,
|
|
|
|
"Hebrew":0x40d,
|
2008-10-13 23:01:51 -07:00
|
|
|
"Japanese":0x411,
|
|
|
|
"Lithuanian":0x10427
|
2008-05-05 16:01:07 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2008-05-08 15:41:13 -07:00
|
|
|
function eventToString(aEvent)
|
|
|
|
{
|
|
|
|
var name = aEvent.layout + " '" + aEvent.chars + "'";
|
|
|
|
if (aEvent.shift) {
|
|
|
|
name += " [Shift]";
|
|
|
|
}
|
2008-10-18 01:37:59 -07:00
|
|
|
if (aEvent.shiftRight) {
|
|
|
|
name += " [Right Shift]";
|
|
|
|
}
|
2008-05-08 15:41:13 -07:00
|
|
|
if (aEvent.ctrl) {
|
|
|
|
name += " [Ctrl]";
|
|
|
|
}
|
2008-10-18 01:37:59 -07:00
|
|
|
if (aEvent.ctrlRight) {
|
|
|
|
name += " [Right Ctrl]";
|
|
|
|
}
|
2008-05-08 15:41:13 -07:00
|
|
|
if (aEvent.alt) {
|
|
|
|
name += " [Alt]";
|
|
|
|
}
|
2008-10-18 01:37:59 -07:00
|
|
|
if (aEvent.altRight) {
|
|
|
|
name += " [Right Alt]";
|
|
|
|
}
|
2008-05-08 15:41:13 -07:00
|
|
|
if (aEvent.command) {
|
|
|
|
name += " [Command]";
|
|
|
|
}
|
2008-10-18 01:37:59 -07:00
|
|
|
if (aEvent.commandRight) {
|
|
|
|
name += " [Right Command]";
|
|
|
|
}
|
2008-05-08 15:41:13 -07:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2008-10-13 23:01:51 -07:00
|
|
|
function synthesizeKey(aEvent, aFocusElementId)
|
2008-05-08 15:41:13 -07:00
|
|
|
{
|
2008-10-13 23:01:51 -07:00
|
|
|
document.getElementById(aFocusElementId).focus();
|
2008-05-08 15:41:13 -07:00
|
|
|
|
|
|
|
synthesizeNativeKey(keyboardLayouts[aEvent.layout],
|
|
|
|
aEvent.keyCode, aEvent, aEvent.chars, aEvent.unmodifiedChars);
|
|
|
|
}
|
|
|
|
|
2008-10-15 20:04:39 -07:00
|
|
|
// Test the charcodes and modifiers being delivered to keypress handlers and
|
|
|
|
// also keydown/keyup events too.
|
|
|
|
function runKeyEventTests()
|
2008-05-05 16:01:07 -07:00
|
|
|
{
|
2008-10-15 20:04:39 -07:00
|
|
|
var eventList, keyDownFlags, keyUpFlags, testingEvent;
|
|
|
|
const kShiftFlag = 0x1;
|
|
|
|
const kCtrlFlag = 0x2;
|
|
|
|
const kAltFlag = 0x4;
|
|
|
|
const kMetaFlag = 0x8;
|
|
|
|
const kNumLockFlag = 0x10;
|
|
|
|
const kCapsLockFlag = 0x20;
|
|
|
|
|
|
|
|
function onKeyEvent(e)
|
2008-05-05 16:01:07 -07:00
|
|
|
{
|
2008-10-15 20:04:39 -07:00
|
|
|
function removeFlag(e, aFlag)
|
|
|
|
{
|
|
|
|
if (e.type == "keydown") {
|
|
|
|
var oldValue = keyDownFlags;
|
|
|
|
keyDownFlags &= ~aFlag;
|
|
|
|
return oldValue != keyDownFlags;
|
|
|
|
} else if (e.type == "keyup") {
|
|
|
|
var oldValue = keyUpFlags;
|
|
|
|
keyUpFlags &= ~aFlag;
|
|
|
|
return oldValue != keyUpFlags;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isStateChangingModifierKeyEvent(e)
|
|
|
|
{
|
|
|
|
switch (e.keyCode) {
|
|
|
|
case e.DOM_VK_SHIFT:
|
|
|
|
return (testingEvent.shift || testingEvent.shiftRight) && removeFlag(e, kShiftFlag);
|
|
|
|
case e.DOM_VK_CONTROL:
|
|
|
|
return (testingEvent.ctrl || testingEvent.ctrlRight) && removeFlag(e, kCtrlFlag);
|
|
|
|
case e.DOM_VK_ALT:
|
|
|
|
return (testingEvent.alt || testingEvent.altRight) && removeFlag(e, kAltFlag);
|
|
|
|
case e.DOM_VK_META:
|
|
|
|
return testingEvent.command && removeFlag(e, kMetaFlag);
|
|
|
|
case e.DOM_VK_NUM_LOCK:
|
|
|
|
return testingEvent.numLock && removeFlag(e, kNumLockFlag);
|
|
|
|
case e.DOM_VK_CAPS_LOCK:
|
|
|
|
return testingEvent.capsLock && removeFlag(e, kCapsLockFlag);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore the state changing key events which is fired by the testing event.
|
|
|
|
if (!isStateChangingModifierKeyEvent(e))
|
|
|
|
eventList.push(e);
|
2008-05-05 16:01:07 -07:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
2008-10-15 20:04:39 -07:00
|
|
|
const SHOULD_DELIVER_NONE = 0x0;
|
|
|
|
const SHOULD_DELIVER_KEYDOWN = 0x1;
|
|
|
|
const SHOULD_DELIVER_KEYPRESS = 0x2;
|
|
|
|
const SHOULD_DELIVER_KEYUP = 0x4;
|
|
|
|
const SHOULD_DELIVER_ALL = SHOULD_DELIVER_KEYDOWN |
|
|
|
|
SHOULD_DELIVER_KEYPRESS |
|
|
|
|
SHOULD_DELIVER_KEYUP;
|
|
|
|
const SHOULD_DELIVER_KEYDOWN_KEYUP = SHOULD_DELIVER_KEYDOWN |
|
|
|
|
SHOULD_DELIVER_KEYUP;
|
|
|
|
const SHOULD_DELIVER_KEYDOWN_KEYPRESS = SHOULD_DELIVER_KEYDOWN |
|
|
|
|
SHOULD_DELIVER_KEYPRESS;
|
|
|
|
|
2008-05-05 16:01:07 -07:00
|
|
|
// The first parameter is the complete input event. The second parameter is
|
2008-10-15 20:04:39 -07:00
|
|
|
// what to test against. The third parameter is which key events should be
|
|
|
|
// delived for the event.
|
|
|
|
function testKey(aEvent, aExpectGeckoChar, aShouldDelivedEvent)
|
2008-05-05 16:01:07 -07:00
|
|
|
{
|
2008-10-15 20:04:39 -07:00
|
|
|
eventList = [];
|
|
|
|
|
|
|
|
// The modifier key events which are fired for state changing are har to
|
|
|
|
// test. We should ignore them for now.
|
|
|
|
keyDownFlags = keyUpFlags = 0;
|
2009-03-30 14:42:11 -07:00
|
|
|
if (!IS_MAC) {
|
2008-10-15 20:04:39 -07:00
|
|
|
// On Mac, nsChildView doesn't generate modifier keydown/keyup events for
|
|
|
|
// state changing for synthesizeNativeKeyEvent.
|
|
|
|
if (aEvent.shift || aEvent.shiftRight)
|
|
|
|
keyDownFlags |= kShiftFlag;
|
|
|
|
if (aEvent.ctrl || aEvent.ctrlRight)
|
|
|
|
keyDownFlags |= kCtrlFlag;
|
|
|
|
if (aEvent.alt || aEvent.altRight)
|
|
|
|
keyDownFlags |= kAltFlag;
|
|
|
|
if (aEvent.command)
|
|
|
|
keyDownFlags |= kMetaFlag;
|
|
|
|
if (aEvent.numLock)
|
|
|
|
keyDownFlags |= kNumLockFlag;
|
|
|
|
if (aEvent.capsLock)
|
|
|
|
keyDownFlags |= kCapsLockFlag;
|
|
|
|
keyUpFlags = keyDownFlags;
|
|
|
|
}
|
2009-03-30 14:42:11 -07:00
|
|
|
|
2008-10-15 20:04:39 -07:00
|
|
|
testingEvent = aEvent;
|
|
|
|
|
2008-10-13 23:01:51 -07:00
|
|
|
synthesizeKey(aEvent, "button");
|
2008-05-05 16:01:07 -07:00
|
|
|
|
2008-05-08 15:41:13 -07:00
|
|
|
var name = eventToString(aEvent);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
2008-10-15 20:04:39 -07:00
|
|
|
var expectEventTypeList = [];
|
|
|
|
if (aShouldDelivedEvent & SHOULD_DELIVER_KEYDOWN)
|
|
|
|
expectEventTypeList.push("keydown");
|
|
|
|
if (aShouldDelivedEvent & SHOULD_DELIVER_KEYPRESS)
|
|
|
|
expectEventTypeList.push("keypress");
|
|
|
|
if (aShouldDelivedEvent & SHOULD_DELIVER_KEYUP)
|
|
|
|
expectEventTypeList.push("keyup");
|
|
|
|
is(eventList.length, expectEventTypeList.length, name + ", wrong number of key events");
|
|
|
|
|
|
|
|
var longerLength = Math.max(eventList.length, expectEventTypeList.length);
|
|
|
|
for (var i = 0; i < longerLength; i++) {
|
|
|
|
var firedEventType = i < eventList.length ? eventList[i].type : "";
|
|
|
|
var expectEventType = i < expectEventTypeList.length ? expectEventTypeList[i] : "";
|
|
|
|
if (firedEventType != "")
|
|
|
|
is(firedEventType, expectEventType, name + ", wrong type event fired");
|
|
|
|
else
|
|
|
|
is(firedEventType, expectEventType, name + ", a needed event is not fired");
|
|
|
|
|
|
|
|
if (firedEventType != "") {
|
|
|
|
var e = eventList[i];
|
2008-10-18 01:37:59 -07:00
|
|
|
is(e.ctrlKey, aEvent.ctrl || aEvent.ctrlRight || 0, name + ", Ctrl mismatch");
|
|
|
|
is(e.metaKey, aEvent.command || aEvent.commandRight || 0, name + ", Command mismatch");
|
|
|
|
is(e.altKey, aEvent.alt || aEvent.altRight || 0, name + ", Alt mismatch");
|
|
|
|
is(e.shiftKey, aEvent.shift || aEvent.shiftRight || 0, name + ", Shift mismatch");
|
2008-10-15 20:04:39 -07:00
|
|
|
|
|
|
|
if (aExpectGeckoChar.length > 0 && e.type == "keypress")
|
|
|
|
is(e.charCode, aExpectGeckoChar.charCodeAt(0), name + ", charcode");
|
|
|
|
else
|
|
|
|
is(e.charCode, 0, name + ", no charcode");
|
|
|
|
}
|
2008-05-05 16:01:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-08 15:41:13 -07:00
|
|
|
// These tests have to be per-plaform.
|
2008-10-15 20:04:39 -07:00
|
|
|
document.addEventListener("keydown", onKeyEvent, false);
|
|
|
|
document.addEventListener("keypress", onKeyEvent, false);
|
|
|
|
document.addEventListener("keyup", onKeyEvent, false);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
2009-03-30 14:42:11 -07:00
|
|
|
if (IS_MAC) {
|
2008-05-05 16:01:07 -07:00
|
|
|
// On Mac, you can produce event records for any desired keyboard input
|
|
|
|
// by running with NSPR_LOG_MODULES=nsCocoaWidgets:5 and typing into the browser.
|
|
|
|
// We will dump the key event fields to the console. Use the International system
|
|
|
|
// preferences widget to enable other keyboard layouts and select them from the
|
|
|
|
// input menu to see what keyboard events they generate.
|
|
|
|
// Note that it's possible to send bogus key events here, e.g.
|
|
|
|
// {keyCode:0, chars:"z", unmodifiedChars:"P"} --- sendNativeKeyEvent
|
|
|
|
// makes no attempt to verify that the keyCode matches the characters. So only
|
|
|
|
// test key event records that you saw Cocoa send.
|
|
|
|
|
|
|
|
// Plain text input
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, chars:"a", unmodifiedChars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_ALL);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:11, chars:"b", unmodifiedChars:"b"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"b", SHOULD_DELIVER_ALL);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, shift:1, chars:"A", unmodifiedChars:"A"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Ctrl keys
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_ALL);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, ctrl:1, shift:1, chars:"\u0001", unmodifiedChars:"A"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Alt keys
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, alt:1, chars:"\u00e5", unmodifiedChars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00e5", SHOULD_DELIVER_ALL);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, alt:1, shift:1, chars:"\u00c5", unmodifiedChars:"A"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00c5", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Command keys
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, command:1, chars:"a", unmodifiedChars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-08 17:01:29 -07:00
|
|
|
// Shift-cmd gives us the shifted character
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, command:1, shift:1, chars:"a", unmodifiedChars:"A"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-05 16:01:07 -07:00
|
|
|
// Ctrl-cmd gives us the unshifted character
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, command:1, ctrl:1, chars:"\u0001", unmodifiedChars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-08 17:01:29 -07:00
|
|
|
// Alt-cmd gives us the shifted character
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, command:1, alt:1, chars:"\u00e5", unmodifiedChars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00e5", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, command:1, alt:1, shift:1, chars:"\u00c5", unmodifiedChars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00c5", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Greek ctrl keys produce Latin charcodes
|
|
|
|
testKey({layout:"Greek", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"\u03b1"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"Greek", keyCode:0, ctrl:1, shift:1, chars:"\u0001", unmodifiedChars:"\u0391"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Greek command keys
|
|
|
|
testKey({layout:"Greek", keyCode:0, command:1, chars:"a", unmodifiedChars:"\u03b1"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-08 17:01:29 -07:00
|
|
|
// Shift-cmd gives us the shifted character
|
2011-06-10 11:21:57 -07:00
|
|
|
testKey({layout:"Greek", keyCode:0, command:1, shift:1, chars:"a", unmodifiedChars:"\u0391"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-05 16:01:07 -07:00
|
|
|
// Ctrl-cmd gives us the unshifted character
|
|
|
|
testKey({layout:"Greek", keyCode:0, command:1, ctrl:1, chars:"\u0001", unmodifiedChars:"\u03b1"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-08 17:01:29 -07:00
|
|
|
// Alt-cmd gives us the shifted character
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"Greek", keyCode:0, command:1, alt:1, chars:"\u00a8", unmodifiedChars:"\u03b1"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00a8", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"Greek", keyCode:0, command:1, alt:1, shift:1, chars:"\u00b9", unmodifiedChars:"\u0391"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00b9", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-07 14:54:21 -07:00
|
|
|
|
|
|
|
// German (KCHR/KeyTranslate case)
|
|
|
|
testKey({layout:"German", keyCode:0, chars:"a", unmodifiedChars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_ALL);
|
2008-05-07 14:54:21 -07:00
|
|
|
testKey({layout:"German", keyCode:33, chars:"\u00fc", unmodifiedChars:"\u00fc"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00fc", SHOULD_DELIVER_ALL);
|
2008-05-09 16:10:40 -07:00
|
|
|
testKey({layout:"German", keyCode:27, chars:"\u00df", unmodifiedChars:"\u00df"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00df", SHOULD_DELIVER_ALL);
|
2008-05-09 16:10:40 -07:00
|
|
|
testKey({layout:"German", keyCode:27, shift:1, chars:"?", unmodifiedChars:"?"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"?", SHOULD_DELIVER_ALL);
|
2008-05-09 16:10:40 -07:00
|
|
|
testKey({layout:"German", keyCode:27, command:1, chars:"\u00df", unmodifiedChars:"\u00df"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u00df", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-05-09 16:10:40 -07:00
|
|
|
// Shift+SS is '?' but Cmd+Shift+SS is '/' on German layout.
|
2009-08-17 21:47:53 -07:00
|
|
|
testKey({layout:"German", keyCode:27, command:1, shift:1, chars:"/", unmodifiedChars:"?"},
|
|
|
|
"?", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
2008-10-15 20:04:39 -07:00
|
|
|
|
|
|
|
// Caps Lock key event
|
|
|
|
// XXX keyup event of Caps Lock key is not fired.
|
|
|
|
testKey({layout:"US", keyCode:57, capsLock:1, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
2008-10-18 01:37:59 -07:00
|
|
|
testKey({layout:"US", keyCode:57, capsLock:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
|
|
|
|
|
|
|
// Shift/RightShift key event
|
|
|
|
testKey({layout:"US", keyCode:56, shift:1, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
|
|
|
testKey({layout:"US", keyCode:56, shift:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYUP);
|
|
|
|
testKey({layout:"US", keyCode:60, shiftRight:1, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
|
|
|
testKey({layout:"US", keyCode:60, shiftRight:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYUP);
|
|
|
|
|
|
|
|
// Control/RightControl key event
|
|
|
|
testKey({layout:"US", keyCode:59, ctrl:1, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
|
|
|
testKey({layout:"US", keyCode:59, ctrl:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYUP);
|
|
|
|
testKey({layout:"US", keyCode:62, ctrlRight:1, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
|
|
|
testKey({layout:"US", keyCode:62, ctrlRight:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYUP);
|
|
|
|
|
|
|
|
// Option/RightOption key event
|
|
|
|
testKey({layout:"US", keyCode:58, alt:1, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
|
|
|
testKey({layout:"US", keyCode:58, alt:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYUP);
|
|
|
|
testKey({layout:"US", keyCode:61, altRight:1, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
|
|
|
testKey({layout:"US", keyCode:61, altRight:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYUP);
|
|
|
|
|
|
|
|
// Command/RightCommand key event
|
|
|
|
testKey({layout:"US", keyCode:55, command:1, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
|
|
|
testKey({layout:"US", keyCode:55, command:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYUP);
|
|
|
|
testKey({layout:"US", keyCode:54, commandRight:1, chars:"", unmodifiedChars:""},
|
2008-10-15 20:04:39 -07:00
|
|
|
"", SHOULD_DELIVER_KEYDOWN);
|
2008-10-18 01:37:59 -07:00
|
|
|
testKey({layout:"US", keyCode:54, commandRight:0, chars:"", unmodifiedChars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYUP);
|
2008-05-05 16:01:07 -07:00
|
|
|
}
|
2009-03-30 14:42:11 -07:00
|
|
|
else if (IS_WIN) {
|
2008-05-05 16:01:07 -07:00
|
|
|
// On Windows, you can use Spy++ or Winspector (free) to watch window messages.
|
|
|
|
// The keyCode is given by the wParam of the last WM_KEYDOWN message. The
|
|
|
|
// chars string is given by the wParam of the WM_CHAR message. unmodifiedChars
|
|
|
|
// is not needed on Windows.
|
|
|
|
|
|
|
|
// Plain text input
|
|
|
|
testKey({layout:"US", keyCode:65, chars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"US", keyCode:66, chars:"b"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"b", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"US", keyCode:65, shift:1, chars:"A"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Ctrl keys
|
|
|
|
testKey({layout:"US", keyCode:65, ctrl:1, chars:"\u0001"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"US", keyCode:65, ctrl:1, shift:1, chars:"\u0001"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Alt keys
|
|
|
|
testKey({layout:"US", keyCode:65, alt:1, chars:"a"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"US", keyCode:65, alt:1, shift:1, chars:"A"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_ALL);
|
|
|
|
|
2008-05-05 16:01:07 -07:00
|
|
|
// Shift-ctrl-alt generates no WM_CHAR, but we still get a keypress
|
|
|
|
testKey({layout:"US", keyCode:65, alt:1, ctrl:1, shift:1, chars:""},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Greek plain text
|
|
|
|
testKey({layout:"Greek", keyCode:65, chars:"\u03b1"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u03b1", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"Greek", keyCode:65, shift:1, chars:"\u0391"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"\u0391", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
// Greek ctrl keys produce Latin charcodes
|
|
|
|
testKey({layout:"Greek", keyCode:65, ctrl:1, chars:"\u0001"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"a", SHOULD_DELIVER_ALL);
|
2008-05-05 16:01:07 -07:00
|
|
|
testKey({layout:"Greek", keyCode:65, ctrl:1, shift:1, chars:"\u0001"},
|
2008-10-15 20:04:39 -07:00
|
|
|
"A", SHOULD_DELIVER_ALL);
|
|
|
|
|
|
|
|
// Caps Lock key event
|
|
|
|
testKey({layout:"US", keyCode:20, capsLock:1, chars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN_KEYUP);
|
|
|
|
testKey({layout:"US", keyCode:20, capsLock:0, chars:""},
|
|
|
|
"", SHOULD_DELIVER_KEYDOWN_KEYUP);
|
2008-05-05 16:01:07 -07:00
|
|
|
}
|
|
|
|
|
2008-10-15 20:04:39 -07:00
|
|
|
document.removeEventListener("keydown", onKeyEvent, false);
|
|
|
|
document.removeEventListener("keypress", onKeyEvent, false);
|
|
|
|
document.removeEventListener("keyup", onKeyEvent, false);
|
2008-05-05 16:01:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the activation (or not) of an HTML accesskey
|
|
|
|
function runAccessKeyTests()
|
|
|
|
{
|
|
|
|
var button = document.getElementById("button");
|
|
|
|
var activationCount;
|
|
|
|
|
|
|
|
function onClick(e)
|
|
|
|
{
|
|
|
|
++activationCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The first parameter is the complete input event. The second and third parameters are
|
|
|
|
// what to test against.
|
|
|
|
function testKey(aEvent, aAccessKey, aShouldActivate)
|
|
|
|
{
|
|
|
|
activationCount = 0;
|
|
|
|
button.setAttribute("accesskey", aAccessKey);
|
|
|
|
|
2008-10-13 23:01:51 -07:00
|
|
|
synthesizeKey(aEvent, "button");
|
2008-05-05 16:01:07 -07:00
|
|
|
|
2008-05-08 15:41:13 -07:00
|
|
|
var name = eventToString(aEvent);
|
2008-05-05 16:01:07 -07:00
|
|
|
|
|
|
|
is(activationCount, aShouldActivate ? 1 : 0, name + ", activating '" + aAccessKey + "'");
|
|
|
|
}
|
|
|
|
|
|
|
|
button.addEventListener("click", onClick, false);
|
|
|
|
|
|
|
|
// These tests have to be per-plaform.
|
2009-03-30 14:42:11 -07:00
|
|
|
if (IS_MAC) {
|
2008-05-05 16:01:07 -07:00
|
|
|
// Basic sanity checks
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, chars:"a", unmodifiedChars:"a"},
|
2008-05-05 16:01:07 -07:00
|
|
|
"a", false);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"a"},
|
2008-05-05 16:01:07 -07:00
|
|
|
"a", true);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"a"},
|
2008-05-05 16:01:07 -07:00
|
|
|
"A", true);
|
|
|
|
|
|
|
|
// Shift-ctrl does not activate accesskeys
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, ctrl:1, shift:1, chars:"\u0001", unmodifiedChars:"A"},
|
2008-05-05 16:01:07 -07:00
|
|
|
"a", false);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, ctrl:1, shift:1, chars:"\u0001", unmodifiedChars:"A"},
|
2008-05-05 16:01:07 -07:00
|
|
|
"A", false);
|
|
|
|
// Alt-ctrl does not activate accesskeys
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, ctrl:1, alt:1, chars:"\u0001", unmodifiedChars:"a"},
|
2008-05-05 16:01:07 -07:00
|
|
|
"a", false);
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:0, ctrl:1, alt:1, chars:"\u0001", unmodifiedChars:"a"},
|
2008-05-05 16:01:07 -07:00
|
|
|
"A", false);
|
|
|
|
|
|
|
|
// Greek layout can activate a Latin accesskey
|
|
|
|
testKey({layout:"Greek", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"\u03b1"},
|
|
|
|
"a", true);
|
|
|
|
testKey({layout:"Greek", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"\u03b1"},
|
|
|
|
"A", true);
|
|
|
|
// ... and a Greek accesskey!
|
|
|
|
testKey({layout:"Greek", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"\u03b1"},
|
|
|
|
"\u03b1", true);
|
|
|
|
testKey({layout:"Greek", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"\u03b1"},
|
|
|
|
"\u0391", true);
|
2008-05-07 14:54:21 -07:00
|
|
|
|
2008-05-08 15:41:13 -07:00
|
|
|
// bug 359638
|
|
|
|
testKey({layout:"US", keyCode:47, ctrl:1, chars:".", unmodifiedChars:"."},
|
|
|
|
".", true);
|
|
|
|
|
2008-05-07 14:54:21 -07:00
|
|
|
// German (KCHR/KeyTranslate case)
|
|
|
|
testKey({layout:"German", keyCode:0, ctrl:1, chars:"a", unmodifiedChars:"a"},
|
|
|
|
"a", true);
|
|
|
|
testKey({layout:"German", keyCode:0, ctrl:1, chars:"a", unmodifiedChars:"a"},
|
|
|
|
"A", true);
|
|
|
|
testKey({layout:"German", keyCode:33, ctrl:1, chars:"\u00fc", unmodifiedChars:"\u00fc"},
|
|
|
|
"\u00fc", true);
|
|
|
|
testKey({layout:"German", keyCode:33, ctrl:1, chars:"\u00fc", unmodifiedChars:"\u00fc"},
|
|
|
|
"\u00dc", true);
|
2008-05-05 16:01:07 -07:00
|
|
|
}
|
2009-03-30 14:42:11 -07:00
|
|
|
else if (IS_WIN) {
|
2008-05-05 16:01:07 -07:00
|
|
|
// Basic sanity checks
|
|
|
|
testKey({layout:"US", keyCode:65, chars:"a"},
|
|
|
|
"a", false);
|
|
|
|
testKey({layout:"US", keyCode:65, shift:1, alt:1, chars:"A"},
|
|
|
|
"a", true);
|
|
|
|
testKey({layout:"US", keyCode:65, shift:1, alt:1, chars:"A"},
|
|
|
|
"A", true);
|
|
|
|
|
|
|
|
// shift-alt-ctrl does not activate accesskeys
|
|
|
|
testKey({layout:"US", keyCode:65, ctrl:1, shift:1, alt:1, chars:""},
|
|
|
|
"a", false);
|
|
|
|
testKey({layout:"US", keyCode:65, ctrl:1, shift:1, alt:1, chars:""},
|
|
|
|
"A", false);
|
|
|
|
|
|
|
|
// Greek layout can activate a Latin accesskey
|
2008-05-06 21:46:37 -07:00
|
|
|
testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
|
|
|
|
"a", true);
|
|
|
|
testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
|
|
|
|
"A", true);
|
2008-05-05 16:01:07 -07:00
|
|
|
// ... and a Greek accesskey!
|
2008-05-06 21:46:37 -07:00
|
|
|
testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
|
|
|
|
"\u03b1", true);
|
|
|
|
testKey({layout:"Greek", keyCode:65, shift:1, alt:1, chars:"A"},
|
|
|
|
"\u0391", true);
|
2008-05-08 15:41:13 -07:00
|
|
|
|
|
|
|
// bug 359638
|
|
|
|
testKey({layout:"US", keyCode:190, shift:1, alt:1, chars:".", unmodifiedChars:"."},
|
|
|
|
".", true);
|
2008-05-05 16:01:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
button.removeEventListener("click", onClick, false);
|
|
|
|
}
|
|
|
|
|
2008-05-08 15:41:13 -07:00
|
|
|
function runXULKeyTests()
|
|
|
|
{
|
|
|
|
function testKey(aEvent, aElem, aShouldActivate)
|
|
|
|
{
|
|
|
|
var elem = document.getElementById(aElem);
|
|
|
|
elem.activeCount = 0;
|
|
|
|
|
2008-10-13 23:01:51 -07:00
|
|
|
synthesizeKey(aEvent, "button");
|
2008-05-08 15:41:13 -07:00
|
|
|
|
|
|
|
var name = eventToString(aEvent);
|
|
|
|
|
|
|
|
is(elem.activeCount, aShouldActivate ? 1 : 0,
|
|
|
|
name + " activating " + aElem);
|
|
|
|
}
|
|
|
|
|
2009-03-30 14:42:11 -07:00
|
|
|
if (IS_MAC) {
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:41, command:1, chars:";", unmodifiedChars:";"},
|
|
|
|
"unshiftedKey", true);
|
|
|
|
testKey({layout:"US", keyCode:41, command:1, chars:";", unmodifiedChars:";"},
|
|
|
|
"shiftedKey", false);
|
|
|
|
testKey({layout:"US", keyCode:41, command:1, shift:1, chars:";", unmodifiedChars:":"},
|
|
|
|
"shiftedKey", true);
|
|
|
|
testKey({layout:"US", keyCode:41, command:1, shift:1, chars:";", unmodifiedChars:":"},
|
|
|
|
"unshiftedKey", false);
|
|
|
|
}
|
2009-03-30 14:42:11 -07:00
|
|
|
else if (IS_WIN) {
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:186, ctrl:1, chars:";"},
|
|
|
|
"unshiftedKey", true);
|
|
|
|
testKey({layout:"US", keyCode:186, ctrl:1, chars:";"},
|
|
|
|
"shiftedKey", false);
|
|
|
|
testKey({layout:"US", keyCode:186, ctrl:1, shift:1, chars:";"},
|
|
|
|
"shiftedKey", true);
|
|
|
|
testKey({layout:"US", keyCode:186, ctrl:1, shift:1, chars:";"},
|
|
|
|
"unshiftedKey", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
keyElems = ["commandOptionF"];
|
|
|
|
|
|
|
|
// 429160
|
2009-03-30 14:42:11 -07:00
|
|
|
if (IS_MAC) {
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:3, command:1, alt:1, chars:"\u0192", unmodifiedChars:"f"},
|
|
|
|
"commandOptionF", true);
|
|
|
|
}
|
2009-03-30 14:42:11 -07:00
|
|
|
else if (IS_WIN) {
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"US", keyCode:70, ctrl:1, alt:1, chars:"\u0006"},
|
|
|
|
"commandOptionF", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 432112
|
2009-03-30 14:42:11 -07:00
|
|
|
if (IS_MAC) {
|
2009-08-17 21:47:53 -07:00
|
|
|
testKey({layout:"Swedish", keyCode:27, command:1, shift:1, chars:"+", unmodifiedChars:"?"},
|
|
|
|
"question", true);
|
2008-05-08 15:41:13 -07:00
|
|
|
}
|
2009-03-30 14:42:11 -07:00
|
|
|
else if (IS_WIN) {
|
2008-05-08 15:41:13 -07:00
|
|
|
testKey({layout:"Swedish", keyCode:187, ctrl:1, shift:1, chars:""},
|
|
|
|
"question", true);
|
|
|
|
testKey({layout:"Swedish", keyCode:187, ctrl:1, chars:""},
|
|
|
|
"question", false);
|
|
|
|
}
|
2008-05-11 17:39:29 -07:00
|
|
|
|
|
|
|
// bug 433192
|
2009-03-30 14:42:11 -07:00
|
|
|
if (IS_WIN) {
|
2008-05-11 17:39:29 -07:00
|
|
|
testKey({layout:"US", keyCode:88, ctrl:1, chars:"\u0018"},
|
|
|
|
"unshiftedX", true);
|
|
|
|
testKey({layout:"US", keyCode:88, ctrl:1, chars:"\u0018"},
|
|
|
|
"shiftedX", false);
|
|
|
|
testKey({layout:"US", keyCode:88, ctrl:1, shift:1, chars:"\u0018"},
|
|
|
|
"unshiftedX", false);
|
|
|
|
testKey({layout:"US", keyCode:88, ctrl:1, shift:1, chars:"\u0018"},
|
|
|
|
"shiftedX", true);
|
|
|
|
testKey({layout:"Arabic", keyCode:88, ctrl:1, chars:"\u0018"},
|
|
|
|
"unshiftedX", true);
|
|
|
|
testKey({layout:"Arabic", keyCode:88, ctrl:1, chars:"\u0018"},
|
|
|
|
"shiftedX", false);
|
|
|
|
testKey({layout:"Arabic", keyCode:88, ctrl:1, shift:1, chars:"\u0018"},
|
|
|
|
"unshiftedX", false);
|
|
|
|
testKey({layout:"Arabic", keyCode:88, ctrl:1, shift:1, chars:"\u0018"},
|
|
|
|
"shiftedX", true);
|
|
|
|
testKey({layout:"Hebrew", keyCode:88, ctrl:1, chars:"\u0018"},
|
|
|
|
"unshiftedX", true);
|
|
|
|
testKey({layout:"Hebrew", keyCode:88, ctrl:1, chars:"\u0018"},
|
|
|
|
"shiftedX", false);
|
|
|
|
testKey({layout:"Hebrew", keyCode:88, ctrl:1, shift:1, chars:"\u0018"},
|
|
|
|
"unshiftedX", false);
|
|
|
|
testKey({layout:"Hebrew", keyCode:88, ctrl:1, shift:1, chars:"\u0018"},
|
|
|
|
"shiftedX", true);
|
|
|
|
testKey({layout:"Japanese", keyCode:187, ctrl:1, chars:""},
|
|
|
|
"unshiftedPlus", false);
|
|
|
|
testKey({layout:"Japanese", keyCode:187, ctrl:1, shift:1, chars:""},
|
|
|
|
"unshiftedPlus", true);
|
|
|
|
}
|
2008-05-08 15:41:13 -07:00
|
|
|
}
|
|
|
|
|
2008-10-13 23:01:51 -07:00
|
|
|
function runTextInputTests()
|
|
|
|
{
|
|
|
|
var textbox = document.getElementById("textbox");
|
|
|
|
|
|
|
|
function testKey(aEvent, aExpectText) {
|
|
|
|
textbox.value = "";
|
|
|
|
textbox.focus();
|
|
|
|
|
|
|
|
synthesizeKey(aEvent, "textbox");
|
|
|
|
|
|
|
|
var name = eventToString(aEvent);
|
|
|
|
|
|
|
|
is(textbox.value, aExpectText, name + " does not input correct text.");
|
|
|
|
}
|
|
|
|
|
2009-03-30 14:42:11 -07:00
|
|
|
if (IS_WIN) {
|
2008-10-13 23:01:51 -07:00
|
|
|
// Basic sanity checks
|
|
|
|
testKey({layout:"US", keyCode:65, chars:"a"},
|
|
|
|
"a");
|
|
|
|
testKey({layout:"US", keyCode:65, shift:1, chars:"A"},
|
|
|
|
"A");
|
|
|
|
// When Ctrl+Alt are pressed, any text should not be inputted.
|
|
|
|
testKey({layout:"US", keyCode:65, ctrl:1, alt:1, chars:""},
|
|
|
|
"");
|
|
|
|
|
|
|
|
// Lithuanian AltGr should be consumed at 9/0 keys pressed
|
|
|
|
testKey({layout:"Lithuanian", keyCode:56, chars:"\u016B"},
|
|
|
|
"\u016B");
|
|
|
|
testKey({layout:"Lithuanian", keyCode:57, chars:"9"},
|
|
|
|
"9");
|
|
|
|
testKey({layout:"Lithuanian", keyCode:48, chars:"0"},
|
|
|
|
"0");
|
|
|
|
testKey({layout:"Lithuanian", keyCode:56, ctrl:1, alt:1, chars:"8"},
|
|
|
|
"8");
|
|
|
|
testKey({layout:"Lithuanian", keyCode:57, ctrl:1, alt:1, chars:"9"},
|
|
|
|
"9");
|
|
|
|
testKey({layout:"Lithuanian", keyCode:48, ctrl:1, alt:1, chars:"0"},
|
|
|
|
"0");
|
|
|
|
}
|
2009-03-30 14:42:11 -07:00
|
|
|
else
|
|
|
|
todo(false, "runTextInputTests() checks Windows only");
|
2009-02-12 02:44:38 -08:00
|
|
|
|
|
|
|
// XXX We need to move focus for canceling to search the autocomplete
|
|
|
|
// result. If we don't do here, Fx will crash at end of this tests.
|
|
|
|
document.getElementById("button").focus();
|
2008-10-13 23:01:51 -07:00
|
|
|
}
|
|
|
|
|
2008-05-05 16:01:07 -07:00
|
|
|
function runTest()
|
|
|
|
{
|
2009-03-30 14:42:11 -07:00
|
|
|
if (!IS_MAC && !IS_WIN) {
|
|
|
|
todo(false, "This test is supported on MacOSX and Windows only. (Bug 431503)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2008-10-15 20:04:39 -07:00
|
|
|
runKeyEventTests();
|
2008-05-05 16:01:07 -07:00
|
|
|
runAccessKeyTests();
|
2008-05-08 15:41:13 -07:00
|
|
|
runXULKeyTests();
|
2008-10-13 23:01:51 -07:00
|
|
|
runTextInputTests();
|
2009-03-30 14:42:11 -07:00
|
|
|
|
2008-05-05 16:01:07 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</window>
|