OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <script> | 8 <script> |
9 | 9 |
10 // If a constraint is specified, it should come back in getConstraints(). | 10 // If a constraint is specified, it should come back in getConstraints(). |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 promise_test(function() { | 54 promise_test(function() { |
55 // We construct a constraint set that covers all defined constraints. | 55 // We construct a constraint set that covers all defined constraints. |
56 // All these constraints make sense for video. | 56 // All these constraints make sense for video. |
57 const complexConstraintSet = { | 57 const complexConstraintSet = { |
58 width: { min: 30, max: 480 }, | 58 width: { min: 30, max: 480 }, |
59 height: { min: 30, max: 480, exact: 350 }, | 59 height: { min: 30, max: 480, exact: 350 }, |
60 aspectRatio: { ideal: 1.3333333, exact: 1.4444 }, | 60 aspectRatio: { ideal: 1.3333333, exact: 1.4444 }, |
61 frameRate: { exact: 30.0 }, | 61 frameRate: { exact: 30.0 }, |
62 facingMode: { ideal: [ "user" ] } | 62 facingMode: { exact: "user" } |
63 }; | 63 }; |
64 // These constraints are syntactically valid, but may cause rejection. | 64 // These constraints are syntactically valid, but may cause rejection. |
65 // They are included in an "advanced" constraint. | 65 // They are included in an "advanced" constraint. |
66 const ignorableConstraintSet = { | 66 const ignorableConstraintSet = { |
67 volume: { exact: 1.0 }, | 67 volume: { exact: 1.0 }, |
68 sampleRate: { exact: 42 }, | 68 sampleRate: { exact: 42 }, |
69 sampleSize: { exact: 3 }, | 69 sampleSize: { exact: 3 }, |
70 echoCancellation: { exact: false }, | 70 echoCancellation: { exact: false }, |
71 latency: { exact: 0.22 }, | 71 latency: { exact: 0.22 }, |
72 channelCount: { exact: 2 }, | 72 channelCount: { exact: 2 }, |
73 deviceId: { exact: ["foo"] }, | 73 deviceId: { exact: ["foo", "fooz"] }, |
74 groupId: { exact: ["bar"] } | 74 groupId: { exact: ["bar", "baz"] } |
75 }; | 75 }; |
76 let complexConstraints = complexConstraintSet; | 76 let complexConstraints = complexConstraintSet; |
77 complexConstraints.advanced = [ ignorableConstraintSet ]; | 77 complexConstraints.advanced = [ ignorableConstraintSet ]; |
78 | 78 |
79 return navigator.mediaDevices.getUserMedia({video: complexConstraints}) | 79 return navigator.mediaDevices.getUserMedia({video: complexConstraints}) |
80 .then(function(s) { | 80 .then(function(s) { |
81 constraints = s.getVideoTracks()[0].getConstraints(); | 81 constraints = s.getVideoTracks()[0].getConstraints(); |
82 assert_true(constraintElementsEqual(constraints, complexConstraints), | 82 assert_true(constraintElementsEqual(constraints, complexConstraints), |
83 "Unexpected result:" + JSON.stringify(constraints, null, 2)); | 83 "Unexpected result: In: " + JSON.stringify(complexConstraints, null, 2) + |
| 84 " Out: " + JSON.stringify(constraints, null, 2)); |
84 }); | 85 }); |
85 }, 'All valid keys are returned for complex constraints'); | 86 }, 'All valid keys are returned for complex constraints'); |
86 | 87 |
| 88 // Syntax tests for constraints. |
| 89 |
| 90 function constraintSyntaxTestWithChange(name, constraints, expected_result) { |
| 91 promise_test(function() { |
| 92 return navigator.mediaDevices.getUserMedia( |
| 93 {'video': { 'advanced': [ constraints ]}}) |
| 94 .then(function(s) { |
| 95 var constraints_out = s.getVideoTracks()[0].getConstraints().advanced[
0]; |
| 96 assert_true(constraintElementsEqual(expected_result, constraints_out), |
| 97 "Unexpected result: Expected: " + |
| 98 JSON.stringify(expected_result, null, 2) + |
| 99 " Out: " + JSON.stringify(constraints_out, null, 2)); |
| 100 }) |
| 101 }, name); |
| 102 } |
| 103 |
| 104 function constraintSyntaxTest(name, constraints) { |
| 105 constraintSyntaxTestWithChange(name, constraints, constraints); |
| 106 } |
| 107 |
| 108 constraintSyntaxTest('Simple integer', { height: 42 }); |
| 109 constraintSyntaxTest('Exact integer', { height: { exact: 42 }}); |
| 110 constraintSyntaxTest('Min/max integer', { height: { min: 42, max: 43 }}); |
| 111 constraintSyntaxTestWithChange('Ideal unwrapped integer', |
| 112 { height: { ideal: 42 } }, { height: 42 }); |
| 113 |
| 114 constraintSyntaxTest('Simple double', { aspectRatio: 1.5 }); |
| 115 constraintSyntaxTest('Exact double', { aspectRatio: { exact: 1.5 }}); |
| 116 constraintSyntaxTest('Min/max double', { aspectRatio: { min: 1.5, max: 2.0 }}); |
| 117 constraintSyntaxTestWithChange('Ideal unwrapped double', |
| 118 { aspectRatio: { ideal: 1.5 } }, { aspectRatio: 1.5 }); |
| 119 |
| 120 constraintSyntaxTest('Simple String', { facingMode: "user1" }); |
| 121 constraintSyntaxTest('Exact String', { facingMode: { exact: "user2" }}); |
| 122 constraintSyntaxTest('Multiple String in Brackets', { facingMode: { exact: ["use
r3", "left3"]}}); |
| 123 constraintSyntaxTest('Multiple Bracketed Naked String', { facingMode: ["user4",
"left4"] }); |
| 124 constraintSyntaxTestWithChange('Single Bracketed string unwrapped', |
| 125 { 'facingMode': ["user5"]}, { facingMode: "user5" }); |
| 126 constraintSyntaxTest('Both Ideal and Exact string', { facingMode: { ideal: "user
6", exact: "left6" }}); |
| 127 |
| 128 constraintSyntaxTest('Simple boolean', { echoCancellation: true }); |
| 129 constraintSyntaxTest('Exact boolean', { echoCancellation: { exact: true }}); |
| 130 constraintSyntaxTestWithChange('Ideal unwrapped boolean', |
| 131 { echoCancellation: { ideal: true } }, { echoCancellation: true }); |
| 132 |
87 </script> | 133 </script> |
88 </body> | 134 </body> |
89 </html> | 135 </html> |
OLD | NEW |