Bug 593283 - Persist each group's active tab across sessions; r=dietrich
authorRaymond Lee <raymond@raysquare.com>
Tue, 20 Sep 2011 13:21:50 +0100
changeset 77189 50b328970b3c
parent 77184 ab120ebd437b
child 77190 f44151e039f6
push id21187
push usermak77@bonardo.net
push date2011-09-21 08:36 +0000
treeherdermozilla-central@3178f1c42505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich
bugs593283
milestone9.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 593283 - Persist each group's active tab across sessions; r=dietrich
browser/base/content/tabview/tabitems.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug593283.js
--- a/browser/base/content/tabview/tabitems.js
+++ b/browser/base/content/tabview/tabitems.js
@@ -218,21 +218,25 @@ TabItem.prototype = Utils.extend(new Ite
     if (this._cachedImageData)
       this._cachedImageData = null;
   },
 
   // ----------
   // Function: getStorageData
   // Get data to be used for persistent storage of this object.
   getStorageData: function TabItem_getStorageData() {
-    return {
+    let data = {
       url: this.tab.linkedBrowser.currentURI.spec,
       groupID: (this.parent ? this.parent.id : 0),
       title: this.tab.label
     };
+    if (this.parent.getActiveTab() == this)
+      data.active = true;
+
+    return data;
   },
 
   // ----------
   // Function: save
   // Store persistent for this object.
   save: function TabItem_save() {
     try {
       if (!this.tab || this.tab.parentNode == null || !this._reconnected) // too soon/late to save
@@ -334,50 +338,53 @@ TabItem.prototype = Utils.extend(new Ite
   // ----------
   // Function: _reconnect
   // Load the reciever's persistent data from storage. If there is none, 
   // treats it as a new tab. 
   _reconnect: function TabItem__reconnect() {
     Utils.assertThrow(!this._reconnected, "shouldn't already be reconnected");
     Utils.assertThrow(this.tab, "should have a xul:tab");
 
-    let self = this;
     let tabData = Storage.getTabData(this.tab);
 
     if (tabData && TabItems.storageSanity(tabData)) {
       this.loadThumbnail(tabData);
 
-      if (self.parent)
-        self.parent.remove(self, {immediately: true});
+      if (this.parent)
+        this.parent.remove(this, {immediately: true});
 
       let groupItem;
 
       if (tabData.groupID) {
         groupItem = GroupItems.groupItem(tabData.groupID);
       } else {
         groupItem = new GroupItem([], {immediately: true, bounds: tabData.bounds});
       }
 
       if (groupItem) {
-        groupItem.add(self, {immediately: true});
+        groupItem.add(this, {immediately: true});
+
+        // restore the active tab for each group between browser sessions
+        if (tabData.active)
+          groupItem.setActiveTab(this);
 
         // if it matches the selected tab or no active tab and the browser
         // tab is hidden, the active group item would be set.
-        if (self.tab == gBrowser.selectedTab ||
-            (!GroupItems.getActiveGroupItem() && !self.tab.hidden))
-          UI.setActive(self.parent);
+        if (this.tab == gBrowser.selectedTab ||
+            (!GroupItems.getActiveGroupItem() && !this.tab.hidden))
+          UI.setActive(this.parent);
       }
     } else {
       // create tab group by double click is handled in UI_init().
-      GroupItems.newTab(self, {immediately: true});
+      GroupItems.newTab(this, {immediately: true});
     }
 
-    self._reconnected = true;
-    self.save();
-    self._sendToSubscribers("reconnected");
+    this._reconnected = true;
+    this.save();
+    this._sendToSubscribers("reconnected");
   },
 
   // ----------
   // Function: setHidden
   // Hide/unhide this item
   setHidden: function TabItem_setHidden(val) {
     if (val)
       this.addClass("tabHidden");
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -53,16 +53,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug587276.js \
                  browser_tabview_bug587351.js \
                  browser_tabview_bug587503.js \
                  browser_tabview_bug587990.js \
                  browser_tabview_bug588265.js \
                  browser_tabview_bug589324.js \
                  browser_tabview_bug590606.js \
                  browser_tabview_bug591706.js \
+                 browser_tabview_bug593283.js \
                  browser_tabview_bug594958.js \
                  browser_tabview_bug595020.js \
                  browser_tabview_bug595191.js \
                  browser_tabview_bug595436.js \
                  browser_tabview_bug595518.js \
                  browser_tabview_bug595521.js \
                  browser_tabview_bug595560.js \
                  browser_tabview_bug595601.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug593283.js
@@ -0,0 +1,75 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const DUMMY_PAGE_URL = "http://example.com/";
+
+let state = {
+  windows: [{
+    tabs: [{
+      entries: [{ url: DUMMY_PAGE_URL }],
+      hidden: false, 
+      attributes: {},
+      extData: {
+        "tabview-tab": '{"url":"' + DUMMY_PAGE_URL + '","groupID":1,"title":null,"active":true}'
+      }
+    },{
+      entries: [{ url: DUMMY_PAGE_URL }],
+      hidden: false,
+      attributes: {},
+      extData: {
+        "tabview-tab": '{"url":"' + DUMMY_PAGE_URL + '","groupID":1,"title":null}'
+      }
+    },{
+      entries: [{ url: DUMMY_PAGE_URL }],
+      hidden: true,
+      attributes: {},
+      extData: {
+        "tabview-tab": '{"url":"' + DUMMY_PAGE_URL + '","groupID":2,"title":null}'
+      },
+    },{
+      entries: [{ url: DUMMY_PAGE_URL }],
+      hidden: true,
+      attributes: {},
+      extData: {
+        "tabview-tab": '{"url":"' + DUMMY_PAGE_URL + '","groupID":2,"title":null,"active":true}'
+      },
+    }],
+    selected:1,
+    _closedTabs: [],
+    extData: {
+      "tabview-groups": '{"nextID":3,"activeGroupId":2,"totalNumber":2}',
+      "tabview-group": 
+        '{"1":{"bounds":{"left":15,"top":28,"width":546,"height":218},' + 
+        '"userSize":{"x":546,"y":218},"title":"","id":1},' +
+        '"2":{"bounds":{"left":15,"top":261,"width":546,"height":199},' + 
+        '"userSize":{"x":546,"y":199},"title":"","id":2}}',
+      "tabview-ui": '{"pageBounds":{"left":0,"top":0,"width":976,"height":663}}'
+    }, sizemode:"normal"
+  }]
+};
+
+function test() {
+  waitForExplicitFinish();
+
+  newWindowWithState(state, function (win) {
+    registerCleanupFunction(function () win.close());
+
+    showTabView(function() {
+      let cw = win.TabView.getContentWindow();
+      let groupItems = cw.GroupItems.groupItems;
+      let groupOne = groupItems[0];
+      let groupTwo = groupItems[1];
+
+      // check the active tab of each group
+      is(groupOne.getActiveTab(), groupOne.getChild(0), "The active tab item of group one is the first one");
+      is(groupTwo.getActiveTab(), groupTwo.getChild(1), "The active tab item of group two is the second one");
+
+      is(cw.UI.getActiveTab(), groupOne.getChild(0), "The hightlighted tab item is the first one in group one");
+      // select a group and the second tab should be hightlighted
+      cw.UI.setActive(groupTwo);
+      is(cw.UI.getActiveTab(), groupTwo.getChild(1), "The hightlighted tab item is the second one in group two");
+
+      finish();
+    }, win);
+  });
+}