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