<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<input id="test" type="text">
<script>
description('This tests that calling input-method functions sends Composition Events and Text Events introduced in DOM Level 3. ' +
'To test manually, enable an IME, input CJK characters, and see this page doesn\'t show \'FAIL\' lines.');
</script>
<script>
function logCompositionStart(event) {
    shouldBeEqualToString('event.type', 'compositionstart');
    testPassed('event.data is "' + event.data + '"');
}
function logCompositionUpdate(event) {
    shouldBeEqualToString('event.type', 'compositionupdate');
    testPassed('event.data is "' + event.data + '"');
}
function logCompositionEnd(event) {
    shouldBeEqualToString('event.type', 'compositionend');
    testPassed('event.data is "' + event.data + '"');
}
function logTextInput(event) {
    shouldBeEqualToString('event.type', 'textInput');
    testPassed('event.data is "' + event.data + '"');
}
var test = document.getElementById('test');
test.focus();
// Add event listeners to the <input> node.
test.addEventListener('compositionstart', logCompositionStart, false);
test.addEventListener('compositionupdate', logCompositionUpdate, false);
test.addEventListener('compositionend', logCompositionEnd, false);
test.addEventListener('textInput', logTextInput, 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.
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');
shouldBeEqualToString('test.value', 'I made a pen');
</script>
</body>
</html>
