Bug 615954 - Intermittent Failure in tabview/browser_tabview_bug597248.js | Tab item is showing cached data or | Tab item is not showing cached data anymore [r=ian, a=orange]
authorRaymond Lee <raymond@raysquare.com>
Wed, 08 Dec 2010 02:13:38 +0800
changeset 58900 3171bf1a510970a5c61af4238cbc6a44fa9c9079
parent 58899 e68363d923898a5378964b9553cbe465b724f8e0
child 58901 93ad1a7be79192e2a45624a08173e934a0536fbd
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersian, orange
bugs615954, 597248
milestone2.0b8pre
Bug 615954 - Intermittent Failure in tabview/browser_tabview_bug597248.js | Tab item is showing cached data or | Tab item is not showing cached data anymore [r=ian, a=orange]
browser/base/content/test/tabview/browser_tabview_bug597248.js
--- a/browser/base/content/test/tabview/browser_tabview_bug597248.js
+++ b/browser/base/content/test/tabview/browser_tabview_bug597248.js
@@ -81,55 +81,58 @@ function setupTwo() {
   tabItems.forEach(function(tabItem) {
     contentWindow.TabItems._update(tabItem.tab);
   });
 
   let checkDataAndCloseWindow = function() {
     // check the storage for stored image data.
     tabItems.forEach(function(tabItem) {
       let tabData = contentWindow.Storage.getTabData(tabItem.tab);
-      ok(tabData && tabData.imageData, "TabItem has stored image data before closing");
+      ok(tabData && tabData.imageData, 
+        "TabItem has stored image data before closing");
     });
 
     // close the new window and restore it.
     newWin.addEventListener("unload", function(event) {
       newWin.removeEventListener("unload", arguments.callee, false);
       newWin = null;
 
       // restore window and test it
       restoredWin = undoCloseWindow();
       restoredWin.addEventListener("load", function(event) {
         restoredWin.removeEventListener("load", arguments.callee, false);
 
+        // execute code when the frame isninitialized.
+        restoredWin.addEventListener("tabviewshown", onTabViewShown, false);
+
         // setup tab variables and listen to the load progress.
         newTabOne = restoredWin.gBrowser.tabs[0];
         newTabTwo = restoredWin.gBrowser.tabs[1];
         restoredWin.gBrowser.addTabsProgressListener(gTabsProgressListener);
-
-        // execute code when the frame isninitialized.
-        restoredWin.addEventListener("tabviewframeinitialized", onTabViewFrameInitialized, false);
       }, false);
     }, false);
 
     newWin.close();
   }
 
   // stimulate a quit application requested so the image data gets stored.
   let quitRequestObserver = function(aSubject, aTopic, aData) {
     ok(aTopic == "quit-application-requested" &&
         aSubject instanceof Ci.nsISupportsPRBool,
         "Received a quit request and going to deny it");
-    Services.obs.removeObserver(quitRequestObserver, "quit-application-requested", false);
+    Services.obs.removeObserver(
+      quitRequestObserver, "quit-application-requested", false);
 
     aSubject.data = true;
     // save all images is execuated when "quit-application-requested" topic is 
     // announced so executeSoon is used to avoid racing condition.
     executeSoon(checkDataAndCloseWindow);
   }
-  Services.obs.addObserver(quitRequestObserver, "quit-application-requested", false);
+  Services.obs.addObserver(
+    quitRequestObserver, "quit-application-requested", false);
   ok(!Application.quit(), "Tried to quit and canceled it");
 }
 
 let gTabsProgressListener = {
   onStateChange: function(browser, webProgress, request, stateFlags, status) {
     if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
          stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
       if (newTabOne.linkedBrowser == browser)
@@ -147,61 +150,68 @@ let gTabsProgressListener = {
           executeSoon(updateAndCheck); 
         }
         restoredWin.gBrowser.removeTabsProgressListener(gTabsProgressListener);
       }
     }
   }
 };
 
-function onTabViewFrameInitialized() {
-  restoredWin.removeEventListener("tabviewframeinitialized", onTabViewFrameInitialized, false);
+function onTabViewShown() {
+  restoredWin.removeEventListener("tabviewshown", onTabViewShown, false);
 
-  let contentWindow = restoredWin.document.getElementById("tab-view").contentWindow;
+  let contentWindow = 
+    restoredWin.document.getElementById("tab-view").contentWindow;
 
   let nextStep = function() {
     // since we are not sure whether the frame is initialized first or two tabs
     // compete loading first so we need this.
     if (restoredNewTabOneLoaded && restoredNewTabTwoLoaded) {
       // executeSoon is used to ensure tabItem.shouldHideCachedData is set
-      // because tabs progress listener might run at the same time as this test code.
+      // because tabs progress listener might run at the same time as this test 
+      // code.
       executeSoon(updateAndCheck);
     } else
       frameInitialized = true;
   }
 
   let tabItems = contentWindow.TabItems.getItems();
   let count = tabItems.length;
   tabItems.forEach(function(tabItem) {
     // tabitem might not be connected so use subscriber for those which are not
     // connected.
     if (tabItem.reconnected) {
-      ok(tabItem.isShowingCachedData(), "Tab item is showing cached data");
+      ok(tabItem.isShowingCachedData(), 
+         "Tab item is showing cached data and is already connected");
       count--;
       if (count == 0)
         nextStep();
     } else {
       tabItem.addSubscriber(tabItem, "reconnected", function() {
         tabItem.removeSubscriber(tabItem, "reconnected");
+        ok(tabItem.isShowingCachedData(), 
+           "Tab item is showing cached data and is just connected");
         count--;
         if (count == 0)
           nextStep();
       });
     }
   });
 }
 
 function updateAndCheck() {
   // force all canvas to update
-  let contentWindow = restoredWin.document.getElementById("tab-view").contentWindow;
+  let contentWindow = 
+    restoredWin.document.getElementById("tab-view").contentWindow;
 
   let tabItems = contentWindow.TabItems.getItems();
   tabItems.forEach(function(tabItem) {
     contentWindow.TabItems._update(tabItem.tab);
-    ok(!tabItem.isShowingCachedData(), "Tab item is not showing cached data anymore");
+    ok(!tabItem.isShowingCachedData(), 
+      "Tab item is not showing cached data anymore");
   });
 
   // clean up and finish
   restoredWin.close();
   finish();
 }
 
 function load(tab, url, callback) {