Bug 625195 - 'Move to New Window' is disabled if a tab is orphaned or the only tab in the active group r=dao
authorRaymond Lee <raymond@raysquare.com>
Fri, 13 May 2011 10:17:04 +0800
changeset 69549 62b546e8060411c69a5c0c1e957063634db5c473
parent 69548 48c0f02f4614fe670a736f6eb8924a4c3c3e60e5
child 69550 e90e60817ea77b837938f728a1ecf9005f3bb1fc
push id20009
push userMs2ger@gmail.com
push dateSun, 15 May 2011 13:28:32 +0000
treeherdermozilla-central@62b546e80604 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs625195
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 625195 - 'Move to New Window' is disabled if a tab is orphaned or the only tab in the active group r=dao
browser/base/content/browser.js
browser/base/content/browser.xul
browser/base/content/tabview/groupitems.js
browser/base/content/test/browser_visibleTabs_contextMenu.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug625195.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -8483,26 +8483,31 @@ function restoreLastSession() {
   ss.restoreLastSession();
 }
 
 var TabContextMenu = {
   contextTab: null,
   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 =
       disabled && gBrowser.tabContainer._closeWindowWithLastTab;
 
     var menuItems = aPopupMenu.getElementsByAttribute("tbattr", "tabbrowser-multiple");
     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"].
       getService(Ci.nsISessionStore).
       getClosedTabCount(window) == 0;
 
     // Only one of pin/unpin should be visible
     document.getElementById("context_pinTab").hidden = this.contextTab.pinned;
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -134,17 +134,17 @@
         </menupopup>
       </menu>
       <menuitem id="context_openTabInWindow" label="&moveToNewWindow.label;"
                 accesskey="&moveToNewWindow.accesskey;"
                 tbattr="tabbrowser-multiple"
                 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;"
                 accesskey="&bookmarkAllTabs.accesskey;"
                 command="Browser:BookmarkAllTabs"/>
       <menuitem id="context_closeOtherTabs" label="&closeOtherTabs.label;" accesskey="&closeOtherTabs.accesskey;"
                 oncommand="gBrowser.removeAllTabsBut(TabContextMenu.contextTab);"/>
       <menuseparator/>
--- a/browser/base/content/tabview/groupitems.js
+++ b/browser/base/content/tabview/groupitems.js
@@ -1908,32 +1908,32 @@ let GroupItems = {
     this._cleanupFunctions.push(function() {
       AllTabs.unregister("attrModified", handleAttrModified);
       AllTabs.unregister("close", handleClose);
     });
   },
 
   // ----------
   // Function: uninit
-  uninit : function GroupItems_uninit () {
+  uninit: function GroupItems_uninit() {
     // call our cleanup functions
     this._cleanupFunctions.forEach(function(func) {
       func();
     });
 
     this._cleanupFunctions = [];
 
     // additional clean up
     this.groupItems = null;
   },
 
   // ----------
   // 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});
   },
 
   // ----------
   // Function: pauseArrange
   // Bypass arrange() calls and collect for resolution in
   // resumeArrange()
--- a/browser/base/content/test/browser_visibleTabs_contextMenu.js
+++ b/browser/base/content/test/browser_visibleTabs_contextMenu.js
@@ -51,17 +51,17 @@ function test() {
   // Hide the original tab.
   gBrowser.selectedTab = testTab;
   gBrowser.showOnlyTheseTabs([testTab]);
   is(gBrowser.visibleTabs.length, 1, "now there is only one visible tab");
   
   // 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
   // So now there's one pinned tab, one visible unpinned tab, and one hidden tab
   let pinned = gBrowser.addTab();
   gBrowser.pinTab(pinned);
   is(gBrowser.visibleTabs.length, 2, "now there are two visible tabs");
 
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -100,16 +100,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug622872.js \
                  browser_tabview_bug623768.js \
                  browser_tabview_bug624265.js \
                  browser_tabview_bug624692.js \
                  browser_tabview_bug624727.js \
                  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 \
                  browser_tabview_bug626368.js \
                  browser_tabview_bug626525.js \
                  browser_tabview_bug626791.js \
                  browser_tabview_bug627288.js \
                  browser_tabview_bug627736.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug625195.js
@@ -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"));
+}
+