OLD | NEW |
(Empty) | |
| 1 function runTest(config,qualifier) { |
| 2 |
| 3 var testname = testnamePrefix( qualifier, config.keysystem ) |
| 4 + ', persistent-license, ' |
| 5 + /video\/([^;]*)/.exec( config.videoType )[ 1 ] |
| 6 + ', playback, destroy and acknowledge'; |
| 7 |
| 8 var configuration = { initDataTypes: [ config.initDataType ], |
| 9 audioCapabilities: [ { contentType: config.audioType
} ], |
| 10 videoCapabilities: [ { contentType: config.videoType
} ], |
| 11 sessionTypes: [ 'persistent-license' ] }; |
| 12 |
| 13 async_test( function(test) { |
| 14 |
| 15 var _video = config.video, |
| 16 _mediaKeys, |
| 17 _mediaKeySession, |
| 18 _mediaSource, |
| 19 _sessionId, |
| 20 _startedReleaseSequence = false; |
| 21 |
| 22 function onFailure(error) { |
| 23 forceTestFailureFromPromise(test, error); |
| 24 } |
| 25 |
| 26 function onMessage(event) { |
| 27 assert_equals(event.target, _mediaKeySession); |
| 28 assert_true(event instanceof window.MediaKeyMessageEvent); |
| 29 assert_equals(event.type, 'message'); |
| 30 |
| 31 config.messagehandler(event.messageType, event.message).then(functio
n(response) { |
| 32 return _mediaKeySession.update(response); |
| 33 }).catch(onFailure); |
| 34 } |
| 35 |
| 36 function onEncrypted(event) { |
| 37 assert_equals(event.target, _video); |
| 38 assert_true(event instanceof window.MediaEncryptedEvent); |
| 39 assert_equals(event.type, 'encrypted'); |
| 40 |
| 41 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test)
; |
| 42 _mediaKeySession.generateRequest( config.initData ? config.initDat
aType : event.initDataType, |
| 43 config.initData || event.initDat
a ).then( test.step_func(function() { |
| 44 assert_not_equals( _mediaKeySession.sessionId, undefined, "Sessi
onId should be defined" ); |
| 45 _sessionId = _mediaKeySession.sessionId; |
| 46 })).catch(onFailure); |
| 47 } |
| 48 |
| 49 function onTimeupdate(event) { |
| 50 if (_video.currentTime > ( config.duration || 1 ) && !_startedReleas
eSequence) { |
| 51 _video.removeEventListener('timeupdate', onTimeupdate); |
| 52 _video.pause(); |
| 53 _video.removeAttribute('src'); |
| 54 _video.load(); |
| 55 |
| 56 _startedReleaseSequence = true; |
| 57 _mediaKeySession.closed.then(onClosed); |
| 58 _mediaKeySession.remove().catch(onFailure); |
| 59 } |
| 60 } |
| 61 |
| 62 function onPlaying(event) { |
| 63 // Not using waitForEventAndRunStep() to avoid too many |
| 64 // EVENT(onTimeUpdate) logs. |
| 65 _video.addEventListener('timeupdate', onTimeupdate, true); |
| 66 } |
| 67 |
| 68 function onClosed() { |
| 69 // Try and reload and check this fails |
| 70 var mediaKeySession = _mediaKeys.createSession( 'persistent-license'
); |
| 71 mediaKeySession.load(_sessionId).then( test.step_func(function(succe
ss) { |
| 72 assert_false( success, "Load of removed session shouold fail" ); |
| 73 test.done(); |
| 74 })).catch(onFailure); |
| 75 } |
| 76 |
| 77 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration])
.then(function(access) { |
| 78 return access.createMediaKeys(); |
| 79 }).then(function(mediaKeys) { |
| 80 _mediaKeys = mediaKeys; |
| 81 return _video.setMediaKeys(_mediaKeys); |
| 82 }).then(function() { |
| 83 _mediaKeySession = _mediaKeys.createSession('persistent-license'); |
| 84 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); |
| 85 waitForEventAndRunStep('playing', _video, onPlaying, test); |
| 86 return testmediasource(config); |
| 87 }).then(function(source) { |
| 88 _mediaSource = source; |
| 89 _video.src = URL.createObjectURL(_mediaSource); |
| 90 return source.done; |
| 91 }).then(function(){ |
| 92 _video.play(); |
| 93 }).catch(onFailure); |
| 94 }, testname); |
| 95 } |
OLD | NEW |