Skip to content

Commit d3d219e

Browse files
authored
Add some Media Capabilities API tests (#49140)
* Add some Media Capabilities API tests Per spec draft at https://www.w3.org/TR/2024/WD-media-capabilities-20241007/ - Test for 'does not imply a codec' - Test for 'valid MIME type string' - Test for 'single media codec' * Add encodingInfo tests * Fixed mediaCapabilities.decodingInfo() test case
1 parent 1943797 commit d3d219e

File tree

2 files changed

+173
-17
lines changed

2 files changed

+173
-17
lines changed

media-capabilities/decodingInfo.any.js

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ promise_test(t => {
110110
}));
111111
}, "Test that decodingInfo rejects if the video configuration contentType doesn't parse");
112112

113+
// See https://mimesniff.spec.whatwg.org/#example-valid-mime-type-string
114+
promise_test(t => {
115+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
116+
type: 'file',
117+
video: {
118+
contentType: 'video/webm;',
119+
width: 800,
120+
height: 600,
121+
bitrate: 3000,
122+
framerate: 24,
123+
},
124+
}));
125+
}, "Test that decodingInfo rejects if the video configuration contentType is not a valid MIME type string");
126+
113127
promise_test(t => {
114128
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
115129
type: 'file',
@@ -172,6 +186,45 @@ promise_test(t => {
172186
}));
173187
}, "Test that decodingInfo rejects if the video configuration contentType has one parameter that isn't codecs");
174188

189+
promise_test(t => {
190+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
191+
type: 'file',
192+
video: {
193+
contentType: 'video/webm',
194+
width: 800,
195+
height: 600,
196+
bitrate: 3000,
197+
framerate: 24,
198+
},
199+
}));
200+
}, "Test that decodingInfo rejects if the video configuration contentType does not imply a single media codec but has no codecs parameter");
201+
202+
promise_test(t => {
203+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
204+
type: 'file',
205+
video: {
206+
contentType: 'video/webm; codecs="vp09.00.10.08, vp8"',
207+
width: 800,
208+
height: 600,
209+
bitrate: 3000,
210+
framerate: 24,
211+
}
212+
}));
213+
}, "Test that decodingInfo rejects if the video configuration contentType has a codecs parameter that indicates multiple video codecs");
214+
215+
promise_test(t => {
216+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
217+
type: 'file',
218+
video: {
219+
contentType: 'video/webm; codecs="vp09.00.10.08, opus"',
220+
width: 800,
221+
height: 600,
222+
bitrate: 3000,
223+
framerate: 24,
224+
}
225+
}));
226+
}, "Test that decodingInfo rejects if the video configuration contentType has a codecs parameter that indicates both an audio and a video codec");
227+
175228
promise_test(t => {
176229
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
177230
type: 'file',
@@ -183,7 +236,7 @@ promise_test(t => {
183236
framerate: '24000/1001',
184237
}
185238
}));
186-
}, "Test that decodingInfo() rejects framerate in the form of x/y");
239+
}, "Test that decodingInfo rejects framerate in the form of x/y");
187240

188241
promise_test(t => {
189242
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
@@ -196,7 +249,7 @@ promise_test(t => {
196249
framerate: '24000/0',
197250
}
198251
}));
199-
}, "Test that decodingInfo() rejects framerate in the form of x/0");
252+
}, "Test that decodingInfo rejects framerate in the form of x/0");
200253

201254
promise_test(t => {
202255
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
@@ -209,7 +262,7 @@ promise_test(t => {
209262
framerate: '0/10001',
210263
}
211264
}));
212-
}, "Test that decodingInfo() rejects framerate in the form of 0/y");
265+
}, "Test that decodingInfo rejects framerate in the form of 0/y");
213266

214267
promise_test(t => {
215268
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
@@ -222,7 +275,7 @@ promise_test(t => {
222275
framerate: '-24000/10001',
223276
}
224277
}));
225-
}, "Test that decodingInfo() rejects framerate in the form of -x/y");
278+
}, "Test that decodingInfo rejects framerate in the form of -x/y");
226279

