Bug 1172473 - Fix intermittent browser_607016.js failures by properly waiting for tabs to be removed. r=mconley, a=test-only
authorTim Taubert <ttaubert@mozilla.com>
Thu, 16 Jul 2015 14:03:04 +0200
changeset 268886 5381ccc44c610bfc3caa4c35db14c5e5536c1ae9
parent 268885 7a72a04efe6a689be1ea40ed0625908fdd6dce5f
child 268887 59f92930d90f871a713a6dafa57a60a8834a9f09
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, test-only
bugs1172473
milestone41.0a2
Bug 1172473 - Fix intermittent browser_607016.js failures by properly waiting for tabs to be removed. r=mconley, a=test-only
browser/components/sessionstore/test/browser_607016.js
--- a/browser/components/sessionstore/test/browser_607016.js
+++ b/browser/components/sessionstore/test/browser_607016.js
@@ -1,57 +1,30 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
 
 let stateBackup = ss.getBrowserState();
 
-function cleanup() {
-  // Reset the pref
-  try {
-    Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
-  } catch (e) {}
-  ss.setBrowserState(stateBackup);
-  executeSoon(finish);
-}
-
-function test() {
+add_task(function* () {
   /** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/
-  waitForExplicitFinish();
   ignoreAllUncaughtExceptions();
 
   // Set the pref to true so we know exactly how many tabs should be restoring at
   // any given time. This guarantees that a finishing load won't start another.
   Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
 
-  // We have our own progress listener for this test, which we'll attach before our state is set
-  let progressListener = {
-    onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
-      if (aBrowser.__SS_restoreState == TAB_STATE_RESTORING &&
-          aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
-          aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
-          aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW)
-        progressCallback(aBrowser);
-    }
-  }
-
   let state = { windows: [{ tabs: [
     { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } },
     { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } }, // overwriting
     { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } }, // hiding
     { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } }, // adding
     { entries: [{ url: "http://example.org#5" }], extData: { "uniq": r() } }, // deleting
     { entries: [{ url: "http://example.org#6" }] } // creating
   ], selected: 1 }] };
 
-  function progressCallback(aBrowser) {
-    // We'll remove the progress listener after the first one because we aren't
-    // loading any other tabs
-    window.gBrowser.removeTabsProgressListener(progressListener);
-
+  function* progressCallback() {
     let curState = JSON.parse(ss.getBrowserState());
     for (let i = 0; i < curState.windows[0].tabs.length; i++) {
       let tabState = state.windows[0].tabs[i];
       let tabCurState = curState.windows[0].tabs[i];
       if (tabState.extData) {
         is(tabCurState.extData["uniq"], tabState.extData["uniq"],
            "sanity check that tab has correct extData");
       }
@@ -62,56 +35,65 @@ function test() {
         ok(!("extData" in tabCurState) || !("uniq" in tabCurState.extData),
            "sanity check that tab doesn't have extData or extData doesn't have 'uniq'");
       }
     }
 
     // Now we'll set a new unique value on 1 of the tabs
     let newUniq = r();
     ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq);
-    gBrowser.removeTab(gBrowser.tabs[1]);
+    yield promiseRemoveTab(gBrowser.tabs[1]);
     let closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
     is(closedTabData.state.extData.uniq, newUniq,
        "(overwriting) new data is stored in extData");
 
     // hide the next tab before closing it
     gBrowser.hideTab(gBrowser.tabs[1]);
-    gBrowser.removeTab(gBrowser.tabs[1]);
+    yield promiseRemoveTab(gBrowser.tabs[1]);
     closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
     ok(closedTabData.state.hidden, "(hiding) tab data has hidden == true");
 
     // set data that's not in a conflicting key
     let stillUniq = r();
     ss.setTabValue(gBrowser.tabs[1], "stillUniq", stillUniq);
-    gBrowser.removeTab(gBrowser.tabs[1]);
+    yield promiseRemoveTab(gBrowser.tabs[1]);
     closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
     is(closedTabData.state.extData.stillUniq, stillUniq,
        "(adding) new data is stored in extData");
 
     // remove the uniq value and make sure it's not there in the closed data
     ss.deleteTabValue(gBrowser.tabs[1], "uniq");
-    gBrowser.removeTab(gBrowser.tabs[1]);
+    yield promiseRemoveTab(gBrowser.tabs[1]);
     closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
     // Since Panorama might have put data in, first check if there is extData.
     // If there is explicitly check that "uniq" isn't in it. Otherwise, we're ok
     if ("extData" in closedTabData.state) {
       ok(!("uniq" in closedTabData.state.extData),
          "(deleting) uniq not in existing extData");
     }
     else {
       ok(true, "(deleting) no data is stored in extData");
     }
 
     // set unique data on the tab that never had any set, make sure that's saved
     let newUniq2 = r();
     ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq2);
-    gBrowser.removeTab(gBrowser.tabs[1]);
+    yield promiseRemoveTab(gBrowser.tabs[1]);
     closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
     is(closedTabData.state.extData.uniq, newUniq2,
        "(creating) new data is stored in extData where there was none");
-
-    cleanup();
   }
 
-  window.gBrowser.addTabsProgressListener(progressListener);
+  // Set the test state.
   ss.setBrowserState(JSON.stringify(state));
-}
+
+  // Wait until the selected tab is restored and all others are pending.
+  yield Promise.all(Array.map(gBrowser.tabs, tab => {
+    return (tab == gBrowser.selectedTab) ?
+      promiseTabRestored(tab) : promiseTabRestoring(tab)
+  }));
 
+  // Kick off the actual tests.
+  yield progressCallback();
+
+  // Cleanup.
+  yield promiseBrowserState(stateBackup);
+});