dom/inputmethod/mochitest/test_bug978918.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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">
    18 // The input context.
    19 var gContext = null;
    21 inputmethod_setup(function() {
    22   runTest();
    23 });
    25 function runTest() {
    26   let im = navigator.mozInputMethod;
    28   im.oninputcontextchange = function() {
    29     ok(true, 'inputcontextchange event was fired.');
    30     im.oninputcontextchange = null;
    32     gContext = im.inputcontext;
    33     if (!gContext) {
    34       ok(false, 'Should have a non-null inputcontext.');
    35       inputmethod_cleanup();
    36       return;
    37     }
    39     test_setSelectionRange();
    40   };
    42   // Set current page as an input method.
    43   SpecialPowers.wrap(im).setActive(true);
    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 }
    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 }
    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 }
    73 </script>
    74 </pre>
    75 </body>
    76 </html>

mercurial