2008-10-22 23:36:52 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Tests for browser context menu</title>
|
|
|
|
<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');
|
2011-12-29 13:06:56 -08:00
|
|
|
Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");
|
2008-10-22 23:36:52 -07:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2011-10-16 19:06:24 -07:00
|
|
|
function openContextMenuFor(element, shiftkey, shouldWaitForFocus) {
|
2008-10-22 23:36:52 -07:00
|
|
|
// Context menu should be closed before we open it again.
|
|
|
|
is(contextMenu.state, "closed", "checking if popup is closed");
|
|
|
|
|
2011-10-16 19:06:24 -07:00
|
|
|
//Some elements need time to focus and spellcheck before any tests are
|
|
|
|
//run on them.
|
|
|
|
if(shouldWaitForFocus)
|
|
|
|
{
|
|
|
|
if (lastElement)
|
|
|
|
lastElement.blur();
|
|
|
|
element.focus();
|
|
|
|
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
lastElement = element;
|
|
|
|
var eventDetails = { type : "contextmenu", button : 2, shiftKey : shiftkey };
|
|
|
|
synthesizeMouse(element, 2, 2, eventDetails, element.ownerDocument.defaultView);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lastElement)
|
|
|
|
lastElement.blur();
|
|
|
|
element.focus();
|
|
|
|
lastElement = element;
|
|
|
|
var eventDetails = { type : "contextmenu", button : 2, shiftKey : shiftkey };
|
|
|
|
synthesizeMouse(element, 2, 2, eventDetails, element.ownerDocument.defaultView);
|
|
|
|
}
|
2008-10-22 23:36:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function closeContextMenu() {
|
|
|
|
contextMenu.hidePopup();
|
|
|
|
}
|
|
|
|
|
2010-08-10 13:55:31 -07:00
|
|
|
function executeCopyCommand(command, expectedValue)
|
|
|
|
{
|
|
|
|
// Just execute the command directly rather than simulating a context menu
|
|
|
|
// press to avoid having to deal with its asynchronous nature
|
|
|
|
subwindow.controllers.getControllerForCommand(command).doCommand(command);
|
|
|
|
|
|
|
|
// The easiest way to check the clipboard is to paste the contents into a
|
|
|
|
// textbox
|
|
|
|
input.focus();
|
|
|
|
input.value = "";
|
|
|
|
input.controllers.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
|
|
|
|
is(input.value, expectedValue, "paste for command " + command);
|
|
|
|
}
|
|
|
|
|
2011-08-18 09:37:26 -07:00
|
|
|
function invokeItemAction(generatedItemId)
|
2011-08-08 10:31:32 -07:00
|
|
|
{
|
2011-08-18 09:37:26 -07:00
|
|
|
var item = contextMenu.getElementsByAttribute("generateditemid",
|
|
|
|
generatedItemId)[0];
|
2011-08-08 10:31:32 -07:00
|
|
|
ok(item, "Got generated XUL menu item");
|
|
|
|
item.doCommand();
|
|
|
|
is(pagemenu.hasAttribute("hopeless"), false, "attribute got removed");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVisibleMenuItems(aMenu, aData) {
|
2008-10-22 23:36:52 -07:00
|
|
|
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();
|
|
|
|
|
2011-08-18 09:37:26 -07:00
|
|
|
var isGenerated = item.hasAttribute("generateditemid");
|
2011-08-08 10:31:32 -07:00
|
|
|
|
2008-10-22 23:36:52 -07:00
|
|
|
if (item.nodeName == "menuitem") {
|
2010-06-01 11:08:38 -07:00
|
|
|
var isSpellSuggestion = item.className == "spell-suggestion";
|
|
|
|
if (isSpellSuggestion) {
|
|
|
|
is(item.id, "", "child menuitem #" + i + " is a spelling suggestion");
|
2011-08-08 10:31:32 -07:00
|
|
|
} else if (isGenerated) {
|
|
|
|
is(item.id, "", "child menuitem #" + i + " is a generated item");
|
2010-06-01 11:08:38 -07:00
|
|
|
} else {
|
|
|
|
ok(item.id, "child menuitem #" + i + " has an ID");
|
|
|
|
}
|
2010-06-05 20:48:30 -07:00
|
|
|
var label = item.getAttribute("label");
|
|
|
|
ok(label.length, "menuitem " + item.id + " has a label");
|
2010-06-01 11:08:38 -07:00
|
|
|
if (isSpellSuggestion) {
|
|
|
|
is(key, "", "Spell suggestions shouldn't have an access key");
|
2010-06-05 20:48:30 -07:00
|
|
|
items.push("*" + label);
|
2011-08-08 10:31:32 -07:00
|
|
|
} else if (isGenerated) {
|
|
|
|
items.push("+" + label);
|
2010-06-01 11:08:38 -07:00
|
|
|
} else if (item.id.indexOf("spell-check-dictionary-") != 0 &&
|
|
|
|
item.id != "spell-no-suggestions") {
|
|
|
|
ok(key, "menuitem " + item.id + " has an access key");
|
|
|
|
if (accessKeys[key])
|
|
|
|
ok(false, "menuitem " + item.id + " has same accesskey as " + accessKeys[key]);
|
|
|
|
else
|
|
|
|
accessKeys[key] = item.id;
|
|
|
|
}
|
2011-08-08 10:31:32 -07:00
|
|
|
if (!isSpellSuggestion && !isGenerated) {
|
2010-06-01 11:08:38 -07:00
|
|
|
items.push(item.id);
|
|
|
|
}
|
2011-08-08 10:31:32 -07:00
|
|
|
if (isGenerated) {
|
|
|
|
var p = {};
|
|
|
|
p.type = item.getAttribute("type");
|
|
|
|
p.icon = item.getAttribute("image");
|
|
|
|
p.checked = item.hasAttribute("checked");
|
|
|
|
p.disabled = item.hasAttribute("disabled");
|
|
|
|
items.push(p);
|
|
|
|
} else {
|
|
|
|
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") {
|
2011-08-08 10:31:32 -07:00
|
|
|
if (isGenerated) {
|
|
|
|
item.id = "generated-submenu-" + aData.generatedSubmenuId++;
|
|
|
|
}
|
2008-10-22 23:36:52 -07:00
|
|
|
ok(item.id, "child menu #" + i + " has an ID");
|
2011-08-08 10:31:32 -07:00
|
|
|
if (!isGenerated) {
|
|
|
|
ok(key, "menu has an access key");
|
|
|
|
if (accessKeys[key])
|
|
|
|
ok(false, "menu " + item.id + " has same accesskey as " + accessKeys[key]);
|
|
|
|
else
|
|
|
|
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");
|
2011-08-08 10:31:32 -07:00
|
|
|
var data = { generatedSubmenuId: 1 };
|
|
|
|
checkMenu(contextMenu, expectedItems, data);
|
2008-10-22 23:36:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
*/
|
2011-08-08 10:31:32 -07:00
|
|
|
function checkMenu(menu, expectedItems, data) {
|
|
|
|
var actualItems = getVisibleMenuItems(menu, data);
|
2008-10-22 23:36:52 -07:00
|
|
|
//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");
|
2011-08-08 10:31:32 -07:00
|
|
|
checkMenu(submenu.menupopup, expectedItem, data);
|
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");
|
2011-08-08 10:31:32 -07:00
|
|
|
|
|
|
|
if (typeof expectedEnabled == "object" && expectedEnabled != null ||
|
|
|
|
typeof actualEnabled == "object" && actualEnabled != null) {
|
|
|
|
|
|
|
|
ok(!(actualEnabled == null), "actualEnabled is not null");
|
|
|
|
ok(!(expectedEnabled == null), "expectedEnabled is not null");
|
|
|
|
is(typeof actualEnabled, typeof expectedEnabled, "checking types");
|
|
|
|
|
|
|
|
if (typeof actualEnabled != typeof expectedEnabled ||
|
|
|
|
actualEnabled == null || expectedEnabled == null)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
is(actualEnabled.type, expectedEnabled.type,
|
|
|
|
"checking item #" + i/2 + " (" + expectedItem + ") type attr value");
|
|
|
|
var icon = actualEnabled.icon;
|
|
|
|
if (icon) {
|
|
|
|
var tmp = "";
|
|
|
|
var j = icon.length - 1;
|
|
|
|
while (j && icon[j] != "/") {
|
|
|
|
tmp = icon[j--] + tmp;
|
|
|
|
}
|
|
|
|
icon = tmp;
|
|
|
|
}
|
|
|
|
is(icon, expectedEnabled.icon,
|
|
|
|
"checking item #" + i/2 + " (" + expectedItem + ") icon attr value");
|
|
|
|
is(actualEnabled.checked, expectedEnabled.checked,
|
|
|
|
"checking item #" + i/2 + " (" + expectedItem + ") has checked attr");
|
|
|
|
is(actualEnabled.disabled, expectedEnabled.disabled,
|
|
|
|
"checking item #" + i/2 + " (" + expectedItem + ") has disabled attr");
|
|
|
|
} else if (expectedEnabled != null)
|
2009-07-09 18:26:35 -07:00
|
|
|
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);
|
|
|
|
|
2011-10-26 19:48:21 -07:00
|
|
|
var inspectItems = [];
|
|
|
|
if (SpecialPowers.getBoolPref("devtools.inspector.enabled")) {
|
|
|
|
inspectItems = ["---", null,
|
|
|
|
"context-inspect", true];
|
|
|
|
}
|
|
|
|
|
2010-02-06 02:40:06 -08:00
|
|
|
switch (testNum) {
|
2008-10-22 23:36:52 -07:00
|
|
|
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,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-viewinfo", true
|
|
|
|
].concat(inspectItems));
|
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
|
2010-07-20 15:11:00 -07:00
|
|
|
checkContextMenu(["context-openlinkintab", true,
|
|
|
|
"context-openlink", true,
|
2009-07-09 18:26:35 -07:00
|
|
|
"---", null,
|
|
|
|
"context-bookmarklink", true,
|
|
|
|
"context-savelink", true,
|
|
|
|
"context-sendlink", true,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-copylink", true
|
|
|
|
].concat(inspectItems));
|
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
|
2011-10-26 19:48:21 -07:00
|
|
|
checkContextMenu(["context-copyemail", true].concat(inspectItems));
|
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,
|
2011-09-23 14:44:53 -07:00
|
|
|
"context-selectall", false,
|
2009-07-09 18:26:35 -07:00
|
|
|
"---", null,
|
2011-10-26 19:48:21 -07:00
|
|
|
"spell-check-enabled", true
|
|
|
|
].concat(inspectItems));
|
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,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-viewimageinfo", true
|
|
|
|
].concat(inspectItems));
|
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,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-selectall", true
|
|
|
|
].concat(inspectItems));
|
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,
|
2011-10-03 20:47:41 -07:00
|
|
|
"context-media-hidecontrols", true,
|
|
|
|
"context-video-showstats", 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,
|
2011-10-03 10:42:36 -07:00
|
|
|
"context-video-saveimage", true,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-sendvideo", true
|
|
|
|
].concat(inspectItems));
|
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,
|
2011-10-03 20:47:41 -07:00
|
|
|
"context-media-hidecontrols", false,
|
|
|
|
"context-video-showstats", 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,
|
2011-10-03 10:42:36 -07:00
|
|
|
"context-video-saveimage", false,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-sendvideo", true
|
|
|
|
].concat(inspectItems));
|
2009-07-09 18:26:35 -07:00
|
|
|
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,
|
2011-10-03 20:47:41 -07:00
|
|
|
"context-media-hidecontrols", false,
|
|
|
|
"context-video-showstats", 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,
|
2011-10-03 10:42:36 -07:00
|
|
|
"context-video-saveimage", false,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-sendvideo", false
|
|
|
|
].concat(inspectItems));
|
2009-07-09 18:26:35 -07:00
|
|
|
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-openframeintab", true,
|
2010-07-20 15:11:00 -07:00
|
|
|
"context-openframe", true,
|
2009-07-09 18:26:35 -07:00
|
|
|
"---", 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,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-viewinfo", true
|
|
|
|
].concat(inspectItems));
|
2008-10-22 23:36:52 -07:00
|
|
|
closeContextMenu();
|
2011-11-02 13:52:21 -07:00
|
|
|
openContextMenuFor(video_in_iframe); // Invoke context menu for next test.
|
2010-06-01 11:08:38 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:
|
2011-11-02 13:52:21 -07:00
|
|
|
// Context menu for a video in an iframe
|
|
|
|
checkContextMenu(["context-media-play", true,
|
|
|
|
"context-media-mute", true,
|
|
|
|
"context-media-hidecontrols", true,
|
|
|
|
"context-video-showstats", true,
|
|
|
|
"context-video-fullscreen", true,
|
|
|
|
"---", null,
|
|
|
|
"context-viewvideo", true,
|
|
|
|
"context-copyvideourl", true,
|
|
|
|
"---", null,
|
|
|
|
"context-savevideo", true,
|
|
|
|
"context-video-saveimage", true,
|
|
|
|
"context-sendvideo", true,
|
|
|
|
"frame", null,
|
|
|
|
["context-showonlythisframe", true,
|
|
|
|
"context-openframeintab", true,
|
|
|
|
"context-openframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-reloadframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-bookmarkframe", true,
|
|
|
|
"context-saveframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-printframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-viewframeinfo", true], null].concat(inspectItems));
|
|
|
|
closeContextMenu();
|
|
|
|
openContextMenuFor(image_in_iframe); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
// Context menu for an image in an iframe
|
|
|
|
checkContextMenu(["context-viewimage", true,
|
|
|
|
"context-copyimage-contents", true,
|
|
|
|
"context-copyimage", true,
|
|
|
|
"---", null,
|
|
|
|
"context-saveimage", true,
|
|
|
|
"context-sendimage", true,
|
|
|
|
"context-setDesktopBackground", true,
|
|
|
|
"context-viewimageinfo", true,
|
|
|
|
"frame", null,
|
|
|
|
["context-showonlythisframe", true,
|
|
|
|
"context-openframeintab", true,
|
|
|
|
"context-openframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-reloadframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-bookmarkframe", true,
|
|
|
|
"context-saveframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-printframe", true,
|
|
|
|
"---", null,
|
|
|
|
"context-viewframeinfo", true], null].concat(inspectItems));
|
|
|
|
closeContextMenu();
|
|
|
|
openContextMenuFor(textarea, false, true); // Invoke context menu for next test, but wait for the spellcheck.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 14:
|
2010-06-01 11:08:38 -07:00
|
|
|
// Context menu for textarea
|
|
|
|
checkContextMenu(["*chubbiness", true, // spelling suggestion
|
|
|
|
"spell-add-to-dictionary", true,
|
|
|
|
"---", null,
|
|
|
|
"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,
|
|
|
|
"spell-dictionaries", true,
|
|
|
|
["spell-check-dictionary-en-US", true,
|
|
|
|
"---", null,
|
2011-09-21 03:16:25 -07:00
|
|
|
"spell-add-dictionaries", true], null,
|
2011-10-26 19:48:21 -07:00
|
|
|
].concat(inspectItems));
|
2011-12-29 13:06:56 -08:00
|
|
|
contextMenu.ownerDocument.getElementById("spell-add-to-dictionary").doCommand(); // Add to dictionary
|
|
|
|
closeContextMenu();
|
|
|
|
openContextMenuFor(textarea, false, true); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
// Context menu for textarea after a word has been added
|
|
|
|
// to the dictionary
|
|
|
|
checkContextMenu(["spell-undo-add-to-dictionary", true,
|
|
|
|
"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,
|
|
|
|
"spell-dictionaries", true,
|
|
|
|
["spell-check-dictionary-en-US", true,
|
|
|
|
"---", null,
|
|
|
|
"spell-add-dictionaries", true], null,
|
|
|
|
].concat(inspectItems));
|
|
|
|
contextMenu.ownerDocument.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary
|
2010-06-01 11:08:38 -07:00
|
|
|
closeContextMenu();
|
2011-12-29 13:06:56 -08:00
|
|
|
openContextMenuFor(contenteditable);
|
2010-06-01 11:08:38 -07:00
|
|
|
break;
|
|
|
|
|
2011-12-29 13:06:56 -08:00
|
|
|
case 16:
|
2010-06-01 11:08:38 -07:00
|
|
|
// Context menu for contenteditable
|
|
|
|
checkContextMenu(["spell-no-suggestions", false,
|
|
|
|
"spell-add-to-dictionary", true,
|
|
|
|
"---", null,
|
|
|
|
"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,
|
|
|
|
"spell-dictionaries", true,
|
|
|
|
["spell-check-dictionary-en-US", true,
|
|
|
|
"---", null,
|
2011-10-26 19:48:21 -07:00
|
|
|
"spell-add-dictionaries", true], null
|
|
|
|
].concat(inspectItems));
|
2010-06-01 11:08:38 -07:00
|
|
|
|
|
|
|
closeContextMenu();
|
|
|
|
openContextMenuFor(inputspell); // Invoke context menu for next test.
|
|
|
|
break;
|
2008-10-22 23:36:52 -07:00
|
|
|
|
2011-12-29 13:06:56 -08:00
|
|
|
case 17:
|
2010-06-01 11:08:38 -07:00
|
|
|
// Context menu for spell-check input
|
|
|
|
checkContextMenu(["*prodigality", true, // spelling suggestion
|
|
|
|
"spell-add-to-dictionary", true,
|
|
|
|
"---", null,
|
|
|
|
"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,
|
|
|
|
"spell-dictionaries", true,
|
|
|
|
["spell-check-dictionary-en-US", true,
|
|
|
|
"---", null,
|
2011-10-26 19:48:21 -07:00
|
|
|
"spell-add-dictionaries", true], null
|
|
|
|
].concat(inspectItems));
|
2010-06-01 11:08:38 -07:00
|
|
|
|
|
|
|
closeContextMenu();
|
2010-08-10 13:55:31 -07:00
|
|
|
openContextMenuFor(link); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
2011-12-29 13:06:56 -08:00
|
|
|
case 18:
|
2010-08-10 13:55:31 -07:00
|
|
|
executeCopyCommand("cmd_copyLink", "http://mozilla.com/");
|
|
|
|
closeContextMenu();
|
2011-08-08 10:31:32 -07:00
|
|
|
openContextMenuFor(pagemenu); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
2011-12-29 13:06:56 -08:00
|
|
|
case 19:
|
2011-08-08 10:31:32 -07:00
|
|
|
// Context menu for element with assigned content context menu
|
|
|
|
checkContextMenu(["+Plain item", {type: "", icon: "", checked: false, disabled: false},
|
|
|
|
"+Disabled item", {type: "", icon: "", checked: false, disabled: true},
|
2011-08-10 23:07:26 -07:00
|
|
|
"+Item w/ textContent", {type: "", icon: "", checked: false, disabled: false},
|
2011-08-08 10:31:32 -07:00
|
|
|
"---", null,
|
|
|
|
"+Checkbox", {type: "checkbox", icon: "", checked: true, disabled: false},
|
|
|
|
"---", null,
|
|
|
|
"+Radio1", {type: "checkbox", icon: "", checked: true, disabled: false},
|
|
|
|
"+Radio2", {type: "checkbox", icon: "", checked: false, disabled: false},
|
|
|
|
"+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false},
|
|
|
|
"---", null,
|
|
|
|
"+Item w/ icon", {type: "", icon: "favicon.ico", checked: false, disabled: false},
|
|
|
|
"+Item w/ bad icon", {type: "", icon: "", checked: false, disabled: false},
|
|
|
|
"---", null,
|
|
|
|
"generated-submenu-1", true,
|
|
|
|
["+Radio1", {type: "checkbox", icon: "", checked: false, disabled: false},
|
|
|
|
"+Radio2", {type: "checkbox", icon: "", checked: true, disabled: false},
|
|
|
|
"+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false},
|
|
|
|
"---", null,
|
|
|
|
"+Checkbox", {type: "checkbox", icon: "", checked: false, disabled: false}], null,
|
|
|
|
"---", null,
|
|
|
|
"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,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-viewinfo", true
|
|
|
|
].concat(inspectItems));
|
2011-08-08 10:31:32 -07:00
|
|
|
|
|
|
|
invokeItemAction("0");
|
|
|
|
closeContextMenu();
|
|
|
|
openContextMenuFor(pagemenu, true); // Invoke context menu for next test.
|
|
|
|
break;
|
|
|
|
|
2011-12-29 13:06:56 -08:00
|
|
|
case 20:
|
2011-08-08 10:31:32 -07:00
|
|
|
// Context menu for element with assigned content context menu
|
|
|
|
// The shift key should bypass content context menu processing
|
|
|
|
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,
|
2011-10-26 19:48:21 -07:00
|
|
|
"context-viewinfo", true
|
|
|
|
].concat(inspectItems));
|
2010-08-10 13:55:31 -07:00
|
|
|
|
2008-10-22 23:36:52 -07:00
|
|
|
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;
|
2011-09-10 09:17:36 -07:00
|
|
|
var subwindow, chromeWin, contextMenu, lastElement;
|
2010-09-04 09:45:25 -07:00
|
|
|
var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2,
|
2011-11-02 13:52:21 -07:00
|
|
|
iframe, video_in_iframe, image_in_iframe, textarea, contenteditable, inputspell, pagemenu;
|
2008-10-22 23:36:52 -07:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2010-09-05 20:30:17 -07:00
|
|
|
if (chromeWin.document.getElementById("Browser:Stop").getAttribute("disabled") != "true") {
|
|
|
|
SimpleTest.executeSoon(startTest);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-10 09:17:36 -07:00
|
|
|
lastElement = null;
|
|
|
|
|
2008-10-22 23:36:52 -07:00
|
|
|
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");
|
2011-11-02 13:52:21 -07:00
|
|
|
video_in_iframe = subwindow.document.getElementById("test-video-in-iframe").contentDocument.getElementsByTagName("video")[0];
|
|
|
|
video_in_iframe.pause();
|
|
|
|
image_in_iframe = subwindow.document.getElementById("test-image-in-iframe").contentDocument.getElementsByTagName("img")[0];
|
2010-06-01 11:08:38 -07:00
|
|
|
textarea = subwindow.document.getElementById("test-textarea");
|
|
|
|
contenteditable = subwindow.document.getElementById("test-contenteditable");
|
2011-08-12 12:12:45 -07:00
|
|
|
contenteditable.focus(); // content editable needs to be focused to enable spellcheck
|
2010-06-01 11:08:38 -07:00
|
|
|
inputspell = subwindow.document.getElementById("test-input-spellcheck");
|
2011-08-08 10:31:32 -07:00
|
|
|
pagemenu = subwindow.document.getElementById("test-pagemenu");
|
2008-10-22 23:36:52 -07:00
|
|
|
|
|
|
|
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>
|