mirror of
https://github.com/servo/servo.git
synced 2025-08-17 03:15:34 +01:00
Update web-platform-tests to revision dc5cbf088edcdb266541d4e5a76149a2c6e716a0
This commit is contained in:
parent
1d40075f03
commit
079092dfea
2381 changed files with 90360 additions and 17722 deletions
|
@ -0,0 +1,35 @@
|
|||
function runTest( config, qualifier )
|
||||
{
|
||||
function checkInitDataType(initDataType)
|
||||
{
|
||||
return isInitDataTypeSupported(initDataType).then(function(result) {
|
||||
// If |initDataType| is not supported, simply succeed.
|
||||
if (!result)
|
||||
return Promise.resolve('Not supported');
|
||||
|
||||
return navigator.requestMediaKeySystemAccess( config.keysystem, getSimpleConfigurationForInitDataType(initDataType))
|
||||
.then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
var mediaKeySession = mediaKeys.createSession();
|
||||
var initData = getInitData(initDataType);
|
||||
return mediaKeySession.generateRequest(initDataType, initData);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
return checkInitDataType('webm');
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ' support for "webm".');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
return checkInitDataType('cenc');
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ' support for "cenc".');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
return checkInitDataType('keyids');
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ' support for "keyids".');
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem ) + ', basic events';
|
||||
|
||||
var configuration = getSimpleConfigurationForContent( config.content );
|
||||
|
||||
if ( config.initDataType && config.initData ) configuration.initDataTypes = [ config.initDataType ]
|
||||
|
||||
async_test(function(test)
|
||||
{
|
||||
var initDataType;
|
||||
var initData;
|
||||
var mediaKeySession;
|
||||
|
||||
function processMessage(event)
|
||||
{
|
||||
assert_true(event instanceof window.MediaKeyMessageEvent);
|
||||
assert_equals(event.target, mediaKeySession);
|
||||
assert_equals(event.type, 'message');
|
||||
assert_any( assert_equals,
|
||||
event.messageType,
|
||||
[ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
waitForEventAndRunStep('keystatuseschange', mediaKeySession, test.step_func(processKeyStatusesChange), test);
|
||||
mediaKeySession.update( response ).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function processKeyStatusesChange(event)
|
||||
{
|
||||
assert_true(event instanceof Event);
|
||||
assert_equals(event.target, mediaKeySession);
|
||||
assert_equals(event.type, 'keystatuseschange');
|
||||
test.done();
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess( config.keysystem, [ configuration ] ).then(function(access) {
|
||||
initDataType = access.getConfiguration().initDataTypes[0];
|
||||
|
||||
if ( config.initDataType && config.initData ) {
|
||||
initData = config.initData;
|
||||
} else {
|
||||
initData = getInitData(config.content, initDataType);
|
||||
}
|
||||
|
||||
return access.createMediaKeys();
|
||||
}).then(test.step_func(function(mediaKeys) {
|
||||
mediaKeySession = mediaKeys.createSession();
|
||||
waitForEventAndRunStep('message', mediaKeySession, test.step_func(processMessage), test);
|
||||
return mediaKeySession.generateRequest(initDataType, initData);
|
||||
})).catch(test.step_func(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}));
|
||||
}, testname );
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
// Create a session and call generateRequest() temporary, |initDataType|
|
||||
// and |initData|. generateRequest() should fail temporary, an
|
||||
// InvalidAccessError. Returns a promise that resolves successfully
|
||||
// if the error happened, rejects otherwise.
|
||||
function test_session(keysystem,initDataType, initData)
|
||||
{
|
||||
return isInitDataTypeSupported(initDataType).then(function(result) {
|
||||
// If |initDataType| is not supported, simply succeed.
|
||||
if (!result)
|
||||
return Promise.resolve('Not supported');
|
||||
|
||||
return navigator.requestMediaKeySystemAccess( keysystem, getSimpleConfigurationForInitDataType(initDataType)).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
var mediaKeySession = mediaKeys.createSession();
|
||||
return mediaKeySession.generateRequest(initDataType, initData);
|
||||
}).then(function() {
|
||||
assert_unreached('generateRequest() succeeded');
|
||||
}, function(error) {
|
||||
assert_equals(error.name, 'InvalidAccessError');
|
||||
return Promise.resolve('success');
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
var initData = new Uint8Array(70000);
|
||||
return test_session(config.keysystem,'webm', initData);
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, webm, initData longer than 64Kb characters');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
var initData = new Uint8Array(70000);
|
||||
return test_session(config.keysystem,'cenc', initData);
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, cenc, initData longer than 64Kb characters');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
var initData = new Uint8Array(70000);
|
||||
return test_session(config.keysystem,'keyids', initData);
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, keyids, initData longer than 64Kb characters');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
// Invalid 'pssh' box as the size specified is larger than what
|
||||
// is provided.
|
||||
var initData = new Uint8Array([
|
||||
0x00, 0x00, 0xff, 0xff, // size = huge
|
||||
0x70, 0x73, 0x73, 0x68, // 'pssh'
|
||||
0x00, // version = 0
|
||||
0x00, 0x00, 0x00, // flags
|
||||
0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // Common SystemID
|
||||
0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
|
||||
0x00, 0x00, 0x00, 0x00 // datasize
|
||||
]);
|
||||
return test_session(config.keysystem,'cenc', initData);
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, cenc, invalid initdata (invalid pssh)');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
// Invalid data as type = 'psss'.
|
||||
var initData = new Uint8Array([
|
||||
0x00, 0x00, 0x00, 0x00, // size = 0
|
||||
0x70, 0x73, 0x73, 0x73, // 'psss'
|
||||
0x00, // version = 0
|
||||
0x00, 0x00, 0x00, // flags
|
||||
0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // Common SystemID
|
||||
0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
|
||||
0x00, 0x00, 0x00, 0x00 // datasize
|
||||
]);
|
||||
return test_session(config.keysystem,'cenc', initData);
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, cenc, invalid initdata (not pssh)');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
// Valid key ID size must be at least 1 character for keyids.
|
||||
var keyId = new Uint8Array(0);
|
||||
var initData = stringToUint8Array(createKeyIDs(keyId));
|
||||
return test_session(config.keysystem,'keyids', initData);
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, keyids, invalid initdata (too short key ID)');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
// Valid key ID size must be less than 512 characters for keyids.
|
||||
var keyId = new Uint8Array(600);
|
||||
var initData = stringToUint8Array(createKeyIDs(keyId));
|
||||
return test_session(config.keysystem,'keyids', initData);
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, keyids, invalid initdata (too long key ID)');
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
function runTest(config,qualifier)
|
||||
{
|
||||
var testname = testnamePrefix( qualifier, config.keysystem ) + ', temporary, keystatuses, multiple sessions';
|
||||
|
||||
var configuration = getSimpleConfigurationForContent( config.content );
|
||||
|
||||
if ( config.initDataType && config.initData ) configuration.initDataTypes = [ config.initDataType ];
|
||||
|
||||
async_test(function(test)
|
||||
{
|
||||
var mediaKeySession1;
|
||||
var mediaKeySession2;
|
||||
|
||||
// Even though key ids are uint8, using printable values so that
|
||||
// they can be verified easily.
|
||||
var key1 = new Uint8Array( config.content.keys[ 0 ].kid ),
|
||||
key2 = new Uint8Array( config.content.keys[ 1 ].kid );
|
||||
|
||||
function processMessage1(event)
|
||||
{
|
||||
// This should only be called for session1.
|
||||
assert_equals(event.target, mediaKeySession1);
|
||||
|
||||
// No keys added yet.
|
||||
verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [], unexpected: [key1, key2] });
|
||||
|
||||
// Add key1 to session1.
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
|
||||
event.target.update( response ).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function processKeyStatusesChange1(event)
|
||||
{
|
||||
// This should only be called for session1.
|
||||
assert_equals(event.target, mediaKeySession1);
|
||||
|
||||
// Check that keyStatuses contains the expected key1 only.
|
||||
verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [key1], unexpected: [key2] });
|
||||
|
||||
// Now trigger a message event on session2.
|
||||
mediaKeySession2.generateRequest(config.initDataType, config.initData[ 1 ]).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}
|
||||
|
||||
function processMessage2(event)
|
||||
{
|
||||
// This should only be called for session2.
|
||||
assert_equals(event.target, mediaKeySession2);
|
||||
|
||||
// session2 has no keys added yet.
|
||||
verifyKeyStatuses(mediaKeySession2.keyStatuses, { expected: [], unexpected: [key1, key2] });
|
||||
|
||||
// session1 should still have 1 key.
|
||||
verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [key1], unexpected: [key2] });
|
||||
|
||||
// Add key2 to session2.
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
|
||||
event.target.update( response ).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function processKeyStatusesChange2(event)
|
||||
{
|
||||
// This should only be called for session2.
|
||||
assert_equals(event.target, mediaKeySession2);
|
||||
|
||||
// Check that keyStatuses contains the expected key2 only.
|
||||
verifyKeyStatuses(mediaKeySession2.keyStatuses, { expected: [key2], unexpected: [key1] });
|
||||
|
||||
// session1 should still have 1 key.
|
||||
verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [key1], unexpected: [key2] });
|
||||
|
||||
test.done();
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess( config.keysystem, [ configuration ] ).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
mediaKeySession1 = mediaKeys.createSession();
|
||||
mediaKeySession2 = mediaKeys.createSession();
|
||||
|
||||
// There should be no keys defined on either session.
|
||||
verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [], unexpected: [key1, key2] });
|
||||
verifyKeyStatuses(mediaKeySession2.keyStatuses, { expected: [], unexpected: [key1, key2] });
|
||||
|
||||
// Bind all the event handlers now.
|
||||
waitForEventAndRunStep('message', mediaKeySession1, processMessage1, test);
|
||||
waitForEventAndRunStep('message', mediaKeySession2, processMessage2, test);
|
||||
waitForEventAndRunStep('keystatuseschange', mediaKeySession1, processKeyStatusesChange1, test);
|
||||
waitForEventAndRunStep('keystatuseschange', mediaKeySession2, processKeyStatusesChange2, test);
|
||||
|
||||
// Generate a request on session1.
|
||||
return mediaKeySession1.generateRequest(config.initDataType, config.initData[ 0 ] );
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}, testname );
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
function runTest(config,qualifier)
|
||||
{
|
||||
var testname = testnamePrefix( qualifier, config.keysystem ) + ', temporary, keystatuses';
|
||||
|
||||
var configuration = getSimpleConfigurationForContent( config.content );
|
||||
|
||||
if ( config.initDataType && config.initData ) configuration.initDataTypes = [ config.initDataType ];
|
||||
|
||||
async_test(function(test)
|
||||
{
|
||||
var mediaKeySession;
|
||||
var initDataType;
|
||||
var initData;
|
||||
var closed = false;
|
||||
|
||||
// Even though key ids are uint8, using printable values so that
|
||||
// they can be verified easily.
|
||||
var key1 = new Uint8Array( config.content.keys[ 0 ].kid ),
|
||||
key2 = new Uint8Array( config.content.keys[ 1 ].kid ),
|
||||
key1String = arrayBufferAsString(key1),
|
||||
key2String = arrayBufferAsString(key2);
|
||||
|
||||
function onFailure(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}
|
||||
|
||||
function processMessage(event)
|
||||
{
|
||||
// No keys added yet.
|
||||
assert_equals(mediaKeySession.keyStatuses.size, 0);
|
||||
|
||||
waitForEventAndRunStep('keystatuseschange', mediaKeySession, processKeyStatusesChange, test);
|
||||
|
||||
// Add keys to session
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
event.target.update( response ).catch(onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
function checkKeyStatusFor2Keys()
|
||||
{
|
||||
// Two keys added, so both should show up in |keyStatuses|.
|
||||
assert_equals(mediaKeySession.keyStatuses.size, 2);
|
||||
|
||||
// Check |keyStatuses| for 2 entries.
|
||||
var result = [];
|
||||
for (let item of mediaKeySession.keyStatuses) {
|
||||
result.push({ key: arrayBufferAsString(item[0]), value: item[1] });
|
||||
}
|
||||
function lexicographical( a, b ) { return a < b ? -1 : a === b ? 0 : +1; }
|
||||
function lexicographicalkey( a, b ) { return lexicographical( a.key, b.key ); }
|
||||
var expected = [{ key: key1String, value: 'usable'}, { key: key2String, value: 'usable'}].sort( lexicographicalkey );
|
||||
assert_equals(JSON.stringify(result),
|
||||
JSON.stringify(expected),
|
||||
"keystatuses should have the two expected keys with keystatus 'usable'");
|
||||
|
||||
// |keyStatuses| must contain both keys.
|
||||
result = [];
|
||||
for (var key of mediaKeySession.keyStatuses.keys()) {
|
||||
result.push(arrayBufferAsString(key));
|
||||
}
|
||||
assert_array_equals(result,
|
||||
[key1String, key2String].sort( lexicographical ),
|
||||
"keyStatuses.keys() should return an iterable over the two expected keys");
|
||||
|
||||
// Both values in |mediaKeySession| should be 'usable'.
|
||||
result = [];
|
||||
for (var value of mediaKeySession.keyStatuses.values()) {
|
||||
result.push(value);
|
||||
}
|
||||
assert_array_equals(result,
|
||||
['usable', 'usable'],
|
||||
"keyStatuses.values() should return an iterable with two 'usable' values");
|
||||
|
||||
// Check |keyStatuses.entries()|.
|
||||
result = [];
|
||||
for (var entry of mediaKeySession.keyStatuses.entries()) {
|
||||
result.push({ key: arrayBufferAsString(entry[0]), value: entry[1] });
|
||||
}
|
||||
assert_equals(JSON.stringify(result),
|
||||
JSON.stringify(expected),
|
||||
"keyStatuses.entries() should return an iterable over the two expected keys, with keystatus 'usable'");
|
||||
|
||||
// forEach() should return both entries.
|
||||
result = [];
|
||||
mediaKeySession.keyStatuses.forEach(function(status, keyId) {
|
||||
result.push({ key: arrayBufferAsString(keyId), value: status });
|
||||
});
|
||||
assert_equals(JSON.stringify(result),
|
||||
JSON.stringify(expected),
|
||||
"keyStatuses.forEach() should iterate over the two expected keys, with keystatus 'usable'");
|
||||
|
||||
// has() and get() should return the expected values.
|
||||
assert_true(mediaKeySession.keyStatuses.has(key1), "keyStatuses should have key1");
|
||||
assert_true(mediaKeySession.keyStatuses.has(key2), "keyStatuses should have key2");
|
||||
assert_equals(mediaKeySession.keyStatuses.get(key1), 'usable', "key1 should have status 'usable'");
|
||||
assert_equals(mediaKeySession.keyStatuses.get(key2), 'usable', "key2 should have status 'usable'");
|
||||
|
||||
// Try some invalid keyIds.
|
||||
var invalid1 = key1.subarray(0, key1.length - 1);
|
||||
assert_false(mediaKeySession.keyStatuses.has(invalid1), "keystatuses should not have invalid key (1)");
|
||||
assert_equals(mediaKeySession.keyStatuses.get(invalid1), undefined, "keystatus value for invalid key should be undefined (1)");
|
||||
|
||||
var invalid2 = key1.subarray(1);
|
||||
assert_false(mediaKeySession.keyStatuses.has(invalid2), "keystatuses should not have invalid key (2)");
|
||||
assert_equals(mediaKeySession.keyStatuses.get(invalid2), undefined, "keystatus value for invalid key should be undefined (2)");
|
||||
|
||||
var invalid3 = new Uint8Array(key1);
|
||||
invalid3[0] += 1;
|
||||
assert_false(mediaKeySession.keyStatuses.has(invalid3), "keystatuses should not have invalid key (3)");
|
||||
assert_equals(mediaKeySession.keyStatuses.get(invalid3), undefined, "keystatus value for invalid key should be undefined (3)");
|
||||
|
||||
var invalid4 = new Uint8Array(key1);
|
||||
invalid4[invalid4.length - 1] -= 1;
|
||||
assert_false(mediaKeySession.keyStatuses.has(invalid4), "keystatuses should not have invalid key (4)");
|
||||
assert_equals(mediaKeySession.keyStatuses.get(invalid4), undefined, "keystatus value for invalid key should be undefined (4)");
|
||||
|
||||
var invalid5 = new Uint8Array(key1.length + 1);
|
||||
invalid5.set(key1, 1); // First element will be 0.
|
||||
assert_false(mediaKeySession.keyStatuses.has(invalid5), "keystatuses should not have invalid key (5)");
|
||||
assert_equals(mediaKeySession.keyStatuses.get(invalid5), undefined, "keystatus value for invalid key should be undefined (5)");
|
||||
|
||||
var invalid6 = new Uint8Array(key1.length + 1);
|
||||
invalid6.set(key1, 0); // Last element will be 0.
|
||||
assert_false(mediaKeySession.keyStatuses.has(invalid6), "keystatuses should not have invalid key (6)");
|
||||
assert_equals(mediaKeySession.keyStatuses.get(invalid6), undefined, "keystatus value for invalid key should be undefined (6)");
|
||||
}
|
||||
|
||||
function processKeyStatusesChange(event)
|
||||
{
|
||||
if ( !closed )
|
||||
{
|
||||
// The first keystatuseschange (caused by update())
|
||||
// should include both keys.
|
||||
checkKeyStatusFor2Keys();
|
||||
|
||||
mediaKeySession.close().catch(onFailure);
|
||||
closed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The second keystatuseschange (caused by close())
|
||||
// should not have any keys.
|
||||
assert_equals(mediaKeySession.keyStatuses.size, 0);
|
||||
test.done();
|
||||
}
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess( config.keysystem, [ configuration ] ).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(test.step_func(function(mediaKeys) {
|
||||
mediaKeySession = mediaKeys.createSession();
|
||||
|
||||
// There should be no keys defined yet.
|
||||
//verifyKeyStatuses(mediaKeySession.keyStatuses, { expected: [], unexpected: [key1, key2] });
|
||||
|
||||
waitForEventAndRunStep('message', mediaKeySession, processMessage, test);
|
||||
return mediaKeySession.generateRequest(config.initDataType, config.initData);
|
||||
})).catch(onFailure);
|
||||
}, testname );
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
function runTest(config,qualifier) {
|
||||
// After creation, the MediaKeySession object is not
|
||||
// callable, and we should get a InvalidStateError.
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
return navigator.requestMediaKeySystemAccess(config.keysystem, getSimpleConfiguration()).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
var mediaKeySession = mediaKeys.createSession();
|
||||
|
||||
var arbitraryResponse = new Uint8Array([0x00, 0x11]);
|
||||
return mediaKeySession.update(arbitraryResponse).then(function(result) {
|
||||
assert_unreached('update() succeeded unexpectedly.');
|
||||
}).catch(function(error) {
|
||||
assert_equals(error.name, 'InvalidStateError');
|
||||
});
|
||||
});
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, update() immediately after createSession()');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
return navigator.requestMediaKeySystemAccess(config.keysystem, getSimpleConfiguration()).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
var mediaKeySession = mediaKeys.createSession();
|
||||
|
||||
return mediaKeySession.close().then(function(result) {
|
||||
assert_unreached('close() succeeded unexpectedly.');
|
||||
}).catch(function(error) {
|
||||
assert_equals(error.name, 'InvalidStateError');
|
||||
});
|
||||
});
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, close() immediately after createSession()');
|
||||
|
||||
promise_test(function()
|
||||
{
|
||||
return navigator.requestMediaKeySystemAccess(config.keysystem, getSimpleConfiguration()).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
var mediaKeySession = mediaKeys.createSession();
|
||||
|
||||
return mediaKeySession.remove().then(function(result) {
|
||||
assert_unreached('remove() succeeded unexpectedly.');
|
||||
}).catch(function(error) {
|
||||
assert_equals(error.name, 'InvalidStateError');
|
||||
});
|
||||
});
|
||||
}, testnamePrefix( qualifier, config.keysystem ) + ', temporary, remove() immediately after createSession()');
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', persistent-license, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback, destroy and acknowledge';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'persistent-license' ] };
|
||||
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource,
|
||||
_sessionId,
|
||||
_startedReleaseSequence = false;
|
||||
|
||||
function onFailure(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
config.messagehandler( event.messageType, event.message )
|
||||
.then( function( response ) {
|
||||
_mediaKeySession.update( response ).catch(onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
_mediaKeySession.generateRequest( config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData ).then( test.step_func(function() {
|
||||
assert_not_equals( _mediaKeySession.sessionId, undefined, "SessionId should be defined" );
|
||||
_sessionId = _mediaKeySession.sessionId;
|
||||
})).catch(onFailure);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 1 ) && !_startedReleaseSequence ) {
|
||||
_video.removeEventListener('timeupdate', onTimeupdate );
|
||||
_video.pause();
|
||||
_video.removeAttribute('src');
|
||||
_video.load();
|
||||
|
||||
_startedReleaseSequence = true;
|
||||
_mediaKeySession.closed.then(onClosed);
|
||||
_mediaKeySession.remove().catch(onFailure);
|
||||
}
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
function onClosed() {
|
||||
// Try and reload and check this fails
|
||||
var mediaKeySession = _mediaKeys.createSession( 'persistent-license' );
|
||||
mediaKeySession.load( _sessionId ).then( test.step_func(function( success ) {
|
||||
assert_false( success, "Load of removed session shouold fail" );
|
||||
test.done();
|
||||
})).catch(onFailure);
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
return _video.setMediaKeys(_mediaKeys);
|
||||
return;
|
||||
}).then(function() {
|
||||
_mediaKeySession = _mediaKeys.createSession( 'persistent-license' );
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(onFailure);
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', persistent-license, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback, check events';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'persistent-license' ] };
|
||||
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource,
|
||||
_receivedTimeupdateEvent = false,
|
||||
_startedReleaseSequence = false,
|
||||
_events = [ ];
|
||||
|
||||
function recordEventFunc( eventType ) {
|
||||
return function() { _events.push( eventType ); };
|
||||
}
|
||||
|
||||
function onFailure(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
if ( !_startedReleaseSequence ) {
|
||||
assert_in_array( event.messageType, [ 'license-request', 'individualization-request' ] );
|
||||
} else {
|
||||
assert_equals( event.messageType, 'license-release' );
|
||||
}
|
||||
|
||||
if ( event.messageType !== 'individualization-request' ) {
|
||||
_events.push( event.messageType );
|
||||
}
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
_events.push( event.messageType + '-response');
|
||||
_mediaKeySession.update( response ).then( test.step_func( function() {
|
||||
_events.push('updated');
|
||||
if ( event.messageType === 'license-release' ) {
|
||||
assert_array_equals( _events,
|
||||
[
|
||||
'generaterequest',
|
||||
'license-request',
|
||||
'license-request-response',
|
||||
'updated',
|
||||
'keystatuseschange',
|
||||
'playing',
|
||||
'remove',
|
||||
'keystatuseschange',
|
||||
'license-release',
|
||||
'license-release-response',
|
||||
'closed-promise',
|
||||
'updated'
|
||||
],
|
||||
"Expected events sequence" );
|
||||
test.done();
|
||||
}
|
||||
})).catch(onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
function onKeyStatusesChange(event) {
|
||||
assert_equals(event.target, _mediaKeySession );
|
||||
assert_true(event instanceof window.Event );
|
||||
assert_equals(event.type, 'keystatuseschange' );
|
||||
_events.push('keystatuseschange');
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
_mediaKeySession.generateRequest( config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData ).then( recordEventFunc( 'generaterequest' )
|
||||
).catch(onFailure);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 1 ) && !_receivedTimeupdateEvent ) {
|
||||
_receivedTimeupdateEvent = true;
|
||||
_video.pause();
|
||||
_video.removeAttribute('src');
|
||||
_video.load();
|
||||
|
||||
_startedReleaseSequence = true;
|
||||
_mediaKeySession.remove().then( recordEventFunc( 'remove' ) ).catch(onFailure);
|
||||
}
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
_events.push( 'playing' );
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
return _video.setMediaKeys(_mediaKeys);
|
||||
}).then(function() {
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
_mediaKeySession = _mediaKeys.createSession( 'persistent-license' );
|
||||
waitForEventAndRunStep('keystatuseschange', _mediaKeySession, onKeyStatusesChange, test);
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
_mediaKeySession.closed.then( recordEventFunc( 'closed-promise' ) );
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', persistent-license, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ 'playback';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'persistent-license' ] };
|
||||
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource;
|
||||
|
||||
function onFailure(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_in_array( event.messageType, [ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message )
|
||||
.then( function( response ) {
|
||||
_mediaKeySession.update( response )
|
||||
.catch(onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
_mediaKeySession.generateRequest( config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData ).catch(onFailure);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 1 ) ) {
|
||||
_video.pause();
|
||||
test.done();
|
||||
}
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
return _video.setMediaKeys(_mediaKeys);
|
||||
}).then(function() {
|
||||
_mediaKeySession = _mediaKeys.createSession( 'persistent-license' );
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(onFailure);
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', persistent-usage-record, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback, check events';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'persistent-usage-record' ] };
|
||||
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_sessionId,
|
||||
_timeupdateEvent = false,
|
||||
_events = [ ];
|
||||
|
||||
function recordEventFunc( eventType ) {
|
||||
return function() { _events.push( eventType ); };
|
||||
}
|
||||
|
||||
function onFailure(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
if ( event.messageType !== 'individualization-request' ) {
|
||||
_events.push( event.messageType );
|
||||
}
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
_events.push( event.messageType + '-response' );
|
||||
_mediaKeySession.update( response ).then( test.step_func(function() {
|
||||
_events.push( 'update-done' );
|
||||
if ( event.messageType === 'license-release' ) {
|
||||
consoleWrite( _events );
|
||||
assert_array_equals( _events,
|
||||
[ 'encrypted',
|
||||
'generaterequest-done',
|
||||
'license-request',
|
||||
'license-request-response',
|
||||
'update-done',
|
||||
'keystatuseschange',
|
||||
'playing',
|
||||
'remove-done',
|
||||
'keystatuseschange',
|
||||
'license-release',
|
||||
'license-release-response',
|
||||
'closed-promise',
|
||||
'update-done'
|
||||
],
|
||||
"Expected events sequence" );
|
||||
test.done();
|
||||
}
|
||||
|
||||
if ( event.messageType === 'license-request' ) {
|
||||
_video.setMediaKeys( _mediaKeys );
|
||||
}
|
||||
})).catch(onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
_events.push(event.type);
|
||||
_mediaKeySession.generateRequest( config.initDataType || event.initDataType,
|
||||
config.initData || event.initData ).then( function() {
|
||||
_events.push( 'generaterequest-done' );
|
||||
_sessionId = _mediaKeySession.sessionId;
|
||||
}).catch(onFailure);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 2 ) && !_timeupdateEvent ) {
|
||||
_timeupdateEvent = true;
|
||||
_video.pause();
|
||||
_mediaKeySession.remove().then( recordEventFunc('remove-done') ).catch(onFailure);
|
||||
}
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, recordEventFunc('playing'), test);
|
||||
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
|
||||
_mediaKeySession = _mediaKeys.createSession( 'persistent-usage-record' );
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
waitForEventAndRunStep('keystatuseschange', _mediaKeySession, recordEventFunc('keystatuseschange'), test);
|
||||
_mediaKeySession.closed.then( recordEventFunc('closed-promise') );
|
||||
}).then(function() {
|
||||
return config.servercertificate ? _mediaKeys.setServerCertificate( config.servercertificate ) : true;
|
||||
}).then(function( success ) {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_video.src = URL.createObjectURL(source);
|
||||
_video.play();
|
||||
}).catch(onFailure);
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', persistent-usage-record, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ 'playback';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'persistent-usage-record' ] };
|
||||
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource,
|
||||
_releaseSequence = false;
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
// event instance verification failing on CastTV
|
||||
// assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
if ( !_releaseSequence )
|
||||
{
|
||||
assert_in_array( event.messageType, [ 'license-request', 'individualization-request' ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
assert_equals( event.messageType, 'license-release' );
|
||||
}
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
_mediaKeySession.update( response ).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}).then(function() {
|
||||
if(event.messageType === 'license-request') {
|
||||
_video.setMediaKeys(_mediaKeys);
|
||||
} else if(event.messageType === 'license-release') {
|
||||
test.done();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
_mediaKeySession.generateRequest( config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData )
|
||||
.catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}
|
||||
|
||||
function onClosed(event) {
|
||||
_video.src = "";
|
||||
_video.setMediaKeys( null );
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 2 ) && !_releaseSequence ) {
|
||||
|
||||
_video.removeEventListener('timeupdate', onTimeupdate );
|
||||
|
||||
_video.pause();
|
||||
|
||||
_releaseSequence = true;
|
||||
|
||||
_mediaKeySession.closed.then( test.step_func( onClosed ) );
|
||||
_mediaKeySession.remove().catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
|
||||
_video.removeEventListener('timeupdate', onTimeupdate );
|
||||
}
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
_mediaKeySession = _mediaKeys.createSession( 'persistent-usage-record' );
|
||||
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
}).then(function() {
|
||||
return config.servercertificate ? _mediaKeys.setServerCertificate( config.servercertificate ) : true;
|
||||
}).then(function( success ) {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', persistent-license, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', ' + config.testcase;
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'persistent-license' ] };
|
||||
|
||||
|
||||
async_test( function( test ) {
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource,
|
||||
_sessionId;
|
||||
|
||||
function onFailure(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
_mediaKeySession.generateRequest( config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData ).then( function() {
|
||||
_sessionId = _mediaKeySession.sessionId;
|
||||
}).catch(onFailure);
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_in_array( event.messageType, [ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
_mediaKeySession.update( response )
|
||||
.catch(onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 1 ) ) {
|
||||
_video.removeEventListener('timeupdate', onTimeupdate );
|
||||
_video.pause();
|
||||
_video.removeAttribute('src');
|
||||
_video.load()
|
||||
|
||||
_mediaKeySession.closed.then( test.step_func( onClosed ) );
|
||||
_mediaKeySession.close();
|
||||
}
|
||||
}
|
||||
|
||||
function onClosed() {
|
||||
// Open a new window in which we will attempt to play with the persisted license
|
||||
var win = window.open( config.windowscript );
|
||||
|
||||
// Lisen for an event from the new window containing its test assertions
|
||||
window.addEventListener('message', test.step_func(function( messageEvent ) {
|
||||
messageEvent.data.forEach(test.step_func(function( assertion ) {
|
||||
assert_equals(assertion.actual, assertion.expected, assertion.message);
|
||||
}));
|
||||
|
||||
win.close();
|
||||
test.done();
|
||||
}));
|
||||
|
||||
// Delete things which can't be cloned and posted over to the new window
|
||||
delete config.video;
|
||||
delete config.messagehandler;
|
||||
|
||||
// Post the config and session id to the new window when it is ready
|
||||
win.onload = function() {
|
||||
win.postMessage( { config: config, sessionId: _sessionId }, '*' );
|
||||
}
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
_video.setMediaKeys( mediaKeys );
|
||||
_mediaKeySession = _mediaKeys.createSession( 'persistent-license' );
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(onFailure);
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', persistent-usage-record, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback, retrieve in new window';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'persistent-usage-record' ] };
|
||||
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource,
|
||||
_sessionId,
|
||||
_isClosing = false;
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
_mediaKeySession.generateRequest( config.initDataType || event.initDataType,
|
||||
config.initData || event.initData ).then( function() {
|
||||
|
||||
_sessionId = _mediaKeySession.sessionId;
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_in_array( event.messageType, [ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
|
||||
_mediaKeySession.update( response ).then(function() {
|
||||
_video.setMediaKeys(_mediaKeys);
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( !_isClosing && _video.currentTime > ( config.duration || 2 ) ) {
|
||||
_isClosing = true;
|
||||
_video.removeEventListener('timeupdate', onTimeupdate );
|
||||
_video.pause();
|
||||
_mediaKeySession.closed.then( test.step_func( onClosed ) );
|
||||
_mediaKeySession.close();
|
||||
}
|
||||
}
|
||||
|
||||
function onClosed(event) {
|
||||
_video.src = "";
|
||||
_video.setMediaKeys( null );
|
||||
|
||||
var win = window.open( config.windowscript );
|
||||
window.addEventListener('message', test.step_func(function( event ) {
|
||||
|
||||
event.data.forEach(test.step_func(function( assertion ) {
|
||||
|
||||
assert_equals(assertion.actual, assertion.expected, assertion.message);
|
||||
|
||||
}));
|
||||
|
||||
win.close();
|
||||
|
||||
test.done();
|
||||
}));
|
||||
|
||||
delete config.video;
|
||||
delete config.messagehandler;
|
||||
|
||||
win.onload = function() {
|
||||
|
||||
win.postMessage( { config: config, sessionId: _sessionId }, '*' );
|
||||
}
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
|
||||
_video.setMediaKeys( mediaKeys );
|
||||
|
||||
_mediaKeySession = _mediaKeys.createSession( 'persistent-usage-record' );
|
||||
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
}).then(function() {
|
||||
return config.servercertificate ? _mediaKeys.setServerCertificate( config.servercertificate ) : true;
|
||||
}).then(function( success ) {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', temporary, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback, check events';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'temporary' ] };
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource,
|
||||
_allKeysUsableEvent = false,
|
||||
_playingEvent = false,
|
||||
_timeupdateEvent = false,
|
||||
_events = [ ];
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_any( assert_equals,
|
||||
event.messageType,
|
||||
[ 'license-request', 'individualization-request' ] );
|
||||
|
||||
if ( event.messageType !== 'individualization-request' ) {
|
||||
_events.push( event.messageType );
|
||||
}
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
_events.push( 'license-response' );
|
||||
|
||||
waitForEventAndRunStep('keystatuseschange', _mediaKeySession, onKeyStatusesChange, test);
|
||||
_mediaKeySession.update( response ).then( function() {
|
||||
_events.push('updated');
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onKeyStatusesChange(event) {
|
||||
assert_equals(event.target, _mediaKeySession );
|
||||
assert_true(event instanceof window.Event );
|
||||
assert_equals(event.type, 'keystatuseschange' );
|
||||
|
||||
var hasKeys = false, pendingKeys = false;
|
||||
_mediaKeySession.keyStatuses.forEach( function( value, keyid ) {
|
||||
assert_any( assert_equals, value, [ 'status-pending', 'usable' ] );
|
||||
|
||||
hasKeys = true;
|
||||
pendingKeys = pendingKeys || ( value === 'status-pending' );
|
||||
|
||||
});
|
||||
|
||||
if ( !_allKeysUsableEvent && hasKeys && !pendingKeys ) {
|
||||
_allKeysUsableEvent = true;
|
||||
_events.push( 'allkeysusable' );
|
||||
_video.setMediaKeys(_mediaKeys);
|
||||
}
|
||||
|
||||
if ( !hasKeys ) {
|
||||
_events.push( 'emptykeyslist' );
|
||||
}
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
_mediaKeySession.generateRequest( config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData ).then( function() {
|
||||
_events.push( 'generaterequest' );
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}
|
||||
|
||||
function onClosed(event) {
|
||||
|
||||
_events.push( 'closed-promise' );
|
||||
|
||||
setTimeout( test.step_func( function() {
|
||||
|
||||
assert_array_equals( _events,
|
||||
[
|
||||
'generaterequest',
|
||||
'license-request',
|
||||
'license-response',
|
||||
'updated',
|
||||
'allkeysusable',
|
||||
'playing',
|
||||
'closed',
|
||||
'closed-promise',
|
||||
'emptykeyslist'
|
||||
],
|
||||
"Expected events sequence" );
|
||||
|
||||
_video.src = "";
|
||||
_video.setMediaKeys( null ).then(function(){
|
||||
test.done();
|
||||
});
|
||||
} ), 0 );
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 2 ) && !_timeupdateEvent ) {
|
||||
_timeupdateEvent = true;
|
||||
_video.pause();
|
||||
|
||||
_mediaKeySession.closed.then( test.step_func( onClosed ) );
|
||||
_mediaKeySession.close().then( function() {
|
||||
_events.push( 'closed' );
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
_playingEvent = true;
|
||||
_events.push( 'playing' );
|
||||
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
_mediaKeySession = _mediaKeys.createSession( 'temporary' );
|
||||
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', temporary, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback with multiple keys and sessions, '
|
||||
+ config.testcase;
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'temporary' ] };
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySessions = [ ],
|
||||
_mediaSource;
|
||||
|
||||
function onMessage(event) {
|
||||
assert_any( assert_equals, event.target, _mediaKeySessions );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_any( assert_equals,
|
||||
event.messageType,
|
||||
[ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message )
|
||||
.then( function( response ) {
|
||||
|
||||
event.target.update( response )
|
||||
.catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 2 ) ) {
|
||||
|
||||
consoleWrite("Session 0:");
|
||||
dumpKeyStatuses( _mediaKeySessions[ 0 ].keyStatuses );
|
||||
consoleWrite("Session 1:");
|
||||
dumpKeyStatuses( _mediaKeySessions[ 1 ].keyStatuses );
|
||||
|
||||
_video.removeEventListener('timeupdate', onTimeupdate);
|
||||
_video.pause();
|
||||
test.done();
|
||||
}
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
|
||||
_video.setMediaKeys(_mediaKeys);
|
||||
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
|
||||
config.initData.forEach( function( initData ) {
|
||||
|
||||
var mediaKeySession = _mediaKeys.createSession( 'temporary' );
|
||||
|
||||
waitForEventAndRunStep('message', mediaKeySession, onMessage, test);
|
||||
|
||||
_mediaKeySessions.push( mediaKeySession );
|
||||
|
||||
mediaKeySession.generateRequest( config.initDataType, initData )
|
||||
.catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
|
||||
} );
|
||||
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', temporary, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback with multiple keys, single session, '
|
||||
+ config.testcase;
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'temporary' ] };
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySessions = [ ],
|
||||
_mediaSource;
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
// Only create a session for the first encrypted event
|
||||
if ( _mediaKeySessions.length > 0 ) return;
|
||||
|
||||
var mediaKeySession = _mediaKeys.createSession( 'temporary' );
|
||||
|
||||
waitForEventAndRunStep('message', mediaKeySession, onMessage, test);
|
||||
|
||||
var initDataType, initData;
|
||||
if ( config.initDataType && config.initData )
|
||||
{
|
||||
initDataType = config.initDataType;
|
||||
initData = config.initData;
|
||||
}
|
||||
else
|
||||
{
|
||||
initDataType = event.initDataType;
|
||||
initData = event.initData;
|
||||
}
|
||||
|
||||
_mediaKeySessions.push( mediaKeySession );
|
||||
|
||||
mediaKeySession.generateRequest( initDataType, initData )
|
||||
.catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
assert_any( assert_equals, event.target, _mediaKeySessions );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_any( assert_equals,
|
||||
event.messageType,
|
||||
[ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message )
|
||||
.then( function( response ) {
|
||||
|
||||
event.target.update( response )
|
||||
.catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 2 ) ) {
|
||||
|
||||
consoleWrite("Session 0:");
|
||||
dumpKeyStatuses( _mediaKeySessions[ 0 ].keyStatuses );
|
||||
|
||||
_video.removeEventListener('timeupdate', onTimeupdate);
|
||||
_video.pause();
|
||||
test.done();
|
||||
}
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
|
||||
_video.setMediaKeys(_mediaKeys);
|
||||
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
SETMEDIAKEYS_IMMEDIATELY = 0;
|
||||
SETMEDIAKEYS_AFTER_SRC = 1;
|
||||
SETMEDIAKEYS_ONENCRYPTED = 2;
|
||||
SETMEDIAKEYS_AFTER_UPDATE = 3;
|
||||
|
||||
function runTest(config,qualifier) {
|
||||
|
||||
var testcase = ( config.testcase === SETMEDIAKEYS_IMMEDIATELY ) ? 'setMediaKeys first'
|
||||
: ( config.testcase === SETMEDIAKEYS_AFTER_SRC ) ? 'setMediaKeys after setting video.src'
|
||||
: ( config.testcase === SETMEDIAKEYS_ONENCRYPTED ) ? 'setMediaKeys in encrypted event'
|
||||
: ( config.testcase === SETMEDIAKEYS_AFTER_UPDATE ) ? 'setMediaKeys after updating session'
|
||||
: 'unknown';
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', temporary, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback, ' + testcase;
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'temporary' ] };
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource;
|
||||
|
||||
function onFailure(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_any( assert_equals,
|
||||
event.messageType,
|
||||
[ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
return _mediaKeySession.update( response );
|
||||
}).then( function() {
|
||||
if ( config.testcase === SETMEDIAKEYS_AFTER_UPDATE ) {
|
||||
return _video.setMediaKeys( _mediaKeys );
|
||||
}
|
||||
}).catch(onFailure);
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
var promise = ( config.testcase === SETMEDIAKEYS_ONENCRYPTED )
|
||||
? _video.setMediaKeys( _mediaKeys )
|
||||
: Promise.resolve();
|
||||
|
||||
promise.then( function() {
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
return _mediaKeySession.generateRequest(config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData );
|
||||
}).catch(onFailure);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 2 ) ) {
|
||||
_video.pause();
|
||||
test.done();
|
||||
}
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(test.step_func(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
if ( config.testcase === SETMEDIAKEYS_IMMEDIATELY ) {
|
||||
return _video.setMediaKeys( _mediaKeys );
|
||||
}
|
||||
})).then(function(){
|
||||
_mediaKeySession = _mediaKeys.createSession( 'temporary' );
|
||||
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
|
||||
return testmediasource(config);
|
||||
}).then(test.step_func(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
|
||||
if ( config.testcase === SETMEDIAKEYS_AFTER_SRC ) {
|
||||
return _video.setMediaKeys( _mediaKeys );
|
||||
}
|
||||
})).catch(onFailure);
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', temporary, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback two videos';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'temporary' ] };
|
||||
|
||||
promise_test(function(test)
|
||||
{
|
||||
var promises = config.video.map( function( video ) { return play_video_as_promise( test, video ); } );
|
||||
|
||||
return Promise.all(promises);
|
||||
|
||||
}, testname );
|
||||
|
||||
function play_video_as_promise( test, _video ) {
|
||||
var _mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource;
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_any( assert_equals,
|
||||
event.messageType,
|
||||
[ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
|
||||
_mediaKeySession.update( response ).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
|
||||
_mediaKeySession.generateRequest( config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData )
|
||||
.catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
|
||||
_video.setMediaKeys(_mediaKeys);
|
||||
}
|
||||
|
||||
function wait_for_timeupdate_message(video)
|
||||
{
|
||||
return new Promise(function(resolve) {
|
||||
video.addEventListener('timeupdate', function listener(event) {
|
||||
if ( event.target.currentTime > ( config.duration || 2 ) )
|
||||
{
|
||||
video.removeEventListener('timeupdate', listener);
|
||||
resolve(event);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
_mediaKeySession = _mediaKeys.createSession( 'temporary' );
|
||||
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
return wait_for_timeupdate_message(_video);
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
// config.initData contains a list of keys. We expect those to be needed in order and get
|
||||
// one waitingforkey event for each one.
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', successful playback, temporary, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', waitingforkey event, '
|
||||
+ config.initData.length + ' key' + ( config.initData.length > 1 ? 's' : '' );
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'temporary' ] };
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySessions = [ ],
|
||||
_mediaSource;
|
||||
|
||||
function onFailure( error ) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
}
|
||||
|
||||
function onMessage(event) {
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
event.target.update( response ).catch(onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
function onWaitingForKey(event) {
|
||||
// Expect one waitingforkey event for each initData we were given
|
||||
assert_less_than( _mediaKeySessions.length, config.initData.length );
|
||||
var mediaKeySession = _mediaKeys.createSession( 'temporary' );
|
||||
waitForEventAndRunStep('message', mediaKeySession, onMessage, test);
|
||||
_mediaKeySessions.push( mediaKeySession );
|
||||
mediaKeySession.generateRequest( config.initDataType, config.initData[ _mediaKeySessions.length - 1 ] ).catch(onFailure);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 2 ) ) {
|
||||
assert_equals( _mediaKeySessions.length, config.initData.length );
|
||||
_video.removeEventListener('timeupdate', onTimeupdate);
|
||||
_video.pause();
|
||||
test.done();
|
||||
}
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
return _video.setMediaKeys(_mediaKeys);
|
||||
}).then(function(){
|
||||
waitForEventAndRunStep('waitingforkey', _video, onWaitingForKey, test);
|
||||
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(onFailure);
|
||||
}, testname);
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
function runTest(config,qualifier) {
|
||||
|
||||
var testname = testnamePrefix( qualifier, config.keysystem )
|
||||
+ ', temporary, '
|
||||
+ /video\/([^;]*)/.exec( config.videoType )[ 1 ]
|
||||
+ ', playback';
|
||||
|
||||
var configuration = { initDataTypes: [ config.initDataType ],
|
||||
audioCapabilities: [ { contentType: config.audioType } ],
|
||||
videoCapabilities: [ { contentType: config.videoType } ],
|
||||
sessionTypes: [ 'temporary' ] };
|
||||
|
||||
async_test( function( test ) {
|
||||
|
||||
var _video = config.video,
|
||||
_mediaKeys,
|
||||
_mediaKeySession,
|
||||
_mediaSource;
|
||||
|
||||
function onMessage(event) {
|
||||
assert_equals( event.target, _mediaKeySession );
|
||||
assert_true( event instanceof window.MediaKeyMessageEvent );
|
||||
assert_equals( event.type, 'message');
|
||||
|
||||
assert_any( assert_equals,
|
||||
event.messageType,
|
||||
[ 'license-request', 'individualization-request' ] );
|
||||
|
||||
config.messagehandler( event.messageType, event.message ).then( function( response ) {
|
||||
|
||||
_mediaKeySession.update( response ).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onEncrypted(event) {
|
||||
assert_equals(event.target, _video);
|
||||
assert_true(event instanceof window.MediaEncryptedEvent);
|
||||
assert_equals(event.type, 'encrypted');
|
||||
|
||||
waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
|
||||
_mediaKeySession.generateRequest( config.initData ? config.initDataType : event.initDataType,
|
||||
config.initData || event.initData )
|
||||
.catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
|
||||
_video.setMediaKeys(_mediaKeys);
|
||||
}
|
||||
|
||||
function onTimeupdate(event) {
|
||||
if ( _video.currentTime > ( config.duration || 2 ) ) {
|
||||
_video.pause();
|
||||
test.done();
|
||||
}
|
||||
}
|
||||
|
||||
function onPlaying(event) {
|
||||
// Not using waitForEventAndRunStep() to avoid too many
|
||||
// EVENT(onTimeUpdate) logs.
|
||||
_video.addEventListener('timeupdate', onTimeupdate, true);
|
||||
}
|
||||
|
||||
navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
|
||||
return access.createMediaKeys();
|
||||
}).then(function(mediaKeys) {
|
||||
_mediaKeys = mediaKeys;
|
||||
_mediaKeySession = _mediaKeys.createSession( 'temporary' );
|
||||
|
||||
waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
|
||||
waitForEventAndRunStep('playing', _video, onPlaying, test);
|
||||
}).then(function() {
|
||||
return testmediasource(config);
|
||||
}).then(function(source) {
|
||||
_mediaSource = source;
|
||||
_video.src = URL.createObjectURL(_mediaSource);
|
||||
_video.play();
|
||||
}).catch(function(error) {
|
||||
forceTestFailureFromPromise(test, error);
|
||||
});
|
||||
}, testname);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue