--- a/browser/base/content/test/webrtc/browser_devices_get_user_media.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media.js
@@ -1,18 +1,14 @@
/* 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/. */
requestLongerTimeout(2);
-registerCleanupFunction(function() {
- gBrowser.removeCurrentTab();
-});
-
const permissionError = "error: NotAllowedError: The request is not allowed " +
"by the user agent or the platform in the current context.";
var gTests = [
{
desc: "getUserMedia audio+video",
run: function* checkAudioVideo() {
@@ -574,44 +570,11 @@ var gTests = [
run: function* checkInitAndUninit() {
webrtcUI.uninit();
webrtcUI.init();
}
}
];
-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");
- 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";
-}
+add_task(async function test() {
+ await runTests(gTests);
+});
--- 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
@@ -1,15 +1,11 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
-registerCleanupFunction(function() {
- gBrowser.removeCurrentTab();
-});
-
var gTests = [
{
desc: "device sharing animation on background tabs",
run: function* checkAudioVideo() {
function* getStreamAndCheckBackgroundAnim(aAudio, aVideo, aSharing) {
// Get a stream
let popupPromise = promisePopupNotificationShown("webRTC-shareDevices");
@@ -71,39 +67,11 @@ var gTests = [
yield getStreamAndCheckBackgroundAnim(true, true, "camera");
yield getStreamAndCheckBackgroundAnim(false, true, "camera");
yield getStreamAndCheckBackgroundAnim(true, false, "microphone");
}
}
];
-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();
- }
- }).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";
-}
+add_task(async function test() {
+ await runTests(gTests);
+});
--- 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,11 @@ 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});
- 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>'
-}
+add_task(async function test() {
+ await runTests(gTests, { relativeURI: "get_user_media_in_frame.html" });
+});
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.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 in a first process + video in a second process",
run: function* checkMultiProcess() {
// The main purpose of this test is to ensure webrtc sharing indicators
// work with multiple content processes, but it makes sense to run this
// test without e10s too to ensure using webrtc devices in two different
@@ -113,41 +109,11 @@ var gTests = [
ok(!webrtcUI.showGlobalIndicator, "webrtcUI wants the global indicator hidden");
is(webrtcUI.getActiveStreams(true, true, true).length, 0, "0 active streams");
}
},
];
-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");
- 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();
- }
- }).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";
-}
+add_task(async function test() {
+ await runTests(gTests);
+});
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_screen.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_screen.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();
-});
-
const permissionError = "error: NotAllowedError: The request is not allowed " +
"by the user agent or the platform in the current context.";
const notFoundError =
"error: NotFoundError: The object can not be found here.";
var gTests = [
@@ -572,44 +568,11 @@ var gTests = [
yield expectObserverCalled("getUserMedia:response:deny");
yield expectObserverCalled("recording-window-ended");
SitePermissions.remove(uri, "screen", browser);
}
}
];
-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");
- 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";
-}
+add_task(async function test() {
+ await runTests(gTests);
+});
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_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 keeps sharing indicators",
run: function* checkTearingOff() {
let promise = promisePopupNotificationShown("webRTC-shareDevices");
yield promiseRequestDevice(true, true);
yield promise;
@@ -57,51 +53,17 @@ var gTests = [
yield expectNoObserverCalled();
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";
-}
+ await runTests(gTests);
+});
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access.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();
-});
-
const permissionError = "error: NotAllowedError: The request is not allowed " +
"by the user agent or the platform in the current context.";
var gTests = [
{
desc: "getUserMedia audio+camera",
run: function* checkAudioVideoWhileLiveTracksExist_audio_camera() {
@@ -246,44 +242,11 @@ var gTests = [
// close all streams
yield closeStream(false, 0, 2);
}
}
];
-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");
- 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";
-}
+add_task(async function test() {
+ await runTests(gTests);
+});
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_in_frame.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_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();
-});
-
const permissionError = "error: NotAllowedError: The request is not allowed " +
"by the user agent or the platform in the current context.";
var gTests = [
{
desc: "getUserMedia audio+camera in frame 1",
run: function* checkAudioVideoWhileLiveTracksExist_frame() {
@@ -205,42 +201,11 @@ var gTests = [
SitePermissions.remove(null, "screen", gBrowser.selectedBrowser);
SitePermissions.remove(null, "camera", gBrowser.selectedBrowser);
SitePermissions.remove(null, "microphone", gBrowser.selectedBrowser);
}
}
];
-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});
- let rootDir = getRootDirectory(gTestPath);
- rootDir = rootDir.replace("chrome://mochitests/content/",
- "https://example.com/");
- content.location = rootDir + "get_user_media_in_frame.html";
-}
+add_task(async function test() {
+ await runTests(gTests, { relativeURI: "get_user_media_in_frame.html" });
+});
--- 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,17 @@ 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";
-}
+ await runTests(gTests);
+});
--- 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,16 @@ 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});
- let rootDir = getRootDirectory(gTestPath);
- rootDir = rootDir.replace("chrome://mochitests/content", ORIGIN);
- content.location = rootDir + "get_user_media.html";
-}
+add_task(async function test() {
+ await runTests(gTests,
+ { cleanup() {
+ 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
@@ -515,8 +515,39 @@ function promiseReloadFrame(aFrameId) {
content.wrappedJSObject
.document
.getElementById(contentFrameId)
.contentWindow
.location
.reload();
});
}
+
+async function runTests(tests, options = {}) {
+ let leaf = options.relativeURI || "get_user_media.html";
+
+ let rootDir = getRootDirectory(gTestPath);
+ rootDir = rootDir.replace("chrome://mochitests/content/",
+ "https://example.com/");
+ let absoluteURI = rootDir + leaf;
+ let cleanup = options.cleanup || (() => expectNoObserverCalled());
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, absoluteURI);
+ let browser = tab.linkedBrowser;
+
+ browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
+
+ 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");
+
+ await SpecialPowers.pushPrefEnv({"set": [[PREF_PERMISSION_FAKE, true]]});
+
+ for (let testCase of tests) {
+ info(testCase.desc);
+ await Task.spawn(testCase.run(browser));
+ await cleanup();
+ }
+
+ // Some tests destroy the original tab and leave a new one in its place.
+ await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+}