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

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: create early 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. Even with the
128 // shortened name, the error message for the last couple of 128 // shortened name, the error message for the last couple of
ddorwin 2014/09/09 21:35:24 Is this still true? These tests aren't using mk#.
jrummell 2014/09/10 01:18:25 The last sentence is false (for this group), so I
ddorwin 2014/09/10 02:30:51 If they aren't cut off, then remove the false stat
129 // tests is the same. 129 // tests is the same.
130 130
131 // Too few parameters. 131 // Too few parameters.
ddorwin 2014/09/09 21:35:24 These should be copied to generateRequests tests.
jrummell 2014/09/10 01:18:25 Done.
132 { 132 {
133 exception: 'TypeError', 133 exception: 'TypeError',
134 func: function(mk) { return mk.createSession(); } 134 func: function(mk) { return mk.createSession(); }
135 }, 135 },
136 { 136 {
137 exception: 'TypeError', 137 exception: 'TypeError',
138 func: function(mk) { return mk.createSession(''); } 138 func: function(mk) { return mk.createSession(''); }
139 }, 139 },
140 { 140 {
141 exception: 'TypeError', 141 exception: 'TypeError',
142 func: function(mk) { return mk.createSession(null); } 142 func: function(mk) { return mk.createSession(null); }
143 }, 143 },
144 { 144 {
145 exception: 'TypeError', 145 exception: 'TypeError',
146 func: function(mk) { return mk.createSession(undefined); } 146 func: function(mk) { return mk.createSession(undefined); }
147 }, 147 },
148 { 148 {
149 exception: 'TypeError', 149 exception: 'TypeError',
150 func: function(mk) { return mk.createSession(1); } 150 func: function(mk) { return mk.createSession(1); }
151 }, 151 },
152 { 152 {
153 exception: 'TypeError', 153 exception: 'TypeError',
154 func: function(mk) { return mk.createSession(new Uint8Array( 0)); } 154 func: function(mk) { return mk.createSession(new Uint8Array( 0)); }
155 }, 155 },
156 { 156 {
157 exception: 'TypeError', 157 exception: 'TypeError',
158 func: function(mk, _, initData) { return mk.createSession(in itData); } 158 func: function(mk) { var initData = stringToUint8Array('init data'); return mk.createSession(initData); }
ddorwin 2014/09/09 21:35:24 Is this just trying to test an invalid type? Would
jrummell 2014/09/10 01:18:25 Removed, since it is a TypeError and the previous
159 }, 159 },
160 {
161 exception: 'TypeError',
162 func: function(mk) { return mk.createSession('TEMPORARY'); }
163 }
164 ];
165
166 async_test(function(test)
167 {
168 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
169 // FIXME: Remove "video/" from the calls to isTypeSupported( ) once it is updated.
ddorwin 2014/09/09 21:35:24 I don't think this comment applies to this case.
jrummell 2014/09/10 01:18:25 Done.
170 // http://crbug.com/405731.
171 var sessionPromises = kCreateSessionExceptionsTestCases.map( function(testCase) {
172 return test_exception(testCase, mediaKeys);
173 });
174
175 assert_not_equals(sessionPromises.length, 0);
176 return Promise.all(sessionPromises);
177 }).then(function(result) {
178 test.done();
179 }).catch(function(error) {
180 forceTestFailureFromPromise(test, error, 'createSession() te sts failed');
181 });
182 }, 'Test MediaKeys createSession() exceptions.');
183
184 var kGenerateRequestExceptionsTestCases = [
185 // Tests in this set use a shortened parameter name due to
186 // format_value() only returning the first 60 characters as the
187 // result. With a longer name the first 60 characters is not
188 // enough to determine which test failed. Even with the
189 // shortened name, the error message for the last couple of
190 // tests is the same.
160 // Invalid parameters. 191 // Invalid parameters.
161 { 192 {
162 exception: 'InvalidAccessError', 193 exception: 'InvalidAccessError',
163 func: function(mk, _, initData) { return mk.createSession('' , initData); } 194 func: function(mk1, _, initData) { return mk1.createSession( ).generateRequest('', initData); }
164 }, 195 },
165 // Not supported contentTypes. 196 // Not supported initDataTypes.
166 { 197 {
167 exception: 'NotSupportedError', 198 exception: 'NotSupportedError',
168 func: function(mk, _, initData) { return mk.createSession(nu ll, initData); } 199 func: function(mk2, _, initData) { return mk2.createSession( ).generateRequest(null, initData); }
169 }, 200 },
170 { 201 {
171 exception: 'NotSupportedError', 202 exception: 'NotSupportedError',
172 func: function(mk, _, initData) { return mk.createSession(un defined, initData); } 203 func: function(mk3, _, initData) { return mk3.createSession( ).generateRequest(undefined, initData); }
173 }, 204 },
174 { 205 {
175 exception: 'NotSupportedError', 206 exception: 'NotSupportedError',
176 func: function(mk, _, initData) { return mk.createSession(1, initData); } 207 func: function(mk4, _, initData) { return mk4.createSession( ).generateRequest(1, initData); }
177 }, 208 },
178 { 209 {
179 exception: 'NotSupportedError', 210 exception: 'NotSupportedError',
180 func: function(mk, _, initData) { return mk.createSession(ne w Uint8Array(0), initData); } 211 func: function(mk5, _, initData) { return mk5.createSession( ).generateRequest(new Uint8Array(0), initData); }
181 }, 212 },
182 { 213 {
183 exception: 'NotSupportedError', 214 exception: 'NotSupportedError',
184 func: function(mk, _, initData) { return mk.createSession('u nsupported', initData); } 215 func: function(mk6, _, initData) { return mk6.createSession( ).generateRequest('unsupported', initData); }
185 }, 216 },
186 { 217 {
187 exception: 'NotSupportedError', 218 exception: 'NotSupportedError',
188 func: function(mk, _, initData) { return mk.createSession('v ideo/foo', initData); } 219 func: function(mk7, _, initData) { return mk7.createSession( ).generateRequest('video/foo', initData); }
189 }, 220 },
190 { 221 {
191 exception: 'NotSupportedError', 222 exception: 'NotSupportedError',
192 func: function(mk, _, initData) { return mk.createSession('t ext/webm', initData); } 223 func: function(mk8, _, initData) { return mk8.createSession( ).generateRequest('text/webm', initData); }
193 } 224 }
194 // FIXME: Enable when switching to initDataType from MIME type. 225 // FIXME: Enable when switching to initDataType from MIME type.
195 // http://crbug.com/385874. 226 // http://crbug.com/385874.
196 // { 227 // {
197 // exception: 'NotSupportedError', 228 // exception: 'NotSupportedError',
198 // func: function(mk, _, initData) { return mk.createSession ('video/webm', initData); } 229 // func: function(mk, _, initData) { return mk.createSession ('video/webm', initData); }
199 // } 230 // }
200 ]; 231 ];
201 232
202 var kTypeSpecificCreateSessionExceptionsTestCases = [ 233 var kTypeSpecificGenerateRequestExceptionsTestCases = [
203 // Tests in this set use a shortened parameter name due to 234 // Tests in this set use a shortened parameter name due to
204 // format_value() only returning the first 60 characters as the 235 // format_value() only returning the first 60 characters as the
205 // result. With a longer name the first 60 characters is not 236 // result. With a longer name the first 60 characters is not
206 // enough to determine which test failed. Even with the 237 // enough to determine which test failed. Even with the
207 // shortened name, the error message for the last couple of 238 // shortened name, the error message for the last couple of
208 // tests is the same. 239 // tests is the same.
209 240
210 // Too few parameters. 241 // Too few parameters.
211 { 242 {
212 exception: 'TypeError', 243 exception: 'TypeError',
213 func: function(mk, type) { return mk.createSession(type); } 244 func: function(mk1, type) { return mk1.createSession().gener ateRequest(type); }
214 }, 245 },
215 // Invalid parameters. 246 // Invalid parameters.
216 { 247 {
217 exception: 'TypeError', 248 exception: 'TypeError',
218 func: function(mk, type) { return mk.createSession(type, '') ; } 249 func: function(mk2, type) { return mk2.createSession().gener ateRequest(type, ''); }
219 }, 250 },
220 { 251 {
221 exception: 'TypeError', 252 exception: 'TypeError',
222 func: function(mk, type) { return mk.createSession(type, nul l); } 253 func: function(mk3, type) { return mk3.createSession().gener ateRequest(type, null); }
223 }, 254 },
224 { 255 {
225 exception: 'TypeError', 256 exception: 'TypeError',
226 func: function(mk, type) { return mk.createSession(type, und efined); } 257 func: function(mk4, type) { return mk4.createSession().gener ateRequest(type, undefined); }
227 }, 258 },
228 { 259 {
229 exception: 'TypeError', 260 exception: 'TypeError',
230 func: function(mk, type) { return mk.createSession(type, 1); } 261 func: function(mk5, type) { return mk5.createSession().gener ateRequest(type, 1); }
231 }, 262 },
232 { 263 {
233 exception: 'InvalidAccessError', 264 exception: 'InvalidAccessError',
234 func: function(mk, type) { return mk.createSession(type, new Uint8Array(0)); } 265 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 } 266 }
262 ]; 267 ];
263 268
264 async_test(function(test) 269 async_test(function(test)
265 { 270 {
266 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { 271 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
267 // FIXME: Remove "video/" from the calls to isTypeSupported( ) once it is updated. 272 // FIXME: Remove "video/" from the calls to isTypeSupported( ) once it is updated.
268 // http://crbug.com/405731. 273 // http://crbug.com/405731.
269 var initData = stringToUint8Array('init data'); 274 var initData = stringToUint8Array('init data');
270 var sessionPromises = kCreateSessionExceptionsTestCases.map( function(testCase) { 275 var sessionPromises = kGenerateRequestExceptionsTestCases.ma p(function(testCase) {
271 return test_exception(testCase, mediaKeys, '', initData) ; 276 return test_exception(testCase, mediaKeys, '', initData) ;
272 }); 277 });
273 278
274 // Test that WebM sessions generate the expected error, if 279 // Test that WebM sessions generate the expected error, if
275 // supported. 280 // supported.
276 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) { 281 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) {
277 var WebmSessionPromises = kTypeSpecificCreateSessionExce ptionsTestCases.map(function(testCase) { 282 var WebmSessionPromises = kTypeSpecificGenerateRequestEx ceptionsTestCases.map(function(testCase) {
278 return test_exception(testCase, mediaKeys, 'webm', g etInitData('webm')); 283 return test_exception(testCase, mediaKeys, 'webm', g etInitData('webm'));
279 }); 284 });
280 sessionPromises = sessionPromises.concat(WebmSessionProm ises); 285 sessionPromises = sessionPromises.concat(WebmSessionProm ises);
281 } 286 }
282 287
283 // Repeat for MP4, if supported. 288 // Repeat for MP4, if supported.
284 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) { 289 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) {
285 var mp4SessionPromises = kTypeSpecificCreateSessionExcep tionsTestCases.map(function(testCase) { 290 var mp4SessionPromises = kTypeSpecificGenerateRequestExc eptionsTestCases.map(function(testCase) {
286 return test_exception(testCase, mediaKeys, 'cenc', g etInitData('cenc')); 291 return test_exception(testCase, mediaKeys, 'cenc', g etInitData('cenc'));
287 }); 292 });
288 sessionPromises = sessionPromises.concat(mp4SessionPromi ses); 293 sessionPromises = sessionPromises.concat(mp4SessionPromi ses);
289 } 294 }
290 295
291 assert_not_equals(sessionPromises.length, 0); 296 assert_not_equals(sessionPromises.length, 0);
292 return Promise.all(sessionPromises); 297 return Promise.all(sessionPromises);
293 }).then(function(result) { 298 }).then(function(result) {
294 test.done(); 299 test.done();
295 }).catch(function(error) { 300 }).catch(function(error) {
296 forceTestFailureFromPromise(test, error, 'createSession() te sts failed'); 301 forceTestFailureFromPromise(test, error, 'generateRequest() tests failed');
297 }); 302 });
298 }, 'Test MediaKeys createSession() exceptions.'); 303 }, 'Test MediaKeys generateRequest() exceptions.');
299 304
300 // All calls to |func| in this group are supposed to succeed. 305 // All calls to |func| in this group are supposed to succeed.
301 // However, the spec notes that some things are optional for 306 // However, the spec notes that some things are optional for
302 // Clear Key. In particular, support for persistent sessions 307 // Clear Key. In particular, support for persistent sessions
303 // is optional. Since some implementations won't support some 308 // is optional. Since some implementations won't support some
304 // features, a NotSupportedError is treated as a success 309 // features, a NotSupportedError is treated as a success
305 // if |isNotSupportedAllowed| is true. 310 // if |isNotSupportedAllowed| is true.
306 var kCreateSessionTestCases = [ 311 var kCreateSessionTestCases = [
307 // Added index to each variable name as otherwise the first 60 312 // Added index to each variable name as otherwise the first 60
ddorwin 2014/09/09 21:35:24 Still true and necessary?
jrummell 2014/09/10 01:18:25 Nope. Removed.
308 // characters of |func| is the same. 313 // characters of |func| is the same.
309 314
310 // Use the default sessionType. 315 // Use the default sessionType.
311 { 316 {
312 func: function(mk1, type, initData) { return mk1.createSessi on(type, initData); }, 317 func: function(mk1) { return mk1.createSession(); },
313 isNotSupportedAllowed: false 318 isNotSupportedAllowed: false
314 }, 319 },
315 // Try variations of sessionType. 320 // Try variations of sessionType.
316 { 321 {
317 func: function(mk2, type, initData) { return mk2.createSessi on(type, initData, 'temporary'); }, 322 func: function(mk2) { return mk2.createSession('temporary'); },
318 isNotSupportedAllowed: false 323 isNotSupportedAllowed: false
319 }, 324 },
320 { 325 {
321 func: function(mk3, type, initData) { return mk3.createSessi on(type, initData, undefined); }, 326 func: function(mk3) { return mk3.createSession(undefined); } ,
ddorwin 2014/09/09 21:35:24 Hmm. It seems this should fail. Maybe our IDL infr
jrummell 2014/09/10 01:18:25 In the previous discussion resolve(void) and resol
322 isNotSupportedAllowed: false 327 isNotSupportedAllowed: false
323 }, 328 },
324 { 329 {
325 // Since this is optional, some Clear Key implementations 330 // Since this is optional, some Clear Key implementations
326 // will succeed, others will return a "NotSupportedError". 331 // will succeed, others will return a "NotSupportedError".
327 // Both are allowed results. 332 // Both are allowed results.
328 func: function(mk4, type, initData) { return mk4.createSessi on(type, initData, 'persistent'); }, 333 func: function(mk4) { return mk4.createSession('persistent') ; },
329 isNotSupportedAllowed: true 334 isNotSupportedAllowed: true
330 }, 335 },
331 // Try additional parameter, which should be ignored. 336 // Try additional parameter, which should be ignored.
332 { 337 {
333 func: function(mk5, type, initData) { return mk5.createSessi on(type, initData, 'temporary', 'extra'); }, 338 func: function(mk5) { return mk5.createSession('temporary', 'extra'); },
334 isNotSupportedAllowed: false 339 isNotSupportedAllowed: false
335 } 340 }
336 ]; 341 ];
337 342
338 // This function checks that calling |testCase.func| creates a 343 // This function checks that calling |testCase.func| creates a
339 // MediaKeySession object with some default values. It also 344 // MediaKeySession object with some default values. It also
340 // allows for an NotSupportedError to be generated and treated as a 345 // allows for an NotSupportedError to be generated and treated as a
341 // success, if allowed. See comment above kCreateSessionTestCases. 346 // success, if allowed. See comment above kCreateSessionTestCases.
342 function test_createSession(testCase /*...*/) 347 function test_createSession(testCase, mediaKeys)
343 { 348 {
344 var func = testCase.func; 349 var mediaKeySession = testCase.func.call(null, mediaKeys);
345 var isNotSupportedAllowed = testCase.isNotSupportedAllowed; 350 // FIXME: Update this set of tests when done
346 var args = Array.prototype.slice.call(arguments, 1); 351 // implementing the latest spec.
347 352 if (mediaKeySession) {
ddorwin 2014/09/09 21:35:24 If not supported, it will throw! That means this m
jrummell 2014/09/10 01:18:25 Done.
348 return func.apply(null, args).then( 353 assert_equals(typeof mediaKeySession, 'object');
349 function(mediaKeySession) 354 assert_equals(typeof mediaKeySession.addEventListener, 'func tion');
350 { 355 assert_equals(typeof mediaKeySession.generateRequest, 'funct ion');
351 // FIXME: Update this set of tests when done 356 assert_equals(typeof mediaKeySession.update, 'function');
352 // implementing the latest spec. 357 assert_equals(typeof mediaKeySession.release, 'function');
353 assert_not_equals(mediaKeySession, null); 358 assert_equals(mediaKeySession.error, null);
354 assert_equals(typeof mediaKeySession, 'object'); 359 assert_equals(mediaKeySession.sessionId, '');
355 assert_equals(typeof mediaKeySession.addEventListener, ' function'); 360 assert_equals(typeof mediaKeySession.sessionId, 'string');
356 assert_equals(typeof mediaKeySession.update, 'function') ; 361 assert_equals(typeof mediaKeySession.onopen, 'undefined');
ddorwin 2014/09/09 21:35:24 As part of the cleanup CL, the event names should
jrummell 2014/09/10 01:18:24 Acknowledged.
357 assert_equals(mediaKeySession.error, null); 362 assert_equals(typeof mediaKeySession.onmessage, 'undefined') ;
358 assert_true(mediaKeySession.sessionId && mediaKeySession .sessionId.length > 0); 363 assert_equals(typeof mediaKeySession.onclose, 'undefined');
359 assert_equals(typeof mediaKeySession.sessionId, 'string' ); 364 assert_equals(typeof mediaKeySession.onerror, 'undefined');
360 assert_equals(typeof mediaKeySession.onopen, 'undefined' ); 365 } else {
361 assert_equals(typeof mediaKeySession.onmessage, 'undefin ed'); 366 assert_true(testCase.isNotSupportedAllowed);
362 assert_equals(typeof mediaKeySession.onclose, 'undefined '); 367 }
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 } 368 }
373 369
374 async_test(function(test) 370 async_test(function(test)
371 {
372 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
373 kCreateSessionTestCases.map(function(testCase) {
374 test_createSession(testCase, mediaKeys);
375 });
376 test.done();
377 }).catch(function(error) {
378 forceTestFailureFromPromise(test, error, 'createSession() te sts failed');
379 });
380 }, 'Test MediaKeys createSession().');
381
382 // This function checks that calling generateRequest() works for
383 // various sessions. |testCase.func| creates a MediaKeySession
384 // object, and then generateRequest() is called on that object. It
385 // allows for an NotSupportedError to be generated and treated as a
386 // success, if allowed. See comment above kCreateSessionTestCases.
387 function test_generateRequest(testCase, mediaKeys, type, initData)
388 {
389 var mediaKeySession = testCase.func.call(null, mediaKeys);
390 if (mediaKeySession) {
ddorwin 2014/09/09 21:35:24 ditto
jrummell 2014/09/10 01:18:25 Done.
391 return mediaKeySession.generateRequest(type, initData);
392 } else {
393 assert_true(testCase.isNotSupportedAllowed);
394 return new Promise(new Promise(function() {}));
395 }
396 }
397
398 async_test(function(test)
375 { 399 {
376 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { 400 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
377 var sessionPromises = []; 401 var sessionPromises = [];
378 402
379 // Test that WebM sessions generate the expected error, if 403 // Test that WebM sessions generate the expected error, if
380 // supported. 404 // supported.
381 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) { 405 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) {
382 var WebmSessionPromises = kCreateSessionTestCases.map(fu nction(testCase) { 406 var WebmSessionPromises = kCreateSessionTestCases.map(fu nction(testCase) {
383 return test_createSession(testCase, mediaKeys, 'webm ', getInitData('webm')); 407 return test_generateRequest(testCase, mediaKeys, 'we bm', getInitData('webm'));
384 }); 408 });
385 sessionPromises = sessionPromises.concat(WebmSessionProm ises); 409 sessionPromises = sessionPromises.concat(WebmSessionProm ises);
386 } 410 }
387 411
388 // Repeat for MP4, if supported. 412 // Repeat for MP4, if supported.
389 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) { 413 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) {
390 var mp4SessionPromises = kCreateSessionTestCases.map(fun ction(testCase) { 414 var mp4SessionPromises = kCreateSessionTestCases.map(fun ction(testCase) {
391 return test_createSession(testCase, mediaKeys, 'cenc ', getInitData('cenc')); 415 return test_generateRequest(testCase, mediaKeys, 'ce nc', getInitData('cenc'));
392 }); 416 });
393 sessionPromises = sessionPromises.concat(mp4SessionPromi ses); 417 sessionPromises = sessionPromises.concat(mp4SessionPromi ses);
394 } 418 }
395 419
396 assert_not_equals(sessionPromises.length, 0); 420 assert_not_equals(sessionPromises.length, 0);
397 return Promise.all(sessionPromises); 421 return Promise.all(sessionPromises);
398 }).then(function(result) { 422 }).then(function(result) {
399 test.done(); 423 test.done();
400 }).catch(function(error) { 424 }).catch(function(error) {
401 forceTestFailureFromPromise(test, error, 'createSession() te sts failed'); 425 forceTestFailureFromPromise(test, error, 'generateRequest() tests failed');
402 }); 426 });
403 }, 'Test MediaKeys createSession().'); 427 }, 'Test MediaKeys generateRequest().');
404 428
405 var kUpdateSessionExceptionsTestCases = [ 429 var kUpdateSessionExceptionsTestCases = [
406 // Tests in this set use a shortened parameter name due to 430 // Tests in this set use a shortened parameter name due to
407 // format_value() only returning the first 60 characters as the 431 // format_value() only returning the first 60 characters as the
408 // result. With a longer name (mediaKeySession) the first 60 432 // result. With a longer name (mediaKeySession) the first 60
409 // characters is not enough to determine which test failed. 433 // characters is not enough to determine which test failed.
410 434
411 // Too few parameters. 435 // Too few parameters.
412 { 436 {
413 exception: 'TypeError', 437 exception: 'TypeError',
(...skipping 15 matching lines...) Expand all
429 { 453 {
430 exception: 'TypeError', 454 exception: 'TypeError',
431 func: function(s) { return s.update(1); } 455 func: function(s) { return s.update(1); }
432 }, 456 },
433 { 457 {
434 exception: 'InvalidAccessError', 458 exception: 'InvalidAccessError',
435 func: function(s) { return s.update(new Uint8Array(0)); } 459 func: function(s) { return s.update(new Uint8Array(0)); }
436 } 460 }
437 ]; 461 ];
438 462
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) 463 async_test(function(test)
452 { 464 {
453 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) { 465 MediaKeys.create('org.w3.clearkey').then(function(mediaKeys) {
454 var promises = []; 466 var promises = [];
455 467
456 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) { 468 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/webm ')) {
457 promises.push(create_update_exception_test(mediaKeys, 'w ebm', getInitData('webm'))); 469 var WebmSessionPromises = kUpdateSessionExceptionsTestCa ses.map(function(testCase) {
470 var mediaKeySession = mediaKeys.createSession();
471 return mediaKeySession.generateRequest('webm', getIn itData('webm')).then(function(result) {
472 return test_exception(testCase, mediaKeySession) ;
473 });
474 });
475 promises = promises.concat(WebmSessionPromises);
458 } 476 }
459 477
460 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) { 478 if (MediaKeys.isTypeSupported('org.w3.clearkey', 'video/mp4' )) {
461 promises.push(create_update_exception_test(mediaKeys, 'c enc', getInitData('cenc'))); 479 var mp4SessionPromises = kUpdateSessionExceptionsTestCas es.map(function(testCase) {
480 var mediaKeySession = mediaKeys.createSession();
481 return mediaKeySession.generateRequest('cenc', getInit Data('cenc')).then(function(result) {
482 return test_exception(testCase, mediaKeySession);
483 });
484 });
485 promises = promises.concat(mp4SessionPromises);
462 } 486 }
463 487
464 assert_not_equals(promises.length, 0); 488 assert_not_equals(promises.length, 0);
465 return Promise.all(promises); 489 return Promise.all(promises);
466 }).then(function(result) { 490 }).then(function(result) {
467 test.done(); 491 test.done();
468 }).catch(function(error) { 492 }).catch(function(error) {
469 forceTestFailureFromPromise(test, error, 'update() tests fai led'); 493 forceTestFailureFromPromise(test, error, 'update() tests fai led');
470 }); 494 });
471 }, 'Test MediaKeySession update() exceptions.'); 495 }, 'Test MediaKeySession update() exceptions.');
472 496
473 function create_update_test(mediaKeys, type, initData) 497 function create_update_test(mediaKeys, type, initData)
474 { 498 {
475 var mediaKeySession; 499 var mediaKeySession = mediaKeys.createSession();
476 var promise = mediaKeys.createSession(type, initData).then(funct ion(result) { 500 var promise = mediaKeySession.generateRequest(type, initData).th en(function(result) {
477 mediaKeySession = result;
478 var validLicense = stringToUint8Array(createJWKSet(createJWK (stringToUint8Array('123'), stringToUint8Array('1234567890abcdef')))); 501 var validLicense = stringToUint8Array(createJWKSet(createJWK (stringToUint8Array('123'), stringToUint8Array('1234567890abcdef'))));
479 return mediaKeySession.update(validLicense); 502 return mediaKeySession.update(validLicense);
480 }).then(function(result) { 503 }).then(function(result) {
481 // Call update() with a different license and an extra 504 // Call update() with a different license and an extra
482 // parameter. The extra parameter is ignored. 505 // parameter. The extra parameter is ignored.
483 var validLicense = stringToUint8Array(createJWKSet(createJWK (stringToUint8Array('4567890'), stringToUint8Array('01234567890abcde')))); 506 var validLicense = stringToUint8Array(createJWKSet(createJWK (stringToUint8Array('4567890'), stringToUint8Array('01234567890abcde'))));
484 return mediaKeySession.update(validLicense, 'extra'); 507 return mediaKeySession.update(validLicense, 'extra');
485 }); 508 });
486 return promise; 509 return promise;
487 } 510 }
(...skipping 15 matching lines...) Expand all
503 return Promise.all(promises); 526 return Promise.all(promises);
504 }).then(function(result) { 527 }).then(function(result) {
505 test.done(); 528 test.done();
506 }).catch(function(error) { 529 }).catch(function(error) {
507 forceTestFailureFromPromise(test, error, 'update() tests fai led'); 530 forceTestFailureFromPromise(test, error, 'update() tests fai led');
508 }); 531 });
509 }, 'Test MediaKeySession update().'); 532 }, 'Test MediaKeySession update().');
510 533
511 function create_release_test(mediaKeys, type, initData) 534 function create_release_test(mediaKeys, type, initData)
512 { 535 {
513 var mediaKeySession; 536 var mediaKeySession = mediaKeys.createSession();
514 var promise = mediaKeys.createSession(type, initData).then(funct ion(result) { 537 var promise = mediaKeySession.generateRequest(type, initData).th en(function(result) {
515 mediaKeySession = result;
516 return mediaKeySession.release(); 538 return mediaKeySession.release();
517 // FIXME: Uncomment once the code supports multiple release() ca lls. 539 // FIXME: Uncomment once the code supports multiple release() ca lls.
518 // }).then(function(result) { 540 // }).then(function(result) {
519 // // Call release() again with an extra parameter. The extra 541 // // Call release() again with an extra parameter. The extra
520 // // parameter is ignored. 542 // // parameter is ignored.
521 // return mediaKeySession.release('extra'); 543 // return mediaKeySession.release('extra');
522 }); 544 });
523 return promise; 545 return promise;
524 } 546 }
525 547
(...skipping 18 matching lines...) Expand all
544 forceTestFailureFromPromise(test, error, 'release() tests fa iled'); 566 forceTestFailureFromPromise(test, error, 'release() tests fa iled');
545 }); 567 });
546 }, 'Test MediaKeySession release().'); 568 }, 'Test MediaKeySession release().');
547 569
548 // FIXME: Add syntax checks for MediaKeys.IsTypeSupported(). 570 // FIXME: Add syntax checks for MediaKeys.IsTypeSupported().
549 // FIXME: Add syntax checks for MediaKeyError and MediaKeySession ev ents. 571 // FIXME: Add syntax checks for MediaKeyError and MediaKeySession ev ents.
550 // FIXME: Add HTMLMediaElement syntax checks, e.g. setMediaKeys, med iakeys, onneedkey. 572 // FIXME: Add HTMLMediaElement syntax checks, e.g. setMediaKeys, med iakeys, onneedkey.
551 </script> 573 </script>
552 </body> 574 </body>
553 </html> 575 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698