Bug 1146349 - Update some widget tests to deal with async native key event synthesization. r=smaug,masayuki

This commit is contained in:
Kartikaya Gupta 2015-04-14 11:36:36 -04:00
Родитель 5cf2d407fd
Коммит f0f1261931
6 изменённых файлов: 2793 добавлений и 2693 удалений

Просмотреть файл

@ -763,7 +763,10 @@ const KEYBOARD_LAYOUT_THAI =
/**
* synthesizeNativeKey() dispatches native key event on active window.
* This is implemented only on Windows and Mac.
* This is implemented only on Windows and Mac. Note that this function
* dispatches the key event asynchronously and returns immediately. If a
* callback function is provided, the callback will be called upon
* completion of the key dispatch.
*
* @param aKeyboardLayout One of KEYBOARD_LAYOUT_* defined above.
* @param aNativeKeyCode A native keycode value defined in
@ -776,12 +779,16 @@ const KEYBOARD_LAYOUT_THAI =
* by the key event.
* @param aUnmodifiedChars Specify characters of unmodified (except Shift)
* aChar value.
* @param aCallback If provided, this callback will be invoked
* once the native keys have been processed
* by Gecko. Will never be called if this
* function returns false.
* @return True if this function succeed dispatching
* native key event. Otherwise, false.
*/
function synthesizeNativeKey(aKeyboardLayout, aNativeKeyCode, aModifiers,
aChars, aUnmodifiedChars)
aChars, aUnmodifiedChars, aCallback)
{
var utils = _getDOMWindowUtils(window);
if (!utils) {
@ -796,9 +803,17 @@ function synthesizeNativeKey(aKeyboardLayout, aNativeKeyCode, aModifiers,
if (nativeKeyboardLayout === null) {
return false;
}
var observer = {
observe: function(aSubject, aTopic, aData) {
if (aCallback && aTopic == "keyevent") {
aCallback(aData);
}
}
};
utils.sendNativeKeyEvent(nativeKeyboardLayout, aNativeKeyCode,
_parseNativeModifiers(aModifiers),
aChars, aUnmodifiedChars);
aChars, aUnmodifiedChars, observer);
return true;
}

Просмотреть файл

@ -119,14 +119,19 @@
function switchToFirstTab() {
// 11) Switch back to first tab.
document.getElementById("tabbox").selectedIndex = 0;
finishTest();
doCmdY();
}
function doCmdY() {
// 12) Back in first tab, try cmd-y.
gCmdOptYReceived = false;
if (!synthesizeNativeCmdOptY(finishTest)) {
ok(false, "Failed to synthesize native key");
finishTest();
}
}
function finishTest() {
// 12) Back in first tab, try cmd-y.
gCmdOptYReceived = false;
synthesizeNativeCmdOptY();
// 13) Check result.
is(gCmdOptYReceived, true);
@ -146,8 +151,8 @@
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_Return, {}, "\u000a", "\u000a");
}
function synthesizeNativeCmdOptY() {
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_Y, {metaKey:1, altKey:1}, "y", "y");
function synthesizeNativeCmdOptY(aCallback) {
return synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_Y, {metaKey:1, altKey:1}, "y", "y", aCallback);
}
]]></script>

Просмотреть файл

