Bug 1088621 - Test constraining video cameras by width/height/frameRate. draft
authorJan-Ivar Bruaroey <jib@mozilla.com>
Fri, 07 Nov 2014 21:24:46 -0500
changeset 645189 34da15b3cfeab033faf253e189b16c7808da3bea
parent 645188 e5b1f0bbe70a2500d0cd0336182de43bc8739df4
child 645190 d3cb5367c9a2bd792317054db7eedf045b11470b
push id73691
push userjbruaroey@mozilla.com
push dateFri, 11 Aug 2017 23:12:29 +0000
bugs1088621
milestone57.0a1
Bug 1088621 - Test constraining video cameras by width/height/frameRate. MozReview-Commit-ID: 9S37aPPg3Wj
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_getUserMedia_constrainVideo.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -56,16 +56,17 @@ skip-if = android_version == '18' # andr
 skip-if = toolkit == 'android' # no screenshare on android
 [test_getUserMedia_basicTabshare.html]
 skip-if = toolkit == 'android' # no windowshare on android
 [test_getUserMedia_basicWindowshare.html]
 skip-if = toolkit == 'android' # no windowshare on android
 [test_getUserMedia_basicVideoAudio.html]
 [test_getUserMedia_bug1223696.html]
 [test_getUserMedia_constraints.html]
+[test_getUserMedia_constrainVideo.html]
 [test_getUserMedia_callbacks.html]
 [test_getUserMedia_getTrackById.html]
 [test_getUserMedia_gumWithinGum.html]
 [test_getUserMedia_loadedmetadata.html]
 [test_getUserMedia_mediaElementCapture_audio.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_mediaElementCapture_tracks.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_constrainVideo.html
@@ -0,0 +1,104 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<div id="content" style="display: none">
+  <video id="video" width="120" autoplay></video><br>
+  <video id="video2" width="120" autoplay></video><br>
+</div>
+<pre id="test">
+<script type="application/javascript">
+createHTML({ title: "Test getUserMedia constraint video", bug: "1088621" });
+
+let videoPropMap = { width: "videoWidth", height: "videoHeight" };
+
+let gum = c => navigator.mediaDevices.getUserMedia({ fake: true, video: c });
+
+let testGum = (constraints, expected) => {
+  let msg = "Testing " + JSON.stringify(constraints) + " - ";
+  let expectedError = (typeof expected == "string")? expected : null;
+
+  return gum(constraints).then(stream => {
+    if (expectedError) {
+      throw ({ name: "success" });
+    }
+    let settings = stream.getTracks()[0].getSettings();
+    for (let prop in expected) {
+      is(settings[prop], expected[prop], msg + "Get expected " + prop);
+    }
+    video.srcObject = stream;
+    return new Promise(resolve => video.onloadedmetadata = resolve);
+  })
+  .then(() => {
+    for (let prop in expected) {
+      if (prop in videoPropMap) {
+        is(video[videoPropMap[prop]], expected[prop],
+           msg + "Get expected video." + videoPropMap[prop]);
+      }
+    }
+    video.srcObject.stop();
+    video.srcObject = null;
+  })
+  .then(() => wait(200)) // TODO: Remove this workaround for Bug 1289665.
+  .catch(e => {
+    is(e.name, expectedError,
+       msg + (e.name == "success" ? "Get expected success" :
+                                    "Get expected error (" + e.message +")"));
+  });
+};
+
+let tests = [
+ [false, "NotSupportedError"],
+ [true, { width: 640, height: 480, frameRate: 30 }],
+ [{}, { width: 640, height: 480, frameRate: 30 }],
+ [{ width: 1280, height: 720 }, { width: 1280, height: 720, frameRate: 30 }],
+ [{ width: 710, height: 800 }, { width: 640, height: 480, frameRate: 30 }],
+ [{ width: 720, height: 800 }, { width: 1408, height: 792, frameRate: 30 }],
+ [{ width: 640, height: 480, frameRate: 17 }, { width: 640, height: 480, frameRate: 30 }],
+ [{ width: 640, height: 480, frameRate: 16 }, { width: 896, height: 504, frameRate: 15 }],
+ [{ width: { ideal: 480 } }, { width: 480, height: 360, frameRate: 30 }],
+ [{ height: { min: 2048 } }, "OverconstrainedError"],
+ [{ height: { min: 576 } }, { width: 1024, height: 576, frameRate: 30 }],
+ [{ height: { max: 35 } }, "OverconstrainedError"],
+ [{ height: { max: 180 } }, { width: 240, height: 180, frameRate: 30 }],
+ [{ frameRate: { exact: 12 } }, "OverconstrainedError"],
+ [{ frameRate: { exact: 10 } }, { width: 896, height: 504, frameRate: 10 }],
+ [{ frameRate: { min: 15, max: 10 } }, "OverconstrainedError"],
+ [{ width: { max: 240 }, height: { min: 720 } }, "OverconstrainedError"],
+ [{ width: { min: 320, ideal: 160, max: 640 },
+    height: { min: 200, ideal: 120, max: 480 } },
+  { width: 320, height: 240, frameRate: 30 }],
+];
+
+let concurrentConstraints = { width: { ideal: 1024, min: 320 },
+                              height: { ideal: 576, max: 720 } };
+let concurrentTests = [
+ [true, { width: 1024, height: 576, frameRate: 30 }],
+ [{ width: 160, height: 120 }, { width: 1024, height: 576, frameRate: 30 }],
+ [{ width: 640, height: 480, frameRate: 10 }, { width: 1024, height: 576, frameRate: 30 }],
+ [{ width: 1280, height: 720, frameRate: 15 }, { width: 1280, height: 720, frameRate: 30 }],
+ [{ width: { max: 160 } }, "OverconstrainedError"],
+ [{ height: { min: 792 } }, "OverconstrainedError"],
+];
+
+runTest(() => tests.reduce((p, test) => p.then(() => testGum(...test)),
+                           Promise.resolve())
+  // Test concurrent gUM requests.
+  .then(() => gum(concurrentConstraints))
+  .then(stream => {
+    video2.srcObject = stream;
+    return concurrentTests.reduce((p, test) => p.then(() => testGum(...test)),
+                                  Promise.resolve());
+  })
+  .then(() => {
+    video2.srcObject.getTracks().forEach(track => track.stop());
+    video2.srcObject = null;
+  })
+  .catch(e => ok(false, "Unexpected " + e)));
+
+</script>
+</pre>
+</body>
+</html>