Bug 627065, copy commands on context menu don't work on sidebar pages, r=dao,a=blocking

This commit is contained in:
Neil Deakin 2011-02-08 10:02:20 -05:00
parent 07c3f84837
commit f8f91575b9
2 changed files with 39 additions and 1 deletions

View File

@ -22,7 +22,7 @@ function openPanelUrl(event) {
sidebar.removeEventListener("load", delayedOpenUrl, true);
// XXX See comment above
sidebar.contentDocument.addEventListener("load", delayedRunTest, true);
var url = 'data:text/html,<div%20id="test_bug409481">Content!</div>';
var url = 'data:text/html,<div%20id="test_bug409481">Content!</div><a id="link" href="http://www.example.com/ctest">Link</a><input id="textbox">';
sidebar.contentWindow.loadWebPanel(url);
}
@ -39,6 +39,42 @@ function runTest(event) {
var div = browser && browser.contentDocument.getElementById("test_bug409481");
ok(div && div.textContent == "Content!", "Sidebar content loaded");
var link = browser && browser.contentDocument.getElementById("link");
sidebar.contentDocument.addEventListener("popupshown", contextMenuOpened, false);
EventUtils.synthesizeMouseAtCenter(link, { type: "contextmenu", button: 2 }, browser.contentWindow);
}
function contextMenuOpened()
{
var sidebar = document.getElementById("sidebar");
sidebar.contentDocument.removeEventListener("popupshown", contextMenuOpened, false);
var copyLinkCommand = sidebar.contentDocument.getElementById("context-copylink");
copyLinkCommand.addEventListener("command", copyLinkCommandExecuted, false);
copyLinkCommand.doCommand();
}
function copyLinkCommandExecuted(event)
{
event.target.removeEventListener("command", copyLinkCommandExecuted, false);
var sidebar = document.getElementById("sidebar");
var browser = sidebar.contentDocument.getElementById("web-panels-browser");
var textbox = browser && browser.contentDocument.getElementById("textbox");
textbox.focus();
document.commandDispatcher.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
is(textbox.value, "http://www.example.com/ctest", "copy link command");
sidebar.contentDocument.addEventListener("popuphidden", contextMenuClosed, false);
event.target.parentNode.hidePopup();
}
function contextMenuClosed()
{
var sidebar = document.getElementById("sidebar");
sidebar.contentDocument.removeEventListener("popuphidden", contextMenuClosed, false);
toggleSidebar("viewWebPanelsSidebar");
ok(document.getElementById("sidebar-box").hidden, "Sidebar successfully hidden");

View File

@ -84,6 +84,8 @@
onpopupshowing="if (event.target != this)
return true;
gContextMenu = new nsContextMenu(this, getPanelBrowser());
if (gContextMenu.shouldDisplay)
document.popupNode = this.triggerNode;
return gContextMenu.shouldDisplay;"
onpopuphiding="if (event.target == this)
gContextMenu = null;">