Bug 388995, 279703, XUL popup tests, r+sr=bz

This commit is contained in:
enndeakin@sympatico.ca 2007-08-03 07:06:16 -07:00
parent 34f05d991b
commit e9443c48b4
17 changed files with 2185 additions and 0 deletions

View File

@ -54,6 +54,8 @@ _TEST_FILES = bug288254_window.xul \
test_bug366992.xul \
bug331215_window.xul \
test_bug331215.xul \
test_popup_preventdefault_chrome.xul \
window_popup_preventdefault_chrome.xul \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Popup Attribute Tests"
onload="setTimeout(runTest, 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Attribute Tests</title>
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script>
SimpleTest.waitForExplicitFinish();
function runTest()
{
window.open("window_popup_preventdefault_chrome.xul", "_new", "chrome,width=600,height=600");
}
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@ -0,0 +1,75 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Popup Prevent Default Tests"
onload="setTimeout(runTest, 0);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Prevent Default Tests</title>
<!--
This tests checks that preventDefault can be called on a popupshowing
event or popuphiding event to prevent the default behaviour.
-->
<script>
var gBlockShowing = true;
var gBlockHiding = true;
var gShownNotAllowed = true;
var gHiddenNotAllowed = true;
function runTest()
{
document.getElementById("menu").open = true;
}
function popupShowing(event)
{
if (gBlockShowing) {
event.preventDefault();
gBlockShowing = false;
setTimeout(function() {
gShownNotAllowed = false;
document.getElementById("menu").open = true;
}, 3000, true);
}
}
function popupShown()
{
window.opener.wrappedJSObject.SimpleTest.ok(!gShownNotAllowed, "popupshowing preventDefault");
document.getElementById("menu").open = false;
}
function popupHiding(event)
{
if (gBlockHiding) {
event.preventDefault();
gBlockHiding = false;
setTimeout(function() {
gHiddenNotAllowed = false;
document.getElementById("menu").open = false;
}, 3000, true);
}
}
function popupHidden()
{
window.opener.wrappedJSObject.SimpleTest.ok(!gHiddenNotAllowed, "popuphiding preventDefault");
window.opener.wrappedJSObject.SimpleTest.finish();
window.close();
}
</script>
<button id="menu" type="menu" label="Menu">
<menupopup onpopupshowing="popupShowing(event);"
onpopupshown="popupShown();"
onpopuphiding="popupHiding(event);"
onpopuphidden="popupHidden();">
<menuitem label="Item"/>
</menupopup>
</button>
</window>

View File

@ -51,6 +51,17 @@ _TEST_FILES = test_bug360220.xul \
test_menulist_keynav.xul \
test_popup_coords.xul \
test_popup_recreate.xul \
test_popup_button.xul \
test_menuchecks.xul \
test_popup_attribute.xul \
test_popup_preventdefault.xul \
test_tooltip.xul \
popup_shared.js \
popup_trigger.js \
window_popup_button.xul \
window_menuchecks.xul \
window_popup_attribute.xul \
window_tooltip.xul \
test_progressmeter.xul \
# Disabled until we can figure out why they're causing failures on the Windows
# unit test box (bug 389616)
@ -58,5 +69,10 @@ _TEST_FILES = test_bug360220.xul \
# test_timepicker.xul \
$(NULL)
ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
_TEST_FILES += test_menubar.xul \
window_menubar.xul
endif
libs:: $(_TEST_FILES)
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

View File

@ -0,0 +1,296 @@
/*
* This script is used for menu and popup tests. Call startPopupTests to start
* the tests, passing an array of tests as an argument. Each test is an object
* with the following properties:
* testname - name of the test
* test - function to call to perform the test
* events - a list of events that are expected to be fired in sequence
* as a result of calling the 'test' function. This list should be
* an array of strings of the form "eventtype targetid" where
* 'eventtype' is the event type and 'targetid' is the id of
* target of the event. This function will be passed two
* arguments, the testname and the step argument.
* Alternatively, events may be a function which returns the array
* of events. This can be used when the events vary per platform.
* result - function to call after all the events have fired to check
* for additional results. May be null. This function will be
* passed two arguments, the testname and the step argument.
* steps - optional array of values. The test will be repeated for
* each step, passing each successive value within the array to
* the test and result functions
* autohide - if set, should be set to the id of a popup to hide after
* the test is complete. This is a convenience for some tests.
* condition - an optional function which, if it returns false, causes the
* test to be skipped.
* end - used for debugging. Set to true to stop the tests after running
* this one.
*/
const menuactiveAttribute = "_moz-menuactive";
var gPopupTests = null;
var gTestIndex = -1;
var gTestStepIndex = 0;
var gTestEventIndex = 0;
var gAutoHide = false;
var gExpectedEventDetails = null;
function startPopupTests(tests)
{
document.addEventListener("popupshowing", eventOccured, false);
document.addEventListener("popupshown", eventOccured, false);
document.addEventListener("popuphiding", eventOccured, false);
document.addEventListener("popuphidden", eventOccured, false);
document.addEventListener("command", eventOccured, false);
document.addEventListener("DOMMenuItemActive", eventOccured, false);
document.addEventListener("DOMMenuItemInactive", eventOccured, false);
document.addEventListener("DOMMenuInactive", eventOccured, false);
document.addEventListener("DOMMenuBarActive", eventOccured, false);
document.addEventListener("DOMMenuBarInactive", eventOccured, false);
gPopupTests = tests;
goNext();
}
function finish()
{
window.close();
window.opener.SimpleTest.finish();
}
function ok(condition, message) {
window.opener.SimpleTest.ok(condition, message);
}
function is(left, right, message) {
window.opener.SimpleTest.is(left, right, message);
}
function eventOccured(event)
{
if (gPopupTests.length <= gTestIndex) {
ok(false, "Extra " + event.type + " event fired");
return;
}
var test = gPopupTests[gTestIndex];
if ("autohide" in test && gAutoHide) {
if (event.type == "DOMMenuInactive") {
gAutoHide = false;
setTimeout(goNextStep, 0);
}
return;
}
var events = test.events;
if (typeof events == "function")
events = events();
if (events) {
if (events.length <= gTestEventIndex) {
ok(false, "Extra " + event.type + " event fired " + gPopupTests[gTestIndex].testname);
return;
}
var eventitem = events[gTestEventIndex].split(" ");
var matches = (eventitem[1] == "#tooltip") ?
(event.originalTarget.localName == "tooltip" &&
event.originalTarget.getAttribute("default") == "true") :
(eventitem[0] == event.type && eventitem[1] == event.target.id);
ok(matches, test.testname + " " + event.type + " fired");
if (matches) {
gTestEventIndex++
if (events.length <= gTestEventIndex)
setTimeout(checkResult, 0);
}
}
}
function checkResult()
{
var step = null;
var test = gPopupTests[gTestIndex];
if ("steps" in test)
step = test.steps[gTestStepIndex];
if ("result" in test)
test.result(test.testname, step);
if ("autohide" in test) {
gAutoHide = true;
document.getElementById(test.autohide).hidePopup();
return;
}
goNextStep();
}
function goNextStep()
{
gTestEventIndex = 0;
var step = null;
var test = gPopupTests[gTestIndex];
if ("steps" in test) {
gTestStepIndex++;
step = test.steps[gTestStepIndex];
if (gTestStepIndex < test.steps.length) {
test.test(test.testname, step);
return;
}
}
goNext();
}
function goNext()
{
if (gTestIndex >= 0 && "end" in gPopupTests[gTestIndex] && gPopupTests[gTestIndex].end) {
finish();
return;
}
gTestIndex++;
gTestStepIndex = 0;
if (gTestIndex < gPopupTests.length) {
var test = gPopupTests[gTestIndex]
// skip the test if the condition returns false
if ("condition" in test && !test.condition()) {
goNext();
return;
}
// start with the first step if there are any
var step = null;
if ("steps" in test)
step = test.steps[gTestStepIndex];
test.test(test.testname, step);
// no events to check for so just check the result
if (!("events" in test))
checkResult();
}
else {
finish();
}
}
function openMenu(menu)
{
if ("open" in menu) {
menu.open = true;
}
else {
var bo = menu.boxObject;
if (bo instanceof Components.interfaces.nsIMenuBoxObject)
bo.openMenu(true);
else
synthesizeMouse(menu, 4, 4, { });
}
}
function closeMenu(menu, popup)
{
if ("open" in menu) {
menu.open = false;
}
else {
var bo = menu.boxObject;
if (bo instanceof Components.interfaces.nsIMenuBoxObject)
bo.openMenu(false);
else
popup.hidePopup();
}
}
function checkActive(popup, id, testname)
{
var activeok = true;
var children = popup.childNodes;
for (var c = 0; c < children.length; c++) {
var child = children[c];
if ((id == child.id && child.getAttribute(menuactiveAttribute) != "true") ||
(id != child.id && child.hasAttribute(menuactiveAttribute) != "")) {
activeok = false;
break;
}
}
ok(activeok, testname + " item " + (id ? id : "none") + " active");
}
function checkOpen(menuid, testname)
{
var menu = document.getElementById(menuid);
if ("open" in menu)
ok(menu.open, testname + " " + menuid + " menu is open");
else if (menu.boxObject instanceof Components.interfaces.nsIMenuBoxObject)
ok(menu.getAttribute("open") == "true", testname + " " + menuid + " menu is open");
}
function checkClosed(menuid, testname)
{
var menu = document.getElementById(menuid);
if ("open" in menu)
ok(!menu.open, testname + " " + menuid + " menu is open");
else if (menu.boxObject instanceof Components.interfaces.nsIMenuBoxObject)
ok(!menu.hasAttribute("open"), testname + " " + menuid + " menu is closed");
}
function convertPosition(anchor, align)
{
if (anchor == "topleft" && align == "topleft") return "overlap";
if (anchor == "topleft" && align == "topright") return "start_before";
if (anchor == "topleft" && align == "bottomleft") return "before_start";
if (anchor == "topright" && align == "topleft") return "end_before";
if (anchor == "topright" && align == "bottomright") return "before_end";
if (anchor == "bottomleft" && align == "bottomright") return "start_after";
if (anchor == "bottomleft" && align == "topleft") return "after_start";
if (anchor == "bottomright" && align == "bottomleft") return "end_after";
if (anchor == "bottomright" && align == "topright") return "after_end";
return "";
}
function compareEdge(anchor, popup, edge, offsetX, offsetY, testname)
{
testname += " " + edge;
checkOpen(anchor.id, testname);
var anchorrect = anchor.getBoundingClientRect();
var popuprect = popup.getBoundingClientRect();
var check1 = false, check2 = false;
ok((Math.round(popuprect.right) - Math.round(popuprect.left)) &&
(Math.round(popuprect.bottom) - Math.round(popuprect.top)),
testname + " size");
if (edge == "overlap") {
ok(Math.round(anchorrect.left) + offsetY == Math.round(popuprect.left) &&
Math.round(anchorrect.top) + offsetY == Math.round(popuprect.top),
testname + " position");
return;
}
if (edge.indexOf("before") == 0)
check1 = (Math.round(anchorrect.top) + offsetY == Math.round(popuprect.bottom));
else if (edge.indexOf("after") == 0)
check1 = (Math.round(anchorrect.bottom) + offsetY == Math.round(popuprect.top));
else if (edge.indexOf("start") == 0)
check1 = (Math.round(anchorrect.left) + offsetX == Math.round(popuprect.right));
else if (edge.indexOf("end") == 0)
check1 = (Math.round(anchorrect.right) + offsetX == Math.round(popuprect.left));
if (0 < edge.indexOf("before"))
check2 = (Math.round(anchorrect.top) + offsetY == Math.round(popuprect.top));
else if (0 < edge.indexOf("after"))
check2 = (Math.round(anchorrect.bottom) + offsetY == Math.round(popuprect.bottom));
else if (0 < edge.indexOf("start"))
check2 = (Math.round(anchorrect.left) + offsetX == Math.round(popuprect.left));
else if (0 < edge.indexOf("end"))
check2 = (Math.round(anchorrect.right) + offsetX == Math.round(popuprect.right));
ok(check1 && check2, testname + " position");
}

