toolkit/content/tests/chrome/test_mousecapture.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4
michael@0 5 <window title="Mouse Capture Tests" align="start"
michael@0 6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 7
michael@0 8 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 10
michael@0 11 <script>
michael@0 12 <![CDATA[
michael@0 13
michael@0 14 SimpleTest.expectAssertions(6);
michael@0 15
michael@0 16 SimpleTest.waitForExplicitFinish();
michael@0 17
michael@0 18 var captureRetargetMode = false;
michael@0 19 var cachedMouseDown = null;
michael@0 20 var previousWidth = 0, originalWidth = 0;
michael@0 21 var loadInWindow = false;
michael@0 22
michael@0 23 function splitterCallback(adjustment)
michael@0 24 {
michael@0 25 var newWidth = Number($("leftbox").width); // getBoundingClientRect().width;
michael@0 26 var expectedWidth = previousWidth + adjustment;
michael@0 27 if (expectedWidth > $("splitterbox").getBoundingClientRect().width)
michael@0 28 expectedWidth = $("splitterbox").getBoundingClientRect().width - $("splitter").getBoundingClientRect().width;
michael@0 29 is(newWidth, expectedWidth, "splitter left box size (" + adjustment + ")");
michael@0 30 previousWidth = newWidth;
michael@0 31 }
michael@0 32
michael@0 33 function selectionCallback(adjustment)
michael@0 34 {
michael@0 35 if (adjustment == 4000) {
michael@0 36 is(frames[0].getSelection().toString(), "This is some text", "selection after drag (" + adjustment + ")");
michael@0 37 ok(frames[0].scrollY > 40, "selection caused scroll down (" + adjustment + ")");
michael@0 38 }
michael@0 39 else {
michael@0 40 if (adjustment == 0) {
michael@0 41 is(frames[0].getSelection().toString(), ".", "selection after drag (" + adjustment + ")");
michael@0 42 }
michael@0 43 is(frames[0].scrollY, 0, "selection scrollY (" + adjustment + ")");
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 function framesetCallback(adjustment)
michael@0 48 {
michael@0 49 var newWidth = frames[1].frames[0].document.documentElement.clientWidth;
michael@0 50 var expectedWidth = originalWidth + adjustment;
michael@0 51 if (adjustment == 0)
michael@0 52 expectedWidth = originalWidth - 12;
michael@0 53 else if (expectedWidth >= 4000)
michael@0 54 expectedWidth = originalWidth * 2 - 2;
michael@0 55
michael@0 56 is(newWidth, expectedWidth, "frameset after drag (" + adjustment + ")");
michael@0 57 }
michael@0 58
michael@0 59 var otherWindow = null;
michael@0 60
michael@0 61 function selectionScrollCheck()
michael@0 62 {
michael@0 63 var element = otherWindow.document.documentElement;
michael@0 64
michael@0 65 var count = 0;
michael@0 66 function selectionScrollDone() {
michael@0 67 // wait for 6 scroll events to occur
michael@0 68 if (count++ < 6)
michael@0 69 return;
michael@0 70
michael@0 71 otherWindow.removeEventListener("scroll", selectionScrollDone, false);
michael@0 72
michael@0 73 var selectedText = otherWindow.getSelection().toString().replace(/\r/g, "");
michael@0 74 is(selectedText, "One\n\nTwo", "text is selected");
michael@0 75
michael@0 76 // should have scrolled 20 pixels from the mousemove above and six extra
michael@0 77 // times from the selection scroll timer for a total of 140
michael@0 78 var oldScrollY = otherWindow.scrollY;
michael@0 79 is(otherWindow.scrollY, 140, "selection scroll position after timer");
michael@0 80
michael@0 81 synthesizeMouse(element, 4, otherWindow.innerHeight + 25, { type: "mouseup" }, otherWindow);
michael@0 82 disableNonTestMouseEvents(false);
michael@0 83 otherWindow.close();
michael@0 84
michael@0 85 if (loadInWindow) {
michael@0 86 SimpleTest.finish();
michael@0 87 }
michael@0 88 else {
michael@0 89 // now try again, but open the page in a new window
michael@0 90 loadInWindow = true;
michael@0 91 synthesizeMouse(document.getElementById("custom"), 2, 2, { type: "mousedown" });
michael@0 92
michael@0 93 // check to ensure that selection dragging scrolls the right scrollable area
michael@0 94 otherWindow = window.open("data:text/html,<html><p>One</p><p style='margin-top: 200px;'>Two</p><p style='margin-top: 4000px'>This is some text</p></html>", "_blank", "width=200,height=200,scrollbars=yes");
michael@0 95 otherWindow.addEventListener("load", function() { SimpleTest.waitForFocus(selectionScrollCheck, otherWindow); }, false);
michael@0 96 }
michael@0 97 }
michael@0 98
michael@0 99 SimpleTest.executeSoon(function () {
michael@0 100 disableNonTestMouseEvents(true);
michael@0 101 synthesizeMouse(element, 2, 2, { type: "mousedown" }, otherWindow);
michael@0 102 synthesizeMouse(element, 100, otherWindow.innerHeight + 20, { type: "mousemove" }, otherWindow);
michael@0 103 otherWindow.addEventListener("scroll", selectionScrollDone, false);
michael@0 104 });
michael@0 105 }
michael@0 106
michael@0 107 function runTests()
michael@0 108 {
michael@0 109 previousWidth = $("leftbox").getBoundingClientRect().width;
michael@0 110 runCaptureTest($("splitter"), splitterCallback);
michael@0 111
michael@0 112 var custom = document.getElementById("custom");
michael@0 113 runCaptureTest(custom);
michael@0 114
michael@0 115 synthesizeMouseExpectEvent($("rightbox"), 2, 2, { type: "mousemove" },
michael@0 116 $("rightbox"), "mousemove", "setCapture and releaseCapture");
michael@0 117
michael@0 118 custom.setCapture();
michael@0 119 synthesizeMouseExpectEvent($("leftbox"), 2, 2, { type: "mousemove" },
michael@0 120 $("leftbox"), "mousemove", "setCapture fails on non mousedown");
michael@0 121
michael@0 122 var custom2 = document.getElementById("custom2");
michael@0 123 synthesizeMouse(custom2, 2, 2, { type: "mousedown" });
michael@0 124 synthesizeMouseExpectEvent($("leftbox"), 2, 2, { type: "mousemove" },
michael@0 125 $("leftbox"), "mousemove", "document.releaseCapture releases capture");
michael@0 126
michael@0 127 var custom3 = document.getElementById("custom3");
michael@0 128 synthesizeMouse(custom3, 2, 2, { type: "mousedown" });
michael@0 129 synthesizeMouseExpectEvent($("leftbox"), 2, 2, { type: "mousemove" },
michael@0 130 $("leftbox"), "mousemove", "element.releaseCapture releases capture");
michael@0 131
michael@0 132 var custom4 = document.getElementById("custom4");
michael@0 133 synthesizeMouse(custom4, 2, 2, { type: "mousedown" });
michael@0 134 synthesizeMouseExpectEvent($("leftbox"), 2, 2, { type: "mousemove" },
michael@0 135 custom4, "mousemove", "element.releaseCapture during mousemove before releaseCapture");
michael@0 136 synthesizeMouseExpectEvent($("leftbox"), 2, 2, { type: "mousemove" },
michael@0 137 $("leftbox"), "mousemove", "element.releaseCapture during mousemove after releaseCapture");
michael@0 138
michael@0 139 var custom5 = document.getElementById("custom5");
michael@0 140 runCaptureTest(custom5);
michael@0 141 captureRetargetMode = true;
michael@0 142 runCaptureTest(custom5);
michael@0 143 captureRetargetMode = false;
michael@0 144
michael@0 145 var custom6 = document.getElementById("custom6");
michael@0 146 synthesizeMouse(custom6, 2, 2, { type: "mousedown" });
michael@0 147 synthesizeMouseExpectEvent($("leftbox"), 2, 2, { type: "mousemove" },
michael@0 148 $("leftbox"), "mousemove", "setCapture only works on elements in documents");
michael@0 149 synthesizeMouse(custom6, 2, 2, { type: "mouseup" });
michael@0 150
michael@0 151 // test that mousedown on an image with setCapture followed by a big enough
michael@0 152 // mouse move does not start a drag (bug 517737)
michael@0 153 var image = document.getElementById("image");
michael@0 154 synthesizeMouse(image, 2, 2, { type: "mousedown" });
michael@0 155 synthesizeMouseExpectEvent($("leftbox"), 2, 2, { type: "mousemove" },
michael@0 156 image, "mousemove", "setCapture works on images");
michael@0 157 synthesizeMouse(image, 2, 2, { type: "mouseup" });
michael@0 158
michael@0 159 // save scroll
michael@0 160 var scrollX = parent ? parent.scrollX : 0;
michael@0 161 var scrollY = parent ? parent.scrollY : 0;
michael@0 162
michael@0 163 var b = frames[0].document.getElementById("b");
michael@0 164 // runCaptureTest(b, selectionCallback);
michael@0 165
michael@0 166 // restore scroll
michael@0 167 if (parent) parent.scroll(scrollX, scrollY);
michael@0 168
michael@0 169 // frames[0].getSelection().collapseToStart();
michael@0 170
michael@0 171 var body = frames[0].document.body;
michael@0 172 var fixed = frames[0].document.getElementById("fixed");
michael@0 173 function captureOnBody() { body.setCapture() }
michael@0 174 body.addEventListener("mousedown", captureOnBody, true);
michael@0 175 synthesizeMouse(body, 8, 8, { type: "mousedown" }, frames[0]);
michael@0 176 body.removeEventListener("mousedown", captureOnBody, true);
michael@0 177 synthesizeMouseExpectEvent(fixed, 2, 2, { type: "mousemove" },
michael@0 178 fixed, "mousemove", "setCapture on body retargets to root node", frames[0]);
michael@0 179 synthesizeMouse(body, 8, 8, { type: "mouseup" }, frames[0]);
michael@0 180
michael@0 181 previousWidth = frames[1].frames[0].document.documentElement.clientWidth;
michael@0 182 originalWidth = previousWidth;
michael@0 183 runCaptureTest(frames[1].document.documentElement.lastChild, framesetCallback);
michael@0 184
michael@0 185 // ensure that clicking on an element where the frame disappears doesn't crash
michael@0 186 synthesizeMouse(frames[2].document.getElementById("input"), 8, 8, { type: "mousedown" }, frames[2]);
michael@0 187 synthesizeMouse(frames[2].document.getElementById("input"), 8, 8, { type: "mouseup" }, frames[2]);
michael@0 188
michael@0 189 synthesizeMouse(document.getElementById("option3"), 2, 2, { type: "mousedown" });
michael@0 190 synthesizeMouse(document.getElementById("option3"), 2, 1000, { type: "mousemove" });
michael@0 191 var select = document.getElementById("select");
michael@0 192 is(select.selectedIndex, 9, "scroll select");
michael@0 193 synthesizeMouse(document.getElementById("select"), 2, 2, { type: "mouseup" });
michael@0 194
michael@0 195 synthesizeMouse(custom, 2, 2, { type: "mousedown" });
michael@0 196
michael@0 197 // check to ensure that selection dragging scrolls the right scrollable area.
michael@0 198 // This should open the page in a new tab.
michael@0 199
michael@0 200 var topPos = window.innerHeight;
michael@0 201 otherWindow = window.open("data:text/html,<html><p>One</p><p style='margin-top: " + topPos + "'>Two</p><p style='margin-top: 4000px'>This is some text</p></html>", "_blank");
michael@0 202 otherWindow.addEventListener("load", function() { SimpleTest.waitForFocus(selectionScrollCheck, otherWindow); }, false);
michael@0 203 }
michael@0 204
michael@0 205 function runCaptureTest(element, callback)
michael@0 206 {
michael@0 207 var expectedTarget = null;
michael@0 208
michael@0 209 var win = element.ownerDocument.defaultView;
michael@0 210
michael@0 211 function mouseMoved(event) {
michael@0 212 is(event.originalTarget, expectedTarget,
michael@0 213 expectedTarget.id + " target for point " + event.clientX + "," + event.clientY);
michael@0 214 }
michael@0 215 win.addEventListener("mousemove", mouseMoved, false);
michael@0 216
michael@0 217 expectedTarget = element;
michael@0 218
michael@0 219 var basepoint = element.localName == "frameset" ? 50 : 2;
michael@0 220 synthesizeMouse(element, basepoint, basepoint, { type: "mousedown" }, win);
michael@0 221
michael@0 222 // in setCapture(true) mode, all events should fire on custom5. In
michael@0 223 // setCapture(false) mode, events can fire at a descendant
michael@0 224 if (expectedTarget == $("custom5") && !captureRetargetMode)
michael@0 225 expectedTarget = $("custom5spacer");
michael@0 226
michael@0 227 // releaseCapture should do nothing for an element which isn't capturing
michael@0 228 $("splitterbox").releaseCapture();
michael@0 229
michael@0 230 synthesizeMouse(element, basepoint + 2, basepoint + 2, { type: "mousemove" }, win);
michael@0 231 if (callback)
michael@0 232 callback(2);
michael@0 233
michael@0 234 if (expectedTarget == $("custom5spacer") && !captureRetargetMode)
michael@0 235 expectedTarget = $("custom5inner");
michael@0 236
michael@0 237 if (element.id == "b") {
michael@0 238 var tooltip = document.getElementById("tooltip");
michael@0 239 tooltip.openPopup();
michael@0 240 tooltip.hidePopup();
michael@0 241 }
michael@0 242
michael@0 243 synthesizeMouse(element, basepoint + 25, basepoint + 25, { type: "mousemove" }, win);
michael@0 244 if (callback)
michael@0 245 callback(25);
michael@0 246
michael@0 247 expectedTarget = element.localName == "b" ? win.document.documentElement : element;
michael@0 248 synthesizeMouse(element, basepoint + 4000, basepoint + 4000, { type: "mousemove" }, win);
michael@0 249 if (callback)
michael@0 250 callback(4000);
michael@0 251 synthesizeMouse(element, basepoint - 12, basepoint - 12, { type: "mousemove" }, win);
michael@0 252 if (callback)
michael@0 253 callback(-12);
michael@0 254
michael@0 255 expectedTarget = element.localName == "frameset" ? element : win.document.documentElement;
michael@0 256 synthesizeMouse(element, basepoint + 30, basepoint + 30, { type: "mouseup" }, win);
michael@0 257 synthesizeMouse(win.document.documentElement, 2, 2, { type: "mousemove" }, win);
michael@0 258 if (callback)
michael@0 259 callback(0);
michael@0 260
michael@0 261 win.removeEventListener("mousemove", mouseMoved, false);
michael@0 262 }
michael@0 263
michael@0 264 SimpleTest.waitForFocus(runTests);
michael@0 265
michael@0 266 ]]>
michael@0 267 </script>
michael@0 268
michael@0 269 <tooltip id="tooltip">
michael@0 270 <label value="Test"/>
michael@0 271 </tooltip>
michael@0 272
michael@0 273 <hbox id="splitterbox" style="margin-top: 5px;" onmousedown="this.setCapture()">
michael@0 274 <hbox id="leftbox" width="100" flex="1"/>
michael@0 275 <splitter id="splitter" height="5"/>
michael@0 276 <hbox id="rightbox" width="100" flex="1"/>
michael@0 277 </hbox>
michael@0 278
michael@0 279 <vbox id="custom" width="10" height="10" onmousedown="this.setCapture(); cachedMouseDown = event;"/>
michael@0 280 <vbox id="custom2" width="10" height="10" onmousedown="this.setCapture(); document.releaseCapture();"/>
michael@0 281 <vbox id="custom3" width="10" height="10" onmousedown="this.setCapture(); this.releaseCapture();"/>
michael@0 282 <vbox id="custom4" width="10" height="10" onmousedown="this.setCapture();"
michael@0 283 onmousemove="this.releaseCapture();"/>
michael@0 284 <hbox id="custom5" width="40" height="40"
michael@0 285 onmousedown="this.setCapture(captureRetargetMode);">
michael@0 286 <spacer id="custom5spacer" width="5"/>
michael@0 287 <hbox id="custom5inner" width="35" height="35"/>
michael@0 288 </hbox>
michael@0 289 <vbox id="custom6" width="10" height="10"
michael@0 290 onmousedown="document.createElement('hbox').setCapture();"/>
michael@0 291
michael@0 292 <hbox>
michael@0 293 <iframe width="100" height="100"
michael@0 294 src="data:text/html,%3Cbody style%3D'font-size%3A 40pt%3B'%3E.%3Cb id%3D'b'%3EThis%3C/b%3E is some text%3Cdiv id='fixed' style='position: fixed; left: 55px; top: 5px; width: 10px; height: 10px'%3E.%3C/div%3E%3C/body%3E"/>
michael@0 295
michael@0 296 <iframe width="100" height="100"
michael@0 297 src="data:text/html,%3Cframeset cols='50%, 50%'%3E%3Cframe src='about:blank'%3E%3Cframe src='about:blank'%3E%3C/frameset%3E"/>
michael@0 298
michael@0 299 <iframe width="100" height="100"
michael@0 300 src="data:text/html,%3Cinput id='input' onfocus='this.style.display = &quot;none&quot;' style='float: left;'>"/>
michael@0 301
michael@0 302 <select id="select" xmlns="http://www.w3.org/1999/xhtml" size="4">
michael@0 303 <option id="option1">One</option>
michael@0 304 <option id="option2">Two</option>
michael@0 305 <option id="option3">Three</option>
michael@0 306 <option id="option4">Four</option>
michael@0 307 <option id="option5">Five</option>
michael@0 308 <option id="option6">Six</option>
michael@0 309 <option id="option7">Seven</option>
michael@0 310 <option id="option8">Eight</option>
michael@0 311 <option id="option9">Nine</option>
michael@0 312 <option id="option10">Ten</option>
michael@0 313 </select>
michael@0 314 </hbox>
michael@0 315
michael@0 316 <hbox>
michael@0 317 <img id="image" xmlns="http://www.w3.org/1999/xhtml"
michael@0 318 onmousedown="this.setCapture();" onmouseup="this.releaseCapture();"
michael@0 319 ondragstart="ok(false, 'should not get a drag when a setCapture is active');"
michael@0 320 src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAG0lEQVR42mP8z0A%2BYKJA76jmUc2jmkc1U0EzACKcASfOgGoMAAAAAElFTkSuQmCC"/>
michael@0 321 </hbox>
michael@0 322
michael@0 323 <body id="body" xmlns="http://www.w3.org/1999/xhtml">
michael@0 324 <p id="display"/><div id="content" style="display: none"/><pre id="test"/>
michael@0 325 </body>
michael@0 326
michael@0 327 </window>

mercurial