Bug 1253499 - Add mochitest for live-updating scaleResolutionDownBy. r?jib
MozReview-Commit-ID: BdWUJBMWei3
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -203,16 +203,18 @@ skip-if = toolkit == 'android' # android
skip-if = toolkit == 'android' # Bug 1189784
[test_peerConnection_syncSetDescription.html]
skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_setLocalAnswerInHaveLocalOffer.html]
[test_peerConnection_setLocalAnswerInStable.html]
[test_peerConnection_setLocalOfferInHaveRemoteOffer.html]
[test_peerConnection_setParameters.html]
skip-if = (android_version == '18') # android(Bug 1189784, timeouts on 4.3 emulator)
+[test_peerConnection_setParameters_scaleResolutionDownBy.html]
+skip-if = (android_version == '18') # android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html]
[test_peerConnection_setRemoteAnswerInStable.html]
[test_peerConnection_setRemoteOfferInHaveLocalOffer.html]
[test_peerConnection_throwInCallbacks.html]
[test_peerConnection_toJSON.html]
[test_peerConnection_trackDisabling_clones.html]
skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_trackDisabling.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_setParameters_scaleResolutionDownBy.html
@@ -0,0 +1,82 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+ createHTML({
+ bug: "1253499",
+ title: "Live-updating scaleResolutionDownBy"
+ });
+
+ let sender, localElem, remoteElem;
+ let originalWidth, originalAspectRatio, originalScale;
+
+ async function checkScaleDownBy(scale) {
+ sender.setParameters({ encodings: [{ scaleResolutionDownBy: scale }] });
+ await haveEvent(remoteElem, "resize", wait(5000, new Error("Timeout")));
+
+ is(remoteElem.videoWidth, Math.floor(originalWidth / scale),
+ "Width should have scaled down by " + scale)
+
+ // If we `originalHeight / scale` we might get a rounding error due to
+ // how we do scaling internally.
+ is(remoteElem.videoHeight, Math.floor(remoteElem.videoWidth / originalAspectRatio),
+ "Height should have scaled down by " + scale)
+ }
+
+ runNetworkTest(function (options) {
+ let test = new PeerConnectionTest(options);
+ test.setMediaConstraints([{video: true}], []);
+ test.chain.append([
+ function CHECK_PRECONDITIONS() {
+ is(test.pcLocal._pc.getSenders().length, 1,
+ "Should have 1 local sender");
+ is(test.pcLocal.localMediaElements.length, 1,
+ "Should have 1 local sending media element");
+ is(test.pcRemote.remoteMediaElements.length, 1,
+ "Should have 1 remote media element");
+
+ sender = test.pcLocal._pc.getSenders()[0];
+ if (!sender) {
+ return Promise.reject(new Error("No sender"));
+ }
+
+ localElem = test.pcLocal.localMediaElements[0];
+ if (!localElem) {
+ return Promise.reject(new Error("No local element"));
+ }
+
+ remoteElem = test.pcRemote.remoteMediaElements[0];
+ if (!remoteElem) {
+ return Promise.reject(new Error("No remote element"));
+ }
+
+ originalWidth = localElem.videoWidth;
+ originalAspectRatio = originalWidth / localElem.videoHeight;
+ originalScale = remoteElem.videoWidth / originalWidth;
+ },
+ function PC_LOCAL_SCALEDOWNBY_2() {
+ return checkScaleDownBy(2);
+ },
+ function PC_LOCAL_SCALEDOWNBY_4() {
+ return checkScaleDownBy(4);
+ },
+ function PC_LOCAL_SCALEDOWNBY_15() {
+ return checkScaleDownBy(15);
+ },
+ function PC_LOCAL_SCALEDOWNBY_8() {
+ return checkScaleDownBy(8);
+ },
+ function PC_LOCAL_SCALEDOWNBY_1() {
+ return checkScaleDownBy(1);
+ },
+ ]);
+ test.run();
+ });
+</script>
+</pre>
+</body>
+</html>