OLD | NEW |
(Empty) | |
| 1 function runTest(config,qualifier) { |
| 2 |
| 3 var testname = testnamePrefix(qualifier, config.keysystem) |
| 4 + ', persistent-usage-record, ' |
| 5 + /video\/([^;]*)/.exec(config.videoType)[1] |
| 6 + 'playback'; |
| 7 |
| 8 var configuration = { initDataTypes: [ config.initDataType ], |
| 9 audioCapabilities: [ { contentType: config.audioType
} ], |
| 10 videoCapabilities: [ { contentType: config.videoType
} ], |
| 11 sessionTypes: [ 'persistent-usage-record' ] }; |
| 12 |
| 13 |
| 14 async_test(function(test) { |
| 15 var _video = config.video, |
| 16 _mediaKeys, |
| 17 _mediaKeySession, |
| 18 _mediaSource, |
| 19 _releaseSequence = false; |
| 20 |
| 21 function onFailure(error) { |
| 22 forceTestFailureFromPromise(test, error); |
| 23 } |
| 24 |
| 25 function onMessage(event) { |
| 26 assert_equals(event.target, _mediaKeySession); |
| 27 // event instance verification failing on CastTV |
| 28 // assert_true( event instanceof window.MediaKeyMessageEvent ); |
| 29 assert_equals(event.type, 'message'); |
| 30 |
| 31 if (!_releaseSequence) |
| 32 { |
| 33 assert_in_array(event.messageType, ['license-request', 'individu
alization-request']); |
| 34 } |
| 35 else |
| 36 { |
| 37 assert_equals(event.messageType, 'license-release'); |
| 38 } |
| 39 |
| 40 config.messagehandler(event.messageType, event.message).then(functio
n(response) { |
| 41 return _mediaKeySession.update(response); |
| 42 }).then(function() { |
| 43 if(event.messageType === 'license-request') { |
| 44 return _video.setMediaKeys(_mediaKeys); |
| 45 } else if(event.messageType === 'license-release') { |
| 46 test.done(); |
| 47 } |
| 48 }).catch(onFailure); |
| 49 } |
| 50 |
| 51 function onEncrypted(event) { |
| 52 assert_equals(event.target, _video); |
| 53 assert_true(event instanceof window.MediaEncryptedEvent); |
| 54 assert_equals(event.type, 'encrypted'); |
| 55 |
| 56 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test)
; |
| 57 _mediaKeySession.generateRequest( config.initData ? config.initDat
aType : event.initDataType, |
| 58 config.initData || event.initDat
a ) |
| 59 .catch(onFailure); |
| 60 } |
| 61 |
| 62 function onClosed(event) { |
| 63 _video.src = ""; |
| 64 _video.setMediaKeys( null ); |
| 65 } |
| 66 |
| 67 function onTimeupdate(event) { |
| 68 if (_video.currentTime > ( config.duration || 1) && !_releaseSequenc
e) { |
| 69 _video.removeEventListener('timeupdate', onTimeupdate ); |
| 70 _video.pause(); |
| 71 _releaseSequence = true; |
| 72 |
| 73 _mediaKeySession.closed.then(test.step_func(onClosed)); |
| 74 _mediaKeySession.remove().catch(onFailure); |
| 75 |
| 76 _video.removeEventListener('timeupdate', onTimeupdate); |
| 77 } |
| 78 } |
| 79 |
| 80 function onPlaying(event) { |
| 81 // Not using waitForEventAndRunStep() to avoid too many |
| 82 // EVENT(onTimeUpdate) logs. |
| 83 _video.addEventListener('timeupdate', onTimeupdate, true); |
| 84 } |
| 85 |
| 86 navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration
]).then(function(access) { |
| 87 return access.createMediaKeys(); |
| 88 }).then(function(mediaKeys) { |
| 89 _mediaKeys = mediaKeys; |
| 90 _mediaKeySession = _mediaKeys.createSession('persistent-usage-record
'); |
| 91 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); |
| 92 waitForEventAndRunStep('playing', _video, onPlaying, test); |
| 93 return config.servercertificate ? _mediaKeys.setServerCertificate(co
nfig.servercertificate) : true; |
| 94 }).then(function(success) { |
| 95 return testmediasource(config); |
| 96 }).then(function(source) { |
| 97 _mediaSource = source; |
| 98 _video.src = URL.createObjectURL(_mediaSource); |
| 99 return source.done; |
| 100 }).then(function(){ |
| 101 _video.play(); |
| 102 }).catch(onFailure); |
| 103 }, testname); |
| 104 } |
OLD | NEW |