Bug 952080 - Rejection state for sendKey. r=yxl

This commit is contained in:
Jan Jongboom 2014-01-02 10:39:26 -05:00
parent 59221a6965
commit 73e1e405de
6 changed files with 97 additions and 3 deletions

View File

@ -75,6 +75,7 @@ this.Keyboard = {
mm.addMessageListener('Forms:SetSelectionRange:Result:OK', this);
mm.addMessageListener('Forms:ReplaceSurroundingText:Result:OK', this);
mm.addMessageListener('Forms:SendKey:Result:OK', this);
mm.addMessageListener('Forms:SendKey:Result:Error', this);
mm.addMessageListener('Forms:SequenceError', this);
mm.addMessageListener('Forms:GetContext:Result:OK', this);
mm.addMessageListener('Forms:SetComposition:Result:OK', this);
@ -125,6 +126,7 @@ this.Keyboard = {
case 'Forms:SetSelectionRange:Result:OK':
case 'Forms:ReplaceSurroundingText:Result:OK':
case 'Forms:SendKey:Result:OK':
case 'Forms:SendKey:Result:Error':
case 'Forms:SequenceError':
case 'Forms:GetContext:Result:OK':
case 'Forms:SetComposition:Result:OK':

View File

@ -498,6 +498,7 @@ MozInputContext.prototype = {
"Keyboard:SetSelectionRange:Result:OK",
"Keyboard:ReplaceSurroundingText:Result:OK",
"Keyboard:SendKey:Result:OK",
"Keyboard:SendKey:Result:Error",
"Keyboard:SetComposition:Result:OK",
"Keyboard:EndComposition:Result:OK",
"Keyboard:SequenceError"]);
@ -543,6 +544,9 @@ MozInputContext.prototype = {
case "Keyboard:SendKey:Result:OK":
resolver.resolve();
break;
case "Keyboard:SendKey:Result:Error":
resolver.reject(json.error);
break;
case "Keyboard:GetText:Result:OK":
resolver.resolve(json.text);
break;

View File

@ -521,11 +521,17 @@ let FormAssistant = {
json.charCode, json.modifiers);
this._editing = false;
if (json.requestId) {
if (json.requestId && doKeypress) {
sendAsyncMessage("Forms:SendKey:Result:OK", {
requestId: json.requestId
});
}
else if (json.requestId && !doKeypress) {
sendAsyncMessage("Forms:SendKey:Result:Error", {
requestId: json.requestId,
error: "Keydown event got canceled"
});
}
break;
case "Forms:Select:Choice":

View File

@ -0,0 +1,14 @@
<!DOCTYPE HTML>
<html>
<body>
<input id="test-input" type="text" value="Yolo"/>
<script type="application/javascript;version=1.7">
let input = document.getElementById('test-input');
input.focus();
input.addEventListener('keydown', function(e) {
e.preventDefault();
});
</script>
</body>
</html>

View File

@ -1,9 +1,10 @@
[DEFAULT]
support-files =
inputmethod_common.js
file_test_app.html
file_inputmethod.html
file_test_app.html
file_test_sendkey_cancel.html
[test_basic.html]
[test_bug944397.html]
[test_sendkey_cancel.html]

View File

@ -0,0 +1,67 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=952080
-->
<head>
<title>SendKey with canceled keydown test for InputMethod API.</title>
<script type="application/javascript;version=1.7" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript;version=1.7" src="inputmethod_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=952080">Mozilla Bug 952080</a>
<p id="display"></p>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
// The input context.
var gContext = null;
inputmethod_setup(function() {
runTest();
});
function runTest() {
let im = navigator.mozInputMethod;
im.oninputcontextchange = function() {
ok(true, 'inputcontextchange event was fired.');
im.oninputcontextchange = null;
gContext = im.inputcontext;
if (!gContext) {
ok(false, 'Should have a non-null inputcontext.');
inputmethod_cleanup();
return;
}
test();
};
// Set current page as an input method.
SpecialPowers.wrap(im).setActive(true);
let iframe = document.createElement('iframe');
iframe.src = 'file_test_sendkey_cancel.html';
iframe.setAttribute('mozbrowser', true);
document.body.appendChild(iframe);
}
function test() {
gContext.sendKey(0, 'j', 0).then(function() {
ok(false, 'sendKey was incorrectly resolved');
inputmethod_cleanup();
}, function(e) {
ok(true, 'sendKey was rejected');
inputmethod_cleanup();
});
}
</script>
</pre>
</body>
</html>