Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | |
michael@0 | 3 | <!-- This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | - License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
michael@0 | 6 | |
michael@0 | 7 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 8 | |
michael@0 | 9 | <window id="NativeMenuWindow" |
michael@0 | 10 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 11 | xmlns:html="http://www.w3.org/1999/xhtml" |
michael@0 | 12 | width="600" |
michael@0 | 13 | height="600" |
michael@0 | 14 | title="Native Mouse Event Test" |
michael@0 | 15 | orient="vertical"> |
michael@0 | 16 | <script type="application/javascript" |
michael@0 | 17 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> |
michael@0 | 18 | |
michael@0 | 19 | <box height="200" id="box"/> |
michael@0 | 20 | <menupopup id="popup" width="250" height="50"/> |
michael@0 | 21 | <panel id="panel" width="250" height="50" noautohide="true"/> |
michael@0 | 22 | |
michael@0 | 23 | <script type="application/javascript"><![CDATA[ |
michael@0 | 24 | |
michael@0 | 25 | function ok(condition, message) { |
michael@0 | 26 | window.opener.wrappedJSObject.SimpleTest.ok(condition, message); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function is(a, b, message) { |
michael@0 | 30 | window.opener.wrappedJSObject.SimpleTest.is(a, b, message); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function todo(condition, message) { |
michael@0 | 34 | window.opener.wrappedJSObject.SimpleTest.todo(condition, message); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function todo_is(a, b, message) { |
michael@0 | 38 | window.opener.wrappedJSObject.SimpleTest.todo_is(a, b, message); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function onTestsFinished() { |
michael@0 | 42 | clearTimeout(gAfterLoopExecution); |
michael@0 | 43 | observe(window, eventMonitor, false); |
michael@0 | 44 | observe(gRightWindow, eventMonitor, false); |
michael@0 | 45 | observe(gPopup, eventMonitor, false); |
michael@0 | 46 | gRightWindow.close(); |
michael@0 | 47 | var openerSimpleTest = window.opener.wrappedJSObject.SimpleTest; |
michael@0 | 48 | window.close(); |
michael@0 | 49 | openerSimpleTest.finish(); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; |
michael@0 | 53 | const xulWin = 'data:application/vnd.mozilla.xul+xml,<?xml version="1.0"?><?xml-stylesheet href="chrome://global/skin" type="text/css"?><window xmlns="' + XUL_NS + '"/>'; |
michael@0 | 54 | |
michael@0 | 55 | const NSLeftMouseDown = 1, |
michael@0 | 56 | NSLeftMouseUp = 2, |
michael@0 | 57 | NSRightMouseDown = 3, |
michael@0 | 58 | NSRightMouseUp = 4, |
michael@0 | 59 | NSMouseMoved = 5, |
michael@0 | 60 | NSLeftMouseDragged = 6, |
michael@0 | 61 | NSRightMouseDragged = 7, |
michael@0 | 62 | NSMouseEntered = 8, |
michael@0 | 63 | NSMouseExited = 9, |
michael@0 | 64 | NSKeyDown = 10, |
michael@0 | 65 | NSKeyUp = 11, |
michael@0 | 66 | NSFlagsChanged = 12, |
michael@0 | 67 | NSAppKitDefined = 13, |
michael@0 | 68 | NSSystemDefined = 14, |
michael@0 | 69 | NSApplicationDefined = 15, |
michael@0 | 70 | NSPeriodic = 16, |
michael@0 | 71 | NSCursorUpdate = 17, |
michael@0 | 72 | NSScrollWheel = 22, |
michael@0 | 73 | NSTabletPoint = 23, |
michael@0 | 74 | NSTabletProximity = 24, |
michael@0 | 75 | NSOtherMouseDown = 25, |
michael@0 | 76 | NSOtherMouseUp = 26, |
michael@0 | 77 | NSOtherMouseDragged = 27, |
michael@0 | 78 | NSEventTypeGesture = 29, |
michael@0 | 79 | NSEventTypeMagnify = 30, |
michael@0 | 80 | NSEventTypeSwipe = 31, |
michael@0 | 81 | NSEventTypeRotate = 18, |
michael@0 | 82 | NSEventTypeBeginGesture = 19, |
michael@0 | 83 | NSEventTypeEndGesture = 20; |
michael@0 | 84 | |
michael@0 | 85 | const NSAlphaShiftKeyMask = 1 << 16, |
michael@0 | 86 | NSShiftKeyMask = 1 << 17, |
michael@0 | 87 | NSControlKeyMask = 1 << 18, |
michael@0 | 88 | NSAlternateKeyMask = 1 << 19, |
michael@0 | 89 | NSCommandKeyMask = 1 << 20, |
michael@0 | 90 | NSNumericPadKeyMask = 1 << 21, |
michael@0 | 91 | NSHelpKeyMask = 1 << 22, |
michael@0 | 92 | NSFunctionKeyMask = 1 << 23; |
michael@0 | 93 | |
michael@0 | 94 | const gDebug = false; |
michael@0 | 95 | |
michael@0 | 96 | function printDebug(msg) { if (gDebug) dump(msg); } |
michael@0 | 97 | |
michael@0 | 98 | var gExpectedEvents = []; |
michael@0 | 99 | var gRightWindow = null, gPopup = null; |
michael@0 | 100 | var gCurrentMouseX = 0, gCurrentMouseY = 0; |
michael@0 | 101 | var gAfterLoopExecution = 0; |
michael@0 | 102 | |
michael@0 | 103 | function testMouse(x, y, msg, elem, win, exp, flags, callback) { |
michael@0 | 104 | clearExpectedEvents(); |
michael@0 | 105 | var syntheticEvent = null; |
michael@0 | 106 | exp.forEach(function (expEv) { |
michael@0 | 107 | expEv.screenX = x; |
michael@0 | 108 | expEv.screenY = y; |
michael@0 | 109 | if (expEv.synthetic) { |
michael@0 | 110 | is(syntheticEvent, null, |
michael@0 | 111 | "Can't handle two synthetic events in a single testMouse call"); |
michael@0 | 112 | syntheticEvent = expEv; |
michael@0 | 113 | } |
michael@0 | 114 | gExpectedEvents.push(expEv); |
michael@0 | 115 | }); |
michael@0 | 116 | printDebug("sending event: " + x + ", " + y + " (" + msg + ")\n"); |
michael@0 | 117 | gCurrentMouseX = x; |
michael@0 | 118 | gCurrentMouseY = y; |
michael@0 | 119 | var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
michael@0 | 120 | getInterface(Components.interfaces.nsIDOMWindowUtils); |
michael@0 | 121 | var callbackFunc = function() { |
michael@0 | 122 | clearExpectedEvents(); |
michael@0 | 123 | callback(); |
michael@0 | 124 | } |
michael@0 | 125 | if (syntheticEvent) { |
michael@0 | 126 | // Set up this listener before we sendNativeMouseEvent, just |
michael@0 | 127 | // in case that synchronously calls us. |
michael@0 | 128 | eventListenOnce(syntheticEvent.target, syntheticEvent.type, |
michael@0 | 129 | // Trigger callbackFunc async, so we're not assuming |
michael@0 | 130 | // anything about how our listener gets ordered with |
michael@0 | 131 | // others. |
michael@0 | 132 | function () { SimpleTest.executeSoon(callbackFunc) }); |
michael@0 | 133 | } |
michael@0 | 134 | utils.sendNativeMouseEvent(x, y, msg, flags || 0, elem); |
michael@0 | 135 | if (!syntheticEvent) { |
michael@0 | 136 | gAfterLoopExecution = setTimeout(callbackFunc, 0); |
michael@0 | 137 | } |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | function eventListenOnce(elem, name, callback) { |
michael@0 | 141 | elem.addEventListener(name, function(e) { |
michael@0 | 142 | elem.removeEventListener(name, arguments.callee, false); |
michael@0 | 143 | callback(e); |
michael@0 | 144 | }, false); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | function focusAndThen(win, callback) { |
michael@0 | 148 | eventListenOnce(win, "focus", callback); |
michael@0 | 149 | printDebug("focusing a window\n"); |
michael@0 | 150 | win.focus(); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | function eventToString(e) { |
michael@0 | 154 | return JSON.stringify({ |
michael@0 | 155 | type: e.type, target: e.target.nodeName, screenX: e.screenX, screenY: e.screenY |
michael@0 | 156 | }); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | function clearExpectedEvents() { |
michael@0 | 160 | while (gExpectedEvents.length > 0) { |
michael@0 | 161 | var expectedEvent = gExpectedEvents.shift(); |
michael@0 | 162 | var errFun = expectedEvent.shouldFireButDoesnt ? todo : ok; |
michael@0 | 163 | errFun(false, "Didn't receive expected event: " + eventToString(expectedEvent)); |
michael@0 | 164 | } |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | var gEventNum = 0; |
michael@0 | 168 | |
michael@0 | 169 | function eventMonitor(e) { |
michael@0 | 170 | printDebug("got event: " + eventToString(e) + "\n"); |
michael@0 | 171 | processEvent(e); |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | function processEvent(e) { |
michael@0 | 175 | if (e.screenX != gCurrentMouseX || e.screenY != gCurrentMouseY) { |
michael@0 | 176 | todo(false, "Oh no! Received a stray event from a confused tracking area. Aborting test."); |
michael@0 | 177 | onTestsFinished(); |
michael@0 | 178 | return; |
michael@0 | 179 | } |
michael@0 | 180 | var expectedEvent = gExpectedEvents.shift(); |
michael@0 | 181 | if (!expectedEvent) { |
michael@0 | 182 | ok(false, "received event I didn't expect: " + eventToString(e)); |
michael@0 | 183 | return; |
michael@0 | 184 | } |
michael@0 | 185 | if (e.type != expectedEvent.type) { |
michael@0 | 186 | // Didn't get expectedEvent. |
michael@0 | 187 | var errFun = expectedEvent.shouldFireButDoesnt ? todo : ok; |
michael@0 | 188 | errFun(false, "Didn't receive expected event: " + eventToString(expectedEvent)); |
michael@0 | 189 | return processEvent(e); |
michael@0 | 190 | } |
michael@0 | 191 | gEventNum++; |
michael@0 | 192 | is(e.screenX, expectedEvent.screenX, gEventNum + " | wrong X coord for event " + eventToString(e)); |
michael@0 | 193 | is(e.screenY, expectedEvent.screenY, gEventNum + " | wrong Y coord for event " + eventToString(e)); |
michael@0 | 194 | is(e.target, expectedEvent.target, gEventNum + " | wrong target for event " + eventToString(e)); |
michael@0 | 195 | if (expectedEvent.firesButShouldnt) { |
michael@0 | 196 | todo(false, gEventNum + " | Got an event that should not have fired: " + eventToString(e)); |
michael@0 | 197 | } |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | function observe(elem, fun, add) { |
michael@0 | 201 | var addOrRemove = add ? "addEventListener" : "removeEventListener"; |
michael@0 | 202 | elem[addOrRemove]("mousemove", fun, false); |
michael@0 | 203 | elem[addOrRemove]("mouseover", fun, false); |
michael@0 | 204 | elem[addOrRemove]("mouseout", fun, false); |
michael@0 | 205 | elem[addOrRemove]("mousedown", fun, false); |
michael@0 | 206 | elem[addOrRemove]("mouseup", fun, false); |
michael@0 | 207 | elem[addOrRemove]("click", fun, false); |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | function start() { |
michael@0 | 211 | window.resizeTo(200, 200); |
michael@0 | 212 | window.moveTo(50, 50); |
michael@0 | 213 | gRightWindow = open(xulWin, '', 'chrome,screenX=300,screenY=50,width=200,height=200'); |
michael@0 | 214 | eventListenOnce(gRightWindow, "focus", function () { |
michael@0 | 215 | focusAndThen(window, runTests); |
michael@0 | 216 | }); |
michael@0 | 217 | gPopup = document.getElementById("popup"); |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | function runTests() { |
michael@0 | 221 | observe(window, eventMonitor, true); |
michael@0 | 222 | observe(gRightWindow, eventMonitor, true); |
michael@0 | 223 | var left = window, right = gRightWindow; |
michael@0 | 224 | var leftElem = document.getElementById("box"); |
michael@0 | 225 | var rightElem = gRightWindow.document.documentElement; |
michael@0 | 226 | var panel = document.getElementById("panel"); |
michael@0 | 227 | var tooltip = (function createTooltipInRightWindow() { |
michael@0 | 228 | var _tooltip = right.document.createElementNS(XUL_NS, "tooltip"); |
michael@0 | 229 | _tooltip.setAttribute("id", "tip"); |
michael@0 | 230 | _tooltip.setAttribute("width", "80"); |
michael@0 | 231 | _tooltip.setAttribute("height", "20"); |
michael@0 | 232 | right.document.documentElement.appendChild(_tooltip); |
michael@0 | 233 | return _tooltip; |
michael@0 | 234 | })(); |
michael@0 | 235 | var tests = [ |
michael@0 | 236 | |
michael@0 | 237 | // Part 1: Disallow click-through |
michael@0 | 238 | |
michael@0 | 239 | function blockClickThrough(callback) { |
michael@0 | 240 | document.documentElement.setAttribute("clickthrough", "never"); |
michael@0 | 241 | gRightWindow.document.documentElement.setAttribute("clickthrough", "never"); |
michael@0 | 242 | callback(); |
michael@0 | 243 | }, |
michael@0 | 244 | // Enter the left window, which is focused. |
michael@0 | 245 | [150, 150, NSMouseMoved, null, left, [ |
michael@0 | 246 | { type: "mouseover", target: leftElem }, |
michael@0 | 247 | { type: "mousemove", target: leftElem } |
michael@0 | 248 | ]], |
michael@0 | 249 | // Test that moving inside the window fires mousemove events. |
michael@0 | 250 | [170, 150, NSMouseMoved, null, left, [ |
michael@0 | 251 | { type: "mousemove", target: leftElem }, |
michael@0 | 252 | ]], |
michael@0 | 253 | // Leaving the window should fire a mouseout event... |
michael@0 | 254 | [170, 20, NSMouseMoved, null, left, [ |
michael@0 | 255 | { type: "mouseout", target: leftElem }, |
michael@0 | 256 | ]], |
michael@0 | 257 | // ... and entering a mouseover event. |
michael@0 | 258 | [170, 120, NSMouseMoved, null, left, [ |
michael@0 | 259 | { type: "mouseover", target: leftElem }, |
michael@0 | 260 | { type: "mousemove", target: leftElem }, |
michael@0 | 261 | ]], |
michael@0 | 262 | // Move over the right window, which is inactive. |
michael@0 | 263 | // Inactive windows shouldn't respond to mousemove events when clickthrough="never", |
michael@0 | 264 | // so we should only get a mouseout event, no mouseover event. |
michael@0 | 265 | [400, 150, NSMouseMoved, null, right, [ |
michael@0 | 266 | { type: "mouseout", target: leftElem }, |
michael@0 | 267 | ]], |
michael@0 | 268 | // Left-clicking while holding Cmd and middle clicking should work even |
michael@0 | 269 | // on inactive windows, but without making them active. |
michael@0 | 270 | [400, 150, NSLeftMouseDown, null, right, [ |
michael@0 | 271 | { type: "mousedown", target: rightElem }, |
michael@0 | 272 | ], NSCommandKeyMask], |
michael@0 | 273 | [400, 150, NSLeftMouseUp, null, right, [ |
michael@0 | 274 | { type: "mouseup", target: rightElem }, |
michael@0 | 275 | { type: "click", target: rightElem }, |
michael@0 | 276 | ], NSCommandKeyMask], |
michael@0 | 277 | [400, 150, NSOtherMouseDown, null, right, [ |
michael@0 | 278 | { type: "mousedown", target: rightElem }, |
michael@0 | 279 | ]], |
michael@0 | 280 | [400, 150, NSOtherMouseUp, null, right, [ |
michael@0 | 281 | { type: "mouseup", target: rightElem }, |
michael@0 | 282 | { type: "click", target: rightElem }, |
michael@0 | 283 | ]], |
michael@0 | 284 | // Clicking an inactive window should make it active and fire a mouseover |
michael@0 | 285 | // event. |
michael@0 | 286 | [400, 150, NSLeftMouseDown, null, right, [ |
michael@0 | 287 | { type: "mouseover", target: rightElem, synthetic: true }, |
michael@0 | 288 | ]], |
michael@0 | 289 | [400, 150, NSLeftMouseUp, null, right, [ |
michael@0 | 290 | ]], |
michael@0 | 291 | // Now it's focused, so we should get a mousedown event when clicking. |
michael@0 | 292 | [400, 150, NSLeftMouseDown, null, right, [ |
michael@0 | 293 | { type: "mousedown", target: rightElem }, |
michael@0 | 294 | ]], |
michael@0 | 295 | // Let's drag to the right without letting the button go. |
michael@0 | 296 | [410, 150, NSLeftMouseDragged, null, right, [ |
michael@0 | 297 | { type: "mousemove", target: rightElem }, |
michael@0 | 298 | ]], |
michael@0 | 299 | // Let go of the mouse. |
michael@0 | 300 | [410, 150, NSLeftMouseUp, null, right, [ |
michael@0 | 301 | { type: "mouseup", target: rightElem }, |
michael@0 | 302 | { type: "click", target: rightElem }, |
michael@0 | 303 | ]], |
michael@0 | 304 | // Move the mouse back over the left window, which is inactive. |
michael@0 | 305 | [150, 170, NSMouseMoved, null, left, [ |
michael@0 | 306 | { type: "mouseout", target: rightElem }, |
michael@0 | 307 | ]], |
michael@0 | 308 | // Now we're being sneaky. The left window is inactive, but *right*-clicks to it |
michael@0 | 309 | // should still get through. Test that. |
michael@0 | 310 | // Ideally we'd be bracketing that event with over and out events, too, but it |
michael@0 | 311 | // probably doesn't matter too much. |
michael@0 | 312 | [150, 170, NSRightMouseDown, null, left, [ |
michael@0 | 313 | { type: "mouseover", target: leftElem, shouldFireButDoesnt: true }, |
michael@0 | 314 | { type: "mousedown", target: leftElem }, |
michael@0 | 315 | { type: "mouseout", target: leftElem, shouldFireButDoesnt: true }, |
michael@0 | 316 | ]], |
michael@0 | 317 | // Let go of the mouse. |
michael@0 | 318 | [150, 170, NSRightMouseUp, null, left, [ |
michael@0 | 319 | { type: "mouseover", target: leftElem, shouldFireButDoesnt: true }, |
michael@0 | 320 | { type: "mouseup", target: leftElem }, |
michael@0 | 321 | { type: "click", target: leftElem }, |
michael@0 | 322 | { type: "mouseout", target: leftElem, shouldFireButDoesnt: true }, |
michael@0 | 323 | ]], |
michael@0 | 324 | // Right clicking hasn't focused it, so the window is still inactive. |
michael@0 | 325 | // Let's focus it; this time without the mouse, for variaton's sake. |
michael@0 | 326 | // Still, mouseout and mouseover events should fire. |
michael@0 | 327 | function raiseLeftWindow(callback) { |
michael@0 | 328 | clearExpectedEvents(); |
michael@0 | 329 | gExpectedEvents.push({ screenX: 150, screenY: 170, type: "mouseover", target: leftElem }); |
michael@0 | 330 | // We have to be a bit careful here. The synthetic mouse event may |
michael@0 | 331 | // not fire for a bit after we focus the left window. |
michael@0 | 332 | eventListenOnce(leftElem, "mouseover", function() { |
michael@0 | 333 | // Trigger callback async, so we're not assuming |
michael@0 | 334 | // anything about how our listener gets ordered with others. |
michael@0 | 335 | SimpleTest.executeSoon(callback); |
michael@0 | 336 | }); |
michael@0 | 337 | printDebug("focusing left window"); |
michael@0 | 338 | left.focus(); |
michael@0 | 339 | }, |
michael@0 | 340 | // It's active, so it should respond to mousemove events now. |
michael@0 | 341 | [150, 170, NSMouseMoved, null, left, [ |
michael@0 | 342 | { type: "mousemove", target: leftElem }, |
michael@0 | 343 | ]], |
michael@0 | 344 | // This was boring... let's introduce a popup. It will overlap both the left |
michael@0 | 345 | // and the right window. |
michael@0 | 346 | function openPopupInLeftWindow(callback) { |
michael@0 | 347 | eventListenOnce(gPopup, "popupshown", callback); |
michael@0 | 348 | gPopup.openPopupAtScreen(150, 50, true); |
michael@0 | 349 | }, |
michael@0 | 350 | // Move the mouse over the popup. |
michael@0 | 351 | [200, 80, NSMouseMoved, gPopup, left, [ |
michael@0 | 352 | { type: "mouseout", target: leftElem }, |
michael@0 | 353 | { type: "mouseover", target: gPopup }, |
michael@0 | 354 | { type: "mousemove", target: gPopup }, |
michael@0 | 355 | ]], |
michael@0 | 356 | // Move the mouse back over the left window outside the popup. |
michael@0 | 357 | [160, 170, NSMouseMoved, null, left, [ |
michael@0 | 358 | { type: "mouseout", target: gPopup }, |
michael@0 | 359 | { type: "mouseover", target: leftElem }, |
michael@0 | 360 | { type: "mousemove", target: leftElem }, |
michael@0 | 361 | ]], |
michael@0 | 362 | // Back over the popup... |
michael@0 | 363 | [190, 80, NSMouseMoved, gPopup, left, [ |
michael@0 | 364 | { type: "mouseout", target: leftElem }, |
michael@0 | 365 | { type: "mouseover", target: gPopup }, |
michael@0 | 366 | { type: "mousemove", target: gPopup }, |
michael@0 | 367 | ]], |
michael@0 | 368 | // ...and over into the right window. |
michael@0 | 369 | // It's inactive, so it shouldn't get mouseover events yet. |
michael@0 | 370 | [400, 170, NSMouseMoved, null, right, [ |
michael@0 | 371 | { type: "mouseout", target: gPopup }, |
michael@0 | 372 | ]], |
michael@0 | 373 | // Again, no mouse events please, even though a popup is open. (bug 425556) |
michael@0 | 374 | [400, 180, NSMouseMoved, null, right, [ |
michael@0 | 375 | ]], |
michael@0 | 376 | // Activate the right window with a click. |
michael@0 | 377 | // This will close the popup and make the mouse enter the right window. |
michael@0 | 378 | [400, 180, NSLeftMouseDown, null, right, [ |
michael@0 | 379 | { type: "mouseover", target: rightElem, synthetic: true }, |
michael@0 | 380 | ]], |
michael@0 | 381 | [400, 180, NSLeftMouseUp, null, right, [ |
michael@0 | 382 | ]], |
michael@0 | 383 | function verifyPopupClosed2(callback) { |
michael@0 | 384 | is(gPopup.popupBoxObject.popupState, "closed", "popup should have closed when clicking"); |
michael@0 | 385 | callback(); |
michael@0 | 386 | }, |
michael@0 | 387 | // Now the right window is active; click it again, just for fun. |
michael@0 | 388 | [400, 180, NSLeftMouseDown, null, right, [ |
michael@0 | 389 | { type: "mousedown", target: rightElem }, |
michael@0 | 390 | ]], |
michael@0 | 391 | [400, 180, NSLeftMouseUp, null, right, [ |
michael@0 | 392 | { type: "mouseup", target: rightElem }, |
michael@0 | 393 | { type: "click", target: rightElem }, |
michael@0 | 394 | ]], |
michael@0 | 395 | |
michael@0 | 396 | // Time for our next trick: a tooltip! |
michael@0 | 397 | // Install the tooltip, but don't show it yet. |
michael@0 | 398 | function setTooltip(callback) { |
michael@0 | 399 | rightElem.setAttribute("tooltip", "tip"); |
michael@0 | 400 | gExpectedEvents.push({ screenX: 410, screenY: 180, type: "mousemove", target: rightElem }); |
michael@0 | 401 | eventListenOnce(rightElem, "popupshown", callback); |
michael@0 | 402 | gCurrentMouseX = 410; |
michael@0 | 403 | gCurrentMouseY = 180; |
michael@0 | 404 | var utils = right.QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
michael@0 | 405 | getInterface(Components.interfaces.nsIDOMWindowUtils); |
michael@0 | 406 | utils.sendNativeMouseEvent(410, 180, NSMouseMoved, 0, null); |
michael@0 | 407 | }, |
michael@0 | 408 | // Now the tooltip is visible. |
michael@0 | 409 | // Move the mouse a little to the right. |
michael@0 | 410 | [411, 180, NSMouseMoved, null, right, [ |
michael@0 | 411 | { type: "mousemove", target: rightElem }, |
michael@0 | 412 | ]], |
michael@0 | 413 | // Move another pixel. |
michael@0 | 414 | [412, 180, NSMouseMoved, null, right, [ |
michael@0 | 415 | { type: "mousemove", target: rightElem }, |
michael@0 | 416 | ]], |
michael@0 | 417 | // Move up and click to make the tooltip go away. |
michael@0 | 418 | [412, 80, NSMouseMoved, null, right, [ |
michael@0 | 419 | { type: "mousemove", target: rightElem }, |
michael@0 | 420 | ]], |
michael@0 | 421 | [412, 80, NSLeftMouseDown, null, right, [ |
michael@0 | 422 | { type: "mousedown", target: rightElem }, |
michael@0 | 423 | ]], |
michael@0 | 424 | [412, 80, NSLeftMouseUp, null, right, [ |
michael@0 | 425 | { type: "mouseup", target: rightElem }, |
michael@0 | 426 | { type: "click", target: rightElem }, |
michael@0 | 427 | ]], |
michael@0 | 428 | // OK, next round. Open a panel in the left window, which is inactive. |
michael@0 | 429 | function openPanel(callback) { |
michael@0 | 430 | eventListenOnce(panel, "popupshown", callback); |
michael@0 | 431 | panel.openPopupAtScreen(150, 150, false); |
michael@0 | 432 | }, |
michael@0 | 433 | // The panel is parented, so it will be z-ordered over its parent but |
michael@0 | 434 | // under the active window. |
michael@0 | 435 | // Now we move the mouse over the part where the panel rect intersects the |
michael@0 | 436 | // right window's rect. Since the panel is under the window, all the events |
michael@0 | 437 | // should target the right window. |
michael@0 | 438 | [390, 170, NSMouseMoved, null, right, [ |
michael@0 | 439 | { type: "mousemove", target: rightElem }, |
michael@0 | 440 | ]], |
michael@0 | 441 | [390, 171, NSMouseMoved, null, right, [ |
michael@0 | 442 | { type: "mousemove", target: rightElem }, |
michael@0 | 443 | ]], |
michael@0 | 444 | [391, 171, NSMouseMoved, null, right, [ |
michael@0 | 445 | { type: "mousemove", target: rightElem }, |
michael@0 | 446 | ]], |
michael@0 | 447 | // Now move off the right window, so that the mouse is directly over the |
michael@0 | 448 | // panel. |
michael@0 | 449 | [260, 170, NSMouseMoved, panel, left, [ |
michael@0 | 450 | { type: "mouseout", target: rightElem }, |
michael@0 | 451 | ]], |
michael@0 | 452 | [260, 171, NSMouseMoved, panel, left, [ |
michael@0 | 453 | ]], |
michael@0 | 454 | [261, 171, NSMouseMoved, panel, left, [ |
michael@0 | 455 | ]], |
michael@0 | 456 | // Let's be evil and click it. |
michael@0 | 457 | [261, 171, NSLeftMouseDown, panel, left, [ |
michael@0 | 458 | ]], |
michael@0 | 459 | [261, 171, NSLeftMouseUp, panel, left, [ |
michael@0 | 460 | ]], |
michael@0 | 461 | // This didn't focus the window, unfortunately, so let's do it ourselves. |
michael@0 | 462 | function raiseLeftWindowTakeTwo(callback) { |
michael@0 | 463 | focusAndThen(left, callback); |
michael@0 | 464 | }, |
michael@0 | 465 | // Now mouse events should get through to the panel (which is now over the |
michael@0 | 466 | // right window). |
michael@0 | 467 | [387, 170, NSMouseMoved, panel, left, [ |
michael@0 | 468 | { type: "mouseover", target: panel }, |
michael@0 | 469 | { type: "mousemove", target: panel }, |
michael@0 | 470 | ]], |
michael@0 | 471 | [387, 171, NSMouseMoved, panel, left, [ |
michael@0 | 472 | { type: "mousemove", target: panel }, |
michael@0 | 473 | ]], |
michael@0 | 474 | [388, 171, NSMouseMoved, panel, left, [ |
michael@0 | 475 | { type: "mousemove", target: panel }, |
michael@0 | 476 | ]], |
michael@0 | 477 | // Click the panel. |
michael@0 | 478 | [388, 171, NSLeftMouseDown, panel, left, [ |
michael@0 | 479 | { type: "mousedown", target: panel } |
michael@0 | 480 | ]], |
michael@0 | 481 | [388, 171, NSLeftMouseUp, panel, left, [ |
michael@0 | 482 | { type: "mouseup", target: panel }, |
michael@0 | 483 | { type: "click", target: panel }, |
michael@0 | 484 | ]], |
michael@0 | 485 | |
michael@0 | 486 | // Last test for this part: Hit testing in the Canyon of Nowhere - |
michael@0 | 487 | // the pixel row directly south of the panel, over the left window. |
michael@0 | 488 | // Before bug 515003 we wrongly thought the mouse wasn't over any window. |
michael@0 | 489 | [173, 200, NSMouseMoved, null, left, [ |
michael@0 | 490 | { type: "mouseout", target: panel }, |
michael@0 | 491 | { type: "mouseover", target: leftElem }, |
michael@0 | 492 | { type: "mousemove", target: leftElem }, |
michael@0 | 493 | ]], |
michael@0 | 494 | [173, 201, NSMouseMoved, null, left, [ |
michael@0 | 495 | { type: "mousemove", target: leftElem }, |
michael@0 | 496 | ]], |
michael@0 | 497 | |
michael@0 | 498 | // Part 2: Allow click-through |
michael@0 | 499 | |
michael@0 | 500 | function hideThatPanel(callback) { |
michael@0 | 501 | eventListenOnce(panel, "popuphidden", callback); |
michael@0 | 502 | panel.hidePopup(); |
michael@0 | 503 | }, |
michael@0 | 504 | function unblockClickThrough(callback) { |
michael@0 | 505 | document.documentElement.removeAttribute("clickthrough"); |
michael@0 | 506 | gRightWindow.document.documentElement.removeAttribute("clickthrough"); |
michael@0 | 507 | callback(); |
michael@0 | 508 | }, |
michael@0 | 509 | // Enter the left window, which is focused. |
michael@0 | 510 | [150, 150, NSMouseMoved, null, left, [ |
michael@0 | 511 | { type: "mousemove", target: leftElem } |
michael@0 | 512 | ]], |
michael@0 | 513 | // Test that moving inside the window fires mousemove events. |
michael@0 | 514 | [170, 150, NSMouseMoved, null, left, [ |
michael@0 | 515 | { type: "mousemove", target: leftElem }, |
michael@0 | 516 | ]], |
michael@0 | 517 | // Leaving the window should fire a mouseout event... |
michael@0 | 518 | [170, 20, NSMouseMoved, null, left, [ |
michael@0 | 519 | { type: "mouseout", target: leftElem }, |
michael@0 | 520 | ]], |
michael@0 | 521 | // ... and entering a mouseover event. |
michael@0 | 522 | [170, 120, NSMouseMoved, null, left, [ |
michael@0 | 523 | { type: "mouseover", target: leftElem }, |
michael@0 | 524 | { type: "mousemove", target: leftElem }, |
michael@0 | 525 | ]], |
michael@0 | 526 | // Move over the right window, which is inactive but still accepts |
michael@0 | 527 | // mouse events. |
michael@0 | 528 | [400, 150, NSMouseMoved, null, right, [ |
michael@0 | 529 | { type: "mouseout", target: leftElem }, |
michael@0 | 530 | { type: "mouseover", target: rightElem }, |
michael@0 | 531 | { type: "mousemove", target: rightElem }, |
michael@0 | 532 | ]], |
michael@0 | 533 | // Left-clicking while holding Cmd and middle clicking should work |
michael@0 | 534 | // on inactive windows, but without making them active. |
michael@0 | 535 | [400, 150, NSLeftMouseDown, null, right, [ |
michael@0 | 536 | { type: "mousedown", target: rightElem }, |
michael@0 | 537 | ], NSCommandKeyMask], |
michael@0 | 538 | [400, 150, NSLeftMouseUp, null, right, [ |
michael@0 | 539 | { type: "mouseup", target: rightElem }, |
michael@0 | 540 | { type: "click", target: rightElem }, |
michael@0 | 541 | ], NSCommandKeyMask], |
michael@0 | 542 | [400, 150, NSOtherMouseDown, null, right, [ |
michael@0 | 543 | { type: "mousedown", target: rightElem }, |
michael@0 | 544 | ]], |
michael@0 | 545 | [400, 150, NSOtherMouseUp, null, right, [ |
michael@0 | 546 | { type: "mouseup", target: rightElem }, |
michael@0 | 547 | { type: "click", target: rightElem }, |
michael@0 | 548 | ]], |
michael@0 | 549 | // Clicking an inactive window should make it active |
michael@0 | 550 | [400, 150, NSLeftMouseDown, null, right, [ |
michael@0 | 551 | { type: "mousedown", target: rightElem }, |
michael@0 | 552 | ]], |
michael@0 | 553 | [400, 150, NSLeftMouseUp, null, right, [ |
michael@0 | 554 | { type: "mouseup", target: rightElem }, |
michael@0 | 555 | { type: "click", target: rightElem }, |
michael@0 | 556 | ]], |
michael@0 | 557 | // Now it's focused. |
michael@0 | 558 | [401, 150, NSLeftMouseDown, null, right, [ |
michael@0 | 559 | { type: "mousedown", target: rightElem }, |
michael@0 | 560 | ]], |
michael@0 | 561 | // Let's drag to the right without letting the button go. |
michael@0 | 562 | [410, 150, NSLeftMouseDragged, null, right, [ |
michael@0 | 563 | { type: "mousemove", target: rightElem }, |
michael@0 | 564 | ]], |
michael@0 | 565 | // Let go of the mouse. |
michael@0 | 566 | [410, 150, NSLeftMouseUp, null, right, [ |
michael@0 | 567 | { type: "mouseup", target: rightElem }, |
michael@0 | 568 | { type: "click", target: rightElem }, |
michael@0 | 569 | ]], |
michael@0 | 570 | // Move the mouse back over the left window, which is inactive. |
michael@0 | 571 | [150, 170, NSMouseMoved, null, left, [ |
michael@0 | 572 | { type: "mouseout", target: rightElem }, |
michael@0 | 573 | { type: "mouseover", target: leftElem }, |
michael@0 | 574 | { type: "mousemove", target: leftElem }, |
michael@0 | 575 | ]], |
michael@0 | 576 | // Right-click it. |
michael@0 | 577 | [150, 170, NSRightMouseDown, null, left, [ |
michael@0 | 578 | { type: "mousedown", target: leftElem }, |
michael@0 | 579 | ]], |
michael@0 | 580 | // Let go of the mouse. |
michael@0 | 581 | [150, 170, NSRightMouseUp, null, left, [ |
michael@0 | 582 | { type: "mouseup", target: leftElem }, |
michael@0 | 583 | { type: "click", target: leftElem }, |
michael@0 | 584 | ]], |
michael@0 | 585 | // Right clicking hasn't focused it, so the window is still inactive. |
michael@0 | 586 | // Let's focus it; this time without the mouse, for variaton's sake. |
michael@0 | 587 | function raiseLeftWindow(callback) { |
michael@0 | 588 | clearExpectedEvents(); |
michael@0 | 589 | focusAndThen(left, function () { SimpleTest.executeSoon(callback); }); |
michael@0 | 590 | }, |
michael@0 | 591 | // It's active and should still respond to mousemove events. |
michael@0 | 592 | [150, 170, NSMouseMoved, null, left, [ |
michael@0 | 593 | { type: "mousemove", target: leftElem }, |
michael@0 | 594 | ]], |
michael@0 | 595 | |
michael@0 | 596 | // This was boring... let's introduce a popup. It will overlap both the left |
michael@0 | 597 | // and the right window. |
michael@0 | 598 | function openPopupInLeftWindow(callback) { |
michael@0 | 599 | eventListenOnce(gPopup, "popupshown", callback); |
michael@0 | 600 | gPopup.openPopupAtScreen(150, 50, true); |
michael@0 | 601 | }, |
michael@0 | 602 | // Move the mouse over the popup. |
michael@0 | 603 | [200, 80, NSMouseMoved, gPopup, left, [ |
michael@0 | 604 | { type: "mouseout", target: leftElem }, |
michael@0 | 605 | { type: "mouseover", target: gPopup }, |
michael@0 | 606 | { type: "mousemove", target: gPopup }, |
michael@0 | 607 | ]], |
michael@0 | 608 | // Move the mouse back over the left window outside the popup. |
michael@0 | 609 | [160, 170, NSMouseMoved, null, left, [ |
michael@0 | 610 | { type: "mouseout", target: gPopup }, |
michael@0 | 611 | { type: "mouseover", target: leftElem }, |
michael@0 | 612 | { type: "mousemove", target: leftElem }, |
michael@0 | 613 | ]], |
michael@0 | 614 | // Back over the popup... |
michael@0 | 615 | [190, 80, NSMouseMoved, gPopup, left, [ |
michael@0 | 616 | { type: "mouseout", target: leftElem }, |
michael@0 | 617 | { type: "mouseover", target: gPopup }, |
michael@0 | 618 | { type: "mousemove", target: gPopup }, |
michael@0 | 619 | ]], |
michael@0 | 620 | // ...and over into the right window. |
michael@0 | 621 | [400, 170, NSMouseMoved, null, right, [ |
michael@0 | 622 | { type: "mouseout", target: gPopup }, |
michael@0 | 623 | { type: "mouseover", target: rightElem }, |
michael@0 | 624 | { type: "mousemove", target: rightElem }, |
michael@0 | 625 | ]], |
michael@0 | 626 | [400, 180, NSMouseMoved, null, right, [ |
michael@0 | 627 | { type: "mousemove", target: rightElem }, |
michael@0 | 628 | ]], |
michael@0 | 629 | // Activate the right window with a click. |
michael@0 | 630 | [400, 180, NSLeftMouseDown, null, right, [ |
michael@0 | 631 | { type: "mousedown", target: rightElem }, |
michael@0 | 632 | ]], |
michael@0 | 633 | [400, 180, NSLeftMouseUp, null, right, [ |
michael@0 | 634 | { type: "mouseup", target: rightElem }, |
michael@0 | 635 | { type: "click", target: rightElem }, |
michael@0 | 636 | ]], |
michael@0 | 637 | function verifyPopupClosed2(callback) { |
michael@0 | 638 | is(gPopup.popupBoxObject.popupState, "closed", "popup should have closed when clicking"); |
michael@0 | 639 | callback(); |
michael@0 | 640 | }, |
michael@0 | 641 | // Now the right window is active; click it again, just for fun. |
michael@0 | 642 | [400, 180, NSLeftMouseDown, null, right, [ |
michael@0 | 643 | { type: "mousedown", target: rightElem }, |
michael@0 | 644 | ]], |
michael@0 | 645 | [400, 180, NSLeftMouseUp, null, right, [ |
michael@0 | 646 | { type: "mouseup", target: rightElem }, |
michael@0 | 647 | { type: "click", target: rightElem }, |
michael@0 | 648 | ]], |
michael@0 | 649 | |
michael@0 | 650 | // Time for our next trick: a tooltip! |
michael@0 | 651 | // Install the tooltip, but don't show it yet. |
michael@0 | 652 | function setTooltip2(callback) { |
michael@0 | 653 | rightElem.setAttribute("tooltip", "tip"); |
michael@0 | 654 | gExpectedEvents.push({ screenX: 410, screenY: 180, type: "mousemove", target: rightElem }); |
michael@0 | 655 | eventListenOnce(rightElem, "popupshown", callback); |
michael@0 | 656 | gCurrentMouseX = 410; |
michael@0 | 657 | gCurrentMouseY = 180; |
michael@0 | 658 | var utils = right.QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
michael@0 | 659 | getInterface(Components.interfaces.nsIDOMWindowUtils); |
michael@0 | 660 | utils.sendNativeMouseEvent(410, 180, NSMouseMoved, 0, null); |
michael@0 | 661 | }, |
michael@0 | 662 | // Now the tooltip is visible. |
michael@0 | 663 | // Move the mouse a little to the right. |
michael@0 | 664 | [411, 180, NSMouseMoved, null, right, [ |
michael@0 | 665 | { type: "mousemove", target: rightElem }, |
michael@0 | 666 | ]], |
michael@0 | 667 | // Move another pixel. |
michael@0 | 668 | [412, 180, NSMouseMoved, null, right, [ |
michael@0 | 669 | { type: "mousemove", target: rightElem }, |
michael@0 | 670 | ]], |
michael@0 | 671 | // Move up and click to make the tooltip go away. |
michael@0 | 672 | [412, 80, NSMouseMoved, null, right, [ |
michael@0 | 673 | { type: "mousemove", target: rightElem }, |
michael@0 | 674 | ]], |
michael@0 | 675 | [412, 80, NSLeftMouseDown, null, right, [ |
michael@0 | 676 | { type: "mousedown", target: rightElem }, |
michael@0 | 677 | ]], |
michael@0 | 678 | [412, 80, NSLeftMouseUp, null, right, [ |
michael@0 | 679 | { type: "mouseup", target: rightElem }, |
michael@0 | 680 | { type: "click", target: rightElem }, |
michael@0 | 681 | ]], |
michael@0 | 682 | // OK, next round. Open a panel in the left window, which is inactive. |
michael@0 | 683 | function openPanel2(callback) { |
michael@0 | 684 | eventListenOnce(panel, "popupshown", callback); |
michael@0 | 685 | panel.openPopupAtScreen(150, 150, false); |
michael@0 | 686 | }, |
michael@0 | 687 | // The panel is parented, so it will be z-ordered over its parent but |
michael@0 | 688 | // under the active window. |
michael@0 | 689 | // Now we move the mouse over the part where the panel rect intersects the |
michael@0 | 690 | // right window's rect. Since the panel is under the window, all the events |
michael@0 | 691 | // should target the right window. |
michael@0 | 692 | [390, 170, NSMouseMoved, null, right, [ |
michael@0 | 693 | { type: "mousemove", target: rightElem }, |
michael@0 | 694 | ]], |
michael@0 | 695 | [390, 171, NSMouseMoved, null, right, [ |
michael@0 | 696 | { type: "mousemove", target: rightElem }, |
michael@0 | 697 | ]], |
michael@0 | 698 | [391, 171, NSMouseMoved, null, right, [ |
michael@0 | 699 | { type: "mousemove", target: rightElem }, |
michael@0 | 700 | ]], |
michael@0 | 701 | // Now move off the right window, so that the mouse is directly over the |
michael@0 | 702 | // panel. |
michael@0 | 703 | [260, 170, NSMouseMoved, panel, left, [ |
michael@0 | 704 | { type: "mouseout", target: rightElem }, |
michael@0 | 705 | { type: "mouseover", target: panel }, |
michael@0 | 706 | { type: "mousemove", target: panel }, |
michael@0 | 707 | ]], |
michael@0 | 708 | [260, 171, NSMouseMoved, panel, left, [ |
michael@0 | 709 | { type: "mousemove", target: panel }, |
michael@0 | 710 | ]], |
michael@0 | 711 | [261, 171, NSMouseMoved, panel, left, [ |
michael@0 | 712 | { type: "mousemove", target: panel }, |
michael@0 | 713 | ]], |
michael@0 | 714 | // Let's be evil and click it. |
michael@0 | 715 | [261, 171, NSLeftMouseDown, panel, left, [ |
michael@0 | 716 | { type: "mousedown", target: panel }, |
michael@0 | 717 | ]], |
michael@0 | 718 | [261, 171, NSLeftMouseUp, panel, left, [ |
michael@0 | 719 | { type: "mouseup", target: panel }, |
michael@0 | 720 | { type: "click", target: panel }, |
michael@0 | 721 | ]], |
michael@0 | 722 | // This didn't focus the window, unfortunately, so let's do it ourselves. |
michael@0 | 723 | function raiseLeftWindowTakeTwo(callback) { |
michael@0 | 724 | focusAndThen(left, callback); |
michael@0 | 725 | }, |
michael@0 | 726 | [387, 170, NSMouseMoved, panel, left, [ |
michael@0 | 727 | { type: "mousemove", target: panel }, |
michael@0 | 728 | ]], |
michael@0 | 729 | [387, 171, NSMouseMoved, panel, left, [ |
michael@0 | 730 | { type: "mousemove", target: panel }, |
michael@0 | 731 | ]], |
michael@0 | 732 | [388, 171, NSMouseMoved, panel, left, [ |
michael@0 | 733 | { type: "mousemove", target: panel }, |
michael@0 | 734 | ]], |
michael@0 | 735 | // Click the panel. |
michael@0 | 736 | [388, 171, NSLeftMouseDown, panel, left, [ |
michael@0 | 737 | { type: "mousedown", target: panel } |
michael@0 | 738 | ]], |
michael@0 | 739 | [388, 171, NSLeftMouseUp, panel, left, [ |
michael@0 | 740 | { type: "mouseup", target: panel }, |
michael@0 | 741 | { type: "click", target: panel }, |
michael@0 | 742 | ]], |
michael@0 | 743 | |
michael@0 | 744 | // Last test for today: Hit testing in the Canyon of Nowhere - |
michael@0 | 745 | // the pixel row directly south of the panel, over the left window. |
michael@0 | 746 | // Before bug 515003 we wrongly thought the mouse wasn't over any window. |
michael@0 | 747 | [173, 200, NSMouseMoved, null, left, [ |
michael@0 | 748 | { type: "mouseout", target: panel }, |
michael@0 | 749 | { type: "mouseover", target: leftElem }, |
michael@0 | 750 | { type: "mousemove", target: leftElem }, |
michael@0 | 751 | ]], |
michael@0 | 752 | [173, 201, NSMouseMoved, null, left, [ |
michael@0 | 753 | { type: "mousemove", target: leftElem }, |
michael@0 | 754 | ]], |
michael@0 | 755 | ]; |
michael@0 | 756 | function runNextTest() { |
michael@0 | 757 | if (!tests.length) |
michael@0 | 758 | return onTestsFinished(); |
michael@0 | 759 | |
michael@0 | 760 | var test = tests.shift(); |
michael@0 | 761 | if (typeof test == "function") |
michael@0 | 762 | return test(runNextTest); |
michael@0 | 763 | |
michael@0 | 764 | var [x, y, msg, elem, win, exp, flags] = test; |
michael@0 | 765 | testMouse(x, y, msg, elem, win, exp, flags, runNextTest); |
michael@0 | 766 | } |
michael@0 | 767 | runNextTest(); |
michael@0 | 768 | } |
michael@0 | 769 | |
michael@0 | 770 | SimpleTest.waitForFocus(start); |
michael@0 | 771 | |
michael@0 | 772 | ]]></script> |
michael@0 | 773 | </window> |