| <!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); |
| 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; // Skip prototypes and such things. |
| 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; // Simple types. |
| } |
| 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'); |
| |
| </script> |
| </body> |
| </html> |