content/html/document/test/bug199692-popup.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/html/document/test/bug199692-popup.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,188 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=199692
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    1.11 +  <title>Popup in test for Bug 199692</title>
    1.12 +  <style type="text/css">
    1.13 +#content * {
    1.14 +  border: 2px solid black;
    1.15 +  margin: 2px;
    1.16 +  clear: both;
    1.17 +  height: 20px;
    1.18 +  overflow: hidden; 
    1.19 +}
    1.20 +
    1.21 +#txt, #static, #fixed, #absolute, #relative, #hidden, #float, #empty, #static, #relative {
    1.22 +  width: 200px !important;
    1.23 +}
    1.24 +  </style>
    1.25 +  
    1.26 +</head>
    1.27 +<!--
    1.28 +Elements are styled in such a way that they don't overlap visually
    1.29 +unless they also overlap structurally.
    1.30 +
    1.31 +This file is designed to be opened from test_bug199692.html in a popup
    1.32 +window, to guarantee that the window in which document.elementFromPoint runs
    1.33 +is large enough to display all the elements being tested.
    1.34 +-->
    1.35 +<body>
    1.36 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=199692">Mozilla Bug 199692</a>
    1.37 +
    1.38 +<div id="content" style="width: 500px; background-color: #ccc;">
    1.39 +
    1.40 +<!-- element containing text -->
    1.41 +<div id="txt" style="height: 30px;">txt</div>
    1.42 +
    1.43 +<!-- element not containing text -->
    1.44 +<div id="empty" style="border: 2px solid blue;"></div>
    1.45 +
    1.46 +<!-- element with only whitespace -->
    1.47 +<p id="whitespace" style="border: 2px solid magenta;"> </p>
    1.48 +
    1.49 +<!-- position: static -->
    1.50 +<span id="static" style="position: static; border-color: green;">static</span>
    1.51 +
    1.52 +<!-- floated element -->
    1.53 +<div id="float" style="border-color: red; float: right;">float</div>
    1.54 +
    1.55 +<!-- position: fixed -->
    1.56 +<span id="fixed" style="position: fixed; top: 500px; left: 100px; border: 3px solid yellow;">fixed</span>
    1.57 +
    1.58 +<!-- position: absolute -->
    1.59 +<span id="absolute" style="position: absolute; top: 550px; left: 150px; border-color: orange;">abs</span>
    1.60 +
    1.61 +<!-- position: relative -->
    1.62 +<div id="relative" style="position: relative; top: 200px; border-color: teal;">rel</div>
    1.63 +
    1.64 +<!-- visibility: hidden -->
    1.65 +<div id="hidden-wrapper" style="border: 1px dashed teal;">
    1.66 +    <div id="hidden" style="opacity: 0.5; background-color: blue; visibility:hidden;">hidden</div>
    1.67 +</div>
    1.68 +
    1.69 +<!-- iframe (within iframe) -->
    1.70 +<iframe id="our-iframe" src="bug199692-nested.html" style="height: 100px; overflow: scroll;"></iframe>
    1.71 +
    1.72 +<input type="textbox" id="textbox" value="textbox"></input>
    1.73 +</div>
    1.74 +
    1.75 +<!-- interaction with scrolling -->
    1.76 +<iframe id="scrolled-iframe"
    1.77 +        src="bug199692-scrolled.html#down"
    1.78 +        style="position: absolute; top: 345px; left: 325px; height: 200px; width: 200px"></iframe>
    1.79 +
    1.80 +<script type="application/javascript">
    1.81 +
    1.82 +var SimpleTest = window.opener.SimpleTest;
    1.83 +function ok() { window.opener.ok.apply(window.opener, arguments); }
    1.84 +function is() { window.opener.is.apply(window.opener, arguments); }
    1.85 +function todo() { window.opener.todo.apply(window.opener, arguments); }
    1.86 +function todo_is() { window.opener.todo_is.apply(window.opener, arguments); }
    1.87 +function $(id) { return document.getElementById(id); }
    1.88 +
    1.89 +/**
    1.90 + * Like is, but for tests which don't always succeed or always fail on all
    1.91 + * platforms.
    1.92 + */
    1.93 +function random_fail(a, b, m)
    1.94 +{
    1.95 +  if (a != b)
    1.96 +    todo_is(a, b, m);
    1.97 +  else
    1.98 +    is(a, b, m);
    1.99 +}
   1.100 +
   1.101 +/* Test for Bug 199692 */
   1.102 +
   1.103 +function getCoords(elt)
   1.104 +{
   1.105 +  var x = 0, y = 0;
   1.106 +
   1.107 +  do
   1.108 +  {
   1.109 +    x += elt.offsetLeft;
   1.110 +    y += elt.offsetTop;
   1.111 +  } while ((elt = elt.offsetParent));
   1.112 +
   1.113 +  return { x: x, y: y };
   1.114 +}
   1.115 +
   1.116 +var elts = ["txt", "empty", "whitespace", "static", "fixed", "absolute",
   1.117 +            "relative", "float", "textbox"];
   1.118 +
   1.119 +function testPoints()
   1.120 +{
   1.121 +  ok('elementFromPoint' in document, "document.elementFromPoint must exist");
   1.122 +  ok(typeof document.elementFromPoint === "function", "must be a function");
   1.123 +  
   1.124 +  var doc = document;
   1.125 +  doc.pt = doc.elementFromPoint; // for shorter lines
   1.126 +  is(doc.pt(-1, 0), null, "Negative coordinates (-1, 0) should return null");
   1.127 +  is(doc.pt(0, -1), null, "Negative coordinates (0, -1) should return null");
   1.128 +  is(doc.pt(-1, -1), null, "Negative coordinates (-1, -1) should return null");
   1.129 +
   1.130 +  var pos;
   1.131 +  for (var i = 0; i < elts.length; i++)
   1.132 +  {
   1.133 +    var id = elts[i];
   1.134 +    var elt = $(id);
   1.135 +
   1.136 +    // The upper left corner of an element (with a moderate offset) will
   1.137 +    // usually contain text, and the lower right corner usually won't.
   1.138 +    var pos = getCoords(elt);
   1.139 +    var x = pos.x, y = pos.y;
   1.140 +    var w = elt.offsetWidth, h = elt.offsetHeight;
   1.141 +
   1.142 +    var d = 5;
   1.143 +    is(doc.pt(x + d, y + d), elt,
   1.144 +       "(" + (x + d) + "," + (y + d) + ") IDs should match (upper left " +
   1.145 +       "corner of " + id + ")");
   1.146 +    is(doc.pt(x + w - d, y + h - d), elt,
   1.147 +       "(" + (x + w - d) + "," + (y + h - d) + ") IDs should match (lower " +
   1.148 +       "right corner of " + id + ")");
   1.149 +  }
   1.150 +
   1.151 +  // content
   1.152 +  var c = $("content");
   1.153 +  pos = getCoords(c);
   1.154 +  x = pos.x + c.offsetWidth / 2;
   1.155 +  y = pos.y;
   1.156 +
   1.157 +  // This fails on some platforms but not others for unknown reasons
   1.158 +  random_fail(doc.pt(x, y), c, "Point to right of #txt should be #content");
   1.159 +  is(doc.pt(x, y + 1), c, "Point to right of #txt should be #content");
   1.160 +  random_fail(doc.pt(x + 1, y), c, "Point to right of #txt should be #content");
   1.161 +  is(doc.pt(x + 1, y + 1), c, "Point to right of #txt should be #content");
   1.162 +
   1.163 +  // hidden
   1.164 +  c = $("hidden");
   1.165 +  pos = getCoords(c);
   1.166 +  x = pos.x, y = pos.y;
   1.167 +  is(doc.pt(x, y), $("hidden-wrapper"),
   1.168 +     "Hit testing should bypass hidden elements.");
   1.169 +
   1.170 +  // iframe nested
   1.171 +  var iframe = $("our-iframe");
   1.172 +  pos = getCoords(iframe);
   1.173 +  x = pos.x, y = pos.y;
   1.174 +  is(doc.pt(x + 20, y + 20), $("our-iframe"),
   1.175 +     "Element from nested iframe returned is from calling document");
   1.176 +  // iframe, doubly nested
   1.177 +  is(doc.pt(x + 60, y + 60), $("our-iframe"),
   1.178 +     "Element from doubly nested iframe returned is from calling document");
   1.179 +
   1.180 +  // scrolled iframe tests
   1.181 +  $("scrolled-iframe").contentWindow.runTests();
   1.182 +
   1.183 +  SimpleTest.finish();
   1.184 +  window.close();
   1.185 +}
   1.186 +
   1.187 +window.onload = testPoints;
   1.188 +</script>
   1.189 +</body>
   1.190 +</html>
   1.191 +

mercurial