test_bug864040.html 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=864040
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 864040</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  11. <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
  12. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  13. </head>
  14. <body>
  15. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=864040">Mozilla Bug 864040</a>
  16. <div id="display">
  17. <textarea id="ta" rows="5" cols="20" style="-moz-appearance:none"></textarea>
  18. <div id="ce" contentEditable="true" style="height: 5em;"></div>
  19. </div>
  20. <div id="content" style="display: none">
  21. </div>
  22. <pre id="test">
  23. <script type="application/javascript">
  24. /**
  25. * Test for Bug 864040
  26. *
  27. * We use a selection event to set the selection to the end of an editor
  28. * containing an ending newline. Then we test to see that the caret is
  29. * actually drawn on the newline.
  30. */
  31. function testSelectEndOfText(elem) {
  32. var tn = elem.tagName;
  33. elem.focus();
  34. // Enter test string into editor
  35. var test_string = 'test\n';
  36. sendString(test_string);
  37. // Get the caret position after what we entered
  38. var result = synthesizeQuerySelectedText();
  39. ok(result, tn + ': failed to query selection (1)');
  40. var refoffset = result.offset;
  41. // Take a snapshot of where the caret is (on the new line)
  42. referenceSnapshot = snapshotWindow(window, true /* withCaret */);
  43. ok(referenceSnapshot, tn + ': failed to take snapshot (1)');
  44. // Set selection to the same spot through a selection event
  45. ok(synthesizeSelectionSet(refoffset, 0, false), tn + ': failed to set selection');
  46. // Make sure new selection is the same
  47. result = synthesizeQuerySelectedText();
  48. ok(result, tn + ': failed to query selection (2)');
  49. is(result.offset, refoffset, tn + ': caret is not at the right position');
  50. // Take a snapshot of where the new caret is (shoud still be on the new line)
  51. testSnapshot = snapshotWindow(window, true /* withCaret */);
  52. ok(testSnapshot, tn + ': failed to take snapshot (2)');
  53. // Compare snapshot (should be the same)
  54. result = compareSnapshots(referenceSnapshot, testSnapshot, true /* expected */)
  55. ok(result, tn + ': failed to compare snapshots');
  56. // result = [correct, s1data, s2data]
  57. ok(result[0], tn + ': caret is not on new line');
  58. if (!result[0]) {
  59. dump('Ref: ' + result[1] + '\n');
  60. dump('Res: ' + result[2] + '\n');
  61. }
  62. }
  63. function runTests() {
  64. // we don't test regular <input> because this test is about multiline support
  65. // test textarea
  66. testSelectEndOfText(document.getElementById('ta'));
  67. // test contentEditable
  68. testSelectEndOfText(document.getElementById('ce'));
  69. SimpleTest.finish();
  70. }
  71. SimpleTest.waitForExplicitFinish();
  72. SimpleTest.waitForFocus(runTests);
  73. </script>
  74. </pre>
  75. </body>
  76. </html>