Bug 1003096 - Make browser_tabview_bug595601.js wait until the test session is restored. r=smacleod, a=test-only
authorTim Taubert <ttaubert@mozilla.com>
Wed, 30 Apr 2014 12:30:56 +0200
changeset 192187 66518d59cdbd
parent 192186 d20b23d033e4
child 192188 97392de21322
push id3515
push userryanvm@gmail.com
push date2014-05-01 17:32 +0000
treeherdermozilla-beta@66518d59cdbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmacleod, test-only
bugs1003096, 595601
milestone30.0
Bug 1003096 - Make browser_tabview_bug595601.js wait until the test session is restored. r=smacleod, a=test-only
browser/components/tabview/test/browser_tabview_bug595601.js
--- a/browser/components/tabview/test/browser_tabview_bug595601.js
+++ b/browser/components/tabview/test/browser_tabview_bug595601.js
@@ -42,52 +42,32 @@ function test() {
   });
 
   TabView._initFrame(function () {
     executeSoon(testRestoreWithHiddenTabs);
   });
 }
 
 function testRestoreWithHiddenTabs() {
-  let checked = false;
-  let ssReady = false;
-  let tabsRestored = false;
+  TabsProgressListener.setCallback(function (needsRestore, isRestoring) {
+    if (needsRestore <= 4) {
+      TabsProgressListener.unsetCallback();
+      is(needsRestore, 4, "4/8 tabs restored");
+    }
+  });
 
-  let check = function () {
-    if (checked || !ssReady || !tabsRestored)
-      return;
-
-    checked = true;
-
+  waitForBrowserState(state, 4, function () {
     is(gBrowser.tabs.length, 8, "there are now eight tabs");
     is(gBrowser.visibleTabs.length, 4, "four visible tabs");
 
     let cw = TabView.getContentWindow();
     is(cw.GroupItems.groupItems.length, 2, "there are now two groupItems");
 
     testSwitchToInactiveGroup();
-  }
-
-  whenSessionStoreReady(function () {
-    ssReady = true;
-    check();
   });
-
-  TabsProgressListener.setCallback(function (needsRestore, isRestoring) {
-    if (4 < needsRestore)
-      return;
-
-    TabsProgressListener.unsetCallback();
-    is(needsRestore, 4, "4/8 tabs restored");
-
-    tabsRestored = true;
-    check();
-  });
-
-  ss.setBrowserState(JSON.stringify(state));
 }
 
 function testSwitchToInactiveGroup() {
   let firstProgress = true;
 
   TabsProgressListener.setCallback(function (needsRestore, isRestoring) {
     if (firstProgress) {
       firstProgress = false;
@@ -103,21 +83,26 @@ function testSwitchToInactiveGroup() {
 
     is(gBrowser.visibleTabs.length, 4, "four visible tabs");
     waitForFocus(finish);
   });
 
   gBrowser.selectedTab = gBrowser.tabs[4];
 }
 
-function whenSessionStoreReady(callback) {
-  window.addEventListener("SSWindowStateReady", function onReady() {
-    window.removeEventListener("SSWindowStateReady", onReady, false);
-    executeSoon(callback);
-  }, false);
+function waitForBrowserState(state, numTabs, callback) {
+  let tabContainer = gBrowser.tabContainer;
+  tabContainer.addEventListener("SSTabRestored", function onRestored() {
+    if (--numTabs <= 0) {
+      tabContainer.removeEventListener("SSTabRestored", onRestored, true);
+      executeSoon(callback);
+    }
+  }, true);
+
+  ss.setBrowserState(JSON.stringify(state));
 }
 
 function countTabs() {
   let needsRestore = 0, isRestoring = 0;
   let windowsEnum = Services.wm.getEnumerator("navigator:browser");
 
   while (windowsEnum.hasMoreElements()) {
     let window = windowsEnum.getNext();