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