Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html

Issue 543173002: Implement MediaKeySession.generateRequest() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>Test EME syntax</title> 4 <title>Test EME syntax</title>
5 <script src="encrypted-media-utils.js"></script> 5 <script src="encrypted-media-utils.js"></script>
6 <script src="../../resources/testharness.js"></script> 6 <script src="../../resources/testharness.js"></script>
7 <script src="../../resources/testharnessreport.js"></script> 7 <script src="../../resources/testharnessreport.js"></script>
8 </head> 8 </head>
9 <body> 9 <body>
10 <div id="log"></div> 10 <div id="log"></div>
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 test.done(); 117 test.done();
118 }).catch(function(error) { 118 }).catch(function(error) {
119 forceTestFailureFromPromise(test, error, 'create() tests fai led'); 119 forceTestFailureFromPromise(test, error, 'create() tests fai led');
120 }); 120 });
121 }, 'Test MediaKeys create().'); 121 }, 'Test MediaKeys create().');
122 122
123 var kCreateSessionExceptionsTestCases = [ 123 var kCreateSessionExceptionsTestCases = [
124 // Tests in this set use a shortened parameter name due to 124 // Tests in this set use a shortened parameter name due to
125 // format_value() only returning the first 60 characters as the 125 // format_value() only returning the first 60 characters as the
126 // result. With a longer name the first 60 characters is not 126 // result. With a longer name the first 60 characters is not
127 // enough to determine which test failed. Even with the 127 // enough to determine which test failed.
128 // shortened name, the error message for the last couple of
129 // tests is the same.
130 128
131 // Too few parameters. 129 // Invalid parameters.
132 { 130 {
133 exception: 'TypeError', 131 exception: 'TypeError',
134 func: function(mk) { return mk.createSession(); } 132 func: function(mk) { return mk.createSession(); }
135 }, 133 },
136 { 134 {
137 exception: 'TypeError', 135 exception: 'TypeError',
138 func: function(mk) { return mk.createSession(''); } 136 func: function(mk) { return mk.createSession(''); }
139 }, 137 },
140 { 138 {
141 exception: 'TypeError', 139 exception: 'TypeError',
142 func: function(mk) { return mk.createSession(null); } 140 func: function(mk) { return mk.createSession(null); }
143 }, 141 },
144 { 142 {
145 exception: 'TypeError', 143 exception: 'TypeError',
146 func: function(mk) { return mk.createSession(undefined); } 144 func: function(mk) { return mk.createSession(undefined); }
147 }, 145 },
148 { 146 {
149 exception: 'TypeError', 147 exception: 'TypeError',
150 func: function(mk) { return mk.createSession(1); } 148 func: function(mk) { return mk.createSession(1); }
151 }, 149 },
152 { 150 {
153 exception: 'TypeError', 151 exception: 'TypeError',
154 func: function(mk) { return mk.createSession(new Uint8Array( 0)); } 152 func: function(mk) { return mk.createSession(new Uint8Array( 0)); }
155 }, 153 },
156 { 154 {
157 exception: 'TypeError', 155 exception: 'TypeError',
158 func: function(mk, _, initData) { return mk.createSession(in itData); } 156 func: function(mk) { return mk.createSession('TEMPORARY'); }
157 }
158 ];
159
160 async_test(function(test)
161 {
162 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
163 var sessionPromises = kCreateSessionExceptionsTestCases.map( function(testCase) {
164 return test_exception(testCase, mediaKeys);
165 });
166
167 assert_not_equals(sessionPromises.length, 0);
168 return Promise.all(sessionPromises);
169 }).then(function(result) {
170 test.done();
171 }).catch(function(error) {
172 forceTestFailureFromPromise(test, error, 'createSession() te sts failed');
173 });
174 }, 'Test MediaKeys createSession() exceptions.');
175
176 var kGenerateRequestExceptionsTestCases = [
177 // Tests in this set use a shortened parameter name due to
178 // format_value() only returning the first 60 characters as the
179 // result. With a longer name the first 60 characters is not
180 // enough to determine which test failed. Even with the
181 // shortened name, the error message for the last couple of
182 // tests is the same.
183 // Too few parameters.
184 {
185 exception: 'TypeError',
186 func: function(mk1) { return mk1.createSession().generateReq uest(); }
187 },
188 {
189 exception: 'TypeError',
190 func: function(mk2) { return mk2.createSession().generateReq uest(''); }
191 },
192 {
193 exception: 'TypeError',
194 func: function(mk3) { return mk3.createSession().generateReq uest(null); }
195 },
196 {
197 exception: 'TypeError',
198 func: function(mk4) { return mk4.createSession().generateReq uest(undefined); }
199 },
200 {
201 exception: 'TypeError',
202 func: function(mk5) { return mk5.createSession().generateReq uest(1); }
203 },
204 {
205 exception: 'TypeError',
206 func: function(mk6) { return mk6.createSession().generateReq uest(new Uint8Array(0)); }
207 },
208 {
209 exception: 'TypeError',
210 func: function(mk7, _, initData) { return mk7.createSession( ).generateRequest(initData); }
159 }, 211 },
160 // Invalid parameters. 212 // Invalid parameters.
161 { 213 {
162 exception: 'InvalidAccessError', 214 exception: 'InvalidAccessError',
163 func: function(mk, _, initData) { return mk.createSession('' , initData); } 215 func: function(mk8, _, initData) { return mk8.createSession( ).generateRequest('', initData); }
164 }, 216 },
165 // Not supported contentTypes. 217 // Not supported initDataTypes.
166 { 218 {
167 exception: 'NotSupportedError', 219 exception: 'NotSupportedError',
168 func: function(mk, _, initData) { return mk.createSession(nu ll, initData); } 220 func: function(mk9, _, initData) { return mk9.createSession( ).generateRequest(null, initData); }
169 }, 221 },
170 { 222 {
171 exception: 'NotSupportedError', 223 exception: 'NotSupportedError',
172 func: function(mk, _, initData) { return mk.createSession(un defined, initData); } 224 func: function(mk10, _, initData) { return mk10.createSessio n().generateRequest(undefined, initData); }
173 }, 225 },
174 { 226 {
175 exception: 'NotSupportedError', 227 exception: 'NotSupportedError',
176 func: function(mk, _, initData) { return mk.createSession(1, initData); } 228 func: function(mk11, _, initData) { return mk11.createSessio n().generateRequest(1, initData); }
177 }, 229 },
178 { 230 {
179 exception: 'NotSupportedError', 231 exception: 'NotSupportedError',
180 func: function(mk, _, initData) { return mk.createSession(ne w Uint8Array(0), initData); } 232 func: function(mk12, _, initData) { return mk12.createSessio n().generateRequest(new Uint8Array(0), initData); }
181 }, 233 },
182 { 234 {
183 exception: 'NotSupportedError', 235 exception: 'NotSupportedError',
184 func: function(mk, _, initData) { return mk.createSession('u nsupported', initData); } 236 func: function(mk13, _, initData) { return mk13.createSessio n().generateRequest('unsupported', initData); }
185 }, 237 },
186 { 238 {
187 exception: 'NotSupportedError', 239 exception: 'NotSupportedError',
188 func: function(mk, _, initData) { return mk.createSession('v ideo/foo', initData); } 240 func: function(mk14, _, initData) { return mk14.createSessio n().generateRequest('video/foo', initData); }
189 }, 241 },
190 { 242 {
191 exception: 'NotSupportedError', 243 exception: 'NotSupportedError',
192 func: function(mk, _, initData) { return mk.createSession('t ext/webm', initData); } 244 func: function(mk15, _, initData) { return mk15.createSessio n().generateRequest('text/webm', initData); }
193 } 245 }
194 // FIXME: Enable when switching to initDataType from MIME type. 246 // FIXME: Enable when switching to initDataType from MIME type.
195 // http://crbug.com/385874. 247 // http://crbug.com/385874.
196 // { 248 // {
197 // exception: 'NotSupportedError', 249 // exception: 'NotSupportedError',
198 // func: function(mk, _, initData) { return mk.createSession ('video/webm', initData); } 250 // func: function(mk16, _, initData) { return mk16.createSes sion('video/webm', initData); }
199 // } 251 // }
200 ]; 252 ];
201 253
202 var kTypeSpecificCreateSessionExceptionsTestCases = [ 254 var kTypeSpecificGenerateRequestExceptionsTestCases = [
203 // Tests in this set use a shortened parameter name due to 255 // Tests in this set use a shortened parameter name due to
204 // format_value() only returning the first 60 characters as the 256 // format_value() only returning the first 60 characters as the
205 // result. With a longer name the first 60 characters is not 257 // result. With a longer name the first 60 characters is not
206 // enough to determine which test failed. Even with the 258 // enough to determine which test failed. Even with the
207 // shortened name, the error message for the last couple of 259 // shortened name, the error message for the last couple of
208 // tests is the same. 260 // tests is the same.
209 261
210 // Too few parameters. 262 // Too few parameters.
211 { 263 {
212 exception: 'TypeError', 264 exception: 'TypeError',
213 func: function(mk, type) { return mk.createSession(type); } 265 func: function(mk1, type) { return mk1.createSession().gener ateRequest(type); }
214 }, 266 },
215 // Invalid parameters. 267 // Invalid parameters.
216 { 268 {
217 exception: 'TypeError', 269 exception: 'TypeError',
218 func: function(mk, type) { return mk.createSession(type, '') ; } 270 func: function(mk2, type) { return mk2.createSession().gener ateRequest(type, ''); }
219 }, 271 },
220 { 272 {
221 exception: 'TypeError', 273 exception: 'TypeError',
222 func: function(mk, type) { return mk.createSession(type, nul l); } 274 func: function(mk3, type) { return mk3.createSession().gener ateRequest(type, null); }
223 }, 275 },
224 { 276 {
225 exception: 'TypeError', 277 exception: 'TypeError',
226 func: function(mk, type) { return mk.createSession(type, und efined); } 278 func: function(mk4, type) { return mk4.createSession().gener ateRequest(type, undefined); }
227 }, 279 },
228 { 280 {
229 exception: 'TypeError', 281 exception: 'TypeError',
230 func: function(mk, type) { return mk.createSession(type, 1); } 282 func: function(mk5, type) { return mk5.createSession().gener ateRequest(type, 1); }
231 }, 283 },
232 { 284 {
233 exception: 'InvalidAccessError', 285 exception: 'InvalidAccessError',
234 func: function(mk, type) { return mk.createSession(type, new Uint8Array(0)); } 286 func: function(mk6, type) { return mk6.createSession().gener ateRequest(type, new Uint8Array(0)); }
235 },
236 // Invalid sessionTypes. Added index to each variable name as
237 // otherwise the first 60 characters of func: is the same.
238 {
239 exception: 'TypeError',
240 func: function(mk1, type, initData) { return mk1.createSessi on(type, initData, ''); }
241 },
242 {
243 exception: 'TypeError',
244 func: function(mk2, type, initData) { return mk2.createSessi on(type, initData, null); }
245 },
246 {
247 exception: 'TypeError',
248 func: function(mk3, type, initData) { return mk3.createSessi on(type, initData, 1); }
249 },
250 {
251 exception: 'TypeError',
252 func: function(mk4, type, initData) { return mk4.createSessi on(type, initData, new Uint8Array(0)); }
253 },
254 {
255 exception: 'TypeError',
256 func: function(mk5, type, initData) { return mk5.createSessi on(type, initData, 'unsupported'); }
257 },
258 {
259 exception: 'TypeError',
260 func: function(mk6, type, initData) { return mk6.createSessi on(type, initData, 'TEMPORARY'); }
261 } 287 }
262 ]; 288 ];
263 289
264 async_test(function(test) 290 async_test(function(test)
265 { 291 {
266 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { 292 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
267 // FIXME: Remove "video/" from the calls to isTypeSupported( ) once it is updated. 293 // FIXME: Remove "video/" from the calls to isTypeSupported( ) once it is updated.
268 // http://crbug.com/405731. 294 // http://crbug.com/405731.
269 var initData = stringToUint8Array('init data'); 295 var initData = stringToUint8Array('init data');
270 var sessionPromises = kCreateSessionExceptionsTestCases.map( function(testCase) { 296 var sessionPromises = kGenerateRequestExceptionsTestCases.ma p(function(testCase) {
271 return test_exception(testCase, mediaKeys, '', initData) ; 297 return test_exception(testCase, mediaKeys, '', initData) ;
272 }); 298 });
273 299
274 // Test that WebM sessions generate the expected error, if 300 // Test that WebM sessions generate the expected error, if
275 // supported. 301 // supported.
276 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) { 302 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) {
277 var WebmSessionPromises = kTypeSpecificCreateSessionExce ptionsTestCases.map(function(testCase) { 303 var WebmSessionPromises = kTypeSpecificGenerateRequestEx ceptionsTestCases.map(function(testCase) {
278 return test_exception(testCase, mediaKeys, 'webm', g etInitData('webm')); 304 return test_exception(testCase, mediaKeys, 'webm', g etInitData('webm'));
279 }); 305 });
280 sessionPromises = sessionPromises.concat(WebmSessionProm ises); 306 sessionPromises = sessionPromises.concat(WebmSessionProm ises);
281 } 307 }
282 308
283 // Repeat for MP4, if supported. 309 // Repeat for MP4, if supported.
284 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) { 310 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) {
285 var mp4SessionPromises = kTypeSpecificCreateSessionExcep tionsTestCases.map(function(testCase) { 311 var mp4SessionPromises = kTypeSpecificGenerateRequestExc eptionsTestCases.map(function(testCase) {
286 return test_exception(testCase, mediaKeys, 'cenc', g etInitData('cenc')); 312 return test_exception(testCase, mediaKeys, 'cenc', g etInitData('cenc'));
287 }); 313 });
288 sessionPromises = sessionPromises.concat(mp4SessionPromi ses); 314 sessionPromises = sessionPromises.concat(mp4SessionPromi ses);
289 } 315 }
290 316
291 assert_not_equals(sessionPromises.length, 0); 317 assert_not_equals(sessionPromises.length, 0);
292 return Promise.all(sessionPromises); 318 return Promise.all(sessionPromises);
293 }).then(function(result) { 319 }).then(function(result) {
294 test.done(); 320 test.done();
295 }).catch(function(error) { 321 }).catch(function(error) {
296 forceTestFailureFromPromise(test, error, 'createSession() te sts failed'); 322 forceTestFailureFromPromise(test, error, 'generateRequest() tests failed');
297 }); 323 });
298 }, 'Test MediaKeys createSession() exceptions.'); 324 }, 'Test MediaKeys generateRequest() exceptions.');
299 325
300 // All calls to |func| in this group are supposed to succeed. 326 // All calls to |func| in this group are supposed to succeed.
301 // However, the spec notes that some things are optional for 327 // However, the spec notes that some things are optional for
302 // Clear Key. In particular, support for persistent sessions 328 // Clear Key. In particular, support for persistent sessions
303 // is optional. Since some implementations won't support some 329 // is optional. Since some implementations won't support some
304 // features, a NotSupportedError is treated as a success 330 // features, a NotSupportedError is treated as a success
305 // if |isNotSupportedAllowed| is true. 331 // if |isNotSupportedAllowed| is true.
306 var kCreateSessionTestCases = [ 332 var kCreateSessionTestCases = [
307 // Added index to each variable name as otherwise the first 60
308 // characters of |func| is the same.
309
310 // Use the default sessionType. 333 // Use the default sessionType.
311 { 334 {
312 func: function(mk1, type, initData) { return mk1.createSessi on(type, initData); }, 335 func: function(mk) { return mk.createSession(); },
313 isNotSupportedAllowed: false 336 isNotSupportedAllowed: false
314 }, 337 },
315 // Try variations of sessionType. 338 // Try variations of sessionType.
316 { 339 {
317 func: function(mk2, type, initData) { return mk2.createSessi on(type, initData, 'temporary'); }, 340 func: function(mk) { return mk.createSession('temporary'); } ,
318 isNotSupportedAllowed: false 341 isNotSupportedAllowed: false
319 }, 342 },
320 { 343 {
321 func: function(mk3, type, initData) { return mk3.createSessi on(type, initData, undefined); }, 344 func: function(mk) { return mk.createSession(undefined); },
322 isNotSupportedAllowed: false 345 isNotSupportedAllowed: false
323 }, 346 },
324 { 347 {
325 // Since this is optional, some Clear Key implementations 348 // Since this is optional, some Clear Key implementations
326 // will succeed, others will return a "NotSupportedError". 349 // will succeed, others will return a "NotSupportedError".
327 // Both are allowed results. 350 // Both are allowed results.
328 func: function(mk4, type, initData) { return mk4.createSessi on(type, initData, 'persistent'); }, 351 func: function(mk) { return mk.createSession('persistent'); },
329 isNotSupportedAllowed: true 352 isNotSupportedAllowed: true
330 }, 353 },
331 // Try additional parameter, which should be ignored. 354 // Try additional parameter, which should be ignored.
332 { 355 {
333 func: function(mk5, type, initData) { return mk5.createSessi on(type, initData, 'temporary', 'extra'); }, 356 func: function(mk) { return mk.createSession('temporary', 'e xtra'); },
334 isNotSupportedAllowed: false 357 isNotSupportedAllowed: false
335 } 358 }
336 ]; 359 ];
337 360
338 // This function checks that calling |testCase.func| creates a 361 // This function checks that calling |testCase.func| creates a
339 // MediaKeySession object with some default values. It also 362 // MediaKeySession object with some default values. It also
340 // allows for an NotSupportedError to be generated and treated as a 363 // allows for an NotSupportedError to be generated and treated as a
341 // success, if allowed. See comment above kCreateSessionTestCases. 364 // success, if allowed. See comment above kCreateSessionTestCases.
342 function test_createSession(testCase /*...*/) 365 function test_createSession(testCase, mediaKeys)
343 { 366 {
344 var func = testCase.func; 367 var mediaKeySession;
345 var isNotSupportedAllowed = testCase.isNotSupportedAllowed; 368 try {
346 var args = Array.prototype.slice.call(arguments, 1); 369 mediaKeySession = testCase.func.call(null, mediaKeys);
370 } catch (e) {
371 assert_true(testCase.isNotSupportedAllowed);
372 return;
373 }
347 374
348 return func.apply(null, args).then( 375 // FIXME: Update this set of tests when done
349 function(mediaKeySession) 376 // implementing the latest spec.
350 { 377 assert_equals(typeof mediaKeySession, 'object');
351 // FIXME: Update this set of tests when done 378 assert_equals(typeof mediaKeySession.addEventListener, 'function ');
352 // implementing the latest spec. 379 assert_equals(typeof mediaKeySession.generateRequest, 'function' );
353 assert_not_equals(mediaKeySession, null); 380 assert_equals(typeof mediaKeySession.update, 'function');
354 assert_equals(typeof mediaKeySession, 'object'); 381 assert_equals(typeof mediaKeySession.release, 'function');
355 assert_equals(typeof mediaKeySession.addEventListener, ' function'); 382 assert_equals(mediaKeySession.error, null);
356 assert_equals(typeof mediaKeySession.update, 'function') ; 383 assert_equals(mediaKeySession.sessionId, '');
357 assert_equals(mediaKeySession.error, null); 384 assert_equals(typeof mediaKeySession.sessionId, 'string');
358 assert_true(mediaKeySession.sessionId && mediaKeySession .sessionId.length > 0); 385 assert_equals(typeof mediaKeySession.onopen, 'undefined');
359 assert_equals(typeof mediaKeySession.sessionId, 'string' ); 386 assert_equals(typeof mediaKeySession.onmessage, 'undefined');
360 assert_equals(typeof mediaKeySession.onopen, 'undefined' ); 387 assert_equals(typeof mediaKeySession.onclose, 'undefined');
361 assert_equals(typeof mediaKeySession.onmessage, 'undefin ed'); 388 assert_equals(typeof mediaKeySession.onerror, 'undefined');
362 assert_equals(typeof mediaKeySession.onclose, 'undefined ');
363 assert_equals(typeof mediaKeySession.onerror, 'undefined ');
364 },
365 function(error)
366 {
367 assert_true(isNotSupportedAllowed, format_value(func));
368 assert_equals(error.name, 'NotSupportedError', format_va lue(func));
369 assert_not_equals(error.message, "", format_value(func)) ;
370 }
371 );
372 } 389 }
373 390
374 async_test(function(test) 391 async_test(function(test)
392 {
393 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
394 kCreateSessionTestCases.map(function(testCase) {
395 test_createSession(testCase, mediaKeys);
396 });
397 test.done();
398 }).catch(function(error) {
399 forceTestFailureFromPromise(test, error, 'createSession() te sts failed');
400 });
401 }, 'Test MediaKeys createSession().');
402
403 // This function checks that calling generateRequest() works for
404 // various sessions. |testCase.func| creates a MediaKeySession
405 // object, and then generateRequest() is called on that object. It
406 // allows for an NotSupportedError to be generated and treated as a
407 // success, if allowed. See comment above kCreateSessionTestCases.
408 function test_generateRequest(testCase, mediaKeys, type, initData)
409 {
410 var mediaKeySession;
411 try {
412 mediaKeySession = testCase.func.call(null, mediaKeys);
413 } catch (e) {
414 assert_true(testCase.isNotSupportedAllowed);
415 return new Promise(new Promise(function() {}));
416 }
417 return mediaKeySession.generateRequest(type, initData);
418 }
419
420 async_test(function(test)
375 { 421 {
376 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { 422 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
377 var sessionPromises = []; 423 var sessionPromises = [];
378 424
379 // Test that WebM sessions generate the expected error, if 425 // Test that WebM sessions generate the expected error, if
380 // supported. 426 // supported.
381 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) { 427 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) {
382 var WebmSessionPromises = kCreateSessionTestCases.map(fu nction(testCase) { 428 var WebmSessionPromises = kCreateSessionTestCases.map(fu nction(testCase) {
383 return test_createSession(testCase, mediaKeys, 'webm ', getInitData('webm')); 429 return test_generateRequest(testCase, mediaKeys, 'we bm', getInitData('webm'));
384 }); 430 });
385 sessionPromises = sessionPromises.concat(WebmSessionProm ises); 431 sessionPromises = sessionPromises.concat(WebmSessionProm ises);
386 } 432 }
387 433
388 // Repeat for MP4, if supported. 434 // Repeat for MP4, if supported.
389 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) { 435 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) {
390 var mp4SessionPromises = kCreateSessionTestCases.map(fun ction(testCase) { 436 var mp4SessionPromises = kCreateSessionTestCases.map(fun ction(testCase) {
391 return test_createSession(testCase, mediaKeys, 'cenc ', getInitData('cenc')); 437 return test_generateRequest(testCase, mediaKeys, 'ce nc', getInitData('cenc'));
392 }); 438 });
393 sessionPromises = sessionPromises.concat(mp4SessionPromi ses); 439 sessionPromises = sessionPromises.concat(mp4SessionPromi ses);
394 } 440 }
395 441
396 assert_not_equals(sessionPromises.length, 0); 442 assert_not_equals(sessionPromises.length, 0);
397 return Promise.all(sessionPromises); 443 return Promise.all(sessionPromises);
398 }).then(function(result) { 444 }).then(function(result) {
399 test.done(); 445 test.done();
400 }).catch(function(error) { 446 }).catch(function(error) {
401 forceTestFailureFromPromise(test, error, 'createSession() te sts failed'); 447 forceTestFailureFromPromise(test, error, 'generateRequest() tests failed');
402 }); 448 });
403 }, 'Test MediaKeys createSession().'); 449 }, 'Test MediaKeys generateRequest().');
404 450
405 var kUpdateSessionExceptionsTestCases = [ 451 var kUpdateSessionExceptionsTestCases = [
406 // Tests in this set use a shortened parameter name due to 452 // Tests in this set use a shortened parameter name due to
407 // format_value() only returning the first 60 characters as the 453 // format_value() only returning the first 60 characters as the
408 // result. With a longer name (mediaKeySession) the first 60 454 // result. With a longer name (mediaKeySession) the first 60
409 // characters is not enough to determine which test failed. 455 // characters is not enough to determine which test failed.
410 456
411 // Too few parameters. 457 // Too few parameters.
412 { 458 {
413 exception: 'TypeError', 459 exception: 'TypeError',
(...skipping 15 matching lines...) Expand all
429 { 475 {
430 exception: 'TypeError', 476 exception: 'TypeError',
431 func: function(s) { return s.update(1); } 477 func: function(s) { return s.update(1); }
432 }, 478 },
433 { 479 {
434 exception: 'InvalidAccessError', 480 exception: 'InvalidAccessError',
435 func: function(s) { return s.update(new Uint8Array(0)); } 481 func: function(s) { return s.update(new Uint8Array(0)); }
436 } 482 }
437 ]; 483 ];
438 484
439 function create_update_exception_test(mediaKeys, type, initData)
440 {
441 var mediaKeySession;
442 var promise = mediaKeys.createSession(type, initData).then(funct ion(mediaKeySession) {
443 var updatePromises = kUpdateSessionExceptionsTestCases.map(f unction(testCase) {
444 return test_exception(testCase, mediaKeySession);
445 });
446 return Promise.all(updatePromises);
447 });
448 return promise;
449 }
450
451 async_test(function(test) 485 async_test(function(test)
452 { 486 {
453 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { 487 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
454 var promises = []; 488 var promises = [];
455 489
456 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) { 490 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) {
457 promises.push(create_update_exception_test(mediaKeys, 'w ebm', getInitData('webm'))); 491 var WebmSessionPromises = kUpdateSessionExceptionsTestCa ses.map(function(testCase) {
492 var mediaKeySession = mediaKeys.createSession();
493 return mediaKeySession.generateRequest('webm', getIn itData('webm')).then(function(result) {
494 return test_exception(testCase, mediaKeySession) ;
495 });
496 });
497 promises = promises.concat(WebmSessionPromises);
458 } 498 }
459 499
460 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) { 500 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) {
461 promises.push(create_update_exception_test(mediaKeys, 'c enc', getInitData('cenc'))); 501 var mp4SessionPromises = kUpdateSessionExceptionsTestCas es.map(function(testCase) {
502 var mediaKeySession = mediaKeys.createSession();
503 return mediaKeySession.generateRequest('cenc', getInit Data('cenc')).then(function(result) {
504 return test_exception(testCase, mediaKeySession);
505 });
506 });
507 promises = promises.concat(mp4SessionPromises);
462 } 508 }
463 509
464 assert_not_equals(promises.length, 0); 510 assert_not_equals(promises.length, 0);
465 return Promise.all(promises); 511 return Promise.all(promises);
466 }).then(function(result) { 512 }).then(function(result) {
467 test.done(); 513 test.done();
468 }).catch(function(error) { 514 }).catch(function(error) {
469 forceTestFailureFromPromise(test, error, 'update() tests fai led'); 515 forceTestFailureFromPromise(test, error, 'update() tests fai led');
470 }); 516 });
471 }, 'Test MediaKeySession update() exceptions.'); 517 }, 'Test MediaKeySession update() exceptions.');
472 518
473 function create_update_test(mediaKeys, type, initData) 519 function create_update_test(mediaKeys, type, initData)
474 { 520 {
475 var mediaKeySession; 521 var mediaKeySession = mediaKeys.createSession();
476 var promise = mediaKeys.createSession(type, initData).then(funct ion(result) { 522 var promise = mediaKeySession.generateRequest(type, initData).th en(function(result) {
477 mediaKeySession = result;
478 var validLicense = stringToUint8Array(createJWKSet(createJWK (stringToUint8Array('123'), stringToUint8Array('1234567890abcdef')))); 523 var validLicense = stringToUint8Array(createJWKSet(createJWK (stringToUint8Array('123'), stringToUint8Array('1234567890abcdef'))));
479 return mediaKeySession.update(validLicense); 524 return mediaKeySession.update(validLicense);
480 }).then(function(result) { 525 }).then(function(result) {
481 // Call update() with a different license and an extra 526 // Call update() with a different license and an extra
482 // parameter. The extra parameter is ignored. 527 // parameter. The extra parameter is ignored.
483 var validLicense = stringToUint8Array(createJWKSet(createJWK (stringToUint8Array('4567890'), stringToUint8Array('01234567890abcde')))); 528 var validLicense = stringToUint8Array(createJWKSet(createJWK (stringToUint8Array('4567890'), stringToUint8Array('01234567890abcde'))));
484 return mediaKeySession.update(validLicense, 'extra'); 529 return mediaKeySession.update(validLicense, 'extra');
485 }); 530 });
486 return promise; 531 return promise;
487 } 532 }
(...skipping 15 matching lines...) Expand all
503 return Promise.all(promises); 548 return Promise.all(promises);
504 }).then(function(result) { 549 }).then(function(result) {
505 test.done(); 550 test.done();
506 }).catch(function(error) { 551 }).catch(function(error) {
507 forceTestFailureFromPromise(test, error, 'update() tests fai led'); 552 forceTestFailureFromPromise(test, error, 'update() tests fai led');
508 }); 553 });
509 }, 'Test MediaKeySession update().'); 554 }, 'Test MediaKeySession update().');
510 555
511 function create_release_test(mediaKeys, type, initData) 556 function create_release_test(mediaKeys, type, initData)
512 { 557 {
513 var mediaKeySession; 558 var mediaKeySession = mediaKeys.createSession();
514 var promise = mediaKeys.createSession(type, initData).then(funct ion(result) { 559 var promise = mediaKeySession.generateRequest(type, initData).th en(function(result) {
515 mediaKeySession = result;
516 return mediaKeySession.release(); 560 return mediaKeySession.release();
517 // FIXME: Uncomment once the code supports multiple release() ca lls. 561 // FIXME: Uncomment once the code supports multiple release() ca lls.
518 // }).then(function(result) { 562 // }).then(function(result) {
519 // // Call release() again with an extra parameter. The extra 563 // // Call release() again with an extra parameter. The extra
520 // // parameter is ignored. 564 // // parameter is ignored.
521 // return mediaKeySession.release('extra'); 565 // return mediaKeySession.release('extra');
522 }); 566 });
523 return promise; 567 return promise;
524 } 568 }
525 569
(...skipping 18 matching lines...) Expand all
544 forceTestFailureFromPromise(test, error, 'release() tests fa iled'); 588 forceTestFailureFromPromise(test, error, 'release() tests fa iled');
545 }); 589 });
546 }, 'Test MediaKeySession release().'); 590 }, 'Test MediaKeySession release().');
547 591
548 // FIXME: Add syntax checks for MediaKeys.IsTypeSupported(). 592 // FIXME: Add syntax checks for MediaKeys.IsTypeSupported().
549 // FIXME: Add syntax checks for MediaKeyError and MediaKeySession ev ents. 593 // FIXME: Add syntax checks for MediaKeyError and MediaKeySession ev ents.
550 // FIXME: Add HTMLMediaElement syntax checks, e.g. setMediaKeys, med iakeys, onneedkey. 594 // FIXME: Add HTMLMediaElement syntax checks, e.g. setMediaKeys, med iakeys, onneedkey.
551 </script> 595 </script>
552 </body> 596 </body>
553 </html> 597 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698