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..2bd2ddd1d76d08a54dbfd7d84800b9826b832cf5 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-getConstraints.html |
| @@ -0,0 +1,85 @@ |
| +<!DOCTYPE HTML> |
| +<html> |
| +<head> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +</head> |
| +<body> |
| +<script> |
| + |
| + |
| +// 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, "constraints(1): " + JSON.stringify(constraints)); |
| + assert_equals(constraints.echoCancellation.exact, true, "constraints(2): " +JSON.stringify(constraints)); |
|
Peter Beverloo
2016/04/21 14:11:45
Could make this a bit more explicit:
assert_true(
hta - Chromium
2016/04/24 09:58:25
Done.
|
| + }); |
| +}, '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, "constraints(1): " + JSON.stringify(constraints)); |
| + assert_equals(constraints.echoCancellation.exact, true, "constraints(2): " +JSON.stringify(constraints)); |
|
Peter Beverloo
2016/04/21 14:11:45
assert_false(constraints.hasOwnProperty('notKnownN
hta - Chromium
2016/04/24 09:58:25
Done.
|
| + }); |
| +}, '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; |
| + } |
| + if (a[p] !== b[p]) return false;; |
| + } |
| + return true; |
| +} |
| + |
| + |
| +promise_test(function() { |
| + // We construct a constraint set that covers all defined constraints. |
| + // All these constraints make sense for video. |
| + 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. |
| + 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"] } |
| + }; |
| + complexConstraints = complexConstraintSet; |
| + complexConstraints.advanced = [ ignorableConstraintSet ]; |
|
Peter Beverloo
2016/04/21 14:11:45
nit: Please prefix these variables with `let` or `
hta - Chromium
2016/04/24 09:58:25
Done.
|
| + |
| + 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'); |
| + |
| + |
| + |
| +</script> |
| +</body> |
| +</html> |