Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eme] Keystatuses test #3490

Merged
merged 7 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions encrypted-media/clearkey-keystatuses.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Encrypted Media Extensions: Verify MediaKeySession.keyStatuses with multiple sessions, Clear Key</title>
<link rel="help" href="https://w3c.github.io/encrypted-media/">

<!-- Web Platform Test Harness scripts -->
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>

<!-- Helper scripts for Encrypted Media Extensions tests -->
<script src=/encrypted-media/util/utils.js></script>
<script src=/encrypted-media/util/fetch.js></script>
<script src=/encrypted-media/util/testmediasource.js></script>
<script src=/encrypted-media/util/utf8.js></script>

<!-- Content metadata -->
<script src=/encrypted-media/content/content-metadata.js></script>

<!-- Message handler for Clear Key keysystem -->
<script src=/encrypted-media/util/clearkey-messagehandler.js></script>

<!-- The script for this specific test -->
<script src=/encrypted-media/scripts/keystatuses.js></script>

</head>
<body>
<div id='log'></div>

<script>
getSupportedContent( 'org.w3.clearkey' )
.then( function( contents ) {

// Select a content item with multiple keys
var contentitem = contents.filter( function( item ) { return item.keys.length > 1; } )[ 0 ];
var handler = new MessageHandler( 'org.w3.clearkey', contentitem );
var config = { keysystem: 'org.w3.clearkey',
content: contentitem,
messagehandler: handler.messagehandler,
initDataType: 'keyids',
initData: getInitData(contentitem,'keyids'),
};

runTest(config);

} );
</script>
</body>
</html>
1 change: 0 additions & 1 deletion encrypted-media/drm-keystatuses-multiple-sessions.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

// Select a content item with multiple keys and initData
var contentitem = contents.filter( function( item ) { return item.keys.length > 1 && item.initDataType && !item.associatedInitData; } )[ 0 ],

