Bug 1057898 - Test for tapping between two inputs. r=yxl

This commit is contained in:
Tim Chien 2014-09-04 19:52:00 -04:00
parent 1de7990d2b
commit 546baa7006
3 changed files with 160 additions and 3 deletions

View File

@ -19,3 +19,4 @@ support-files =
[test_bug1043828.html]
[test_delete_focused_element.html]
[test_sendkey_cancel.html]
[test_two_inputs.html]

View File

@ -29,12 +29,17 @@ function appFrameScript() {
content.document.body.appendChild(textarea);
textarea.onfocus = function() {
textarea.parentNode.removeChild(textarea);
sendAsyncMessage('test:InputMethod:finished', {});
content.setTimeout(function() {
textarea.parentNode.removeChild(textarea);
sendAsyncMessage('test:InputMethod:finished', {});
}, 10);
};
content.setTimeout(function() {
textarea.focus();
content.setTimeout(function() {
textarea.focus();
}, 10);
input.parentNode.removeChild(input);
}, 0);
}

View File

@ -0,0 +1,151 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1057898
-->
<head>
<title>Test switching between two inputs</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=1057898">Mozilla Bug 1057898</a>
<p id="display"></p>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
inputmethod_setup(function() {
runTest();
});
let appFrameScript = function appFrameScript() {
let input1 = content.document.body.firstElementChild;
let input2 = content.document.body.children[1];
let i = 1;
input1.focus();
addMessageListener('test:next', function() {
i++;
switch (i) {
case 2:
input2.focus();
break;
case 3:
input2.blur();
input2.focus();
break;
case 4:
input2.blur();
break;
case 5:
input2.focus();
input2.blur();
input1.focus();
break;
case 6:
input1.blur();
break;
}
});
};
function runTest() {
let im = navigator.mozInputMethod;
let i = 0;
im.oninputcontextchange = function(evt) {
var inputcontext = navigator.mozInputMethod.inputcontext;
i++;
switch (i) {
// focus on the first input receives the first input context.
case 1:
ok(!!inputcontext, 'Receving the first input context');
is(inputcontext.textAfterCursor, 'First');
mm.sendAsyncMessage('test:next');
break;
// focus on the second input (implicitly blur the first input)
// results the second input context.
case 2:
ok(!!inputcontext, 'Receving the second input context');
is(inputcontext.textAfterCursor, 'Second');
mm.sendAsyncMessage('test:next');
break;
// blur and re-focus on the second input results updated
// input context for the second input.
case 3:
ok(!!inputcontext, 'Receving the second input context');
is(inputcontext.textAfterCursor, 'Second');
mm.sendAsyncMessage('test:next');
break;
// blur on the second input results null input context
case 4:
is(inputcontext, null, 'Receving null inputcontext');
mm.sendAsyncMessage('test:next');
break;
// focus and blur on the second input sends no message;
// focus on the first input receives the first input context.
case 5:
ok(!!inputcontext, 'Receving the first input context');
is(inputcontext.textAfterCursor, 'First');
mm.sendAsyncMessage('test:next');
break;
// blur on the first input results null input context
case 6:
is(inputcontext, null, 'Receving null inputcontext');
inputmethod_cleanup();
break;
default:
ok(false, 'Receving extra inputcontextchange calls');
inputmethod_cleanup();
break;
}
};
// Set current page as an input method.
SpecialPowers.wrap(im).setActive(true);
let iframe = document.createElement('iframe');
iframe.src = 'data:text/html,<html><body><input value="First"><input value="Second"></body></html>';
iframe.setAttribute('mozbrowser', true);
document.body.appendChild(iframe);
let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
iframe.addEventListener('mozbrowserloadend', function() {
mm.loadFrameScript('data:,(' + encodeURIComponent(appFrameScript.toString()) + ')();', false);
});
}
</script>
</pre>
</body>
</html>