OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>MediaCapabilities.query()</title> | 2 <title>MediaCapabilities.query()</title> |
3 <script src=/resources/testharness.js></script> | 3 <script src=/resources/testharness.js></script> |
4 <script src="/resources/testharnessreport.js"></script> | 4 <script src="/resources/testharnessreport.js"></script> |
5 <script> | 5 <script> |
6 | 6 |
| 7 // Minimal VideoConfiguration that will be allowed per spec. All optional |
| 8 // properties are missing. |
| 9 var minimalVideoConfiguration = { |
| 10 contentType: 'video/webm; codecs="vp9"', |
| 11 width: 800, |
| 12 height: 600, |
| 13 bitrate: 3000, |
| 14 framerate: 24, |
| 15 }; |
| 16 |
| 17 // Minimal AudioConfiguration that will be allowed per spec. All optional |
| 18 // properties are missing. |
| 19 var minimalAudioConfiguration = { |
| 20 contentType: 'audio/webm; codecs="opus"', |
| 21 }; |
| 22 |
7 promise_test(t => { | 23 promise_test(t => { |
8 return promise_rejects(t, new TypeError(), navigator.mediaCapabilities.query()
); | 24 return promise_rejects(t, new TypeError(), navigator.mediaCapabilities.query()
); |
9 }, "Test that query rejects if it doesn't get a configuration"); | 25 }, "Test that query rejects if it doesn't get a configuration"); |
10 | 26 |
11 promise_test(t => { | 27 promise_test(t => { |
12 return promise_rejects(t, new TypeError(), navigator.mediaCapabilities.query({
})); | 28 return promise_rejects(t, new TypeError(), navigator.mediaCapabilities.query({
})); |
13 }, "Test that query rejects if the MediaConfiguration isn't valid"); | 29 }, "Test that query rejects if the MediaConfiguration isn't valid"); |
14 | 30 |
15 promise_test(t => { | 31 promise_test(t => { |
| 32 return promise_rejects(t, new TypeError(), navigator.mediaCapabilities.query({ |
| 33 video: minimalVideoConfiguration, |
| 34 audio: minimalAudioConfiguration, |
| 35 })); |
| 36 }, "Test that query rejects if the MediaConfiguration does not have a type"); |
| 37 |
| 38 promise_test(t => { |
16 return navigator.mediaCapabilities.query({ | 39 return navigator.mediaCapabilities.query({ |
17 type: 'file', | 40 type: 'file', |
18 video: { | 41 video: minimalVideoConfiguration, |
19 type: 'video/webm', | 42 audio: minimalAudioConfiguration, |
20 width: 800, | |
21 height: 600, | |
22 bitrate: 3000, | |
23 framerate: 24, | |
24 }, | |
25 audio: { | |
26 type: 'audio/webm', | |
27 }, | |
28 }).then(ability => { | 43 }).then(ability => { |
29 assert_idl_attribute(ability, 'supported'); | 44 assert_idl_attribute(ability, 'supported'); |
30 assert_idl_attribute(ability, 'smooth'); | 45 assert_idl_attribute(ability, 'smooth'); |
31 assert_idl_attribute(ability, 'powerEfficient'); | 46 assert_idl_attribute(ability, 'powerEfficient'); |
32 }); | 47 }); |
33 }, "Test that query returns a valid MediaDecodingAbility objects"); | 48 }, "Test that query returns a valid MediaDecodingAbility objects"); |
34 | 49 |
| 50 async_test(t => { |
| 51 var validTypes = [ 'file', 'media-source' ]; |
| 52 var invalidTypes = [ undefined, null, '', 'foobar', 'mse', 'MediaSource' ]; |
| 53 |
| 54 var validPromises = []; |
| 55 var invalidCaught = 0; |
| 56 |
| 57 validTypes.forEach(type => { |
| 58 validPromises.push(navigator.mediaCapabilities.query({ |
| 59 type: type, |
| 60 video: minimalVideoConfiguration, |
| 61 audio: minimalAudioConfiguration, |
| 62 })); |
| 63 }); |
| 64 |
| 65 // validTypes are tested via Promise.all(validPromises) because if one of the |
| 66 // promises fail, Promise.all() will reject. This mechanism can't be used for |
| 67 // invalid types which will be tested individually and increment invalidCaught |
| 68 // when rejected until the amount of rejection matches the expectation. |
| 69 Promise.all(validPromises).then(t.step_func(() => { |
| 70 for (var i = 0; i < invalidTypes.length; ++i) { |
| 71 navigator.mediaCapabilities.query({ |
| 72 type: invalidTypes[i], |
| 73 video: minimalVideoConfiguration, |
| 74 audio: minimalAudioConfiguration, |
| 75 }).then(t.unreached_func(), t.step_func(e => { |
| 76 assert_equals(e.name, 'TypeError'); |
| 77 ++invalidCaught; |
| 78 if (invalidCaught == invalidTypes.length) |
| 79 t.done(); |
| 80 })); |
| 81 } |
| 82 }), t.unreached_func('Promise.all should not reject for valid types')); |
| 83 }, "Test that query rejects if the MediaConfiguration does not have a valid type
"); |
| 84 |
35 </script> | 85 </script> |
OLD | NEW |