encodingInfo.any.js (10230B)
1 // Minimal VideoConfiguration that will be allowed per spec. All optional 2 // properties are missing. 3 var minimalVideoConfiguration = { 4 contentType: 'video/webm; codecs="vp09.00.10.08"', 5 width: 800, 6 height: 600, 7 bitrate: 3000, 8 framerate: 24, 9 }; 10 11 // Minimal WebRTC VideoConfiguration that will be allowed per spec. All optional 12 // properties are missing. 13 var minimalWebrtcVideoConfiguration = { 14 contentType: 'video/VP9', 15 width: 800, 16 height: 600, 17 bitrate: 3000, 18 framerate: 24, 19 }; 20 21 // Minimal AudioConfiguration that will be allowed per spec. All optional 22 // properties are missing. 23 var minimalAudioConfiguration = { 24 contentType: 'audio/webm; codecs="opus"', 25 }; 26 27 // Minimal WebRTC AudioConfiguration that will be allowed per spec. All optional 28 // properties are missing. 29 var minimalWebrtcAudioConfiguration = { 30 contentType: 'audio/opus', 31 }; 32 33 promise_test(t => { 34 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo()); 35 }, "Test that encodingInfo rejects if it doesn't get a configuration"); 36 37 promise_test(t => { 38 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({})); 39 }, "Test that encodingInfo rejects if the MediaConfiguration isn't valid"); 40 41 promise_test(t => { 42 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 43 video: minimalVideoConfiguration, 44 audio: minimalAudioConfiguration, 45 })); 46 }, "Test that encodingInfo rejects if the MediaConfiguration does not have a type"); 47 48 promise_test(t => { 49 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 50 type: 'record', 51 })); 52 }, "Test that encodingInfo rejects if the configuration doesn't have an audio or video field"); 53 54 promise_test(t => { 55 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 56 type: 'record', 57 video: { 58 contentType: 'video/webm; codecs="vp09.00.10.08"', 59 width: 800, 60 height: 600, 61 bitrate: 3000, 62 framerate: -1, 63 }, 64 })); 65 }, "Test that encodingInfo rejects if the video configuration has a negative framerate"); 66 67 promise_test(t => { 68 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 69 type: 'record', 70 video: { 71 contentType: 'video/webm; codecs="vp09.00.10.08"', 72 width: 800, 73 height: 600, 74 bitrate: 3000, 75 framerate: 0, 76 }, 77 })); 78 }, "Test that encodingInfo rejects if the video configuration has a framerate set to 0"); 79 80 promise_test(t => { 81 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 82 type: 'record', 83 video: { 84 contentType: 'video/webm; codecs="vp09.00.10.08"', 85 width: 800, 86 height: 600, 87 bitrate: 3000, 88 framerate: Infinity, 89 }, 90 })); 91 }, "Test that encodingInfo rejects if the video configuration has a framerate set to Infinity"); 92 93 promise_test(t => { 94 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 95 type: 'record', 96 video: { 97 contentType: 'fgeoa', 98 width: 800, 99 height: 600, 100 bitrate: 3000, 101 framerate: 24, 102 }, 103 })); 104 }, "Test that encodingInfo rejects if the video configuration contentType doesn't parse"); 105 106 // See https://mimesniff.spec.whatwg.org/#example-valid-mime-type-string 107 promise_test(t => { 108 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 109 type: 'record', 110 video: { 111 contentType: 'video/webm;', 112 width: 800, 113 height: 600, 114 bitrate: 3000, 115 framerate: 24, 116 }, 117 })); 118 }, "Test that encodingInfo rejects if the video configuration contentType is not a valid MIME type string"); 119 120 promise_test(t => { 121 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 122 type: 'record', 123 video: { 124 contentType: 'audio/fgeoa', 125 width: 800, 126 height: 600, 127 bitrate: 3000, 128 framerate: 24, 129 }, 130 })); 131 }, "Test that encodingInfo rejects if the video configuration contentType isn't of type video"); 132 133 promise_test(t => { 134 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 135 type: 'record', 136 video: { 137 contentType: 'video/webm; codecs="vp09.00.10.08"; foo="bar"', 138 width: 800, 139 height: 600, 140 bitrate: 3000, 141 framerate: 24, 142 }, 143 })); 144 }, "Test that encodingInfo rejects if the video configuration contentType has more than one parameter"); 145 146 promise_test(t => { 147 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 148 type: 'record', 149 video: { 150 contentType: 'video/webm; foo="bar"', 151 width: 800, 152 height: 600, 153 bitrate: 3000, 154 framerate: 24, 155 }, 156 })); 157 }, "Test that encodingInfo rejects if the video configuration contentType has one parameter that isn't codecs"); 158 159 promise_test(t => { 160 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 161 type: 'record', 162 video: { 163 contentType: 'video/webm', 164 width: 800, 165 height: 600, 166 bitrate: 3000, 167 framerate: 24, 168 }, 169 })); 170 }, "Test that encodingInfo rejects if the video configuration contentType does not imply a single media codec but has no codecs parameter"); 171 172 promise_test(t => { 173 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 174 type: 'record', 175 video: { 176 contentType: 'video/webm; codecs="vp09.00.10.08, vp8"', 177 width: 800, 178 height: 600, 179 bitrate: 3000, 180 framerate: 24, 181 } 182 })); 183 }, "Test that encodingInfo rejects if the video configuration contentType has a codecs parameter that indicates multiple video codecs"); 184 185 promise_test(t => { 186 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 187 type: 'record', 188 video: { 189 contentType: 'video/webm; codecs="vp09.00.10.08, opus"', 190 width: 800, 191 height: 600, 192 bitrate: 3000, 193 framerate: 24, 194 } 195 })); 196 }, "Test that encodingInfo rejects if the video configuration contentType has a codecs parameter that indicates both an audio and a video codec"); 197 198 promise_test(t => { 199 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 200 type: 'record', 201 audio: { contentType: 'fgeoa' }, 202 })); 203 }, "Test that encodingInfo rejects if the audio configuration contenType doesn't parse"); 204 205 promise_test(t => { 206 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 207 type: 'record', 208 audio: { contentType: 'video/fgeoa' }, 209 })); 210 }, "Test that encodingInfo rejects if the audio configuration contentType isn't of type audio"); 211 212 promise_test(t => { 213 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 214 type: 'record', 215 audio: { contentType: 'audio/webm; codecs="opus"; foo="bar"' }, 216 })); 217 }, "Test that encodingInfo rejects if the audio configuration contentType has more than one parameters"); 218 219 promise_test(t => { 220 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 221 type: 'record', 222 audio: { contentType: 'audio/webm; foo="bar"' }, 223 })); 224 }, "Test that encodingInfo rejects if the audio configuration contentType has one parameter that isn't codecs"); 225 226 promise_test(t => { 227 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 228 type: 'record', 229 audio: { contentType: 'audio/webm' }, 230 })); 231 }, "Test that encodingInfo rejects if the audio configuration contentType does not imply a single media codec but has no codecs parameter"); 232 233 promise_test(t => { 234 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 235 type: 'record', 236 audio: { contentType: 'audio/webm; codecs="vorbis, opus"' }, 237 })); 238 }, "Test that encodingInfo rejects if the audio configuration contentType has a codecs parameter that indicates multiple audio codecs"); 239 240 promise_test(t => { 241 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 242 type: 'record', 243 audio: { contentType: 'audio/webm; codecs="vp09.00.10.08, opus"' }, 244 })); 245 }, "Test that encodingInfo rejects if the audio configuration contentType has a codecs parameter that indicates both an audio and a video codec"); 246 247 promise_test(t => { 248 return navigator.mediaCapabilities.encodingInfo({ 249 type: 'record', 250 video: minimalVideoConfiguration, 251 audio: minimalAudioConfiguration, 252 }).then(ability => { 253 assert_equals(typeof ability.supported, "boolean"); 254 assert_equals(typeof ability.smooth, "boolean"); 255 assert_equals(typeof ability.powerEfficient, "boolean"); 256 }); 257 }, "Test that encodingInfo returns a valid MediaCapabilitiesInfo object for record type"); 258 259 async_test(t => { 260 var validTypes = [ 'record', 'webrtc' ]; 261 var invalidTypes = [ undefined, null, '', 'foobar', 'mse', 'MediaSource', 262 'file', 'media-source', ]; 263 264 var validPromises = []; 265 var invalidCaught = 0; 266 267 validTypes.forEach(type => { 268 validPromises.push(navigator.mediaCapabilities.encodingInfo({ 269 type: type, 270 video: type != "webrtc" ? minimalVideoConfiguration : minimalWebrtcVideoConfiguration, 271 audio: type != "webrtc" ? minimalAudioConfiguration : minimalWebrtcAudioConfiguration, 272 })); 273 }); 274 275 // validTypes are tested via Promise.all(validPromises) because if one of the 276 // promises fail, Promise.all() will reject. This mechanism can't be used for 277 // invalid types which will be tested individually and increment invalidCaught 278 // when rejected until the amount of rejection matches the expectation. 279 Promise.all(validPromises).then(t.step_func(() => { 280 for (var i = 0; i < invalidTypes.length; ++i) { 281 navigator.mediaCapabilities.encodingInfo({ 282 type: invalidTypes[i], 283 video: minimalVideoConfiguration, 284 audio: minimalAudioConfiguration, 285 }).then(t.unreached_func(), t.step_func(e => { 286 assert_equals(e.name, 'TypeError'); 287 ++invalidCaught; 288 if (invalidCaught == invalidTypes.length) 289 t.done(); 290 })); 291 } 292 }), t.unreached_func('Promise.all should not reject for valid types')); 293 }, "Test that encodingInfo rejects if the MediaConfiguration does not have a valid type");