| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE HTML> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 </head> |
| 7 <body> |
| 8 <script> |
| 9 |
| 10 // If a constraint is specified, it should come back in getConstraints(). |
| 11 promise_test(function() { |
| 12 return navigator.mediaDevices.getUserMedia({audio: { echoCancellation: { exact
: true}}}) |
| 13 .then(function(s) { |
| 14 constraints = s.getAudioTracks()[0].getConstraints(); |
| 15 assert_equals(Object.keys(constraints).length, 1); |
| 16 assert_true(constraints.hasOwnProperty('echoCancellation')); |
| 17 assert_true(constraints.echoCancellation.exact); |
| 18 }); |
| 19 }, 'A set constraint is returned on getConstraints'); |
| 20 |
| 21 promise_test(function() { |
| 22 return navigator.mediaDevices.getUserMedia({audio: { echoCancellation: { exact
: true}, notKnownName: { exact: true }}}) |
| 23 .then(function(s) { |
| 24 constraints = s.getAudioTracks()[0].getConstraints(); |
| 25 assert_equals(Object.keys(constraints).length, 1); |
| 26 assert_false(constraints.hasOwnProperty('notKnownName')); |
| 27 }); |
| 28 }, 'An unknown constraint is NOT returned on getConstraints'); |
| 29 |
| 30 function constraintElementsEqual(a, b) { |
| 31 if (a === b) |
| 32 return true; |
| 33 if (!(a instanceof Object)) |
| 34 return false; |
| 35 if (!(b instanceof Object)) |
| 36 return false; |
| 37 if (Object.keys(a).length != Object.keys(b).length) |
| 38 return false; |
| 39 for (var p in a) { |
| 40 if (!a.hasOwnProperty(p)) |
| 41 continue; // Skip prototypes and such things. |
| 42 if (!b.hasOwnProperty(p)) |
| 43 return false; |
| 44 if (a[p] instanceof Object && b[p] instanceof Object) { |
| 45 if (!constraintElementsEqual(a[p], b[p])) |
| 46 return false; |
| 47 continue; |
| 48 } |
| 49 if (a[p] !== b[p]) return false; // Simple types. |
| 50 } |
| 51 return true; |
| 52 } |
| 53 |
| 54 promise_test(function() { |
| 55 // We construct a constraint set that covers all defined constraints. |
| 56 // All these constraints make sense for video. |
| 57 const complexConstraintSet = { |
| 58 width: { min: 30, max: 480 }, |
| 59 height: { min: 30, max: 480, exact: 350 }, |
| 60 aspectRatio: { ideal: 1.3333333, exact: 1.4444 }, |
| 61 frameRate: { exact: 30.0 }, |
| 62 facingMode: { ideal: [ "user" ] } |
| 63 }; |
| 64 // These constraints are syntactically valid, but may cause rejection. |
| 65 // They are included in an "advanced" constraint. |
| 66 const ignorableConstraintSet = { |
| 67 volume: { exact: 1.0 }, |
| 68 sampleRate: { exact: 42 }, |
| 69 sampleSize: { exact: 3 }, |
| 70 echoCancellation: { exact: false }, |
| 71 latency: { exact: 0.22 }, |
| 72 channelCount: { exact: 2 }, |
| 73 deviceId: { exact: ["foo"] }, |
| 74 groupId: { exact: ["bar"] } |
| 75 }; |
| 76 let complexConstraints = complexConstraintSet; |
| 77 complexConstraints.advanced = [ ignorableConstraintSet ]; |
| 78 |
| 79 return navigator.mediaDevices.getUserMedia({video: complexConstraints}) |
| 80 .then(function(s) { |
| 81 constraints = s.getVideoTracks()[0].getConstraints(); |
| 82 assert_true(constraintElementsEqual(constraints, complexConstraints), |
| 83 "Unexpected result:" + JSON.stringify(constraints, null, 2)); |
| 84 }); |
| 85 }, 'All valid keys are returned for complex constraints'); |
| 86 |
| 87 </script> |
| 88 </body> |
| 89 </html> |
| OLD | NEW |