OLD | NEW |
(Empty) | |
| 1 SETMEDIAKEYS_IMMEDIATELY = 0; |
| 2 SETMEDIAKEYS_AFTER_SRC = 1; |
| 3 SETMEDIAKEYS_ONENCRYPTED = 2; |
| 4 SETMEDIAKEYS_AFTER_UPDATE = 3; |
| 5 |
| 6 function runTest(config,qualifier) { |
| 7 |
| 8 var testcase = (config.testcase === SETMEDIAKEYS_IMMEDIATELY) ? 'setMediaKey
s first' |
| 9 : (config.testcase === SETMEDIAKEYS_AFTER_SRC) ? 'setMediaKe
ys after setting video.src' |
| 10 : (config.testcase === SETMEDIAKEYS_ONENCRYPTED) ? 'setMedia
Keys in encrypted event' |
| 11 : (config.testcase === SETMEDIAKEYS_AFTER_UPDATE) ? 'setMedi
aKeys after updating session' |
| 12 : 'unknown'; |
| 13 |
| 14 var testname = testnamePrefix(qualifier, config.keysystem) |
| 15 + ', temporary, ' |
| 16 + /video\/([^;]*)/.exec(config.videoType)[1] |
| 17 + ', playback, ' + testcase; |
| 18 |
| 19 var configuration = { initDataTypes: [ config.initDataType ], |
| 20 audioCapabilities: [ { contentType: config.audioType
} ], |
| 21 videoCapabilities: [ { contentType: config.videoType
} ], |
| 22 sessionTypes: [ 'temporary' ] }; |
| 23 |
| 24 async_test(function(test) { |
| 25 var _video = config.video, |
| 26 _mediaKeys, |
| 27 _mediaKeySession, |
| 28 _mediaSource; |
| 29 |
| 30 function onFailure(error) { |
| 31 forceTestFailureFromPromise(test, error); |
| 32 } |
| 33 |
| 34 function onMessage(event) { |
| 35 assert_equals(event.target, _mediaKeySession); |
| 36 assert_true(event instanceof window.MediaKeyMessageEvent); |
| 37 assert_equals(event.type, 'message'); |
| 38 |
| 39 assert_in_array( event.messageType, ['license-request', 'individuali
zation-request']); |
| 40 |
| 41 config.messagehandler(event.messageType, event.message).then(functio
n(response) { |
| 42 return _mediaKeySession.update( response ); |
| 43 }).then(function() { |
| 44 if (config.testcase === SETMEDIAKEYS_AFTER_UPDATE) { |
| 45 return _video.setMediaKeys(_mediaKeys); |
| 46 } |
| 47 }).catch(onFailure); |
| 48 } |
| 49 |
| 50 function onEncrypted(event) { |
| 51 assert_equals(event.target, _video); |
| 52 assert_true(event instanceof window.MediaEncryptedEvent); |
| 53 assert_equals(event.type, 'encrypted'); |
| 54 |
| 55 var promise = ( config.testcase === SETMEDIAKEYS_ONENCRYPTED ) |
| 56 ? _video.setMediaKeys(_mediaKeys) |
| 57 : Promise.resolve(); |
| 58 |
| 59 promise.then( function() { |
| 60 waitForEventAndRunStep('message', _mediaKeySession, onMessage, t
est); |
| 61 return _mediaKeySession.generateRequest(config.initData ? config
.initDataType : event.initDataType, |
| 62 config.initData || event
.initData ); |
| 63 }).catch(onFailure); |
| 64 } |
| 65 |
| 66 function onTimeupdate(event) { |
| 67 if (_video.currentTime > (config.duration || 1)) { |
| 68 _video.pause(); |
| 69 test.done(); |
| 70 } |
| 71 } |
| 72 |
| 73 function onPlaying(event) { |
| 74 // Not using waitForEventAndRunStep() to avoid too many |
| 75 // EVENT(onTimeUpdate) logs. |
| 76 _video.addEventListener('timeupdate', onTimeupdate, true); |
| 77 } |
| 78 |
| 79 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration])
.then(function(access) { |
| 80 return access.createMediaKeys(); |
| 81 }).then(test.step_func(function(mediaKeys) { |
| 82 _mediaKeys = mediaKeys; |
| 83 if ( config.testcase === SETMEDIAKEYS_IMMEDIATELY ) { |
| 84 return _video.setMediaKeys( _mediaKeys ); |
| 85 } |
| 86 })).then(function(){ |
| 87 _mediaKeySession = _mediaKeys.createSession( 'temporary' ); |
| 88 |
| 89 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); |
| 90 waitForEventAndRunStep('playing', _video, onPlaying, test); |
| 91 |
| 92 return testmediasource(config); |
| 93 }).then(function(source) { |
| 94 _mediaSource = source; |
| 95 _video.src = URL.createObjectURL(_mediaSource); |
| 96 return source.done; |
| 97 }).then(function(){ |
| 98 _video.play(); |
| 99 |
| 100 if (config.testcase === SETMEDIAKEYS_AFTER_SRC) { |
| 101 return _video.setMediaKeys(_mediaKeys); |
| 102 } |
| 103 }).catch(onFailure); |
| 104 }, testname); |
| 105 } |
OLD | NEW |