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, check events'; |
| 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 _sessionId, |
| 19 _timeupdateEvent = false, |
| 20 _events = [ ]; |
| 21 |
| 22 function recordEventFunc(eventType) { |
| 23 return function() { _events.push(eventType); }; |
| 24 } |
| 25 |
| 26 function onFailure(error) { |
| 27 forceTestFailureFromPromise(test, error); |
| 28 } |
| 29 |
| 30 function onMessage(event) { |
| 31 assert_equals(event.target, _mediaKeySession); |
| 32 assert_true(event instanceof window.MediaKeyMessageEvent); |
| 33 assert_equals(event.type, 'message'); |
| 34 |
| 35 if (event.messageType !== 'individualization-request') { |
| 36 _events.push(event.messageType); |
| 37 } |
| 38 |
| 39 config.messagehandler(event.messageType, event.message).then(functio
n(response) { |
| 40 _events.push(event.messageType + '-response'); |
| 41 return _mediaKeySession.update(response); |
| 42 }).then(test.step_func(function() { |
| 43 _events.push('update-resolved'); |
| 44 if (event.messageType === 'license-release') { |
| 45 checkEventSequence( _events, |
| 46 ['encrypted','generaterequest-done', |
| 47 ['license-request', 'license-request-res
ponse', 'update-resolved'], // potentially repeating |
| 48 'keystatuseschange', |
| 49 'playing', |
| 50 'remove-resolved', |
| 51 'keystatuseschange', |
| 52 'license-release', |
| 53 'license-release-response', |
| 54 'closed-attribute-resolved', |
| 55 'update-resolved' ]); |
| 56 test.done(); |
| 57 } |
| 58 |
| 59 if ( event.messageType === 'license-request' ) { |
| 60 _video.setMediaKeys(_mediaKeys); |
| 61 } |
| 62 })).catch(onFailure); |
| 63 } |
| 64 |
| 65 function onEncrypted(event) { |
| 66 assert_equals(event.target, _video); |
| 67 assert_true(event instanceof window.MediaEncryptedEvent); |
| 68 _events.push(event.type); |
| 69 _mediaKeySession.generateRequest( config.initDataType || event.ini
tDataType, |
| 70 config.initData || event.initDat
a ).then( function() { |
| 71 _events.push( 'generaterequest-done' ); |
| 72 _sessionId = _mediaKeySession.sessionId; |
| 73 }).catch(onFailure); |
| 74 } |
| 75 |
| 76 function onTimeupdate(event) { |
| 77 if (_video.currentTime > (config.duration || 1) && !_timeupdateEvent
) { |
| 78 _timeupdateEvent = true; |
| 79 _video.pause(); |
| 80 _mediaKeySession.remove().then(recordEventFunc('remove-resolved'
)).catch(onFailure); |
| 81 } |
| 82 } |
| 83 |
| 84 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration])
.then(function(access) { |
| 85 return access.createMediaKeys(); |
| 86 }).then(function(mediaKeys) { |
| 87 _mediaKeys = mediaKeys; |
| 88 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); |
| 89 waitForEventAndRunStep('playing', _video, recordEventFunc('playing')
, test); |
| 90 |
| 91 // Not using waitForEventAndRunStep() to avoid too many |
| 92 // EVENT(onTimeUpdate) logs. |
| 93 _video.addEventListener('timeupdate', onTimeupdate, true); |
| 94 |
| 95 _mediaKeySession = _mediaKeys.createSession( 'persistent-usage-recor
d' ); |
| 96 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test)
; |
| 97 waitForEventAndRunStep('keystatuseschange', _mediaKeySession, record
EventFunc('keystatuseschange'), test); |
| 98 _mediaKeySession.closed.then(recordEventFunc('closed-attribute-resol
ved')); |
| 99 return config.servercertificate ? _mediaKeys.setServerCertificate(co
nfig.servercertificate) : true; |
| 100 }).then(function( success ) { |
| 101 return testmediasource(config); |
| 102 }).then(function(source) { |
| 103 _video.src = URL.createObjectURL(source); |
| 104 return source.done; |
| 105 }).then(function(){ |
| 106 _video.play(); |
| 107 }).catch(onFailure); |
| 108 }, testname); |
| 109 } |
OLD | NEW |