Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>nsIDOMWindowUtils::nodesFromRect test - bug 489127</title> |
michael@0 | 5 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
michael@0 | 7 | <script type="application/javascript;version=1.8"> |
michael@0 | 8 | |
michael@0 | 9 | let SimpleTest = window.opener.SimpleTest; |
michael@0 | 10 | function ok() { window.opener.ok.apply(window.opener, arguments); } |
michael@0 | 11 | function done() { window.opener.done.apply(window.opener, arguments); } |
michael@0 | 12 | let e = {}; |
michael@0 | 13 | |
michael@0 | 14 | let dwu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) |
michael@0 | 15 | .getInterface(Components.interfaces.nsIDOMWindowUtils); |
michael@0 | 16 | |
michael@0 | 17 | /* |
michael@0 | 18 | nsIDOMNodeList nodesFromRect(in float aX, |
michael@0 | 19 | in float aY, |
michael@0 | 20 | in float aTopSize, |
michael@0 | 21 | in float aRightSize, |
michael@0 | 22 | in float aBottomSize, |
michael@0 | 23 | in float aLeftSize, |
michael@0 | 24 | in boolean aIgnoreRootScrollFrame, |
michael@0 | 25 | in boolean aFlushLayout); |
michael@0 | 26 | |
michael@0 | 27 | */ |
michael@0 | 28 | |
michael@0 | 29 | function check(x, y, top, right, bottom, left, list) { |
michael@0 | 30 | let nodes = dwu.nodesFromRect(x, y, top, right, bottom, left, true, false); |
michael@0 | 31 | |
michael@0 | 32 | list.push(e.body); |
michael@0 | 33 | list.push(e.html); |
michael@0 | 34 | |
michael@0 | 35 | if (nodes.length != list.length) { |
michael@0 | 36 | ok(false, "Different number of nodes for rect" + |
michael@0 | 37 | "[" + x + "," + y + "], " + |
michael@0 | 38 | "[" + top + "," + right + "," + bottom + "," + left + "]"); |
michael@0 | 39 | return; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | for (var i = 0; i < nodes.length; i++) { |
michael@0 | 43 | if (nodes[i] != list[i]) { |
michael@0 | 44 | ok(false, "Unexpected node #" + i + " for rect " + |
michael@0 | 45 | "[" + x + "," + y + "], " + |
michael@0 | 46 | "[" + top + "," + right + "," + bottom + "," + left + "]"); |
michael@0 | 47 | return; |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | ok(true, "All correct nodes found for rect " + |
michael@0 | 51 | "[" + x + "," + y + "], " + |
michael@0 | 52 | "[" + top + "," + right + "," + bottom + "," + left + "]"); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function doTest() { |
michael@0 | 56 | |
michael@0 | 57 | // Set up shortcut access to elements |
michael@0 | 58 | e['html'] = document.getElementsByTagName("html")[0]; |
michael@0 | 59 | ['h1', 'd1', 'd2', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'span', |
michael@0 | 60 | 'a1', 'a2', 'a3', 'transf', 'iframe1', 'body'].forEach(function(a) { |
michael@0 | 61 | e[a] = document.getElementById(a); |
michael@0 | 62 | }); |
michael@0 | 63 | |
michael@0 | 64 | window.scrollTo(0, 0); |
michael@0 | 65 | |
michael@0 | 66 | // Top, Right, Bottom, Left directions: |
michael@0 | 67 | check(53, 71, 0, 0, 0, 0, []); |
michael@0 | 68 | check(53, 71, 10, 0, 0, 0, [e.h1]); |
michael@0 | 69 | check(53, 71, 0, 10, 0, 0, [e.p3]); |
michael@0 | 70 | check(53, 71, 0, 0, 10, 0, [e.d1]); |
michael@0 | 71 | check(152, 105, 0, 0, 0, 10, [e.d1]); |
michael@0 | 72 | check(152, 105, 10, 10, 10, 10, [e.p4, e.p3, e.d1]); |
michael@0 | 73 | |
michael@0 | 74 | // e.p1 is invisible and shouldn't appear: |
michael@0 | 75 | check(153,193,0,0,0,0,[e.p5]); |
michael@0 | 76 | check(153,193,0,20,0,20, [e.p5, e.d2]); |
michael@0 | 77 | |
michael@0 | 78 | // Precise pixel checks: |
michael@0 | 79 | check(144, 183, 0, 0, 0, 0, []); |
michael@0 | 80 | check(144, 183, 0, 0, 1, 0, [e.p5]); |
michael@0 | 81 | check(144, 183, 0, 0, 0, 1, [e.d2]); |
michael@0 | 82 | check(144, 183, 0, 0, 1, 1, [e.p5, e.d2]); |
michael@0 | 83 | check(77, 240, 0, 0, 0, 0, [e.p2]); |
michael@0 | 84 | check(77, 240, 1, 0, 0, 0, [e.p5, e.p2]); |
michael@0 | 85 | check(77, 240, 0, 0, 1, 0, [e.span, e.p2]); |
michael@0 | 86 | check(77, 240, 1, 0, 1, 0, [e.p5, e.span, e.p2]); |
michael@0 | 87 | |
michael@0 | 88 | // Expanding area checks: |
michael@0 | 89 | check(39, 212, 0, 0, 0, 0, []); |
michael@0 | 90 | check(39, 212, 10, 0, 0, 0, [e.d2]); |
michael@0 | 91 | check(39, 212, 0, 0, 10, 0, [e.p2]); |
michael@0 | 92 | check(39, 212, 10, 1, 30, 0, [e.d2, e.p2]); |
michael@0 | 93 | check(39, 212, 10, 5, 30, 0, [e.span, e.d2, e.p2]); |
michael@0 | 94 | check(39, 212, 10, 15, 30, 0, [e.p5, e.span, e.d2, e.p2]); |
michael@0 | 95 | |
michael@0 | 96 | // Elements inside iframe shouldn't be returned: |
michael@0 | 97 | check(15, 410, 0, 30, 50, 0, [e.iframe1]); |
michael@0 | 98 | |
michael@0 | 99 | // Area with links and text nodes: |
michael@0 | 100 | let [x1, y1] = getCenterFor(e.a1); |
michael@0 | 101 | let [x2, y2] = getCenterFor(e.a2); |
michael@0 | 102 | let [x3, y3] = getCenterFor(e.a3); |
michael@0 | 103 | let [xt, yt] = [(x2 + x1) / 2, y1]; //text node between a1 and a2 |
michael@0 | 104 | |
michael@0 | 105 | check(x1, y1, 0, 0, 0, 0, [e.a1.firstChild, e.a1, e.p6]); |
michael@0 | 106 | check(x1, y1, 0, 0, y3 - y1, 0, [e.a3.firstChild, e.a3, e.a1.firstChild, e.a1, e.p6]); |
michael@0 | 107 | check(x1, y1, 0, xt - x1, 0, 0, [e.p6.childNodes[1], e.a1.firstChild, e.a1, e.p6]); |
michael@0 | 108 | check(x1, y1, 0, x2 - x1, 0, 0, [e.a2.firstChild, e.a2, e.p6.childNodes[1], e.a1.firstChild, e.a1, e.p6]); |
michael@0 | 109 | 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]); |
michael@0 | 110 | |
michael@0 | 111 | // 2d transform: |
michael@0 | 112 | check(61, 671, 0, 0, 0, 0, []); |
michael@0 | 113 | check(61, 671, 0, 30, 0, 10, [e.transf]); |
michael@0 | 114 | check(61, 671, 0, 30, 90, 10, [e.transf.firstChild, e.transf]); |
michael@0 | 115 | |
michael@0 | 116 | done(); |
michael@0 | 117 | |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function getCenterFor(element) { |
michael@0 | 121 | let rect = element.getBoundingClientRect(); |
michael@0 | 122 | return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2]; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | addLoadEvent(doTest); |
michael@0 | 126 | </script> |
michael@0 | 127 | <style type="text/css"> |
michael@0 | 128 | |
michael@0 | 129 | body { |
michael@0 | 130 | margin: 8px; |
michael@0 | 131 | padding: 0; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | h1, div, p, span, iframe { |
michael@0 | 135 | display: block; |
michael@0 | 136 | width: 100px; |
michael@0 | 137 | height: 30px; |
michael@0 | 138 | border: 3px solid black; |
michael@0 | 139 | padding: 10px; |
michael@0 | 140 | margin: 10px; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | |
michael@0 | 144 | span { |
michael@0 | 145 | display: inline-block; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | #iframe1 { |
michael@0 | 149 | height: 100px; |
michael@0 | 150 | margin-top: 60px; |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | #p6 { |
michael@0 | 154 | height: 50px; |
michael@0 | 155 | margin-top: 30px; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | #transf { |
michael@0 | 159 | margin-top: 60px; |
michael@0 | 160 | -moz-transform: rotate(-45deg); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | #decimal { |
michael@0 | 164 | position: relative; |
michael@0 | 165 | left: 0.5px; |
michael@0 | 166 | top: 50.5px; |
michael@0 | 167 | } |
michael@0 | 168 | </style> |
michael@0 | 169 | </head> |
michael@0 | 170 | <body id="body"> |
michael@0 | 171 | <h1 id="h1"></h1> |
michael@0 | 172 | <div id="d1"></div> |
michael@0 | 173 | |
michael@0 | 174 | <!-- floated element --> |
michael@0 | 175 | <div id="d2" style="float: left"></div> |
michael@0 | 176 | |
michael@0 | 177 | <!-- hidden element --> |
michael@0 | 178 | <p id="p1" style="float: left; visibility: hidden"></p> |
michael@0 | 179 | |
michael@0 | 180 | <p id="p2" style="clear: left"><span id="span"></span></p> |
michael@0 | 181 | |
michael@0 | 182 | <!-- absolute position --> |
michael@0 | 183 | <p id="p3" style="position:absolute; top: 10px; left:50px; height:50px;"></p> |
michael@0 | 184 | |
michael@0 | 185 | <!-- fixed position --> |
michael@0 | 186 | <p id="p4" style="position: fixed; top: 30px; left: 150px; height: 50px; background-color: blue;"></p> |
michael@0 | 187 | |
michael@0 | 188 | <!-- relative position --> |
michael@0 | 189 | <p id="p5" style="position:relative; top: -100px; left: 30px; margin-bottom: -70px; background-color: green"></p> |
michael@0 | 190 | |
michael@0 | 191 | <!-- decimal CSS pixels --> |
michael@0 | 192 | <div id="decimal"></div> |
michael@0 | 193 | |
michael@0 | 194 | <iframe id="iframe1" src="data:text/html,<div>div</div><p>p</p>"></iframe> |
michael@0 | 195 | |
michael@0 | 196 | <p id="p6"><a href="#" id="a1">A</a> / <a href="#" id="a2">A</a><br/><a href="#" id="a3">A</a></p> |
michael@0 | 197 | |
michael@0 | 198 | <div id="transf">text</div> |
michael@0 | 199 | </body> |
michael@0 | 200 | </html> |