OLD | NEW |
(Empty) | |
| 1 function runTest(configEncrypted,configClear,qualifier) { |
| 2 |
| 3 var testname = testnamePrefix(qualifier, configEncrypted.keysystem) |
| 4 + ', temporary, ' |
| 5 + /video\/([^;]*)/.exec(configEncrypted.vide
oType)[1] |
| 6 + ', playback, encrypted and clear sources'; |
| 7 |
| 8 var configuration = { initDataTypes: [ configEncrypted.initDataType ], |
| 9 audioCapabilities: [ { contentType: configEncrypted.
audioType } ], |
| 10 videoCapabilities: [ { contentType: configEncrypted.
videoType } ], |
| 11 sessionTypes: [ 'temporary' ] }; |
| 12 |
| 13 async_test(function(test) { |
| 14 var playbackCount = 0, |
| 15 _video = configEncrypted.video, |
| 16 _mediaKeys, |
| 17 _mediaKeySession, |
| 18 _mediaSource; |
| 19 |
| 20 function onFailure(error) { |
| 21 forceTestFailureFromPromise(test, error); |
| 22 } |
| 23 |
| 24 function onMessage(event) { |
| 25 assert_equals(event.target, _mediaKeySession); |
| 26 assert_true(event instanceof window.MediaKeyMessageEvent); |
| 27 assert_equals(event.type, 'message'); |
| 28 assert_in_array(event.messageType, ['license-request', 'individualiz
ation-request']); |
| 29 |
| 30 configEncrypted.messagehandler(event.messageType, event.message).the
n(function(response) { |
| 31 return _mediaKeySession.update( response ); |
| 32 }).catch(onFailure); |
| 33 } |
| 34 |
| 35 function onEncrypted(event) { |
| 36 assert_equals(event.target, _video); |
| 37 assert_true(event instanceof window.MediaEncryptedEvent); |
| 38 assert_equals(event.type, 'encrypted'); |
| 39 |
| 40 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test)
; |
| 41 _mediaKeySession.generateRequest(configEncrypted.initData ? configEn
crypted.initDataType : event.initDataType, |
| 42 configEncrypted.initData || even
t.initData).then(function(){ |
| 43 return _video.setMediaKeys(_mediaKeys); |
| 44 }).catch(onFailure); |
| 45 } |
| 46 |
| 47 function onPlaying(event) |
| 48 { |
| 49 // Not using waitForEventAndRunStep() to avoid too many |
| 50 // EVENT(onTimeUpdate) logs. |
| 51 _video.addEventListener('timeupdate', onTimeUpdate, true); |
| 52 } |
| 53 |
| 54 function onTimeUpdate(event) { |
| 55 if (_video.currentTime < (configEncrypted.duration || 0.5)) { |
| 56 return; |
| 57 } |
| 58 |
| 59 _video.removeEventListener('timeupdate', onTimeUpdate, true); |
| 60 |
| 61 resetSrc().then(function(){ |
| 62 if (playbackCount >= 2) { |
| 63 test.done(); |
| 64 } else { |
| 65 playbackCount++; |
| 66 startPlayback(); |
| 67 } |
| 68 }).catch(onFailure); |
| 69 } |
| 70 |
| 71 function resetSrc() { |
| 72 _video.pause(); |
| 73 _video.removeAttribute('src'); |
| 74 _video.load(); |
| 75 return _video.setMediaKeys(null); |
| 76 } |
| 77 |
| 78 function startPlayback() { |
| 79 // Alternate between encrypted and unencrypted files. |
| 80 if (playbackCount % 2) { |
| 81 // Unencrypted files don't require MediaKeys |
| 82 testmediasource( configClear ).then(function( source ) { |
| 83 _mediaSource = source; |
| 84 _video.src = URL.createObjectURL(_mediaSource); |
| 85 _video.play(); |
| 86 }).catch(onFailure); |
| 87 } else { |
| 88 navigator.requestMediaKeySystemAccess(configEncrypted.keysystem,
[ configuration ]).then(function(access) { |
| 89 return access.createMediaKeys(); |
| 90 }).then(function(mediaKeys) { |
| 91 _mediaKeys = mediaKeys; |
| 92 _mediaKeySession = _mediaKeys.createSession( 'temporary' ); |
| 93 }).then(function() { |
| 94 return testmediasource(configEncrypted); |
| 95 }).then(function(source) { |
| 96 _mediaSource = source; |
| 97 _video.src = URL.createObjectURL(_mediaSource); |
| 98 return source.done; |
| 99 }).then(function(){ |
| 100 _video.play(); |
| 101 }).catch(onFailure); |
| 102 } |
| 103 } |
| 104 |
| 105 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); |
| 106 waitForEventAndRunStep('playing', _video, onPlaying, test); |
| 107 startPlayback(); |
| 108 }, testname); |
| 109 } |
OLD | NEW |