Bug 1353910 - Fix browser_webrtc_hooks.js. r=florian draft
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 06 Apr 2017 15:56:25 -0400
changeset 557435 322d3ca8979954ea6f03a4bf5363fed821f572c4
parent 557434 a6080d91425a0f6810e3a8833ff9a6457ad2ad00
child 558418 6f9b197f68af3b7f7ade953299f46dd3ece3073d
push id52720
push userbmo:mrbkap@mozilla.com
push dateThu, 06 Apr 2017 20:12:02 +0000
reviewersflorian
bugs1353910
milestone55.0a1
Bug 1353910 - Fix browser_webrtc_hooks.js. r=florian MozReview-Commit-ID: KPCTaQzoQfK
browser/base/content/test/webrtc/browser_webrtc_hooks.js
browser/base/content/test/webrtc/head.js
--- a/browser/base/content/test/webrtc/browser_webrtc_hooks.js
+++ b/browser/base/content/test/webrtc/browser_webrtc_hooks.js
@@ -1,20 +1,16 @@
 /* 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/. */
 
 Cu.import("resource:///modules/webrtcUI.jsm");
 
 const ORIGIN = "https://example.com";
 
-registerCleanupFunction(function() {
-  gBrowser.removeCurrentTab();
-});
-
 function* tryPeerConnection(browser, expectedError = null) {
   let errtype = yield ContentTask.spawn(browser, null, function*() {
     let pc = new content.RTCPeerConnection();
     try {
       yield pc.createOffer({offerToReceiveAudio: true});
       return null;
     } catch (err) {
       return err.name;
@@ -321,41 +317,18 @@ var gTests = [
       isnot(details.callID, undefined, "peer-request-cancel event includes callID");
       is(details.origin, ORIGIN, "peer-request-cancel event has correct origin");
 
       webrtcUI.removePeerConnectionBlocker(blocker);
     },
   },
 ];
 
-function test() {
-  waitForExplicitFinish();
-
-  let tab = gBrowser.addTab();
-  gBrowser.selectedTab = tab;
-  let browser = tab.linkedBrowser;
-
-  browser.addEventListener("load", function() {
-    is(PopupNotifications._currentNotifications.length, 0,
-       "should start the test without any prior popup notification");
-    ok(gIdentityHandler._identityPopup.hidden,
-       "should start the test with the control center hidden");
-
-    Task.spawn(function* () {
-      yield SpecialPowers.pushPrefEnv({"set": [[PREF_PERMISSION_FAKE, true]]});
-
-      for (let testCase of gTests) {
-        info(testCase.desc);
-        yield testCase.run(browser);
-
-        // Make sure the test cleaned up after itself.
-        is(webrtcUI.peerConnectionBlockers.size, 0, "Peer connection blockers list is empty");
-      }
-    }).then(finish, ex => {
-     Cu.reportError(ex);
-     ok(false, "Unexpected Exception: " + ex);
-     finish();
-    });
-  }, {capture: true, once: true});
+add_task(async function test() {
   let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content", ORIGIN);
-  content.location = rootDir + "get_user_media.html";
-}
+  rootDir = rootDir.replace("chrome://mochitests/content",
+                            ORIGIN);
+  await runTests(gTests, rootDir + "get_user_media.html",
+                 () => {
+                   is(webrtcUI.peerConnectionBlockers.size, 0,
+                      "Peer connection blockers list is empty");
+                 });
+});
--- a/browser/base/content/test/webrtc/head.js
+++ b/browser/base/content/test/webrtc/head.js
@@ -533,15 +533,15 @@ async function runTests(tests, page, tes
          "should start the test without any prior popup notification");
       ok(gIdentityHandler._identityPopup.hidden,
          "should start the test with the control center hidden");
 
       yield SpecialPowers.pushPrefEnv({"set": [[PREF_PERMISSION_FAKE, true]]});
 
       for (let testCase of tests) {
         info(testCase.desc);
-        yield testCase.run();
+        yield testCase.run(browser);
         if (testCleanup) {
           yield testCleanup();
         }
       }
     });
 }