Bug 654295 - Closing last tab of a group doesn't show Panorama r=tim
authorRaymond Lee <raymond@raysquare.com>
Mon, 10 Oct 2011 17:50:07 +0800
changeset 78434 8586a8f3929fd0ecd1f1f897a3367a836064adac
parent 78433 e0e9529bdc84a40a82d064505e7d5f4d8fa3ea20
child 78435 17eecce51c43cd1e9f44bb502312db9ec47aa9b1
push id2540
push userbmo@edmorley.co.uk
push dateMon, 10 Oct 2011 14:42:38 +0000
treeherdermozilla-inbound@8586a8f3929f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstim
bugs654295
milestone10.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 654295 - Closing last tab of a group doesn't show Panorama r=tim
browser/base/content/browser-tabview.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug654295.js
--- a/browser/base/content/browser-tabview.js
+++ b/browser/base/content/browser-tabview.js
@@ -37,16 +37,17 @@
 # ***** END LICENSE BLOCK *****
 
 let TabView = {
   _deck: null,
   _iframe: null,
   _window: null,
   _initialized: false,
   _browserKeyHandlerInitialized: false,
+  _closedLastVisibleTabBeforeFrameInitialized: false,
   _isFrameLoading: false,
   _initFrameCallbacks: [],
   _lastSessionGroupName: null,
   PREF_BRANCH: "browser.panorama.",
   PREF_FIRST_RUN: "browser.panorama.experienced_first_run",
   PREF_STARTUP_PAGE: "browser.startup.page",
   PREF_RESTORE_ENABLED_ONCE: "browser.panorama.session_restore_enabled_once",
   GROUPS_IDENTIFIER: "tabview-groups",
@@ -119,24 +120,34 @@ let TabView = {
             let parsedData = JSON.parse(data);
             this.updateGroupNumberBroadcaster(parsedData.totalNumber || 1);
           }
         } catch (e) { }
 
         let self = this;
         // if a tab is changed from hidden to unhidden and the iframe is not
         // initialized, load the iframe and setup the tab.
-        this._tabShowEventListener = function (event) {
+        this._tabShowEventListener = function(event) {
           if (!self._window)
             self._initFrame(function() {
               self._window.UI.onTabSelect(gBrowser.selectedTab);
+              if (self._closedLastVisibleTabBeforeFrameInitialized) {
+                self._closedLastVisibleTabBeforeFrameInitialized = false;
+                self._window.UI.showTabView(false);
+              }
             });
         };
+        this._tabCloseEventListener = function(event) {
+          if (!self._window && gBrowser.visibleTabs.length == 0)
+            self._closedLastVisibleTabBeforeFrameInitialized = true;
+        };
         gBrowser.tabContainer.addEventListener(
-          "TabShow", this._tabShowEventListener, true);
+          "TabShow", this._tabShowEventListener, false);
+        gBrowser.tabContainer.addEventListener(
+          "TabClose", this._tabCloseEventListener, false);
 
        // grab the last used group title
        this._lastSessionGroupName = sessionstore.getWindowValue(window,
          this.LAST_SESSION_GROUP_NAME_IDENTIFIER);
       }
     }
 
     Services.prefs.addObserver(this.PREF_BRANCH, this, false);
