gecko-dev/dom/inputmethod/mochitest/test_delete_focused_element.html

108 lines
2.9 KiB
HTML

<!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() {
textarea.parentNode.removeChild(textarea);
sendAsyncMessage('test:InputMethod:finished', {});
};
content.setTimeout(function() {
textarea.focus();
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>