Bug 625195 - 'Move to New Window' is disabled if a tab is orphaned or the only tab in the active group r=dao

This commit is contained in:
Raymond Lee 2011-05-13 10:17:04 +08:00
parent b32b5f5fa7
commit ce22dc914e
6 changed files with 66 additions and 5 deletions

View File

@ -8488,7 +8488,7 @@ var TabContextMenu = {
updateContextMenu: function updateContextMenu(aPopupMenu) {
this.contextTab = document.popupNode.localName == "tab" ?
document.popupNode : gBrowser.selectedTab;
let disabled = gBrowser.visibleTabs.length == 1;
let disabled = gBrowser.tabs.length == 1;
// Enable the "Close Tab" menuitem when the window doesn't close with the last tab.
document.getElementById("context_closeTab").disabled =
@ -8498,6 +8498,11 @@ var TabContextMenu = {
for (var i = 0; i < menuItems.length; i++)
menuItems[i].disabled = disabled;
disabled = gBrowser.visibleTabs.length == 1;
menuItems = aPopupMenu.getElementsByAttribute("tbattr", "tabbrowser-multiple-visible");
for (var i = 0; i < menuItems.length; i++)
menuItems[i].disabled = disabled;
// Session store
document.getElementById("context_undoCloseTab").disabled =
Cc["@mozilla.org/browser/sessionstore;1"].

View File

@ -139,7 +139,7 @@
oncommand="gBrowser.replaceTabWithWindow(TabContextMenu.contextTab);"/>
<menuseparator/>
<menuitem id="context_reloadAllTabs" label="&reloadAllTabs.label;" accesskey="&reloadAllTabs.accesskey;"
tbattr="tabbrowser-multiple"
tbattr="tabbrowser-multiple-visible"
oncommand="gBrowser.reloadAllTabs();"/>
<menuitem id="context_bookmarkAllTabs"
label="&bookmarkAllTabs.label;"

View File

@ -1913,7 +1913,7 @@ let GroupItems = {
// ----------
// Function: uninit
uninit : function GroupItems_uninit () {
uninit: function GroupItems_uninit() {
// call our cleanup functions
this._cleanupFunctions.forEach(function(func) {
func();
@ -1928,7 +1928,7 @@ let GroupItems = {
// ----------
// Function: newGroup
// Creates a new empty group.
newGroup: function () {
newGroup: function GroupItems_newGroup() {
let bounds = new Rect(20, 20, 250, 200);
return new GroupItem([], {bounds: bounds, immediately: true});
},

View File

@ -56,7 +56,7 @@ function test() {
// Check the context menu with one tab.
popup(testTab);
is(TabContextMenu.contextTab, testTab, "TabContextMenu context is the test tab");
is(document.getElementById("context_closeTab").disabled, true, "Close Tab is disabled");
is(document.getElementById("context_closeTab").disabled, false, "Close Tab is enabled when more than one tab exists");
is(document.getElementById("context_reloadAllTabs").disabled, true, "Reload All Tabs is disabled");
// Add a tab that will get pinned

View File

@ -105,6 +105,7 @@ _BROWSER_FILES = \
browser_tabview_bug624847.js \
browser_tabview_bug624931.js \
browser_tabview_bug624953.js \
browser_tabview_bug625195.js \
browser_tabview_bug625269.js \
browser_tabview_bug625424.js \
browser_tabview_bug625666.js \

View File

@ -0,0 +1,55 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
is(gBrowser.tabs.length, 1, "Only one tab exist");
let originalTab = gBrowser.tabs[0];
popup(originalTab);
ok(document.getElementById("context_closeTab").disabled, "The 'Close tab' menu item is disabled");
ok(document.getElementById("context_openTabInWindow").disabled, "The 'Move to New Window' menu item is disabled");
let newTabOne = gBrowser.addTab("about:blank", {skipAnimation: true});
waitForExplicitFinish();
showTabView(function() {
registerCleanupFunction(function () {
if (gBrowser.tabs[1])
gBrowser.removeTab(gBrowser.tabs[1]);
if (gBrowser.tabs[2])
gBrowser.removeTab(gBrowser.tabs[2]);
TabView.hide();
});
let contentWindow = TabView.getContentWindow();
is(contentWindow.GroupItems.groupItems.length, 1, "Has one group only");
let tabItems = contentWindow.GroupItems.groupItems[0].getChildren();
ok(tabItems.length, 2, "There are two tabItems in this group");
whenTabViewIsHidden(function() {
popup(gBrowser.tabs[0]);
ok(!document.getElementById("context_closeTab").disabled, "The 'Close tab' menu item is enabled");
ok(!document.getElementById("context_openTabInWindow").disabled, "The 'Move to New Window' menu item is enabled");
let newTabTwo = gBrowser.selectedTab;
gBrowser.selected = originalTab;
gBrowser.removeTab(newTabOne);
gBrowser.removeTab(newTabTwo);
finish();
});
let newGroup = contentWindow.GroupItems.newGroup();
newGroup.newTab();
});
}
function popup(tab) {
document.popupNode = tab;
TabContextMenu.updateContextMenu(document.getElementById("tabContextMenu"));
}