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