syntax-mediakeysystemaccess.js (5475B)
1 function runTest(config) { 2 var keysystem = config.keysystem; 3 var testname = testnamePrefix(null, config.keysystem); 4 var initDataType = config.initDataType; 5 var configuration = { 6 initDataTypes: [config.initDataType], 7 audioCapabilities: [{contentType: config.audioType}], 8 videoCapabilities: [{contentType: config.videoType}], 9 sessionTypes: ['temporary'] 10 }; 11 12 var kRequestMediaKeySystemAccessExceptionsTestCases = [ 13 // Too few parameters. 14 { 15 exception: 'TypeError', 16 func: function () { 17 return navigator.requestMediaKeySystemAccess(); 18 } 19 }, 20 { 21 exception: 'TypeError', 22 func: function () { 23 return navigator.requestMediaKeySystemAccess(keysystem); 24 } 25 }, 26 // Invalid key systems. Note that JavaScript converts all these 27 // values into strings by calling toString(), so they fail due 28 // to the key system not being supported, not due to the type. 29 { 30 exception: 'NotSupportedError', 31 func: function () { 32 return navigator.requestMediaKeySystemAccess(null, [{}]); 33 } 34 }, 35 { 36 exception: 'NotSupportedError', 37 func: function () { 38 return navigator.requestMediaKeySystemAccess(undefined, [{}]); 39 } 40 }, 41 { 42 exception: 'NotSupportedError', 43 func: function () { 44 return navigator.requestMediaKeySystemAccess(1, [{}]); 45 } 46 }, 47 { 48 exception: 'NotSupportedError', 49 func: function () { 50 return navigator.requestMediaKeySystemAccess('unsupported', [{}]); 51 } 52 }, 53 // Empty keysystem string should be rejected with TypeError. 54 { 55 exception: 'TypeError', 56 func: function () { 57 return navigator.requestMediaKeySystemAccess('', [{}]); 58 } 59 }, 60 // (new Uint8Array(0)).toString() should return ''. So this case should be the same 61 // as the above. 62 { 63 exception: 'TypeError', 64 func: function () { 65 return navigator.requestMediaKeySystemAccess(new Uint8Array(0), [{}]); 66 } 67 }, 68 // Non-ASCII names. 69 { 70 exception: 'NotSupportedError', 71 func: function () { 72 return navigator.requestMediaKeySystemAccess(keysystem + '\u263A', [{}]); 73 } 74 }, 75 // Empty sequence of MediaKeySystemConfiguration. 76 { 77 exception: 'TypeError', 78 func: function () { 79 return navigator.requestMediaKeySystemAccess(keysystem, []); 80 } 81 }, 82 // Things that don't convert to valid sequences of MediaKeySystemConfigurations. 83 { 84 exception: 'TypeError', 85 func: function () { 86 return navigator.requestMediaKeySystemAccess(keysystem, {}); 87 } 88 }, 89 { 90 exception: 'TypeError', 91 func: function () { 92 return navigator.requestMediaKeySystemAccess(keysystem, "invalid"); 93 } 94 }, 95 { 96 exception: 'TypeError', 97 func: function () { 98 return navigator.requestMediaKeySystemAccess(keysystem, [{}, 6]); 99 } 100 }, 101 { 102 exception: 'TypeError', 103 func: function () { 104 return navigator.requestMediaKeySystemAccess(keysystem, ["invalid", "upsupported"]); 105 } 106 } 107 ]; 108 109 function requestMediaKeySystemAccessTestExceptions(){ 110 return new Promise(function(resolve, reject){ 111 var createPromises = kRequestMediaKeySystemAccessExceptionsTestCases.map(function (testCase) { 112 return test_exception(testCase); 113 }); 114 Promise.all(createPromises).then(function (result) { 115 resolve(); 116 }).catch(function (error) { 117 reject(error); 118 }); 119 }) 120 } 121 promise_test(function() { 122 return requestMediaKeySystemAccessTestExceptions(); 123 }, testname + ' test requestMediaKeySystemAccess() exceptions.'); 124 125 function requestMediaKeySystemAccessTestAttributes(){ 126 return new Promise(function(resolve, reject){ 127 isInitDataTypeSupported(keysystem, initDataType).then(function (isTypeSupported) { 128 assert_equals(typeof navigator.requestMediaKeySystemAccess, 'function'); 129 assert_true(isTypeSupported, "initDataType not supported"); 130 return navigator.requestMediaKeySystemAccess(keysystem, [configuration]); 131 }).then(function (access) { 132 assert_not_equals(access, null); 133 assert_equals(typeof access, 'object'); 134 assert_equals(access.keySystem, keysystem); 135 assert_equals(typeof access.getConfiguration, 'function'); 136 assert_equals(typeof access.createMediaKeys, 'function'); 137 resolve(); 138 }).catch(function(error){ 139 reject(error); 140 }) 141 }) 142 } 143 promise_test(function() { 144 return requestMediaKeySystemAccessTestAttributes(); 145 }, testname + ' test MediaKeySystemAccess attribute syntax.'); 146 147 }