Bug 615954 - Intermittent Failure in tabview/browser_tabview_bug597248.js [r=ian, a=orange]
authorRaymond Lee <raymond@raysquare.com>
Fri, 10 Dec 2010 17:46:10 +0800
changeset 59154 210237f7d62607a0122d5e5fe6dc4ac14981aecb
parent 59153 8fba5ba589117d7b2dacfec4f5accb213b4f0cad
child 59155 c141a4b27049138f545202c0c5d83d23daa159ea
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 [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
@@ -60,72 +60,78 @@ function setupOne() {
     if (++loadedCount == 2) {
       newWin.addEventListener("tabviewshown", setupTwo, false);
       newWin.TabView.toggle();
     }
   }
   
   newTabOne = newWin.gBrowser.tabs[0];
   newTabTwo = newWin.gBrowser.addTab();
-  load(newTabOne, "http://mochi.test:8888/", allLoaded);
+  load(newTabOne, "http://mochi.test:8888/browser/browser/base/content/test/tabview/search1.html", allLoaded);
   load(newTabTwo, "http://mochi.test:8888/browser/browser/base/content/test/tabview/dummy_page.html", allLoaded);
 }
 
 function setupTwo() {
   newWin.removeEventListener("tabviewshown", setupTwo, false);
 
   let contentWindow = newWin.document.getElementById("tab-view").contentWindow;
 
   let tabItems = contentWindow.TabItems.getItems();
   is(tabItems.length, 2, "There should be 2 tab items before closing");
 
   // force all canvas to update
   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");
-    });
+  // after the window is closed, restore it.
+  let xulWindowDestory = function() {
+    Services.obs.removeObserver(
+       xulWindowDestory, "xul-window-destroyed", false);
 
-    // 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
+    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.
         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);
       }, false);
-    }, false);
+    });
+  };
 
+  // check the storage for stored image data
+  let checkDataAndCloseWindow = function() {
+    tabItems.forEach(function(tabItem) {
+      let tabData = contentWindow.Storage.getTabData(tabItem.tab);
+      ok(tabData && tabData.imageData,
+        "TabItem has stored image data before closing");
+    });
+
+    Services.obs.addObserver(
+      xulWindowDestory, "xul-window-destroyed", false);
     newWin.close();
   }
 
-  // stimulate a quit application requested so the image data gets stored.
+  // 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);
-
+    // cancel the shut down
     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);
   ok(!Application.quit(), "Tried to quit and canceled it");
@@ -175,25 +181,27 @@ function onTabViewShown() {
 
   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");
+         "Tab item is showing cached data and is already connected. " +
+         tabItem.tab.linkedBrowser.currentURI.spec);
       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");
+           "Tab item is showing cached data and is just connected. "  +
+           tabItem.tab.linkedBrowser.currentURI.spec);
         count--;
         if (count == 0)
           nextStep();
       });
     }
   });
 }
 
@@ -201,17 +209,18 @@ function updateAndCheck() {
   // force all canvas to update
   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");
+      "Tab item is not showing cached data anymore. " +
+      tabItem.tab.linkedBrowser.currentURI.spec);
   });
 
   // clean up and finish
   restoredWin.close();
   finish();
 }
 
 function load(tab, url, callback) {