227280
promise_test(t => {
228281
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
@@ -235,7 +288,7 @@ promise_test(t => {
235288
framerate: '24000/-10001',
236289
}
237290
}));
238-
}, "Test that decodingInfo() rejects framerate in the form of x/-y");
291+
}, "Test that decodingInfo rejects framerate in the form of x/-y");
239292

240293
promise_test(t => {
241294
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
@@ -248,7 +301,7 @@ promise_test(t => {
248301
framerate: '24000/',
249302
}
250303
}));
251-
}, "Test that decodingInfo() rejects framerate in the form of x/");
304+
}, "Test that decodingInfo rejects framerate in the form of x/");
252305

253306
promise_test(t => {
254307
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
@@ -261,14 +314,22 @@ promise_test(t => {
261314
framerate: '1/3x',
262315
}
263316
}));
264-
}, "Test that decodingInfo() rejects framerate with trailing unallowed characters");
317+
}, "Test that decodingInfo rejects framerate with trailing unallowed characters");
265318

266319
promise_test(t => {
267320
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
268321
type: 'file',
269322
audio: { contentType: 'fgeoa' },
270323
}));
271-
}, "Test that decodingInfo rejects if the audio configuration contenType doesn't parse");
324+
}, "Test that decodingInfo rejects if the audio configuration contentType doesn't parse");
325+
326+
// See https://mimesniff.spec.whatwg.org/#example-valid-mime-type-string
327+
promise_test(t => {
328+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
329+
type: 'file',
330+
audio: { contentType: 'audio/mpeg;' },
331+
}));
332+
}, "Test that decodingInfo rejects if the audio configuration contentType is not a valid MIME type string");
272333

273334
promise_test(t => {
274335
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
@@ -282,7 +343,7 @@ promise_test(t => {
282343
type: 'file',
283344
audio: { contentType: 'audio/webm; codecs="opus"; foo="bar"' },
284345
}));
285-
}, "Test that decodingInfo rejects if the audio configuration contentType has more than one parameters");
346+
}, "Test that decodingInfo rejects if the audio configuration contentType has more than one parameter");
286347

287348
promise_test(t => {
288349
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
@@ -291,6 +352,27 @@ promise_test(t => {
291352
}));
292353
}, "Test that decodingInfo rejects if the audio configuration contentType has one parameter that isn't codecs");
293354

355+
promise_test(t => {
356+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
357+
type: 'file',
358+
audio: { contentType: 'audio/webm' },
359+
}));
360+
}, "Test that decodingInfo rejects if the audio configuration contentType does not imply a single media codec but has no codecs parameter");
361+
362+
promise_test(t => {
363+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
364+
type: 'file',
365+
audio: { contentType: 'audio/webm; codecs="vorbis, opus"' },
366+
}));
367+
}, "Test that decodingInfo rejects if the audio configuration contentType has a codecs parameter that indicates multiple audio codecs");
368+
369+
promise_test(t => {
370+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.decodingInfo({
371+
type: 'file',
372+
audio: { contentType: 'audio/webm; codecs="vp09.00.10.08, opus"' },
373+
}));
374+
}, "Test that decodingInfo rejects if the audio configuration contentType has a codecs parameter that indicates both an audio and a video codec");
375+
294376
promise_test(t => {
295377
return navigator.mediaCapabilities.decodingInfo({
296378
type: 'file',

media-capabilities/encodingInfo.any.js

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ promise_test(t => {
103103
}));
104104
}, "Test that encodingInfo rejects if the video configuration contentType doesn't parse");
105105

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+
106120
promise_test(t => {
107121
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
108122
type: 'record',
@@ -142,6 +156,45 @@ promise_test(t => {
142156
}));
143157
}, "Test that encodingInfo rejects if the video configuration contentType has one parameter that isn't codecs");
144158

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+
145198
promise_test(t => {
146199
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
147200
type: 'record',
@@ -153,7 +206,7 @@ promise_test(t => {
153206
framerate: '24000/1001',
154207
}
155208
}));
156-
}, "Test that encodingInfo() rejects framerate in the form of x/y");
209+
}, "Test that encodingInfo rejects framerate in the form of x/y");
157210

