Bug 555547 - A command of placesContextMenu is carried out for a wrong bookmark item.

r=mak a=blocking
This commit is contained in:
Asaf Romano 2011-02-02 17:00:52 +01:00
parent dc7fcb7f03
commit 5bd9e94f22
5 changed files with 77 additions and 9 deletions

View File

@ -57,6 +57,8 @@ PlacesViewBase.prototype = {
_viewElt: null,
get viewElt() this._viewElt,
get controllers() this._viewElt.controllers,
// The xul element that represents the root container.
_rootElt: null,

View File

@ -1584,20 +1584,22 @@ function goUpdatePlacesCommands() {
function doGetPlacesControllerForCommand(aCommand)
{
// A context menu may be built for non-focusable views. Thus, we first try
// to look for a view associated with document.popupNode
let popupNode = document.popupNode;
if (popupNode) {
let view = PlacesUIUtils.getViewForNode(popupNode);
if (view && view._contextMenuShown)
return view.controllers.getControllerForCommand(aCommand);
}
// When we're not building a context menu, only focusable views
// are possible. Thus, we can safely use the command dispatcher.
let controller = top.document.commandDispatcher
.getControllerForCommand(aCommand);
if (controller)
return controller;
// If building commands for a context menu, look for an element in the
// current popup.
let element = document.popupNode;
if (element) {
let view = PlacesUIUtils.getViewForNode(element);
if (view && view._contextMenuShown)
return view.viewElt.controllers.getControllerForCommand(aCommand);
}
return null;
}

View File

@ -665,15 +665,19 @@
]]></body>
</method>
<field name="_contextMenuShown">false</field>
<method name="buildContextMenu">
<parameter name="aPopup"/>
<body><![CDATA[
this._contextMenuShown = true;
return this.controller.buildContextMenu(aPopup);
]]></body>
</method>
<method name="destroyContextMenu">
<parameter name="aPopup"/>
this._contextMenuShown = false;
<body/>
</method>
</implementation>

View File

@ -72,6 +72,7 @@ _BROWSER_TEST_FILES = \
frameRight.html \
browser_toolbar_migration.js \
browser_library_batch_delete.js \
browser_555547.js \
$(NULL)
libs:: $(_BROWSER_TEST_FILES)

View File

@ -0,0 +1,59 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
function test() {
waitForExplicitFinish();
let sidebarBox = document.getElementById("sidebar-box");
is(sidebarBox.hidden, true, "The sidebar should be hidden");
// Uncollapse the personal toolbar if needed.
let toolbar = document.getElementById("PersonalToolbar");
let wasCollapsed = toolbar.collapsed;
if (wasCollapsed)
setToolbarVisibility(toolbar, true);
let sidebar = document.getElementById("sidebar");
sidebar.addEventListener("load", function() {
sidebar.removeEventListener("load", arguments.callee, true);
let tree = sidebar.contentDocument.getElementById("bookmarks-view");
// The Places view is build on load, so we enqueue our test.
executeSoon(function() {
// Focus the tree and check if its controller is returned.
tree.focus();
let controller = doGetPlacesControllerForCommand("placesCmd_copy");
let treeController = tree.controllers
.getControllerForCommand("placesCmd_copy");
ok(controller == treeController, "tree controller was returned");
// Open the context menu for a toolbar item, and check if the toolbar's
// controller is returned.
let toolbarItems = document.getElementById("PlacesToolbarItems");
EventUtils.synthesizeMouse(toolbarItems.childNodes[0],
4, 4, { type: "contextmenu", button: 2 },
window);
controller = doGetPlacesControllerForCommand("placesCmd_copy");
let toolbarController = document.getElementById("PlacesToolbar")
.controllers
.getControllerForCommand("placesCmd_copy");
ok(controller == toolbarController, "the toolbar controller was returned");
document.getElementById("placesContext").hidePopup();
// Now that the context menu is closed, try to get the tree controller again.
tree.focus();
controller = doGetPlacesControllerForCommand("placesCmd_copy");
ok(controller == treeController, "tree controller was returned");
toggleSidebar();
if (wasCollapsed)
setToolbarVisibility(toolbar, false);
finish();
});
}, true);
toggleSidebar("viewBookmarksSidebar", true);
}