Bug 1244913 - Add test_peerConnection_scaleResolution.html r=bwc,jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Thu, 18 Feb 2016 01:18:13 -0500
changeset 321726 5a2fc31ff7897c2f87867dba09b78e1d3109438c
parent 321725 607884f102a7daaf1092ae0ad94373669d4b64e2
child 321727 f72ada9941bbfe936e1d4704e28b950200884352
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwc, jesup
bugs1244913
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1244913 - Add test_peerConnection_scaleResolution.html r=bwc,jesup MozReview-Commit-ID: 8jeVEoL5JMR
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_peerConnection_scaleResolution.html
dom/media/tests/mochitest/test_peerConnection_setParameters.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -136,16 +136,18 @@ skip-if = toolkit == 'gonk' # B2G emulat
 skip-if = toolkit == 'gonk' # B2G emulator is too slow to handle a two-way audio call reliably
 [test_peerConnection_offerRequiresReceiveAudio.html]
 [test_peerConnection_offerRequiresReceiveVideo.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_offerRequiresReceiveVideoAudio.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_promiseSendOnly.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
+[test_peerConnection_scaleResolution.html]
+skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_simulcastOffer.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version # b2g(Bug 960442, video support for WebRTC is disabled on b2g), no simulcast support on android
 #[test_peerConnection_relayOnly.html]
 #skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_callbacks.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_replaceTrack.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version == '18' # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_scaleResolution.html
@@ -0,0 +1,75 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript;version=1.8">
+  createHTML({
+    bug: "1244913",
+    title: "Scale resolution down on a PeerConnection",
+    visible: true
+  });
+
+  var pc1 = new RTCPeerConnection();
+  var pc2 = new RTCPeerConnection();
+
+  var add = (pc, can, failed) => can && pc.addIceCandidate(can).catch(failed);
+  pc1.onicecandidate = e => add(pc2, e.candidate, generateErrorCallback());
+  pc2.onicecandidate = e => add(pc1, e.candidate, generateErrorCallback());
+
+  pc1.onnegotiationneeded = e =>
+    pc1.createOffer().then(d => pc1.setLocalDescription(d))
+    .then(() => pc2.setRemoteDescription(pc1.localDescription))
+    .then(() => pc2.createAnswer()).then(d => pc2.setLocalDescription(d))
+    .then(() => pc1.setRemoteDescription(pc2.localDescription))
+    .catch(generateErrorCallback());
+
+  function mustThrowWith(msg, reason, f) {
+    try {
+      f();
+      ok(false, msg + " must throw");
+    } catch (e) {
+      is(e.name, reason, msg + " must throw: " + e.message);
+    }
+  }
+
+  var v1, v2;
+
+  runNetworkTest(function() {
+    v1 = createMediaElement('video', 'v1');
+    v2 = createMediaElement('video', 'v2');
+
+    is(v2.currentTime, 0, "v2.currentTime is zero at outset");
+
+    navigator.mediaDevices.getUserMedia({ video: true })
+    .then(stream => {
+      v1.srcObject = stream;
+      var sender = pc1.addTrack(stream.getVideoTracks()[0], stream);
+
+      mustThrowWith("scaleResolutionDownBy must be valid", "RangeError",
+        () => sender.setParameters({ encodings: [{ scaleResolutionDownBy: 0.5 } ] }));
+
+      sender.setParameters({ encodings: [{ maxBitrate: 60000,
+                                           scaleResolutionDownBy: 2 }] });
+    })
+    .then(() => new Promise(resolve => pc2.ontrack = e => resolve(e)))
+    .then(e => v2.srcObject = e.streams[0])
+    .then(() => new Promise(resolve => v2.onloadedmetadata = resolve))
+    .then(() => waitUntil(() => v2.currentTime > 0 && v2.srcObject.currentTime > 0))
+    .then(() => ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")"))
+    .then(() => wait(1000)) // TODO: Bug 1248154
+    .then(() => {
+      ok(v1.videoWidth > 0, "source width is positive");
+      ok(v1.videoHeight > 0, "source height is positive");
+      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");
+    })
+    .catch(generateErrorCallback())
+    .then(networkTestFinished);
+  });
+</script>
+</pre>
+</body>
+</html>
--- a/dom/media/tests/mochitest/test_peerConnection_setParameters.html
+++ b/dom/media/tests/mochitest/test_peerConnection_setParameters.html
@@ -17,39 +17,41 @@ function parameterstest(wrapper) {
   ok(pc.getSenders().length > 0, "have senders");
   var sender = pc.getSenders()[0];
 
   var testParameters = (params, errorName, errorMsg) => {
     var compareParameters = (a, b) => {
       var compareEncoding = (a, b) => {
         is(a.rid, b.rid || "", "same rid");
         is(a.maxBitrate, b.maxBitrate, "same maxBitrate");
+        is(a.scaleResolutionDownBy, b.scaleResolutionDownBy,
+           "same scaleResolutionDownBy");
       };
       is(a.encodings.length, (b.encodings || []).length, "same encodings");
       a.encodings.forEach((en, i) => compareEncoding(en, b.encodings[i]));
     };
     try {
       sender.setParameters(params);
       compareParameters(sender.getParameters(), params);
       is(null, errorName || null, "is success expected");
     } catch (e) {
       is(e.name, errorName, "correct error name");
       is(e.message, errorMsg, "correct error message");
     }
   };
 
   testParameters({
     encodings: [
-      { rid: "foo", maxBitrate: 40000 },
-      { rid: "bar", maxBitrate: 10000 },
+      { rid: "foo", maxBitrate: 40000, scaleResolutionDownBy: 2 },
+      { rid: "bar", maxBitrate: 10000, scaleResolutionDownBy: 4 },
     ]
   });
   testParameters({
     encodings: [
-      { maxBitrate: 10000 },
+      { maxBitrate: 10000, scaleResolutionDownBy: 4 },
     ]
   });
   testParameters({
     encodings: [
       { maxBitrate: 40000 },
       { rid: "bar", maxBitrate: 10000 },
     ]
   }, "TypeError", "Missing rid");
@@ -58,32 +60,29 @@ function parameterstest(wrapper) {
       { rid: "foo", maxBitrate: 40000 },
       { rid: "bar", maxBitrate: 10000 },
       { rid: "bar", maxBitrate: 20000 },
     ]
   }, "TypeError", "Duplicate rid");
   testParameters({});
 }
 
-var pushPrefs = (...p) => new Promise(r => SpecialPowers.pushPrefEnv({set: p}, r));
+runNetworkTest(() => {
 
-runNetworkTest(() =>
-  pushPrefs(['media.peerconnection.simulcast', true]).then(() => {
-
-    test = new PeerConnectionTest();
-    test.setMediaConstraints([{video: true}], [{video: true}]);
-    test.chain.removeAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW");
+  test = new PeerConnectionTest();
+  test.setMediaConstraints([{video: true}], [{video: true}]);
+  test.chain.removeAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW");
 
-    // Test sender parameters.
-    test.chain.append([
-      function PC_LOCAL_SET_PARAMETERS(test) {
-        return parameterstest(test.pcLocal);
-      }
-    ]);
+  // Test sender parameters.
+  test.chain.append([
+    function PC_LOCAL_SET_PARAMETERS(test) {
+      return parameterstest(test.pcLocal);
+    }
+  ]);
 
-    return test.run();
-  })
-  .catch(e => ok(false, "unexpected failure: " + e)));
+  return test.run()
+    .catch(e => ok(false, "unexpected failure: " + e));
+});
 
 </script>
 </pre>
 </body>
 </html>