158211
promise_test(t => {
159212
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
@@ -166,7 +219,7 @@ promise_test(t => {
166219
framerate: '24000/0',
167220
}
168221
}));
169-
}, "Test that encodingInfo() rejects framerate in the form of x/0");
222+
}, "Test that encodingInfo rejects framerate in the form of x/0");
170223

171224
promise_test(t => {
172225
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
@@ -179,7 +232,7 @@ promise_test(t => {
179232
framerate: '0/10001',
180233
}
181234
}));
182-
}, "Test that encodingInfo() rejects framerate in the form of 0/y");
235+
}, "Test that encodingInfo rejects framerate in the form of 0/y");
183236

184237
promise_test(t => {
185238
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
@@ -192,7 +245,7 @@ promise_test(t => {
192245
framerate: '-24000/10001',
193246
}
194247
}));
195-
}, "Test that encodingInfo() rejects framerate in the form of -x/y");
248+
}, "Test that encodingInfo rejects framerate in the form of -x/y");
196249

197250
promise_test(t => {
198251
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
@@ -205,7 +258,7 @@ promise_test(t => {
205258
framerate: '24000/-10001',
206259
}
207260
}));
208-
}, "Test that encodingInfo() rejects framerate in the form of x/-y");
261+
}, "Test that encodingInfo rejects framerate in the form of x/-y");
209262

210263
promise_test(t => {
211264
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
@@ -218,7 +271,7 @@ promise_test(t => {
218271
framerate: '24000/',
219272
}
220273
}));
221-
}, "Test that encodingInfo() rejects framerate in the form of x/");
274+
}, "Test that encodingInfo rejects framerate in the form of x/");
222275

223276
promise_test(t => {
224277
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
@@ -231,7 +284,7 @@ promise_test(t => {
231284
framerate: '1/3x',
232285
}
233286
}));
234-
}, "Test that encodingInfo() rejects framerate with trailing unallowed characters");
287+
}, "Test that encodingInfo rejects framerate with trailing unallowed characters");
235288

236289
promise_test(t => {
237290
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
@@ -261,6 +314,27 @@ promise_test(t => {
261314
}));
262315
}, "Test that encodingInfo rejects if the audio configuration contentType has one parameter that isn't codecs");
263316

317+
promise_test(t => {
318+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
319+
type: 'record',
320+
audio: { contentType: 'audio/webm' },
321+
}));
322+
}, "Test that encodingInfo rejects if the audio configuration contentType does not imply a single media codec but has no codecs parameter");
323+
324+
promise_test(t => {
325+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
326+
type: 'record',
327+
audio: { contentType: 'audio/webm; codecs="vorbis, opus"' },
328+
}));
329+
}, "Test that encodingInfo rejects if the audio configuration contentType has a codecs parameter that indicates multiple audio codecs");
330+
331+
promise_test(t => {
332+
return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({
333+
type: 'record',
334+
audio: { contentType: 'audio/webm; codecs="vp09.00.10.08, opus"' },
335+
}));
336+
}, "Test that encodingInfo rejects if the audio configuration contentType has a codecs parameter that indicates both an audio and a video codec");
337+
264338
promise_test(t => {
265339
return navigator.mediaCapabilities.encodingInfo({
266340
type: 'record',
@@ -271,7 +345,7 @@ promise_test(t => {
271345
assert_equals(typeof ability.smooth, "boolean");
272346
assert_equals(typeof ability.powerEfficient, "boolean");
273347
});
274-
}, "Test that encodingInfo returns a valid MediaCapabilitiesInfo objects for record type");
348+
}, "Test that encodingInfo returns a valid MediaCapabilitiesInfo object for record type");
275349

276350
async_test(t => {
277351
var validTypes = [ 'record', 'webrtc' ];

0 commit comments

Comments
 (0)