@ -35,7 +35,7 @@
e.preventDefault();
}
function runTest()
function* testBody()
{
window.addEventListener("keydown", onKeyDown, false);
window.addEventListener("keypress", onKeyPress, false);
@ -43,27 +43,48 @@
// Test ctrl-tab
gKeyDownEventCount = 0;
gKeyPressEventCount = 0;
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_Tab, {ctrlKey:1}, "\t", "\t");
yield synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_Tab, {ctrlKey:1}, "\t", "\t", continueTest);
is(gKeyDownEventCount, 1);
is(gKeyPressEventCount, 0, "ctrl-tab should be consumed by tabbox of tabbrowser at keydown");
// Test cmd+shift+a
gKeyDownEventCount = 0;
gKeyPressEventCount = 0;
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A, {metaKey:1, shiftKey:1}, "a", "A");
yield synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A, {metaKey:1, shiftKey:1}, "a", "A", continueTest);
is(gKeyDownEventCount, 1);
is(gKeyPressEventCount, 1);
// Test cmd-;
gKeyDownEventCount = 0;
gKeyPressEventCount = 0;
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_Semicolon, {metaKey:1}, ";", ";");
yield synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_Semicolon, {metaKey:1}, ";", ";", continueTest);
is(gKeyDownEventCount, 1);
is(gKeyPressEventCount, 1);
window.removeEventListener("keydown", onKeyDown, false);
window.removeEventListener("keypress", onKeyPress, false);
}
var gTestContinuation = null;
function continueTest()
{
if (!gTestContinuation) {
gTestContinuation = testBody();
}
var ret = gTestContinuation.next();
if (ret.done) {
SimpleTest.finish();
} else {
is(ret.value, true, "Key synthesized successfully");
}
}
function runTest()
{
SimpleTest.waitForExplicitFinish();
continueTest();
}
]]></script>
</window>

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -297,7 +297,7 @@
aElement.id + ": Incorrect selection end");
}
function testRun(aElement, aSelectionCheck)
function* testRun(aElement, aSelectionCheck, aCallback)
{
if (document.activeElement) {
document.activeElement.blur();
@ -306,21 +306,38 @@
aElement.focus();
for (let i = 0; i < synthesizedKeys.length; i++) {
synthesizeNativeKey.apply(null, synthesizedKeys[i]);
aSelectionCheck.call(null, aElement, expectations[i]);
synthesizedKeys[i].push(function() {
aSelectionCheck.call(null, aElement, expectations[i]);
continueTest();
});
var synthOk = synthesizeNativeKey.apply(null, synthesizedKeys[i]);
synthesizedKeys[i].pop();
yield synthOk;
}
}
function doTest()
{
testRun(document.getElementById("editable"), checkWindowSelection);
testRun(document.getElementById("textarea"), checkElementSelection);
testRun(document.getElementById("input"), checkElementSelection);
SimpleTest.finish();
function* doTest() {
yield* testRun(document.getElementById("editable"), checkWindowSelection);
yield* testRun(document.getElementById("textarea"), checkElementSelection);
yield* testRun(document.getElementById("input"), checkElementSelection);
}
SimpleTest.waitForFocus(doTest);
let gTestContinuation = null;
function continueTest()
{
if (!gTestContinuation) {
gTestContinuation = doTest();
}
var ret = gTestContinuation.next();
if (ret.done) {
SimpleTest.finish();
} else {
is(ret.value, true, "Successfully synthesized key");
}
}
SimpleTest.waitForFocus(continueTest);
</script>
</body>
</html>

Просмотреть файл

@ -35,7 +35,7 @@ var gUtils = window.
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
function doTest() {
function* doTest() {
gPlugin.focus();
is(gUtils.IMEStatus, gUtils.IME_STATUS_PLUGIN,
@ -43,19 +43,31 @@ function doTest() {
is(gPlugin.getLastKeyText(), "", "Must be empty before first key test");
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, WIN_VK_A, {}, "a", "a");
yield synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, WIN_VK_A, {}, "a", "a", continueTest);
is(gPlugin.getLastKeyText(), "a", "Invalid character was inputted");
synthesizeNativeKey(KEYBOARD_LAYOUT_GERMAN, WIN_VK_OEM_PLUS, {}, "+", "+");
yield synthesizeNativeKey(KEYBOARD_LAYOUT_GERMAN, WIN_VK_OEM_PLUS, {}, "+", "+", continueTest);
is(gPlugin.getLastKeyText(), "+", "Invalid character was inputted");
synthesizeNativeKey(KEYBOARD_LAYOUT_GERMAN, WIN_VK_OEM_PLUS, {altGrKey:1}, "~", "+");
yield synthesizeNativeKey(KEYBOARD_LAYOUT_GERMAN, WIN_VK_OEM_PLUS, {altGrKey:1}, "~", "+", continueTest);
is(gPlugin.getLastKeyText(), "~", "Invalid character was inputted");
SimpleTest.finish();
}
SimpleTest.waitForFocus(doTest);
var gTestContinuation = null;
function continueTest() {
if (!gTestContinuation) {
gTestContinuation = doTest(continueTest);
}
var ret = gTestContinuation.next();
if (ret.done) {
SimpleTest.finish();
} else {
is(ret.value, true, "Key synthesized successfully");
}
}
SimpleTest.waitForFocus(continueTest);
</script>
</body>