OLD | NEW |
(Empty) | |
| 1 function runTest(config,qualifier) { |
| 2 |
| 3 // config.initData contains a list of keys. We expect those to be needed in
order and get |
| 4 // one waitingforkey event for each one. |
| 5 |
| 6 var testname = testnamePrefix(qualifier, config.keysystem) |
| 7 + ', successful playback, temporary, ' |
| 8 + /video\/([^;]*)/.exec(config.videoType)[1] |
| 9 + ', multiple keys, sequential' |
| 10 + (config.checkReadyState ? ', readyState' :
''); |
| 11 |
| 12 var configuration = { initDataTypes: [config.initDataType], |
| 13 audioCapabilities: [{contentType: config.audioType}]
, |
| 14 videoCapabilities: [{contentType: config.videoType}]
, |
| 15 sessionTypes: ['temporary'] }; |
| 16 |
| 17 async_test(function(test) { |
| 18 var _video = config.video, |
| 19 _mediaKeys, |
| 20 _mediaKeySessions = [], |
| 21 _mediaSource, |
| 22 _waitingForKey = false, |
| 23 _playingCount = 0, |
| 24 _canplayCount = 0, |
| 25 _timeupdateWhileWaitingCount = 0; |
| 26 |
| 27 function startNewSession() { |
| 28 assert_less_than(_mediaKeySessions.length, config.initData.length); |
| 29 var mediaKeySession = _mediaKeys.createSession('temporary'); |
| 30 waitForEventAndRunStep('message', mediaKeySession, onMessage, test); |
| 31 _mediaKeySessions.push(mediaKeySession); |
| 32 mediaKeySession.variantId = config.variantIds ? config.variantIds[_m
ediaKeySessions.length - 1] : undefined; |
| 33 mediaKeySession.generateRequest(config.initDataType, config.initData
[_mediaKeySessions.length - 1]).catch(onFailure); |
| 34 } |
| 35 |
| 36 function onFailure(error) { |
| 37 forceTestFailureFromPromise(test, error); |
| 38 } |
| 39 |
| 40 function onMessage(event) { |
| 41 var firstMessage = !_video.src; |
| 42 config.messagehandler(event.messageType, event.message, {variantId:
event.target.variantId}).then(function(response) { |
| 43 return event.target.update(response); |
| 44 }).then(function(){ |
| 45 if (firstMessage) { |
| 46 _video.src = URL.createObjectURL(_mediaSource); |
| 47 return _mediaSource.done; |
| 48 } else if (event.target.keyStatuses.size > 0){ |
| 49 _waitingForKey = false; |
| 50 return Promise.resolve(); |
| 51 } |
| 52 }).then(function(){ |
| 53 if (firstMessage) { |
| 54 _video.play(); |
| 55 } |
| 56 }).catch(onFailure); |
| 57 } |
| 58 |
| 59 function onWaitingForKey(event) { |
| 60 _waitingForKey = true; |
| 61 if (config.checkReadyState) { |
| 62 // This test does not start playing until the first license has
been provided, |
| 63 // so this event should occur when transitioning between keys. |
| 64 // Thus, the frame at the current playback position is available
and readyState |
| 65 // should be HAVE_CURRENT_DATA. |
| 66 assert_equals(_video.readyState, _video.HAVE_CURRENT_DATA, "Vide
o readyState should be HAVE_CURRENT_DATA on watingforkey event"); |
| 67 } |
| 68 startNewSession(); |
| 69 } |
| 70 |
| 71 function onPlaying(event) { |
| 72 _playingCount++; |
| 73 assert_equals(_mediaKeySessions.length, _playingCount, "Should get o
ne 'playing' event per key / session added"); |
| 74 assert_less_than_equal(_playingCount, 2, "Should not get more than t
wo 'playing' events."); |
| 75 } |
| 76 |
| 77 function onCanPlay(event) { |
| 78 _canplayCount++; |
| 79 assert_equals(_mediaKeySessions.length, _canplayCount, "Should get o
ne 'canplay' event per key / session added"); |
| 80 assert_less_than_equal(_canplayCount, 2, "Should not get more than t
wo 'canplay' events."); |
| 81 } |
| 82 |
| 83 function onTimeupdate(event) { |
| 84 // We should not receive 'timeupdate' events due to playing while wa
iting for a key, except |
| 85 // when we first start waiting for key we should change the readySta
te to HAVE_CURRENT_DATA |
| 86 // which will trigger the "If the previous ready state was HAVE_FUTU
RE_DATA or more, and |
| 87 // the new ready state is HAVE_CURRENT_DATA or less" case of the rea
dyState change |
| 88 // algorithm which requires a "timeupdate" event be fired. |
| 89 if (_waitingForKey) { |
| 90 assert_equals(++_timeupdateWhileWaitingCount, 1, "Should only re
ceive one timeupdate while waiting for key"); |
| 91 assert_equals(_video.readyState, _video.HAVE_CURRENT_DATA, "Vide
o readyState should be HAVE_CURRENT_DATA while wating for key"); |
| 92 } |
| 93 |
| 94 if (_video.currentTime > config.duration) { |
| 95 assert_equals(_mediaKeySessions.length, config.initData.length,
"It should require all keys to reach end of content"); |
| 96 assert_equals(_timeupdateWhileWaitingCount, 1, "Should have only
received exactly one timeupdate while waiting for key"); |
| 97 _video.pause(); |
| 98 test.done(); |
| 99 } |
| 100 } |
| 101 |
| 102 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration])
.then(function(access) { |
| 103 return access.createMediaKeys(); |
| 104 }).then(function(mediaKeys) { |
| 105 _mediaKeys = mediaKeys; |
| 106 return _video.setMediaKeys(_mediaKeys); |
| 107 }).then(function(){ |
| 108 // Not using waitForEventAndRunStep() to avoid too many |
| 109 // EVENT(onTimeUpdate) logs. |
| 110 _video.addEventListener('timeupdate', test.step_func(onTimeupdate),
true); |
| 111 |
| 112 waitForEventAndRunStep('waitingforkey', _video, onWaitingForKey, tes
t); |
| 113 waitForEventAndRunStep('playing', _video, onPlaying, test); |
| 114 waitForEventAndRunStep('canplay', _video, onCanPlay, test); |
| 115 |
| 116 return testmediasource(config); |
| 117 }).then(function(source) { |
| 118 _mediaSource = source; |
| 119 startNewSession(); |
| 120 }).catch(onFailure); |
| 121 }, testname); |
| 122 } |
OLD | NEW |