handler = new MessageHandler( keysystem, contentitem ),
config = { keysystem: keysystem,
content: contentitem,
Expand Down
54 changes: 54 additions & 0 deletions encrypted-media/drm-keystatuses.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Encrypted Media Extensions: Verify MediaKeySession.keyStatuses with multiple sessions, DRM</title>
<link rel="help" href="https://w3c.github.io/encrypted-media/">

<!-- Web Platform Test Harness scripts -->
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>

<!-- Helper scripts for Encrypted Media Extensions tests -->
<script src=/encrypted-media/util/utils.js></script>
<script src=/encrypted-media/util/fetch.js></script>
<script src=/encrypted-media/util/testmediasource.js></script>
<script src=/encrypted-media/util/utf8.js></script>

<!-- Content metadata -->
<script src=/encrypted-media/content/content-metadata.js></script>

<!-- Message handler for DRM -->
<script src=/encrypted-media/util/drm-messagehandler.js></script>

<!-- The script for this specific test -->
<script src=/encrypted-media/scripts/keystatuses.js></script>

</head>
<body>
<div id='log'></div>

<script>
var keysystem = getSupportedKeySystem();
getSupportedContent( keysystem ).then( function( contents ) {

// Select a content item with multiple keys and initData that retrieves all keys
var contentitem = contents.filter( function( item ) {
return item.keys.length > 1 && item.initDataType && item.associatedInitData;
} )[ 0 ];

var handler = new MessageHandler( keysystem, contentitem );
var config = { keysystem: keysystem,
content: contentitem,
messagehandler: handler.messagehandler,
initDataType: contentitem.initDataType,
initData: base64DecodeToUnit8Array( getProprietaryInitDatas(contentitem).initDatas[ 0 ] ),
};

runTest(config);

} );
</script>
</body>
</html>
161 changes: 161 additions & 0 deletions encrypted-media/scripts/keystatuses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
function runTest(config)
{
var testname = config.keysystem + ', 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 );
}
9 changes: 4 additions & 5 deletions encrypted-media/util/drm-messagehandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,25 @@ drmconfig = {
"userId" : "12345",
"merchant" : "cablelabs"
},

/*
"com.microsoft.playready": {
"serverURL": "http://playready-testserver.azurewebsites.net/rightsmanager.asmx",
"servertype": "microsoft",
"certificate" : "Q0hBSQAAAAEAAAUEAAAAAAAAAAJDRVJUAAAAAQAAAfQAAAFkAAEAAQAAAFjt9G6KdSncCkrjbTQPN+/2AAAAAAAAAAAAAAAJIPbrW9dj0qydQFIomYFHOwbhGZVGP2ZsPwcvjh+NFkP/////AAAAAAAAAAAAAAAAAAAAAAABAAoAAABYxw6TjIuUUmvdCcl00t4RBAAAADpodHRwOi8vcGxheXJlYWR5LmRpcmVjdHRhcHMubmV0L3ByL3N2Yy9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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgDEuMC4wLjEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEACAAAAJAAAQBArAKJsEIDWNG5ulOgLvSUb8I2zZ0c5lZGYvpIO56Z0UNk/uC4Mq3jwXQUUN6m/48V5J/vuLDhWu740aRQc1dDDAAAAgCGTWHP8iVuQixWizwoABz7PhUnZYWEugUht5sYKNk23h2Cao/D5uf6epDVyilG8fZKLvufXc/+fkNOtEKT+sWr"
},
/*

"com.microsoft.playready": {
"serverURL": "http://playready.directtaps.net/pr/svc/rightsmanager.asmx",
"servertype": "microsoft",
"certificate" : "Q0hBSQAAAAEAAAUEAAAAAAAAAAJDRVJUAAAAAQAAAfQAAAFkAAEAAQAAAFjt9G6KdSncCkrjbTQPN+/2AAAAAAAAAAAAAAAJIPbrW9dj0qydQFIomYFHOwbhGZVGP2ZsPwcvjh+NFkP/////AAAAAAAAAAAAAAAAAAAAAAABAAoAAABYxw6TjIuUUmvdCcl00t4RBAAAADpodHRwOi8vcGxheXJlYWR5LmRpcmVjdHRhcHMubmV0L3ByL3N2Yy9yaWdodHNtYW5hZ2VyLmFzbXgAAAAAAQAFAAAADAAAAAAAAQAGAAAAXAAAAAEAAQIAAAAAADBRmRRpqV4cfRLcWz9WoXIGZ5qzD9xxJe0CSI2mXJQdPHEFZltrTkZtdmurwVaEI2etJY0OesCeOCzCqmEtTkcAAAABAAAAAgAAAAcAAAA8AAAAAAAAAAVEVEFQAAAAAAAAABVNZXRlcmluZyBDZXJ0aWZpY2F0ZQAAAAAAAAABAAAAAAABAAgAAACQAAEAQGHic/IPbmLCKXxc/MH20X/RtjhXH4jfowBWsQE1QWgUUBPFId7HH65YuQJ5fxbQJCT6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VuQixWizwoABz7PhUnZYWEugUht5sYKNk23h2Cao/D5uf6epDVyilG8fZKLvufXc/+fkNOtEKT+sWr"
},

*/
"com.microsoft.playready": {
"serverURL": "https://lic.staging.drmtoday.com/license-proxy-headerauth/drmtoday/RightsManager.asmx",
"servertype" : "drmtoday",
"userId" : "12345",
"merchant" : "cablelabs"
}
*/

};

function MessageHandler( keysystem, content, sessionType ) {
Expand Down Expand Up @@ -88,6 +86,7 @@ MessageHandler.prototype.messagehandler = function messagehandler( messageType,
var dataview = new Uint16Array(message);

msg = String.fromCharCode.apply(null, dataview);

xmlDoc = parser.parseFromString(msg, 'application/xml');

if (xmlDoc.getElementsByTagName('Challenge')[0]) {
Expand Down
10 changes: 5 additions & 5 deletions encrypted-media/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ function verifyKeyStatuses(keyStatuses, keys)
var unexpected = keys.unexpected || [];

// |keyStatuses| should have same size as number of |keys.expected|.
assert_equals(keyStatuses.size, expected.length);
assert_equals(keyStatuses.size, expected.length, "keystatuses should have expected size");

// All |keys.expected| should be found.
expected.map(function(key) {
assert_true(keyStatuses.has(key));
assert_equals(keyStatuses.get(key), 'usable');
assert_true(keyStatuses.has(key), "keystatuses should have the expected keys");
assert_equals(keyStatuses.get(key), 'usable', "keystatus value should be 'usable'");
});

// All |keys.unexpected| should not be found.
unexpected.map(function(key) {
assert_false(keyStatuses.has(key));
assert_equals(keyStatuses.get(key), undefined);
assert_false(keyStatuses.has(key), "keystatuses should not have unexpected keys");
assert_equals(keyStatuses.get(key), undefined, "keystatus for unexpected key should be undefined");
});
}

Expand Down