diff --git a/browser/base/content/test/test_contextmenu.html b/browser/base/content/test/test_contextmenu.html index cbaa09667888..de2ad4cc4475 100644 --- a/browser/base/content/test/test_contextmenu.html +++ b/browser/base/content/test/test_contextmenu.html @@ -36,6 +36,20 @@ function closeContextMenu() { contextMenu.hidePopup(); } +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); +} + function getVisibleMenuItems(aMenu) { var items = []; var accessKeys = {}; @@ -391,6 +405,13 @@ function runTest(testNum) { "spell-add-dictionaries", true], null]); closeContextMenu(); + openContextMenuFor(link); // Invoke context menu for next test. + break; + + case 15: + executeCopyCommand("cmd_copyLink", "http://mozilla.com/"); + closeContextMenu(); + subwindow.close(); SimpleTest.finish(); return; diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 6a10e75d54d8..e7aa916fd075 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -3328,6 +3328,8 @@ DocumentViewerImpl::GetPopupNode(nsIDOMNode** aNode) { NS_ENSURE_ARG_POINTER(aNode); + *aNode = nsnull; + // get the document nsIDocument* document = GetDocument(); NS_ENSURE_TRUE(document, NS_ERROR_FAILURE); @@ -3340,7 +3342,22 @@ DocumentViewerImpl::GetPopupNode(nsIDOMNode** aNode) NS_ENSURE_TRUE(root, NS_ERROR_FAILURE); // get the popup node - NS_IF_ADDREF(*aNode = root->GetPopupNode()); + nsCOMPtr node = root->GetPopupNode(); +#ifdef MOZ_XUL + if (!node) { + nsPIDOMWindow* rootWindow = root->GetWindow(); + if (rootWindow) { + nsCOMPtr rootDoc = do_QueryInterface(rootWindow->GetExtantDocument()); + if (rootDoc) { + nsXULPopupManager* pm = nsXULPopupManager::GetInstance(); + if (pm) { + node = pm->GetLastTriggerPopupNode(rootDoc); + } + } + } + } +#endif + node.swap(*aNode); } return NS_OK;