OLD | NEW |
(Empty) | |
| 1 function runTest(config, qualifier) { |
| 2 var testname = testnamePrefix(qualifier, config.keysystem) |
| 3 + ', setmediakeys again after playback'; |
| 4 |
| 5 var configuration = getSimpleConfigurationForContent(config.content); |
| 6 |
| 7 if (config.initDataType && config.initData) { |
| 8 configuration.initDataTypes = [config.initDataType]; |
| 9 } |
| 10 |
| 11 async_test(function(test) { |
| 12 var _video = config.video, |
| 13 _access, |
| 14 _mediaKeys, |
| 15 _mediaKeySession, |
| 16 _mediaSource; |
| 17 |
| 18 function onFailure(error) { |
| 19 forceTestFailureFromPromise(test, error); |
| 20 } |
| 21 |
| 22 function onMessage(event) { |
| 23 config.messagehandler(event.messageType, event.message).then( functi
on(response) { |
| 24 _mediaKeySession.update(response).catch(onFailure).then(function
() { |
| 25 _video.play(); |
| 26 }); |
| 27 }); |
| 28 } |
| 29 |
| 30 function onEncrypted(event) { |
| 31 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test)
; |
| 32 _mediaKeySession.generateRequest( config.initData ? config.initDat
aType : event.initDataType, |
| 33 config.initData || event.initDat
a ) |
| 34 .catch(onFailure); |
| 35 } |
| 36 |
| 37 function playVideo() |
| 38 { |
| 39 return new Promise(function(resolve) { |
| 40 _mediaKeySession = _mediaKeys.createSession('temporary'); |
| 41 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); |
| 42 _video.src = URL.createObjectURL(_mediaSource); |
| 43 resolve('success'); |
| 44 }); |
| 45 } |
| 46 |
| 47 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration])
.then(function(access) { |
| 48 _access = access; |
| 49 return _access.createMediaKeys(); |
| 50 }).then(function(result) { |
| 51 _mediaKeys = result; |
| 52 return _video.setMediaKeys(_mediaKeys); |
| 53 }).then(function() { |
| 54 return config.servercertificate ? _mediaKeys.setServerCertificate( c
onfig.servercertificate ) : true; |
| 55 }).then(function( success ) { |
| 56 return testmediasource(config); |
| 57 }).then(function(source) { |
| 58 _mediaSource = source; |
| 59 return playVideo(); |
| 60 }).then(function(results) { |
| 61 return _access.createMediaKeys(); |
| 62 }).then(function(result) { |
| 63 _mediaKeys = result; |
| 64 return waitForEvent('playing', _video); |
| 65 }).then(test.step_func(function(result) { |
| 66 assert_false(_video.ended); |
| 67 return _video.setMediaKeys(_mediaKeys); |
| 68 })).then(function() { |
| 69 // Able to change MediaKeys while playing. |
| 70 // This is not required to fail. |
| 71 _video.src=''; |
| 72 test.done(); |
| 73 }, test.step_func(function(error) { |
| 74 assert_in_array(error.name, ['InvalidStateError','NotSupportedError'
]); |
| 75 _video.src=''; |
| 76 test.done(); |
| 77 })).catch(onFailure); |
| 78 }, testname); |
| 79 } |
OLD | NEW |