View File

@ -0,0 +1,631 @@
var gMenuPopup = null;
var gTrigger = null;
var gIsMenu = false;
var gScreenX = -1, gScreenY = -1;
function runTests()
{
gMenuPopup = document.getElementById("thepopup");
gTrigger = document.getElementById("trigger");
gIsMenu = gTrigger.boxObject instanceof Components.interfaces.nsIMenuBoxObject;
var mouseFn = function(event) {
gScreenX = event.screenX;
gScreenY = event.screenY;
}
// a hacky way to get the screen position of the document
window.addEventListener("mousedown", mouseFn, false);
synthesizeMouse(document.documentElement, 0, 0, { });
window.removeEventListener("mousedown", mouseFn, false);
startPopupTests(popupTests);
}
var popupTests = [
{
testname: "mouse click on trigger",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function() { synthesizeMouse(gTrigger, 4, 4, { }); },
result: function (testname) {
checkActive(gMenuPopup, "", testname);
checkOpen("trigger", testname);
// if a menu, the popup should be opened underneath the menu in the
// 'after_start' position, otherwise it is opened at the mouse position
if (gIsMenu)
compareEdge(gTrigger, gMenuPopup, "after_start", 0, 0, testname);
}
},
{
// check that pressing cursor down while there is no selection
// highlights the first item
testname: "cursor down no selection",
events: [ "DOMMenuItemActive item1" ],
test: function() { synthesizeKey("VK_DOWN", { }); },
result: function(testname) { checkActive(gMenuPopup, "item1", testname); }
},
{
// check that pressing cursor up wraps and highlights the last item
testname: "cursor up wrap",
events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive last" ],
test: function() { synthesizeKey("VK_UP", { }); },
result: function(testname) {
checkActive(gMenuPopup, "last", testname);
}
},
{
// check that pressing cursor down wraps and highlights the first item
testname: "cursor down wrap",
events: [ "DOMMenuItemInactive last", "DOMMenuItemActive item1" ],
test: function() { synthesizeKey("VK_DOWN", { }); },
result: function(testname) { checkActive(gMenuPopup, "item1", testname); }
},
{
// check that pressing cursor down highlights the second item
testname: "cursor down",
events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive item2" ],
test: function() { synthesizeKey("VK_DOWN", { }); },
result: function(testname) { checkActive(gMenuPopup, "item2", testname); }
},
{
// check that pressing cursor up highlights the second item
testname: "cursor up",
events: [ "DOMMenuItemInactive item2", "DOMMenuItemActive item1" ],
test: function() { synthesizeKey("VK_UP", { }); },
result: function(testname) { checkActive(gMenuPopup, "item1", testname); }
},
{
// cursor left should not do anything
testname: "cursor left",
test: function() { synthesizeKey("VK_LEFT", { }); },
result: function(testname) { checkActive(gMenuPopup, "item1", testname); }
},
{
// cursor right should not do anything
testname: "cursor right",
test: function() { synthesizeKey("VK_RIGHT", { }); },
result: function(testname) { checkActive(gMenuPopup, "item1", testname); }
},
{
// check cursor down when a disabled item exists in the menu
testname: "cursor down disabled",
events: function() {
// On Windows, disabled items are included when navigating, but on
// other platforms, disabled items are skipped over
if (navigator.platform.indexOf("Win") == 0)
return [ "DOMMenuItemInactive item1", "DOMMenuItemActive item2" ];
else
return [ "DOMMenuItemInactive item1", "DOMMenuItemActive amenu" ];
},
test: function() {
document.getElementById("item2").disabled = true;
synthesizeKey("VK_DOWN", { });
}
},
{
// check cursor up when a disabled item exists in the menu
testname: "cursor up disabled",
events: function() {
if (navigator.platform.indexOf("Win") == 0)
return [ "DOMMenuItemInactive item2", "DOMMenuItemActive amenu",
"DOMMenuItemInactive amenu", "DOMMenuItemActive item2",
"DOMMenuItemInactive item2", "DOMMenuItemActive item1" ];
else
return [ "DOMMenuItemInactive amenu", "DOMMenuItemActive item1" ];
},
test: function() {
if (navigator.platform.indexOf("Win") == 0)
synthesizeKey("VK_DOWN", { });
synthesizeKey("VK_UP", { });
if (navigator.platform.indexOf("Win") == 0)
synthesizeKey("VK_UP", { });
}
},
{
testname: "mouse click outside",
events: [ "popuphiding thepopup", "popuphidden thepopup",
"DOMMenuItemInactive item1", "DOMMenuInactive thepopup" ],
test: function() {
gMenuPopup.hidePopup();
// XXXndeakin event simulation fires events outside of the platform specific
// widget code so the popup capturing isn't handled. Thus, the menu won't
// rollup this way.
// synthesizeMouse(gTrigger, 0, -12, { });
},
result: function(testname, step) { checkClosed("trigger", testname); }
},
{
// these tests check to ensure that passing an anchor and position
// puts the popup in the right place
testname: "open popup anchored",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
steps: ["before_start", "before_end", "after_start", "after_end",
"start_before", "start_after", "end_before", "end_after", "overlap"],
test: function(testname, step) { gMenuPopup.openPopup(gTrigger, step, 0, 0, false, false); },
result: function(testname, step) { compareEdge(gTrigger, gMenuPopup, step, 0, 0, testname); }
},
{
// these tests check to ensure that the position attribute can be used
// to set the position of a popup instead of passing it as an argument
testname: "open popup anchored with attribute",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
steps: ["before_start", "before_end", "after_start", "after_end",
"start_before", "start_after", "end_before", "end_after", "overlap"],
test: function(testname, step) {
gMenuPopup.setAttribute("position", step);
gMenuPopup.openPopup(gTrigger, "", 0, 0, false, false);
},
result: function(testname, step) { compareEdge(gTrigger, gMenuPopup, step, 0, 0, testname); }
},
{
// this test checks to ensure that attributes override flag to openPopup
// can be used to override the popup's position
testname: "open popup anchored with override",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function(testname, step) {
// attribute overrides the position passed in
gMenuPopup.setAttribute("position", "end_after");
gMenuPopup.openPopup(gTrigger, "before_start", 0, 0, false, true);
},
result: function(testname, step) { compareEdge(gTrigger, gMenuPopup, "end_after", 0, 0, testname); }
},
{
testname: "close popup with escape",
events: [ "popuphiding thepopup", "popuphidden thepopup",
"DOMMenuInactive thepopup", ],
test: function(testname, step) {
synthesizeKey("VK_ESCAPE", { });
checkClosed("trigger", testname);
}
},
{
// check that offsets may be supplied to the openPopup method
testname: "open popup anchored with offsets",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
test: function(testname, step) {
// attribute is empty so does not override
gMenuPopup.setAttribute("position", "");
gMenuPopup.openPopup(gTrigger, "before_start", 5, 10, true, true);
},
result: function(testname, step) { compareEdge(gTrigger, gMenuPopup, "before_start", 5, 10, testname); }
},
{
// these tests check to ensure that passing an anchor and position
// puts the popup in the right place
testname: "show popup anchored",
condition: function() {
// only perform this test for popups not in a menu, such as those using
// the popup attribute, as the showPopup implementation in popup.xml
// calls openMenu if the popup is inside a menu
return !gIsMenu;
},
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
steps: [["topleft", "topleft"],
["topleft", "topright"], ["topleft", "bottomleft"],
["topright", "topleft"], ["topright", "bottomright"],
["bottomleft", "bottomright"], ["bottomleft", "topleft"],
["bottomright", "bottomleft"], ["bottomright", "topright"]],
test: function(testname, step) {
// the attributes should be ignored
gMenuPopup.setAttribute("popupanchor", "topright");
gMenuPopup.setAttribute("popupalign", "bottomright");
gMenuPopup.setAttribute("position", "end_after");
gMenuPopup.showPopup(gTrigger, -1, -1, "popup", step[0], step[1]);
},
result: function(testname, step) {
var pos = convertPosition(step[0], step[1]);
compareEdge(gTrigger, gMenuPopup, pos, 0, 0, testname);
gMenuPopup.removeAttribute("popupanchor");
gMenuPopup.removeAttribute("popupalign");
gMenuPopup.removeAttribute("position");
}
},
{
testname: "show popup with position",
condition: function() { return !gIsMenu; },
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
test: function(testname, step) {
gMenuPopup.showPopup(gTrigger, gScreenX + 60, gScreenY + 15,
"context", "topleft", "bottomright");
},
result: function(testname, step) {
var rect = gMenuPopup.getBoundingClientRect();
ok(rect.left == 60 && rect.top == 15 && rect.right && rect.bottom, testname);
}
},
{
// if no anchor is supplied to openPopup, it should be opened relative
// to the viewport.
testname: "open popup unanchored",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function(testname, step) { gMenuPopup.openPopup(null, "after_start", 6, 8, false); },
result: function(testname, step) {
var rect = gMenuPopup.getBoundingClientRect();
ok(rect.left == 6 && rect.top == 8 && rect.right && rect.bottom, testname);
}
},
{
testname: "activate menuitem with mouse",
events: [ "DOMMenuInactive thepopup", "command item3", "DOMMenuItemInactive item3",
"popuphiding thepopup", "popuphidden thepopup" ],
test: function(testname, step) {
var item3 = document.getElementById("item3");
synthesizeMouse(item3, 4, 4, { });
},
result: function(testname, step) { checkClosed("trigger", testname); }
},
{
testname: "close popup",
condition: function() { return false; },
events: [ "popuphiding thepopup", "popuphidden thepopup",
"DOMMenuInactive thepopup" ],
test: function(testname, step) { gMenuPopup.hidePopup(); }
},
{
testname: "open popup at screen",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function(testname, step) {
gMenuPopup.openPopupAtScreen(gScreenX + 24, gScreenY + 20, false);
},
result: function(testname, step) {
var rect = gMenuPopup.getBoundingClientRect();
ok(rect.left == 24 && rect.top == 20 && rect.right && rect.bottom, testname);
}
},
{
// check that pressing a menuitem's accelerator selects it. Note that
// the menuitem with the M accesskey overrides the earlier menuitem that
// begins with M.
testname: "menuitem accelerator",
events: [ "DOMMenuItemActive amenu", "DOMMenuItemInactive amenu",
"DOMMenuInactive thepopup",
"command amenu", "DOMMenuItemInactive amenu",
"popuphiding thepopup", "popuphidden thepopup",
],
test: function() { synthesizeKey("M", { }); },
result: function(testname) { checkClosed("trigger", testname); }
},
{
testname: "open context popup at screen",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function(testname, step) {
gMenuPopup.openPopupAtScreen(gScreenX + 8, gScreenY + 16, false);
},
result: function(testname, step) {
var rect = gMenuPopup.getBoundingClientRect();
ok(rect.left == 8 && rect.top == 16 && rect.right && rect.bottom, testname);
}
},
{
// pressing a letter that doesn't correspond to an accelerator, but does
// correspond to the first letter in a menu's label. The menu should not
// close because there is more than one item corresponding to that letter
testname: "menuitem with non accelerator",
events: [ "DOMMenuItemActive one" ],
test: function() { synthesizeKey("O", { }); },
result: function(testname) {
checkOpen("trigger", testname);
checkActive(gMenuPopup, "one", testname);
}
},
{
// pressing the letter again should select the next one that starts with
// that letter
testname: "menuitem with non accelerator again",
events: [ "DOMMenuItemInactive one", "DOMMenuItemActive submenu" ],
test: function() { synthesizeKey("O", { }); },
result: function(testname) {
// 'submenu' is a menu but it should not be open
checkOpen("trigger", testname);
checkClosed("submenu", testname);
checkActive(gMenuPopup, "submenu", testname);
}
},
{
// open the submenu with the cursor right key
testname: "open submenu with cursor right",
events: [ "popupshowing submenupopup", "DOMMenuItemActive submenuitem",
"popupshown submenupopup" ],
test: function() { synthesizeKey("VK_RIGHT", { }); },
result: function(testname) {
checkOpen("trigger", testname);
checkOpen("submenu", testname);
checkActive(gMenuPopup, "submenu", testname);
checkActive(document.getElementById("submenupopup"), "submenuitem", testname);
}
},
{
// close the submenu with the cursor left key
testname: "close submenu with cursor left",
events: [ "popuphiding submenupopup", "popuphidden submenupopup",
"DOMMenuItemInactive submenuitem", "DOMMenuInactive submenupopup",
"DOMMenuItemActive submenu" ],
test: function() { synthesizeKey("VK_LEFT", { }); },
result: function(testname) {
checkOpen("trigger", testname);
checkClosed("submenu", testname);
checkActive(gMenuPopup, "submenu", testname);
checkActive(document.getElementById("submenupopup"), "", testname);
}
},
{
// open the submenu with the enter key
testname: "open submenu with enter",
events: [ "popupshowing submenupopup", "DOMMenuItemActive submenuitem",
"popupshown submenupopup" ],
test: function() { synthesizeKey("VK_ENTER", { }); },
result: function(testname) {
checkOpen("trigger", testname);
checkOpen("submenu", testname);
checkActive(gMenuPopup, "submenu", testname);
checkActive(document.getElementById("submenupopup"), "submenuitem", testname);
}
},
{
// close the submenu with the escape key
testname: "close submenu with escape",
events: [ "popuphiding submenupopup", "popuphidden submenupopup",
"DOMMenuItemInactive submenuitem", "DOMMenuInactive submenupopup",
"DOMMenuItemActive submenu" ],
test: function() { synthesizeKey("VK_ESCAPE", { }); },
result: function(testname) {
checkOpen("trigger", testname);
checkClosed("submenu", testname);
checkActive(gMenuPopup, "submenu", testname);
checkActive(document.getElementById("submenupopup"), "", testname);
}
},
{
// pressing the letter again when the next item is disabled should still
// select the disabled item on Windows, but select the next item on other
// platforms
testname: "menuitem with non accelerator disabled",
events: function() {
if (navigator.platform.indexOf("Win") == 0)
return [ "DOMMenuItemInactive submenu", "DOMMenuItemActive other",
"DOMMenuItemInactive other", "DOMMenuItemActive item1" ];
else
return [ "DOMMenuItemInactive submenu", "DOMMenuItemActive last",
"DOMMenuItemInactive last", "DOMMenuItemActive item1" ];
},
test: function() { synthesizeKey("O", { }); synthesizeKey("F", { }); },
result: function(testname) {
checkActive(gMenuPopup, "item1", testname);
}
},
{
// pressing a letter that doesn't correspond to an accelerator nor the
// first letter of a menu. This should have no effect.
testname: "menuitem with keypress no accelerator found",
test: function() { synthesizeKey("G", { }); },
result: function(testname) {
checkOpen("trigger", testname);
checkActive(gMenuPopup, "item1", testname);
}
},
{
// when only one menuitem starting with that letter exists, it should be
// selected and the menu closed
testname: "menuitem with non accelerator single",
events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive amenu",
"DOMMenuItemInactive amenu", "DOMMenuInactive thepopup",
"command amenu", "DOMMenuItemInactive amenu",
"popuphiding thepopup", "popuphidden thepopup",
],
test: function() { synthesizeKey("M", { }); },
result: function(testname) {
checkClosed("trigger", testname);
checkActive(gMenuPopup, "", testname);
}
},
{
testname: "open popup with open property",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function(testname, step) { openMenu(gTrigger); },
result: function(testname, step) {
checkOpen("trigger", testname);
if (gIsMenu)
compareEdge(gTrigger, gMenuPopup, "after_start", 0, 0, testname);
}
},
{ end: true,
testname: "open submenu with open property",
events: [ "popupshowing submenupopup", "DOMMenuItemActive submenu",
"popupshown submenupopup" ],
test: function(testname, step) { openMenu(document.getElementById("submenu")); },
result: function(testname, step) {
checkOpen("trigger", testname);
checkOpen("submenu", testname);
// XXXndeakin
// getBoundingClientRect doesn't seem to working right for submenus
// so disable this test for now
// compareEdge(document.getElementById("submenu"),
// document.getElementById("submenupopup"), "end_before", 0, 0, testname);
}
},
{
testname: "hidePopup hides entire chain",
events: [ "popuphiding submenupopup", "popuphidden submenupopup",
"popuphiding thepopup", "popuphidden thepopup",
"DOMMenuInactive submenupopup",
"DOMMenuItemInactive submenu", "DOMMenuItemInactive submenu",
"DOMMenuInactive thepopup", ],
test: function() { gMenuPopup.hidePopup(); },
result: function(testname, step) {
checkClosed("trigger", testname);
checkClosed("submenu", testname);
}
},
{
testname: "open submenu with open property without parent open",
test: function(testname, step) { openMenu(document.getElementById("submenu")); },
result: function(testname, step) {
checkClosed("trigger", testname);
checkClosed("submenu", testname);
}
},
{
testname: "open popup with open property and position",
condition: function() { return gIsMenu; },
events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function(testname, step) {
gMenuPopup.setAttribute("position", "before_start");
openMenu(gTrigger);
},
result: function(testname, step) {
compareEdge(gTrigger, gMenuPopup, "before_start", 0, 0, testname);
}
},
{
testname: "close popup with open property",
condition: function() { return gIsMenu; },
events: [ "popuphiding thepopup", "popuphidden thepopup",
"DOMMenuInactive thepopup" ],
test: function(testname, step) { closeMenu(gTrigger, gMenuPopup); },
result: function(testname, step) { checkClosed("trigger", testname); }
},
{
testname: "open popup with open property, position, anchor and alignment",
condition: function() { return gIsMenu; },
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
test: function(testname, step) {
gMenuPopup.setAttribute("position", "start_after");
gMenuPopup.setAttribute("popupanchor", "topright");
gMenuPopup.setAttribute("popupalign", "bottomright");
openMenu(gTrigger);
},
result: function(testname, step) {
compareEdge(gTrigger, gMenuPopup, "start_after", 0, 0, testname);
}
},
{
testname: "open popup with open property, anchor and alignment",
condition: function() { return gIsMenu; },
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
test: function(testname, step) {
gMenuPopup.removeAttribute("position");
gMenuPopup.setAttribute("popupanchor", "bottomright");
gMenuPopup.setAttribute("popupalign", "topright");
openMenu(gTrigger);
},
result: function(testname, step) {
compareEdge(gTrigger, gMenuPopup, "after_end", 0, 0, testname);
gMenuPopup.removeAttribute("popupanchor");
gMenuPopup.removeAttribute("popupalign");
}
},
{
testname: "focus and cursor down on trigger",
condition: function() { return gIsMenu; },
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
test: function(testname, step) {
gTrigger.focus();
synthesizeKey("VK_DOWN", { altKey: (navigator.platform.indexOf("Mac") == -1) });
},
result: function(testname, step) {
checkOpen("trigger", testname);
checkActive(gMenuPopup, "", testname);
}
},
{
testname: "focus and cursor up on trigger",
condition: function() { return gIsMenu; },
events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function(testname, step) {
gTrigger.focus();
synthesizeKey("VK_UP", { altKey: (navigator.platform.indexOf("Mac") == -1) });
},
result: function(testname, step) {
checkOpen("trigger", testname);
checkActive(gMenuPopup, "", testname);
}
},
{
testname: "select and enter on menuitem",
condition: function() { return gIsMenu; },
events: [ "DOMMenuItemActive item1", "DOMMenuItemInactive item1",
"DOMMenuInactive thepopup", "command item1",
"DOMMenuItemInactive item1",
"popuphiding thepopup", "popuphidden thepopup" ],
test: function(testname, step) {
synthesizeKey("VK_DOWN", { });
synthesizeKey("VK_ENTER", { });
},
result: function(testname, step) { checkClosed("trigger", testname); }
},
{
testname: "focus trigger and key to open",
condition: function() { return gIsMenu; },
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
test: function(testname, step) {
gTrigger.focus();
synthesizeKey((navigator.platform.indexOf("Mac") == -1) ? "VK_F4" : " ", { });
},
result: function(testname, step) {
checkOpen("trigger", testname);
checkActive(gMenuPopup, "", testname);
}
},
{
// the menu should only open when the meta or alt key is not pressed
testname: "focus trigger and key wrong modifier",
condition: function() { return gIsMenu; },
test: function(testname, step) {
gTrigger.focus();
if (navigator.platform.indexOf("Mac") == -1)
synthesizeKey("", { metaKey: true });
else
synthesizeKey("VK_F4", { altKey: true });
},
result: function(testname, step) {
checkClosed("trigger", testname);
}
},
{
testname: "mouse click on disabled menu",
condition: function() { return gIsMenu; },
test: function(testname, step) {
gTrigger.setAttribute("disabled", "true");
synthesizeMouse(gTrigger, 4, 4, { });
},
result: function(testname, step) {
checkClosed("trigger", testname);
gTrigger.removeAttribute("disabled");
}
},
{
// openPopup should open the menu synchronously, however popupshown
// is fired asynchronously
testname: "openPopup synchronous",
events: [ "popupshowing thepopup", "popupshowing submenupopup",
"popupshown thepopup", "DOMMenuItemActive submenu",
"popupshown submenupopup" ],
test: function(testname, step) {
gMenuPopup.openPopup(gTrigger, "after_start", 0, 0, false, true);
document.getElementById("submenupopup").
openPopup(gTrigger, "end_before", 0, 0, false, true);
checkOpen("trigger", testname);
checkOpen("submenu", testname);
}
},
{
// remove the content nodes for the popup
testname: "remove content",
test: function(testname, step) {
var submenupopup = document.getElementById("submenupopup");
submenupopup.parentNode.removeChild(submenupopup);
var popup = document.getElementById("thepopup");
popup.parentNode.removeChild(popup);
}
},
];

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<window title="Menubar Popup Tests"
onload="setTimeout(runTest, 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Menubar Popup Tests</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script>
SimpleTest.waitForExplicitFinish();
function runTest()
{
window.open("window_menubar.xul", "_new", "width=600,height=600");
}
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@ -0,0 +1,34 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<window title="Menu Checkbox and Radio Tests"
onload="setTimeout(runTest, 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Menu Checkbox and Radio Tests</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<!--
This test checks that checkbox and radio menu items work properly
-->
<script>
SimpleTest.waitForExplicitFinish();
function runTest()
{
window.open("window_menuchecks.xul", "_new", "width=600,height=600");
}
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<window title="Popup Attribute Tests"
onload="setTimeout(runTest, 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Attribute Tests</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script>
SimpleTest.waitForExplicitFinish();
function runTest()
{
window.open("window_popup_attribute.xul", "_new", "width=600,height=600");
}
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<window title="Menu Button Popup Tests"
onload="setTimeout(runTest, 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Menu Button Popup Tests</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script>
SimpleTest.waitForExplicitFinish();
function runTest()
{
window.open("window_popup_button.xul", "_new", "width=600,height=600");
}
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@ -0,0 +1,79 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<window title="Popup Prevent Default Tests"
onload="setTimeout(runTest, 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Prevent Default Tests</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<!--
This tests checks that preventDefault can be called on a popupshowing
event and that preventDefault has no effect for the popuphiding event.
-->
<script>
SimpleTest.waitForExplicitFinish();
var gBlockShowing = true;
var gShownNotAllowed = true;
function runTest()
{
document.getElementById("menu").open = true;
}
function popupShowing(event)
{
if (gBlockShowing) {
event.preventDefault();
gBlockShowing = false;
setTimeout(function() {
gShownNotAllowed = false;
document.getElementById("menu").open = true;
}, 3000, true);
}
}
function popupShown()
{
ok(!gShownNotAllowed, "popupshowing preventDefault");
document.getElementById("menu").open = false;
}
function popupHiding(event)
{
// since this is a content test, preventDefault should have no effect
event.preventDefault();
}
function popupHidden()
{
ok(true, "popuphiding preventDefault not allowed");
SimpleTest.finish();
}
</script>
<button id="menu" type="menu" label="Menu">
<menupopup onpopupshowing="popupShowing(event);"
onpopupshown="popupShown();"
onpopuphiding="popupHiding(event);"
onpopuphidden="popupHidden();">
<menuitem label="Item"/>
</menupopup>
</button>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<window title="Tooltip Tests"
onload="setTimeout(runTest, 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Tooltip Tests</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script>
SimpleTest.waitForExplicitFinish();
function runTest()
{
window.open("window_tooltip.xul", "_new", "width=600,height=600");
}
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@ -0,0 +1,501 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Popup Tests"
onfocus="runTests()"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Tests</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="popup_shared.js"></script>
<!--
Need to investigate these tests a bit more. Some of the accessibility events
are firing multiple times or in different orders in different circumstances.
Note that this was also the case before bug 279703.
-->
<hbox style="margin-left: 275px; margin-top: 275px;">
<menubar id="menubar">
<menu id="filemenu" label="File" accesskey="F">
<menupopup id="filepopup">
<menuitem id="item1" label="Open" accesskey="O"/>
<menuitem id="item2" label="Save" accesskey="S"/>
<menuitem id="item3" label="Close" accesskey="C"/>
</menupopup>
</menu>
<menu id="secretmenu" label="Secret Menu" accesskey="S" disabled="true">
<menupopup>
<menuitem label="Secret Command" accesskey="S"/>
</menupopup>
</menu>
<menu id="editmenu" label="Edit" accesskey="E">
<menupopup id="editpopup">
<menuitem id="cut" label="Cut" accesskey="t" disabled="true"/>
<menuitem id="copy" label="Copy" accesskey="C"/>
<menuitem id="paste" label="Paste" accesskey="P"/>
</menupopup>
</menu>
<menu id="viewmenu" label="View" accesskey="V">
<menupopup id="viewpopup">
<menu id="toolbar" label="Toolbar" accesskey="T">
<menupopup id="toolbarpopup">
<menuitem id="navigation" label="Navigation" accesskey="N" disabled="true"/>
<menuitem label="Bookmarks" accesskey="B" disabled="true"/>
</menupopup>
</menu>
<menuitem label="Status Bar" accesskey="S"/>
<menu label="Sidebar" accesskey="d">
<menupopup>
<menuitem label="Bookmarks" accesskey="B"/>
<menuitem label="History" accesskey="H"/>
</menupopup>
</menu>
</menupopup>
</menu>
<menu id="helpmenu" label="Help" accesskey="H">
<menupopup id="helppopup" >
<label value="Unselectable"/>
<menuitem id="contents" label="Contents" accesskey="C"/>
<menuitem label="More Info" accesskey="I"/>
<menuitem id="amenu" label="A Menu" accesskey="M"/>
<menuitem label="Another Menu"/>
<menuitem id="one" label="One"/>
<menu id="only" label="Only Menu">
<menupopup>
<menuitem label="Test Submenu"/>
</menupopup>
</menu>
<menuitem label="Second Menu"/>
<menuitem id="other" disabled="true" label="Other Menu"/>
<menuitem id="third" label="Third Menu"/>
<menuitem label="One Other Menu"/>
<label value="Unselectable"/>
<menuitem id="about" label="About" accesskey="A"/>
</menupopup>
</menu>
</menubar>
</hbox>
<script class="testbody" type="application/javascript">
<![CDATA[
function runTests()
{
gFilePopup = document.getElementById("filepopup");
document.getElementById("filemenu").focus();
startPopupTests(popupTests);
}
var popupTests = [
{
testname: "press on menu",
events: [ "popupshowing filepopup", "DOMMenuBarActive menubar",
"DOMMenuItemActive filemenu", "popupshown filepopup" ],
test: function() { synthesizeMouse(document.getElementById("filemenu"), 8, 8, { }); },
result: function (testname) {
checkActive(gFilePopup, "", testname);
checkOpen("filemenu", testname);
}
},
{
// check that pressing cursor down while there is no selection
// highlights the first item
testname: "cursor down no selection",
events: [ "DOMMenuItemActive item1" ],
test: function() { synthesizeKey("VK_DOWN", { }); },
result: function(testname) { checkActive(gFilePopup, "item1", testname); }
},
{
// check that pressing cursor up wraps and highlights the last item
testname: "cursor up wrap",
events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive item3" ],
test: function() { synthesizeKey("VK_UP", { }); },
result: function(testname) { checkActive(gFilePopup, "item3", testname); }
},
{
// check that pressing cursor down wraps and highlights the first item
testname: "cursor down wrap",
events: [ "DOMMenuItemInactive item3", "DOMMenuItemActive item1" ],
test: function() { synthesizeKey("VK_DOWN", { }); },
result: function(testname) { checkActive(gFilePopup, "item1", testname); }
},
{
// check that pressing cursor down highlights the second item
testname: "cursor down",
events: [ "DOMMenuItemInactive item1", "DOMMenuItemActive item2" ],
test: function() { synthesizeKey("VK_DOWN", { }); },
result: function(testname) { checkActive(gFilePopup, "item2", testname); }
},
{
// check that pressing cursor up highlights the second item
testname: "cursor up",
events: [ "DOMMenuItemInactive item2", "DOMMenuItemActive item1" ],
test: function() { synthesizeKey("VK_UP", { }); },
result: function(testname) { checkActive(gFilePopup, "item1", testname); }
},
{
// cursor right should skip the disabled menu and move to the edit menu
testname: "cursor right skip disabled",
events: function() {
var elist = [
// the file menu gets deactivated, the file menu gets hidden, then
// the edit menu is activated
"DOMMenuItemInactive filemenu", "popuphiding filepopup",
"popuphidden filepopup", "DOMMenuItemActive editmenu",
// the popupshowing event gets fired when showing the edit menu.
// The item from the file menu doesn't get deactivated until the
// next item needs to be selected
"popupshowing editpopup", "DOMMenuItemInactive item1",
// not sure why the menu inactivated event is firing so late
"DOMMenuInactive filepopup", "DOMMenuBarInactive menubar",
// the new menu gets disabled and reenabled again, I suspect a
// check isn't done to see if the old value equals the new value
// somewhere
"DOMMenuItemInactive editmenu",
"DOMMenuBarActive menubar", "DOMMenuItemActive editmenu",
// finally, the first item is activated and popupshown is fired
"DOMMenuItemActive copy", "popupshown editpopup"
];
// don't skip disabled items on Windows
if (navigator.platform.indexOf("Win") == 0)
elist[elist.length - 2] = "DOMMenuItemActive cut";
return elist;
},
test: function() { synthesizeKey("VK_RIGHT", { }); },
result: function(testname) {
var expected = (navigator.platform.indexOf("Win") == 0) ? "cut" : "copy";
checkActive(document.getElementById("editpopup"), expected, testname);
checkClosed("filemenu", testname);
checkOpen("editmenu", testname);
}
},
{
// on Windows, a disabled item is selected, so pressing ENTER should close
// the menu but not fire a command event
testname: "enter on disabled",
events: function() {
if (navigator.platform.indexOf("Win") == 0)
return [ "popuphiding editpopup", "popuphidden editpopup",
"DOMMenuItemInactive cut", "DOMMenuInactive editpopup",
"DOMMenuBarInactive menubar",
"DOMMenuItemInactive editmenu", "DOMMenuItemInactive editmenu" ];
else
return [ "DOMMenuItemInactive copy", "DOMMenuInactive editpopup",
"DOMMenuBarInactive menubar",
"DOMMenuItemInactive editmenu", "DOMMenuItemInactive editmenu",
"command copy", "DOMMenuItemInactive copy",
"popuphiding editpopup", "popuphidden editpopup" ];
},
test: function() { synthesizeKey("VK_ENTER", { }); },
result: function(testname) { checkClosed("editmenu", testname); }
},
{
// pressing Alt + a key should open the corresponding menu
testname: "open with accelerator",
events: function() {
var elist = ["DOMMenuBarActive menubar",
"popupshowing viewpopup", "DOMMenuItemActive viewmenu"];
// XXXndeakin not sure why, but windows fires these in a different order
if (navigator.platform.indexOf("Win") == 0)
elist.push("popupshown viewpopup", "DOMMenuItemActive toolbar");
else
elist.push("DOMMenuItemActive toolbar", "popupshown viewpopup");
return elist;
},
test: function() { synthesizeKey("V", { altKey: true }); },
result: function(testname) { checkOpen("viewmenu", testname); }
},
{
// open the submenu with the cursor right key
testname: "open submenu with cursor right",
events: function() {
// on Windows, the disabled 'navigation' item can stll be highlihted
if (navigator.platform.indexOf("Win") == 0)
return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
"popupshown toolbarpopup" ];
else
return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
},
test: function() { synthesizeKey("VK_RIGHT", { }); },
result: function(testname) {
checkOpen("viewmenu", testname);
checkOpen("toolbar", testname);
}
},
{
// close the submenu with the cursor left key
testname: "close submenu with cursor left",
events: function() {
if (navigator.platform.indexOf("Win") == 0)
return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
"DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
"DOMMenuItemActive toolbar" ];
else
return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
"DOMMenuInactive toolbarpopup",
"DOMMenuItemActive toolbar" ];
},
test: function() { synthesizeKey("VK_LEFT", { }); },
result: function(testname) {
checkOpen("viewmenu", testname);
checkClosed("toolbar", testname);
}
},
{
// open the submenu with the enter key
testname: "open submenu with enter",
events: function() {
// on Windows, the disabled 'navigation' item can stll be highlihted
if (navigator.platform.indexOf("Win") == 0)
return [ "popupshowing toolbarpopup", "DOMMenuItemActive navigation",
"popupshown toolbarpopup" ];
else
return [ "popupshowing toolbarpopup", "popupshown toolbarpopup" ];
},
test: function() { synthesizeKey("VK_ENTER", { }); },
result: function(testname) {
checkOpen("viewmenu", testname);
checkOpen("toolbar", testname);
},
},
{
// close the submenu with the escape key
testname: "close submenu with escape",
events: function() {
if (navigator.platform.indexOf("Win") == 0)
return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
"DOMMenuItemInactive navigation", "DOMMenuInactive toolbarpopup",
"DOMMenuItemActive toolbar" ];
else
return [ "popuphiding toolbarpopup", "popuphidden toolbarpopup",
"DOMMenuInactive toolbarpopup",
"DOMMenuItemActive toolbar" ];
},
test: function() { synthesizeKey("VK_ESCAPE", { }); },
result: function(testname) {
checkOpen("viewmenu", testname);
checkClosed("toolbar", testname);
},
},
{
// close the main menu with the escape key
testname: "close menubar menu with escape",
events: [ "popuphiding viewpopup", "popuphidden viewpopup",
"DOMMenuItemInactive toolbar", "DOMMenuInactive viewpopup",
"DOMMenuBarInactive menubar",
"DOMMenuItemInactive viewmenu" ],
test: function() { synthesizeKey("VK_ESCAPE", { }); },
result: function(testname) { checkClosed("viewmenu", testname); },
},
{
// on Windows, pressing Alt should highlight the first menu but not open it
testname: "alt to activate menubar",
condition: function() { return (navigator.platform.indexOf("Win") == 0) },
events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
test: function() { synthesizeKey("VK_ALT", { }); },
result: function(testname) { checkClosed("filemenu", testname); },
},
{
// pressing cursor left should select the previous menu but not open it
testname: "cursor left on active menubar",
condition: function() { return (navigator.platform.indexOf("Win") == 0) },
events: [ "DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu" ],
test: function() { synthesizeKey("VK_LEFT", { }); },
result: function(testname) { checkClosed("helpmenu", testname); },
},
{
// pressing cursor right should select the previous menu but not open it
testname: "cursor right on active menubar",
condition: function() { return (navigator.platform.indexOf("Win") == 0) },
events: [ "DOMMenuItemInactive helpmenu", "DOMMenuItemActive filemenu" ],
test: function() { synthesizeKey("VK_RIGHT", { }); },
result: function(testname) { checkClosed("filemenu", testname); },
},
{
// pressing a character should act as an accelerator and open the menu
testname: "accelerator on active menubar",
condition: function() { return (navigator.platform.indexOf("Win") == 0) },
events: [ "popupshowing helppopup",
"DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu",
"popupshown helppopup", "DOMMenuItemActive contents" ],
test: function() { synthesizeKey("H", { }); },
result: function(testname) { checkOpen("helpmenu", testname); },
},
{
testname: "open with accelerator again",
condition: function() { return (navigator.platform.indexOf("Win") == -1) },
events: [ "DOMMenuBarActive menubar", "popupshowing helppopup",
"DOMMenuItemActive helpmenu", "DOMMenuItemActive contents",
"popupshown helppopup" ],
test: function() { synthesizeKey("H", { altKey: true }); },
result: function(testname) { checkOpen("helpmenu", testname); },
},
{
// check that pressing cursor up skips non menuitems
testname: "cursor up wrap",
events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive about" ],
test: function() { synthesizeKey("VK_UP", { }); },
result: function(testname) { }
},
{
// check that pressing cursor down skips non menuitems
testname: "cursor down wrap",
events: [ "DOMMenuItemInactive about", "DOMMenuItemActive contents" ],
test: function() { synthesizeKey("VK_DOWN", { }); },
result: function(testname) { }
},
{
// check that pressing a menuitem's accelerator selects it
testname: "menuitem accelerator",
events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive amenu",
"DOMMenuItemInactive amenu", "DOMMenuInactive helppopup",
"DOMMenuBarInactive menubar", "DOMMenuItemInactive helpmenu",
"DOMMenuItemInactive helpmenu",
"command amenu", "DOMMenuItemInactive amenu",
"popuphiding helppopup", "popuphidden helppopup",
],
test: function() { synthesizeKey("M", { }); },
result: function(testname) { checkClosed("helpmenu", testname); }
},
{
// pressing F10 should highlight the first menu but not open it
testname: "F10 to activate menubar",
events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
test: function() { synthesizeKey("VK_F10", { }); },
result: function(testname) { checkClosed("filemenu", testname); },
},
{
// pressing cursor down should open a menu
testname: "cursor down on menu",
events: [
"popupshowing helppopup",
"DOMMenuItemInactive filemenu", "DOMMenuItemActive helpmenu",
// This is in a different order than the
// "accelerator on active menubar" because menus opened from a
// shortcut key are fired asynchronously
"DOMMenuItemActive contents", "popupshown helppopup" ],
test: function() { synthesizeKey("VK_LEFT", { }); synthesizeKey("VK_DOWN", { }); },
},
{
// pressing a letter that doesn't correspond to an accelerator. The menu
// should not close because there is more than one item corresponding to
// that letter
testname: "menuitem with no accelerator",
events: [ "DOMMenuItemInactive contents", "DOMMenuItemActive one" ],
test: function() { synthesizeKey("O", { }); },
result: function(testname) { checkOpen("helpmenu", testname); }
},
{
// pressing the letter again should select the next one that starts with
// that letter
testname: "menuitem with no accelerator again",
events: [ "DOMMenuItemInactive one", "DOMMenuItemActive only" ],
test: function() { synthesizeKey("O", { }); },
result: function(testname) {
// 'only' is a menu but it should not be open
checkOpen("helpmenu", testname);
checkClosed("only", testname);
}
},
{
// pressing the letter again when the next item is disabled should still
// select the disabled item
testname: "menuitem with no accelerator disabled",
condition: function() { return (navigator.platform.indexOf("Win") == 0) },
events: [ "DOMMenuItemInactive only", "DOMMenuItemActive other" ],
test: function() { synthesizeKey("O", { }); },
result: function(testname) { }
},
{
// when only one menuitem starting with that letter exists, it should be
// selected and the menu closed
testname: "menuitem with no accelerator single",
events: function() {
var elist = [ "DOMMenuItemInactive other", "DOMMenuItemActive third",
"DOMMenuItemInactive third", "DOMMenuInactive helppopup",
"DOMMenuBarInactive menubar",
"DOMMenuItemInactive helpmenu",
"DOMMenuItemInactive helpmenu",
"command third", "DOMMenuItemInactive third",
"popuphiding helppopup", "popuphidden helppopup",
];
if (navigator.platform.indexOf("Win") == -1)
elist[0] = "DOMMenuItemInactive only";
return elist;
},
test: function() { synthesizeKey("T", { }); },
result: function(testname) { checkClosed("helpmenu", testname); }
},
{
// pressing F10 should highlight the first menu but not open it
testname: "F10 to activate menubar again",
condition: function() { return (navigator.platform.indexOf("Win") == 0) },
events: [ "DOMMenuBarActive menubar", "DOMMenuItemActive filemenu" ],
test: function() { synthesizeKey("VK_F10", { }); },
result: function(testname) { checkClosed("filemenu", testname); },
},
{
// pressing an accelerator for a disabled item should deactivate the menubar
testname: "accelerator for disabled menu",
condition: function() { return (navigator.platform.indexOf("Win") == 0) },
events: [ "DOMMenuItemInactive filemenu", "DOMMenuBarInactive menubar" ],
test: function() { synthesizeKey("S", { }); },
result: function(testname) { checkClosed("secretmenu", testname); },
},
{
testname: "press on disabled menu",
test: function() {
synthesizeMouse(document.getElementById("secretmenu"), 8, 8, { });
},
result: function (testname) {
checkClosed("secretmenu", testname);
}
},
{
testname: "press on second menu with shift",
events: [ "popupshowing editpopup", "DOMMenuBarActive menubar",
"DOMMenuItemActive editmenu", "popupshown editpopup" ],
test: function() {
synthesizeMouse(document.getElementById("editmenu"), 8, 8, { shiftKey : true });
},
result: function (testname) {
checkOpen("editmenu", testname);
checkActive(document.getElementById("menubar"), "editmenu", testname);
}
},
{
testname: "press on disabled menuitem",
test: function() {
synthesizeMouse(document.getElementById("cut"), 8, 8, { });
},
result: function (testname) {
checkOpen("editmenu", testname);
}
},
{
testname: "press on menuitem",
events: [ "DOMMenuInactive editpopup",
"DOMMenuBarInactive menubar",
"DOMMenuItemInactive editmenu",
"DOMMenuItemInactive editmenu",
"command copy", "DOMMenuItemInactive copy",
"popuphiding editpopup", "popuphidden editpopup",
],
test: function() {
synthesizeMouse(document.getElementById("copy"), 8, 8, { });
},
result: function (testname) {
checkClosed("editmenu", testname);
}
},
];
]]>
</script>
</window>

