Bug 1299515 - Put pushPrefs in head.js. r?jib
MozReview-Commit-ID: F770g5cjH0k
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -370,16 +370,20 @@ function getUserMedia(constraints) {
.then(stream => (checkMediaStreamTracks(constraints, stream), stream));
}
// These are the promises we use to track that the prerequisites for the test
// are in place before running it.
var setTestOptions;
var testConfigured = new Promise(r => setTestOptions = r);
+function pushPrefs(...p) {
+ return SpecialPowers.pushPrefEnv({set: p});
+}
+
function setupEnvironment() {
if (!window.SimpleTest) {
// Running under Steeplechase
return;
}
var defaultMochitestPrefs = {
'set': [
--- a/dom/media/tests/mochitest/mediaStreamPlayback.js
+++ b/dom/media/tests/mochitest/mediaStreamPlayback.js
@@ -225,18 +225,16 @@ var scriptsReady = Promise.all([
document.head.appendChild(el);
return new Promise(r => el.onload = r);
}));
function createHTML(options) {
return scriptsReady.then(() => realCreateHTML(options));
}
-var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
// noGum - Helper to detect whether active guM tracks still exist.
//
// It relies on the fact that, by spec, device labels from enumerateDevices are
// only visible during active gum calls. They're also visible when persistent
// permissions are granted, so turn off media.navigator.permission.disabled
// (which is normally on otherwise in our tests). Lastly, we must turn on
// media.navigator.permission.fake otherwise fake devices don't count as active.
--- a/dom/media/tests/mochitest/test_enumerateDevices.html
+++ b/dom/media/tests/mochitest/test_enumerateDevices.html
@@ -27,17 +27,16 @@ async function mustFailWith(msg, reason,
} catch(e) {
is(e.name, reason, msg + " must fail: " + e.message);
if (constraint) {
is(e.constraint, constraint, msg + " must fail w/correct constraint.");
}
}
}
-var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
var gUM = c => navigator.mediaDevices.getUserMedia(c);
var validateDevice = ({kind, label, deviceId, groupId}) => {
ok(kind == "videoinput" || kind == "audioinput", "Known device kind");
is(deviceId.length, 44, "deviceId length id as expected for Firefox");
ok(label.length !== undefined, "Device label: " + label);
// TODO: s/todo_// once Bug 1213453 is fixed.
--- a/dom/media/tests/mochitest/test_getUserMedia_basicTabshare.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_basicTabshare.html
@@ -18,17 +18,16 @@
*/
runTest(function () {
const isWinXP = navigator.userAgent.indexOf("Windows NT 5.1") != -1;
if (IsMacOSX10_6orOlder() || isWinXP) {
ok(true, "Screensharing disabled for OSX10.6 and WinXP");
return;
}
var testVideo = createMediaElement('video', 'testVideo');
- var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
return Promise.resolve()
.then(() => pushPrefs(["media.getusermedia.browser.enabled", true]))
.then(() => getUserMedia({
video: { mediaSource: "browser",
scrollWithPage: true },
fake: false
}))
--- a/dom/media/tests/mochitest/test_ondevicechange.html
+++ b/dom/media/tests/mochitest/test_ondevicechange.html
@@ -1,29 +1,25 @@
<!DOCTYPE HTML>
<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=1041393
--->
<head>
<meta charset="utf-8">
- <title>onndevicechange tests</title>
- <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
- <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="mediaStreamPlayback.js"></script>
</head>
<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1152383">ondevicechange tests</a>
<script type="application/javascript">
+"use strict";
+
+createHTML({
+ title: "ondevicechange tests",
+ bug: "1152383"
+});
const RESPONSE_WAIT_TIME_MS = 10000;
-function wait(time, message) {
- return new Promise(r => setTimeout(() => r(message), time));
-}
-
function OnDeviceChangeEvent() {
return new Promise(resolve => navigator.mediaDevices.ondevicechange = resolve);
}
function OnDeviceChangeEventReceived() {
return Promise.race([
OnDeviceChangeEvent(),
wait(RESPONSE_WAIT_TIME_MS).then(() => Promise.reject("Timed out while waiting for devicechange event"))
@@ -32,49 +28,37 @@ function OnDeviceChangeEventReceived() {
function OnDeviceChangeEventNotReceived() {
return Promise.race([
OnDeviceChangeEvent().then(() => Promise.reject("ondevicechange event is fired unexpectedly.")),
wait(RESPONSE_WAIT_TIME_MS)
]);
}
-var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
-var videoTracks;
+runTest(async () => {
+ SimpleTest.requestCompleteLog();
-SimpleTest.requestCompleteLog();
-SimpleTest.waitForExplicitFinish();
-SimpleTest.requestFlakyTimeout("Fake devicechange event is fired periodically, \
-so we need to wait a while to make sure the event is fired or not as we expect.");
+ await pushPrefs(["media.ondevicechange.fakeDeviceChangeEvent.enabled", true]);
+ await pushPrefs(["media.navigator.permission.disabled", false]);
+ await pushPrefs(["media.ondevicechange.enabled", true]);
-var videoTracks;
-
-function wait(time, message) {
- return new Promise(r => setTimeout(() => r(message), time));
-}
+ info("assure devicechange event is NOT fired when gUM is NOT in use and permanent permission is NOT granted");
+ await OnDeviceChangeEventNotReceived();
+ ok(true, "devicechange event is NOT fired when gUM is NOT in use and permanent permission is NOT granted");
-pushPrefs(["media.ondevicechange.fakeDeviceChangeEvent.enabled", true])
-.then(() => pushPrefs(["media.navigator.permission.disabled", false]))
-.then(() => pushPrefs(["media.ondevicechange.enabled", true]))
-.then(() => info("assure devicechange event is NOT fired when gUM is NOT in use and permanent permission is NOT granted"))
-.then(() => OnDeviceChangeEventNotReceived())
-.then(() => ok(true, "devicechange event is NOT fired when gUM is NOT in use and permanent permission is NOT granted"))
-.then(() => pushPrefs(['media.navigator.permission.disabled', true]))
-.then(() => info("assure devicechange event is fired when gUM is NOT in use and permanent permission is granted"))
-.then(() => OnDeviceChangeEventReceived())
-.then(() => ok(true, "devicechange event is fired when gUM is NOT in use and permanent permission is granted"))
-.then(() => navigator.mediaDevices.getUserMedia({video: true, fake: true}))
-.then(st => {videoTracks = st.getVideoTracks();})
-.then(() => info("assure devicechange event is fired when gUM is in use"))
-.then(() => OnDeviceChangeEventReceived())
-.then(() => ok(true, "devicechange event is fired when gUM is in use"))
-.catch(e => ok(false, "Error: " + e))
-.then(() => {
- if(videoTracks)
- videoTracks.forEach(track => track.stop());
-})
-.then(() => SimpleTest.finish());
+ await pushPrefs(['media.navigator.permission.disabled', true]);
+
+ info("assure devicechange event is fired when gUM is NOT in use and permanent permission is granted");
+ await OnDeviceChangeEventReceived();
+ ok(true, "devicechange event is fired when gUM is NOT in use and permanent permission is granted");
+ let st = await getUserMedia({video: true, fake: true});
+ let videoTracks = st.getVideoTracks();
+
+ info("assure devicechange event is fired when gUM is in use");
+ await OnDeviceChangeEventReceived();
+ ok(true, "devicechange event is fired when gUM is in use");
+ videoTracks.forEach(track => track.stop());
+});
</script>
</pre>
</body>
</html>
--- a/dom/media/tests/mochitest/test_peerConnection_insertDTMF.html
+++ b/dom/media/tests/mochitest/test_peerConnection_insertDTMF.html
@@ -61,18 +61,16 @@ runNetworkTest(() => {
test.chain.append([
function PC_LOCAL_INSERT_DTMF(test) {
// We want to call removeTrack
test.pcLocal.expectNegotiationNeeded();
return insertdtmftest(test.pcLocal._pc);
}
]);
- var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
return pushPrefs(['media.peerconnection.dtmf.enabled', true])
.then(() => { test.run() })
.catch(e => ok(false, "unexpected failure: " + e));
});
</script>
</pre>
</body>
--- a/dom/media/tests/mochitest/test_peerConnection_maxFsConstraint.html
+++ b/dom/media/tests/mochitest/test_peerConnection_maxFsConstraint.html
@@ -7,18 +7,16 @@
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "1393687",
title: "Enforce max-fs constraint on a PeerConnection",
visible: true
});
- const pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
var mustRejectWith = (msg, reason, f) =>
f().then(() => ok(false, msg),
e => is(e.name, reason, msg));
var removeAllButCodec = (d, codec) =>
(d.sdp = d.sdp.replace(/m=video (\w) UDP\/TLS\/RTP\/SAVPF \w.*\r\n/,
"m=video $1 UDP/TLS/RTP/SAVPF " + codec + "\r\n"), d);
@@ -76,21 +74,21 @@
is(v2.videoHeight, 120, "sink height should be 120 for " + codec);
}})
.then(() => {
stream.getTracks().forEach(track => track.stop());
v1.srcObject = v2.srcObject = null;
}).catch(generateErrorCallback());
}
- pushPrefs(['media.peerconnection.video.lock_scaling', true]).then(() => {
+ runNetworkTest(async () => {
+ await pushPrefs(['media.peerconnection.video.lock_scaling', true]);
+ await testScale("VP8");
if (!navigator.appVersion.includes("Android")) {
- runNetworkTest(() => testScale("VP8").then(() => testScale("H264"))
- .then(networkTestFinished));
- } else {
// No support for H.264 on Android in automation, see Bug 1355786
- runNetworkTest(() => testScale("VP8").then(networkTestFinished));
+ await testScale("H264");
}
+ networkTestFinished();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/tests/mochitest/test_peerConnection_relayOnly.html
+++ b/dom/media/tests/mochitest/test_peerConnection_relayOnly.html
@@ -23,17 +23,16 @@ function PC_BOTH_WAIT_FOR_ICE_FAILED(tes
return Promise.all([
isFail(() => waitForIceConnected(test, test.pcLocal), "ICE failed", "Local ICE"),
isFail(() => waitForIceConnected(test, test.pcRemote), "ICE failed", "Remote ICE")
])
.then(() => ok(true, "ICE on both sides must fail."));
}
-var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
var test;
runNetworkTest(options =>
pushPrefs(['media.peerconnection.ice.stun_client_maximum_transmits', 3],
['media.peerconnection.ice.trickle_grace_period', 5000]).then(() => {
options = options || {};
options.config_local = options.config_local || {};
var servers = options.config_local.iceServers || [];
--- a/dom/media/tests/mochitest/test_peerConnection_replaceVideoThenRenegotiate.html
+++ b/dom/media/tests/mochitest/test_peerConnection_replaceVideoThenRenegotiate.html
@@ -7,18 +7,16 @@
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "1017888",
title: "Renegotiation: replaceTrack followed by adding a second video stream"
});
- const pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
runNetworkTest(function (options) {
pushPrefs(['media.peerconnection.video.min_bitrate_estimate', 180*1000]).then(() => {
const test = new PeerConnectionTest(options);
test.setMediaConstraints([{video:true}], [{video:true}]);
const helper = new VideoStreamHelper();
const emitter1 = new VideoFrameEmitter(CaptureStreamTestHelper.prototype.red,
CaptureStreamTestHelper.prototype.green);
const emitter2 = new VideoFrameEmitter(CaptureStreamTestHelper.prototype.blue,
--- a/dom/media/tests/mochitest/test_peerConnection_scaleResolution.html
+++ b/dom/media/tests/mochitest/test_peerConnection_scaleResolution.html
@@ -7,18 +7,16 @@
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "1244913",
title: "Scale resolution down on a PeerConnection",
visible: true
});
- const pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
var mustRejectWith = (msg, reason, f) =>
f().then(() => ok(false, msg),
e => is(e.name, reason, msg));
async function testScale(codec) {
var pc1 = new RTCPeerConnection();
var pc2 = new RTCPeerConnection();
@@ -74,21 +72,21 @@
is(v2.videoWidth, v1.videoWidth / 2, "sink is half the width of source");
is(v2.videoHeight, v1.videoHeight / 2, "sink is half the height of source");
stream.getTracks().forEach(track => track.stop());
v1.srcObject = v2.srcObject = null;
pc1.close()
pc2.close()
}
- pushPrefs(['media.peerconnection.video.lock_scaling', true]).then(() => {
+ runNetworkTest(async () => {
+ await pushPrefs(['media.peerconnection.video.lock_scaling', true]);
+ await testScale("VP8");
if (!navigator.appVersion.includes("Android")) {
- runNetworkTest(() => testScale("VP8").then(() => testScale("H264"))
- .then(networkTestFinished));
- } else {
// No support for H.264 on Android in automation, see Bug 1355786
- runNetworkTest(() => testScale("VP8").then(networkTestFinished));
+ await testScale("H264");
}
+ networkTestFinished();
});
</script>
</pre>
</body>
</html>
--- a/dom/media/tests/mochitest/test_peerConnection_simulcastAnswer.html
+++ b/dom/media/tests/mochitest/test_peerConnection_simulcastAnswer.html
@@ -8,18 +8,16 @@
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "1231507",
title: "Basic video-only peer connection with Simulcast answer",
visible: true
});
- const pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
function addRIDExtension(pc, extensionId) {
const receivers = pc._pc.getReceivers();
is(receivers.length, 1, "We have exactly one RTP receiver");
const receiver = receivers[0];
SpecialPowers.wrap(pc._pc).mozAddRIDExtension(receiver, extensionId);
}
--- a/dom/media/tests/mochitest/test_peerConnection_simulcastOffer.html
+++ b/dom/media/tests/mochitest/test_peerConnection_simulcastOffer.html
@@ -9,18 +9,16 @@
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "1231507",
title: "Basic video-only peer connection with Simulcast offer",
visible: true
});
- const pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
function addRIDExtension(pc, extensionId) {
const receivers = pc._pc.getReceivers();
is(receivers.length, 1, "We have exactly one RTP receiver");
const receiver = receivers[0];
SpecialPowers.wrap(pc._pc).mozAddRIDExtension(receiver, extensionId);
}