OLD | NEW |
(Empty) | |
| 1 function runTest(config,qualifier) { |
| 2 |
| 3 // This test assumes one session is required for each provided initData |
| 4 |
| 5 var testname = testnamePrefix(qualifier, config.keysystem) |
| 6 + ', temporary, ' |
| 7 + /video\/([^;]*)/.exec(config.videoType)[1] |
| 8 + ', playback with multiple sessions, ' |
| 9 + config.testcase; |
| 10 |
| 11 var configuration = { initDataTypes: [ config.initDataType ], |
| 12 audioCapabilities: [ { contentType: config.audioType
} ], |
| 13 videoCapabilities: [ { contentType: config.videoType
} ], |
| 14 sessionTypes: [ 'temporary' ] }; |
| 15 |
| 16 async_test(function(test) { |
| 17 var _video = config.video, |
| 18 _mediaKeys, |
| 19 _mediaKeySessions = [], |
| 20 _mediaSource; |
| 21 |
| 22 function onFailure(error) { |
| 23 forceTestFailureFromPromise(test, error); |
| 24 } |
| 25 |
| 26 function onMessage(event) { |
| 27 assert_any(assert_equals, event.target, _mediaKeySessions); |
| 28 assert_true(event instanceof window.MediaKeyMessageEvent); |
| 29 assert_equals(event.type, 'message'); |
| 30 |
| 31 assert_in_array(event.messageType, ['license-request', 'individualiz
ation-request']); |
| 32 |
| 33 config.messagehandler(event.messageType, event.message, {variantId:
event.target._variantId}).then(function(response) { |
| 34 return event.target.update(response); |
| 35 }).catch(onFailure); |
| 36 } |
| 37 |
| 38 function onPlaying(event) { |
| 39 // Not using waitForEventAndRunStep() to avoid too many |
| 40 // EVENT(onTimeUpdate) logs. |
| 41 _video.addEventListener('timeupdate', onTimeupdate, true); |
| 42 } |
| 43 |
| 44 function onTimeupdate(event) { |
| 45 if (_video.currentTime > (config.duration || 1)) { |
| 46 _video.removeEventListener('timeupdate', onTimeupdate); |
| 47 _video.pause(); |
| 48 test.done(); |
| 49 } |
| 50 } |
| 51 |
| 52 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration])
.then(function(access) { |
| 53 return access.createMediaKeys(); |
| 54 }).then(function(mediaKeys) { |
| 55 _mediaKeys = mediaKeys; |
| 56 return _video.setMediaKeys(_mediaKeys); |
| 57 }).then(function() { |
| 58 waitForEventAndRunStep('playing', _video, onPlaying, test); |
| 59 |
| 60 config.initData.forEach(function(initData,i) { |
| 61 var mediaKeySession = _mediaKeys.createSession( 'temporary' ); |
| 62 mediaKeySession._variantId = config.variantIds ? config.variantI
ds[i] : undefined; |
| 63 waitForEventAndRunStep('message', mediaKeySession, onMessage, te
st); |
| 64 _mediaKeySessions.push(mediaKeySession); |
| 65 mediaKeySession.generateRequest(config.initDataType, initData).c
atch(onFailure); |
| 66 } ); |
| 67 return testmediasource(config); |
| 68 }).then(function(source) { |
| 69 _mediaSource = source; |
| 70 _video.src = URL.createObjectURL(_mediaSource); |
| 71 return source.done; |
| 72 }).then(function(){ |
| 73 _video.play(); |
| 74 }).catch(onFailure); |
| 75 }, testname); |
| 76 } |
OLD | NEW |