Bug 615954 - Intermittent Failure in tabview/browser_tabview_bug597248.js [r=ian, a=orange]
authorRaymond Lee <raymond@raysquare.com>
Thu, 16 Dec 2010 04:16:23 +0800
changeset 59417 822e23ac1f719679292e6a9574e6c2abc4174322
parent 59416 eae26f4fac418131f8bdc64557c32f50f5d618e9
child 59418 01169ff998baa1de8c2fa911dc5b31556af09f66
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersian, orange
bugs615954, 597248
milestone2.0b9pre
Bug 615954 - Intermittent Failure in tabview/browser_tabview_bug597248.js [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
@@ -90,18 +90,20 @@ function setupTwo() {
     newWin = null;
     // "xul-window-destroyed" is just fired just before a XUL window is
     // destroyed so restore window and test it after a delay
     executeSoon(function() {
       restoredWin = undoCloseWindow();
       restoredWin.addEventListener("load", function(event) {
         restoredWin.removeEventListener("load", arguments.callee, false);
 
-        // execute code when the frame isninitialized.
+        // execute code when the frame is initialized.
         restoredWin.addEventListener("tabviewshown", onTabViewShown, false);
+        
+        is(restoredWin.gBrowser.tabs.length, 2, "The total number of tabs is 2");
 
         // setup tab variables and listen to the load progress.
         newTabOne = restoredWin.gBrowser.tabs[0];
         newTabTwo = restoredWin.gBrowser.tabs[1];
         restoredWin.gBrowser.addTabsProgressListener(gTabsProgressListener);
       }, false);
     });
   };
@@ -134,33 +136,36 @@ function setupTwo() {
   }
   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) {
+    // ensure about:blank doesn't trigger the code
+    if ((stateFlags & Ci.nsIWebProgressListener.STATE_STOP) &&
+        (stateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) &&
+         browser.currentURI.spec != "about:blank") {
       if (newTabOne.linkedBrowser == browser)
         restoredNewTabOneLoaded = true;
       else if (newTabTwo.linkedBrowser == browser)
         restoredNewTabTwoLoaded = true;
- 
+
       // since we are not sure whether the frame is initialized first or two tabs
       // compete loading first so we need this.
       if (restoredNewTabOneLoaded && restoredNewTabTwoLoaded) {
+        restoredWin.gBrowser.removeTabsProgressListener(gTabsProgressListener);
+
         if (frameInitialized) {
           // since a tabs progress listener is used in the code to set 
           // tabItem.shouldHideCachedData, executeSoon is used to avoid a racing
           // condition.
           executeSoon(updateAndCheck); 
         }
-        restoredWin.gBrowser.removeTabsProgressListener(gTabsProgressListener);
       }
     }
   }
 };
 
 function onTabViewShown() {
   restoredWin.removeEventListener("tabviewshown", onTabViewShown, false);
 
@@ -170,40 +175,39 @@ function onTabViewShown() {
   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.
       executeSoon(updateAndCheck);
-    } else
+    } 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 and is already connected. " +
          tabItem.tab.linkedBrowser.currentURI.spec);
-      count--;
-      if (count == 0)
+      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. "  +
            tabItem.tab.linkedBrowser.currentURI.spec);
-        count--;
-        if (count == 0)
+        if (--count == 0)
           nextStep();
       });
     }
   });
 }
 
 function updateAndCheck() {
   // force all canvas to update