mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 17:23:59 +00:00
Bug 459820 Need automated tests for Caps Lock key events r+sr=roc
This commit is contained in:
parent
7e4a306174
commit
36b09f73c2
@ -201,6 +201,93 @@ nsIWidget * gRollupWidget = nsnull;
|
||||
|
||||
#pragma mark -
|
||||
|
||||
// Key code constants
|
||||
enum
|
||||
{
|
||||
kEscapeKeyCode = 0x35,
|
||||
kRCommandKeyCode = 0x36, // right command key
|
||||
kCommandKeyCode = 0x37,
|
||||
kShiftKeyCode = 0x38,
|
||||
kCapsLockKeyCode = 0x39,
|
||||
kOptionkeyCode = 0x3A,
|
||||
kControlKeyCode = 0x3B,
|
||||
kRShiftKeyCode = 0x3C, // right shift key
|
||||
kROptionKeyCode = 0x3D, // right option key
|
||||
kRControlKeyCode = 0x3E, // right control key
|
||||
kClearKeyCode = 0x47,
|
||||
|
||||
// function keys
|
||||
kF1KeyCode = 0x7A,
|
||||
kF2KeyCode = 0x78,
|
||||
kF3KeyCode = 0x63,
|
||||
kF4KeyCode = 0x76,
|
||||
kF5KeyCode = 0x60,
|
||||
kF6KeyCode = 0x61,
|
||||
kF7KeyCode = 0x62,
|
||||
kF8KeyCode = 0x64,
|
||||
kF9KeyCode = 0x65,
|
||||
kF10KeyCode = 0x6D,
|
||||
kF11KeyCode = 0x67,
|
||||
kF12KeyCode = 0x6F,
|
||||
kF13KeyCode = 0x69,
|
||||
kF14KeyCode = 0x6B,
|
||||
kF15KeyCode = 0x71,
|
||||
|
||||
kPrintScreenKeyCode = kF13KeyCode,
|
||||
kScrollLockKeyCode = kF14KeyCode,
|
||||
kPauseKeyCode = kF15KeyCode,
|
||||
|
||||
// keypad
|
||||
kKeypad0KeyCode = 0x52,
|
||||
kKeypad1KeyCode = 0x53,
|
||||
kKeypad2KeyCode = 0x54,
|
||||
kKeypad3KeyCode = 0x55,
|
||||
kKeypad4KeyCode = 0x56,
|
||||
kKeypad5KeyCode = 0x57,
|
||||
kKeypad6KeyCode = 0x58,
|
||||
kKeypad7KeyCode = 0x59,
|
||||
kKeypad8KeyCode = 0x5B,
|
||||
kKeypad9KeyCode = 0x5C,
|
||||
|
||||
// The following key codes are not defined until Mac OS X 10.5
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
|
||||
kVK_ANSI_1 = 0x12,
|
||||
kVK_ANSI_2 = 0x13,
|
||||
kVK_ANSI_3 = 0x14,
|
||||
kVK_ANSI_4 = 0x15,
|
||||
kVK_ANSI_5 = 0x17,
|
||||
kVK_ANSI_6 = 0x16,
|
||||
kVK_ANSI_7 = 0x1A,
|
||||
kVK_ANSI_8 = 0x1C,
|
||||
kVK_ANSI_9 = 0x19,
|
||||
kVK_ANSI_0 = 0x1D,
|
||||
#endif
|
||||
|
||||
kKeypadMultiplyKeyCode = 0x43,
|
||||
kKeypadAddKeyCode = 0x45,
|
||||
kKeypadSubtractKeyCode = 0x4E,
|
||||
kKeypadDecimalKeyCode = 0x41,
|
||||
kKeypadDivideKeyCode = 0x4B,
|
||||
kKeypadEqualsKeyCode = 0x51, // no correpsonding gecko key code
|
||||
kEnterKeyCode = 0x4C,
|
||||
kReturnKeyCode = 0x24,
|
||||
kPowerbookEnterKeyCode = 0x34, // Enter on Powerbook's keyboard is different
|
||||
|
||||
kInsertKeyCode = 0x72, // also help key
|
||||
kDeleteKeyCode = 0x75, // also forward delete key
|
||||
kTabKeyCode = 0x30,
|
||||
kTildeKeyCode = 0x32,
|
||||
kBackspaceKeyCode = 0x33,
|
||||
kHomeKeyCode = 0x73,
|
||||
kEndKeyCode = 0x77,
|
||||
kPageUpKeyCode = 0x74,
|
||||
kPageDownKeyCode = 0x79,
|
||||
kLeftArrowKeyCode = 0x7B,
|
||||
kRightArrowKeyCode = 0x7C,
|
||||
kUpArrowKeyCode = 0x7E,
|
||||
kDownArrowKeyCode = 0x7D
|
||||
};
|
||||
|
||||
|
||||
/* Convenience routines to go from a gecko rect to cocoa NSRects and back
|
||||
*
|
||||
@ -1377,7 +1464,9 @@ nsresult nsChildView::SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
|
||||
}
|
||||
}
|
||||
int windowNumber = [[mView window] windowNumber];
|
||||
NSEvent* downEvent = [NSEvent keyEventWithType:NSKeyDown
|
||||
BOOL sendFlagsChangedEvent = aNativeKeyCode == kCapsLockKeyCode;
|
||||
NSEventType eventType = sendFlagsChangedEvent ? NSFlagsChanged : NSKeyDown;
|
||||
NSEvent* downEvent = [NSEvent keyEventWithType:eventType
|
||||
location:NSMakePoint(0,0)
|
||||
modifierFlags:modifierFlags
|
||||
timestamp:0
|
||||
@ -1388,15 +1477,17 @@ nsresult nsChildView::SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
|
||||
isARepeat:NO
|
||||
keyCode:aNativeKeyCode];
|
||||
|
||||
NSEvent* upEvent = [ChildView makeNewCocoaEventWithType:NSKeyUp
|
||||
fromEvent:downEvent];
|
||||
NSEvent* upEvent = sendFlagsChangedEvent ? nil :
|
||||
[ChildView makeNewCocoaEventWithType:NSKeyUp
|
||||
fromEvent:downEvent];
|
||||
|
||||
if (downEvent && upEvent) {
|
||||
if (downEvent && (sendFlagsChangedEvent || upEvent)) {
|
||||
KeyboardLayoutOverride currentLayout = gOverrideKeyboardLayout;
|
||||
gOverrideKeyboardLayout.mKeyboardLayout = aNativeKeyboardLayout;
|
||||
gOverrideKeyboardLayout.mOverrideEnabled = PR_TRUE;
|
||||
[NSApp sendEvent:downEvent];
|
||||
[NSApp sendEvent:upEvent];
|
||||
if (upEvent)
|
||||
[NSApp sendEvent:upEvent];
|
||||
// processKeyDownEvent and keyUp block exceptions so we're sure to
|
||||
// reach here to restore gOverrideKeyboardLayout
|
||||
gOverrideKeyboardLayout = currentLayout;
|
||||
@ -3865,94 +3956,6 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
// Key code constants
|
||||
enum
|
||||
{
|
||||
kEscapeKeyCode = 0x35,
|
||||
kRCommandKeyCode = 0x36, // right command key
|
||||
kCommandKeyCode = 0x37,
|
||||
kShiftKeyCode = 0x38,
|
||||
kCapsLockKeyCode = 0x39,
|
||||
kOptionkeyCode = 0x3A,
|
||||
kControlKeyCode = 0x3B,
|
||||
kRShiftKeyCode = 0x3C, // right shift key
|
||||
kROptionKeyCode = 0x3D, // right option key
|
||||
kRControlKeyCode = 0x3E, // right control key
|
||||
kClearKeyCode = 0x47,
|
||||
|
||||
// function keys
|
||||
kF1KeyCode = 0x7A,
|
||||
kF2KeyCode = 0x78,
|
||||
kF3KeyCode = 0x63,
|
||||
kF4KeyCode = 0x76,
|
||||
kF5KeyCode = 0x60,
|
||||
kF6KeyCode = 0x61,
|
||||
kF7KeyCode = 0x62,
|
||||
kF8KeyCode = 0x64,
|
||||
kF9KeyCode = 0x65,
|
||||
kF10KeyCode = 0x6D,
|
||||
kF11KeyCode = 0x67,
|
||||
kF12KeyCode = 0x6F,
|
||||
kF13KeyCode = 0x69,
|
||||
kF14KeyCode = 0x6B,
|
||||
kF15KeyCode = 0x71,
|
||||
|
||||
kPrintScreenKeyCode = kF13KeyCode,
|
||||
kScrollLockKeyCode = kF14KeyCode,
|
||||
kPauseKeyCode = kF15KeyCode,
|
||||
|
||||
// keypad
|
||||
kKeypad0KeyCode = 0x52,
|
||||
kKeypad1KeyCode = 0x53,
|
||||
kKeypad2KeyCode = 0x54,
|
||||
kKeypad3KeyCode = 0x55,
|
||||
kKeypad4KeyCode = 0x56,
|
||||
kKeypad5KeyCode = 0x57,
|
||||
kKeypad6KeyCode = 0x58,
|
||||
kKeypad7KeyCode = 0x59,
|
||||
kKeypad8KeyCode = 0x5B,
|
||||
kKeypad9KeyCode = 0x5C,
|
||||
|
||||
// The following key codes are not defined until Mac OS X 10.5
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
|
||||
kVK_ANSI_1 = 0x12,
|
||||
kVK_ANSI_2 = 0x13,
|
||||
kVK_ANSI_3 = 0x14,
|
||||
kVK_ANSI_4 = 0x15,
|
||||
kVK_ANSI_5 = 0x17,
|
||||
kVK_ANSI_6 = 0x16,
|
||||
kVK_ANSI_7 = 0x1A,
|
||||
kVK_ANSI_8 = 0x1C,
|
||||
kVK_ANSI_9 = 0x19,
|
||||
kVK_ANSI_0 = 0x1D,
|
||||
#endif
|
||||
|
||||
kKeypadMultiplyKeyCode = 0x43,
|
||||
kKeypadAddKeyCode = 0x45,
|
||||
kKeypadSubtractKeyCode = 0x4E,
|
||||
kKeypadDecimalKeyCode = 0x41,
|
||||
kKeypadDivideKeyCode = 0x4B,
|
||||
kKeypadEqualsKeyCode = 0x51, // no correpsonding gecko key code
|
||||
kEnterKeyCode = 0x4C,
|
||||
kReturnKeyCode = 0x24,
|
||||
kPowerbookEnterKeyCode = 0x34, // Enter on Powerbook's keyboard is different
|
||||
|
||||
kInsertKeyCode = 0x72, // also help key
|
||||
kDeleteKeyCode = 0x75, // also forward delete key
|
||||
kTabKeyCode = 0x30,
|
||||
kTildeKeyCode = 0x32,
|
||||
kBackspaceKeyCode = 0x33,
|
||||
kHomeKeyCode = 0x73,
|
||||
kEndKeyCode = 0x77,
|
||||
kPageUpKeyCode = 0x74,
|
||||
kPageDownKeyCode = 0x79,
|
||||
kLeftArrowKeyCode = 0x7B,
|
||||
kRightArrowKeyCode = 0x7C,
|
||||
kUpArrowKeyCode = 0x7E,
|
||||
kDownArrowKeyCode = 0x7D
|
||||
};
|
||||
|
||||
|
||||
static PRBool IsPrintableChar(PRUnichar aChar)
|
||||
{
|
||||
return (aChar >= 0x20 && aChar <= 0x7E) || aChar >= 0xA0;
|
||||
@ -4353,7 +4356,9 @@ static SInt32
|
||||
GetScriptFromKeyboardLayout(SInt32 aLayoutID)
|
||||
{
|
||||
switch (aLayoutID) {
|
||||
case 0: // US
|
||||
case 3: // German
|
||||
case 224: // Swedish
|
||||
case -2: return smRoman; // US-Extended
|
||||
case -18944: return smGreek; // Greek
|
||||
default: NS_NOTREACHED("unknown keyboard layout");
|
||||
|
@ -126,45 +126,141 @@ function synthesizeKey(aEvent, aFocusElementId)
|
||||
aEvent.keyCode, aEvent, aEvent.chars, aEvent.unmodifiedChars);
|
||||
}
|
||||
|
||||
// Test the charcodes and modifiers being delivered to keypress handlers.
|
||||
function runPressTests()
|
||||
// Test the charcodes and modifiers being delivered to keypress handlers and
|
||||
// also keydown/keyup events too.
|
||||
function runKeyEventTests()
|
||||
{
|
||||
var pressList;
|
||||
function onKeyPress(e)
|
||||
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)
|
||||
{
|
||||
pressList.push(e);
|
||||
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);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// The first parameter is the complete input event. The second parameter is
|
||||
// what to test against.
|
||||
// XXX should probably check that keydown and keyup events were dispatched too
|
||||
function testKey(aEvent, aExpectGeckoChar)
|
||||
// what to test against. The third parameter is which key events should be
|
||||
// delived for the event.
|
||||
function testKey(aEvent, aExpectGeckoChar, aShouldDelivedEvent)
|
||||
{
|
||||
pressList = [];
|
||||
|
||||
eventList = [];
|
||||
|
||||
// The modifier key events which are fired for state changing are har to
|
||||
// test. We should ignore them for now.
|
||||
keyDownFlags = keyUpFlags = 0;
|
||||
if (navigator.platform.indexOf("Mac") != 0) {
|
||||
// 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;
|
||||
}
|
||||
testingEvent = aEvent;
|
||||
|
||||
synthesizeKey(aEvent, "button");
|
||||
|
||||
var name = eventToString(aEvent);
|
||||
|
||||
is(pressList.length, aExpectGeckoChar == "" ? 0 : 1, name + ", wrong number of press events");
|
||||
if (pressList.length == 0)
|
||||
return;
|
||||
var e = pressList[0];
|
||||
is(e.ctrlKey, aEvent.ctrl || 0, name + ", Ctrl mismatch");
|
||||
is(e.metaKey, aEvent.command || 0, name + ", Command mismatch");
|
||||
is(e.altKey, aEvent.alt || 0, name + ", Alt mismatch");
|
||||
is(e.shiftKey, aEvent.shift || 0, name + ", Shift mismatch");
|
||||
|
||||
if (aExpectGeckoChar.length > 0) {
|
||||
is(e.charCode, aExpectGeckoChar.charCodeAt(0), name + ", charcode");
|
||||
} else {
|
||||
is(e.charCode, 0, name + ", no charcode");
|
||||
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];
|
||||
is(e.ctrlKey, aEvent.ctrl || 0, name + ", Ctrl mismatch");
|
||||
is(e.metaKey, aEvent.command || 0, name + ", Command mismatch");
|
||||
is(e.altKey, aEvent.alt || 0, name + ", Alt mismatch");
|
||||
is(e.shiftKey, aEvent.shift || 0, name + ", Shift mismatch");
|
||||
|
||||
if (aExpectGeckoChar.length > 0 && e.type == "keypress")
|
||||
is(e.charCode, aExpectGeckoChar.charCodeAt(0), name + ", charcode");
|
||||
else
|
||||
is(e.charCode, 0, name + ", no charcode");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// These tests have to be per-plaform.
|
||||
document.addEventListener("keypress", onKeyPress, false);
|
||||
document.addEventListener("keydown", onKeyEvent, false);
|
||||
document.addEventListener("keypress", onKeyEvent, false);
|
||||
document.addEventListener("keyup", onKeyEvent, false);
|
||||
|
||||
if (navigator.platform.indexOf("Mac") == 0) {
|
||||
// On Mac, you can produce event records for any desired keyboard input
|
||||
@ -179,77 +275,84 @@ function runPressTests()
|
||||
|
||||
// Plain text input
|
||||
testKey({layout:"US", keyCode:0, chars:"a", unmodifiedChars:"a"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"US", keyCode:11, chars:"b", unmodifiedChars:"b"},
|
||||
"b");
|
||||
"b", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"US", keyCode:0, shift:1, chars:"A", unmodifiedChars:"A"},
|
||||
"A");
|
||||
"A", SHOULD_DELIVER_ALL);
|
||||
|
||||
// Ctrl keys
|
||||
testKey({layout:"US", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"a"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"US", keyCode:0, ctrl:1, shift:1, chars:"\u0001", unmodifiedChars:"A"},
|
||||
"A");
|
||||
"A", SHOULD_DELIVER_ALL);
|
||||
|
||||
// Alt keys
|
||||
testKey({layout:"US", keyCode:0, alt:1, chars:"\u00e5", unmodifiedChars:"a"},
|
||||
"\u00e5");
|
||||
"\u00e5", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"US", keyCode:0, alt:1, shift:1, chars:"\u00c5", unmodifiedChars:"A"},
|
||||
"\u00c5");
|
||||
"\u00c5", SHOULD_DELIVER_ALL);
|
||||
|
||||
// Command keys
|
||||
testKey({layout:"US", keyCode:0, command:1, chars:"a", unmodifiedChars:"a"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
// Shift-cmd gives us the shifted character
|
||||
testKey({layout:"US", keyCode:0, command:1, shift:1, chars:"a", unmodifiedChars:"A"},
|
||||
"A");
|
||||
"A", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
// Ctrl-cmd gives us the unshifted character
|
||||
testKey({layout:"US", keyCode:0, command:1, ctrl:1, chars:"\u0001", unmodifiedChars:"a"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
// Alt-cmd gives us the shifted character
|
||||
testKey({layout:"US", keyCode:0, command:1, alt:1, chars:"\u00e5", unmodifiedChars:"a"},
|
||||
"\u00e5");
|
||||
"\u00e5", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
testKey({layout:"US", keyCode:0, command:1, alt:1, shift:1, chars:"\u00c5", unmodifiedChars:"a"},
|
||||
"\u00c5");
|
||||
"\u00c5", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
|
||||
// Greek ctrl keys produce Latin charcodes
|
||||
testKey({layout:"Greek", keyCode:0, ctrl:1, chars:"\u0001", unmodifiedChars:"\u03b1"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"Greek", keyCode:0, ctrl:1, shift:1, chars:"\u0001", unmodifiedChars:"\u0391"},
|
||||
"A");
|
||||
"A", SHOULD_DELIVER_ALL);
|
||||
|
||||
// Greek command keys
|
||||
testKey({layout:"Greek", keyCode:0, command:1, chars:"a", unmodifiedChars:"\u03b1"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
// Shift-cmd gives us the shifted character
|
||||
testKey({layout:"Greek", keyCode:0, command:1, shift:1, chars:"a", unmodifiedChars:"\u391"},
|
||||
"A");
|
||||
"A", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
// Ctrl-cmd gives us the unshifted character
|
||||
testKey({layout:"Greek", keyCode:0, command:1, ctrl:1, chars:"\u0001", unmodifiedChars:"\u03b1"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
// Alt-cmd gives us the shifted character
|
||||
testKey({layout:"Greek", keyCode:0, command:1, alt:1, chars:"\u00a8", unmodifiedChars:"\u03b1"},
|
||||
"\u00a8");
|
||||
"\u00a8", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
testKey({layout:"Greek", keyCode:0, command:1, alt:1, shift:1, chars:"\u00b9", unmodifiedChars:"\u0391"},
|
||||
"\u00b9");
|
||||
"\u00b9", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
|
||||
// German (KCHR/KeyTranslate case)
|
||||
testKey({layout:"German", keyCode:0, chars:"a", unmodifiedChars:"a"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"German", keyCode:33, chars:"\u00fc", unmodifiedChars:"\u00fc"},
|
||||
"\u00fc");
|
||||
"\u00fc", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"German", keyCode:27, chars:"\u00df", unmodifiedChars:"\u00df"},
|
||||
"\u00df");
|
||||
"\u00df", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"German", keyCode:27, shift:1, chars:"?", unmodifiedChars:"?"},
|
||||
"?");
|
||||
"?", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"German", keyCode:27, command:1, chars:"\u00df", unmodifiedChars:"\u00df"},
|
||||
"\u00df");
|
||||
"\u00df", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
// Shift+SS is '?' but Cmd+Shift+SS is '/' on German layout.
|
||||
// XXX this test failed on 10.4
|
||||
//testKey({layout:"German", keyCode:27, command:1, shift:1, chars:"/", unmodifiedChars:"?"},
|
||||
// "?");
|
||||
// "?", SHOULD_DELIVER_KEYDOWN_KEYPRESS);
|
||||
|
||||
// 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);
|
||||
testKey({layout:"US", keyCode:57, chars:"", unmodifiedChars:""},
|
||||
"", SHOULD_DELIVER_KEYDOWN);
|
||||
}
|
||||
|
||||
|
||||
if (navigator.platform.indexOf("Win") == 0) {
|
||||
// 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
|
||||
@ -258,42 +361,50 @@ function runPressTests()
|
||||
|
||||
// Plain text input
|
||||
testKey({layout:"US", keyCode:65, chars:"a"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"US", keyCode:66, chars:"b"},
|
||||
"b");
|
||||
"b", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"US", keyCode:65, shift:1, chars:"A"},
|
||||
"A");
|
||||
"A", SHOULD_DELIVER_ALL);
|
||||
|
||||
// Ctrl keys
|
||||
testKey({layout:"US", keyCode:65, ctrl:1, chars:"\u0001"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"US", keyCode:65, ctrl:1, shift:1, chars:"\u0001"},
|
||||
"A");
|
||||
"A", SHOULD_DELIVER_ALL);
|
||||
|
||||
// Alt keys
|
||||
testKey({layout:"US", keyCode:65, alt:1, chars:"a"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"US", keyCode:65, alt:1, shift:1, chars:"A"},
|
||||
"A");
|
||||
|
||||
"A", SHOULD_DELIVER_ALL);
|
||||
|
||||
// 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:""},
|
||||
"A");
|
||||
"A", SHOULD_DELIVER_ALL);
|
||||
|
||||
// Greek plain text
|
||||
testKey({layout:"Greek", keyCode:65, chars:"\u03b1"},
|
||||
"\u03b1");
|
||||
"\u03b1", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"Greek", keyCode:65, shift:1, chars:"\u0391"},
|
||||
"\u0391");
|
||||
"\u0391", SHOULD_DELIVER_ALL);
|
||||
|
||||
// Greek ctrl keys produce Latin charcodes
|
||||
testKey({layout:"Greek", keyCode:65, ctrl:1, chars:"\u0001"},
|
||||
"a");
|
||||
"a", SHOULD_DELIVER_ALL);
|
||||
testKey({layout:"Greek", keyCode:65, ctrl:1, shift:1, chars:"\u0001"},
|
||||
"A");
|
||||
"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);
|
||||
}
|
||||
|
||||
document.removeEventListener("keypress", onKeyPress, false);
|
||||
document.removeEventListener("keydown", onKeyEvent, false);
|
||||
document.removeEventListener("keypress", onKeyEvent, false);
|
||||
document.removeEventListener("keyup", onKeyEvent, false);
|
||||
}
|
||||
|
||||
// Test the activation (or not) of an HTML accesskey
|
||||
@ -541,7 +652,7 @@ function runTextInputTests()
|
||||
|
||||
function runTest()
|
||||
{
|
||||
runPressTests();
|
||||
runKeyEventTests();
|
||||
runAccessKeyTests();
|
||||
runXULKeyTests();
|
||||
runTextInputTests();
|
||||
|
Loading…
Reference in New Issue
Block a user