OLD | NEW |
(Empty) | |
| 1 function runTest(config,qualifier) { |
| 2 |
| 3 var testname = testnamePrefix(qualifier, config.keysystem) |
| 4 + ', temporary, ' |
| 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: [ 'temporary' ] }; |
| 12 |
| 13 async_test(function(test) { |
| 14 var _video = config.video, |
| 15 _mediaKeys, |
| 16 _mediaKeySession, |
| 17 _mediaSource, |
| 18 _timeupdateEvent = false, |
| 19 _events = [ ]; |
| 20 |
| 21 function onFailure(error) { |
| 22 forceTestFailureFromPromise(test, error); |
| 23 } |
| 24 |
| 25 function onMessage(event) { |
| 26 assert_equals(event.target, _mediaKeySession); |
| 27 assert_true(event instanceof window.MediaKeyMessageEvent); |
| 28 assert_equals(event.type, 'message'); |
| 29 |
| 30 assert_in_array( event.messageType, ['license-request', 'individual
ization-request']); |
| 31 |
| 32 if (event.messageType !== 'individualization-request') { |
| 33 _events.push(event.messageType); |
| 34 } |
| 35 |
| 36 config.messagehandler(event.messageType, event.message).then(functio
n(response) { |
| 37 _events.push('license-request-response'); |
| 38 waitForEventAndRunStep('keystatuseschange', _mediaKeySession, on
KeyStatusesChange, test); |
| 39 return _mediaKeySession.update( response ); |
| 40 }).then(function() { |
| 41 _events.push('update-resolved'); |
| 42 }).catch(onFailure); |
| 43 } |
| 44 |
| 45 function onKeyStatusesChange(event) { |
| 46 assert_equals(event.target, _mediaKeySession); |
| 47 assert_true(event instanceof window.Event); |
| 48 assert_equals(event.type, 'keystatuseschange'); |
| 49 var hasKeys = false, pendingKeys = false; |
| 50 _mediaKeySession.keyStatuses.forEach(function(value, keyid) { |
| 51 assert_in_array(value, ['status-pending', 'usable']); |
| 52 hasKeys = true; |
| 53 pendingKeys = pendingKeys || (value === 'status-pending'); |
| 54 }); |
| 55 |
| 56 if (!hasKeys) { |
| 57 _events.push('emptykeyslist'); |
| 58 } else if (!pendingKeys ) { |
| 59 _events.push('allkeysusable'); |
| 60 _video.setMediaKeys(_mediaKeys).catch(onFailure); |
| 61 } else { |
| 62 assert_unreached('unexpected ' + event.type + ' event'); |
| 63 } |
| 64 } |
| 65 |
| 66 function onEncrypted(event) { |
| 67 assert_equals(event.target, _video); |
| 68 assert_true(event instanceof window.MediaEncryptedEvent); |
| 69 assert_equals(event.type, 'encrypted'); |
| 70 |
| 71 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test)
; |
| 72 _mediaKeySession.generateRequest(config.initData ? config.initDataTy
pe : event.initDataType, |
| 73 config.initData || event.initDat
a ).then(function() { |
| 74 _events.push('generaterequest'); |
| 75 }).catch(onFailure); |
| 76 } |
| 77 |
| 78 function onClosed(event) { |
| 79 _events.push('closed-attribute-resolved'); |
| 80 setTimeout(test.step_func(function() { |
| 81 checkEventSequence( _events, |
| 82 ['generaterequest', |
| 83 ['license-request', 'license-request-res
ponse', 'update-resolved'], // potentially repeating |
| 84 'allkeysusable', |
| 85 'playing', |
| 86 'closed-attribute-resolved', |
| 87 'close-promise-resolved', |
| 88 'emptykeyslist']); |
| 89 test.done(); |
| 90 } ), 0); |
| 91 } |
| 92 |
| 93 function onTimeupdate(event) { |
| 94 if (_video.currentTime > (config.duration || 1) && !_timeupdateEvent
) { |
| 95 _timeupdateEvent = true; |
| 96 _video.pause(); |
| 97 |
| 98 _mediaKeySession.closed.then(test.step_func(onClosed)); |
| 99 _mediaKeySession.close().then(function() { |
| 100 _events.push('close-promise-resolved'); |
| 101 }).catch(onFailure); |
| 102 } |
| 103 } |
| 104 |
| 105 function onPlaying(event) { |
| 106 _events.push('playing'); |
| 107 |
| 108 // Not using waitForEventAndRunStep() to avoid too many |
| 109 // EVENT(onTimeUpdate) logs. |
| 110 _video.addEventListener('timeupdate', onTimeupdate, true); |
| 111 } |
| 112 |
| 113 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration])
.then(function(access) { |
| 114 return access.createMediaKeys(); |
| 115 }).then(function(mediaKeys) { |
| 116 _mediaKeys = mediaKeys; |
| 117 _mediaKeySession = _mediaKeys.createSession('temporary'); |
| 118 |
| 119 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); |
| 120 waitForEventAndRunStep('playing', _video, onPlaying, test); |
| 121 }).then(function() { |
| 122 return testmediasource(config); |
| 123 }).then(function(source) { |
| 124 _mediaSource = source; |
| 125 _video.src = URL.createObjectURL(_mediaSource); |
| 126 return source.done; |
| 127 }).then(function(){ |
| 128 _video.play(); |
| 129 }).catch(onFailure); |
| 130 }, testname); |
| 131 } |
OLD | NEW |