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