Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-getConstraints.html |
| diff --git a/third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-getConstraints.html b/third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-getConstraints.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a7a94992b0cc8045965591712c171b78ff2bf3d1 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-getConstraints.html |
| @@ -0,0 +1,86 @@ |
| +<!DOCTYPE HTML> |
| +<html> |
| +<head> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +</head> |
| +<body> |
| +<script> |
| + |
|
tommi (sloooow) - chröme
2016/04/27 08:57:40
nit: one empty line (or none)
hta - Chromium
2016/04/27 09:32:37
Done.
|
| + |
| +// If a constraint is specified, it should come back in getConstraints(). |
| +promise_test(function() { |
| + return navigator.mediaDevices.getUserMedia({audio: { echoCancellation: { exact: true}}}) |
| + .then(function(s) { |
| + constraints = s.getAudioTracks()[0].getConstraints(); |
| + assert_equals(Object.keys(constraints).length, 1); |
| + assert_true(constraints.hasOwnProperty('echoCancellation')); |
| + assert_true(constraints.echoCancellation.exact); |
| + }); |
| +}, 'A set constraint is returned on getConstraints'); |
| + |
| +promise_test(function() { |
| + return navigator.mediaDevices.getUserMedia({audio: { echoCancellation: { exact: true}, notKnownName: { exact: true }}}) |
| + .then(function(s) { |
| + constraints = s.getAudioTracks()[0].getConstraints(); |
| + assert_equals(Object.keys(constraints).length, 1); |
| + assert_false(constraints.hasOwnProperty('notKnownName')); |
| + }); |
| +}, 'An unknown constraint is NOT returned on getConstraints'); |
| + |
| +function constraintElementsEqual(a, b) { |
| + if (a === b) return true; |
| + if (!(a instanceof Object)) return false; |
| + if (!(b instanceof Object)) return false; |
| + if (Object.keys(a).length != Object.keys(b).length) return false; |
| + for (var p in a) { |
| + if (!a.hasOwnProperty(p)) continue; |
| + if (!b.hasOwnProperty(p)) return false; |
| + if (a[p] instanceof Object && b[p] instanceof Object) { |
| + if (!constraintElementsEqual(a[p], b[p])) return false; |
| + continue; |
|
tommi (sloooow) - chröme
2016/04/27 08:57:40
this is kind of hard to read and easy to read inco
hta - Chromium
2016/04/27 09:32:37
Done - consistent newlines imposed.
|
| + } |
| + if (a[p] !== b[p]) return false;; |
|
tommi (sloooow) - chröme
2016/04/27 08:57:40
nit: one semicolon should cut it ;)
hta - Chromium
2016/04/27 09:32:37
Done.
|
| + } |
| + return true; |
| +} |
| + |
| + |
| +promise_test(function() { |
| + // We construct a constraint set that covers all defined constraints. |
| + // All these constraints make sense for video. |
| + const complexConstraintSet = { |
| + width: { min: 30, max: 480 }, |
| + height: { min: 30, max: 480, exact: 350 }, |
| + aspectRatio: { ideal: 1.3333333, exact: 1.4444 }, |
| + frameRate: { exact: 30.0 }, |
| + facingMode: { ideal: [ "user" ] } |
| + }; |
| + // These constraints are syntactically valid, but may cause rejection. |
| + // They are included in an "advanced" constraint. |
| + const ignorableConstraintSet = { |
| + volume: { exact: 1.0 }, |
| + sampleRate: { exact: 42 }, |
| + sampleSize: { exact: 3 }, |
| + echoCancellation: { exact: false }, |
| + latency: { exact: 0.22 }, |
| + channelCount: { exact: 2 }, |
| + deviceId: { exact: ["foo"] }, |
| + groupId: { exact: ["bar"] } |
| + }; |
| + let complexConstraints = complexConstraintSet; |
| + complexConstraints.advanced = [ ignorableConstraintSet ]; |
| + |
| + return navigator.mediaDevices.getUserMedia({video: complexConstraints}) |
| + .then(function(s) { |
| + constraints = s.getVideoTracks()[0].getConstraints(); |
| + assert_true(constraintElementsEqual(constraints, complexConstraints), |
| + "Unexpected result:" + JSON.stringify(constraints, null, 2)); |
| + }); |
| +}, 'All valid keys are returned for complex constraints'); |
| + |
| + |
|
tommi (sloooow) - chröme
2016/04/27 08:57:40
nit: reduce whitespace
hta - Chromium
2016/04/27 09:32:37
Done.
|
| + |
| +</script> |
| +</body> |
| +</html> |