dom/inputmethod/mochitest/test_bug944397.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/inputmethod/mochitest/test_bug944397.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=944397
     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=944397">Mozilla Bug 944397</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 +inputmethod_setup(function() {
    1.22 +  runTest();
    1.23 +});
    1.24 +
    1.25 +// The frame script running in file_test_app.html.
    1.26 +function appFrameScript() {
    1.27 +  let input = content.document.getElementById('test-input');
    1.28 +  input.oninput = function() {
    1.29 +    sendAsyncMessage('test:InputMethod:oninput', {
    1.30 +      value: input.value
    1.31 +    });
    1.32 +  };
    1.33 +}
    1.34 +
    1.35 +function runTest() {
    1.36 +  let app, keyboard;
    1.37 +
    1.38 +  /**
    1.39 +   * So this test does the following:
    1.40 +   * 1. Create a mozbrowser iframe with a text field in it, and focus the text field
    1.41 +   * 2. 100ms. after loading we create new keyboard iframe, that will try to execute
    1.42 +   *    replaceSurroundingText on the current active inputcontext
    1.43 +   * 3. That should trigger 'input' event on the said text field
    1.44 +   * 4. And if that happens we know everything is OK
    1.45 +   */
    1.46 +
    1.47 +  let path = location.pathname;
    1.48 +  let basePath = location.protocol + '//' + location.host +
    1.49 +               path.substring(0, path.lastIndexOf('/'));
    1.50 +
    1.51 +  // STEP 1: Create an app frame to recieve keyboard inputs.
    1.52 +  function step1() {
    1.53 +    app = document.createElement('iframe');
    1.54 +    app.src = basePath + '/file_test_app.html';
    1.55 +    app.setAttribute('mozbrowser', true);
    1.56 +    document.body.appendChild(app);
    1.57 +    app.addEventListener('mozbrowserloadend', function() {
    1.58 +      let mm = SpecialPowers.getBrowserFrameMessageManager(app);
    1.59 +      mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false);
    1.60 +      mm.addMessageListener("test:InputMethod:oninput", function(ev) {
    1.61 +        step4(SpecialPowers.wrap(ev).json.value);
    1.62 +      });
    1.63 +
    1.64 +      step2();
    1.65 +    });
    1.66 +  }
    1.67 +
    1.68 +  function step2() {
    1.69 +    // STEP 2a: Create a browser frame to load the input method app.
    1.70 +    keyboard = document.createElement('iframe');
    1.71 +    keyboard.setAttribute('mozbrowser', true);
    1.72 +    document.body.appendChild(keyboard);
    1.73 +
    1.74 +    // STEP 2b: Grant input privileges to the keyboard iframe
    1.75 +    let imeUrl = basePath + '/file_inputmethod.html#data';
    1.76 +
    1.77 +    SpecialPowers.pushPermissions([{
    1.78 +      type: 'input',
    1.79 +      allow: true,
    1.80 +      context: imeUrl
    1.81 +    }], function() {
    1.82 +      // STEP 2c: Tell Gecko to use this iframe as its keyboard app
    1.83 +      let req = keyboard.setInputMethodActive(true);
    1.84 +
    1.85 +      req.onsuccess = function() {
    1.86 +        ok(true, 'setInputMethodActive succeeded.');
    1.87 +      };
    1.88 +
    1.89 +      req.onerror = function() {
    1.90 +        ok(false, 'setInputMethodActive failed: ' + this.error.name);
    1.91 +        inputmethod_cleanup();
    1.92 +      };
    1.93 +
    1.94 +      // STEP 3: Loads the input method app to the browser frame after a delay.
    1.95 +      setTimeout(function() {
    1.96 +        keyboard.src = imeUrl;
    1.97 +      }, 100);
    1.98 +    });
    1.99 +  }
   1.100 +
   1.101 +  function step4(val) {
   1.102 +    ok(true, 'Keyboard input was received.');
   1.103 +    is(val, '#dataYuan', 'Input value');
   1.104 +    inputmethod_cleanup();
   1.105 +  }
   1.106 +
   1.107 +  step1();
   1.108 +}
   1.109 +
   1.110 +</script>
   1.111 +</pre>
   1.112 +</body>
   1.113 +</html>
   1.114 +

mercurial