playback-temporary-waitingforkey.js (3137B)
1 function runTest(config,qualifier) { 2 3 // config.initData contains a list of keys. We expect those to be needed in order and get 4 // one waitingforkey event for each one. 5 6 var testname = testnamePrefix(qualifier, config.keysystem) 7 + ', successful playback, temporary, ' 8 + /video\/([^;]*)/.exec(config.videoType)[1] 9 + ', waitingforkey event, ' 10 + config.initData.length + ' key' + (config.initData.length > 1 ? 's' : ''); 11 12 var configuration = { initDataTypes: [ config.initDataType ], 13 audioCapabilities: [ { contentType: config.audioType } ], 14 videoCapabilities: [ { contentType: config.videoType } ], 15 sessionTypes: [ 'temporary' ] }; 16 17 async_test(function(test) { 18 var _video = config.video, 19 _mediaKeys, 20 _mediaKeySessions = [], 21 _mediaSource; 22 23 function onFailure(error) { 24 forceTestFailureFromPromise(test, error); 25 } 26 27 function onMessage(event) { 28 config.messagehandler( event.messageType, event.message ).then( function( response ) { 29 return event.target.update( response ); 30 }).catch(onFailure); 31 } 32 33 function onWaitingForKey(event) { 34 // Expect one waitingforkey event for each initData we were given 35 assert_less_than(_mediaKeySessions.length, config.initData.length); 36 var mediaKeySession = _mediaKeys.createSession( 'temporary' ); 37 waitForEventAndRunStep('message', mediaKeySession, onMessage, test); 38 _mediaKeySessions.push(mediaKeySession); 39 mediaKeySession.generateRequest(config.initDataType, config.initData[_mediaKeySessions.length - 1]).catch(onFailure); 40 } 41 42 function onTimeupdate(event) { 43 if (_video.currentTime > (config.duration || 1)) { 44 assert_equals(_mediaKeySessions.length, config.initData.length); 45 _video.removeEventListener('timeupdate', onTimeupdate); 46 _video.pause(); 47 test.done(); 48 } 49 } 50 51 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]).then(function(access) { 52 return access.createMediaKeys(); 53 }).then(function(mediaKeys) { 54 _mediaKeys = mediaKeys; 55 return _video.setMediaKeys(_mediaKeys); 56 }).then(function(){ 57 waitForEventAndRunStep('waitingforkey', _video, onWaitingForKey, test); 58 59 // Not using waitForEventAndRunStep() to avoid too many 60 // EVENT(onTimeUpdate) logs. 61 _video.addEventListener('timeupdate', onTimeupdate, true); 62 return testmediasource(config); 63 }).then(function(source) { 64 _mediaSource = source; 65 _video.src = URL.createObjectURL(_mediaSource); 66 return source.done; 67 }).then(function(){ 68 _video.play(); 69 }).catch(onFailure); 70 }, testname); 71 }