Bug 1353910 - Fix browser_devices_get_user_media_unprompted_access_tear_off_tab.js. r=florian draft
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 06 Apr 2017 15:46:23 -0400
changeset 557434 a6080d91425a0f6810e3a8833ff9a6457ad2ad00
parent 557433 d04cf5f70575a943c26e38f37f98da46a9690563
child 557435 322d3ca8979954ea6f03a4bf5363fed821f572c4
push id52720
push userbmo:mrbkap@mozilla.com
push dateThu, 06 Apr 2017 20:12:02 +0000
reviewersflorian
bugs1353910
milestone55.0a1
Bug 1353910 - Fix browser_devices_get_user_media_unprompted_access_tear_off_tab.js. r=florian MozReview-Commit-ID: G4JGBlCUTxX
browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_tear_off_tab.js
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_tear_off_tab.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_tear_off_tab.js
@@ -1,16 +1,12 @@
 /* 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/. */
 
-registerCleanupFunction(function() {
-  gBrowser.removeCurrentTab();
-});
-
 var gTests = [
 
 {
   desc: "getUserMedia: tearing-off a tab",
   run: function* checkAudioVideoWhileLiveTracksExist_TearingOff() {
     let promise = promisePopupNotificationShown("webRTC-shareDevices");
     yield promiseRequestDevice(true, true);
     yield promise;
@@ -51,51 +47,25 @@ var gTests = [
     yield Promise.all(promises);
 
     yield checkNotSharing();
   }
 }
 
 ];
 
-function test() {
-  waitForExplicitFinish();
-  SpecialPowers.pushPrefEnv({"set": [["dom.ipc.processCount", 1]]}, runTest);
-}
+add_task(async function test() {
+  await SpecialPowers.pushPrefEnv({"set": [["dom.ipc.processCount", 1]]});
 
-function runTest() {
   // An empty tab where we can load the content script without leaving it
   // behind at the end of the test.
-  gBrowser.addTab();
-
   let tab = gBrowser.addTab();
-  gBrowser.selectedTab = tab;
-  let browser = tab.linkedBrowser;
-
-  browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
-
-  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();
-
-        // Cleanup before the next test
-        yield expectNoObserverCalled();
-      }
-    }).then(finish, ex => {
-     Cu.reportError(ex);
-     ok(false, "Unexpected Exception: " + ex);
-     finish();
-    });
-  }, {capture: true, once: true});
   let rootDir = getRootDirectory(gTestPath);
   rootDir = rootDir.replace("chrome://mochitests/content/",
                             "https://example.com/");
-  content.location = rootDir + "get_user_media.html";
-}
+
+  // NB: This causes withNewTab to warn that we already closed the tab. That
+  // doesn't cause the test to fail, so that's OK.
+  await runTests(gTests, rootDir + "get_user_media.html", () => expectNoObserverCalled());
+
+  await BrowserTestUtils.removeTab(tab);
+});