test_bug1026997.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1026997
  5. -->
  6. <head>
  7. <title>SelectionChange on InputMethod API.</title>
  8. <script type="application/javascript;version=1.7" src="chrome://mochikit/content/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="chrome://mochikit/content/tests/SimpleTest/test.css"/>
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1026997">Mozilla Bug 1026997</a>
  14. <p id="display"></p>
  15. <pre id="test">
  16. <script class="testbody" type="application/javascript;version=1.7">
  17. inputmethod_setup(function() {
  18. runTest();
  19. });
  20. // The frame script running in file_test_app.html.
  21. function appFrameScript() {
  22. let input = content.document.getElementById('test-input');
  23. input.focus();
  24. function next(start, end) {
  25. input.setSelectionRange(start, end);
  26. }
  27. addMessageListener("test:KeyBoard:nextSelection", function(event) {
  28. let json = event.json;
  29. next(json[0], json[1]);
  30. });
  31. }
  32. function runTest() {
  33. let actions = [
  34. [0, 4],
  35. [1, 1],
  36. [3, 3],
  37. [2, 3]
  38. ];
  39. let counter = 0;
  40. let mm = null;
  41. let ic = null;
  42. let im = navigator.mozInputMethod;
  43. im.oninputcontextchange = function() {
  44. ok(true, 'inputcontextchange event was fired.');
  45. im.oninputcontextchange = null;
  46. ic = im.inputcontext;
  47. if (!ic) {
  48. ok(false, 'Should have a non-null inputcontext.');
  49. inputmethod_cleanup();
  50. return;
  51. }
  52. ic.onselectionchange = function() {
  53. is(ic.selectionStart, actions[counter][0], "start");
  54. is(ic.selectionEnd, actions[counter][1], "end");
  55. if (++counter === actions.length) {
  56. inputmethod_cleanup();
  57. return;
  58. }
  59. next();
  60. };
  61. next();
  62. };
  63. // Set current page as an input method.
  64. SpecialPowers.wrap(im).setActive(true);
  65. // Create an app frame to recieve keyboard inputs.
  66. let app = document.createElement('iframe');
  67. app.src = 'file_test_app.html';
  68. app.setAttribute('mozbrowser', true);
  69. document.body.appendChild(app);
  70. app.addEventListener('mozbrowserloadend', function() {
  71. mm = SpecialPowers.getBrowserFrameMessageManager(app);
  72. mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false);
  73. next();
  74. });
  75. function next() {
  76. if (ic && mm) {
  77. mm.sendAsyncMessage('test:KeyBoard:nextSelection', actions[counter]);
  78. }
  79. }
  80. }
  81. </script>
  82. </pre>
  83. </body>
  84. </html>