Bug 1592309 - Rewrite tests using xpcEnumerateContentWindows. r=kmag
authorAndreas Farre <farre@mozilla.com>
Tue, 12 Nov 2019 21:52:26 +0000
changeset 501671 b562df92157acd793a7da500c718f95685c91990
parent 501670 09005ea3861f549d6f4f613d1e83fe18fd13ebc8
child 501672 ac88099aca2d631b5f1d79856c49b3ffb59e0d52
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1592309
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1592309 - Rewrite tests using xpcEnumerateContentWindows. r=kmag Differential Revision: https://phabricator.services.mozilla.com/D51110
docshell/test/navigation/NavigationUtils.js
docshell/test/navigation/mochitest.ini
docshell/test/navigation/test_bug13871.html
docshell/test/navigation/test_bug270414.html
docshell/test/navigation/test_bug278916.html
docshell/test/navigation/test_bug279495.html
docshell/test/navigation/test_child.html
docshell/test/navigation/test_grandchild.html
docshell/test/navigation/test_not-opener.html
docshell/test/navigation/test_opener.html
docshell/test/navigation/test_popup-navigates-children.html
docshell/test/navigation/test_reserved.html
docshell/test/navigation/test_sibling-matching-parent.html
docshell/test/navigation/test_sibling-off-domain.html
--- a/docshell/test/navigation/NavigationUtils.js
+++ b/docshell/test/navigation/NavigationUtils.js
@@ -91,149 +91,24 @@ function isInaccessible(wnd, message) {
   try {
     wnd.document.body.innerHTML;
     ok(false, message);
   } catch (ex) {
     ok(true, message);
   }
 }
 
