playback-temporary-playduration.js (3423B)
1 function runTest(config,qualifier) { 2 3 var testname = testnamePrefix(qualifier, config.keysystem) 4 + ', temporary, ' 5 + /video\/([^;]*)/.exec(config.videoType)[1] 6 + ', playback with limited playduration, ' + config.testcase; 7 8 var configuration = { initDataTypes: [ config.initDataType ], 9 audioCapabilities: [ { contentType: config.audioType } ], 10 videoCapabilities: [ { contentType: config.videoType } ], 11 sessionTypes: [ 'temporary' ] }; 12 13 async_test(function(test) { 14 15 var _video = config.video, 16 _mediaKeys, 17 _mediaKeySession, 18 _mediaSource; 19 20 function onFailure(error) { 21 forceTestFailureFromPromise(test, error); 22 } 23 24 function onEncrypted(event) { 25 assert_equals(event.target, _video); 26 assert_true(event instanceof window.MediaEncryptedEvent); 27 assert_equals(event.type, 'encrypted'); 28 29 // Only create the session for the first encrypted event 30 if (_mediaKeySession !== undefined) return; 31 32 var initDataType = config.initData ? config.initDataType : event.initDataType; 33 var initData = config.initData || event.initData; 34 35 _mediaKeySession = _mediaKeys.createSession('temporary'); 36 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test); 37 _mediaKeySession.generateRequest( initDataType, initData ).catch(onFailure); 38 } 39 40 function onMessage(event) { 41 assert_equals(event.target, _mediaKeySession); 42 assert_true(event instanceof window.MediaKeyMessageEvent); 43 assert_equals(event.type, 'message'); 44 45 assert_in_array(event.messageType, ['license-request', 'individualization-request']); 46 47 config.messagehandler(event.messageType, event.message, {playDuration: config.playduration}).then(function(response) { 48 return event.target.update(response); 49 }).catch(onFailure); 50 } 51 52 function onPlaying(event) { 53 // Not using waitForEventAndRunStep() to avoid too many 54 // EVENT(onTimeUpdate) logs. 55 _video.addEventListener('timeupdate', test.step_func(onTimeupdate), true); 56 test.step_timeout(function(){ 57 test.done(); 58 },config.playduration * 2); 59 } 60 61 function onTimeupdate(event) { 62 assert_less_than(_video.currentTime * 1000, config.playduration, "Video should not play for more than playDuration from licence"); 63 } 64 65 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]).then(function(access) { 66 return access.createMediaKeys(); 67 }).then(function(mediaKeys) { 68 _mediaKeys = mediaKeys; 69 return _video.setMediaKeys(_mediaKeys); 70 }).then(function(){ 71 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); 72 waitForEventAndRunStep('playing', _video, onPlaying, test); 73 return testmediasource(config); 74 }).then(function(source) { 75 _mediaSource = source; 76 _video.src = URL.createObjectURL(_mediaSource); 77 _video.play(); 78 }).catch(onFailure); 79 }, testname); 80 }