bug199692-popup.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=199692
  5. -->
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <title>Popup in test for Bug 199692</title>
  9. <style type="text/css">
  10. #content * {
  11. border: 2px solid black;
  12. margin: 2px;
  13. clear: both;
  14. height: 20px;
  15. overflow: hidden;
  16. }
  17. #txt, #static, #fixed, #absolute, #relative, #hidden, #float, #empty, #static, #relative {
  18. width: 200px !important;
  19. }
  20. </style>
  21. </head>
  22. <!--
  23. Elements are styled in such a way that they don't overlap visually
  24. unless they also overlap structurally.
  25. This file is designed to be opened from test_bug199692.html in a popup
  26. window, to guarantee that the window in which document.elementFromPoint runs
  27. is large enough to display all the elements being tested.
  28. -->
  29. <body>
  30. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=199692">Mozilla Bug 199692</a>
  31. <div id="content" style="width: 500px; background-color: #ccc;">
  32. <!-- element containing text -->
  33. <div id="txt" style="height: 30px;">txt</div>
  34. <!-- element not containing text -->
  35. <div id="empty" style="border: 2px solid blue;"></div>
  36. <!-- element with only whitespace -->
  37. <p id="whitespace" style="border: 2px solid magenta;"> </p>
  38. <!-- position: static -->
  39. <span id="static" style="position: static; border-color: green;">static</span>
  40. <!-- floated element -->
  41. <div id="float" style="border-color: red; float: right;">float</div>
  42. <!-- position: fixed -->
  43. <span id="fixed" style="position: fixed; top: 500px; left: 100px; border: 3px solid yellow;">fixed</span>
  44. <!-- position: absolute -->
  45. <span id="absolute" style="position: absolute; top: 550px; left: 150px; border-color: orange;">abs</span>
  46. <!-- position: relative -->
  47. <div id="relative" style="position: relative; top: 200px; border-color: teal;">rel</div>
  48. <!-- visibility: hidden -->
  49. <div id="hidden-wrapper" style="border: 1px dashed teal;">
  50. <div id="hidden" style="opacity: 0.5; background-color: blue; visibility:hidden;">hidden</div>
  51. </div>
  52. <!-- iframe (within iframe) -->
  53. <iframe id="our-iframe" src="bug199692-nested.html" style="height: 100px; overflow: scroll;"></iframe>
  54. <input type="textbox" id="textbox" value="textbox"></input>
  55. </div>
  56. <!-- interaction with scrolling -->
  57. <iframe id="scrolled-iframe"
  58. src="bug199692-scrolled.html#down"
  59. style="position: absolute; top: 345px; left: 325px; height: 200px; width: 200px"></iframe>
  60. <script type="application/javascript">
  61. var SimpleTest = window.opener.SimpleTest;
  62. function ok() { window.opener.ok.apply(window.opener, arguments); }
  63. function is() { window.opener.is.apply(window.opener, arguments); }
  64. function todo() { window.opener.todo.apply(window.opener, arguments); }
  65. function todo_is() { window.opener.todo_is.apply(window.opener, arguments); }
  66. function $(id) { return document.getElementById(id); }
  67. /**
  68. * Like is, but for tests which don't always succeed or always fail on all
  69. * platforms.
  70. */
  71. function random_fail(a, b, m)
  72. {
  73. if (a != b)
  74. todo_is(a, b, m);
  75. else
  76. is(a, b, m);
  77. }
  78. /* Test for Bug 199692 */
  79. function getCoords(elt)
  80. {
  81. var x = 0, y = 0;
  82. do
  83. {
  84. x += elt.offsetLeft;
  85. y += elt.offsetTop;
  86. } while ((elt = elt.offsetParent));
  87. return { x: x, y: y };
  88. }
  89. var elts = ["txt", "empty", "whitespace", "static", "fixed", "absolute",
  90. "relative", "float", "textbox"];
  91. function testPoints()
  92. {
  93. ok('elementFromPoint' in document, "document.elementFromPoint must exist");
  94. ok(typeof document.elementFromPoint === "function", "must be a function");
  95. var doc = document;
  96. doc.pt = doc.elementFromPoint; // for shorter lines
  97. is(doc.pt(-1, 0), null, "Negative coordinates (-1, 0) should return null");
  98. is(doc.pt(0, -1), null, "Negative coordinates (0, -1) should return null");
  99. is(doc.pt(-1, -1), null, "Negative coordinates (-1, -1) should return null");
  100. var pos;
  101. for (var i = 0; i < elts.length; i++)
  102. {
  103. var id = elts[i];
  104. var elt = $(id);
  105. // The upper left corner of an element (with a moderate offset) will
  106. // usually contain text, and the lower right corner usually won't.
  107. var pos = getCoords(elt);
  108. var x = pos.x, y = pos.y;
  109. var w = elt.offsetWidth, h = elt.offsetHeight;
  110. var d = 5;
  111. is(doc.pt(x + d, y + d), elt,
  112. "(" + (x + d) + "," + (y + d) + ") IDs should match (upper left " +
  113. "corner of " + id + ")");
  114. is(doc.pt(x + w - d, y + h - d), elt,
  115. "(" + (x + w - d) + "," + (y + h - d) + ") IDs should match (lower " +
  116. "right corner of " + id + ")");
  117. }
  118. // content
  119. var c = $("content");
  120. pos = getCoords(c);
  121. x = pos.x + c.offsetWidth / 2;
  122. y = pos.y;
  123. // This fails on some platforms but not others for unknown reasons
  124. random_fail(doc.pt(x, y), c, "Point to right of #txt should be #content");
  125. is(doc.pt(x, y + 1), c, "Point to right of #txt should be #content");
  126. random_fail(doc.pt(x + 1, y), c, "Point to right of #txt should be #content");
  127. is(doc.pt(x + 1, y + 1), c, "Point to right of #txt should be #content");
  128. // hidden
  129. c = $("hidden");
  130. pos = getCoords(c);
  131. x = pos.x, y = pos.y;
  132. is(doc.pt(x, y), $("hidden-wrapper"),
  133. "Hit testing should bypass hidden elements.");
  134. // iframe nested
  135. var iframe = $("our-iframe");
  136. pos = getCoords(iframe);
  137. x = pos.x, y = pos.y;
  138. is(doc.pt(x + 20, y + 20), $("our-iframe"),
  139. "Element from nested iframe returned is from calling document");
  140. // iframe, doubly nested
  141. is(doc.pt(x + 60, y + 60), $("our-iframe"),
  142. "Element from doubly nested iframe returned is from calling document");
  143. // scrolled iframe tests
  144. $("scrolled-iframe").contentWindow.runTests();
  145. SimpleTest.finish();
  146. window.close();
  147. }
  148. window.onload = testPoints;
  149. </script>
  150. </body>
  151. </html>