Bug 1346286 - Remove CPOWs from more tests. r=Felipe, r=Gijs, a=test-only
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 09 Mar 2017 17:29:08 -0800
changeset 395253 8e62e7262959dd317b29df48b0c9fcdb13967155
parent 395252 d161f1a31dfaec12fdeb7128380ce05723a63c1a
child 395254 c1d72390b27a1ec22279e9adb936be664216c5a5
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, Gijs, test-only
bugs1346286
milestone54.0a2
Bug 1346286 - Remove CPOWs from more tests. r=Felipe, r=Gijs, a=test-only
browser/base/content/test/general/browser_aboutCertError.js
browser/base/content/test/general/browser_aboutNetError.js
browser/base/content/test/general/browser_bug578534.js
browser/base/content/test/general/browser_bug749738.js
browser/base/content/test/general/browser_bug882977.js
browser/base/content/test/popupNotifications/browser_popupNotification_3.js
browser/base/content/test/siteIdentity/browser_bug1045809.js
browser/base/content/test/siteIdentity/browser_bug822367.js
browser/components/contextualidentity/test/browser/browser_usercontext.js
browser/components/sessionstore/test/browser_500328.js
browser/components/sessionstore/test/browser_687710_2.js
browser/components/sessionstore/test/browser_739805.js
browser/components/sessionstore/test/browser_911547.js
browser/components/sessionstore/test/browser_history_persist.js
docshell/test/browser/browser_bug554155.js
netwerk/test/browser/browser_child_resource.js
toolkit/components/startup/tests/browser/head.js
toolkit/content/tests/browser/browser_findbar.js
--- a/browser/base/content/test/general/browser_aboutCertError.js
+++ b/browser/base/content/test/general/browser_aboutCertError.js
@@ -30,24 +30,24 @@ add_task(function* checkReturnToAboutHom
 
   // Populate the shistory entries manually, since it happens asynchronously
   // and the following tests will be too soon otherwise.
   yield TabStateFlusher.flush(browser);
   let {entries} = JSON.parse(ss.getTabState(tab));
   is(entries.length, 1, "there is one shistory entry");
 
   info("Clicking the go back button on about:certerror");
-  let pageshowPromise = promiseWaitForEvent(browser, "pageshow");
   yield ContentTask.spawn(browser, null, function* () {
     let doc = content.document;
     let returnButton = doc.getElementById("returnButton");
     is(returnButton.getAttribute("autofocus"), "true", "returnButton has autofocus");
     returnButton.click();
+
+    yield ContentTaskUtils.waitForEvent(this, "pageshow", true);
   });
-  yield pageshowPromise;
 
   is(browser.webNavigation.canGoBack, true, "webNavigation.canGoBack");
   is(browser.webNavigation.canGoForward, false, "!webNavigation.canGoForward");
   is(gBrowser.currentURI.spec, "about:home", "Went back");
 
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
@@ -66,23 +66,23 @@ add_task(function* checkReturnToPrevious
 
   // Populate the shistory entries manually, since it happens asynchronously
   // and the following tests will be too soon otherwise.
   yield TabStateFlusher.flush(browser);
   let {entries} = JSON.parse(ss.getTabState(tab));
   is(entries.length, 2, "there are two shistory entries");
 
   info("Clicking the go back button on about:certerror");
-  let pageshowPromise = promiseWaitForEvent(browser, "pageshow");
   yield ContentTask.spawn(browser, null, function* () {
     let doc = content.document;
     let returnButton = doc.getElementById("returnButton");
     returnButton.click();
+
+    yield ContentTaskUtils.waitForEvent(this, "pageshow", true);
   });
-  yield pageshowPromise;
 
   is(browser.webNavigation.canGoBack, false, "!webNavigation.canGoBack");
   is(browser.webNavigation.canGoForward, true, "webNavigation.canGoForward");
   is(gBrowser.currentURI.spec, GOOD_PAGE, "Went back");
 
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
--- a/browser/base/content/test/general/browser_aboutNetError.js
+++ b/browser/base/content/test/general/browser_aboutNetError.js
@@ -19,26 +19,29 @@ add_task(function* checkReturnToPrevious
     gBrowser.selectedTab = gBrowser.addTab(LOW_TLS_VERSION);
     browser = gBrowser.selectedBrowser;
     pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
   }, false);
 
   info("Loading and waiting for the net error");
   yield pageLoaded;
 
-  Assert.ok(content.document.getElementById("prefResetButton").getBoundingClientRect().left >= 0,
-    "Should have a visible button");
+  // NB: This code assumes that the error page and the test page load in the
+  // same process. If this test starts to fail, it could be because they load
+  // in different processes.
+  yield ContentTask.spawn(browser, LOW_TLS_VERSION, function* (LOW_TLS_VERSION_) {
+    ok(content.document.getElementById("prefResetButton").getBoundingClientRect().left >= 0,
+      "Should have a visible button");
 
-  Assert.ok(content.document.documentURI.startsWith("about:neterror"), "Should be showing error page");
+    ok(content.document.documentURI.startsWith("about:neterror"), "Should be showing error page");
 
-  let pageshowPromise = promiseWaitForEvent(browser, "pageshow");
-  yield ContentTask.spawn(browser, null, function* () {
     let doc = content.document;
     let prefResetButton = doc.getElementById("prefResetButton");
-    Assert.equal(prefResetButton.getAttribute("autofocus"), "true", "prefResetButton has autofocus");
+    is(prefResetButton.getAttribute("autofocus"), "true", "prefResetButton has autofocus");
     prefResetButton.click();
+
+    yield ContentTaskUtils.waitForEvent(this, "pageshow", true);
+
+    is(content.document.documentURI, LOW_TLS_VERSION_, "Should not be showing page");
   });
-  yield pageshowPromise;
-
-  Assert.equal(content.document.documentURI, LOW_TLS_VERSION, "Should not be showing page");
 
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
--- a/browser/base/content/test/general/browser_bug578534.js
+++ b/browser/base/content/test/general/browser_bug578534.js
@@ -1,28 +1,23 @@
 /* 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() {
+add_task(function* test() {
   let uriString = "http://example.com/";
   let cookieBehavior = "network.cookie.cookieBehavior";
   let uriObj = Services.io.newURI(uriString)
   let cp = Components.classes["@mozilla.org/cookie/permission;1"]
                      .getService(Components.interfaces.nsICookiePermission);
 
-  Services.prefs.setIntPref(cookieBehavior, 2);
-
+  yield SpecialPowers.pushPrefEnv({ set: [[ cookieBehavior, 2 ]] });
   cp.setAccess(uriObj, cp.ACCESS_ALLOW);
-  gBrowser.selectedTab = gBrowser.addTab(uriString);
-  waitForExplicitFinish();
-  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(onTabLoaded);
 
-  function onTabLoaded() {
-    is(gBrowser.selectedBrowser.contentWindow.navigator.cookieEnabled, true,
-       "navigator.cookieEnabled should be true");
-    // Clean up
-    gBrowser.removeTab(gBrowser.selectedTab);
-    Services.prefs.setIntPref(cookieBehavior, 0);
-    cp.setAccess(uriObj, cp.ACCESS_DEFAULT);
-    finish();
-  }
-}
+  yield BrowserTestUtils.withNewTab({ gBrowser, url: uriString }, function* (browser) {
+    yield ContentTask.spawn(browser, null, function() {
+      is(content.navigator.cookieEnabled, true,
+         "navigator.cookieEnabled should be true");
+    });
+  });
+
+  cp.setAccess(uriObj, cp.ACCESS_DEFAULT);
+});
--- a/browser/base/content/test/general/browser_bug749738.js
+++ b/browser/base/content/test/general/browser_bug749738.js
@@ -7,29 +7,23 @@
 const DUMMY_PAGE = "http://example.org/browser/browser/base/content/test/general/dummy_page.html";
 
 function test() {
   waitForExplicitFinish();
 
   let tab = gBrowser.addTab();
   gBrowser.selectedTab = tab;
 
-  load(tab, DUMMY_PAGE, function() {
+  BrowserTestUtils.loadURI(tab.linkedBrowser, DUMMY_PAGE);
+  BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
     gFindBar.onFindCommand();
     EventUtils.sendString("Dummy");
     gBrowser.removeTab(tab);
 
     try {
       gFindBar.close();
       ok(true, "findbar.close should not throw an exception");
     } catch (e) {
       ok(false, "findbar.close threw exception: " + e);
     }
     finish();
   });
 }
-
-function load(aTab, aUrl, aCallback) {
-  aTab.linkedBrowser.addEventListener("load", function(aEvent) {
-    waitForFocus(aCallback, content);
-  }, {capture: true, once: true});
-  aTab.linkedBrowser.loadURI(aUrl);
-}
--- a/browser/base/content/test/general/browser_bug882977.js
+++ b/browser/base/content/test/general/browser_bug882977.js
@@ -9,28 +9,21 @@ add_task(function*() {
   yield SpecialPowers.pushPrefEnv({
     "set": [
       ["browser.startup.homepage", homepage],
       ["browser.startup.page", 1],
     ]
   });
 
   let win = OpenBrowserWindow();
-  yield BrowserTestUtils.waitForEvent(win, "load");
+  yield BrowserTestUtils.firstBrowserLoaded(win, false);
 
   let browser = win.gBrowser.selectedBrowser;
-  // If we've finished loading about:home already, we can check
-  // right away - otherwise, we need to wait.
-  if (browser.contentDocument.readyState == "complete" &&
-      browser.currentURI.spec == homepage) {
-    checkIdentityMode(win);
-  } else {
-    yield BrowserTestUtils.browserLoaded(browser, false, homepage);
-    checkIdentityMode(win);
-  }
+  is(browser.currentURI.spec, homepage, "Loaded the correct homepage");
+  checkIdentityMode(win);
 
   yield BrowserTestUtils.closeWindow(win);
 });
 
 function checkIdentityMode(win) {
   let identityMode = win.document.getElementById("identity-box").className;
   is(identityMode, "chromeUI", "Identity state should be chromeUI for about:home in a new window");
 }
--- a/browser/base/content/test/popupNotifications/browser_popupNotification_3.js
+++ b/browser/base/content/test/popupNotifications/browser_popupNotification_3.js
@@ -238,31 +238,33 @@ var tests = [
       showNotification(this.notifyObj);
     },
     onShown(popup) {
       let self = this;
       let progressListener = {
         onLocationChange: function onLocationChange() {
           gBrowser.removeProgressListener(progressListener);
 
-	  executeSoon(() => {
+          executeSoon(() => {
             let notification = PopupNotifications.getNotification(self.notifyObj.id,
                                                                   self.notifyObj.browser);
             ok(notification != null, "Notification remained when subframe navigated");
             self.notifyObj.options.eventCallback = undefined;
 
             notification.remove();
-	  });
+          });
         },
       };
 
       info("Adding progress listener and performing navigation");
       gBrowser.addProgressListener(progressListener);
-      content.document.getElementById("iframe")
-                      .setAttribute("src", "http://example.org/");
+      ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+        content.document.getElementById("iframe")
+                        .setAttribute("src", "http://example.org/");
+      });
     },
     onHidden() {}
   },
   // Popup Notifications should catch exceptions from callbacks
   { id: "Test#10",
     run() {
       this.testNotif1 = new BasicNotification(this.id);
       this.testNotif1.message += " 1";
--- a/browser/base/content/test/siteIdentity/browser_bug1045809.js
+++ b/browser/base/content/test/siteIdentity/browser_bug1045809.js
@@ -30,31 +30,37 @@ add_task(function* () {
   // Test 3: mixed content must be blocked again
   yield promiseTabLoadEvent(tab);
   yield* test3(gBrowser.getBrowserForTab(tab));
 });
 
 function* test1(gTestBrowser) {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
-  var x = content.document.getElementsByTagName("iframe")[0].contentDocument.getElementById("mixedContentContainer");
-  is(x, null, "Mixed Content is NOT to be found in Test1");
+  yield ContentTask.spawn(gTestBrowser, null, function() {
+    var x = content.document.getElementsByTagName("iframe")[0].contentDocument.getElementById("mixedContentContainer");
+    is(x, null, "Mixed Content is NOT to be found in Test1");
+  });
 
   // Disable Mixed Content Protection for the page (and reload)
   gIdentityHandler.disableMixedContentProtection();
 }
 
 function* test2(gTestBrowser) {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: false});
 
-  var x = content.document.getElementsByTagName("iframe")[0].contentDocument.getElementById("mixedContentContainer");
-  isnot(x, null, "Mixed Content is to be found in Test2");
+  yield ContentTask.spawn(gTestBrowser, null, function() {
+    var x = content.document.getElementsByTagName("iframe")[0].contentDocument.getElementById("mixedContentContainer");
+    isnot(x, null, "Mixed Content is to be found in Test2");
+  });
 
   // Re-enable Mixed Content Protection for the page (and reload)
   gIdentityHandler.enableMixedContentProtection();
 }
 
 function* test3(gTestBrowser) {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
-  var x = content.document.getElementsByTagName("iframe")[0].contentDocument.getElementById("mixedContentContainer");
-  is(x, null, "Mixed Content is NOT to be found in Test3");
+  yield ContentTask.spawn(gTestBrowser, null, function() {
+    var x = content.document.getElementsByTagName("iframe")[0].contentDocument.getElementById("mixedContentContainer");
+    is(x, null, "Mixed Content is NOT to be found in Test3");
+  });
 }
--- a/browser/base/content/test/siteIdentity/browser_bug822367.js
+++ b/browser/base/content/test/siteIdentity/browser_bug822367.js
@@ -7,189 +7,181 @@ const PREF_DISPLAY = "security.mixed_con
 const PREF_ACTIVE = "security.mixed_content.block_active_content";
 
 // We alternate for even and odd test cases to simulate different hosts
 const HTTPS_TEST_ROOT = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com");
 const HTTPS_TEST_ROOT_2 = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://test1.example.com");
 
 var gTestBrowser = null;
 
-registerCleanupFunction(function() {
-  // Set preferences back to their original values
-  Services.prefs.clearUserPref(PREF_DISPLAY);
-  Services.prefs.clearUserPref(PREF_ACTIVE);
-});
-
-function MixedTestsCompleted() {
-  gBrowser.removeCurrentTab();
-  window.focus();
-  finish();
-}
-
-function test() {
-  waitForExplicitFinish();
-
-  Services.prefs.setBoolPref(PREF_DISPLAY, true);
-  Services.prefs.setBoolPref(PREF_ACTIVE, true);
+add_task(function* test() {
+  yield SpecialPowers.pushPrefEnv({ set: [[ PREF_DISPLAY, true ],
+                                          [ PREF_ACTIVE, true  ]] });
 
   var newTab = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
   gTestBrowser = gBrowser.selectedBrowser;
   newTab.linkedBrowser.stop()
 
   // Mixed Script Test
-  gTestBrowser.addEventListener("load", MixedTest1A, true);
   var url = HTTPS_TEST_ROOT + "file_bug822367_1.html";
-  gTestBrowser.contentWindow.location = url;
-}
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
 // Mixed Script Test
-function MixedTest1A() {
-  gTestBrowser.removeEventListener("load", MixedTest1A, true);
-  gTestBrowser.addEventListener("load", MixedTest1B, true);
-
+add_task(function* MixedTest1A() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
   let {gIdentityHandler} = gTestBrowser.ownerGlobal;
   gIdentityHandler.disableMixedContentProtection();
-}
-function MixedTest1B() {
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p1").innerHTML == "hello", "Waited too long for mixed script to run in Test 1").then(MixedTest1C);
-}
-function MixedTest1C() {
-  ok(content.document.getElementById("p1").innerHTML == "hello", "Mixed script didn't load in Test 1");
-  gTestBrowser.removeEventListener("load", MixedTest1B, true);
-  MixedTest2();
-}
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest1B() {
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p1").innerHTML == "hello",
+      "Waited too long for mixed script to run in Test 1");
+  });
+});
 
 // Mixed Display Test - Doorhanger should not appear
-function MixedTest2() {
-  gTestBrowser.addEventListener("load", MixedTest2A, true);
+add_task(function* MixedTest2() {
   var url = HTTPS_TEST_ROOT_2 + "file_bug822367_2.html";
-  gTestBrowser.contentWindow.location = url;
-}
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
 
-function MixedTest2A() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: false, passiveLoaded: false});
-  MixedTest3();
-}
+});
 
 // Mixed Script and Display Test - User Override should cause both the script and the image to load.
-function MixedTest3() {
-  gTestBrowser.removeEventListener("load", MixedTest2A, true);
-  gTestBrowser.addEventListener("load", MixedTest3A, true);
+add_task(function* MixedTest3() {
   var url = HTTPS_TEST_ROOT + "file_bug822367_3.html";
-  gTestBrowser.contentWindow.location = url;
-}
-function MixedTest3A() {
-  gTestBrowser.removeEventListener("load", MixedTest3A, true);
-  gTestBrowser.addEventListener("load", MixedTest3B, true);
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest3A() {
+  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
+
+  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
+  gIdentityHandler.disableMixedContentProtection();
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
+add_task(function* MixedTest3B() {
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    let p1 = ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p1").innerHTML == "hello",
+      "Waited too long for mixed script to run in Test 3");
+    let p2 = ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p2").innerHTML == "bye",
+      "Waited too long for mixed image to load in Test 3");
+    yield Promise.all([ p1, p2 ]);
+  });
+
+  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: true});
+});
+
+// Location change - User override on one page doesn't propogate to another page after location change.
+add_task(function* MixedTest4() {
+  var url = HTTPS_TEST_ROOT_2 + "file_bug822367_4.html";
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest4A() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
   let {gIdentityHandler} = gTestBrowser.ownerGlobal;
   gIdentityHandler.disableMixedContentProtection();
-}
-function MixedTest3B() {
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p1").innerHTML == "hello", "Waited too long for mixed script to run in Test 3").then(MixedTest3C);
-}
-function MixedTest3C() {
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p2").innerHTML == "bye", "Waited too long for mixed image to load in Test 3").then(MixedTest3D);
-}
-function MixedTest3D() {
-  ok(content.document.getElementById("p1").innerHTML == "hello", "Mixed script didn't load in Test 3");
-  ok(content.document.getElementById("p2").innerHTML == "bye", "Mixed image didn't load in Test 3");
-  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: true});
-  MixedTest4();
-}
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest4B() {
+  let url = HTTPS_TEST_ROOT + "file_bug822367_4B.html";
+  yield ContentTask.spawn(gTestBrowser, url, function* (wantedUrl) {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.location == wantedUrl,
+      "Waited too long for mixed script to run in Test 4");
+  });
+});
+
+add_task(function* MixedTest4C() {
+  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
-// Location change - User override on one page doesn't propogate to another page after location change.
-function MixedTest4() {
-  gTestBrowser.removeEventListener("load", MixedTest3B, true);
-  gTestBrowser.addEventListener("load", MixedTest4A, true);
-  var url = HTTPS_TEST_ROOT_2 + "file_bug822367_4.html";
-  gTestBrowser.contentWindow.location = url;
-}
-function MixedTest4A() {
-  gTestBrowser.removeEventListener("load", MixedTest4A, true);
-  gTestBrowser.addEventListener("load", MixedTest4B, true);
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p1").innerHTML == "",
+      "Mixed script loaded in test 4 after location change!");
+  });
+});
 
+// Mixed script attempts to load in a document.open()
+add_task(function* MixedTest5() {
+  var url = HTTPS_TEST_ROOT + "file_bug822367_5.html";
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest5A() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
   let {gIdentityHandler} = gTestBrowser.ownerGlobal;
   gIdentityHandler.disableMixedContentProtection();
-}
-function MixedTest4B() {
-  BrowserTestUtils.waitForCondition(() => content.document.location == HTTPS_TEST_ROOT + "file_bug822367_4B.html", "Waited too long for mixed script to run in Test 4").then(MixedTest4C);
-}
-function MixedTest4C() {
-  ok(content.document.location == HTTPS_TEST_ROOT + "file_bug822367_4B.html", "Location didn't change in test 4");
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
-  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
+add_task(function* MixedTest5B() {
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p1").innerHTML == "hello",
+      "Waited too long for mixed script to run in Test 5");
+  });
+});
 
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p1").innerHTML == "", "Mixed script loaded in test 4 after location change!").then(MixedTest4D);
-}
-function MixedTest4D() {
-  ok(content.document.getElementById("p1").innerHTML == "", "p1.innerHTML changed; mixed script loaded after location change in Test 4");
-  MixedTest5();
-}
+// Mixed script attempts to load in a document.open() that is within an iframe.
+add_task(function* MixedTest6() {
+  var url = HTTPS_TEST_ROOT_2 + "file_bug822367_6.html";
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
-// Mixed script attempts to load in a document.open()
-function MixedTest5() {
-  gTestBrowser.removeEventListener("load", MixedTest4B, true);
-  gTestBrowser.addEventListener("load", MixedTest5A, true);
-  var url = HTTPS_TEST_ROOT + "file_bug822367_5.html";
-  gTestBrowser.contentWindow.location = url;
-}
-function MixedTest5A() {
-  gTestBrowser.removeEventListener("load", MixedTest5A, true);
-  gTestBrowser.addEventListener("load", MixedTest5B, true);
+add_task(function* MixedTest6A() {
+  gTestBrowser.removeEventListener("load", MixedTest6A, true);
+  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
 
+  yield BrowserTestUtils.waitForCondition(
+    () => gIdentityHandler._identityBox.classList.contains("mixedActiveBlocked"),
+    "Waited too long for control center to get mixed active blocked state");
+});
+
+add_task(function* MixedTest6B() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
   let {gIdentityHandler} = gTestBrowser.ownerGlobal;
   gIdentityHandler.disableMixedContentProtection();
-}
-function MixedTest5B() {
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p1").innerHTML == "hello", "Waited too long for mixed script to run in Test 5").then(MixedTest5C);
-}
-function MixedTest5C() {
-  ok(content.document.getElementById("p1").innerHTML == "hello", "Mixed script didn't load in Test 5");
-  MixedTest6();
-}
 
-// Mixed script attempts to load in a document.open() that is within an iframe.
-function MixedTest6() {
-  gTestBrowser.removeEventListener("load", MixedTest5B, true);
-  gTestBrowser.addEventListener("load", MixedTest6A, true);
-  var url = HTTPS_TEST_ROOT_2 + "file_bug822367_6.html";
-  gTestBrowser.contentWindow.location = url;
-}
-function MixedTest6A() {
-  gTestBrowser.removeEventListener("load", MixedTest6A, true);
-  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
-  BrowserTestUtils.waitForCondition(() => gIdentityHandler._identityBox.classList.contains("mixedActiveBlocked"), "Waited too long for control center to get mixed active blocked state").then(MixedTest6B);
-}
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
-function MixedTest6B() {
-  gTestBrowser.addEventListener("load", MixedTest6C, true);
-
-  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
-
-  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
-  gIdentityHandler.disableMixedContentProtection();
-}
+add_task(function* MixedTest6C() {
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    function test() {
+      try {
+        return content.document.getElementById("f1").contentDocument.getElementById("p1").innerHTML == "hello";
+      } catch (e) {
+        return false;
+      }
+    }
 
-function MixedTest6C() {
-  gTestBrowser.removeEventListener("load", MixedTest6C, true);
-  BrowserTestUtils.waitForCondition(function() {
-    try {
-      return content.document.getElementById("f1").contentDocument.getElementById("p1").innerHTML == "hello";
-    } catch (e) {
-      return false;
-    }
-  }, "Waited too long for mixed script to run in Test 6").then(MixedTest6D);
-}
-function MixedTest6D() {
-  ok(content.document.getElementById("f1").contentDocument.getElementById("p1").innerHTML == "hello", "Mixed script didn't load in Test 6");
+    yield ContentTaskUtils.waitForCondition(test, "Waited too long for mixed script to run in Test 6");
+  });
+});
+
+add_task(function* MixedTest6D() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: false});
-  MixedTestsCompleted();
-}
+});
+
+add_task(function* cleanup() {
+  gBrowser.removeCurrentTab();
+});
--- a/browser/components/contextualidentity/test/browser/browser_usercontext.js
+++ b/browser/components/contextualidentity/test/browser/browser_usercontext.js
@@ -64,17 +64,17 @@ add_task(function* test() {
 
     let tab = openTabInUserContext(BASE_URI, userContextId);
 
     // wait for load
     let browser = gBrowser.getBrowserForTab(tab);
     yield BrowserTestUtils.browserLoaded(browser);
 
     // get the title
-    let title = browser.contentTitle.trim().split("|");
+    let title = browser.contentDocument.title.trim().split("|");
 
     // check each item in the title and validate it meets expectatations
     for (let part of title) {
       let [storageMethodName, value] = part.split("=");
       is(value, expectedContext,
             "the title reflects the expected contextual identity of " +
             expectedContext + " for method " + storageMethodName + ": " + value);
     }
--- a/browser/components/sessionstore/test/browser_500328.js
+++ b/browser/components/sessionstore/test/browser_500328.js
@@ -1,116 +1,120 @@
 /* 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 checkState(tab) {
+let checkState = Task.async(function*(browser) {
   // Go back and then forward, and make sure that the state objects received
   // from the popState event are as we expect them to be.
   //
   // We also add a node to the document's body when after going back and make
   // sure it's still there after we go forward -- this is to test that the two
   // history entries correspond to the same document.
 
+  let deferred = {};
+  deferred.promise = new Promise(resolve => deferred.resolve = resolve);
+
   let popStateCount = 0;
 
-  tab.linkedBrowser.addEventListener('popstate', function(aEvent) {
-    let contentWindow = tab.linkedBrowser.contentWindow;
+  browser.addEventListener("popstate", function(aEvent) {
     if (popStateCount == 0) {
       popStateCount++;
 
-      is(tab.linkedBrowser.contentWindow.testState, 'foo',
-         'testState after going back');
+      ok(aEvent.state, "Event should have a state property.");
 
-      ok(aEvent.state, "Event should have a state property.");
-      is(JSON.stringify(tab.linkedBrowser.contentWindow.history.state), JSON.stringify({obj1:1}),
-         "first popstate object.");
+      ContentTask.spawn(browser, null, function() {
+        is(content.testState, "foo",
+           "testState after going back");
+        is(JSON.stringify(content.history.state), JSON.stringify({obj1:1}),
+           "first popstate object.");
 
-      // Add a node with id "new-elem" to the document.
-      let doc = contentWindow.document;
-      ok(!doc.getElementById("new-elem"),
-         "doc shouldn't contain new-elem before we add it.");
-      let elem = doc.createElement("div");
-      elem.id = "new-elem";
-      doc.body.appendChild(elem);
-
-      tab.linkedBrowser.goForward();
-    }
-    else if (popStateCount == 1) {
+        // Add a node with id "new-elem" to the document.
+        let doc = content.document;
+        ok(!doc.getElementById("new-elem"),
+           "doc shouldn't contain new-elem before we add it.");
+        let elem = doc.createElement("div");
+        elem.id = "new-elem";
+        doc.body.appendChild(elem);
+      }).then(() => {
+        browser.goForward();
+      });
+    } else if (popStateCount == 1) {
       popStateCount++;
       // When content fires a PopStateEvent and we observe it from a chrome event
       // listener (as we do here, and, thankfully, nowhere else in the tree), the
       // state object will be a cross-compartment wrapper to an object that was
       // deserialized in the content scope. And in this case, since RegExps are
       // not currently Xrayable (see bug 1014991), trying to pull |obj3| (a RegExp)
       // off of an Xrayed Object won't work. So we need to waive.
-      ContentTask.spawn(tab.linkedBrowser, aEvent.state, function(state) {
+      ContentTask.spawn(browser, aEvent.state, function(state) {
         Assert.equal(Cu.waiveXrays(state).obj3.toString(),
           "/^a$/", "second popstate object.");
-      }).then(function() {
+
         // Make sure that the new-elem node is present in the document.  If it's
         // not, then this history entry has a different doc identifier than the
         // previous entry, which is bad.
-        let doc = contentWindow.document;
+        let doc = content.document;
         let newElem = doc.getElementById("new-elem");
         ok(newElem, "doc should contain new-elem.");
         newElem.remove();
         ok(!doc.getElementById("new-elem"), "new-elem should be removed.");
-
-        tab.linkedBrowser.removeEventListener("popstate", arguments.callee, true);
-        gBrowser.removeTab(tab);
-        finish();
+      }).then(() => {
+        browser.removeEventListener("popstate", arguments.callee, true);
+        deferred.resolve();
       });
     }
   });
 
   // Set some state in the page's window.  When we go back(), the page should
   // be retrieved from bfcache, and this state should still be there.
-  tab.linkedBrowser.contentWindow.testState = 'foo';
+  yield ContentTask.spawn(browser, null, function() {
+    content.testState = "foo";
+  });
 
   // Now go back.  This should trigger the popstate event handler above.
-  tab.linkedBrowser.goBack();
-}
+  browser.goBack();
 
-function test() {
+  yield deferred.promise;
+});
+
+add_task(function* test() {
   // Tests session restore functionality of history.pushState and
   // history.replaceState().  (Bug 500328)
 
-  waitForExplicitFinish();
-
   // We open a new blank window, let it load, and then load in
   // http://example.com.  We need to load the blank window first, otherwise the
   // docshell gets confused and doesn't have a current history entry.
-  let tab = gBrowser.addTab("about:blank");
-  let browser = tab.linkedBrowser;
-
-  promiseBrowserLoaded(browser).then(() => {
-    browser.loadURI("http://example.com", null, null);
+  let state;
+  yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, function* (browser) {
+    BrowserTestUtils.loadURI(browser, "http://example.com");
+    yield BrowserTestUtils.browserLoaded(browser);
 
-    promiseBrowserLoaded(browser).then(() => {
-      // After these push/replaceState calls, the window should have three
-      // history entries:
-      //   testURL        (state object: null)          <-- oldest
-      //   testURL        (state object: {obj1:1})
-      //   testURL?page2  (state object: {obj3:/^a$/})  <-- newest
-      function contentTest() {
-        let history = content.window.history;
-        history.pushState({obj1:1}, "title-obj1");
-        history.pushState({obj2:2}, "title-obj2", "?page2");
-        history.replaceState({obj3:/^a$/}, "title-obj3");
-      }
-      ContentTask.spawn(browser, null, contentTest).then(function() {
-        return TabStateFlusher.flush(tab.linkedBrowser);
-      }).then(() => {
-        let state = ss.getTabState(tab);
-        gBrowser.removeTab(tab);
+    // After these push/replaceState calls, the window should have three
+    // history entries:
+    //   testURL        (state object: null)          <-- oldest
+    //   testURL        (state object: {obj1:1})
+    //   testURL?page2  (state object: {obj3:/^a$/})  <-- newest
+    function contentTest() {
+      let history = content.window.history;
+      history.pushState({obj1:1}, "title-obj1");
+      history.pushState({obj2:2}, "title-obj2", "?page2");
+      history.replaceState({obj3:/^a$/}, "title-obj3");
+    }
+    yield ContentTask.spawn(browser, null, contentTest);
+    yield TabStateFlusher.flush(browser);
 
-        // Restore the state into a new tab.  Things don't work well when we
-        // restore into the old tab, but that's not a real use case anyway.
-        let tab2 = gBrowser.addTab("about:blank");
-        ss.setTabState(tab2, state, true);
+    state = ss.getTabState(gBrowser.getTabForBrowser(browser));
+  });
+
+  // Restore the state into a new tab.  Things don't work well when we
+  // restore into the old tab, but that's not a real use case anyway.
+  yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, function* (browser) {
+    let tab2 = gBrowser.getTabForBrowser(browser);
 
-        // Run checkState() once the tab finishes loading its restored state.
-        promiseTabRestored(tab2).then(() => checkState(tab2));
-      });
-    });
+    let tabRestoredPromise = promiseTabRestored(tab2);
+    ss.setTabState(tab2, state, true);
+
+    // Run checkState() once the tab finishes loading its restored state.
+    yield tabRestoredPromise;
+    yield checkState(browser);
   });
-}
+});
--- a/browser/components/sessionstore/test/browser_687710_2.js
+++ b/browser/components/sessionstore/test/browser_687710_2.js
@@ -1,8 +1,9 @@
+/* eslint-env mozilla/frame-script */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Test that the fix for bug 687710 isn't too aggressive -- shentries which are
 // cousins should be able to share bfcache entries.
 
 var stateBackup = ss.getBrowserState();
 
@@ -20,54 +21,48 @@ var state = {entries:[
     url: "http://example.com?1#a",
     triggeringPrincipal_base64,
     children: [{ docIdentifier: 10,
                  url: "http://example.com?10#aa",
                  triggeringPrincipal_base64 }]
   }
 ]};
 
-function test()
-{
-  waitForExplicitFinish();
+add_task(function* test() {
+  let tab = gBrowser.addTab("about:blank");
+  yield promiseTabState(tab, state);
+  yield ContentTask.spawn(tab.linkedBrowser, null, function() {
+    function compareEntries(i, j, history) {
+      let e1 = history.getEntryAtIndex(i, false)
+                      .QueryInterface(Ci.nsISHEntry)
+                      .QueryInterface(Ci.nsISHContainer);
+
+      let e2 = history.getEntryAtIndex(j, false)
+                      .QueryInterface(Ci.nsISHEntry)
+                      .QueryInterface(Ci.nsISHContainer);
 
-  registerCleanupFunction(function () {
-    ss.setBrowserState(stateBackup);
-  });
+      ok(e1.sharesDocumentWith(e2),
+         `${i} should share doc with ${j}`);
+      is(e1.childCount, e2.childCount,
+         `Child count mismatch (${i}, ${j})`);
 
-  let tab = gBrowser.addTab("about:blank");
-  promiseTabState(tab, state).then(() => {
-    let history = tab.linkedBrowser.webNavigation.sessionHistory;
+      for (let c = 0; c < e1.childCount; c++) {
+        let c1 = e1.GetChildAt(c);
+        let c2 = e2.GetChildAt(c);
+
+        ok(c1.sharesDocumentWith(c2),
+           `Cousins should share documents. (${i}, ${j}, ${c})`);
+      }
+    }
+
+    let history = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsISHistory);
 
     is(history.count, 2, "history.count");
     for (let i = 0; i < history.count; i++) {
       for (let j = 0; j < history.count; j++) {
         compareEntries(i, j, history);
       }
     }
-
-    finish();
   });
-}
-
-function compareEntries(i, j, history)
-{
-  let e1 = history.getEntryAtIndex(i, false)
-                  .QueryInterface(Ci.nsISHEntry)
-                  .QueryInterface(Ci.nsISHContainer);
 
-  let e2 = history.getEntryAtIndex(j, false)
-                  .QueryInterface(Ci.nsISHEntry)
-                  .QueryInterface(Ci.nsISHContainer);
-
-  ok(e1.sharesDocumentWith(e2),
-     i + ' should share doc with ' + j);
-  is(e1.childCount, e2.childCount,
-     'Child count mismatch (' + i + ', ' + j + ')');
-
-  for (let c = 0; c < e1.childCount; c++) {
-    let c1 = e1.GetChildAt(c);
-    let c2 = e2.GetChildAt(c);
-
-    ok(c1.sharesDocumentWith(c2),
-       'Cousins should share documents. (' + i + ', ' + j + ', ' + c + ')');
-  }
-}
+  ss.setBrowserState(stateBackup);
+});
--- a/browser/components/sessionstore/test/browser_739805.js
+++ b/browser/components/sessionstore/test/browser_739805.js
@@ -24,17 +24,18 @@ function test() {
 
     ss.setTabState(tab, JSON.stringify(tabState));
     is(browser.__SS_restoreState, TAB_STATE_NEEDS_RESTORE, "tab needs restoring");
 
     let {formdata} = JSON.parse(ss.getTabState(tab));
     is(formdata && formdata.id["foo"], "bar", "tab state's formdata is valid");
 
     promiseTabRestored(tab).then(() => {
-      let input = browser.contentDocument.getElementById("foo");
-      is(input.value, "bar", "formdata has been restored correctly");
-      finish();
+      ContentTask.spawn(browser, null, function() {
+        let input = content.document.getElementById("foo");
+        is(input.value, "bar", "formdata has been restored correctly");
+      }).then(() => { finish(); });
     });
 
     // Restore the tab by selecting it.
     gBrowser.selectedTab = tab;
   });
 }
--- a/browser/components/sessionstore/test/browser_911547.js
+++ b/browser/components/sessionstore/test/browser_911547.js
@@ -11,42 +11,53 @@ add_task(function* test() {
   let tab = gBrowser.selectedTab = gBrowser.addTab(testURL);
   gBrowser.selectedTab = tab;
 
   let browser = tab.linkedBrowser;
   yield promiseBrowserLoaded(browser);
 
   // this is a baseline to ensure CSP is active
   // attempt to inject and run a script via inline (pre-restore, allowed)
-  injectInlineScript(browser,'document.getElementById("test_id").value = "fail";');
-  is(browser.contentDocument.getElementById("test_id").value, "ok",
-     "CSP should block the inline script that modifies test_id");
+  yield injectInlineScript(browser, `document.getElementById("test_id").value = "fail";`);
+
+  let loadedPromise = promiseBrowserLoaded(browser);
+  yield ContentTask.spawn(browser, null, function() {
+    is(content.document.getElementById("test_id").value, "ok",
+       "CSP should block the inline script that modifies test_id");
 
-  // attempt to click a link to a data: URI (will inherit the CSP of the
-  // origin document) and navigate to the data URI in the link.
-  browser.contentDocument.getElementById("test_data_link").click();
-  yield promiseBrowserLoaded(browser);
+    // attempt to click a link to a data: URI (will inherit the CSP of the
+    // origin document) and navigate to the data URI in the link.
+    content.document.getElementById("test_data_link").click();
+  });
 
-  is(browser.contentDocument.getElementById("test_id2").value, "ok",
-     "CSP should block the script loaded by the clicked data URI");
+  yield loadedPromise;
+
+  yield ContentTask.spawn(browser, null, function() {
+    is(content.document.getElementById("test_id2").value, "ok",
+       "CSP should block the script loaded by the clicked data URI");
+  });
 
   // close the tab
   yield promiseRemoveTab(tab);
 
   // open new tab and recover the state
   tab = ss.undoCloseTab(window, 0);
   yield promiseTabRestored(tab);
   browser = tab.linkedBrowser;
 
-  is(browser.contentDocument.getElementById("test_id2").value, "ok",
-     "CSP should block the script loaded by the clicked data URI after restore");
+  yield ContentTask.spawn(browser, null, function() {
+    is(content.document.getElementById("test_id2").value, "ok",
+       "CSP should block the script loaded by the clicked data URI after restore");
+  });
 
   // clean up
   gBrowser.removeTab(tab);
 });
 
 // injects an inline script element (with a text body)
 function injectInlineScript(browser, scriptText) {
-  let scriptElt = browser.contentDocument.createElement("script");
-  scriptElt.type = 'text/javascript';
-  scriptElt.text = scriptText;
-  browser.contentDocument.body.appendChild(scriptElt);
+  return ContentTask.spawn(browser, scriptText, function(text) {
+    let scriptElt = content.document.createElement("script");
+    scriptElt.type = "text/javascript";
+    scriptElt.text = text;
+    content.document.body.appendChild(scriptElt);
+  });
 }
--- a/browser/components/sessionstore/test/browser_history_persist.js
+++ b/browser/components/sessionstore/test/browser_history_persist.js
@@ -1,8 +1,9 @@
+/* eslint-env mozilla/frame-script */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 /**
  * Ensure that history entries that should not be persisted are restored in the
  * same state.
@@ -12,68 +13,81 @@ add_task(function* check_history_not_per
   let tab = gBrowser.addTab("about:blank");
   let browser = tab.linkedBrowser;
   yield promiseBrowserLoaded(browser);
 
   // Retrieve the tab state.
   yield TabStateFlusher.flush(browser);
   let state = JSON.parse(ss.getTabState(tab));
   ok(!state.entries[0].persist, "Should have collected the persistence state");
-  gBrowser.removeTab(tab);
+  yield promiseRemoveTab(tab);
   browser = null;
 
   // Open a new tab to restore into.
   tab = gBrowser.addTab("about:blank");
   browser = tab.linkedBrowser;
   yield promiseTabState(tab, state);
-  let sessionHistory = browser.sessionHistory;
 
-  is(sessionHistory.count, 1, "Should be a single history entry");
-  is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
+  yield ContentTask.spawn(browser, null, function() {
+    let sessionHistory = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISHistory);
+
+    is(sessionHistory.count, 1, "Should be a single history entry");
+    is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
+  });
 
   // Load a new URL into the tab, it should replace the about:blank history entry
   browser.loadURI("about:robots");
   yield promiseBrowserLoaded(browser);
-  sessionHistory = browser.sessionHistory;
-  is(sessionHistory.count, 1, "Should be a single history entry");
-  is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:robots", "Should be the right URL");
+  yield ContentTask.spawn(browser, null, function() {
+    let sessionHistory = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISHistory);
+    is(sessionHistory.count, 1, "Should be a single history entry");
+    is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:robots", "Should be the right URL");
+  });
 
   // Cleanup.
-  gBrowser.removeTab(tab);
+  yield promiseRemoveTab(tab);
 });
 
 /**
  * Check that entries default to being persisted when the attribute doesn't
  * exist
  */
 add_task(function* check_history_default_persisted() {
   // Create an about:blank tab
   let tab = gBrowser.addTab("about:blank");
   let browser = tab.linkedBrowser;
   yield promiseBrowserLoaded(browser);
 
   // Retrieve the tab state.
   yield TabStateFlusher.flush(browser);
   let state = JSON.parse(ss.getTabState(tab));
   delete state.entries[0].persist;
-  gBrowser.removeTab(tab);
+  yield promiseRemoveTab(tab);
   browser = null;
 
   // Open a new tab to restore into.
   tab = gBrowser.addTab("about:blank");
   browser = tab.linkedBrowser;
   yield promiseTabState(tab, state);
-  let sessionHistory = browser.sessionHistory;
+  yield ContentTask.spawn(browser, null, function() {
+    let sessionHistory = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISHistory);
 
-  is(sessionHistory.count, 1, "Should be a single history entry");
-  is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
+    is(sessionHistory.count, 1, "Should be a single history entry");
+    is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
+  });
 
   // Load a new URL into the tab, it should replace the about:blank history entry
   browser.loadURI("about:robots");
   yield promiseBrowserLoaded(browser);
-  sessionHistory = browser.sessionHistory;
-  is(sessionHistory.count, 2, "Should be two history entries");
-  is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
-  is(sessionHistory.getEntryAtIndex(1, false).URI.spec, "about:robots", "Should be the right URL");
+  yield ContentTask.spawn(browser, null, function() {
+    let sessionHistory = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISHistory);
+    is(sessionHistory.count, 2, "Should be two history entries");
+    is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
+    is(sessionHistory.getEntryAtIndex(1, false).URI.spec, "about:robots", "Should be the right URL");
+  });
 
   // Cleanup.
-  gBrowser.removeTab(tab);
+  yield promiseRemoveTab(tab);
 });
