dom/tests/mochitest/chrome/489127.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/chrome/489127.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,200 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>nsIDOMWindowUtils::nodesFromRect test - bug 489127</title>
     1.8 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    1.10 +<script type="application/javascript;version=1.8">
    1.11 +
    1.12 +  let SimpleTest = window.opener.SimpleTest;
    1.13 +  function ok() { window.opener.ok.apply(window.opener, arguments); }
    1.14 +  function done() { window.opener.done.apply(window.opener, arguments); }
    1.15 +  let e = {};
    1.16 +
    1.17 +  let dwu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    1.18 +                  .getInterface(Components.interfaces.nsIDOMWindowUtils);
    1.19 +
    1.20 +  /*
    1.21 +    nsIDOMNodeList nodesFromRect(in float aX,
    1.22 +                                 in float aY,
    1.23 +                                 in float aTopSize, 
    1.24 +                                 in float aRightSize,
    1.25 +                                 in float aBottomSize,
    1.26 +                                 in float aLeftSize,
    1.27 +                                 in boolean aIgnoreRootScrollFrame,
    1.28 +                                 in boolean aFlushLayout);
    1.29 +
    1.30 +  */
    1.31 +
    1.32 +  function check(x, y, top, right, bottom, left, list) {
    1.33 +    let nodes = dwu.nodesFromRect(x, y, top, right, bottom, left, true, false);
    1.34 +    
    1.35 +    list.push(e.body);
    1.36 +    list.push(e.html);
    1.37 +
    1.38 +    if (nodes.length != list.length) {
    1.39 +      ok(false, "Different number of nodes for rect" +
    1.40 +                "[" + x + "," + y + "], " + 
    1.41 +                "[" + top + "," + right + "," + bottom + "," + left + "]");
    1.42 +      return;
    1.43 +    }
    1.44 +
    1.45 +    for (var i = 0; i < nodes.length; i++) {
    1.46 +      if (nodes[i] != list[i]) {
    1.47 +        ok(false, "Unexpected node #" + i + " for rect " +
    1.48 +                  "[" + x + "," + y + "], " + 
    1.49 +                  "[" + top + "," + right + "," + bottom + "," + left + "]");
    1.50 +        return;
    1.51 +      }
    1.52 +    }
    1.53 +    ok(true, "All correct nodes found for rect "  +
    1.54 +             "[" + x + "," + y + "], " + 
    1.55 +             "[" + top + "," + right + "," + bottom + "," + left + "]");
    1.56 +  }
    1.57 +
    1.58 +  function doTest() {
    1.59 +
    1.60 +    // Set up shortcut access to elements
    1.61 +    e['html'] = document.getElementsByTagName("html")[0];
    1.62 +    ['h1', 'd1', 'd2', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'span',
    1.63 +     'a1', 'a2', 'a3', 'transf', 'iframe1', 'body'].forEach(function(a) {
    1.64 +      e[a] = document.getElementById(a);
    1.65 +    });
    1.66 +
    1.67 +    window.scrollTo(0, 0);
    1.68 +
    1.69 +    // Top, Right, Bottom, Left directions:
    1.70 +    check(53, 71, 0,  0,  0,  0, []);
    1.71 +    check(53, 71, 10, 0,  0,  0, [e.h1]);
    1.72 +    check(53, 71, 0,  10, 0,  0, [e.p3]);
    1.73 +    check(53, 71, 0,  0,  10, 0, [e.d1]);
    1.74 +    check(152, 105, 0, 0, 0, 10, [e.d1]);
    1.75 +    check(152, 105, 10, 10, 10, 10, [e.p4, e.p3, e.d1]);
    1.76 +
    1.77 +    // e.p1 is invisible and shouldn't appear:
    1.78 +    check(153,193,0,0,0,0,[e.p5]);
    1.79 +    check(153,193,0,20,0,20, [e.p5, e.d2]);
    1.80 +
    1.81 +    // Precise pixel checks:
    1.82 +    check(144, 183, 0, 0, 0, 0, []);
    1.83 +    check(144, 183, 0, 0, 1, 0, [e.p5]);
    1.84 +    check(144, 183, 0, 0, 0, 1, [e.d2]);
    1.85 +    check(144, 183, 0, 0, 1, 1, [e.p5, e.d2]);
    1.86 +    check(77,  240, 0, 0, 0, 0, [e.p2]);
    1.87 +    check(77,  240, 1, 0, 0, 0, [e.p5, e.p2]);
    1.88 +    check(77,  240, 0, 0, 1, 0, [e.span, e.p2]);
    1.89 +    check(77,  240, 1, 0, 1, 0, [e.p5, e.span, e.p2]);
    1.90 +
    1.91 +    // Expanding area checks:
    1.92 +    check(39, 212, 0,  0,  0,  0, []);
    1.93 +    check(39, 212, 10, 0,  0,  0, [e.d2]);
    1.94 +    check(39, 212, 0,  0,  10, 0, [e.p2]);
    1.95 +    check(39, 212, 10, 1,  30, 0, [e.d2, e.p2]);
    1.96 +    check(39, 212, 10, 5,  30, 0, [e.span, e.d2, e.p2]);
    1.97 +    check(39, 212, 10, 15, 30, 0, [e.p5, e.span, e.d2, e.p2]);
    1.98 +
    1.99 +    // Elements inside iframe shouldn't be returned:
   1.100 +    check(15, 410, 0, 30, 50, 0, [e.iframe1]);
   1.101 +
   1.102 +    // Area with links and text nodes:
   1.103 +    let [x1, y1] = getCenterFor(e.a1);
   1.104 +    let [x2, y2] = getCenterFor(e.a2);
   1.105 +    let [x3, y3] = getCenterFor(e.a3);
   1.106 +    let [xt, yt] = [(x2 + x1) / 2, y1]; //text node between a1 and a2
   1.107 +
   1.108 +    check(x1, y1, 0, 0,       0,       0, [e.a1.firstChild, e.a1, e.p6]);
   1.109 +    check(x1, y1, 0, 0,       y3 - y1, 0, [e.a3.firstChild, e.a3, e.a1.firstChild, e.a1, e.p6]);
   1.110 +    check(x1, y1, 0, xt - x1, 0,       0, [e.p6.childNodes[1], e.a1.firstChild, e.a1, e.p6]);
   1.111 +    check(x1, y1, 0, x2 - x1, 0,       0, [e.a2.firstChild, e.a2, e.p6.childNodes[1], e.a1.firstChild, e.a1, e.p6]);
   1.112 +    check(x1, y1, 0, x2 - x1, y3 - y1, 0, [e.a3.firstChild, e.a3, e.a2.firstChild, e.a2, e.p6.childNodes[1], e.a1.firstChild, e.a1, e.p6]);
   1.113 +
   1.114 +    // 2d transform:
   1.115 +    check(61, 671, 0, 0,  0,  0,  []);
   1.116 +    check(61, 671, 0, 30, 0,  10, [e.transf]);
   1.117 +    check(61, 671, 0, 30, 90, 10, [e.transf.firstChild, e.transf]);
   1.118 +
   1.119 +    done();
   1.120 +
   1.121 +  }
   1.122 +
   1.123 +  function getCenterFor(element) {
   1.124 +    let rect = element.getBoundingClientRect();
   1.125 +    return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];
   1.126 +  }
   1.127 +
   1.128 +  addLoadEvent(doTest);
   1.129 +</script>
   1.130 +<style type="text/css">
   1.131 +
   1.132 +body {
   1.133 +  margin: 8px;
   1.134 +  padding: 0;
   1.135 +}
   1.136 +
   1.137 +h1, div, p, span, iframe {
   1.138 +  display: block;
   1.139 +  width: 100px;
   1.140 +  height: 30px;
   1.141 +  border: 3px solid black;
   1.142 +  padding: 10px;
   1.143 +  margin: 10px;
   1.144 +}
   1.145 +
   1.146 +
   1.147 +span {
   1.148 +  display: inline-block;
   1.149 +}
   1.150 +
   1.151 +#iframe1 {
   1.152 +  height: 100px;
   1.153 +  margin-top: 60px;
   1.154 +}
   1.155 +
   1.156 +#p6 {
   1.157 +  height: 50px;
   1.158 +  margin-top: 30px;
   1.159 +}
   1.160 +
   1.161 +#transf {
   1.162 +  margin-top: 60px;
   1.163 +  -moz-transform: rotate(-45deg);
   1.164 +}
   1.165 +
   1.166 +#decimal {
   1.167 +  position: relative;
   1.168 +  left: 0.5px;
   1.169 +  top: 50.5px;
   1.170 +}
   1.171 +</style>
   1.172 +</head>
   1.173 +<body id="body">
   1.174 +  <h1 id="h1"></h1>
   1.175 +  <div id="d1"></div>
   1.176 +  
   1.177 +  <!-- floated element -->
   1.178 +  <div id="d2" style="float: left"></div>
   1.179 +
   1.180 +  <!-- hidden element -->
   1.181 +  <p id="p1" style="float: left; visibility: hidden"></p>
   1.182 +
   1.183 +  <p id="p2" style="clear: left"><span id="span"></span></p>
   1.184 +  
   1.185 +  <!-- absolute position -->
   1.186 +  <p id="p3" style="position:absolute; top: 10px; left:50px; height:50px;"></p>
   1.187 +  
   1.188 +  <!-- fixed position -->
   1.189 +  <p id="p4" style="position: fixed; top: 30px; left: 150px; height: 50px; background-color: blue;"></p>
   1.190 +
   1.191 +  <!-- relative position -->
   1.192 +  <p id="p5" style="position:relative; top: -100px; left: 30px; margin-bottom: -70px; background-color: green"></p>
   1.193 +
   1.194 +  <!-- decimal CSS pixels -->
   1.195 +  <div id="decimal"></div>
   1.196 +
   1.197 +  <iframe id="iframe1" src="data:text/html,<div>div</div><p>p</p>"></iframe>
   1.198 +
   1.199 +  <p id="p6"><a href="#" id="a1">A</a> / <a href="#" id="a2">A</a><br/><a href="#" id="a3">A</a></p>
   1.200 +
   1.201 +  <div id="transf">text</div>
   1.202 +</body>
   1.203 +</html>

mercurial