test_eme_special_key_system.html (2018B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Test Encrypted Media Extensions - Special key system</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <pre id="test"> 10 <script class="testbody" type="text/javascript"> 11 function requestProtectionQueryKeySystemAccess() { 12 const kKeySystemOptions = [ 13 { 14 initDataTypes: ["cenc"], 15 videoCapabilities: [{ contentType: 'video/mp4; codecs="avc1.4d4015"' }], 16 }, 17 ]; 18 const kClearKeyWithProtectionQuery = 19 "org.mozilla.clearkey_with_protection_query"; 20 return navigator.requestMediaKeySystemAccess( 21 kClearKeyWithProtectionQuery, 22 kKeySystemOptions 23 ); 24 } 25 // Tests that org.mozilla.clearkey_with_protection_query cannot be accessed from JS if not preffed on. 26 add_task(async function protectionQueryKeySystemShouldBeHidden() { 27 try { 28 // Should throw since special key systems are not enabled. 29 await requestProtectionQueryKeySystemAccess(); 30 ok( 31 false, 32 "Test should have thrown by default because media.clearkey.test-key-systems.enabled should not be set" 33 ); 34 } catch (e) { 35 is(e.name, "NotSupportedError", "Should get not supported error"); 36 is( 37 e.message, 38 "Key system is unsupported", 39 "Should get message that key system is unsupported" 40 ); 41 } 42 }); 43 44 // Tests that org.mozilla.clearkey_with_protection_query can be accessed from JS if preffed on. 45 add_task(async function protectionQueryKeySystemShouldBeExposed() { 46 await SpecialPowers.pushPrefEnv({ 47 set: [["media.clearkey.test-key-systems.enabled", true]], 48 }); 49 try { 50 // Should not throw since special key systems are enabled. 51 let access = await requestProtectionQueryKeySystemAccess(); 52 ok( 53 access, 54 "Should get access to protection query key system when preffed on" 55 ); 56 } catch (e) { 57 ok(false, "Test should not have thrown and key system should be available"); 58 } 59 }); 60 </script> 61 </pre> 62 </body> 63 </html>