2007-08-08 07:11:11 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
|
|
|
|
<window title="Large Menu Tests"
|
2009-09-03 12:30:06 -07:00
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
2007-08-08 07:11:11 -07:00
|
|
|
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
This test checks that a large menu is displayed with arrow buttons
|
|
|
|
and is on the screen.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<![CDATA[
|
|
|
|
|
|
|
|
var gOverflowed = false, gUnderflowed = false;
|
2009-01-06 11:21:23 -08:00
|
|
|
var gContextMenuTests = false;
|
2007-08-08 07:11:11 -07:00
|
|
|
var gScreenY = -1;
|
|
|
|
var gTestIndex = 0;
|
2007-12-19 08:37:32 -08:00
|
|
|
var gTests = ["open normal", "open flipped position", "open with scrolling",
|
2009-01-06 11:21:23 -08:00
|
|
|
"open after scrolling", "open small again",
|
2009-02-17 07:51:11 -08:00
|
|
|
"menu movement", "panel movement",
|
2009-01-06 11:21:23 -08:00
|
|
|
"context menu enough space below",
|
|
|
|
"context menu more space above",
|
|
|
|
"context menu too big either side",
|
|
|
|
"context menu larger than screen"];
|
2007-08-08 07:11:11 -07:00
|
|
|
|
2009-04-22 05:55:49 -07:00
|
|
|
function getScreenXY(element)
|
2007-08-08 07:11:11 -07:00
|
|
|
{
|
2009-04-22 05:55:49 -07:00
|
|
|
var screenX, screenY;
|
|
|
|
var mouseFn = function(event) {
|
|
|
|
screenX = event.screenX - 1;
|
|
|
|
screenY = event.screenY - 1;
|
|
|
|
}
|
2007-08-08 07:11:11 -07:00
|
|
|
|
2009-04-22 05:55:49 -07:00
|
|
|
// a hacky way to get the screen position of an element without using the box object
|
2007-08-08 07:11:11 -07:00
|
|
|
window.addEventListener("mousedown", mouseFn, false);
|
2009-04-22 05:55:49 -07:00
|
|
|
synthesizeMouse(element, 1, 1, { });
|
2007-08-08 07:11:11 -07:00
|
|
|
window.removeEventListener("mousedown", mouseFn, false);
|
2009-04-22 05:55:49 -07:00
|
|
|
|
|
|
|
return [screenX, screenY];
|
2009-01-06 11:21:23 -08:00
|
|
|
}
|
2007-08-08 07:11:11 -07:00
|
|
|
|
2009-01-06 11:21:23 -08:00
|
|
|
function runTests()
|
|
|
|
{
|
2009-04-22 05:55:49 -07:00
|
|
|
[, gScreenY] = getScreenXY(document.documentElement);
|
2007-08-08 07:11:11 -07:00
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function nextTest()
|
|
|
|
{
|
|
|
|
gOverflowed = false, gUnderflowed = false;
|
|
|
|
|
|
|
|
var y = screen.height;
|
|
|
|
if (gTestIndex == 1) // open flipped position test:
|
|
|
|
y -= 100;
|
|
|
|
else
|
|
|
|
y /= 2;
|
|
|
|
|
|
|
|
var popup = document.getElementById("popup");
|
|
|
|
if (gTestIndex == 2) {
|
|
|
|
// add some more menuitems so that scrolling will be necessary
|
|
|
|
for (var t = 1; t <= 30; t++) {
|
|
|
|
var menu = document.createElement("menuitem");
|
|
|
|
menu.setAttribute("label", "More" + t);
|
|
|
|
popup.appendChild(menu);
|
|
|
|
}
|
|
|
|
}
|
2007-12-19 08:37:32 -08:00
|
|
|
else if (gTestIndex == 4) {
|
2007-08-08 07:11:11 -07:00
|
|
|
for (var t = 1; t <= 30; t++)
|
|
|
|
popup.removeChild(popup.lastChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
popup.openPopupAtScreen(100, y, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function popupShown()
|
|
|
|
{
|
2009-02-17 07:51:11 -08:00
|
|
|
if (gTests[gTestIndex] == "menu movement")
|
|
|
|
return testPopupMovement();
|
|
|
|
|
2009-01-06 11:21:23 -08:00
|
|
|
if (gContextMenuTests)
|
|
|
|
return contextMenuPopupShown();
|
|
|
|
|
2007-08-08 07:11:11 -07:00
|
|
|
var popup = document.getElementById("popup");
|
|
|
|
var rect = popup.getBoundingClientRect();
|
2007-12-19 08:37:32 -08:00
|
|
|
var sbo = document.getAnonymousNodes(popup)[0].scrollBoxObject;
|
|
|
|
var expectedScrollPos = 0;
|
|
|
|
|
2007-08-08 07:11:11 -07:00
|
|
|
if (gTestIndex == 0) {
|
2009-04-25 01:39:32 -07:00
|
|
|
// the popup should be in the center of the screen
|
|
|
|
// note that if the height is odd, the y-offset will have been rounded
|
|
|
|
// down when we pass the fractional value to openPopupAtScreen above.
|
|
|
|
is(Math.round(rect.top) + gScreenY, Math.floor(screen.height / 2),
|
2007-08-08 07:11:11 -07:00
|
|
|
gTests[gTestIndex] + " top");
|
|
|
|
ok(Math.round(rect.bottom) + gScreenY < screen.height,
|
|
|
|
gTests[gTestIndex] + " bottom");
|
|
|
|
ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow")
|
|
|
|
}
|
|
|
|
else if (gTestIndex == 1) {
|
|
|
|
// the popup was supposed to open 100 pixels from the bottom, but that
|
2007-08-09 01:53:19 -07:00
|
|
|
// would put it off screen so it should be flipped to have its bottom
|
2007-08-08 07:11:11 -07:00
|
|
|
// edge 100 pixels from the bottom
|
2007-08-15 16:48:31 -07:00
|
|
|
ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top");
|
2007-08-08 07:11:11 -07:00
|
|
|
is(Math.round(rect.bottom) + gScreenY, screen.height - 100,
|
|
|
|
gTests[gTestIndex] + " bottom");
|
|
|
|
ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow")
|
|
|
|
}
|
|
|
|
else if (gTestIndex == 2) {
|
|
|
|
// the popup is too large so ensure that it is on screen
|
2007-08-15 16:48:31 -07:00
|
|
|
ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top");
|
|
|
|
ok(Math.round(rect.bottom) + gScreenY < screen.height, gTests[gTestIndex] + " bottom");
|
2007-08-08 07:11:11 -07:00
|
|
|
ok(gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow")
|
2007-12-19 08:37:32 -08:00
|
|
|
|
|
|
|
sbo.scrollTo(0, 40);
|
|
|
|
expectedScrollPos = 40;
|
2007-08-08 07:11:11 -07:00
|
|
|
}
|
|
|
|
else if (gTestIndex == 3) {
|
2007-12-19 08:37:32 -08:00
|
|
|
expectedScrollPos = 40;
|
|
|
|
}
|
|
|
|
else if (gTestIndex == 4) {
|
2009-04-25 01:39:32 -07:00
|
|
|
// note that if the height is odd, the y-offset will have been rounded
|
|
|
|
// down when we pass the fractional value to openPopupAtScreen above.
|
|
|
|
is(Math.round(rect.top) + gScreenY, Math.floor(screen.height / 2),
|
2007-08-08 07:11:11 -07:00
|
|
|
gTests[gTestIndex] + " top");
|
|
|
|
ok(Math.round(rect.bottom) + gScreenY < screen.height,
|
|
|
|
gTests[gTestIndex] + " bottom");
|
|
|
|
ok(!gOverflowed && gUnderflowed, gTests[gTestIndex] + " overflow")
|
|
|
|
}
|
|
|
|
|
2007-12-19 08:37:32 -08:00
|
|
|
var sx = { }, sy = { };
|
|
|
|
sbo.getPosition(sx, sy);
|
|
|
|
is(sy.value, expectedScrollPos, "menu scroll position");
|
|
|
|
|
2007-08-08 07:11:11 -07:00
|
|
|
popup.hidePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }
|
|
|
|
function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); }
|
|
|
|
|
|
|
|
function popupHidden()
|
|
|
|
{
|
|
|
|
gTestIndex++;
|
|
|
|
if (gTestIndex == gTests.length) {
|
|
|
|
window.opener.wrappedJSObject.SimpleTest.finish();
|
|
|
|
window.close();
|
|
|
|
}
|
2009-01-06 11:21:23 -08:00
|
|
|
else if (gTests[gTestIndex] == "context menu enough space below") {
|
|
|
|
gContextMenuTests = true;
|
2009-01-14 10:23:09 -08:00
|
|
|
window.moveTo(window.screenX, screen.availTop + 10);
|
2009-01-06 11:21:23 -08:00
|
|
|
synthesizeMouse(document.getElementById("label"), 4, 4, { type: "contextmenu", button: 2 });
|
|
|
|
}
|
2009-02-17 07:51:11 -08:00
|
|
|
else if (gTests[gTestIndex] == "menu movement") {
|
|
|
|
document.getElementById("popup").openPopup(
|
|
|
|
document.getElementById("label"), "after_start", 0, 0, false, false);
|
|
|
|
}
|
|
|
|
else if (gTests[gTestIndex] == "panel movement") {
|
|
|
|
document.getElementById("panel").openPopup(
|
|
|
|
document.getElementById("label"), "after_start", 0, 0, false, false);
|
|
|
|
}
|
2009-01-06 11:21:23 -08:00
|
|
|
else if (gContextMenuTests) {
|
|
|
|
contextMenuPopupHidden();
|
|
|
|
}
|
2007-08-08 07:11:11 -07:00
|
|
|
else {
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
}
|
2009-01-06 11:21:23 -08:00
|
|
|
|
|
|
|
function contextMenuPopupShown()
|
|
|
|
{
|
|
|
|
var popup = document.getElementById("popup");
|
|
|
|
var rect = popup.getBoundingClientRect();
|
|
|
|
var labelrect = document.getElementById("label").getBoundingClientRect();
|
|
|
|
|
2009-04-22 05:55:49 -07:00
|
|
|
is(rect.left, labelrect.left + 6, gTests[gTestIndex] + " left");
|
2009-01-06 11:21:23 -08:00
|
|
|
switch (gTests[gTestIndex]) {
|
|
|
|
case "context menu enough space below":
|
|
|
|
is(rect.top, labelrect.top + 6, gTests[gTestIndex] + " top");
|
|
|
|
break;
|
|
|
|
case "context menu more space above":
|
|
|
|
is(rect.top, labelrect.top - rect.height + 2, gTests[gTestIndex] + " top");
|
|
|
|
break;
|
|
|
|
case "context menu too big either side":
|
2009-04-22 05:55:49 -07:00
|
|
|
[, gScreenY] = getScreenXY(document.documentElement);
|
2009-01-06 11:21:23 -08:00
|
|
|
// compare against the available size as well as the total size, as some
|
|
|
|
// platforms allow the menu to overlap os chrome and others do not
|
|
|
|
// the - 3 here is to account for 3 pixels that are subtracted from the
|
|
|
|
// screen size when sizing a popup for the popup shadow
|
|
|
|
var pos = (screen.availTop + screen.availHeight - 3 - rect.height) - gScreenY;
|
|
|
|
var availPos = (screen.top + screen.height - 3 - rect.height) - gScreenY;
|
|
|
|
ok(rect.top == pos || rect.top == availPos,
|
|
|
|
gTests[gTestIndex] + " top");
|
|
|
|
break;
|
|
|
|
case "context menu larger than screen":
|
2009-01-14 10:23:09 -08:00
|
|
|
ok(rect.top == -(gScreenY - screen.availTop) || rect.top == -(gScreenY - screen.top), gTests[gTestIndex] + " top");
|
2009-01-06 11:21:23 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
popup.hidePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuPopupHidden()
|
|
|
|
{
|
|
|
|
var screenAvailBottom = screen.availTop + screen.availHeight;
|
|
|
|
|
|
|
|
var desiredHeight = -1;
|
|
|
|
if (gTests[gTestIndex] == "context menu more space above") {
|
|
|
|
window.moveTo(window.screenX, screenAvailBottom - 80);
|
|
|
|
}
|
|
|
|
if (gTests[gTestIndex] == "context menu too big either side") {
|
|
|
|
window.moveTo(window.screenX, screenAvailBottom / 2 - 80);
|
|
|
|
desiredHeight = screenAvailBottom / 2 + 120;
|
|
|
|
}
|
|
|
|
else if (gTests[gTestIndex] == "context menu larger than screen") {
|
|
|
|
desiredHeight = screen.availHeight + 80;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desiredHeight >= 0) {
|
|
|
|
var popup = document.getElementById("popup");
|
|
|
|
var height = popup.getBoundingClientRect().height;
|
|
|
|
var itemheight = document.getElementById("firstitem").getBoundingClientRect().height;
|
|
|
|
while (height < desiredHeight) {
|
|
|
|
var menu = document.createElement("menuitem");
|
|
|
|
menu.setAttribute("label", "Item");
|
|
|
|
popup.appendChild(menu);
|
|
|
|
height += itemheight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
synthesizeMouse(document.getElementById("label"), 4, 4, { type: "contextmenu", button: 2 });
|
|
|
|
}
|
|
|
|
|
2009-02-17 07:51:11 -08:00
|
|
|
function testPopupMovement()
|
|
|
|
{
|
|
|
|
var button = document.getElementById("label");
|
|
|
|
var popup = document.getElementById((gTests[gTestIndex] == "panel movement") ? "panel" : "popup");
|
|
|
|
|
2009-04-22 05:55:49 -07:00
|
|
|
var screenX, screenY, buttonScreenX, buttonScreenY;
|
2009-02-17 07:51:11 -08:00
|
|
|
var rect = popup.getBoundingClientRect();
|
|
|
|
|
|
|
|
var overlapOSChrome = (navigator.platform.indexOf("Mac") == -1);
|
|
|
|
popup.moveTo(1, 1);
|
2009-04-22 05:55:49 -07:00
|
|
|
[screenX, screenY] = getScreenXY(popup);
|
|
|
|
|
|
|
|
var expectedx = overlapOSChrome ? 1 : (screen.availLeft < 1 ? 1 : screen.availLeft);
|
|
|
|
var expectedy = overlapOSChrome ? 1 : (screen.availTop < 1 ? 1 : screen.availTop);
|
|
|
|
is(screenX, expectedx, gTests[gTestIndex] + " (1, 1) x");
|
|
|
|
is(screenY, expectedy, gTests[gTestIndex] + " (1, 1) y");
|
2009-02-17 07:51:11 -08:00
|
|
|
|
|
|
|
popup.moveTo(100, 8000);
|
|
|
|
var expectedy = (overlapOSChrome ? screen.height + screen.top : screen.availHeight + screen.availTop) -
|
|
|
|
Math.round(rect.height) - 3;
|
2009-04-22 05:55:49 -07:00
|
|
|
[screenX, screenY] = getScreenXY(popup);
|
|
|
|
is(screenX, 100, gTests[gTestIndex] + " (100, 8000) x");
|
|
|
|
is(screenY, expectedy, gTests[gTestIndex] + " (100, 8000) y");
|
2009-02-17 07:51:11 -08:00
|
|
|
|
|
|
|
popup.moveTo(6000, 100);
|
2009-04-22 05:55:49 -07:00
|
|
|
expectedx = (overlapOSChrome ? screen.width + screen.left : screen.availWidth + screen.availLeft) -
|
|
|
|
Math.round(rect.width) - 3;
|
|
|
|
|
|
|
|
[screenX, screenY] = getScreenXY(popup);
|
|
|
|
is(screenX, expectedx, gTests[gTestIndex] + " (6000, 100) x");
|
|
|
|
is(screenY, 100, gTests[gTestIndex] + " (6000, 100) y");
|
2009-02-17 07:51:11 -08:00
|
|
|
|
|
|
|
is(popup.left, "", gTests[gTestIndex] + " left is empty after moving");
|
|
|
|
is(popup.top, "", gTests[gTestIndex] + " top is empty after moving");
|
|
|
|
popup.setAttribute("left", "80");
|
|
|
|
popup.setAttribute("top", "82");
|
2009-04-22 05:55:49 -07:00
|
|
|
[screenX, screenY] = getScreenXY(popup);
|
|
|
|
is(screenX, 80, gTests[gTestIndex] + " set left and top x");
|
|
|
|
is(screenY, 82, gTests[gTestIndex] + " set left and top y");
|
2009-02-17 07:51:11 -08:00
|
|
|
popup.moveTo(95, 98);
|
2009-04-22 05:55:49 -07:00
|
|
|
[screenX, screenY] = getScreenXY(popup);
|
|
|
|
is(screenX, 95, gTests[gTestIndex] + " move after set left and top x");
|
|
|
|
is(screenY, 98, gTests[gTestIndex] + " move after set left and top y");
|
2009-02-17 07:51:11 -08:00
|
|
|
is(popup.left, "95", gTests[gTestIndex] + " left is set after moving");
|
|
|
|
is(popup.top, "98", gTests[gTestIndex] + " top is set after moving");
|
|
|
|
popup.removeAttribute("left");
|
|
|
|
popup.removeAttribute("top");
|
|
|
|
|
|
|
|
popup.moveTo(-1, -1);
|
2009-04-22 05:55:49 -07:00
|
|
|
[screenX, screenY] = getScreenXY(popup);
|
|
|
|
[buttonScreenX, buttonScreenY] = getScreenXY(button);
|
|
|
|
is(screenX, buttonScreenX, gTests[gTestIndex] + " original x");
|
|
|
|
is(screenY, buttonScreenY + button.getBoundingClientRect().height, gTests[gTestIndex] + " original y");
|
2009-02-17 07:51:11 -08:00
|
|
|
|
|
|
|
popup.hidePopup();
|
|
|
|
}
|
|
|
|
|
2009-09-03 12:30:06 -07:00
|
|
|
window.opener.wrappedJSObject.SimpleTest.waitForFocus(runTests, window);
|
|
|
|
|
2007-08-08 07:11:11 -07:00
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
|
2009-01-06 11:21:23 -08:00
|
|
|
<button id="label" label="OK" context="popup"/>
|
2007-08-08 07:11:11 -07:00
|
|
|
<menupopup id="popup" onpopupshown="popupShown();" onpopuphidden="popupHidden();"
|
|
|
|
onoverflow="gOverflowed = true" onunderflow="gUnderflowed = true;">
|
2009-01-06 11:21:23 -08:00
|
|
|
<menuitem id="firstitem" label="1"/>
|
2007-08-08 07:11:11 -07:00
|
|
|
<menuitem label="2"/>
|
|
|
|
<menuitem label="3"/>
|
|
|
|
<menuitem label="4"/>
|
|
|
|
<menuitem label="5"/>
|
|
|
|
<menuitem label="6"/>
|
|
|
|
<menuitem label="7"/>
|
|
|
|
<menuitem label="8"/>
|
|
|
|
<menuitem label="9"/>
|
|
|
|
<menuitem label="10"/>
|
|
|
|
<menuitem label="11"/>
|
|
|
|
<menuitem label="12"/>
|
|
|
|
<menuitem label="13"/>
|
|
|
|
<menuitem label="14"/>
|
|
|
|
<menuitem label="15"/>
|
|
|
|
</menupopup>
|
|
|
|
|
2009-04-22 05:55:49 -07:00
|
|
|
<panel id="panel" onpopupshown="testPopupMovement();" onpopuphidden="popupHidden();" style="margin: 0">
|
2009-02-17 07:51:11 -08:00
|
|
|
<button label="OK"/>
|
|
|
|
</panel>
|
|
|
|
|
2007-08-08 07:11:11 -07:00
|
|
|
</window>
|