| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>MediaCapabilities.query()</title> | |
| 3 <script src=/resources/testharness.js></script> | |
| 4 <script src="/resources/testharnessreport.js"></script> | |
| 5 <script> | |
| 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 | |
| 23 promise_test(t => { | |
| 24 return promise_rejects(t, new TypeError(), navigator.mediaCapabilities.query()
); | |
| 25 }, "Test that query rejects if it doesn't get a configuration"); | |
| 26 | |
| 27 promise_test(t => { | |
| 28 return promise_rejects(t, new TypeError(), navigator.mediaCapabilities.query({
})); | |
| 29 }, "Test that query rejects if the MediaConfiguration isn't valid"); | |
| 30 | |
| 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 => { | |
| 39 return navigator.mediaCapabilities.query({ | |
| 40 type: 'file', | |
| 41 video: minimalVideoConfiguration, | |
| 42 audio: minimalAudioConfiguration, | |
| 43 }).then(ability => { | |
| 44 assert_idl_attribute(ability, 'supported'); | |
| 45 assert_idl_attribute(ability, 'smooth'); | |
| 46 assert_idl_attribute(ability, 'powerEfficient'); | |
| 47 }); | |
| 48 }, "Test that query returns a valid MediaDecodingAbility objects"); | |
| 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 | |
| 85 </script> | |
| OLD | NEW |