Sat, 03 Jan 2015 20:18:00 +0100
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 | |
michael@0 | 4 | <window title="Large Menu Tests" |
michael@0 | 5 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 6 | |
michael@0 | 7 | <script type="application/javascript" |
michael@0 | 8 | src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
michael@0 | 9 | |
michael@0 | 10 | <!-- |
michael@0 | 11 | This test checks that a large menu is displayed with arrow buttons |
michael@0 | 12 | and is on the screen. |
michael@0 | 13 | --> |
michael@0 | 14 | |
michael@0 | 15 | <script> |
michael@0 | 16 | <![CDATA[ |
michael@0 | 17 | |
michael@0 | 18 | var gOverflowed = false, gUnderflowed = false; |
michael@0 | 19 | var gContextMenuTests = false; |
michael@0 | 20 | var gScreenY = -1; |
michael@0 | 21 | var gTestIndex = 0; |
michael@0 | 22 | var gTests = ["open normal", "open flipped position", "open with scrolling", |
michael@0 | 23 | "open after scrolling", "open small again", |
michael@0 | 24 | "menu movement", "panel movement", |
michael@0 | 25 | "context menu enough space below", |
michael@0 | 26 | "context menu more space above", |
michael@0 | 27 | "context menu too big either side", |
michael@0 | 28 | "context menu larger than screen"]; |
michael@0 | 29 | |
michael@0 | 30 | function getScreenXY(element) |
michael@0 | 31 | { |
michael@0 | 32 | var screenX, screenY; |
michael@0 | 33 | var mouseFn = function(event) { |
michael@0 | 34 | screenX = event.screenX - 1; |
michael@0 | 35 | screenY = event.screenY - 1; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | // a hacky way to get the screen position of an element without using the box object |
michael@0 | 39 | window.addEventListener("mousedown", mouseFn, false); |
michael@0 | 40 | synthesizeMouse(element, 1, 1, { }); |
michael@0 | 41 | window.removeEventListener("mousedown", mouseFn, false); |
michael@0 | 42 | |
michael@0 | 43 | return [screenX, screenY]; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function hidePopup() { |
michael@0 | 47 | window.requestAnimationFrame( |
michael@0 | 48 | function() { |
michael@0 | 49 | setTimeout( |
michael@0 | 50 | function() { |
michael@0 | 51 | document.getElementById("popup").hidePopup(); |
michael@0 | 52 | }, 0); |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function runTests() |
michael@0 | 57 | { |
michael@0 | 58 | [, gScreenY] = getScreenXY(document.documentElement); |
michael@0 | 59 | nextTest(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function nextTest() |
michael@0 | 63 | { |
michael@0 | 64 | gOverflowed = false, gUnderflowed = false; |
michael@0 | 65 | |
michael@0 | 66 | var y = screen.height; |
michael@0 | 67 | if (gTestIndex == 1) // open flipped position test: |
michael@0 | 68 | y -= 100; |
michael@0 | 69 | else |
michael@0 | 70 | y /= 2; |
michael@0 | 71 | |
michael@0 | 72 | var popup = document.getElementById("popup"); |
michael@0 | 73 | if (gTestIndex == 2) { |
michael@0 | 74 | // add some more menuitems so that scrolling will be necessary |
michael@0 | 75 | for (var t = 1; t <= 30; t++) { |
michael@0 | 76 | var menu = document.createElement("menuitem"); |
michael@0 | 77 | menu.setAttribute("label", "More" + t); |
michael@0 | 78 | popup.appendChild(menu); |
michael@0 | 79 | } |
michael@0 | 80 | } |
michael@0 | 81 | else if (gTestIndex == 4) { |
michael@0 | 82 | for (var t = 1; t <= 30; t++) |
michael@0 | 83 | popup.removeChild(popup.lastChild); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | window.requestAnimationFrame(function() { |
michael@0 | 87 | setTimeout( |
michael@0 | 88 | function() { |
michael@0 | 89 | popup.openPopupAtScreen(100, y, false); |
michael@0 | 90 | }, 0); |
michael@0 | 91 | }); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function popupShown() |
michael@0 | 95 | { |
michael@0 | 96 | if (gTests[gTestIndex] == "menu movement") |
michael@0 | 97 | return testPopupMovement(); |
michael@0 | 98 | |
michael@0 | 99 | if (gContextMenuTests) |
michael@0 | 100 | return contextMenuPopupShown(); |
michael@0 | 101 | |
michael@0 | 102 | var popup = document.getElementById("popup"); |
michael@0 | 103 | var rect = popup.getBoundingClientRect(); |
michael@0 | 104 | var sbo = document.getAnonymousNodes(popup)[0].scrollBoxObject; |
michael@0 | 105 | var expectedScrollPos = 0; |
michael@0 | 106 | |
michael@0 | 107 | if (gTestIndex == 0) { |
michael@0 | 108 | // the popup should be in the center of the screen |
michael@0 | 109 | // note that if the height is odd, the y-offset will have been rounded |
michael@0 | 110 | // down when we pass the fractional value to openPopupAtScreen above. |
michael@0 | 111 | is(Math.round(rect.top) + gScreenY, Math.floor(screen.height / 2), |
michael@0 | 112 | gTests[gTestIndex] + " top"); |
michael@0 | 113 | ok(Math.round(rect.bottom) + gScreenY < screen.height, |
michael@0 | 114 | gTests[gTestIndex] + " bottom"); |
michael@0 | 115 | ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow") |
michael@0 | 116 | } |
michael@0 | 117 | else if (gTestIndex == 1) { |
michael@0 | 118 | // the popup was supposed to open 100 pixels from the bottom, but that |
michael@0 | 119 | // would put it off screen so it should be flipped to have its bottom |
michael@0 | 120 | // edge 100 pixels from the bottom |
michael@0 | 121 | ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top"); |
michael@0 | 122 | is(Math.round(rect.bottom) + gScreenY, screen.height - 100, |
michael@0 | 123 | gTests[gTestIndex] + " bottom"); |
michael@0 | 124 | ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow") |
michael@0 | 125 | } |
michael@0 | 126 | else if (gTestIndex == 2) { |
michael@0 | 127 | // the popup is too large so ensure that it is on screen |
michael@0 | 128 | ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top"); |
michael@0 | 129 | ok(Math.round(rect.bottom) + gScreenY <= screen.height, gTests[gTestIndex] + " bottom"); |
michael@0 | 130 | ok(gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow") |
michael@0 | 131 | |
michael@0 | 132 | sbo.scrollTo(0, 40); |
michael@0 | 133 | expectedScrollPos = 40; |
michael@0 | 134 | } |
michael@0 | 135 | else if (gTestIndex == 3) { |
michael@0 | 136 | expectedScrollPos = 40; |
michael@0 | 137 | } |
michael@0 | 138 | else if (gTestIndex == 4) { |
michael@0 | 139 | // note that if the height is odd, the y-offset will have been rounded |
michael@0 | 140 | // down when we pass the fractional value to openPopupAtScreen above. |
michael@0 | 141 | is(Math.round(rect.top) + gScreenY, Math.floor(screen.height / 2), |
michael@0 | 142 | gTests[gTestIndex] + " top"); |
michael@0 | 143 | ok(Math.round(rect.bottom) + gScreenY < screen.height, |
michael@0 | 144 | gTests[gTestIndex] + " bottom"); |
michael@0 | 145 | ok(!gOverflowed && gUnderflowed, gTests[gTestIndex] + " overflow") |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | var sx = { }, sy = { }; |
michael@0 | 149 | sbo.getPosition(sx, sy); |
michael@0 | 150 | is(sy.value, expectedScrollPos, "menu scroll position"); |
michael@0 | 151 | |
michael@0 | 152 | hidePopup(); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); } |
michael@0 | 156 | function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); } |
michael@0 | 157 | |
michael@0 | 158 | var oldx, oldy, waitSteps = 0; |
michael@0 | 159 | function moveWindowTo(x, y, callback, arg) |
michael@0 | 160 | { |
michael@0 | 161 | if (!waitSteps) { |
michael@0 | 162 | oldx = window.screenX; |
michael@0 | 163 | oldy = window.screenY; |
michael@0 | 164 | window.moveTo(x, y); |
michael@0 | 165 | |
michael@0 | 166 | waitSteps++; |
michael@0 | 167 | setTimeout(moveWindowTo, 100, x, y, callback, arg); |
michael@0 | 168 | return; |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | if (window.screenX == oldx && window.screenY == oldy) { |
michael@0 | 172 | if (waitSteps++ > 10) { |
michael@0 | 173 | ok(false, "Window never moved properly to " + x + "," + y); |
michael@0 | 174 | window.opener.wrappedJSObject.SimpleTest.finish(); |
michael@0 | 175 | window.close(); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | setTimeout(moveWindowTo, 100, x, y, callback, arg); |
michael@0 | 179 | } |
michael@0 | 180 | else { |
michael@0 | 181 | waitSteps = 0; |
michael@0 | 182 | callback(arg); |
michael@0 | 183 | } |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | function popupHidden() |
michael@0 | 187 | { |
michael@0 | 188 | gTestIndex++; |
michael@0 | 189 | if (gTestIndex == gTests.length) { |
michael@0 | 190 | window.opener.wrappedJSObject.SimpleTest.finish(); |
michael@0 | 191 | window.close(); |
michael@0 | 192 | } |
michael@0 | 193 | else if (gTests[gTestIndex] == "context menu enough space below") { |
michael@0 | 194 | gContextMenuTests = true; |
michael@0 | 195 | moveWindowTo(window.screenX, screen.availTop + 10, |
michael@0 | 196 | function () synthesizeMouse(document.getElementById("label"), 4, 4, { type: "contextmenu", button: 2 })); |
michael@0 | 197 | } |
michael@0 | 198 | else if (gTests[gTestIndex] == "menu movement") { |
michael@0 | 199 | document.getElementById("popup").openPopup( |
michael@0 | 200 | document.getElementById("label"), "after_start", 0, 0, false, false); |
michael@0 | 201 | } |
michael@0 | 202 | else if (gTests[gTestIndex] == "panel movement") { |
michael@0 | 203 | document.getElementById("panel").openPopup( |
michael@0 | 204 | document.getElementById("label"), "after_start", 0, 0, false, false); |
michael@0 | 205 | } |
michael@0 | 206 | else if (gContextMenuTests) { |
michael@0 | 207 | contextMenuPopupHidden(); |
michael@0 | 208 | } |
michael@0 | 209 | else { |
michael@0 | 210 | nextTest(); |
michael@0 | 211 | } |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | function contextMenuPopupShown() |
michael@0 | 215 | { |
michael@0 | 216 | var popup = document.getElementById("popup"); |
michael@0 | 217 | var rect = popup.getBoundingClientRect(); |
michael@0 | 218 | var labelrect = document.getElementById("label").getBoundingClientRect(); |
michael@0 | 219 | |
michael@0 | 220 | is(rect.left, labelrect.left + 6, gTests[gTestIndex] + " left"); |
michael@0 | 221 | switch (gTests[gTestIndex]) { |
michael@0 | 222 | case "context menu enough space below": |
michael@0 | 223 | is(rect.top, labelrect.top + 6, gTests[gTestIndex] + " top"); |
michael@0 | 224 | break; |
michael@0 | 225 | case "context menu more space above": |
michael@0 | 226 | is(rect.top, labelrect.top - rect.height + 2, gTests[gTestIndex] + " top"); |
michael@0 | 227 | break; |
michael@0 | 228 | case "context menu too big either side": |
michael@0 | 229 | [, gScreenY] = getScreenXY(document.documentElement); |
michael@0 | 230 | // compare against the available size as well as the total size, as some |
michael@0 | 231 | // platforms allow the menu to overlap os chrome and others do not |
michael@0 | 232 | var pos = (screen.availTop + screen.availHeight - rect.height) - gScreenY; |
michael@0 | 233 | var availPos = (screen.top + screen.height - rect.height) - gScreenY; |
michael@0 | 234 | ok(rect.top == pos || rect.top == availPos, |
michael@0 | 235 | gTests[gTestIndex] + " top"); |
michael@0 | 236 | break; |
michael@0 | 237 | case "context menu larger than screen": |
michael@0 | 238 | ok(rect.top == -(gScreenY - screen.availTop) || rect.top == -(gScreenY - screen.top), gTests[gTestIndex] + " top"); |
michael@0 | 239 | break; |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | hidePopup(); |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | function contextMenuPopupHidden() |
michael@0 | 246 | { |
michael@0 | 247 | var screenAvailBottom = screen.availTop + screen.availHeight; |
michael@0 | 248 | |
michael@0 | 249 | if (gTests[gTestIndex] == "context menu more space above") { |
michael@0 | 250 | moveWindowTo(window.screenX, screenAvailBottom - 80, nextContextMenuTest, -1); |
michael@0 | 251 | } |
michael@0 | 252 | else if (gTests[gTestIndex] == "context menu too big either side") { |
michael@0 | 253 | moveWindowTo(window.screenX, screenAvailBottom / 2 - 80, nextContextMenuTest, screenAvailBottom / 2 + 120); |
michael@0 | 254 | } |
michael@0 | 255 | else if (gTests[gTestIndex] == "context menu larger than screen") { |
michael@0 | 256 | nextContextMenuTest(screen.availHeight + 80); |
michael@0 | 257 | } |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | function nextContextMenuTest(desiredHeight) |
michael@0 | 261 | { |
michael@0 | 262 | if (desiredHeight >= 0) { |
michael@0 | 263 | var popup = document.getElementById("popup"); |
michael@0 | 264 | var height = popup.getBoundingClientRect().height; |
michael@0 | 265 | var itemheight = document.getElementById("firstitem").getBoundingClientRect().height; |
michael@0 | 266 | while (height < desiredHeight) { |
michael@0 | 267 | var menu = document.createElement("menuitem"); |
michael@0 | 268 | menu.setAttribute("label", "Item"); |
michael@0 | 269 | popup.appendChild(menu); |
michael@0 | 270 | height += itemheight; |
michael@0 | 271 | } |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | synthesizeMouse(document.getElementById("label"), 4, 4, { type: "contextmenu", button: 2 }); |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | function testPopupMovement() |
michael@0 | 278 | { |
michael@0 | 279 | var button = document.getElementById("label"); |
michael@0 | 280 | var isPanelTest = (gTests[gTestIndex] == "panel movement"); |
michael@0 | 281 | var popup = document.getElementById(isPanelTest ? "panel" : "popup"); |
michael@0 | 282 | |
michael@0 | 283 | var screenX, screenY, buttonScreenX, buttonScreenY; |
michael@0 | 284 | var rect = popup.getBoundingClientRect(); |
michael@0 | 285 | |
michael@0 | 286 | var overlapOSChrome = (navigator.platform.indexOf("Mac") == -1); |
michael@0 | 287 | popup.moveTo(1, 1); |
michael@0 | 288 | [screenX, screenY] = getScreenXY(popup); |
michael@0 | 289 | |
michael@0 | 290 | var expectedx = 1, expectedy = 1; |
michael@0 | 291 | if (!isPanelTest && !overlapOSChrome) { |
michael@0 | 292 | if (screen.availLeft >= 1) expectedx = screen.availLeft; |
michael@0 | 293 | if (screen.availTop >= 1) expectedy = screen.availTop; |
michael@0 | 294 | } |
michael@0 | 295 | is(screenX, expectedx, gTests[gTestIndex] + " (1, 1) x"); |
michael@0 | 296 | is(screenY, expectedy, gTests[gTestIndex] + " (1, 1) y"); |
michael@0 | 297 | |
michael@0 | 298 | popup.moveTo(100, 8000); |
michael@0 | 299 | if (isPanelTest) { |
michael@0 | 300 | expectedy = 8000; |
michael@0 | 301 | } |
michael@0 | 302 | else { |
michael@0 | 303 | expectedy = (overlapOSChrome ? screen.height + screen.top : screen.availHeight + screen.availTop) - |
michael@0 | 304 | Math.round(rect.height); |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | [screenX, screenY] = getScreenXY(popup); |
michael@0 | 308 | is(screenX, 100, gTests[gTestIndex] + " (100, 8000) x"); |
michael@0 | 309 | is(screenY, expectedy, gTests[gTestIndex] + " (100, 8000) y"); |
michael@0 | 310 | |
michael@0 | 311 | popup.moveTo(6000, 100); |
michael@0 | 312 | |
michael@0 | 313 | if (isPanelTest) { |
michael@0 | 314 | expectedx = 6000; |
michael@0 | 315 | } |
michael@0 | 316 | else { |
michael@0 | 317 | expectedx = (overlapOSChrome ? screen.width + screen.left : screen.availWidth + screen.availLeft) - |
michael@0 | 318 | Math.round(rect.width); |
michael@0 | 319 | } |
michael@0 | 320 | |
michael@0 | 321 | [screenX, screenY] = getScreenXY(popup); |
michael@0 | 322 | is(screenX, expectedx, gTests[gTestIndex] + " (6000, 100) x"); |
michael@0 | 323 | is(screenY, 100, gTests[gTestIndex] + " (6000, 100) y"); |
michael@0 | 324 | |
michael@0 | 325 | is(popup.left, "", gTests[gTestIndex] + " left is empty after moving"); |
michael@0 | 326 | is(popup.top, "", gTests[gTestIndex] + " top is empty after moving"); |
michael@0 | 327 | popup.setAttribute("left", "80"); |
michael@0 | 328 | popup.setAttribute("top", "82"); |
michael@0 | 329 | [screenX, screenY] = getScreenXY(popup); |
michael@0 | 330 | is(screenX, 80, gTests[gTestIndex] + " set left and top x"); |
michael@0 | 331 | is(screenY, 82, gTests[gTestIndex] + " set left and top y"); |
michael@0 | 332 | popup.moveTo(95, 98); |
michael@0 | 333 | [screenX, screenY] = getScreenXY(popup); |
michael@0 | 334 | is(screenX, 95, gTests[gTestIndex] + " move after set left and top x"); |
michael@0 | 335 | is(screenY, 98, gTests[gTestIndex] + " move after set left and top y"); |
michael@0 | 336 | is(popup.left, "95", gTests[gTestIndex] + " left is set after moving"); |
michael@0 | 337 | is(popup.top, "98", gTests[gTestIndex] + " top is set after moving"); |
michael@0 | 338 | popup.removeAttribute("left"); |
michael@0 | 339 | popup.removeAttribute("top"); |
michael@0 | 340 | |
michael@0 | 341 | popup.moveTo(-1, -1); |
michael@0 | 342 | [screenX, screenY] = getScreenXY(popup); |
michael@0 | 343 | [buttonScreenX, buttonScreenY] = getScreenXY(button); |
michael@0 | 344 | is(screenX, buttonScreenX, gTests[gTestIndex] + " original x"); |
michael@0 | 345 | is(screenY, buttonScreenY + button.getBoundingClientRect().height, gTests[gTestIndex] + " original y"); |
michael@0 | 346 | |
michael@0 | 347 | popup.hidePopup(); |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | window.opener.wrappedJSObject.SimpleTest.waitForFocus(runTests, window); |
michael@0 | 351 | |
michael@0 | 352 | ]]> |
michael@0 | 353 | </script> |
michael@0 | 354 | |
michael@0 | 355 | <button id="label" label="OK" context="popup"/> |
michael@0 | 356 | <menupopup id="popup" onpopupshown="popupShown();" onpopuphidden="popupHidden();" |
michael@0 | 357 | onoverflow="gOverflowed = true" onunderflow="gUnderflowed = true;"> |
michael@0 | 358 | <menuitem id="firstitem" label="1"/> |
michael@0 | 359 | <menuitem label="2"/> |
michael@0 | 360 | <menuitem label="3"/> |
michael@0 | 361 | <menuitem label="4"/> |
michael@0 | 362 | <menuitem label="5"/> |
michael@0 | 363 | <menuitem label="6"/> |
michael@0 | 364 | <menuitem label="7"/> |
michael@0 | 365 | <menuitem label="8"/> |
michael@0 | 366 | <menuitem label="9"/> |
michael@0 | 367 | <menuitem label="10"/> |
michael@0 | 368 | <menuitem label="11"/> |
michael@0 | 369 | <menuitem label="12"/> |
michael@0 | 370 | <menuitem label="13"/> |
michael@0 | 371 | <menuitem label="14"/> |
michael@0 | 372 | <menuitem label="15"/> |
michael@0 | 373 | </menupopup> |
michael@0 | 374 | |
michael@0 | 375 | <panel id="panel" onpopupshown="testPopupMovement();" onpopuphidden="popupHidden();" style="margin: 0"> |
michael@0 | 376 | <button label="OK"/> |
michael@0 | 377 | </panel> |
michael@0 | 378 | |
michael@0 | 379 | </window> |