| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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: { exact: "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: { ideal: 1.0 }, |
| 68 sampleRate: { exact: 42 }, | 68 sampleRate: { ideal: 42 }, |
| 69 sampleSize: { exact: 3 }, | 69 sampleSize: { ideal: 3 }, |
| 70 echoCancellation: { exact: false }, | 70 echoCancellation: { ideal: false }, |
| 71 latency: { exact: 0.22 }, | 71 latency: { ideal: 0.22 }, |
| 72 channelCount: { exact: 2 }, | 72 channelCount: { ideal: 2 }, |
| 73 deviceId: { exact: ["foo", "fooz"] }, | 73 deviceId: { ideal: ["foo", "fooz"] }, |
| 74 groupId: { exact: ["bar", "baz"] } | 74 groupId: { ideal: ["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: In: " + JSON.stringify(complexConstraints, null, 2) + | 83 "Unexpected result: In: " + JSON.stringify(complexConstraints, null, 2) + |
| 84 " Out: " + JSON.stringify(constraints, null, 2)); | 84 " Out: " + JSON.stringify(constraints, null, 2)); |
| 85 }); | 85 }); |
| 86 }, 'All valid keys are returned for complex constraints'); | 86 }, 'All valid keys are returned for complex constraints'); |
| 87 | 87 |
| 88 // Syntax tests for constraints. | 88 // Syntax tests for constraints. |
| 89 // These work by putting the constraints into an advanced constraint |
| 90 // (so that they can be ignored), calling getUserMedia, and then |
| 91 // inspecting the constraints. |
| 92 // In advanced constraints, naked values mean "exact", and "exact" values |
| 93 // are thus unwrapped, which is the opposite behavior from the "basic" |
| 94 // constraint set (outside advanced). |
| 89 | 95 |
| 90 function constraintSyntaxTestWithChange(name, constraints, expected_result) { | 96 function constraintSyntaxTestWithChange(name, constraints, expected_result) { |
| 91 promise_test(function() { | 97 promise_test(function() { |
| 92 return navigator.mediaDevices.getUserMedia( | 98 return navigator.mediaDevices.getUserMedia( |
| 93 {'video': { 'advanced': [ constraints ]}}) | 99 {'video': { 'advanced': [ constraints ]}}) |
| 94 .then(function(s) { | 100 .then(function(s) { |
| 95 var constraints_out = s.getVideoTracks()[0].getConstraints().advanced[
0]; | 101 var constraints_out = s.getVideoTracks()[0].getConstraints().advanced[
0]; |
| 96 assert_true(constraintElementsEqual(expected_result, constraints_out), | 102 assert_true(constraintElementsEqual(expected_result, constraints_out), |
| 97 "Unexpected result: Expected: " + | 103 "Unexpected result: Expected: " + |
| 98 JSON.stringify(expected_result, null, 2) + | 104 JSON.stringify(expected_result, null, 2) + |
| 99 " Out: " + JSON.stringify(constraints_out, null, 2)); | 105 " Out: " + JSON.stringify(constraints_out, null, 2)); |
| 100 }) | 106 }) |
| 101 }, name); | 107 }, name); |
| 102 } | 108 } |
| 103 | 109 |
| 104 function constraintSyntaxTest(name, constraints) { | 110 function constraintSyntaxTest(name, constraints) { |
| 105 constraintSyntaxTestWithChange(name, constraints, constraints); | 111 constraintSyntaxTestWithChange(name, constraints, constraints); |
| 106 } | 112 } |
| 107 | 113 |
| 108 constraintSyntaxTest('Simple integer', { height: 42 }); | 114 constraintSyntaxTest('Simple integer', { height: 42 }); |
| 109 constraintSyntaxTest('Exact integer', { height: { exact: 42 }}); | 115 constraintSyntaxTest('Ideal integer', { height: { ideal: 42 }}); |
| 110 constraintSyntaxTest('Min/max integer', { height: { min: 42, max: 43 }}); | 116 constraintSyntaxTest('Min/max integer', { height: { min: 42, max: 43 }}); |
| 111 constraintSyntaxTestWithChange('Ideal unwrapped integer', | 117 constraintSyntaxTestWithChange('Exact unwrapped integer', |
| 112 { height: { ideal: 42 } }, { height: 42 }); | 118 { height: { exact: 42 } }, { height: 42 }); |
| 113 | 119 |
| 114 constraintSyntaxTest('Simple double', { aspectRatio: 1.5 }); | 120 constraintSyntaxTest('Simple double', { aspectRatio: 1.5 }); |
| 115 constraintSyntaxTest('Exact double', { aspectRatio: { exact: 1.5 }}); | 121 constraintSyntaxTest('Ideal double', { aspectRatio: { ideal: 1.5 }}); |
| 116 constraintSyntaxTest('Min/max double', { aspectRatio: { min: 1.5, max: 2.0 }}); | 122 constraintSyntaxTest('Min/max double', { aspectRatio: { min: 1.5, max: 2.0 }}); |
| 117 constraintSyntaxTestWithChange('Ideal unwrapped double', | 123 constraintSyntaxTestWithChange('Exact unwrapped double', |
| 118 { aspectRatio: { ideal: 1.5 } }, { aspectRatio: 1.5 }); | 124 { aspectRatio: { exact: 1.5 } }, { aspectRatio: 1.5 }); |
| 119 | 125 |
| 120 constraintSyntaxTest('Simple String', { facingMode: "user1" }); | 126 constraintSyntaxTest('Simple String', { facingMode: "user1" }); |
| 121 constraintSyntaxTest('Exact String', { facingMode: { exact: "user2" }}); | 127 constraintSyntaxTest('Ideal String', { facingMode: { ideal: "user2" }}); |
| 122 constraintSyntaxTest('Multiple String in Brackets', { facingMode: { exact: ["use
r3", "left3"]}}); | 128 constraintSyntaxTest('Multiple String in Brackets', { facingMode: { ideal: ["use
r3", "left3"]}}); |
| 123 constraintSyntaxTest('Multiple Bracketed Naked String', { facingMode: ["user4",
"left4"] }); | 129 constraintSyntaxTest('Multiple Bracketed Naked String', { facingMode: ["user4",
"left4"] }); |
| 124 constraintSyntaxTestWithChange('Single Bracketed string unwrapped', | 130 constraintSyntaxTestWithChange('Single Bracketed string unwrapped', |
| 125 { 'facingMode': ["user5"]}, { facingMode: "user5" }); | 131 { 'facingMode': ["user5"]}, { facingMode: "user5" }); |
| 126 constraintSyntaxTest('Both Ideal and Exact string', { facingMode: { ideal: "user
6", exact: "left6" }}); | 132 constraintSyntaxTest('Both Ideal and Exact string', { facingMode: { ideal: "user
6", exact: "left6" }}); |
| 127 | 133 |
| 128 constraintSyntaxTest('Simple boolean', { echoCancellation: true }); | 134 constraintSyntaxTest('Simple boolean', { echoCancellation: true }); |
| 129 constraintSyntaxTest('Exact boolean', { echoCancellation: { exact: true }}); | 135 constraintSyntaxTest('Ideal boolean', { echoCancellation: { ideal: true }}); |
| 130 constraintSyntaxTestWithChange('Ideal unwrapped boolean', | 136 constraintSyntaxTestWithChange('Exact unwrapped boolean', |
| 131 { echoCancellation: { ideal: true } }, { echoCancellation: true }); | 137 { echoCancellation: { exact: true } }, { echoCancellation: true }); |
| 132 | 138 |
| 133 </script> | 139 </script> |
| 134 </body> | 140 </body> |
| 135 </html> | 141 </html> |
| OLD | NEW |