View File

@ -0,0 +1,135 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Menu Checkbox and Radio Tests"
onfocus="runTests()"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Menu Checkbox and Radio Tests</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<hbox style="margin-left: 275px; margin-top: 275px;">
<button id="menu" type="menu" label="View">
<menupopup id="popup" onpopupshown="popupShown()" onpopuphidden="popupHidden()">
<menuitem id="toolbar" label="Show Toolbar" type="checkbox"/>
<menuitem id="statusbar" label="Show Status Bar" type="checkbox" checked="true"/>
<menuitem id="bookmarks" label="Show Bookmarks" type="checkbox" autocheck="false"/>
<menuitem id="history" label="Show History" type="checkbox" autocheck="false" checked="true"/>
<menuseparator/>
<menuitem id="byname" label="By Name" type="radio" name="sort"/>
<menuitem id="bydate" label="By Date" type="radio" name="sort" checked="true"/>
<menuseparator/>
<menuitem id="ascending" label="Ascending" type="radio" name="order" checked="true"/>
<menuitem id="descending" label="Descending" type="radio" name="order" autocheck="false"/>
<menuitem id="bysubject" label="By Subject" type="radio" name="sort"/>
</menupopup>
</button>
</hbox>
<script class="testbody" type="application/javascript">
<![CDATA[
var gTestIndex = 0;
// tests to perform
var tests = [
{
testname: "select unchecked checkbox",
item: "toolbar",
checked: ["toolbar", "statusbar", "history", "bydate", "ascending"]
},
{
testname: "select checked checkbox",
item: "statusbar",
checked: ["toolbar", "history", "bydate", "ascending"]
},
{
testname: "select unchecked autocheck checkbox",
item: "bookmarks",
checked: ["toolbar", "history", "bydate", "ascending"]
},
{
testname: "select checked autocheck checkbox",
item: "history",
checked: ["toolbar", "history", "bydate", "ascending"]
},
{
testname: "select unchecked radio",
item: "byname",
checked: ["toolbar", "history", "byname", "ascending"]
},
{
testname: "select checked radio",
item: "byname",
checked: ["toolbar", "history", "byname", "ascending"]
},
{
testname: "select out of order checked radio",
item: "bysubject",
checked: ["toolbar", "history", "bysubject", "ascending"]
},
{
testname: "select first radio again",
item: "byname",
checked: ["toolbar", "history", "byname", "ascending"]
},
{
testname: "select autocheck radio",
item: "descending",
checked: ["toolbar", "history", "byname", "ascending"]
}
];
function runTests()
{
checkMenus(["statusbar", "history", "bydate", "ascending"], "initial");
document.getElementById("menu").open = true;
}
function checkMenus(checkedItems, testname)
{
var isok = true;
var children = document.getElementById("popup").childNodes;
for (var c = 0; c < children.length; c++) {
var child = children[c];
if ((checkedItems.indexOf(child.id) != -1 && child.getAttribute("checked") != "true") ||
(checkedItems.indexOf(child.id) == -1 && child.hasAttribute("checked"))) {
isok = false;
break;
}
}
window.opener.SimpleTest.ok(isok, testname);
}
function popupShown()
{
var test = tests[gTestIndex];
synthesizeMouse(document.getElementById(test.item), 4, 4, { });
}
function popupHidden()
{
if (gTestIndex < tests.length) {
var test = tests[gTestIndex];
checkMenus(test.checked, test.testname);
gTestIndex++;
if (gTestIndex < tests.length) {
document.getElementById("menu").open = true;
}
else {
// manually setting the checkbox should also update the radio state
document.getElementById("bydate").setAttribute("checked", "true");
checkMenus(["toolbar", "history", "bydate", "ascending"], "set checked attribute on radio");
window.opener.SimpleTest.finish();
window.close();
}
}
}
]]>
</script>
</window>

