test_bug534833.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=534833
  5. -->
  6. <head>
  7. <title>Test for Bug 534833</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=534833">Mozilla Bug 534833</a>
  14. <p id="display"></p>
  15. <div id="content" style="display: none">
  16. </div>
  17. <pre id="test">
  18. <script type="application/javascript">
  19. /** Test for Bug 534833 **/
  20. SimpleTest.waitForExplicitFinish();
  21. addLoadEvent(runTests);
  22. var input1GotClick = 0;
  23. var input2GotClick = 0;
  24. var textarea1GotClick = 0;
  25. var textarea2GotClick = 0;
  26. var div1GotClick = 0;
  27. var div2GotClick = 0;
  28. var tests = [ { element: "text", clickText: true },
  29. { element: "text2", clickText: false },
  30. { element: "area", clickText: true },
  31. { element: "area2", clickText: false },
  32. { element: "d", clickText: true },
  33. { element: "d", clickText: false },
  34. { element: "d2", clickText: true },
  35. { element: "d2", clickText: false }
  36. ];
  37. function nextTest_() {
  38. if (!tests.length) {
  39. finishTests();
  40. return;
  41. }
  42. var test = tests.shift();
  43. var el = document.getElementById(test.element);
  44. el.scrollIntoView(true);
  45. if (test.clickText) {
  46. synthesizeMouse(el, 5, 5, {type : "mousedown" });
  47. synthesizeMouse(el, 5, 5, {type : "mouseup" });
  48. } else {
  49. synthesizeMouse(el, el.getBoundingClientRect().width - 5, 5, {type : "mousedown" });
  50. synthesizeMouse(el, el.getBoundingClientRect().width - 5, 5, {type : "mouseup" });
  51. }
  52. nextTest();
  53. }
  54. function nextTest() {
  55. var el = document.getElementById("initialfocus");
  56. el.addEventListener("focus", function() {
  57. el.removeEventListener("focus", arguments.callee, false);
  58. setTimeout(nextTest_, 0);
  59. }, false);
  60. el.focus();
  61. }
  62. function runTests() {
  63. var t = document.getElementById("text");
  64. var t2 = document.getElementById("text2");
  65. var a = document.getElementById("area");
  66. var a2 = document.getElementById("area2");
  67. var d = document.getElementById("d");
  68. var d2 = document.getElementById("d2");
  69. // input 1
  70. t.onfocus = function(e) {
  71. t.value = "";
  72. }
  73. t.onclick = function(e) {
  74. ++input1GotClick;
  75. }
  76. // input 2
  77. t2.onfocus = function(e) {
  78. t2.value = "";
  79. }
  80. t2.onclick = function(e) {
  81. ++input2GotClick;
  82. }
  83. // textarea 1
  84. a.onfocus = function(e) {
  85. a.value = "";
  86. }
  87. a.onclick = function(e) {
  88. ++textarea1GotClick;
  89. }
  90. // textarea 2
  91. a2.onfocus = function(e) {
  92. a2.value = "";
  93. }
  94. a2.onclick = function(e) {
  95. ++textarea2GotClick;
  96. }
  97. // div 1
  98. var c = 0;
  99. d.onmousedown = function(e) {
  100. d.textContent = (++c) + " / click before or after |";
  101. }
  102. d.onclick = function(e) {
  103. ++div1GotClick;
  104. }
  105. // div 2
  106. var c2 = 0;
  107. d2.onmousedown = function(e) {
  108. d2.firstChild.data = (++c2) + " / click before or after |";
  109. }
  110. d2.onclick = function(e) {
  111. ++div2GotClick;
  112. }
  113. nextTest();
  114. }
  115. function finishTests() {
  116. is(input1GotClick, 1, "input element should have got a click!");
  117. is(input2GotClick, 1, "input element should have got a click! (2)");
  118. is(textarea1GotClick, 1, "textarea element should have got a click!");
  119. is(textarea2GotClick, 1, "textarea element should have got a click! (2)");
  120. is(div1GotClick, 2, "div element's content text was replaced, it should have got 2 click!");
  121. is(div2GotClick, 2, "div element's content text was modified, it should have got 2 clicks!");
  122. SimpleTest.finish();
  123. }
  124. </script>
  125. </pre>
  126. <input type="text" id="initialfocus"><br>
  127. <input type="text" id="text" value="click before |" style="width: 95%;"><br>
  128. <input type="text" id="text2" value="click after |" style="width: 95%;">
  129. <br>
  130. <textarea id="area" rows="2" style="width: 95%;">
  131. click before
  132. |
  133. </textarea><br>
  134. <textarea id="area2" rows="2" style="width: 95%;">
  135. click after |
  136. </textarea>
  137. <div id="d" style="border: 1px solid black;">click before or after |</div>
  138. <div id="d2" style="border: 1px solid black;">click before or after |</div>
  139. </body>
  140. </html>