Skip to content

Commit

Permalink
Bug 1057898 - Add a test for tapping between two inputs. r=yxl
Browse files Browse the repository at this point in the history
  • Loading branch information
timdream committed Aug 27, 2014
1 parent 55de3e5 commit 6e8227f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
1 change: 1 addition & 0 deletions dom/inputmethod/mochitest/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ support-files =
[test_bug1043828.html]
[test_delete_focused_element.html]
[test_sendkey_cancel.html]
[test_two_inputs.html]
5 changes: 4 additions & 1 deletion dom/inputmethod/mochitest/test_delete_focused_element.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
};

content.setTimeout(function() {
textarea.focus();
content.setTimeout(function() {
textarea.focus();
}, 10);

input.parentNode.removeChild(input);
}, 0);
}
Expand Down
106 changes: 106 additions & 0 deletions dom/inputmethod/mochitest/test_two_inputs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<!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=932145">Mozilla Bug 932145</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();
});

let appFrameScript = function appFrameScript() {
let input1 = content.document.body.firstElementChild;
let input2 = content.document.body.children[1];

let i = 0;

input1.focus();

addMessageListener('test:next', function() {
i++;
switch (i) {
case 1:
input2.focus();

break;

case 2:
input2.blur();

break;
}
});
};

function runTest() {
let im = navigator.mozInputMethod;

let i = 0;
im.oninputcontextchange = function(evt) {
var inputcontext = navigator.mozInputMethod.inputcontext;

i++;
switch (i) {
case 1:
ok(!!inputcontext, 'Receving the first input context');
is(inputcontext.textAfterCursor, 'First');

mm.sendAsyncMessage('test:next');
break;

case 2:
ok(!!inputcontext, 'Receving the second input context');
is(inputcontext.textAfterCursor, 'Second');


mm.sendAsyncMessage('test:next');
break;

case 3:
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>

0 comments on commit 6e8227f

Please sign in to comment.