View File

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Popup Attribute Tests"
onfocus="runTests()"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Attribute Tests</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="popup_shared.js"></script>
<script type="application/javascript" src="popup_trigger.js"></script>
<hbox style="margin-left: 275px; margin-top: 275px;">
<label id="trigger" popup="thepopup" value="Popup"/>
</hbox>
<menupopup id="thepopup">
<menuitem id="item1" label="First"/>
<menuitem id="item2" label="Main Item"/>
<menuitem id="amenu" label="A Menu" accesskey="M"/>
<menuitem id="item3" label="Third"/>
<menuitem id="one" label="One"/>
<menuitem id="fancier" label="Fancier Menu"/>
<menu id="submenu" label="Only Menu">
<menupopup id="submenupopup">
<menuitem id="submenuitem" label="Test Submenu"/>
</menupopup>
</menu>
<menuitem id="other" disabled="true" label="Other Menu"/>
<menuitem id="secondlast" label="Second Last Menu" accesskey="T"/>
<menuitem id="last" label="One Other Menu"/>
</menupopup>
</window>

View File

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Popup Tests"
onfocus="runTests()"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Tests</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="popup_shared.js"></script>
<script type="application/javascript" src="popup_trigger.js"></script>
<hbox style="margin-left: 275px; margin-top: 275px;">
<button id="trigger" type="menu" label="Popup">
<menupopup id="thepopup">
<menuitem id="item1" label="First"/>
<menuitem id="item2" label="Main Item"/>
<menuitem id="amenu" label="A Menu" accesskey="M"/>
<menuitem id="item3" label="Third"/>
<menuitem id="one" label="One"/>
<menuitem id="fancier" label="Fancier Menu"/>
<menu id="submenu" label="Only Menu">
<menupopup id="submenupopup">
<menuitem id="submenuitem" label="Test Submenu"/>
</menupopup>
</menu>
<menuitem id="other" disabled="true" label="Other Menu"/>
<menuitem id="secondlast" label="Second Last Menu" accesskey="T"/>
<menuitem id="last" label="One Other Menu"/>
</menupopup>
</button>
</hbox>
</window>