-// /////////////////////////////////////////////////////////////////////////
-// Functions that require UniversalXPConnect privilege
-// /////////////////////////////////////////////////////////////////////////
-// Replacing the getService with Services.ww format causes test errors, so ignore for now
-/* eslint-disable mozilla/use-services */
-function xpcEnumerateContentWindows(callback) {
-  var Ci = SpecialPowers.Ci;
-  var ww = SpecialPowers.Cc[
-    "@mozilla.org/embedcomp/window-watcher;1"
-  ].getService(Ci.nsIWindowWatcher);
-
-  var contentWindows = [];
-
-  for (let win of ww.getWindowEnumerator()) {
-    if (win.isChromeWindow) {
-      var docshellTreeNode = win.docShell;
-      var childCount = docshellTreeNode.childCount;
-      for (var i = 0; i < childCount; ++i) {
-        var childTreeNode = docshellTreeNode.getChildAt(i);
-
-        // we're only interested in content docshells
-        if (
-          SpecialPowers.unwrap(childTreeNode.itemType) !=
-          Ci.nsIDocShellTreeItem.typeContent
-        ) {
-          continue;
-        }
-
-        var webNav = childTreeNode.QueryInterface(Ci.nsIWebNavigation);
-        contentWindows.push(webNav.document.defaultView);
-      }
-    } else {
-      contentWindows.push(win);
-    }
-  }
-
-  while (contentWindows.length > 0) {
-    callback(contentWindows.pop());
-  }
-}
-/* eslint-enable mozilla/use-services */
-
-// Note: This only searches for top-level frames with this name.
-function xpcGetFramesByName(name) {
-  var results = [];
-
-  xpcEnumerateContentWindows(function(win) {
-    if (win.name == name) {
-      results.push(win);
-    }
-  });
-
-  return results;
-}
-
-function xpcCleanupWindows() {
-  xpcEnumerateContentWindows(function(win) {
-    if (
-      win.location &&
-      (win.location.href.endsWith(target_url) ||
-        win.location.href.endsWith(target_popup_url))
-    ) {
-      win.close();
-    }
-  });
-}
-
-function xpcWaitForFinishedFrames(callback, numFrames) {
-  var finishedFrameCount = 0;
-  function frameFinished() {
-    finishedFrameCount++;
-
-    if (finishedFrameCount == numFrames) {
-      clearInterval(frameWaitInterval);
-      setTimeout(callback, 0);
-      return;
-    }
-
-    if (finishedFrameCount > numFrames) {
-      throw new Error("Too many frames loaded.");
-    }
-  }
-
-  var finishedWindows = [];
-
-  function contains(obj, arr) {
-    for (var i = 0; i < arr.length; i++) {
-      if (obj === arr[i]) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  function searchForFinishedFrames(win) {
-    if (
-      (win.location.href.endsWith(target_url) ||
-        win.location.href.endsWith(target_popup_url)) &&
-      win.document &&
-      win.document.body &&
-      (win.document.body.textContent.trim() == body ||
-        win.document.body.textContent.trim() == popup_body) &&
-      win.document.readyState == "complete"
-    ) {
-      var windowId = win.windowUtils.outerWindowID;
-      if (!contains(windowId, finishedWindows)) {
-        finishedWindows.push(windowId);
-        frameFinished();
-      }
-    }
-    for (var i = 0; i < win.frames.length; i++) {
-      searchForFinishedFrames(win.frames[i]);
-    }
-  }
-
-  function poll() {
-    try {
-      // This only gives us UniversalXPConnect for the current stack frame
-      // We're using setInterval, so the main page's privileges are still normal
-      xpcEnumerateContentWindows(searchForFinishedFrames);
-    } catch (ex) {
-      // We might be accessing windows before they are fully constructed,
-      // which can throw.  We'll find those frames on our next poll().
-    }
-  }
-
-  var frameWaitInterval = setInterval(poll, 500);
-}
-
 function delay(msec) {
   return new Promise(resolve => setTimeout(resolve, msec));
 }
 
+// /////////////////////////////////////////////////////////////////////////
+// Functions that uses SpecialPowers.spawn
+// /////////////////////////////////////////////////////////////////////////
+
 async function waitForFinishedFrames(numFrames) {
   SimpleTest.requestFlakyTimeout("Polling");
 
   var finishedWindows = new Set();
 
   async function searchForFinishedFrames(win) {
     try {
       let { href, bodyText, readyState } = await SpecialPowers.spawn(
@@ -274,8 +149,52 @@ async function waitForFinishedFrames(num
       await searchForFinishedFrames(win);
     }
   }
 
   if (finishedWindows.size > numFrames) {
     throw new Error("Too many frames loaded.");
   }
 }
+
+async function getFramesByName(name) {
+  let results = [];
+  for (let win of SpecialPowers.getGroupTopLevelWindows(window)) {
+    if (
+      (await SpecialPowers.spawn(win, [], () => this.content.name)) === name
+    ) {
+      results.push(win);
+    }
+  }
+
+  return results;
+}
+
+async function cleanupWindows() {
+  for (let win of SpecialPowers.getGroupTopLevelWindows(window)) {
+    if (win.closed) {
+      continue;
+    }
+
+    let href = "";
+    try {
+      href = await SpecialPowers.spawn(
+        win,
+        [],
+        () =>
+          this.content && this.content.location && this.content.location.href
+      );
+    } catch (error) {
+      // SpecialPowers.spawn(win, ...) throws if win is closed. We did
+      // our best to not call it on a closed window, but races happen.
+      if (!win.closed) {
+        throw error;
+      }
+    }
+
+    if (
+      href &&
+      (href.endsWith(target_url) || href.endsWith(target_popup_url))
+    ) {
+      win.close();
+    }
+  }
+}
--- a/docshell/test/navigation/mochitest.ini
+++ b/docshell/test/navigation/mochitest.ini
@@ -72,23 +72,22 @@ skip-if = (!debug && (os == 'mac' || os 
 skip-if = (os == "android") # Bug 1560378
 [test_bug1375833.html]
 [test_bug1536471.html]
 support-files = file_bug1536471.html
 [test_child.html]
 [test_grandchild.html]
 [test_load_history_entry.html]
 [test_not-opener.html]
-skip-if = fission # Times out.
 [test_opener.html]
 [test_popup-navigates-children.html]
 [test_reserved.html]
 skip-if =
-  (debug && e10s) || (os == 'mac' && os_version == '10.14') || # bug 1263213 for debug e10s, macosx1014 due to 1548821
-  fission # Times out.
+  (debug && e10s) || # bug 1263213
+  (os == 'mac' && os_version == '10.14') # Bug 1548821
 [test_performance_navigation.html]
 [test_sessionhistory.html]
 skip-if = toolkit == 'android' # RANDOM on android
 support-files = file_bug1379762-1.html
 [test_sibling-matching-parent.html]
 [test_sibling-off-domain.html]
 [test_triggeringprincipal_frame_nav.html]
 [test_triggeringprincipal_window_open.html]
--- a/docshell/test/navigation/test_bug13871.html
+++ b/docshell/test/navigation/test_bug13871.html
@@ -1,39 +1,39 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
-function runTest() {
+async function runTest() {
   navigateByLocation(window0.frames[0]);
   navigateByOpen("window1_child0");
   navigateByForm("window2_child0");
   navigateByHyperlink("window3_child0");
 
-  xpcWaitForFinishedFrames(function() {
-    isInaccessible(window0.frames[0], "Should not be able to navigate off-domain frame by setting location.");
-    isInaccessible(window1.frames[0], "Should not be able to navigate off-domain frame by calling window.open.");
-    isInaccessible(window2.frames[0], "Should not be able to navigate off-domain frame by submitting form.");
-    isInaccessible(window3.frames[0], "Should not be able to navigate off-domain frame by targeted hyperlink.");
+  await waitForFinishedFrames(4);
+
+  isInaccessible(window0.frames[0], "Should not be able to navigate off-domain frame by setting location.");
+  isInaccessible(window1.frames[0], "Should not be able to navigate off-domain frame by calling window.open.");
+  isInaccessible(window2.frames[0], "Should not be able to navigate off-domain frame by submitting form.");
+  isInaccessible(window3.frames[0], "Should not be able to navigate off-domain frame by targeted hyperlink.");
 
-    window0.close();
-    window1.close();
-    window2.close();
-    window3.close();
+  window0.close();
+  window1.close();
+  window2.close();
+  window3.close();
 
-    xpcCleanupWindows();
-    SimpleTest.finish();
-  }, 4);
+  await cleanupWindows();
+  SimpleTest.finish();
 }
 
 // Because our open()'d windows are cross-origin, we can't wait for onload.
 // We instead wait for a postMessage from parent.html.
 var windows = new Map();
 addEventListener("message", function windowLoaded(evt) {
   // Because window.open spins the event loop in order to open new windows,
   // we might receive the "ready" message before we call waitForLoad.
--- a/docshell/test/navigation/test_bug270414.html
+++ b/docshell/test/navigation/test_bug270414.html
@@ -69,18 +69,18 @@ add_task(async function() {
   await isNavigated(frames[2], "Should be able to navigate on-domain opener's children by submitting form.");
   await isNavigated(frames[3], "Should be able to navigate on-domain opener's children by targeted hyperlink.");
 
   window0.close();
   window1.close();
   window2.close();
   window3.close();
 
-  xpcCleanupWindows();
-}, 4);
+  await cleanupWindows();
+});
 
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=270414">Mozilla Bug 270414</a>
 <div id="frames">
 <iframe onload="testChild0();" name="child0" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
 <iframe onload="testChild1();" name="child1" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
--- a/docshell/test/navigation/test_bug278916.html
+++ b/docshell/test/navigation/test_bug278916.html
@@ -1,30 +1,30 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     <script type="text/javascript" src="NavigationUtils.js"></script>
 <script>
-window.onload = function() {
+window.onload = async function() {
   document.getElementById("link0").href = target_url;
   sendMouseEvent({type: "click"}, "link0");
 
-  xpcWaitForFinishedFrames(function() {
-    var array_of_frames = xpcGetFramesByName("window0");
-    is(array_of_frames.length, 1, "Should only open one window using a fancy hyperlink.");
+  await waitForFinishedFrames(1);
+
+  var array_of_frames = await getFramesByName("window0");
+  is(array_of_frames.length, 1, "Should only open one window using a fancy hyperlink.");
 
-    for (var i = 0; i < array_of_frames.length; ++i)
-      array_of_frames[i].close();
+  for (var i = 0; i < array_of_frames.length; ++i)
+    array_of_frames[i].close();
 
-    xpcCleanupWindows();
-    SimpleTest.finish();
-  }, 1);
+  await cleanupWindows();
+  SimpleTest.finish();
 };
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=278916">Mozilla Bug 278916</a>
 <div id="links">
 <a id="link0" target="window0" onclick="window.open('', 'window0', 'width=10,height=10');">This is a fancy hyperlink</a>
 </div>
--- a/docshell/test/navigation/test_bug279495.html
+++ b/docshell/test/navigation/test_bug279495.html
@@ -1,40 +1,36 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     <script type="text/javascript" src="NavigationUtils.js"></script>
 <script>
-window.onload = function() {
+window.onload = async function() {
   document.getElementById("link0").href = target_url;
   document.getElementById("link1").href = target_url;
 
   sendMouseEvent({type: "click"}, "link0");
   sendMouseEvent({type: "click"}, "link1");
 
-  xpcWaitForFinishedFrames(function() {
-    countAndClose("window0", 1);
-    countAndClose("window1", 1);
+  await waitForFinishedFrames(2);
+  await countAndClose("window0", 1);
+  await countAndClose("window1", 1);
 
-    xpcCleanupWindows();
-    SimpleTest.finish();
-  }, 2);
+  await cleanupWindows();
+  SimpleTest.finish();
 };
 
-function countAndClose(name, expected_count) {
-  var array_of_frames = xpcGetFramesByName(name);
+async function countAndClose(name, expected_count) {
+  var array_of_frames = await getFramesByName(name);
   is(array_of_frames.length, expected_count,
      "Should only open " + expected_count +
      " window(s) with name " + name + " using a fancy hyperlink.");
-
-  for (var i = 0; i < array_of_frames.length; ++i)
-    array_of_frames[i].close();
 }
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=279495">Mozilla Bug 279495</a>
 <div id="links">
 <a id="link0" target="window0" onclick="window.open('blank.html', 'window0', 'width=10,height=10');">This is a fancy hyperlink</a>
 <a id="link1" target="window1" onclick="window.open('http://test1.example.org:80/tests/docshell/test/navigation/blank.html', 'window1', 'width=10,height=10');">This is a fancy hyperlink</a>
--- a/docshell/test/navigation/test_child.html
+++ b/docshell/test/navigation/test_child.html
@@ -1,38 +1,37 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 if (!navigator.platform.startsWith("Win")) {
   SimpleTest.expectAssertions(0, 1);
 }
 
-window.onload = function() {
+window.onload = async function() {
   navigateByLocation(frames[0]);
   navigateByOpen("child1");
   navigateByForm("child2");
   navigateByHyperlink("child3");
 
-  xpcWaitForFinishedFrames(async function() {
-    await isNavigated(frames[0], "Should be able to navigate off-domain child by setting location.");
-    await isNavigated(frames[1], "Should be able to navigate off-domain child by calling window.open.");
-    await isNavigated(frames[2], "Should be able to navigate off-domain child by submitting form.");
-    await isNavigated(frames[3], "Should be able to navigate off-domain child by targeted hyperlink.");
+  await waitForFinishedFrames(4);
+  await isNavigated(frames[0], "Should be able to navigate off-domain child by setting location.");
+  await isNavigated(frames[1], "Should be able to navigate off-domain child by calling window.open.");
+  await isNavigated(frames[2], "Should be able to navigate off-domain child by submitting form.");
+  await isNavigated(frames[3], "Should be able to navigate off-domain child by targeted hyperlink.");
 
-    xpcCleanupWindows();
-    SimpleTest.finish();
-  }, 4);
+  await cleanupWindows();
+  SimpleTest.finish();
 };
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 <iframe name="child0" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
 <iframe name="child1" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
--- a/docshell/test/navigation/test_grandchild.html
+++ b/docshell/test/navigation/test_grandchild.html
@@ -1,38 +1,37 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 200px; }
     </style>
 <script>
 if (!navigator.platform.startsWith("Win")) {
   SimpleTest.expectAssertions(0, 1);
 }
 
-window.onload = function() {
+window.onload = async function() {
   navigateByLocation(frames[0].frames[0]);
   navigateByOpen("child1_child0");
   navigateByForm("child2_child0");
   navigateByHyperlink("child3_child0");
 
-  xpcWaitForFinishedFrames(async function() {
-    await isNavigated(frames[0].frames[0], "Should be able to navigate off-domain grandchild by setting location.");
-    await isNavigated(frames[1].frames[0], "Should be able to navigate off-domain grandchild by calling window.open.");
-    await isNavigated(frames[2].frames[0], "Should be able to navigate off-domain grandchild by submitting form.");
-    await isNavigated(frames[3].frames[0], "Should be able to navigate off-domain grandchild by targeted hyperlink.");
+  await waitForFinishedFrames(4);
+  await isNavigated(frames[0].frames[0], "Should be able to navigate off-domain grandchild by setting location.");
+  await isNavigated(frames[1].frames[0], "Should be able to navigate off-domain grandchild by calling window.open.");
+  await isNavigated(frames[2].frames[0], "Should be able to navigate off-domain grandchild by submitting form.");
+  await isNavigated(frames[3].frames[0], "Should be able to navigate off-domain grandchild by targeted hyperlink.");
 
-    xpcCleanupWindows();
-    SimpleTest.finish();
-  }, 4);
+  await cleanupWindows();
+  SimpleTest.finish();
 };
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 <iframe name="child0" src="http://test1.example.org:80/tests/docshell/test/navigation/parent.html"></iframe>
 <iframe name="child1" src="http://test1.example.org:80/tests/docshell/test/navigation/parent.html"></iframe>
--- a/docshell/test/navigation/test_not-opener.html
+++ b/docshell/test/navigation/test_not-opener.html
@@ -1,42 +1,44 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 if (!navigator.platform.startsWith("Win")) {
   SimpleTest.expectAssertions(0, 1);
 }
 
-window.onload = function() {
+window.onload = async function() {
   // navigateByLocation(window0);  // Don't have a handle to the window.
   navigateByOpen("window1");
   navigateByForm("window2");
   navigateByHyperlink("window3");
 
-  xpcWaitForFinishedFrames(function() {
-    is(xpcGetFramesByName("window1").length, 2, "Should not be able to navigate popup's popup by calling window.open.");
-    is(xpcGetFramesByName("window2").length, 2, "Should not be able to navigate popup's popup by submitting form.");
-    is(xpcGetFramesByName("window3").length, 2, "Should not be able to navigate popup's popup by targeted hyperlink.");
+  await waitForFinishedFrames(6);
+
+  is((await getFramesByName("window1")).length, 2, "Should not be able to navigate popup's popup by calling window.open.");
+  is((await getFramesByName("window2")).length, 2, "Should not be able to navigate popup's popup by submitting form.");
+  is((await getFramesByName("window3")).length, 2, "Should not be able to navigate popup's popup by targeted hyperlink.");
 
-    // opener0.close();
-    opener1.close();
-    opener2.close();
-    opener3.close();
+  // opener0.close();
+  opener1.close();
+  opener2.close();
+  opener3.close();
 
-    xpcCleanupWindows();
-    SimpleTest.finish();
-  }, 6);
+  info("here")
+  await cleanupWindows();
+  info("there")
+  SimpleTest.finish();
 };
 
 // opener0 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/open.html#window0", "_blank", "width=10,height=10");
 let opener1 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/open.html#window1", "_blank", "width=10,height=10");
 let opener2 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/open.html#window2", "_blank", "width=10,height=10");
 let opener3 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/open.html#window3", "_blank", "width=10,height=10");
 </script>
 </head>
--- a/docshell/test/navigation/test_opener.html
+++ b/docshell/test/navigation/test_opener.html
@@ -1,43 +1,43 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 if (navigator.platform.startsWith("Linux")) {
   SimpleTest.expectAssertions(0, 1);
 }
 
-window.onload = function() {
+window.onload = async function() {
   navigateByLocation(window0);
   navigateByOpen("window1");
   navigateByForm("window2");
   navigateByHyperlink("window3");
 
-  xpcWaitForFinishedFrames(async function() {
-    await isNavigated(window0, "Should be able to navigate popup by setting location.");
-    await isNavigated(window1, "Should be able to navigate popup by calling window.open.");
-    await isNavigated(window2, "Should be able to navigate popup by submitting form.");
-    await isNavigated(window3, "Should be able to navigate popup by targeted hyperlink.");
+  await waitForFinishedFrames(4);
+  await isNavigated(window0, "Should be able to navigate popup by setting location.");
+  await isNavigated(window1, "Should be able to navigate popup by calling window.open.");
+  await isNavigated(window2, "Should be able to navigate popup by submitting form.");
+  await isNavigated(window3, "Should be able to navigate popup by targeted hyperlink.");
 
-    window0.close();
-    window1.close();
-    window2.close();
-    window3.close();
+  window0.close();
+  window1.close();
+  window2.close();
+  window3.close();
 
-    xpcCleanupWindows();
-    SimpleTest.finish();
-  }, 4);
+  await cleanupWindows();
+
+  SimpleTest.finish();
 };
 
 var window0 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/blank.html", "window0", "width=10,height=10");
 var window1 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/blank.html", "window1", "width=10,height=10");
 var window2 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/blank.html", "window2", "width=10,height=10");
 var window3 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/blank.html", "window3", "width=10,height=10");
 </script>
 </head>
--- a/docshell/test/navigation/test_popup-navigates-children.html
+++ b/docshell/test/navigation/test_popup-navigates-children.html
@@ -1,15 +1,15 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 
 let window0 = null;
 let window1 = null;
 let window2 = null;
@@ -30,30 +30,31 @@ function testChild2() {
     window2 = window.open("navigate.html#child2,form", "window2", "width=10,height=10");
 }
 
 function testChild3() {
   if (!window.window3)
     window3 = window.open("navigate.html#child3,hyperlink", "window3", "width=10,height=10");
 }
 
-xpcWaitForFinishedFrames(async function() {
+window.onload = async function() {
+  await waitForFinishedFrames(4);
   await isNavigated(frames[0], "Should be able to navigate on-domain opener's children by setting location.");
   await isNavigated(frames[1], "Should be able to navigate on-domain opener's children by calling window.open.");
   await isNavigated(frames[2], "Should be able to navigate on-domain opener's children by submitting form.");
   await isNavigated(frames[3], "Should be able to navigate on-domain opener's children by targeted hyperlink.");
 
   window0.close();
   window1.close();
   window2.close();
   window3.close();
 
-  xpcCleanupWindows();
+  await cleanupWindows();
   SimpleTest.finish();
-}, 4);
+};
 
 </script>
 </head>
 <body>
 <div id="frames">
 <iframe onload="testChild0()" name="child0" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
 <iframe onload="testChild1()" name="child1" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
 <iframe onload="testChild2()" name="child2" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
--- a/docshell/test/navigation/test_reserved.html
+++ b/docshell/test/navigation/test_reserved.html
@@ -1,94 +1,86 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 200px; }
     </style>
 <script>
 if (navigator.platform.startsWith("Mac")) {
   SimpleTest.expectAssertions(0, 2);
 }
 
-function testTop() {
+async function testTop() {
   let window0 = window.open("iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#top,location", "_blank", "width=10,height=10");
 
-  xpcWaitForFinishedFrames(function() {
-    isInaccessible(window0, "Should be able to navigate off-domain top by setting location.");
-    window0.close();
-    xpcCleanupWindows();
+  await waitForFinishedFrames(1);
+  isInaccessible(window0, "Should be able to navigate off-domain top by setting location.");
+  window0.close();
+  await cleanupWindows();
 
-    let window1 = window.open("iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_top,open", "_blank", "width=10,height=10");
+  let window1 = window.open("iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_top,open", "_blank", "width=10,height=10");
 
-    xpcWaitForFinishedFrames(function() {
-      isInaccessible(window1, "Should be able to navigate off-domain top by calling window.open.");
-      window1.close();
-      xpcCleanupWindows();
+  await waitForFinishedFrames(1);
+  isInaccessible(window1, "Should be able to navigate off-domain top by calling window.open.");
+  window1.close();
+  await cleanupWindows();
 
-      let window2 = window.open("iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_top,form", "_blank", "width=10,height=10");
+  let window2 = window.open("iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_top,form", "_blank", "width=10,height=10");
 
-      xpcWaitForFinishedFrames(function() {
-        isInaccessible(window2, "Should be able to navigate off-domain top by submitting form.");
-        window2.close();
-        xpcCleanupWindows();
+  await waitForFinishedFrames(1);
+  isInaccessible(window2, "Should be able to navigate off-domain top by submitting form.");
+  window2.close();
+  await cleanupWindows();
 
-        let window3 = window.open("iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_top,hyperlink", "_blank", "width=10,height=10");
+  let window3 = window.open("iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_top,hyperlink", "_blank", "width=10,height=10");
 
-        xpcWaitForFinishedFrames(function() {
-          isInaccessible(window3, "Should be able to navigate off-domain top by targeted hyperlink.");
-          window3.close();
-          xpcCleanupWindows();
+  await waitForFinishedFrames(1);
+  isInaccessible(window3, "Should be able to navigate off-domain top by targeted hyperlink.");
+  window3.close();
+  await cleanupWindows();
 
-          testParent();
-        }, 1);
-      }, 1);
-    }, 1);
-  }, 1);
+  await testParent();
 }
 
-function testParent() {
+async function testParent() {
   document.getElementById("frames").innerHTML = '<iframe src="iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#parent,location"></iframe>';
 
-  xpcWaitForFinishedFrames(function() {
-    isAccessible(frames[0], "Should not be able to navigate off-domain parent by setting location.");
-    xpcCleanupWindows();
+  await waitForFinishedFrames(1);
+  isAccessible(frames[0], "Should not be able to navigate off-domain parent by setting location.");
+  await cleanupWindows();
 
-    document.getElementById("frames").innerHTML = '<iframe src="iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_parent,open"></iframe>';
+  document.getElementById("frames").innerHTML = '<iframe src="iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_parent,open"></iframe>';
 
-    xpcWaitForFinishedFrames(function() {
-      isAccessible(frames[0], "Should not be able to navigate off-domain parent by calling window.open.");
-      xpcCleanupWindows();
+  await waitForFinishedFrames(1);
+  isAccessible(frames[0], "Should not be able to navigate off-domain parent by calling window.open.");
+  await cleanupWindows();
 
-      document.getElementById("frames").innerHTML = '<iframe src="iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_parent,form"></iframe>';
+  document.getElementById("frames").innerHTML = '<iframe src="iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_parent,form"></iframe>';
 
-      xpcWaitForFinishedFrames(function() {
-        isAccessible(frames[0], "Should not be able to navigate off-domain parent by submitting form.");
-        xpcCleanupWindows();
+  await waitForFinishedFrames(1);
+  isAccessible(frames[0], "Should not be able to navigate off-domain parent by submitting form.");
+  await cleanupWindows();
 
-        document.getElementById("frames").innerHTML = '<iframe src="iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_parent,hyperlink"></iframe>';
+  document.getElementById("frames").innerHTML = '<iframe src="iframe.html#http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#_parent,hyperlink"></iframe>';
 
-        xpcWaitForFinishedFrames(function() {
-          isAccessible(frames[0], "Should not be able to navigate off-domain parent by targeted hyperlink.");
-          xpcCleanupWindows();
+  await waitForFinishedFrames(1);
+  isAccessible(frames[0], "Should not be able to navigate off-domain parent by targeted hyperlink.");
+  await cleanupWindows();
 
-          document.getElementById("frames").innerHTML = "";
-          SimpleTest.finish();
-        }, 1);
-      }, 1);
-    }, 1);
-  }, 1);
+  document.getElementById("frames").innerHTML = "";
+  SimpleTest.finish();
 }
 
-window.onload = function() {
-  testTop();
+window.onload = async function() {
+  await testTop();
 };
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 </div>
 <pre id="test">
--- a/docshell/test/navigation/test_sibling-matching-parent.html
+++ b/docshell/test/navigation/test_sibling-matching-parent.html
@@ -1,15 +1,15 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 window.onload = async function() {
   document.getElementById("active").innerHTML =
       '<iframe src="navigate.html#parent.frames[0],location"></iframe>' +
       '<iframe src="navigate.html#child1,open"></iframe>' +
@@ -18,17 +18,17 @@ window.onload = async function() {
 
   await waitForFinishedFrames(4);
 
   await isNavigated(frames[0], "Should be able to navigate sibling with on-domain parent by setting location.");
   await isNavigated(frames[1], "Should be able to navigate sibling with on-domain parent by calling window.open.");
   await isNavigated(frames[2], "Should be able to navigate sibling with on-domain parent by submitting form.");
   await isNavigated(frames[3], "Should be able to navigate sibling with on-domain parent by targeted hyperlink.");
 
-  xpcCleanupWindows();
+  await cleanupWindows();
   SimpleTest.finish();
 };
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 <iframe name="child0" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
--- a/docshell/test/navigation/test_sibling-off-domain.html
+++ b/docshell/test/navigation/test_sibling-off-domain.html
@@ -1,15 +1,15 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <script src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script type="text/javascript" src="NavigationUtils.js"></script>        
+    <script type="text/javascript" src="NavigationUtils.js"></script>
     <style type="text/css">
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 window.onload = async function() {
   document.getElementById("active").innerHTML =
       '<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#parent.frames[0],location"></iframe>' +
       '<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#child1,open"></iframe>' +
@@ -18,17 +18,17 @@ window.onload = async function() {
 
   await waitForFinishedFrames(4);
 
   isBlank(frames[0], "Should not be able to navigate off-domain sibling by setting location.");
   isBlank(frames[1], "Should not be able to navigate off-domain sibling by calling window.open.");
   isBlank(frames[2], "Should not be able to navigate off-domain sibling by submitting form.");
   isBlank(frames[3], "Should not be able to navigate off-domain sibling by targeted hyperlink.");
 
-  xpcCleanupWindows();
+  await cleanupWindows();
   SimpleTest.finish();
 };
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 <iframe name="child0" src="blank.html"></iframe>