Bug 1304531 - Remove CPOW usage from browser_ua_emulation.js. r=Felipe, a=test-only
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 20 Sep 2016 17:19:34 -0700
changeset 355926 4ec7f48bd14fc2cfa456d552917a25563c21b0db
parent 355925 cc34bcf6b29d57392c073e8078c7fce42acb3976
child 355927 f8124f7149a65d2573c8a94dfd959b0fcd0521f5
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, test-only
bugs1304531
milestone51.0a2
Bug 1304531 - Remove CPOW usage from browser_ua_emulation.js. r=Felipe, a=test-only MozReview-Commit-ID: 4RnoWuVogCT
docshell/test/browser/browser_ua_emulation.js
--- a/docshell/test/browser/browser_ua_emulation.js
+++ b/docshell/test/browser/browser_ua_emulation.js
@@ -1,52 +1,36 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-// Test that the docShell UA emulation works
-add_task(function*() {
-  yield openUrl("data:text/html;charset=utf-8,<iframe id='test-iframe'></iframe>");
+const URL = "data:text/html;charset=utf-8,<iframe id='test-iframe'></iframe>";
 
-  let docshell = content.QueryInterface(Ci.nsIInterfaceRequestor)
-                        .getInterface(Ci.nsIWebNavigation)
-                        .QueryInterface(Ci.nsIDocShell);
+// Test that the docShell UA emulation works
+function* contentTask() {
+  let docshell = docShell;
   is(docshell.customUserAgent, "", "There should initially be no customUserAgent");
 
   docshell.customUserAgent = "foo";
   is(content.navigator.userAgent, "foo", "The user agent should be changed to foo");
 
   let frameWin = content.document.querySelector("#test-iframe").contentWindow;
   is(frameWin.navigator.userAgent, "foo", "The UA should be passed on to frames.");
 
   let newFrame = content.document.createElement("iframe");
   content.document.body.appendChild(newFrame);
 
   let newFrameWin = newFrame.contentWindow;
   is(newFrameWin.navigator.userAgent, "foo", "Newly created frames should use the new UA");
 
   newFrameWin.location.reload();
-  yield waitForEvent(newFrameWin, "load");
+  yield ContentTaskUtils.waitForEvent(newFrameWin, "load");
 
   is(newFrameWin.navigator.userAgent, "foo", "New UA should persist across reloads");
-  gBrowser.removeCurrentTab();
-});
-
-function waitForEvent(target, event) {
-  return new Promise(function(resolve) {
-    target.addEventListener(event, resolve);
-  });
 }
 
-function openUrl(url) {
-  return new Promise(function(resolve, reject) {
-    window.focus();
-
-    let tab = window.gBrowser.selectedTab = window.gBrowser.addTab(url);
-    let linkedBrowser = tab.linkedBrowser;
-
-    linkedBrowser.addEventListener("load", function onload() {
-      linkedBrowser.removeEventListener("load", onload, true);
-      resolve(tab);
-    }, true);
-  });
-}
+add_task(function* () {
+  yield BrowserTestUtils.withNewTab({ gBrowser, url: URL },
+    function* (browser) {
+      yield ContentTask.spawn(browser, null, contentTask);
+    });
+});