2008-10-22 23:36:52 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Tests for browser context menu</title>
|
2009-05-06 13:46:04 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
2008-10-22 23:36:52 -07:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Browser context menu tests.
|
|
|
|
<p id="display"></p>
|
|
|
|
|
|
|
|
<div id="content">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Login Manager: multiple login autocomplete. **/
|
|
|
|
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
|
|
|
function openContextMenuFor(element) {
|
|
|
|
// Context menu should be closed before we open it again.
|
|
|
|
is(contextMenu.state, "closed", "checking if popup is closed");
|
|
|
|
|
2009-10-01 07:07:21 -07:00
|
|
|
var eventDetails = { type : "contextmenu", button : 2 };
|
2009-08-04 11:03:42 -07:00
|
|
|
synthesizeMouse(element, 2, 2, eventDetails, element.ownerDocument.defaultView);
|
2008-10-22 23:36:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function closeContextMenu() {
|
|
|
|
contextMenu.hidePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVisibleMenuItems(aMenu) {
|
|
|
|
var items = [];
|
|
|
|
var accessKeys = {};
|
|
|
|
for (var i = 0; i < aMenu.childNodes.length; i++) {
|
|
|
|
var item = aMenu.childNodes[i];
|
|
|
|
if (item.hidden)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var key = item.accessKey;
|
|
|
|
if (key)
|
|
|
|
key = key.toLowerCase();
|
|
|
|
|
|
|
|
if (item.nodeName == "menuitem") {
|
|
|
|
ok(item.id, "child menuitem #" + i + " has an ID");
|
|
|
|
ok(key, "menuitem has an access key");
|
|
|
|
if (accessKeys[key])
|
|
|
|
ok(false, "menuitem " + item.id + " has same accesskey as " + accessKeys[key]);
|
|
|
|
else
|
2009-10-01 07:07:21 -07:00
|
|
|
accessKeys[key] = item.id;
|
2008-10-22 23:36:52 -07:00
|
|
|
items.push(item.id);
|
2009-07-09 18:26:35 -07:00
|
|
|
items.push(!item.disabled);
|
2008-10-22 23:36:52 -07:00
|
|
|
} else if (item.nodeName == "menuseparator") {
|
|
|
|
ok(true, "--- seperator id is " + item.id);
|
|
|
|
items.push("---");
|
2009-07-09 18:26:35 -07:00
|
|
|
items.push(null);
|
2008-10-22 23:36:52 -07:00
|
|
|
} else if (item.nodeName == "menu") {
|
|
|
|
ok(item.id, "child menu #" + i + " has an ID");
|
|
|
|
ok(key, "menu has an access key");
|
|
|
|
if (accessKeys[key])
|
|
|
|
ok(false, "menu " + item.id + " has same accesskey as " + accessKeys[key]);
|
|
|
|
else
|
2009-10-01 07:07:21 -07:00
|
|
|
accessKeys[key] = item.id;
|
2008-10-22 23:36:52 -07:00
|
|
|
items.push(item.id);
|
2009-07-09 18:26:35 -07:00
|
|
|
items.push(!item.disabled);
|
2008-10-22 23:36:52 -07:00
|
|
|
// Add a dummy item to that the indexes in checkMenu are the same
|
|
|
|
// for expectedItems and actualItems.
|
|
|
|
items.push([]);
|
2009-07-09 18:26:35 -07:00
|
|
|
items.push(null);
|
2008-10-22 23:36:52 -07:00
|
|
|
} else {
|
|
|
|
ok(false, "child #" + i + " of menu ID " + aMenu.id +
|
|
|
|
" has an unknown type (" + item.nodeName + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkContextMenu(expectedItems) {
|
|
|
|
is(contextMenu.state, "open", "checking if popup is open");
|
|
|
|
checkMenu(contextMenu, expectedItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* checkMenu - checks to see if the specified <menupopup> contains the
|
2009-07-09 18:26:35 -07:00
|
|
|
* expected items and state.
|
|
|
|
* expectedItems is a array of (1) item IDs and (2) a boolean specifying if
|
|
|
|
* the item is enabled or not (or null to ignore it). Submenus can be checked
|
|
|
|
* by providing a nested array entry after the expected <menu> ID.
|
|
|
|
* For example: ["blah", true, // item enabled
|
|
|
|
* "submenu", null, // submenu
|
|
|
|
* ["sub1", true, // submenu contents
|
|
|
|
* "sub2", false], null, // submenu contents
|
|
|
|
* "lol", false] // item disabled
|
2008-10-22 23:36:52 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
function checkMenu(menu, expectedItems) {
|
|
|
|
var actualItems = getVisibleMenuItems(menu);
|
|
|
|
//ok(false, "Items are: " + actualItems);
|
2009-07-09 18:26:35 -07:00
|
|
|
for (var i = 0; i < expectedItems.length; i+=2) {
|
|
|
|
var actualItem = actualItems[i];
|
|
|
|
var actualEnabled = actualItems[i + 1];
|
|
|
|
var expectedItem = expectedItems[i];
|
|
|
|
var expectedEnabled = expectedItems[i + 1];
|
|
|
|
if (expectedItem instanceof Array) {
|
2008-10-22 23:36:52 -07:00
|
|
|
ok(true, "Checking submenu...");
|
2009-07-09 18:26:35 -07:00
|
|
|
var menuID = expectedItems[i - 2]; // The last item was the menu ID.
|
2008-10-22 23:36:52 -07:00
|
|
|
var submenu = menu.getElementsByAttribute("id", menuID)[0];
|
|
|
|
ok(submenu && submenu.nodeName == "menu", "got expected submenu element");
|
2009-07-09 18:26:35 -07:00
|
|
|
checkMenu(submenu.menupopup, expectedItem);
|
2008-10-22 23:36:52 -07:00
|
|
|
} else {
|
2009-07-09 18:26:35 -07:00
|
|
|
is(actualItem, expectedItem,
|
|
|
|
"checking item #" + i/2 + " (" + expectedItem + ") name");
|
|
|
|
if (expectedEnabled != null)
|
|
|
|
is(actualEnabled, expectedEnabled,
|
|
|
|
"checking item #" + i/2 + " (" + expectedItem + ") enabled state");
|
2008-10-22 23:36:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Could find unexpected extra items at the end...
|
|
|
|
is(actualItems.length, expectedItems.length, "checking expected number of menu entries");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* runTest
|
|
|
|
*
|
|
|
|
* Called by a popupshowing event handler. Each test checks for expected menu
|
|
|
|
* contents, closes the popup, and finally triggers the popup on a new element
|
|
|
|
* (thus kicking off another cycle).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function runTest(testNum) {
|
|
|
|
// Seems we need to enable this again, or sendKeyEvent() complaints.
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
ok(true, "Starting test #" + testNum);
|
|
|
|
|
|
|
|
switch(testNum) {
|
|
|
|
case 1:
|
|
|
|
// Invoke context menu for next test.
|
|
|
|
openContextMenuFor(text);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
// Context menu for plain text
|
2009-07-09 18:26:35 -07:00
|
|
|
checkContextMenu(["context-back", false,
|
|
|
|
"context-forward", false,
|
|
|
|
"context-reload", true,
|
|
|
|
"context-stop", false,
|
|
|
|
"---", null,
|
|
|
|
"context-bookmarkpage", true,
|
|
|
|
"context-savepage", true,
|
|
|
|
"context-sendpage", true,
|
|
|
|
"---", null,
|
|
|
|
"context-viewbgimage", false,
|
|
|
|
"context-selectall", true,
|
|
|
|
"---", null,
|
|
|
|
"context-viewsource", true,
|
|
|
|
"context-viewinfo", true]);
|
2009-10-01 07:07:21 -07:00
|
|
|
closeContextMenu();
|
2008-10-22 23:36:52 -07:00
|
|
|
openContextMenuFor(link); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
// Context menu for text link
|
2009-07-09 18:26:35 -07:00
|
|
|
checkContextMenu(["context-openlink", true,
|
|
|
|
"context-openlinkintab", true,
|
|
|
|
"---", null,
|
|
|
|
"context-bookmarklink", true,
|
|
|
|
"context-savelink", true,
|
|
|
|
"context-sendlink", true,
|
2010-01-15 21:28:27 -08:00
|
|
|
"context-copylink", true,
|
|
|
|
"context-copylinktext", true]);
|
2009-10-01 07:07:21 -07:00
|
|
|
closeContextMenu();
|
2008-10-22 23:36:52 -07:00
|
|
|
openContextMenuFor(mailto); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
// Context menu for text mailto-link
|
2010-01-15 21:28:27 -08:00
|
|
|
checkContextMenu(["context-copyemail", true,
|
|
|
|
"context-copylinktext", true]);
|
2009-10-01 07:07:21 -07:00
|
|
|
closeContextMenu();
|
2008-10-22 23:36:52 -07:00
|
|
|
openContextMenuFor(input); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
// Context menu for text input field
|
2009-07-09 18:26:35 -07:00
|
|
|
checkContextMenu(["context-undo", false,
|
|
|
|
"---", null,
|
|
|
|
"context-cut", false,
|
|
|
|
"context-copy", false,
|
|
|
|
"context-paste", null, // ignore clipboard state
|
|
|
|
"context-delete", false,
|
|
|
|
"---", null,
|
|
|
|
"context-selectall", true,
|
|
|
|
"---", null,
|
|
|
|
"spell-check-enabled", true]);
|
2009-10-01 07:07:21 -07:00
|
|
|
closeContextMenu();
|
2008-10-22 23:36:52 -07:00
|
|
|
openContextMenuFor(img); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
// Context menu for an image
|
2009-07-09 18:26:35 -07:00
|
|
|
checkContextMenu(["context-viewimage", true,
|
|
|
|
"context-copyimage-contents", true,
|
|
|
|
"context-copyimage", true,
|
|
|
|
"---", null,
|
|
|
|
"context-saveimage", true,
|
|
|
|
"context-sendimage", true,
|
|
|
|
"context-setDesktopBackground", true,
|
2009-10-22 17:32:49 -07:00
|
|
|
"context-blockimage", true,
|
|
|
|
"context-viewimageinfo", true]);
|
2008-10-22 23:36:52 -07:00
|
|
|
closeContextMenu();
|
|
|
|
openContextMenuFor(canvas); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
// Context menu for a canvas
|
2009-07-09 18:26:35 -07:00
|
|
|
checkContextMenu(["context-viewimage", true,
|
|
|
|
"context-saveimage", true,
|
|
|
|
"context-bookmarkpage", true,
|
|
|
|
"context-selectall", true]);
|
2008-10-22 23:36:52 -07:00
|
|
|
closeContextMenu();
|
2009-07-09 18:26:35 -07:00
|
|
|
openContextMenuFor(video_ok); // Invoke context menu for next test.
|
2008-10-22 23:36:52 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
2009-07-09 18:26:35 -07:00
|
|
|
// Context menu for a video (with a VALID media source)
|
|
|
|
checkContextMenu(["context-media-play", true,
|
|
|
|
"context-media-mute", true,
|
|
|
|
"context-media-showcontrols", true,
|
2009-10-01 01:49:00 -07:00
|
|
|
"context-video-fullscreen", true,
|
2009-07-09 18:26:35 -07:00
|
|
|
"---", null,
|
|
|
|
"context-viewvideo", true,
|
|
|
|
"context-copyvideourl", true,
|
|
|
|
"---", null,
|
|
|
|
"context-savevideo", true,
|
|
|
|
"context-sendvideo", true]);
|
2008-10-22 23:36:52 -07:00
|
|
|
closeContextMenu();
|
2009-07-09 18:26:35 -07:00
|
|
|
openContextMenuFor(video_bad); // Invoke context menu for next test.
|
2008-10-22 23:36:52 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
2009-10-22 17:32:49 -07:00
|
|
|
// Context menu for a video (with an INVALID media source)
|
2009-07-09 18:26:35 -07:00
|
|
|
checkContextMenu(["context-media-play", false,
|
|
|
|
"context-media-mute", false,
|
|
|
|
"context-media-showcontrols", false,
|
2009-10-01 01:49:00 -07:00
|
|
|
"context-video-fullscreen", false,
|
2009-07-09 18:26:35 -07:00
|
|
|
"---", null,
|
|
|
|
"context-viewvideo", true,
|
|
|
|
"context-copyvideourl", true,
|
|
|
|
"---", null,
|
|
|
|
"context-savevideo", true,
|
|
|
|
"context-sendvideo", true]);
|
|
|
|
closeContextMenu();
|
|
|
|
openContextMenuFor(video_bad2); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
2009-10-22 17:32:49 -07:00
|
|
|
// Context menu for a video (with an INVALID media source)
|
2009-07-09 18:26:35 -07:00
|
|
|
checkContextMenu(["context-media-play", false,
|
|
|
|
"context-media-mute", false,
|
|
|
|
"context-media-showcontrols", false,
|
2009-10-01 01:49:00 -07:00
|
|
|
"context-video-fullscreen", false,
|
2009-07-09 18:26:35 -07:00
|
|
|
"---", null,
|
|
|
|
"context-viewvideo", false,
|
|
|
|
"context-copyvideourl", false,
|
|
|
|
"---", null,
|
|
|
|
"context-savevideo", false,
|
|
|
|
"context-sendvideo", false]);
|
|
|
|
closeContextMenu();
|
|
|
|
openContextMenuFor(iframe); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
2008-10-22 23:36:52 -07:00
|
|
|
// Context menu for an iframe
|
2009-07-09 18:26:35 -07:00
|
|
|
checkContextMenu(["context-back", false,
|
|
|
|
"context-forward", false,
|
|
|
|
"context-reload", true,
|
|
|
|
"context-stop", false,
|
|
|
|
"---", null,
|
|
|
|
"context-bookmarkpage", true,
|
|
|
|
"context-savepage", true,
|
|
|
|
"context-sendpage", true,
|
|
|
|
"---", null,
|
|
|
|
"context-viewbgimage", false,
|
|
|
|
"context-selectall", true,
|
|
|
|
"frame", null,
|
|
|
|
["context-showonlythisframe", true,
|
|
|
|
"context-openframe", true,
|
|
|
|
"context-openframeintab", true,
|
|
|
|
"---", null,
|
|
|
|
"context-reloadframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-bookmarkframe", true,
|
|
|
|
"context-saveframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-printframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-viewframesource", true,
|
|
|
|
"context-viewframeinfo", true], null,
|
|
|
|
"---", null,
|
|
|
|
"context-viewsource", true,
|
|
|
|
"context-viewinfo", true]);
|
2008-10-22 23:36:52 -07:00
|
|
|
closeContextMenu();
|
|
|
|
|
|
|
|
subwindow.close();
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Other things that would be nice to test:
|
|
|
|
* - selected text
|
|
|
|
* - spelling / misspelled word (in text input?)
|
|
|
|
* - check state of disabled items
|
|
|
|
* - test execution of menu items (maybe as a separate test?)
|
|
|
|
*/
|
|
|
|
|
|
|
|
default:
|
2009-06-19 13:19:18 -07:00
|
|
|
ok(false, "Unexpected invocation of test #" + testNum);
|
2008-10-22 23:36:52 -07:00
|
|
|
subwindow.close();
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var testNum = 1;
|
|
|
|
var subwindow, chromeWin, contextMenu;
|
|
|
|
var text, link, mailto, input, img, canvas, video, iframe;
|
|
|
|
|
|
|
|
function startTest() {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
chromeWin = subwindow
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
|
|
|
.rootTreeItem
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow)
|
|
|
|
.QueryInterface(Ci.nsIDOMChromeWindow);
|
|
|
|
contextMenu = chromeWin.document.getElementById("contentAreaContextMenu");
|
|
|
|
ok(contextMenu, "Got context menu XUL");
|
|
|
|
|
|
|
|
text = subwindow.document.getElementById("test-text");
|
|
|
|
link = subwindow.document.getElementById("test-link");
|
|
|
|
mailto = subwindow.document.getElementById("test-mailto");
|
|
|
|
input = subwindow.document.getElementById("test-input");
|
|
|
|
img = subwindow.document.getElementById("test-image");
|
|
|
|
canvas = subwindow.document.getElementById("test-canvas");
|
2009-07-09 18:26:35 -07:00
|
|
|
video_ok = subwindow.document.getElementById("test-video-ok");
|
|
|
|
video_bad = subwindow.document.getElementById("test-video-bad");
|
|
|
|
video_bad2 = subwindow.document.getElementById("test-video-bad2");
|
2008-10-22 23:36:52 -07:00
|
|
|
iframe = subwindow.document.getElementById("test-iframe");
|
|
|
|
|
|
|
|
contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false);
|
|
|
|
runTest(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We open this in a separate window, because the Mochitests run inside a frame.
|
|
|
|
// The frame causes an extra menu item, and prevents running the test
|
|
|
|
// standalone (ie, clicking the test name in the Mochitest window) to see
|
|
|
|
// success/failure messages.
|
2009-08-12 07:04:51 -07:00
|
|
|
var painted = false, loaded = false;
|
|
|
|
|
|
|
|
function waitForEvents(event)
|
|
|
|
{
|
|
|
|
if (event.type == "MozAfterPaint")
|
|
|
|
painted = true;
|
|
|
|
else if (event.type == "load")
|
|
|
|
loaded = true;
|
|
|
|
if (painted && loaded) {
|
|
|
|
subwindow.removeEventListener("MozAfterPaint", waitForEvents, false);
|
|
|
|
subwindow.onload = null;
|
|
|
|
startTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-23 13:51:47 -07:00
|
|
|
var subwindow = window.open("./subtst_contextmenu.html", "contextmenu-subtext", "width=600,height=700");
|
2009-08-12 07:04:51 -07:00
|
|
|
subwindow.addEventListener("MozAfterPaint", waitForEvents, false);
|
|
|
|
subwindow.onload = waitForEvents;
|
2008-10-22 23:36:52 -07:00
|
|
|
|
2008-10-23 13:51:47 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2008-10-22 23:36:52 -07:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|