Bug 1069055 - Merge focused element deletion test to another test. r=yxl

This commit is contained in:
Tim Chien 2014-10-31 02:11:00 +01:00
parent 77e8098fd8
commit 2f7e428dec
3 changed files with 29 additions and 115 deletions

View File

@ -21,7 +21,6 @@ support-files =
[test_bug1043828.html]
[test_bug1059163.html]
[test_bug1066515.html]
[test_delete_focused_element.html]
[test_sendkey_cancel.html]
[test_sync_edit.html]
[test_two_inputs.html]

View File

@ -1,112 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=952741
-->
<head>
<title>Test focused element deletion 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=952741">Mozilla Bug 952741</a>
<input type="text" />
<p id="display"></p>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
inputmethod_setup(function() {
runTest();
});
// The frame script running in file_test_app.html.
function appFrameScript() {
let input = content.document.getElementById('test-input');
let textarea = content.document.createElement('textarea');
textarea.lang = 'en';
content.document.body.appendChild(textarea);
textarea.onfocus = function() {
content.setTimeout(function() {
textarea.parentNode.removeChild(textarea);
sendAsyncMessage('test:InputMethod:finished', {});
}, 10);
};
content.setTimeout(function() {
content.setTimeout(function() {
textarea.focus();
}, 10);
input.parentNode.removeChild(input);
}, 0);
}
function runTest() {
var timeoutId = null;
// Create an app frame to recieve keyboard inputs.
let app = document.createElement('iframe');
app.src = 'file_test_app.html';
app.setAttribute('mozbrowser', true);
document.body.appendChild(app);
app.addEventListener('mozbrowserloadend', function() {
let mm = SpecialPowers.getBrowserFrameMessageManager(app);
mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false);
mm.addMessageListener("test:InputMethod:finished", function() {
timeoutId = setTimeout(function() {
ok(false, 'No inputcontextchange event when textarea is deleted.');
inputmethod_cleanup();
}, 20000);
});
});
let im = navigator.mozInputMethod;
let count = 0;
im.oninputcontextchange = function() {
switch (count++) {
case 0:
if (!im.inputcontext) {
break;
}
is(im.inputcontext.lang, 'zh', 'input was focused.');
return;
case 1:
if (im.inputcontext) {
break;
}
ok(true, 'input was blurred.');
return;
case 2:
if (!im.inputcontext) {
break;
}
is(im.inputcontext.lang, 'en', 'textarea was focused.');
return;
case 3:
if (im.inputcontext) {
break;
}
ok(true, 'textarea was removed.');
clearTimeout(timeoutId);
inputmethod_cleanup();
return;
default:
return;
}
count = 100;
ok(false, 'Should not arrive here.');
inputmethod_cleanup();
};
// Set current page as an input method.
SpecialPowers.wrap(im).setActive(true);
}
</script>
</pre>
</body>
</html>

View File

@ -2,6 +2,7 @@
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1057898
https://bugzilla.mozilla.org/show_bug.cgi?id=952741
-->
<head>
<title>Test switching between two inputs</title>
@ -11,6 +12,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1057898
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1057898">Mozilla Bug 1057898</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=952741">Mozilla Bug 952741</a>
<p id="display"></p>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
@ -55,7 +57,17 @@ let appFrameScript = function appFrameScript() {
break;
case 6:
input1.blur();
content.document.body.removeChild(input1);
break;
case 7:
input2.focus();
break;
case 8:
content.document.body.removeChild(input2);
break;
}
@ -114,10 +126,25 @@ function runTest() {
mm.sendAsyncMessage('test:next');
break;
// blur on the first input results null input context
// remove on the first focused input results null input context
case 6:
is(inputcontext, null, 'Receving null inputcontext');
mm.sendAsyncMessage('test:next');
break;
// input context for the second input.
case 7:
ok(!!inputcontext, 'Receving the second input context');
is(inputcontext.textAfterCursor, 'Second');
mm.sendAsyncMessage('test:next');
break;
// remove on the second focused input results null input context
case 8:
is(inputcontext, null, 'Receving null inputcontext');
inputmethod_cleanup();
break;