1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<html>
<head>
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<input id="test">
<input id="test2">
<script>
description("This tests confirmComposition() of InputMethodContext.");
var test = document.getElementById('test');
var test2 = document.getElementById('test2');
// Checks .inputMethodContext returns an InputMethodContext object.
var context = test.inputMethodContext;
shouldBeTrue('context instanceof InputMethodContext');
var expectedText;
// Register event listeners.
test.addEventListener('compositionstart', function(event) {
testPassed('compositionstart fired');
}, false);
test.addEventListener('compositionend', function(event) {
testPassed('compositionend fired');
shouldBeEqualToString('event.type', 'compositionend');
shouldBeEqualToString('event.data', expectedText);
}, false);
test.addEventListener('textInput', function(event) {
testPassed('textInput fired');
shouldBeEqualToString('event.type', 'textInput');
shouldBeEqualToString('event.data', expectedText);
}, false);
test.focus();
debug("Check if composition text 'abcd' is committed properly.");
expectedText = 'abcd';
textInputController.setComposition(expectedText);
context.confirmComposition();
shouldBeEqualToString('test.value', 'abcd');
debug("Check if no compositionend event will occur when composition is empty.");
context.confirmComposition();
shouldBeEqualToString('test.value', 'abcd');
debug("Check if composition text 'efgh' is committed properly, and appended to the input field's value.");
expectedText = 'efgh';
textInputController.setComposition(expectedText);
context.confirmComposition();
shouldBeEqualToString('test.value', 'abcdefgh');
debug("Check if confirmComposition on non-focused element doesn't affect the focused editor.");
var context2 = test2.inputMethodContext;
// Focus will still stay in the original field.
test.focus();
expectedText = 'ijkl';
textInputController.setComposition(expectedText);
// As composition for context2 is not on-going, no events will fire.
context2.confirmComposition();
// Cancel the composition.
expectedText = '';
textInputController.setComposition(expectedText);
shouldBeEqualToString('test.value', 'abcdefgh');
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
|