Bug 1290280 - Make tests more resilient. draft
authorMike Conley <mconley@mozilla.com>
Sat, 13 Aug 2016 18:46:38 -0400
changeset 400476 8641b8c3a18099d25e87cdddf16d5b4dcf3d73e8
parent 400475 deed3fe61a2fb0ea2c6d5e7d83d40a89d35736bb
child 528212 fb38ce976ab5d037fcd3db4c6c8f6ebd25b95b4f
push id26156
push usermconley@mozilla.com
push dateSat, 13 Aug 2016 23:05:35 +0000
bugs1290280
milestone51.0a1
Bug 1290280 - Make tests more resilient. MozReview-Commit-ID: BtQRx7og52A
browser/components/sessionstore/test/browser_423132.js
browser/components/sessionstore/test/browser_remoteness_flip_on_restore.js
--- a/browser/components/sessionstore/test/browser_423132.js
+++ b/browser/components/sessionstore/test/browser_423132.js
@@ -1,81 +1,61 @@
 /* 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/. */
 
-function test() {
-  // test that cookies are stored and restored correctly by sessionstore,
-  // bug 423132.
-
-  waitForExplicitFinish();
-
-  let cs = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
-  cs.removeAll();
-
-  // make sure that sessionstore.js can be forced to be created by setting
-  // the interval pref to 0
-  gPrefService.setIntPref("browser.sessionstore.interval", 0);
-
+/**
+ * Tests that cookies are stored and restored correctly
+ * by sessionstore (bug 423132).
+ */
+add_task(function*() {
   const testURL = "http://mochi.test:8888/browser/" +
     "browser/components/sessionstore/test/browser_423132_sample.html";
 
-  // open a new window
-  let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:blank");
-
-  // make sure sessionstore saves the cookie data, then close the window
-  newWin.addEventListener("load", function (aEvent) {
-    newWin.removeEventListener("load", arguments.callee, false);
-
-    // Wait for sessionstore to be ready to restore this window
-    executeSoon(function() {
-      newWin.gBrowser.loadURI(testURL, null, null);
+  Services.cookies.removeAll();
+  // make sure that sessionstore.js can be forced to be created by setting
+  // the interval pref to 0
+  yield SpecialPowers.pushPrefEnv({
+    set: [["browser.sessionstore.interval", 0]]
+  });
 
-      promiseBrowserLoaded(newWin.gBrowser.selectedBrowser).then(() => {
-        let ready = () => {
-          // get the sessionstore state for the window
-          let state = ss.getWindowState(newWin);
+  let win = yield BrowserTestUtils.openNewBrowserWindow();
+  let browser = win.gBrowser.selectedBrowser;
+  browser.loadURI(testURL);
+  yield BrowserTestUtils.browserLoaded(browser);
 
-          // verify our cookie got set during pageload
-          let e = cs.enumerator;
-          let cookie;
-          let i = 0;
-          while (e.hasMoreElements()) {
-            cookie = e.getNext().QueryInterface(Ci.nsICookie);
-            i++;
-          }
-          is(i, 1, "expected one cookie");
+  yield TabStateFlusher.flush(browser);
 
-          // remove the cookie
-          cs.removeAll();
+  // get the sessionstore state for the window
+  let state = ss.getWindowState(win);
 
-          // restore the window state
-          ss.setWindowState(newWin, state, true);
+  // verify our cookie got set during pageload
+  let enumerator = Services.cookies.enumerator;
+  let cookie;
+  let i = 0;
+  while (enumerator.hasMoreElements()) {
+    cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
+    i++;
+  }
+  Assert.equal(i, 1, "expected one cookie");
 
-          // at this point, the cookie should be restored...
-          e = cs.enumerator;
-          let cookie2;
-          while (e.hasMoreElements()) {
-            cookie2 = e.getNext().QueryInterface(Ci.nsICookie);
-            if (cookie.name == cookie2.name)
-              break;
-          }
-          is(cookie.name, cookie2.name, "cookie name successfully restored");
-          is(cookie.value, cookie2.value, "cookie value successfully restored");
-          is(cookie.path, cookie2.path, "cookie path successfully restored");
+  // remove the cookie
+  Services.cookies.removeAll();
+
+  // restore the window state
+  ss.setWindowState(win, state, true);
 
-          // clean up
-          if (gPrefService.prefHasUserValue("browser.sessionstore.interval"))
-            gPrefService.clearUserPref("browser.sessionstore.interval");
-          cs.removeAll();
-          BrowserTestUtils.closeWindow(newWin).then(finish);
-        };
+  // at this point, the cookie should be restored...
+  enumerator = Services.cookies.enumerator;
+  let cookie2;
+  while (enumerator.hasMoreElements()) {
+    cookie2 = enumerator.getNext().QueryInterface(Ci.nsICookie);
+    if (cookie.name == cookie2.name)
+      break;
+  }
+  is(cookie.name, cookie2.name, "cookie name successfully restored");
+  is(cookie.value, cookie2.value, "cookie value successfully restored");
+  is(cookie.path, cookie2.path, "cookie path successfully restored");
 
-        function flushAndReady() {
-          TabStateFlusher.flush(newWin.gBrowser.selectedBrowser).then(ready);
-        }
-
-        flushAndReady();
-      }, true, testURL);
-    });
-  }, false);
-}
-
+  // clean up
+  Services.cookies.removeAll();
+  yield BrowserTestUtils.closeWindow(win);
+});
--- a/browser/components/sessionstore/test/browser_remoteness_flip_on_restore.js
+++ b/browser/components/sessionstore/test/browser_remoteness_flip_on_restore.js
@@ -194,17 +194,17 @@ function* runScenarios(scenarios) {
  * a variety of initial remoteness states, that we only flip
  * the remoteness on the necessary tabs. For this particular
  * set of tests, we assume that tabs are restoring on demand.
  */
 add_task(function*() {
   // This test opens and closes windows, which might bog down
   // a debug build long enough to time out the test, so we
   // extend the tolerance on timeouts.
-  requestLongerTimeout(2);
+  requestLongerTimeout(5);
 
   yield SpecialPowers.pushPrefEnv({
     "set": [["browser.sessionstore.restore_on_demand", true]],
   });
 
   const TEST_SCENARIOS = [
     // Only one tab in the new window, and it's remote. This
     // is the common case, since this is how restoration occurs