dom/inputmethod/mochitest/test_bug978918.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/inputmethod/mochitest/test_bug978918.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=978918
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Basic test for InputMethod API.</title>
    1.11 +  <script type="application/javascript;version=1.7" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="application/javascript;version=1.7" src="inputmethod_common.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=978918">Mozilla Bug 978918</a>
    1.17 +<p id="display"></p>
    1.18 +<pre id="test">
    1.19 +<script class="testbody" type="application/javascript;version=1.7">
    1.20 +
    1.21 +// The input context.
    1.22 +var gContext = null;
    1.23 +
    1.24 +inputmethod_setup(function() {
    1.25 +  runTest();
    1.26 +});
    1.27 +
    1.28 +function runTest() {
    1.29 +  let im = navigator.mozInputMethod;
    1.30 +
    1.31 +  im.oninputcontextchange = function() {
    1.32 +    ok(true, 'inputcontextchange event was fired.');
    1.33 +    im.oninputcontextchange = null;
    1.34 +
    1.35 +    gContext = im.inputcontext;
    1.36 +    if (!gContext) {
    1.37 +      ok(false, 'Should have a non-null inputcontext.');
    1.38 +      inputmethod_cleanup();
    1.39 +      return;
    1.40 +    }
    1.41 +
    1.42 +    test_setSelectionRange();
    1.43 +  };
    1.44 +
    1.45 +  // Set current page as an input method.
    1.46 +  SpecialPowers.wrap(im).setActive(true);
    1.47 +
    1.48 +  let iframe = document.createElement('iframe');
    1.49 +  iframe.src = 'file_test_sms_app.html';
    1.50 +  iframe.setAttribute('mozbrowser', true);
    1.51 +  document.body.appendChild(iframe);
    1.52 +}
    1.53 +
    1.54 +function test_setSelectionRange() {
    1.55 +  gContext.setSelectionRange(0, 100).then(function() {
    1.56 +    is(gContext.selectionStart, 0, 'selectionStart was set successfully.');
    1.57 +    is(gContext.selectionEnd, 5, 'selectionEnd was set successfully.');
    1.58 +    test_replaceSurroundingText();
    1.59 +  }, function(e) {
    1.60 +    ok(false, 'setSelectionRange failed:' + e.name);
    1.61 +    inputmethod_cleanup();
    1.62 +  });
    1.63 +}
    1.64 +
    1.65 +function test_replaceSurroundingText() {
    1.66 +  // Replace 'Httvb' with 'Hito'.
    1.67 +  gContext.replaceSurroundingText('Hito', 0, 100).then(function() {
    1.68 +    ok(true, 'replaceSurroundingText finished');
    1.69 +    inputmethod_cleanup();
    1.70 +  }, function(e) {
    1.71 +    ok(false, 'replaceSurroundingText failed: ' + e.name);
    1.72 +    inputmethod_cleanup();
    1.73 +  });
    1.74 +}
    1.75 +
    1.76 +</script>
    1.77 +</pre>
    1.78 +</body>
    1.79 +</html>
    1.80 +

mercurial