OLD | NEW |
(Empty) | |
| 1 function runTest(config,qualifier) { |
| 2 |
| 3 var testname = testnamePrefix(qualifier, config.keysystem) + ', basic events
'; |
| 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 { |
| 13 var initDataType; |
| 14 var initData; |
| 15 var mediaKeySession; |
| 16 |
| 17 function onFailure(error) { |
| 18 forceTestFailureFromPromise(test, error); |
| 19 } |
| 20 |
| 21 function processMessage(event) |
| 22 { |
| 23 assert_true(event instanceof window.MediaKeyMessageEvent); |
| 24 assert_equals(event.target, mediaKeySession); |
| 25 assert_equals(event.type, 'message'); |
| 26 assert_in_array(event.messageType,['license-request', 'individualiza
tion-request']); |
| 27 |
| 28 config.messagehandler( event.messageType, event.message ).then(funct
ion(response) { |
| 29 waitForEventAndRunStep('keystatuseschange', mediaKeySession, tes
t.step_func(processKeyStatusesChange), test); |
| 30 return mediaKeySession.update( response ); |
| 31 }).catch(onFailure); |
| 32 } |
| 33 |
| 34 function processKeyStatusesChange(event) |
| 35 { |
| 36 assert_true(event instanceof Event); |
| 37 assert_equals(event.target, mediaKeySession); |
| 38 assert_equals(event.type, 'keystatuseschange'); |
| 39 test.done(); |
| 40 } |
| 41 |
| 42 navigator.requestMediaKeySystemAccess(config.keysystem,[configuration]).
then(function(access) { |
| 43 initDataType = access.getConfiguration().initDataTypes[0]; |
| 44 |
| 45 if (config.initDataType && config.initData) { |
| 46 initData = config.initData; |
| 47 } else { |
| 48 initData = getInitData(config.content, initDataType); |
| 49 } |
| 50 |
| 51 return access.createMediaKeys(); |
| 52 }).then(test.step_func(function(mediaKeys) { |
| 53 mediaKeySession = mediaKeys.createSession(); |
| 54 waitForEventAndRunStep('message', mediaKeySession, test.step_func(pr
ocessMessage), test); |
| 55 return mediaKeySession.generateRequest(initDataType, initData); |
| 56 })).catch(onFailure); |
| 57 }, testname ); |
| 58 |
| 59 } |
OLD | NEW |