--- a/docshell/test/browser/browser_bug554155.js
+++ b/docshell/test/browser/browser_bug554155.js
@@ -1,31 +1,26 @@
-function test() {
-  waitForExplicitFinish();
-
-  let tab = gBrowser.addTab("http://example.com");
-
-  tab.linkedBrowser.addEventListener("load", function() {
+add_task(function* test() {
+  yield BrowserTestUtils.withNewTab({ gBrowser, url: "http://example.com" }, function* (browser) {
     let numLocationChanges = 0;
 
     let listener = {
       onLocationChange: function(browser, webProgress, request, uri, flags) {
         info("location change: " + (uri && uri.spec));
         numLocationChanges++;
       }
     };
 
     gBrowser.addTabsProgressListener(listener);
 
-    // pushState to a new URL (http://example.com/foo").  This should trigger
-    // exactly one LocationChange event.
-    tab.linkedBrowser.contentWindow.history.pushState(null, null, "foo");
-
-    executeSoon(function() {
-      gBrowser.removeTab(tab);
-      gBrowser.removeTabsProgressListener(listener);
-      is(numLocationChanges, 1,
-         "pushState should cause exactly one LocationChange event.");
-      finish();
+    yield ContentTask.spawn(browser, null, function() {
+      // pushState to a new URL (http://example.com/foo").  This should trigger
+      // exactly one LocationChange event.
+      content.history.pushState(null, null, "foo");
     });
 
-  }, {capture: true, once: true});
-}
+    yield Promise.resolve();
+
+    gBrowser.removeTabsProgressListener(listener);
+    is(numLocationChanges, 1,
+       "pushState should cause exactly one LocationChange event.");
+  });
+});
--- a/netwerk/test/browser/browser_child_resource.js
+++ b/netwerk/test/browser/browser_child_resource.js
@@ -116,17 +116,17 @@ function remoteResolveURI(uri) {
     manager.addMessageListener("Test:ResolvedURI", listener);
     manager.sendAsyncMessage("Test:ResolveURI", uri);
   });
 }
 
 var loadTestTab = Task.async(function*() {
   gBrowser.selectedTab = gBrowser.addTab(TEST_URL);
   let browser = gBrowser.selectedBrowser;
-  yield waitForEvent(browser, "load", true);
+  yield BrowserTestUtils.browserLoaded(browser);
   browser.messageManager.loadFrameScript("data:,(" + frameScript.toString() + ")();", true);
   return browser;
 });
 
 // Restarts the child process by crashing it then reloading the tab
 var restart = Task.async(function*() {
   let browser = gBrowser.selectedBrowser;
   // If the tab isn't remote this would crash the main process so skip it
--- a/toolkit/components/startup/tests/browser/head.js
+++ b/toolkit/components/startup/tests/browser/head.js
@@ -1,22 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 function whenBrowserLoaded(browser, callback) {
-  browser.addEventListener("load", function onLoad(event) {
-    if (event.target == browser.contentDocument) {
-      browser.removeEventListener("load", onLoad, true);
-      executeSoon(callback);
-    }
-  }, true);
+  return BrowserTestUtils.browserLoaded(browser).then(callback);
 }
 
 function waitForOnBeforeUnloadDialog(browser, callback) {
   browser.addEventListener("DOMWillOpenModalDialog", function onModalDialog(event) {
     if (Cu.isCrossProcessWrapper(event.target)) {
       // This event fires in both the content and chrome processes. We
       // want to ignore the one in the content process.
       return;
--- a/toolkit/content/tests/browser/browser_findbar.js
+++ b/toolkit/content/tests/browser/browser_findbar.js
@@ -22,17 +22,17 @@ add_task(function* test_hotkey_event_pro
 
   // Pressing these keys open the findbar.
   const HOTKEYS = ["/", "'"];
 
   // Checking if findbar appears when any hotkey is pressed.
   for (let key of HOTKEYS) {
     is(findbar.hidden, true, "Findbar is hidden now.");
     gBrowser.selectedTab = tab;
-    yield promiseFocus();
+    yield SimpleTest.promiseFocus(gBrowser.selectedBrowser);
     yield BrowserTestUtils.sendChar(key, browser);
     is(findbar.hidden, false, "Findbar should not be hidden.");
     yield closeFindbarAndWait(findbar);
   }
 
   // Stop propagation for all keyboard events.
   let frameScript = () => {
     const stopPropagation = e => e.stopImmediatePropagation();
@@ -44,17 +44,17 @@ add_task(function* test_hotkey_event_pro
 
   let mm = browser.messageManager;
   mm.loadFrameScript("data:,(" + frameScript.toString() + ")();", false);
 
   // Checking if findbar still appears when any hotkey is pressed.
   for (let key of HOTKEYS) {
     is(findbar.hidden, true, "Findbar is hidden now.");
     gBrowser.selectedTab = tab;
-    yield promiseFocus();
+    yield SimpleTest.promiseFocus(gBrowser.selectedBrowser);
     yield BrowserTestUtils.sendChar(key, browser);
     is(findbar.hidden, false, "Findbar should not be hidden.");
     yield closeFindbarAndWait(findbar);
   }
 
   gBrowser.removeTab(tab);
 });
 
@@ -232,27 +232,16 @@ function promiseFindFinished(searchText,
     };
     findbar.browser.finder.addResultListener(resultListener);
     findbar._find();
   });
 
   return deferred.promise;
 }
 
-/**
- * A promise-like wrapper for the waitForFocus helper.
- */
-function promiseFocus() {
-  return new Promise((resolve) => {
-    waitForFocus(function() {
-      resolve();
-    }, content);
-  });
-}
-
 function promiseRemotenessChange(tab, shouldBeRemote) {
   return new Promise((resolve) => {
     let browser = gBrowser.getBrowserForTab(tab);
     tab.addEventListener("TabRemotenessChange", function() {
       resolve();
     }, {once: true});
     gBrowser.updateBrowserRemoteness(browser, shouldBeRemote);
   });