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 id="html" style="height:100%"> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=780847 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test radii for mouse events</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | <style> |
michael@0 | 12 | .target { position:absolute; left:100px; top:100px; width:100px; height:100px; background:blue; } |
michael@0 | 13 | </style> |
michael@0 | 14 | </head> |
michael@0 | 15 | <body id="body" onload="setTimeout(startTest, 0)" style="margin:0; width:100%; height:100%; overflow:hidden"> |
michael@0 | 16 | <p id="display"></p> |
michael@0 | 17 | <div id="content"> |
michael@0 | 18 | <div id="ruler" style="position:absolute; left:0; top:0; width:1mozmm; height:0;"></div> |
michael@0 | 19 | |
michael@0 | 20 | <div class="target" id="t" onmousedown="x=1"></div> |
michael@0 | 21 | |
michael@0 | 22 | <div class="target" id="t2" hidden></div> |
michael@0 | 23 | |
michael@0 | 24 | <input class="target" id="t3_1" hidden></input> |
michael@0 | 25 | <a href="#" class="target" id="t3_2" hidden></a> |
michael@0 | 26 | <label class="target" id="t3_3" hidden></label> |
michael@0 | 27 | <button class="target" id="t3_4" hidden></button> |
michael@0 | 28 | <select class="target" id="t3_5" hidden></select> |
michael@0 | 29 | <textarea class="target" id="t3_6" hidden></textarea> |
michael@0 | 30 | <div role="button" class="target" id="t3_7" hidden></div> |
michael@0 | 31 | <div role="key" class="target" id="t3_8" hidden></div> |
michael@0 | 32 | <img class="target" id="t3_9" hidden></img> |
michael@0 | 33 | |
michael@0 | 34 | <div class="target" style="transform:translate(-80px,0);" id="t4" onmousedown="x=1" hidden></div> |
michael@0 | 35 | |
michael@0 | 36 | <div class="target" style="left:0; z-index:1" id="t5_left" onmousedown="x=1" hidden></div> |
michael@0 | 37 | <div class="target" style="left:106px;" id="t5_right" onmousedown="x=1" hidden></div> |
michael@0 | 38 | <div class="target" style="left:0; top:210px;" id="t5_below" onmousedown="x=1" hidden></div> |
michael@0 | 39 | |
michael@0 | 40 | <div class="target" id="t6" onmousedown="x=1" hidden> |
michael@0 | 41 | <div id="t6_inner" style="position:absolute; left:-20px; top:20px; width:60px; height:60px; background:yellow;"></div> |
michael@0 | 42 | </div> |
michael@0 | 43 | |
michael@0 | 44 | <div class="target" id="t7" onmousedown="x=1" hidden></div> |
michael@0 | 45 | <div class="target" id="t7_over" hidden></div> |
michael@0 | 46 | |
michael@0 | 47 | <div id="t8" contenteditable="true" class="target" hidden></div> |
michael@0 | 48 | |
michael@0 | 49 | <div id="t9" class="target" ontouchend="x=1" hidden></div> |
michael@0 | 50 | |
michael@0 | 51 | <div id="t10_left" class="target" style="left:-50px;" onmousedown="x=1" hidden></div> |
michael@0 | 52 | <div id="t10_right" class="target" style="left:auto;right:-50px" onmousedown="x=1" hidden></div> |
michael@0 | 53 | <div id="t10_top" class="target" style="top:-50px;" onmousedown="x=1" hidden></div> |
michael@0 | 54 | <div id="t10_bottom" class="target" style="top:auto;bottom:-50px;" onmousedown="x=1" hidden></div> |
michael@0 | 55 | <div id="t10_over" style="position:absolute; left:0; top:0; width:100%; height:100%; background:yellow;" hidden></div> |
michael@0 | 56 | </div> |
michael@0 | 57 | <pre id="test"> |
michael@0 | 58 | <script type="application/javascript"> |
michael@0 | 59 | function startTest() { |
michael@0 | 60 | SpecialPowers.pushPrefEnv({"set": [["ui.mouse.radius.enabled", true], |
michael@0 | 61 | ["ui.mouse.radius.inputSource.touchOnly", false], |
michael@0 | 62 | ["ui.mouse.radius.leftmm", 12], |
michael@0 | 63 | ["ui.mouse.radius.topmm", 8], |
michael@0 | 64 | ["ui.mouse.radius.rightmm", 4], |
michael@0 | 65 | ["ui.mouse.radius.bottommm", 4], |
michael@0 | 66 | ["ui.mouse.radius.visitedweight", 50]]}, runTest); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | |
michael@0 | 70 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 71 | |
michael@0 | 72 | function endTest() { |
michael@0 | 73 | SimpleTest.finish(); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | var eventTarget; |
michael@0 | 77 | window.onmousedown = function(event) { eventTarget = event.target; }; |
michael@0 | 78 | |
michael@0 | 79 | function testMouseClick(idPosition, dx, dy, idTarget, msg, options) { |
michael@0 | 80 | eventTarget = null; |
michael@0 | 81 | synthesizeMouse(document.getElementById(idPosition), dx, dy, options || {}); |
michael@0 | 82 | try { |
michael@0 | 83 | is(eventTarget.id, idTarget, |
michael@0 | 84 | "checking '" + idPosition + "' offset " + dx + "," + dy + " [" + msg + "]"); |
michael@0 | 85 | } catch (ex) { |
michael@0 | 86 | ok(false, "checking '" + idPosition + "' offset " + dx + "," + dy + " [" + msg + "]; got " + eventTarget); |
michael@0 | 87 | } |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function setShowing(id, show) { |
michael@0 | 91 | var e = document.getElementById(id); |
michael@0 | 92 | e.hidden = !show; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | var mm; |
michael@0 | 96 | function runTest() { |
michael@0 | 97 | mm = document.getElementById("ruler").getBoundingClientRect().width; |
michael@0 | 98 | ok(4*mm >= 10, "WARNING: mm " + mm + " too small in this configuration. Test results will be bogus"); |
michael@0 | 99 | |
michael@0 | 100 | // Test basic functionality: clicks sufficiently close to the element |
michael@0 | 101 | // should be allowed to hit the element. We test points just inside and |
michael@0 | 102 | // just outside the edges we set up in the prefs. |
michael@0 | 103 | testMouseClick("t", 100 + 13*mm, 10, "body", "basic functionality"); |
michael@0 | 104 | testMouseClick("t", 100 + 11*mm, 10, "t", "basic functionality"); |
michael@0 | 105 | testMouseClick("t", 10, 100 + 9*mm, "body", "basic functionality"); |
michael@0 | 106 | testMouseClick("t", 10, 100 + 7*mm, "t", "basic functionality"); |
michael@0 | 107 | testMouseClick("t", -5*mm, 10, "body", "basic functionality"); |
michael@0 | 108 | testMouseClick("t", -3*mm, 10, "t", "basic functionality"); |
michael@0 | 109 | testMouseClick("t", 10, -5*mm, "body", "basic functionality"); |
michael@0 | 110 | testMouseClick("t", 10, -3*mm, "t", "basic functionality"); |
michael@0 | 111 | |
michael@0 | 112 | // When inputSource.touchOnly is true, mouse input is not retargeted. |
michael@0 | 113 | SpecialPowers.pushPrefEnv({"set": [["ui.mouse.radius.inputSource.touchOnly", true]]}, test2); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function test2() { |
michael@0 | 117 | testMouseClick("t", 100 + 11*mm, 10, "body", "disabled for mouse input"); |
michael@0 | 118 | testMouseClick("t", 100 + 11*mm, 10, "t", "enabled for touch input", { |
michael@0 | 119 | inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH |
michael@0 | 120 | }); |
michael@0 | 121 | testMouseClick("t", 100 + 13*mm, 10, "body", "basic functionality for touch", { |
michael@0 | 122 | inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH |
michael@0 | 123 | }); |
michael@0 | 124 | SpecialPowers.pushPrefEnv({"set": [["ui.mouse.radius.inputSource.touchOnly", false]]}, test3); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | function test3() { |
michael@0 | 128 | setShowing("t", false); |
michael@0 | 129 | |
michael@0 | 130 | // Now test the criteria we use to determine which elements are hittable |
michael@0 | 131 | // this way. |
michael@0 | 132 | |
michael@0 | 133 | setShowing("t2", true); |
michael@0 | 134 | var t2 = document.getElementById("t2"); |
michael@0 | 135 | // Unadorned DIVs are not click radius targets |
michael@0 | 136 | testMouseClick("t2", 100 + 11*mm, 10, "body", "unadorned DIV"); |
michael@0 | 137 | // DIVs with the right event handlers are click radius targets |
michael@0 | 138 | t2.onmousedown = function() {}; |
michael@0 | 139 | testMouseClick("t2", 100 + 11*mm, 10, "t2", "DIV with onmousedown"); |
michael@0 | 140 | t2.onmousedown = null; |
michael@0 | 141 | testMouseClick("t2", 100 + 11*mm, 10, "body", "DIV with onmousedown removed"); |
michael@0 | 142 | t2.onmouseup = function() {}; |
michael@0 | 143 | testMouseClick("t2", 100 + 11*mm, 10, "t2", "DIV with onmouseup"); |
michael@0 | 144 | t2.onmouseup = null; |
michael@0 | 145 | t2.onclick = function() {}; |
michael@0 | 146 | testMouseClick("t2", 100 + 11*mm, 10, "t2", "DIV with onclick"); |
michael@0 | 147 | t2.onclick = null; |
michael@0 | 148 | // Keypresses don't make click radius targets |
michael@0 | 149 | t2.onkeypress = function() {}; |
michael@0 | 150 | testMouseClick("t2", 100 + 11*mm, 10, "body", "DIV with onkeypress"); |
michael@0 | 151 | t2.onkeypress = null; |
michael@0 | 152 | setShowing("t2", false); |
michael@0 | 153 | |
michael@0 | 154 | // Now check that certain elements are click radius targets and others are not |
michael@0 | 155 | for (var i = 1; i <= 9; ++i) { |
michael@0 | 156 | var id = "t3_" + i; |
michael@0 | 157 | var shouldHit = i <= 8; |
michael@0 | 158 | setShowing(id, true); |
michael@0 | 159 | testMouseClick(id, 100 + 11*mm, 10, shouldHit ? id : "body", |
michael@0 | 160 | "<" + document.getElementById(id).tagName + "> element"); |
michael@0 | 161 | setShowing(id, false); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | // Check that our targeting computations take into account the effects of |
michael@0 | 165 | // CSS transforms |
michael@0 | 166 | setShowing("t4", true); |
michael@0 | 167 | testMouseClick("t4", -1, 10, "t4", "translated DIV"); |
michael@0 | 168 | setShowing("t4", false); |
michael@0 | 169 | |
michael@0 | 170 | // Test the prioritization of multiple targets based on distance to |
michael@0 | 171 | // the target. |
michael@0 | 172 | setShowing("t5_left", true); |
michael@0 | 173 | setShowing("t5_right", true); |
michael@0 | 174 | setShowing("t5_below", true); |
michael@0 | 175 | testMouseClick("t5_left", 102, 10, "t5_left", "closest DIV is left"); |
michael@0 | 176 | testMouseClick("t5_left", 102.5, 10, "t5_left", |
michael@0 | 177 | "closest DIV to midpoint is left because of its higher z-index"); |
michael@0 | 178 | testMouseClick("t5_left", 104, 10, "t5_right", "closest DIV is right"); |
michael@0 | 179 | testMouseClick("t5_left", 10, 104, "t5_left", "closest DIV is left"); |
michael@0 | 180 | testMouseClick("t5_left", 10, 105, "t5_left", |
michael@0 | 181 | "closest DIV to midpoint is left because of its higher z-index"); |
michael@0 | 182 | testMouseClick("t5_left", 10, 106, "t5_below", "closest DIV is below"); |
michael@0 | 183 | setShowing("t5_left", false); |
michael@0 | 184 | setShowing("t5_right", false); |
michael@0 | 185 | setShowing("t5_below", false); |
michael@0 | 186 | |
michael@0 | 187 | // Test behavior of nested elements. |
michael@0 | 188 | // The following behaviors are questionable and may need to be changed. |
michael@0 | 189 | setShowing("t6", true); |
michael@0 | 190 | testMouseClick("t6_inner", -1, 10, "t6_inner", |
michael@0 | 191 | "inner element is clickable because its parent is, even when it sticks outside parent"); |
michael@0 | 192 | testMouseClick("t6_inner", 19, -1, "t6_inner", |
michael@0 | 193 | "when outside both inner and parent, but in range of both, the inner is selected"); |
michael@0 | 194 | testMouseClick("t6_inner", 25, -1, "t6", |
michael@0 | 195 | "clicking in clickable parent close to inner activates parent, not inner"); |
michael@0 | 196 | setShowing("t6", false); |
michael@0 | 197 | |
michael@0 | 198 | setShowing("t7", true); |
michael@0 | 199 | setShowing("t7_over", true); |
michael@0 | 200 | testMouseClick("t7", 100 + 11*mm, 10, "body", "covered div is not clickable"); |
michael@0 | 201 | testMouseClick("t7", 10, 10, "t7_over", "covered div is not clickable even within its bounds"); |
michael@0 | 202 | setShowing("t7", false); |
michael@0 | 203 | setShowing("t7_over", false); |
michael@0 | 204 | |
michael@0 | 205 | // Check that contenteditable elements are considered clickable for fluffing. |
michael@0 | 206 | setShowing("t8", true); |
michael@0 | 207 | var rect = document.getElementById("t8").getBoundingClientRect(); |
michael@0 | 208 | testMouseClick("t8", rect.left + 1, rect.top + 1, "t8", "content editable enabled for mouse input"); |
michael@0 | 209 | testMouseClick("t8", rect.left + 1, rect.top + 1, "t8", "content editable enabled for touch input", { |
michael@0 | 210 | inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH |
michael@0 | 211 | }); |
michael@0 | 212 | setShowing("t8", false); |
michael@0 | 213 | |
michael@0 | 214 | // Check that elements are touchable |
michael@0 | 215 | setShowing("t9", true); |
michael@0 | 216 | var rect = document.getElementById("t9").getBoundingClientRect(); |
michael@0 | 217 | testMouseClick("t9", rect.left + 1, rect.top + 1, "t9", "div enabled with mouse input"); |
michael@0 | 218 | testMouseClick("t9", rect.left + 1, rect.top + 1, "t9", "div enabled with touch input", { |
michael@0 | 219 | inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH |
michael@0 | 220 | }); |
michael@0 | 221 | setShowing("t9", false); |
michael@0 | 222 | |
michael@0 | 223 | setShowing("t10_over", true); |
michael@0 | 224 | setShowing("t10_left", true); |
michael@0 | 225 | setShowing("t10_right", true); |
michael@0 | 226 | setShowing("t10_top", true); |
michael@0 | 227 | setShowing("t10_bottom", true); |
michael@0 | 228 | testMouseClick("t10_left", 51, 10, "t10_over", "element outside of visible area is not selected"); |
michael@0 | 229 | if (self.frameElement && |
michael@0 | 230 | (self.frameElement.offsetLeft + self.innerWidth > |
michael@0 | 231 | SpecialPowers.wrap(top).innerWidth)) { |
michael@0 | 232 | info("WARNING: Window is too narrow, can't test t10_right"); |
michael@0 | 233 | } else { |
michael@0 | 234 | testMouseClick("t10_right", 49, 10, "t10_over", "element outside of visible area is not selected"); |
michael@0 | 235 | } |
michael@0 | 236 | testMouseClick("t10_top", 10, 51, "t10_over", "element outside of visible area is not selected"); |
michael@0 | 237 | if (self.frameElement && |
michael@0 | 238 | (self.frameElement.offsetTop + self.innerHeight > |
michael@0 | 239 | SpecialPowers.wrap(top).innerHeight)) { |
michael@0 | 240 | info("WARNING: Window is too short, can't test t10_bottom"); |
michael@0 | 241 | } else { |
michael@0 | 242 | testMouseClick("t10_bottom", 10, 49, "t10_over", "element outside of visible area is not selected"); |
michael@0 | 243 | } |
michael@0 | 244 | setShowing("t10_over", false); |
michael@0 | 245 | setShowing("t10_left", false); |
michael@0 | 246 | setShowing("t10_right", false); |
michael@0 | 247 | setShowing("t10_top", false); |
michael@0 | 248 | setShowing("t10_bottom", false); |
michael@0 | 249 | |
michael@0 | 250 | // Not yet tested: |
michael@0 | 251 | // -- visited link weight |
michael@0 | 252 | // -- "Closest" using Euclidean distance |
michael@0 | 253 | endTest(); |
michael@0 | 254 | } |
michael@0 | 255 | </script> |
michael@0 | 256 | </pre> |
michael@0 | 257 | </body> |
michael@0 | 258 | </html> |