blob: 114a4d478dd2cef59b58392434f11c5eeb4388e2 [file] [log] [blame]
<html>
<head>
<title></title>
</head>
<body>
<p>This tests that calling input-method functions sends Composition Events and Text Events introduced in DOM Level 3.</p>
<p>To test manually, enable an IME, input CJK characters, and see this page doesn't show 'FAILED' lines.</p>
<input id="test" type="text"/>
<ul id="console"></ul>
<script language="javascript" type="text/javascript">
function log(str) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(str));
var console = document.getElementById('console');
console.appendChild(li);
}
function logEvent(e) {
var target = e.target;
var type = e.type;
if (e.type == 'compositionstart' || e.type == 'compositionupdate' || e.type == 'compositionend' || e.type == 'textInput')
log('SUCCESS: ' + target.tagName + ' - ' + e.type + ' - "' + e.data + '"');
else
log('FAILED: ' + target.tagName + ' - ' + e.type + ' - "' + e.data + '"');
}
var test = document.getElementById('test');
test.focus();
if (window.testRunner) {
testRunner.dumpAsText();
// Add event listeners to the <input> node.
test.addEventListener("compositionstart", logEvent, false);
test.addEventListener("compositionupdate", logEvent, false);
test.addEventListener("compositionend", logEvent, false);
test.addEventListener("textInput", logEvent, false);
// Case 1: Compose a text and commit it.
textInputController.setMarkedText('1', 0, 1);
textInputController.setMarkedText('2', 0, 1);
textInputController.setMarkedText('3', 0, 1);
textInputController.insertText('4');
// Case 2: Compose a text but cancel it.
textInputController.setMarkedText('5', 0, 1);
textInputController.setMarkedText('6', 0, 1);
textInputController.setMarkedText('7', 0, 1);
textInputController.setMarkedText('', 0, 0);
// Case 3: Insert a text without composition.
textInputController.insertText('8');
// Case 4: Compose a text and commit it by removing the mark.
// Only Mac and Chromium ports support unmarkText.
if (textInputController.unmarkText) {
textInputController.setMarkedText('9', 0, 1);
textInputController.unmarkText();
}
// Case 5: Compose a text on selection and commit it.
test.value = 'I have a pen';
test.selectionStart = 2;
test.selectionEnd = 6;
textInputController.setMarkedText('lost', 0, 1);
textInputController.insertText('made');
if (test.value == 'I made a pen')
log('SUCCESS: ' + test.value);
else
log('FAILURE: ' + test.value + ' is not "I made a pen".');
}
</script>
</body>
</html>