Bug 627288 - Tabs restored from last session show stale cache data; r=ian a=sdwilsh
authorTim Taubert <tim.taubert@gmx.de>
Fri, 28 Jan 2011 19:59:59 +0100
changeset 61563 b5ee327bf5367e5c5e64230969dee2b297d81c1a
parent 61562 a63f1b9d9878fe213f63f5e53dd6e3a5ac75edd5
child 61564 a2f4bc829c88d52e5720109e9b9ecf6954e90e94
push id18388
push usereakhgari@mozilla.com
push dateFri, 28 Jan 2011 19:59:22 +0000
treeherdermozilla-central@b5ee327bf536 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersian, sdwilsh
bugs627288
milestone2.0b11pre
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 627288 - Tabs restored from last session show stale cache data; r=ian a=sdwilsh
browser/base/content/tabview/tabitems.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug627288.js
--- a/browser/base/content/tabview/tabitems.js
+++ b/browser/base/content/tabview/tabitems.js
@@ -364,17 +364,18 @@ TabItem.prototype = Utils.extend(new Ite
           // if it matches the selected tab or no active tab and the browser 
           // tab is hidden, the active group item would be set.
           if (this.tab == gBrowser.selectedTab || 
               (!GroupItems.getActiveGroupItem() && !this.tab.hidden))
             GroupItems.setActiveGroupItem(this.parent);
         }
       }
 
-      if (tabData.imageData)
+      let currentUrl = this.tab.linkedBrowser.currentURI.spec;
+      if (tabData.imageData && tabData.url == currentUrl)
         this.showCachedData(tabData);
     } else {
       // create tab by double click is handled in UI_init().
       if (!TabItems.creatingNewOrphanTab)
         GroupItems.newTab(this, {immediately: true});
     }
 
     this._reconnected = true;  
@@ -968,17 +969,19 @@ let TabItems = {
         let oldURL = tabItem.url;
         tabItem.url = tabUrl;
         tabItem.save();
       }
 
       // ___ label
       let label = tab.label;
       let $name = tabItem.$tabTitle;
-      if (!tabItem.isShowingCachedData() && $name.text() != label)
+      let isLabelUpdateAllowed = !tabItem.isShowingCachedData() ||
+                                 tabItem.shouldHideCachedData;
+      if (isLabelUpdateAllowed && $name.text() != label)
         $name.text(label);
 
       // ___ thumbnail
       let $canvas = tabItem.$canvas;
       if (!tabItem.canvasSizeForced) {
         let w = $canvas.width();
         let h = $canvas.height();
         if (w != tabItem.$canvas[0].width || h != tabItem.$canvas[0].height) {
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -87,16 +87,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug618828.js \
                  browser_tabview_bug619937.js \
                  browser_tabview_bug622835.js \
                  browser_tabview_bug622872.js \
                  browser_tabview_bug624265.js \
                  browser_tabview_bug624953.js \
                  browser_tabview_bug625269.js \
                  browser_tabview_bug626368.js \
+                 browser_tabview_bug627288.js \
                  browser_tabview_bug627736.js \
                  browser_tabview_bug628165.js \
                  browser_tabview_dragdrop.js \
                  browser_tabview_exit_button.js \
                  browser_tabview_expander.js \
                  browser_tabview_group.js \
                  browser_tabview_launch.js \
                  browser_tabview_multiwindow_search.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug627288.js
@@ -0,0 +1,85 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  let cw;
+  let tab;
+
+  let testReconnectWithSameUrl = function () {
+    tab = gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
+
+    afterAllTabsLoaded(function () {
+      let tabItem = tab._tabViewTabItem;
+      let data = tabItem.getStorageData(true);
+      gBrowser.removeTab(tab);
+
+      cw.TabItems.pauseReconnecting();
+      tab = gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
+      cw.Storage.saveTab(tab, data);
+
+      whenTabAttrModified(tab, function () {
+        tabItem = tab._tabViewTabItem;
+        cw.TabItems.resumeReconnecting();
+        ok(tabItem.isShowingCachedData(), 'tabItem shows cached data');
+
+        testChangeUrlAfterReconnect();
+      });
+    });
+  }
+
+  let testChangeUrlAfterReconnect = function () {
+    tab.linkedBrowser.loadURI('http://mochi.test:8888/browser/');
+
+    whenTabAttrModified(tab, function () {
+      cw.TabItems._update(tab);
+
+      let tabItem = tab._tabViewTabItem;
+      let currentLabel = tabItem.$tabTitle.text();
+
+      is(currentLabel, 'mochitest index /browser/', 'tab label is up-to-date');
+      testReconnectWithNewUrl();
+    });
+  }
+
+  let testReconnectWithNewUrl = function () {
+    let tabItem = tab._tabViewTabItem;
+    let data = tabItem.getStorageData(true);
+    gBrowser.removeTab(tab);
+
+    cw.TabItems.pauseReconnecting();
+    tab = gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
+    cw.Storage.saveTab(tab, data);
+
+    whenTabAttrModified(tab, function () {
+      tabItem = tab._tabViewTabItem;
+      cw.TabItems.resumeReconnecting();
+      ok(!tabItem.isShowingCachedData(), 'tabItem does not show cached data');
+
+      gBrowser.removeTab(tab);
+      hideTabView(finish);
+    });
+  }
+
+  waitForExplicitFinish();
+
+  showTabView(function () {
+    cw = TabView.getContentWindow();
+    testReconnectWithSameUrl();
+  });
+}
+
+// ----------
+function whenTabAttrModified(tab, callback) {
+  let onModified = function (event) {
+    if (tab === event.target) {
+      container.removeEventListener('TabAttrModified', onModified, false);
+      // we need executeSoon here because the tabItem also listens for the
+      // onTabAttrModified event. so this is to make sure the tabItem logic
+      // is executed before the test logic.
+      executeSoon(callback);
+    }
+  }
+
+  let container = gBrowser.tabContainer;
+  container.addEventListener('TabAttrModified', onModified, false);
+}