test_sync_edit.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1079455
  5. -->
  6. <head>
  7. <title>Sync edit of an input</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=1079455">Mozilla Bug 1079455</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. let appFrameScript = function appFrameScript() {
  21. let input = content.document.body.firstElementChild;
  22. input.focus();
  23. input.value = 'First1';
  24. input.blur();
  25. };
  26. function runTest() {
  27. let im = navigator.mozInputMethod;
  28. let i = 0;
  29. im.oninputcontextchange = function() {
  30. let inputcontext = im.inputcontext;
  31. i++;
  32. switch (i) {
  33. case 1:
  34. ok(!!inputcontext, 'Should receive inputcontext from focus().');
  35. is(inputcontext.textAfterCursor, 'First');
  36. break;
  37. case 2:
  38. ok(!!inputcontext, 'Should receive inputcontext from value change.');
  39. is(inputcontext.textBeforeCursor, 'First1');
  40. break;
  41. case 3:
  42. ok(!inputcontext, 'Should lost inputcontext from blur().');
  43. inputmethod_cleanup();
  44. break;
  45. default:
  46. ok(false, 'Unknown event count.');
  47. inputmethod_cleanup();
  48. }
  49. };
  50. // Set current page as an input method.
  51. SpecialPowers.wrap(im).setActive(true);
  52. let iframe = document.createElement('iframe');
  53. iframe.src = 'file_test_sync_edit.html';
  54. iframe.setAttribute('mozbrowser', true);
  55. document.body.appendChild(iframe);
  56. let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
  57. iframe.addEventListener('mozbrowserloadend', function() {
  58. mm.loadFrameScript('data:,(' + encodeURIComponent(appFrameScript.toString()) + ')();', false);
  59. });
  60. }
  61. </script>
  62. </pre>
  63. </body>
  64. </html>