Bug 1546737 - Don't use the hidden window in browser_xhr_sandbox.js. r=Gijs
authorFelipe Gomes <felipc@gmail.com>
Wed, 24 Apr 2019 22:43:04 +0000
changeset 530035 4e06efa9d48ede0a40fdbb321c870986e72a0cae
parent 530034 f9ccfa09fb6d69c35ddeeaf8984c044e8731ca2a
child 530036 eda47278259fdd88b27f573b1d848435f7acc4b4
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1546737
milestone68.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 1546737 - Don't use the hidden window in browser_xhr_sandbox.js. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D28710
dom/tests/browser/browser_xhr_sandbox.js
--- a/dom/tests/browser/browser_xhr_sandbox.js
+++ b/dom/tests/browser/browser_xhr_sandbox.js
@@ -16,34 +16,32 @@ var sandboxCode = (function() {
         result = "ok";
       }
       postMessage({result}, "*");
     }
   };
   req.send(null);
 }).toSource() + "();";
 
-function test() {
-  waitForExplicitFinish();
-  let appShell = Services.appShell;
-  let doc = appShell.hiddenDOMWindow.document;
-  let frame = doc.createElement("iframe");
+add_task(async function test() {
+  let newWin = await BrowserTestUtils.openNewBrowserWindow();
+
+  let frame = newWin.document.createElement("iframe");
   frame.setAttribute("type", "content");
   frame.setAttribute("src", "http://mochi.test:8888/browser/dom/tests/browser/browser_xhr_sandbox.js");
 
-  frame.addEventListener("load", function() {
-    let workerWindow = frame.contentWindow;
-    workerWindow.addEventListener("message", function(evt) {
-      is(evt.data.result, "ok", "check the sandbox code was happy");
-      frame.remove();
-      finish();
-    }, true);
-    let sandbox = new Cu.Sandbox(workerWindow);
-    // inject some functions from the window into the sandbox.
-    // postMessage so the async code in the sandbox can report a result.
-    sandbox.importFunction(workerWindow.postMessage.bind(workerWindow), "postMessage");
-    sandbox.importFunction(workerWindow.XMLHttpRequest, "XMLHttpRequest");
-    Cu.evalInSandbox(sandboxCode, sandbox, "1.8");
-  }, true);
+  newWin.document.documentElement.appendChild(frame);
+  await BrowserTestUtils.waitForEvent(frame, "load", true);
+
+  let contentWindow = frame.contentWindow;
+  let sandbox = new Cu.Sandbox(contentWindow);
 
-  let container = doc.body ? doc.body : doc.documentElement;
-  container.appendChild(frame);
-}
+  // inject some functions from the window into the sandbox.
+  // postMessage so the async code in the sandbox can report a result.
+  sandbox.importFunction(contentWindow.postMessage.bind(contentWindow), "postMessage");
+  sandbox.importFunction(contentWindow.XMLHttpRequest, "XMLHttpRequest");
+  Cu.evalInSandbox(sandboxCode, sandbox, "1.8");
+
+  let sandboxReply = await BrowserTestUtils.waitForEvent(contentWindow, "message", true);
+  is(sandboxReply.data.result, "ok", "check the sandbox code was felipe");
+
+  await BrowserTestUtils.closeWindow(newWin);
+});