setmediakeys.js (2094B)
1 function runTest(config, qualifier) { 2 var testname = testnamePrefix( qualifier, config.keysystem ) 3 + ', setMediaKeys'; 4 5 var configuration = getSimpleConfigurationForContent( config.content ); 6 7 if ( config.initDataType && config.initData ) { 8 configuration.initDataTypes = [ config.initDataType ]; 9 } 10 11 async_test (function (test) { 12 var _video = config.video, 13 _mediaKeys; 14 15 // Test MediaKeys assignment. 16 assert_equals(_video.mediaKeys, null); 17 assert_equals(typeof _video.setMediaKeys, 'function'); 18 19 function onFailure(error) { 20 forceTestFailureFromPromise(test, error); 21 } 22 23 // Try setting mediaKeys to null. 24 _video.setMediaKeys(null).then(function(result) { 25 assert_equals(_video.mediaKeys, null); 26 27 // setMediaKeys should fail when setting to the wrong type of object - Date. 28 return _video.setMediaKeys(new Date()); 29 }).then(function (result) { 30 assert_unreached('setMediaKeys should fail when setting to wrong kind of object (Date)'); 31 }, function(error) { 32 // The error should be TypeError. 33 assert_throws_js(TypeError, () => { throw error; }, 34 'setMediaKeys should return a TypeError when setting to wrong kind of object (Date)'); 35 return navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]); 36 }).then(function(access) { 37 assert_equals(access.keySystem, config.keysystem) 38 return access.createMediaKeys(); 39 }).then(function(result) { 40 _mediaKeys = result; 41 assert_not_equals(_mediaKeys, null); 42 assert_equals(typeof _mediaKeys.createSession, 'function'); 43 return _video.setMediaKeys(_mediaKeys); 44 }).then(function(result) { 45 assert_not_equals(_video.mediaKeys, null); 46 assert_equals(_video.mediaKeys, _mediaKeys); 47 test.done(); 48 }).catch(onFailure); 49 }, testname); 50 }