mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-06 00:55:37 +00:00
112 lines
3.3 KiB
HTML
112 lines
3.3 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=944397
|
|
-->
|
|
<head>
|
|
<title>Basic 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=944397">Mozilla Bug 944397</a>
|
|
<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');
|
|
input.oninput = function() {
|
|
dump('oninput was called in file_test_app.html.');
|
|
sendAsyncMessage('test:InputMethod:oninput', {});
|
|
};
|
|
|
|
/*
|
|
* Bug 957213. Sometimes we need to refocus the input field to avoid
|
|
* intermittent test failure.
|
|
*/
|
|
content.setInterval(function() {
|
|
input.focus();
|
|
}, 500);
|
|
}
|
|
|
|
function runTest() {
|
|
let 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:oninput", function() {
|
|
ok(true, 'Keyboard input was received.');
|
|
clearTimeout(timeoutId);
|
|
inputmethod_cleanup();
|
|
});
|
|
});
|
|
|
|
// Create a browser frame to load the input method app.
|
|
let keyboard = document.createElement('iframe');
|
|
keyboard.setAttribute('mozbrowser', true);
|
|
document.body.appendChild(keyboard);
|
|
|
|
// Bug 953044 setInputMethodActive(false) before input method app loads should
|
|
// always succeed.
|
|
let req = keyboard.setInputMethodActive(false);
|
|
req.onsuccess = function() {
|
|
ok(true, 'setInputMethodActive before loading succeeded.');
|
|
};
|
|
|
|
req.onerror = function() {
|
|
ok(false, 'setInputMethodActive before loading failed: ' + this.error.name);
|
|
clearTimeout(timeoutId);
|
|
inputmethod_cleanup();
|
|
};
|
|
|
|
let path = location.pathname;
|
|
let imeUrl = location.protocol + '//' + location.host +
|
|
path.substring(0, path.lastIndexOf('/')) +
|
|
'/file_inputmethod.html#data';
|
|
SpecialPowers.pushPermissions([{
|
|
type: 'input',
|
|
allow: true,
|
|
context: imeUrl
|
|
}], function() {
|
|
let req = keyboard.setInputMethodActive(true);
|
|
|
|
req.onsuccess = function() {
|
|
ok(true, 'setInputMethodActive succeeded.');
|
|
};
|
|
|
|
req.onerror = function() {
|
|
ok(false, 'setInputMethodActive failed: ' + this.error.name);
|
|
inputmethod_cleanup();
|
|
};
|
|
|
|
// Loads the input method app to the browser frame after a delay.
|
|
SpecialPowers.DOMWindowUtils.focus(app);
|
|
setTimeout(function() {
|
|
keyboard.src = imeUrl;
|
|
timeoutId = setTimeout(function() {
|
|
inputmethod_cleanup();
|
|
ok(false, 'Failed to generate keyboard input.');
|
|
}, 20000);
|
|
}, 100);
|
|
});
|
|
}
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|
|
|