test_eme_requestKeySystemAccess.html (13058B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test Encrypted Media Extensions</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 <script type="text/javascript" src="manifest.js"></script> 8 <script type="text/javascript" src="eme.js"></script> 9 </head> 10 <body> 11 <pre id="test"> 12 <script class="testbody" type="text/javascript"> 13 14 const SUPPORTED_LABEL = "pass label"; 15 16 function ValidateConfig(name, expected, observed) { 17 info("ValidateConfig " + name); 18 info("expected cfg=" + JSON.stringify(expected)); 19 info("observed cfg=" + JSON.stringify(observed)); 20 21 is(observed.label, expected.label, name + " label should match"); 22 if (expected.initDataTypes) { 23 ok(expected.initDataTypes.every((element) => observed.initDataTypes.includes(element)), name + " initDataTypes should match."); 24 } 25 26 if (expected.audioCapabilities) { 27 ok(expected.audioCapabilities.length == 1, "Test function can only handle one capability."); 28 ok(observed.audioCapabilities.length == 1, "Test function can only handle one capability."); 29 is(observed.audioCapabilities[0].contentType, expected.audioCapabilities[0].contentType, name + " audioCapabilities should match."); 30 } 31 if (typeof expected.videoCapabilities !== 'undefined') { 32 info("expected.videoCapabilities=" + expected.videoCapabilities); 33 dump("expected.videoCapabilities=" + expected.videoCapabilities + "\n"); 34 ok(expected.videoCapabilities.length == 1, "Test function can only handle one capability."); 35 ok(observed.videoCapabilities.length == 1, "Test function can only handle one capability."); 36 is(observed.videoCapabilities[0].contentType, expected.videoCapabilities[0].contentType, name + " videoCapabilities should match."); 37 } 38 if (expected.sessionTypes) { 39 is(expected.sessionTypes.length, observed.sessionTypes.length, "Should have expected number of sessionTypes"); 40 for (var i = 0; i < expected.sessionTypes.length; i++) { 41 is(expected[i], observed[i], "Session type " + i + " should match"); 42 } 43 } 44 } 45 46 function Test(test) { 47 var name = "'" + test.name + "'"; 48 return new Promise(function(resolve) { 49 var p; 50 if (test.options) { 51 var keySystem = (test.keySystem !== undefined) ? test.keySystem : CLEARKEY_KEYSYSTEM; 52 p = navigator.requestMediaKeySystemAccess(keySystem, test.options); 53 } else { 54 p = navigator.requestMediaKeySystemAccess(keySystem); 55 } 56 p.then( 57 function(keySystemAccess) { 58 ok(test.shouldPass, name + " passed and was expected to " + (test.shouldPass ? "pass" : "fail")); 59 is(keySystemAccess.keySystem, CLEARKEY_KEYSYSTEM, "CDM keySystem should be in MediaKeySystemAccess.keySystem"); 60 ValidateConfig(name, test.expectedConfig, keySystemAccess.getConfiguration()); 61 resolve(); 62 }, 63 function(ex) { 64 if (test.shouldPass) { 65 info(name + " failed: " + ex); 66 } 67 ok(!test.shouldPass, name + " failed and was expected to " + (test.shouldPass ? "pass" : "fail")); 68 resolve(); 69 }); 70 }); 71 } 72 73 var tests = [ 74 { 75 name: 'Empty keySystem string', 76 keySystem: '', 77 options: [ 78 { 79 initDataTypes: ['cenc'], 80 videoCapabilities: [{contentType: 'video/mp4'}], 81 } 82 ], 83 shouldPass: false, 84 }, 85 { 86 name: 'Empty options specified', 87 options: [ ], 88 shouldPass: false, 89 }, 90 { 91 name: 'Undefined options', 92 shouldPass: false, 93 }, 94 { 95 name: 'Basic MP4 cenc', 96 options: [ 97 { 98 label: SUPPORTED_LABEL, 99 initDataTypes: ['cenc'], 100 audioCapabilities: [{contentType: 'audio/mp4'}], 101 videoCapabilities: [{contentType: 'video/mp4'}], 102 } 103 ], 104 expectedConfig: { 105 label: SUPPORTED_LABEL, 106 initDataTypes: ['cenc'], 107 audioCapabilities: [{contentType: 'audio/mp4'}], 108 videoCapabilities: [{contentType: 'video/mp4'}], 109 }, 110 shouldPass: true, 111 }, 112 { 113 name: 'Invalid keysystem failure', 114 keySystem: 'bogusKeySystem', 115 options: [ 116 { 117 initDataTypes: ['cenc'], 118 videoCapabilities: [{contentType: 'video/mp4'}], 119 } 120 ], 121 shouldPass: false, 122 }, 123 { 124 name: 'Invalid initDataType', 125 options: [ 126 { 127 initDataTypes: ['bogus'], 128 audioCapabilities: [{contentType: 'audio/mp4'}], 129 } 130 ], 131 shouldPass: false, 132 }, 133 { 134 name: 'Valid initDataType after invalid', 135 options: [ 136 { 137 label: SUPPORTED_LABEL, 138 initDataTypes: ['bogus', 'invalid', 'cenc'], 139 audioCapabilities: [{contentType: 'audio/mp4'}], 140 } 141 ], 142 expectedConfig: { 143 label: SUPPORTED_LABEL, 144 initDataTypes: ['cenc'], 145 audioCapabilities: [{contentType: 'audio/mp4'}], 146 }, 147 shouldPass: true, 148 }, 149 { 150 name: 'Invalid videoType', 151 options: [ 152 { 153 initDataTypes: ['cenc'], 154 videoCapabilities: [{contentType: 'video/bogus'}], 155 } 156 ], 157 shouldPass: false, 158 }, 159 { 160 name: 'Invalid distinctiveIdentifier fails', 161 options: [ 162 { 163 initDataTypes: ['cenc'], 164 videoCapabilities: [{contentType: 'video/mp4'}], 165 distinctiveIdentifier: 'bogus', 166 persistentState: 'bogus', 167 } 168 ], 169 shouldPass: false, 170 }, 171 { 172 name: 'distinctiveIdentifier is prohibited for ClearKey', 173 options: [ 174 { 175 initDataTypes: ['cenc'], 176 videoCapabilities: [{contentType: 'video/mp4'}], 177 distinctiveIdentifier: 'required', 178 } 179 ], 180 shouldPass: false, 181 }, 182 { 183 name: 'Invalid persistentState fails', 184 options: [ 185 { 186 initDataTypes: ['cenc'], 187 videoCapabilities: [{contentType: 'video/mp4'}], 188 persistentState: 'bogus', 189 } 190 ], 191 shouldPass: false, 192 }, 193 { 194 name: 'Invalid robustness unsupported', 195 options: [ 196 { 197 initDataTypes: ['cenc'], 198 videoCapabilities: [{contentType: 'video/mp4', robustness: 'very much so'}], 199 } 200 ], 201 shouldPass: false, 202 }, 203 { 204 name: 'Unexpected config entry should be ignored', 205 options: [ 206 { 207 label: SUPPORTED_LABEL, 208 initDataTypes: ['cenc'], 209 videoCapabilities: [{contentType: 'video/mp4'}], 210 unexpectedEntry: 'this should be ignored', 211 } 212 ], 213 expectedConfig: { 214 label: SUPPORTED_LABEL, 215 initDataTypes: ['cenc'], 216 videoCapabilities: [{contentType: 'video/mp4'}], 217 }, 218 shouldPass: true, 219 }, 220 { 221 name: 'Invalid option followed by valid', 222 options: [ 223 { 224 label: "this config should not be supported", 225 initDataTypes: ['bogus'], 226 }, 227 { 228 label: SUPPORTED_LABEL, 229 initDataTypes: ['cenc'], 230 videoCapabilities: [{contentType: 'video/mp4'}], 231 } 232 ], 233 expectedConfig: { 234 label: SUPPORTED_LABEL, 235 initDataTypes: ['cenc'], 236 videoCapabilities: [{contentType: 'video/mp4'}], 237 }, 238 shouldPass: true, 239 }, 240 { 241 name: 'Persistent-license should not be supported by ClearKey', 242 options: [ 243 { 244 initDataTypes: ['cenc'], 245 videoCapabilities: [{contentType: 'video/mp4'}], 246 sessionTypes: ['persistent-license'], 247 persistentState: 'optional', 248 } 249 ], 250 shouldPass: false, 251 }, 252 { 253 name: 'Persistent-usage-record should not be supported by ClearKey', 254 options: [ 255 { 256 initDataTypes: ['cenc'], 257 videoCapabilities: [{contentType: 'video/mp4'}], 258 sessionTypes: ['persistent-usage-record'], 259 persistentState: 'optional', 260 } 261 ], 262 shouldPass: false, 263 }, 264 { 265 name: 'MP4 audio container', 266 options: [ 267 { 268 label: SUPPORTED_LABEL, 269 initDataTypes: ['cenc'], 270 audioCapabilities: [{contentType: 'audio/mp4'}], 271 } 272 ], 273 expectedConfig: { 274 label: SUPPORTED_LABEL, 275 initDataTypes: ['cenc'], 276 audioCapabilities: [{contentType: 'audio/mp4'}], 277 }, 278 shouldPass: true, 279 }, 280 { 281 name: 'MP4 audio container with AAC-LC', 282 options: [ 283 { 284 label: SUPPORTED_LABEL, 285 initDataTypes: ['cenc'], 286 audioCapabilities: [{contentType: 'audio/mp4; codecs="mp4a.40.2"'}], 287 } 288 ], 289 expectedConfig: { 290 label: SUPPORTED_LABEL, 291 initDataTypes: ['cenc'], 292 audioCapabilities: [{contentType: 'audio/mp4; codecs="mp4a.40.2"'}], 293 }, 294 shouldPass: true, 295 }, 296 { 297 name: 'MP4 audio container with invalid codecs', 298 options: [ 299 { 300 initDataTypes: ['cenc'], 301 audioCapabilities: [{contentType: 'audio/mp4; codecs="bogus"'}], 302 } 303 ], 304 shouldPass: false, 305 }, 306 { 307 name: 'MP4 audio container with mp3 is unsupported', 308 options: [ 309 { 310 initDataTypes: ['cenc'], 311 audioCapabilities: [{contentType: 'audio/mp4; codecs="mp3"'}], 312 } 313 ], 314 shouldPass: false, 315 }, 316 { 317 name: 'MP4 video container type with an mp3 codec is unsupported', 318 options: [ 319 { 320 initDataTypes: ['cenc'], 321 videoCapabilities: [{contentType: 'video/mp4; codecs="mp3"'}], 322 } 323 ], 324 shouldPass: false, 325 }, 326 { 327 name: 'MP4 audio container type with a video codec is unsupported', 328 options: [ 329 { 330 initDataTypes: ['cenc'], 331 audioCapabilities: [{contentType: 'audio/mp4; codecs="avc1.42E01E"'}], 332 } 333 ], 334 shouldPass: false, 335 }, 336 { 337 name: 'MP4 video container with constrained baseline h.264', 338 options: [ 339 { 340 label: SUPPORTED_LABEL, 341 initDataTypes: ['cenc'], 342 videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E"'}], 343 } 344 ], 345 expectedConfig: { 346 label: SUPPORTED_LABEL, 347 initDataTypes: ['cenc'], 348 videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E"'}], 349 }, 350 shouldPass: true, 351 }, 352 { 353 name: 'MP4 video container with invalid codecs', 354 options: [ 355 { 356 initDataTypes: ['cenc'], 357 videoCapabilities: [{contentType: 'video/mp4; codecs="bogus"'}], 358 } 359 ], 360 shouldPass: false, 361 }, 362 { 363 name: 'MP4 video container with both audio and video codec type in videoType', 364 options: [ 365 { 366 initDataTypes: ['cenc'], 367 videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E,mp4a.40.2"'}], 368 } 369 ], 370 shouldPass: false, 371 }, 372 { 373 name: 'MP4 audio and video type both specified', 374 options: [ 375 { 376 label: SUPPORTED_LABEL, 377 initDataTypes: ['cenc'], 378 videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E"'}], 379 audioCapabilities: [{contentType: 'audio/mp4; codecs="mp4a.40.2"'}], 380 } 381 ], 382 expectedConfig: { 383 label: SUPPORTED_LABEL, 384 initDataTypes: ['cenc'], 385 videoCapabilities: [{contentType: 'video/mp4; codecs="avc1.42E01E"'}], 386 audioCapabilities: [{contentType: 'audio/mp4; codecs="mp4a.40.2"'}], 387 }, 388 shouldPass: true, 389 }, 390 { 391 name: 'Basic WebM video', 392 options: [ 393 { 394 label: SUPPORTED_LABEL, 395 initDataTypes: ['webm'], 396 videoCapabilities: [{contentType: 'video/webm'}], 397 } 398 ], 399 expectedConfig: { 400 label: SUPPORTED_LABEL, 401 initDataTypes: ['webm'], 402 videoCapabilities: [{contentType: 'video/webm'}], 403 }, 404 shouldPass: true, 405 }, 406 { 407 name: 'Basic WebM audio', 408 options: [ 409 { 410 label: SUPPORTED_LABEL, 411 initDataTypes: ['webm'], 412 audioCapabilities: [{contentType: 'audio/webm'}], 413 } 414 ], 415 expectedConfig: { 416 label: SUPPORTED_LABEL, 417 initDataTypes: ['webm'], 418 audioCapabilities: [{contentType: 'audio/webm'}], 419 }, 420 shouldPass: true, 421 }, 422 { 423 name: 'Webm with Vorbis audio and VP8 video.', 424 options: [ 425 { 426 label: SUPPORTED_LABEL, 427 initDataTypes: ['webm'], 428 videoCapabilities: [{contentType: 'video/webm;codecs="vp8"'}], 429 audioCapabilities: [{contentType: 'audio/webm;codecs="vorbis"'}], 430 } 431 ], 432 expectedConfig: { 433 label: SUPPORTED_LABEL, 434 initDataTypes: ['webm'], 435 videoCapabilities: [{contentType: 'video/webm;codecs="vp8"'}], 436 audioCapabilities: [{contentType: 'audio/webm;codecs="vorbis"'}], 437 }, 438 shouldPass: true, 439 }, 440 { 441 name: 'Webm with Vorbis audio and VP9 video.', 442 options: [ 443 { 444 label: SUPPORTED_LABEL, 445 initDataTypes: ['webm'], 446 videoCapabilities: [{contentType: 'video/webm;codecs="vp9"'}], 447 audioCapabilities: [{contentType: 'audio/webm;codecs="vorbis"'}], 448 } 449 ], 450 expectedConfig: { 451 label: SUPPORTED_LABEL, 452 initDataTypes: ['webm'], 453 videoCapabilities: [{contentType: 'video/webm;codecs="vp9"'}], 454 audioCapabilities: [{contentType: 'audio/webm;codecs="vorbis"'}], 455 }, 456 shouldPass: true, 457 }, 458 { 459 name: 'Webm with bogus video.', 460 options: [ 461 { 462 initDataTypes: ['webm'], 463 videoCapabilities: [{contentType: 'video/webm;codecs="bogus"'}], 464 } 465 ], 466 shouldPass: false, 467 }, 468 ]; 469 470 SimpleTest.waitForExplicitFinish(); 471 Promise.all(tests.map(Test)).then(function() { 472 SimpleTest.finish(); 473 }); 474 </script> 475 </pre> 476 </body> 477 </html>