View File

@ -0,0 +1,188 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Tooltip Tests"
onfocus="runTests()"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Tooltip Tests</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="popup_shared.js"></script>
<tooltip id="thetooltip">
<label id="label" value="This is a tooltip"/>
</tooltip>
<box tooltiptext="Box Tooltip">
<button id="withtext" label="Tooltip Text" tooltiptext="Button Tooltip"/>
<button id="without" label="No Tooltip"/>
<!-- remove the native theme and borders to avoid some platform
specific sizing differences -->
<button id="withtooltip" label="Tooltip Element" tooltip="thetooltip"
class="plain" style="-moz-appearance: none;"/>
</box>
<script class="testbody" type="application/javascript">
<![CDATA[
var gOriginalWidth = -1;
var gOriginalHeight = -1;
function runTests()
{
startPopupTests(popupTests);
}
var popupTests = [
{
testname: "hover tooltiptext attribute",
events: [ "popupshowing #tooltip", "popupshown #tooltip" ],
test: function() {
var button = document.getElementById("withtext");
synthesizeMouse(button, 2, 2, { type: "mouseover" });
synthesizeMouse(button, 4, 4, { type: "mousemove" });
synthesizeMouse(button, 6, 6, { type: "mousemove" });
}
},
{
testname: "close tooltip",
events: [ "popuphiding #tooltip", "popuphidden #tooltip",
"DOMMenuInactive #tooltip" ],
test: function() {
synthesizeMouse(document.documentElement, 2, 2, { type: "mousemove" });
},
},
{
testname: "hover inherited tooltip",
events: [ "popupshowing #tooltip", "popupshown #tooltip" ],
test: function() {
var button = document.getElementById("without");
synthesizeMouse(button, 2, 2, { type: "mouseover" });
synthesizeMouse(button, 4, 4, { type: "mousemove" });
synthesizeMouse(button, 6, 6, { type: "mousemove" });
}
},
{
testname: "hover tooltip attribute",
events: [ "popuphiding #tooltip", "popuphidden #tooltip",
"DOMMenuInactive #tooltip",
"popupshowing thetooltip", "popupshown thetooltip" ],
test: function() {
var button = document.getElementById("withtooltip");
synthesizeMouse(button, 2, 2, { type: "mouseover" });
synthesizeMouse(button, 4, 4, { type: "mousemove" });
synthesizeMouse(button, 6, 6, { type: "mousemove" });
},
result: function(testname) {
var buttonrect = document.getElementById("withtooltip").getBoundingClientRect();
var rect = document.getElementById("thetooltip").getBoundingClientRect();
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
is(Math.round(rect.left), Math.round(buttonrect.left) +
parseInt(popupstyle.marginLeft) + 6,
testname + " top position of tooltip");
is(Math.round(rect.top), Math.round(buttonrect.top) +
parseInt(popupstyle.marginTop) + 6,
testname + " top position of tooltip");
var labelrect = document.getElementById("label").getBoundingClientRect();
ok(labelrect.right < rect.right, testname + " tooltip width");
ok(labelrect.bottom < rect.bottom, testname + " tooltip height");
gOriginalWidth = rect.right - rect.left;
gOriginalHeight = rect.bottom - rect.top;
}
},
{
testname: "click to close tooltip",
events: [ "popuphiding thetooltip", "popuphidden thetooltip",
"command withtooltip", "DOMMenuInactive thetooltip" ],
test: function() {
var button = document.getElementById("withtooltip");
synthesizeMouse(button, 2, 2, { });
},
},
{
testname: "hover tooltip after size increased",
events: [ "popupshowing thetooltip", "popupshown thetooltip" ],
test: function() {
var label = document.getElementById("label");
label.removeAttribute("value");
label.textContent = "This is a longer tooltip than before\nIt has multiple lines\nIt is testing tooltip sizing\n";
var button = document.getElementById("withtooltip");
synthesizeMouse(button, 2, 2, { type: "mouseover" });
synthesizeMouse(button, 6, 6, { type: "mousemove" });
synthesizeMouse(button, 4, 4, { type: "mousemove" });
},
result: function(testname) {
var buttonrect = document.getElementById("withtooltip").getBoundingClientRect();
var rect = document.getElementById("thetooltip").getBoundingClientRect();
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), "");
is(Math.round(rect.left), Math.round(buttonrect.left) +
parseInt(popupstyle.marginLeft) + 4,
testname + " top position of tooltip");
is(Math.round(rect.top), Math.round(buttonrect.top) +
parseInt(popupstyle.marginTop) + 4,
testname + " top position of tooltip");
var labelrect = document.getElementById("label").getBoundingClientRect();
ok(labelrect.right < rect.right, testname + " tooltip width");
ok(labelrect.bottom < rect.bottom, testname + " tooltip height");
// make sure that the tooltip is larger than it was before by just
// checking against the original height plus an arbitrary 15 pixels
ok(gOriginalWidth + 15 < rect.right - rect.left, testname + " tooltip is wider");
ok(gOriginalHeight + 15 < rect.bottom - rect.top, testname + " tooltip is taller");
}
},
{
testname: "close tooltip with hidePopup",
events: [ "popuphiding thetooltip", "popuphidden thetooltip",
"DOMMenuInactive thetooltip" ],
test: function() {
document.getElementById("thetooltip").hidePopup();
},
},
{
testname: "hover tooltip after size decreased",
events: [ "popupshowing thetooltip", "popupshown thetooltip" ],
autohide: "thetooltip",
test: function() {
var label = document.getElementById("label");
label.value = "This is a tooltip";
var button = document.getElementById("withtooltip");
synthesizeMouse(button, 2, 2, { type: "mouseover" });
synthesizeMouse(button, 4, 4, { type: "mousemove" });
synthesizeMouse(button, 6, 6, { type: "mousemove" });
},
result: function(testname) {
var buttonrect = document.getElementById("withtooltip").getBoundingClientRect();
var rect = document.getElementById("thetooltip").getBoundingClientRect();
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), "");
is(Math.round(rect.left), Math.round(buttonrect.left) +
parseInt(popupstyle.marginLeft) + 6,
testname + " top position of tooltip");
is(Math.round(rect.top), Math.round(buttonrect.top) +
parseInt(popupstyle.marginTop) + 6,
testname + " top position of tooltip");
var labelrect = document.getElementById("label").getBoundingClientRect();
ok(labelrect.right < rect.right, testname + " tooltip width");
ok(labelrect.bottom < rect.bottom, testname + " tooltip height");
is(gOriginalWidth, rect.right - rect.left, testname + " tooltip is original width");
is(gOriginalHeight, rect.bottom - rect.top, testname + " tooltip is original height");
}
},
];
]]>
</script>
</window>