@@ -156,20 +167,23 @@ let TabView = {
   // ----------
   // Uninitializes TabView.
   uninit: function TabView_uninit() {
     if (!this._initialized)
       return;
 
     Services.prefs.removeObserver(this.PREF_BRANCH, this);
 
-    if (this._tabShowEventListener) {
+    if (this._tabShowEventListener)
       gBrowser.tabContainer.removeEventListener(
-        "TabShow", this._tabShowEventListener, true);
-    }
+        "TabShow", this._tabShowEventListener, false);
+
+    if (this._tabCloseEventListener)
+      gBrowser.tabContainer.removeEventListener(
+        "TabClose", this._tabCloseEventListener, false);
 
     this._initialized = false;
   },
 
   // ----------
   // Creates the frame and calls the callback once it's loaded. 
   // If the frame already exists, calls the callback immediately. 
   _initFrame: function TabView__initFrame(callback) {
@@ -208,20 +222,24 @@ let TabView = {
       window.removeEventListener("tabviewframeinitialized", onInit, false);
 
       self._isFrameLoading = false;
       self._window = self._iframe.contentWindow;
       self._setBrowserKeyHandlers();
 
       if (self._tabShowEventListener) {
         gBrowser.tabContainer.removeEventListener(
-          "TabShow", self._tabShowEventListener, true);
+          "TabShow", self._tabShowEventListener, false);
         self._tabShowEventListener = null;
       }
-
+      if (self._tabCloseEventListener) {
+        gBrowser.tabContainer.removeEventListener(
+          "TabClose", self._tabCloseEventListener, false);
+        self._tabCloseEventListener = null;
+      }
       self._initFrameCallbacks.forEach(function (cb) cb());
       self._initFrameCallbacks = [];
     }, false);
 
     this._iframe.setAttribute("src", "chrome://browser/content/tabview.html");
     this._deck.appendChild(this._iframe);
   },
 
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -141,16 +141,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug644097.js \
                  browser_tabview_bug648882.js \
                  browser_tabview_bug649006.js \
                  browser_tabview_bug649307.js \
                  browser_tabview_bug649319.js \
                  browser_tabview_bug650280.js \
                  browser_tabview_bug650573.js \
                  browser_tabview_bug651311.js \
+                 browser_tabview_bug654295.js \
                  browser_tabview_bug654721.js \
                  browser_tabview_bug654941.js \
                  browser_tabview_bug655269.js \
                  browser_tabview_bug656778.js \
                  browser_tabview_bug656913.js \
                  browser_tabview_bug662266.js \
                  browser_tabview_bug663421.js \
                  browser_tabview_bug665502.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug654295.js
@@ -0,0 +1,62 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  waitForExplicitFinish();
+
+  const DUMMY_PAGE_URL = "about:blank";
+  const DUMMY_PAGE_URL_2 = "http://mochi.test:8888/";
+
+  // create two groups and each group has one tab item
+  let newState = {
+    windows: [{
+      tabs: [{
+        entries: [{ url: DUMMY_PAGE_URL }],
+        hidden: true,
+        attributes: {},
+        extData: {
+          "tabview-tab":
+            '{"bounds":{"left":21,"top":29,"width":204,"height":153},' +
+            '"userSize":null,"url":"' + DUMMY_PAGE_URL + '","groupID":1,' +
+            '"imageData":null,"title":null}'
+        }
+      },{
+        entries: [{ url: DUMMY_PAGE_URL_2 }],
+        hidden: false,
+        attributes: {},
+        extData: {
+          "tabview-tab":
+            '{"bounds":{"left":315,"top":29,"width":111,"height":84},' +
+            '"userSize":null,"url":"' + DUMMY_PAGE_URL_2 + '","groupID":2,' +
+            '"imageData":null,"title":null}'
+        },
+      }],
+      selected:2,
+      _closedTabs: [],
+      extData: {
+        "tabview-groups": '{"nextID":3,"activeGroupId":2}',
+        "tabview-group":
+          '{"1":{"bounds":{"left":15,"top":5,"width":280,"height":232},' +
+          '"userSize":null,"title":"","id":1},' +
+          '"2":{"bounds":{"left":309,"top":5,"width":267,"height":226},' +
+          '"userSize":null,"title":"","id":2}}',
+        "tabview-ui": '{"pageBounds":{"left":0,"top":0,"width":788,"height":548}}'
+      }, sizemode:"normal"
+    }]
+  };
+
+  newWindowWithState(newState, function(win) {
+    registerCleanupFunction(function () win.close());
+
+    whenTabViewIsShown(function() {
+      let contentWindow = win.TabView.getContentWindow();
+
+      is(contentWindow.GroupItems.groupItems.length, 2, "There are still two groups");
+      is(win.gBrowser.tabs.length, 1, "There is only one tab");
+
+      finish();
+    }, win);
+    win.gBrowser.removeTab(win.gBrowser.selectedTab);
+  });
+}
+