test_bug1059163.html 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1059163
  5. -->
  6. <head>
  7. <title>Basic test for repeat sendKey events</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=1059163">Mozilla Bug 1059163</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 the file
  21. function appFrameScript() {
  22. let document = content.document;
  23. let window = content.document.defaultView;
  24. let t = document.getElementById('text');
  25. t.focus();
  26. let range = document.createRange();
  27. range.selectNodeContents(t);
  28. range.collapse(false);
  29. let selection = window.getSelection();
  30. selection.removeAllRanges();
  31. selection.addRange(range);
  32. addMessageListener('test:InputMethod:clear', function() {
  33. t.innerHTML = '';
  34. });
  35. }
  36. function runTest() {
  37. let im = navigator.mozInputMethod;
  38. // Set current page as an input method.
  39. SpecialPowers.wrap(im).setActive(true);
  40. // Create an app frame to recieve keyboard inputs.
  41. let app = document.createElement('iframe');
  42. app.src = 'file_test_bug1066515.html';
  43. app.setAttribute('mozbrowser', true);
  44. document.body.appendChild(app);
  45. app.addEventListener('mozbrowserloadend', function() {
  46. let mm = SpecialPowers.getBrowserFrameMessageManager(app);
  47. mm.loadFrameScript('data:,(' + encodeURIComponent(appFrameScript.toString()) + ')();', false);
  48. im.oninputcontextchange = function() {
  49. is(im.inputcontext.type, 'contenteditable', 'type');
  50. is(im.inputcontext.inputType, 'textarea', 'inputType');
  51. if (im.inputcontext) {
  52. im.oninputcontextchange = null;
  53. register();
  54. }
  55. };
  56. function register() {
  57. im.inputcontext.onselectionchange = function() {
  58. im.inputcontext.onselectionchange = null;
  59. is(im.inputcontext.textBeforeCursor, '', 'textBeforeCursor');
  60. is(im.inputcontext.textAfterCursor, '', 'textAfterCursor');
  61. is(im.inputcontext.selectionStart, 0, 'selectionStart');
  62. is(im.inputcontext.selectionEnd, 0, 'selectionEnd');
  63. inputmethod_cleanup();
  64. };
  65. mm.sendAsyncMessage('test:InputMethod:clear');
  66. }
  67. });
  68. }
  69. </script>
  70. </pre>
  71. </body>
  72. </html>