OLD | NEW |
(Empty) | |
| 1 function runTest(config,qualifier) { |
| 2 |
| 3 var testname = testnamePrefix(qualifier, config.keysystem) |
| 4 + ', temporary, ' |
| 5 + /video\/([^;]*)/.exec(config.videoType)[1] |
| 6 + ', expired license'; |
| 7 |
| 8 var configuration = { initDataTypes: [config.initDataType], |
| 9 audioCapabilities: [{contentType: config.audioType}]
, |
| 10 videoCapabilities: [{contentType: config.videoType}]
, |
| 11 sessionTypes: ['temporary'] }; |
| 12 |
| 13 async_test(function(test) { |
| 14 |
| 15 var _video = config.video, |
| 16 _mediaKeys, |
| 17 _mediaKeySession, |
| 18 _mediaSource; |
| 19 |
| 20 function onFailure(error) { |
| 21 forceTestFailureFromPromise(test, error); |
| 22 } |
| 23 |
| 24 function onEncrypted(event) { |
| 25 assert_equals(event.target, _video); |
| 26 assert_true(event instanceof window.MediaEncryptedEvent); |
| 27 assert_equals(event.type, 'encrypted'); |
| 28 |
| 29 // Only create the session for the first encrypted event |
| 30 if (_mediaKeySession !== undefined) return; |
| 31 |
| 32 var initDataType = config.initData ? config.initDataType : event.ini
tDataType; |
| 33 var initData = config.initData || event.initData; |
| 34 |
| 35 _mediaKeySession = _mediaKeys.createSession('temporary'); |
| 36 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test)
; |
| 37 _mediaKeySession.generateRequest(initDataType, initData).catch(onFai
lure); |
| 38 } |
| 39 |
| 40 function onMessage(event) { |
| 41 assert_equals(event.target, _mediaKeySession); |
| 42 assert_true(event instanceof window.MediaKeyMessageEvent); |
| 43 assert_equals(event.type, 'message'); |
| 44 |
| 45 assert_in_array(event.messageType, ['license-request', 'individualiz
ation-request']); |
| 46 |
| 47 var expiration = Date.now().valueOf() + 1000; |
| 48 config.messagehandler(event.messageType, event.message, { expiration
: expiration }).then(function(response) { |
| 49 return event.target.update(response); |
| 50 }).then(test.step_func(function() { |
| 51 // License server may only have second granularity, so check |
| 52 // that session expiration time is close to the desired value. |
| 53 assert_approx_equals(event.target.expiration, expiration, 2000,
"expiration attribute should equal provided expiration time"); |
| 54 |
| 55 // Since the expiration time is in the future, wait 5 seconds |
| 56 // so that the license has expired before calling play(). |
| 57 test.step_timeout(function() { |
| 58 assert_greater_than(Date.now().valueOf(), expiration, "Start
ing play before license expired"); |
| 59 _video.play(); |
| 60 // Wait 2 seconds to ensure that the video does not play. |
| 61 test.step_timeout(function() { test.done(); }, 2000); |
| 62 }, 5000); |
| 63 })).catch(onFailure); |
| 64 } |
| 65 |
| 66 function onPlaying(event) { |
| 67 // Not using waitForEventAndRunStep() to avoid too many |
| 68 // EVENT(onTimeUpdate) logs. |
| 69 _video.addEventListener('timeupdate', test.step_func(onTimeupdate),
true); |
| 70 } |
| 71 |
| 72 function onTimeupdate(event) { |
| 73 _video.pause(); |
| 74 assert_unreached("Playback should not start with expired license"); |
| 75 } |
| 76 |
| 77 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration])
.then(function(access) { |
| 78 return access.createMediaKeys(); |
| 79 }).then(function(mediaKeys) { |
| 80 _mediaKeys = mediaKeys; |
| 81 return _video.setMediaKeys(_mediaKeys); |
| 82 }).then(function(){ |
| 83 waitForEventAndRunStep('encrypted', _video, onEncrypted, test); |
| 84 waitForEventAndRunStep('playing', _video, onPlaying, test); |
| 85 return testmediasource(config); |
| 86 }).then(function(source) { |
| 87 _mediaSource = source; |
| 88 _video.src = URL.createObjectURL(_mediaSource); |
| 89 return source.done; |
| 90 }).catch(onFailure); |
| 91 }, testname); |
| 92 } |
OLD | NEW |