diff --git a/testing/mochitest/tests/SimpleTest/EventUtils.js b/testing/mochitest/tests/SimpleTest/EventUtils.js index 67095680410..87ece73c112 100644 --- a/testing/mochitest/tests/SimpleTest/EventUtils.js +++ b/testing/mochitest/tests/SimpleTest/EventUtils.js @@ -9,6 +9,7 @@ * synthesizeMouseAtCenter * synthesizeWheel * synthesizeKey + * synthesizeNativeKey * synthesizeMouseExpectEvent * synthesizeKeyExpectEvent * @@ -568,6 +569,114 @@ function synthesizeKey(aKey, aEvent, aWindow) } } +function _parseNativeModifiers(aModifiers) +{ + var modifiers; + if (aModifiers.capsLockKey) { + modifiers |= 0x00000001; + } + if (aModifiers.numLockKey) { + modifiers |= 0x00000002; + } + if (aModifiers.shiftKey) { + modifiers |= 0x00000100; + } + if (aModifiers.shiftRightKey) { + modifiers |= 0x00000200; + } + if (aModifiers.ctrlKey) { + modifiers |= 0x00000400; + } + if (aModifiers.ctrlRightKey) { + modifiers |= 0x00000800; + } + if (aModifiers.altKey) { + modifiers |= 0x00001000; + } + if (aModifiers.altRightKey) { + modifiers |= 0x00002000; + } + if (aModifiers.metaKey) { + modifiers |= 0x00004000; + } + if (aModifiers.metaRightKey) { + modifiers |= 0x00008000; + } + if (aModifiers.helpKey) { + modifiers |= 0x00010000; + } + if (aModifiers.fnKey) { + modifiers |= 0x00100000; + } + if (aModifiers.numericKeyPadKey) { + modifiers |= 0x01000000; + } + + if (aModifiers.accelKey) { + modifiers |= + (navigator.platform.indexOf("Mac") == 0) ? 0x00004000 : 0x00000400; + } + if (aModifiers.accelRightKey) { + modifiers |= + (navigator.platform.indexOf("Mac") == 0) ? 0x00008000 : 0x00000800; + } + return modifiers; +} + +const KEYBOARD_LAYOUT_EN_US = 0; + +/** + * synthesizeNativeKey() dispatches native key event on active window. + * This is implemented only on Windows and Mac. + * + * @param aKeyboardLayout One of KEYBOARD_LAYOUT_* defined above. + * @param aNativeKeyCode A native keycode value defined in + * NativeKeyCodes.js. + * @param aModifiers Modifier keys. If no modifire key is pressed, + * this must be {}. Otherwise, one or more items + * referred in _parseNativeModifiers() must be + * true. + * @param aChars Specify characters which should be generated + * by the key event. + * @param aUnmodifiedChars Specify characters of unmodified (except Shift) + * aChar value. + * @return True if this function succeed dispatching + * native key event. Otherwise, false. + */ + +function synthesizeNativeKey(aKeyboardLayout, aNativeKeyCode, aModifiers, + aChars, aUnmodifiedChars) +{ + var utils = _getDOMWindowUtils(window); + if (!utils) { + return false; + } + var nativeKeyboardLayout; + if (navigator.platform.indexOf("Mac") == 0) { + switch (aKeyboardLayout) { + case KEYBOARD_LAYOUT_EN_US: + nativeKeyboardLayout = 0; + break; + default: + return false; + } + } else if (navigator.platform.indexOf("Win") == 0) { + switch (aKeyboardLayout) { + case KEYBOARD_LAYOUT_EN_US: + nativeKeyboardLayout = 0x409; + break; + default: + return false; + } + } else { + return false; + } + utils.sendNativeKeyEvent(nativeKeyboardLayout, aNativeKeyCode, + _parseNativeModifiers(aModifiers), + aChars, aUnmodifiedChars); + return true; +} + var _gSeenEvent = false; /** diff --git a/widget/tests/chrome.ini b/widget/tests/chrome.ini index 316e515d877..e2df32eff9e 100644 --- a/widget/tests/chrome.ini +++ b/widget/tests/chrome.ini @@ -26,7 +26,6 @@ support-files = window_composition_text_querycontent.xul [test_position_on_resize.xul] [test_sizemode_events.xul] [test_bug760802.xul] -[test_assign_event_data.html] # Cocoa [test_native_menus.xul] diff --git a/widget/tests/mochitest.ini b/widget/tests/mochitest.ini index 90d19adddce..c78c438f34d 100644 --- a/widget/tests/mochitest.ini +++ b/widget/tests/mochitest.ini @@ -1,3 +1,5 @@ +[test_assign_event_data.html] +skip-if = toolkit == "cocoa" # Bug 933303 [test_bug565392.html] skip-if = toolkit != "windows" [test_picker_no_crash.html] diff --git a/widget/tests/test_assign_event_data.html b/widget/tests/test_assign_event_data.html index 553b954f5bb..7aee46b476a 100644 --- a/widget/tests/test_assign_event_data.html +++ b/widget/tests/test_assign_event_data.html @@ -2,11 +2,10 @@ Testing ns*Event::Assign*EventData() - - - - - + + + +