|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=978918 |
|
5 --> |
|
6 <head> |
|
7 <title>Basic test for InputMethod API.</title> |
|
8 <script type="application/javascript;version=1.7" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="application/javascript;version=1.7" src="inputmethod_common.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=978918">Mozilla Bug 978918</a> |
|
14 <p id="display"></p> |
|
15 <pre id="test"> |
|
16 <script class="testbody" type="application/javascript;version=1.7"> |
|
17 |
|
18 // The input context. |
|
19 var gContext = null; |
|
20 |
|
21 inputmethod_setup(function() { |
|
22 runTest(); |
|
23 }); |
|
24 |
|
25 function runTest() { |
|
26 let im = navigator.mozInputMethod; |
|
27 |
|
28 im.oninputcontextchange = function() { |
|
29 ok(true, 'inputcontextchange event was fired.'); |
|
30 im.oninputcontextchange = null; |
|
31 |
|
32 gContext = im.inputcontext; |
|
33 if (!gContext) { |
|
34 ok(false, 'Should have a non-null inputcontext.'); |
|
35 inputmethod_cleanup(); |
|
36 return; |
|
37 } |
|
38 |
|
39 test_setSelectionRange(); |
|
40 }; |
|
41 |
|
42 // Set current page as an input method. |
|
43 SpecialPowers.wrap(im).setActive(true); |
|
44 |
|
45 let iframe = document.createElement('iframe'); |
|
46 iframe.src = 'file_test_sms_app.html'; |
|
47 iframe.setAttribute('mozbrowser', true); |
|
48 document.body.appendChild(iframe); |
|
49 } |
|
50 |
|
51 function test_setSelectionRange() { |
|
52 gContext.setSelectionRange(0, 100).then(function() { |
|
53 is(gContext.selectionStart, 0, 'selectionStart was set successfully.'); |
|
54 is(gContext.selectionEnd, 5, 'selectionEnd was set successfully.'); |
|
55 test_replaceSurroundingText(); |
|
56 }, function(e) { |
|
57 ok(false, 'setSelectionRange failed:' + e.name); |
|
58 inputmethod_cleanup(); |
|
59 }); |
|
60 } |
|
61 |
|
62 function test_replaceSurroundingText() { |
|
63 // Replace 'Httvb' with 'Hito'. |
|
64 gContext.replaceSurroundingText('Hito', 0, 100).then(function() { |
|
65 ok(true, 'replaceSurroundingText finished'); |
|
66 inputmethod_cleanup(); |
|
67 }, function(e) { |
|
68 ok(false, 'replaceSurroundingText failed: ' + e.name); |
|
69 inputmethod_cleanup(); |
|
70 }); |
|
71 } |
|
72 |
|
73 </script> |
|
74 </pre> |
|
75 </body> |
|
76 </html> |
|
77 |