Bug 1353910 - Wait for the tab switch (and deduplicate code) in browser_devices_get_user_media_in_frame.js. r=florian draft
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 06 Apr 2017 11:49:48 -0700
changeset 557428 8ddfa8a22bee00da50b030898bdeb1f454321ec6
parent 557427 982484cdc9da9738048a0084b6077e23b6f46eb2
child 557429 e31b4742f1760d7a02c17e0bc937aa5d97fa09d8
push id52720
push userbmo:mrbkap@mozilla.com
push dateThu, 06 Apr 2017 20:12:02 +0000
reviewersflorian
bugs1353910
milestone55.0a1
Bug 1353910 - Wait for the tab switch (and deduplicate code) in browser_devices_get_user_media_in_frame.js. r=florian MozReview-Commit-ID: ALT3yFNwXAk
browser/base/content/test/webrtc/browser_devices_get_user_media.js
browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js
browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js
browser/base/content/test/webrtc/head.js
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media.js
@@ -570,11 +570,15 @@ var gTests = [
   run: function* checkInitAndUninit() {
     webrtcUI.uninit();
     webrtcUI.init();
   }
 }
 
 ];
 
-function test() {
-  await runTests(gTests, "get_user_media.html");
-}
+add_task(async function test() {
+  let rootDir = getRootDirectory(gTestPath);
+  rootDir = rootDir.replace("chrome://mochitests/content/",
+                            "https://example.com/");
+
+  await runTests(gTests, rootDir + "get_user_media.html");
+});
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js
@@ -68,10 +68,14 @@ var gTests = [
     yield getStreamAndCheckBackgroundAnim(false, true, "camera");
     yield getStreamAndCheckBackgroundAnim(true, false, "microphone");
   }
 }
 
 ];
 
 add_task(async function test() {
-  await runTests(gTests, "get_user_media.html");
+  let rootDir = getRootDirectory(gTestPath);
+  rootDir = rootDir.replace("chrome://mochitests/content/",
+                            "https://example.com/");
+
+  await runTests(gTests, rootDir + "get_user_media.html");
 });
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.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 audio+video",
   run: function* checkAudioVideo() {
     let promise = promisePopupNotificationShown("webRTC-shareDevices");
     yield promiseRequestDevice(true, true, "frame1");
     yield promise;
@@ -211,43 +207,17 @@ var gTests = [
     yield checkSharingUI({video: true, audio: true});
 
     yield reloadAndAssertClosedStreams();
   }
 }
 
 ];
 
-function test() {
-  waitForExplicitFinish();
-
-  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");
-
-    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});
+add_task(async function test() {
   let rootDir = getRootDirectory(gTestPath);
   rootDir = rootDir.replace("chrome://mochitests/content/",
                             "https://example.com/");
   let url = rootDir + "get_user_media.html";
-  content.location = 'data:text/html,<iframe id="frame1" src="' + url + '"></iframe><iframe id="frame2" src="' + url + '"></iframe>'
-}
+  let testUrl = `data:text/html,<iframe id="frame1" src="${url}"></iframe><iframe id="frame2" src="${url}"></iframe>`
+
+  await runTests(gTests, testUrl, () => expectNoObserverCalled());
+});
--- a/browser/base/content/test/webrtc/head.js
+++ b/browser/base/content/test/webrtc/head.js
@@ -516,33 +516,32 @@ function promiseReloadFrame(aFrameId) {
            .document
            .getElementById(contentFrameId)
            .contentWindow
            .location
            .reload();
   });
 }
 
-async function runTests(tests, page) {
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-
+async function runTests(tests, page, testCleanup = null) {
   await BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
     function* (browser) {
       browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
 
-      BrowserTestUtils.loadURI(browser, rootDir + page);
+      BrowserTestUtils.loadURI(browser, page);
       yield BrowserTestUtils.browserLoaded(browser);
 
       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");
 
       yield SpecialPowers.pushPrefEnv({"set": [[PREF_PERMISSION_FAKE, true]]});
 
       for (let testCase of tests) {
         info(testCase.desc);
         yield testCase.run();
+        if (testCleanup) {
+          yield testCleanup();
+        }
       }
     });
 }