Bug 633788 - "closing last tab" inconsistency between main browser window and panorama [r=ian, a=beltzner]
authorRaymond Lee <raymond@appcoast.com>
Tue, 22 Feb 2011 16:02:29 -0500
changeset 63010 9fad1f22f5566648e7f578076ddfc6930a7b9309
parent 63009 d6975e3ecb4e80d5b89800a2bc2dbefb5ed7ed46
child 63011 7e2ebe8812428633b31174f31a1423e2d910e398
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersian, beltzner
bugs633788
milestone2.0b13pre
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 633788 - "closing last tab" inconsistency between main browser window and panorama [r=ian, a=beltzner]
browser/base/content/tabview/groupitems.js
browser/base/content/tabview/tabitems.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug633788.js
--- a/browser/base/content/tabview/groupitems.js
+++ b/browser/base/content/tabview/groupitems.js
@@ -801,17 +801,17 @@ GroupItem.prototype = Utils.extend(new I
     // In other words, the group "close" event is fired before all browser
     // tabs in the group are closed.  The below code would fire the group "close"
     // event only after all browser tabs in that group are closed.
     let shouldRemoveTabItems = [];
     let toClose = this._children.concat();
     toClose.forEach(function(child) {
       child.removeSubscriber(self, "close");
 
-      let removed = child.close();
+      let removed = child.close(true);
       if (removed) {
         shouldRemoveTabItems.push(child);
       } else {
         // child.removeSubscriber() must be called before child.close(), 
         // therefore we call child.addSubscriber() if the tab is not removed.
         child.addSubscriber(self, "close", function() {
           self.remove(child);
         });
--- a/browser/base/content/tabview/tabitems.js
+++ b/browser/base/content/tabview/tabitems.js
@@ -536,18 +536,34 @@ TabItem.prototype = Utils.extend(new Ite
     this.zIndex = value;
     this.$container.css({zIndex: value});
   },
 
   // ----------
   // Function: close
   // Closes this item (actually closes the tab associated with it, which automatically
   // closes the item.
+  // Parameters:
+  //   groupClose - true if this method is called by group close action.
   // Returns true if this tab is removed.
-  close: function TabItem_close() {
+  close: function TabItem_close(groupClose) {
+    // When the last tab is closed, put a new tab into closing tab's group. If
+    // closing tab doesn't belong to a group and no empty group, create a new 
+    // one for the new tab.
+    if (!groupClose && gBrowser.tabs.length == 1) {
+      if (this.tab._tabViewTabItem.parent) {
+        group = this.tab._tabViewTabItem.parent;
+      } else {
+        let emptyGroups = GroupItems.groupItems.filter(function (groupItem) {
+          return (!groupItem.getChildren().length);
+        });
+        group = (emptyGroups.length ? emptyGroups[0] : GroupItems.newGroup());
+      }
+      group.newTab();
+    }
     // when "TabClose" event is fired, the browser tab is about to close and our 
     // item "close" is fired before the browser tab actually get closed. 
     // Therefore, we need "tabRemoved" event below.
     gBrowser.removeTab(this.tab);
     let tabNotClosed = 
       Array.some(gBrowser.tabs, function(tab) { return tab == this.tab; }, this);
     if (!tabNotClosed)
       this._sendToSubscribers("tabRemoved");
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -109,16 +109,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug627736.js \
                  browser_tabview_bug628165.js \
                  browser_tabview_bug628270.js \
                  browser_tabview_bug629189.js \
                  browser_tabview_bug629195.js \
                  browser_tabview_bug630102.js \
                  browser_tabview_bug630157.js \
                  browser_tabview_bug631662.js \
+                 browser_tabview_bug633788.js \
                  browser_tabview_bug634077.js \
                  browser_tabview_bug634085.js \
                  browser_tabview_bug634158.js \
                  browser_tabview_dragdrop.js \
                  browser_tabview_exit_button.js \
                  browser_tabview_expander.js \
                  browser_tabview_group.js \
                  browser_tabview_launch.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug633788.js
@@ -0,0 +1,31 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  waitForExplicitFinish();
+
+  showTabView(function () {
+    is(gBrowser.tabs.length, 1, "There is only one tab");
+
+    let tab = gBrowser.tabs[0];
+    let tabItem = tab._tabViewTabItem;
+    ok(tabItem.parent, "The tab item belongs to a group");
+    let groupId = tabItem.parent.id;
+
+    tab._tabViewTabItem.close();
+
+    whenTabViewIsHidden(function() {
+      // a new tab with group should be opened
+      is(gBrowser.tabs.length, 1, "There is still one tab");
+      isnot(gBrowser.selectedTab, tab, "The tab is different");
+
+      tab = gBrowser.tabs[0];
+      tabItem = tab._tabViewTabItem;
+      ok(tabItem.parent, "This new tab item belongs to a group");
+
+      is(tabItem.parent.id, groupId, "The group is different");
+
+      finish();
+    });
+  });
+}