mirror of
https://github.com/servo/servo.git
synced 2025-08-20 04:45:33 +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,44 @@
|
|||
// Expect utf8decoder and utf8decoder to be TextEncoder('utf-8') and TextDecoder('utf-8') respectively
|
||||
|
||||
function MessageHandler( keysystem, content ) {
|
||||
this._keysystem = keysystem;
|
||||
this._content = content;
|
||||
this.messagehandler = MessageHandler.prototype.messagehandler.bind( this );
|
||||
this.servercertificate = undefined;
|
||||
}
|
||||
|
||||
MessageHandler.prototype.messagehandler = function messagehandler( messageType, message )
|
||||
{
|
||||
if ( messageType === 'license-request' )
|
||||
{
|
||||
var request = fromUtf8( message );
|
||||
|
||||
var keys = request.kids.map( function( kid ) {
|
||||
|
||||
var key;
|
||||
for( var i=0; i < this._content.keys.length; ++i )
|
||||
{
|
||||
if ( base64urlEncode( this._content.keys[ i ].kid ) === kid )
|
||||
{
|
||||
key = base64urlEncode( this._content.keys[ i ].key );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return { kty: 'oct', kid: kid, k: key };
|
||||
|
||||
}.bind( this ) );
|
||||
|
||||
return Promise.resolve( toUtf8( { keys: keys } ) );
|
||||
}
|
||||
else if ( messageType === 'license-release' )
|
||||
{
|
||||
var release = fromUtf8( message );
|
||||
|
||||
// TODO: Check the license release message here
|
||||
|
||||
return Promise.resolve( toUtf8( { kids: release.kids } ) );
|
||||
}
|
||||
|
||||
throw new TypeError( 'Unsupported message type for ClearKey' );
|
||||
};
|
|
@ -0,0 +1,245 @@
|
|||
// Expect utf8decoder and utf8decoder to be TextEncoder('utf-8') and TextDecoder('utf-8') respectively
|
||||
//
|
||||
// drmconfig format:
|
||||
// { <keysystem> : { "serverURL" : <the url for the server>,
|
||||
// "httpRequestHeaders" : <map of HTTP request headers>,
|
||||
// "servertype" : "microsoft" | "drmtoday", // affects how request parameters are formed
|
||||
// "certificate" : <base64 encoded server certificate> } }
|
||||
//
|
||||
|
||||
drmconfig = {
|
||||
"com.widevine.alpha": [ {
|
||||
"serverURL": "https://lic.staging.drmtoday.com/license-proxy-widevine/cenc/",
|
||||
"servertype" : "drmtoday",
|
||||
"userId" : "12345",
|
||||
"merchant" : "cablelabs",
|
||||
} ],
|
||||
"com.microsoft.playready": [ {
|
||||
"serverURL": "http://playready-testserver.azurewebsites.net/rightsmanager.asmx",
|
||||
"servertype": "microsoft",
|
||||
"sessionTypes" : [ "persistent-usage-record" ],
|
||||
"certificate" : "Q0hBSQAAAAEAAAUEAAAAAAAAAAJDRVJUAAAAAQAAAfQAAAFkAAEAAQAAAFjt9G6KdSncCkrjbTQPN+/2AAAAAAAAAAAAAAAJIPbrW9dj0qydQFIomYFHOwbhGZVGP2ZsPwcvjh+NFkP/////AAAAAAAAAAAAAAAAAAAAAAABAAoAAABYxw6TjIuUUmvdCcl00t4RBAAAADpodHRwOi8vcGxheXJlYWR5LmRpcmVjdHRhcHMubmV0L3ByL3N2Yy9yaWdodHNtYW5hZ2VyLmFzbXgAAAAAAQAFAAAADAAAAAAAAQAGAAAAXAAAAAEAAQIAAAAAADBRmRRpqV4cfRLcWz9WoXIGZ5qzD9xxJe0CSI2mXJQdPHEFZltrTkZtdmurwVaEI2etJY0OesCeOCzCqmEtTkcAAAABAAAAAgAAAAcAAAA8AAAAAAAAAAVEVEFQAAAAAAAAABVNZXRlcmluZyBDZXJ0aWZpY2F0ZQAAAAAAAAABAAAAAAABAAgAAACQAAEAQGHic/IPbmLCKXxc/MH20X/RtjhXH4jfowBWsQE1QWgUUBPFId7HH65YuQJ5fxbQJCT6Hw0iHqKzaTkefrhIpOoAAAIAW+uRUsdaChtq/AMUI4qPlK2Bi4bwOyjJcSQWz16LAFfwibn5yHVDEgNA4cQ9lt3kS4drx7pCC+FR/YLlHBAV7ENFUlQAAAABAAAC/AAAAmwAAQABAAAAWMk5Z0ovo2X0b2C9K5PbFX8AAAAAAAAAAAAAAARTYd1EkpFovPAZUjOj2doDLnHiRSfYc89Fs7gosBfar/////8AAAAAAAAAAAAAAAAAAAAAAAEABQAAAAwAAAAAAAEABgAAAGAAAAABAAECAAAAAABb65FSx1oKG2r8AxQjio+UrYGLhvA7KMlxJBbPXosAV/CJufnIdUMSA0DhxD2W3eRLh2vHukIL4VH9guUcEBXsAAAAAgAAAAEAAAAMAAAABwAAAZgAAAAAAAAAgE1pY3Jvc29mdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgFBsYXlSZWFkeSBTTDAgTWV0ZXJpbmcgUm9vdCBDQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgDEuMC4wLjEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEACAAAAJAAAQBArAKJsEIDWNG5ulOgLvSUb8I2zZ0c5lZGYvpIO56Z0UNk/uC4Mq3jwXQUUN6m/48V5J/vuLDhWu740aRQc1dDDAAAAgCGTWHP8iVuQixWizwoABz7PhUnZYWEugUht5sYKNk23h2Cao/D5uf6epDVyilG8fZKLvufXc/+fkNOtEKT+sWr"
|
||||
},
|
||||
{
|
||||
"serverURL": "http://playready.directtaps.net/pr/svc/rightsmanager.asmx",
|
||||
"servertype": "microsoft",
|
||||
"sessionTypes" : [ "persistent-usage-record" ],
|
||||
"certificate" : "Q0hBSQAAAAEAAAUEAAAAAAAAAAJDRVJUAAAAAQAAAfQAAAFkAAEAAQAAAFjt9G6KdSncCkrjbTQPN+/2AAAAAAAAAAAAAAAJIPbrW9dj0qydQFIomYFHOwbhGZVGP2ZsPwcvjh+NFkP/////AAAAAAAAAAAAAAAAAAAAAAABAAoAAABYxw6TjIuUUmvdCcl00t4RBAAAADpodHRwOi8vcGxheXJlYWR5LmRpcmVjdHRhcHMubmV0L3ByL3N2Yy9yaWdodHNtYW5hZ2VyLmFzbXgAAAAAAQAFAAAADAAAAAAAAQAGAAAAXAAAAAEAAQIAAAAAADBRmRRpqV4cfRLcWz9WoXIGZ5qzD9xxJe0CSI2mXJQdPHEFZltrTkZtdmurwVaEI2etJY0OesCeOCzCqmEtTkcAAAABAAAAAgAAAAcAAAA8AAAAAAAAAAVEVEFQAAAAAAAAABVNZXRlcmluZyBDZXJ0aWZpY2F0ZQAAAAAAAAABAAAAAAABAAgAAACQAAEAQGHic/IPbmLCKXxc/MH20X/RtjhXH4jfowBWsQE1QWgUUBPFId7HH65YuQJ5fxbQJCT6Hw0iHqKzaTkefrhIpOoAAAIAW+uRUsdaChtq/AMUI4qPlK2Bi4bwOyjJcSQWz16LAFfwibn5yHVDEgNA4cQ9lt3kS4drx7pCC+FR/YLlHBAV7ENFUlQAAAABAAAC/AAAAmwAAQABAAAAWMk5Z0ovo2X0b2C9K5PbFX8AAAAAAAAAAAAAAARTYd1EkpFovPAZUjOj2doDLnHiRSfYc89Fs7gosBfar/////8AAAAAAAAAAAAAAAAAAAAAAAEABQAAAAwAAAAAAAEABgAAAGAAAAABAAECAAAAAABb65FSx1oKG2r8AxQjio+UrYGLhvA7KMlxJBbPXosAV/CJufnIdUMSA0DhxD2W3eRLh2vHukIL4VH9guUcEBXsAAAAAgAAAAEAAAAMAAAABwAAAZgAAAAAAAAAgE1pY3Jvc29mdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgFBsYXlSZWFkeSBTTDAgTWV0ZXJpbmcgUm9vdCBDQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgDEuMC4wLjEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEACAAAAJAAAQBArAKJsEIDWNG5ulOgLvSUb8I2zZ0c5lZGYvpIO56Z0UNk/uC4Mq3jwXQUUN6m/48V5J/vuLDhWu740aRQc1dDDAAAAgCGTWHP8iVuQixWizwoABz7PhUnZYWEugUht5sYKNk23h2Cao/D5uf6epDVyilG8fZKLvufXc/+fkNOtEKT+sWr"
|
||||
},
|
||||
{
|
||||
"serverURL": "https://lic.staging.drmtoday.com/license-proxy-headerauth/drmtoday/RightsManager.asmx",
|
||||
"servertype" : "drmtoday",
|
||||
"sessionTypes" : [ "temporary", "persistent-usage-record", "persistent-license" ],
|
||||
"userId" : "12345",
|
||||
"merchant" : "cablelabs"
|
||||
} ]
|
||||
};
|
||||
|
||||
function MessageHandler( keysystem, content, sessionType ) {
|
||||
sessionType = sessionType || "temporary";
|
||||
|
||||
this._keysystem = keysystem;
|
||||
this._content = content;
|
||||
this._sessionType = sessionType;
|
||||
this._drmconfig = drmconfig[ this._keysystem ].filter( function( drmconfig ) {
|
||||
return drmconfig.sessionTypes === undefined || ( drmconfig.sessionTypes.indexOf( sessionType ) !== -1 );
|
||||
} )[ 0 ];
|
||||
|
||||
this.messagehandler = MessageHandler.prototype.messagehandler.bind( this );
|
||||
if ( this._drmconfig && this._drmconfig.certificate ) {
|
||||
this.servercertificate = stringToUint8Array( atob( this._drmconfig.certificate ) );
|
||||
}
|
||||
}
|
||||
|
||||
MessageHandler.prototype.messagehandler = function messagehandler( messageType, message) {
|
||||
|
||||
// For the DRM Today server, mapping between Key System messages and server protocol messages depends on
|
||||
// the Key System, so we provide key-system-specific functions here to perform the mapping.
|
||||
//
|
||||
// For the Microsoft server, the mapping for PlayReady is the same as for the DRM Today server
|
||||
//
|
||||
const keySystems = {
|
||||
'com.widevine.alpha': {
|
||||
responseType: 'json',
|
||||
getLicenseMessage: function(response) {
|
||||
return base64DecodeToUnit8Array( response.license );
|
||||
},
|
||||
getErrorResponse: function(response) {
|
||||
return response;
|
||||
},
|
||||
getLicenseRequestFromMessage: function(message) {
|
||||
return new Uint8Array(message);
|
||||
},
|
||||
getRequestHeadersFromMessage: function(/*message*/) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
'com.microsoft.playready': {
|
||||
responseType: 'arraybuffer',
|
||||
getLicenseMessage: function(response) {
|
||||
return response;
|
||||
},
|
||||
getErrorResponse: function(response) {
|
||||
return String.fromCharCode.apply(null, new Uint16Array(response));
|
||||
},
|
||||
getLicenseRequestFromMessage: function(message) {
|
||||
var msg,
|
||||
xmlDoc;
|
||||
var licenseRequest = null;
|
||||
var parser = new DOMParser();
|
||||
var dataview = new Uint16Array(message);
|
||||
|
||||
msg = String.fromCharCode.apply(null, dataview);
|
||||
|
||||
xmlDoc = parser.parseFromString(msg, 'application/xml');
|
||||
|
||||
if (xmlDoc.getElementsByTagName('Challenge')[0]) {
|
||||
var Challenge = xmlDoc.getElementsByTagName('Challenge')[0].childNodes[0].nodeValue;
|
||||
if (Challenge) {
|
||||
licenseRequest = atob(Challenge);
|
||||
}
|
||||
}
|
||||
return licenseRequest;
|
||||
},
|
||||
getRequestHeadersFromMessage: function(message) {
|
||||
var msg,
|
||||
xmlDoc;
|
||||
var headers = {};
|
||||
var parser = new DOMParser();
|
||||
var dataview = new Uint16Array(message);
|
||||
|
||||
msg = String.fromCharCode.apply(null, dataview);
|
||||
xmlDoc = parser.parseFromString(msg, 'application/xml');
|
||||
|
||||
var headerNameList = xmlDoc.getElementsByTagName('name');
|
||||
var headerValueList = xmlDoc.getElementsByTagName('value');
|
||||
for (var i = 0; i < headerNameList.length; i++) {
|
||||
headers[headerNameList[i].childNodes[0].nodeValue] = headerValueList[i].childNodes[0].nodeValue;
|
||||
}
|
||||
// some versions of the PlayReady CDM return 'Content' instead of 'Content-Type',
|
||||
// but the license server expects 'Content-Type', so we fix it up here.
|
||||
if (headers.hasOwnProperty('Content')) {
|
||||
headers['Content-Type'] = headers.Content;
|
||||
delete headers.Content;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// License request parameters are communicated to the DRM Today and Microsoft servers in different ways,
|
||||
// using a custom HTTP headers (DRM Today) and URL parameters (Microsoft).
|
||||
const serverTypes = {
|
||||
'drmtoday': {
|
||||
constructLicenseRequestUrl : function( serverURL, sessionType, messageType, content ) {
|
||||
return serverURL;
|
||||
},
|
||||
getCustomHeaders : function( drmconfig, sessionType, messageType ) {
|
||||
|
||||
var customToken;
|
||||
if ( messageType === 'license-request' ) {
|
||||
var customToken = { outputProtection: { digital : false, analogue: false, enforce: false },
|
||||
profile: { purchase: { } },
|
||||
storeLicense: ( sessionType === 'persistent-license' ) };
|
||||
} else {
|
||||
customToken = {};
|
||||
}
|
||||
|
||||
var customHeader = { userId: drmconfig.userId,
|
||||
merchant: drmconfig.merchant,
|
||||
sessionId: btoa( JSON.stringify( customToken )) };
|
||||
return { "dt-custom-data" : btoa( JSON.stringify( customHeader ) ) };
|
||||
}
|
||||
},
|
||||
'microsoft': {
|
||||
constructLicenseRequestUrl : function( serverURL, sessionType, messageType, content ) {
|
||||
if ( messageType !== 'license-request' ) {
|
||||
return serverURL;
|
||||
}
|
||||
|
||||
var url = serverURL + "?";
|
||||
if ( sessionType === 'temporary' || sessionType === 'persistent-usage-record' ) {
|
||||
url += "UseSimpleNonPersistentLicense=1&";
|
||||
}
|
||||
if ( sessionType === 'persistent-usage-record' ) {
|
||||
url += "SecureStop=1&";
|
||||
}
|
||||
url += "PlayEnablers=B621D91F-EDCC-4035-8D4B-DC71760D43E9&"; // disable output protection
|
||||
url += "ContentKey=" + btoa(String.fromCharCode.apply(null, content.keys[0].key));
|
||||
return url;
|
||||
},
|
||||
getCustomHeaders : function() { return {}; }
|
||||
}
|
||||
};
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
var keysystemfns = keySystems[this._keysystem],
|
||||
serverfns,
|
||||
url = undefined,
|
||||
requestheaders = {},
|
||||
credentials = undefined;
|
||||
|
||||
if ( !this._drmconfig || !keysystemfns || !this._drmconfig.servertype || !serverTypes[this._drmconfig.servertype] ) {
|
||||
reject('Unsupported Key System');
|
||||
return;
|
||||
}
|
||||
|
||||
serverfns = serverTypes[this._drmconfig.servertype];
|
||||
|
||||
if ( !this._drmconfig.serverURL ) {
|
||||
reject('Undefined serverURL');
|
||||
return;
|
||||
}
|
||||
|
||||
url = serverfns.constructLicenseRequestUrl( this._drmconfig.serverURL, this._sessionType, messageType, this._content );
|
||||
|
||||
// Ensure valid license server URL
|
||||
if (!url) {
|
||||
reject('No license server URL specified!');
|
||||
return;
|
||||
}
|
||||
|
||||
// Set optional XMLHttpRequest headers from protection data and message
|
||||
var updateHeaders = function(headers) {
|
||||
var key;
|
||||
if (headers) {
|
||||
for (key in headers) {
|
||||
if ('authorization' === key.toLowerCase()) {
|
||||
credentials = 'include';
|
||||
}
|
||||
requestheaders[key] = headers[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
updateHeaders(serverfns.getCustomHeaders( this._drmconfig, this._sessionType, messageType ) );
|
||||
updateHeaders(keysystemfns.getRequestHeadersFromMessage(message));
|
||||
|
||||
// Set withCredentials property from server
|
||||
if ( this._drmconfig.withCredentials ) {
|
||||
credentials = 'include';
|
||||
}
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: requestheaders,
|
||||
credentials: credentials,
|
||||
body: keysystemfns.getLicenseRequestFromMessage(message)
|
||||
}).then(function(fetchresponse) {
|
||||
if(fetchresponse.status !== 200) {
|
||||
reject( this._keysystem + ' update, XHR status is "' + fetchresponse.statusText
|
||||
+ '" (' + fetchresponse.status + '), expected to be 200. readyState is ' + fetchresponse.readyState + '.'
|
||||
+ ' Response is ' + ((fetchresponse) ? keysystemfns.getErrorResponse(fetchresponse) : 'NONE' ));
|
||||
return;
|
||||
}
|
||||
|
||||
if(keysystemfns.responseType === 'json') {
|
||||
return fetchresponse.json();
|
||||
} else if(keysystemfns.responseType === 'arraybuffer') {
|
||||
return fetchresponse.arrayBuffer();
|
||||
}
|
||||
}.bind( this )).then(function(response){
|
||||
resolve(keysystemfns.getLicenseMessage(response));
|
||||
}).catch(reject);
|
||||
}.bind( this ));
|
||||
};
|
456
tests/wpt/web-platform-tests/encrypted-media/util/fetch.js
Normal file
456
tests/wpt/web-platform-tests/encrypted-media/util/fetch.js
Normal file
|
@ -0,0 +1,456 @@
|
|||
// https://github.com/github/fetch
|
||||
//
|
||||
// Copyright (c) 2014-2016 GitHub, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
(function(self) {
|
||||
'use strict';
|
||||
|
||||
if (self.fetch) {
|
||||
return
|
||||
}
|
||||
|
||||
var support = {
|
||||
searchParams: 'URLSearchParams' in self,
|
||||
iterable: 'Symbol' in self && 'iterator' in Symbol,
|
||||
blob: 'FileReader' in self && 'Blob' in self && (function() {
|
||||
try {
|
||||
new Blob()
|
||||
return true
|
||||
} catch(e) {
|
||||
return false
|
||||
}
|
||||
})(),
|
||||
formData: 'FormData' in self,
|
||||
arrayBuffer: 'ArrayBuffer' in self
|
||||
}
|
||||
|
||||
function normalizeName(name) {
|
||||
if (typeof name !== 'string') {
|
||||
name = String(name)
|
||||
}
|
||||
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
|
||||
throw new TypeError('Invalid character in header field name')
|
||||
}
|
||||
return name.toLowerCase()
|
||||
}
|
||||
|
||||
function normalizeValue(value) {
|
||||
if (typeof value !== 'string') {
|
||||
value = String(value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// Build a destructive iterator for the value list
|
||||
function iteratorFor(items) {
|
||||
var iterator = {
|
||||
next: function() {
|
||||
var value = items.shift()
|
||||
return {done: value === undefined, value: value}
|
||||
}
|
||||
}
|
||||
|
||||
if (support.iterable) {
|
||||
iterator[Symbol.iterator] = function() {
|
||||
return iterator
|
||||
}
|
||||
}
|
||||
|
||||
return iterator
|
||||
}
|
||||
|
||||
function Headers(headers) {
|
||||
this.map = {}
|
||||
|
||||
if (headers instanceof Headers) {
|
||||
headers.forEach(function(value, name) {
|
||||
this.append(name, value)
|
||||
}, this)
|
||||
|
||||
} else if (headers) {
|
||||
Object.getOwnPropertyNames(headers).forEach(function(name) {
|
||||
this.append(name, headers[name])
|
||||
}, this)
|
||||
}
|
||||
}
|
||||
|
||||
Headers.prototype.append = function(name, value) {
|
||||
name = normalizeName(name)
|
||||
value = normalizeValue(value)
|
||||
var list = this.map[name]
|
||||
if (!list) {
|
||||
list = []
|
||||
this.map[name] = list
|
||||
}
|
||||
list.push(value)
|
||||
}
|
||||
|
||||
Headers.prototype['delete'] = function(name) {
|
||||
delete this.map[normalizeName(name)]
|
||||
}
|
||||
|
||||
Headers.prototype.get = function(name) {
|
||||
var values = this.map[normalizeName(name)]
|
||||
return values ? values[0] : null
|
||||
}
|
||||
|
||||
Headers.prototype.getAll = function(name) {
|
||||
return this.map[normalizeName(name)] || []
|
||||
}
|
||||
|
||||
Headers.prototype.has = function(name) {
|
||||
return this.map.hasOwnProperty(normalizeName(name))
|
||||
}
|
||||
|
||||
Headers.prototype.set = function(name, value) {
|
||||
this.map[normalizeName(name)] = [normalizeValue(value)]
|
||||
}
|
||||
|
||||
Headers.prototype.forEach = function(callback, thisArg) {
|
||||
Object.getOwnPropertyNames(this.map).forEach(function(name) {
|
||||
this.map[name].forEach(function(value) {
|
||||
callback.call(thisArg, value, name, this)
|
||||
}, this)
|
||||
}, this)
|
||||
}
|
||||
|
||||
Headers.prototype.keys = function() {
|
||||
var items = []
|
||||
this.forEach(function(value, name) { items.push(name) })
|
||||
return iteratorFor(items)
|
||||
}
|
||||
|
||||
Headers.prototype.values = function() {
|
||||
var items = []
|
||||
this.forEach(function(value) { items.push(value) })
|
||||
return iteratorFor(items)
|
||||
}
|
||||
|
||||
Headers.prototype.entries = function() {
|
||||
var items = []
|
||||
this.forEach(function(value, name) { items.push([name, value]) })
|
||||
return iteratorFor(items)
|
||||
}
|
||||
|
||||
if (support.iterable) {
|
||||
Headers.prototype[Symbol.iterator] = Headers.prototype.entries
|
||||
}
|
||||
|
||||
function consumed(body) {
|
||||
if (body.bodyUsed) {
|
||||
return Promise.reject(new TypeError('Already read'))
|
||||
}
|
||||
body.bodyUsed = true
|
||||
}
|
||||
|
||||
function fileReaderReady(reader) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
reader.onload = function() {
|
||||
resolve(reader.result)
|
||||
}
|
||||
reader.onerror = function() {
|
||||
reject(reader.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function readBlobAsArrayBuffer(blob) {
|
||||
var reader = new FileReader()
|
||||
reader.readAsArrayBuffer(blob)
|
||||
return fileReaderReady(reader)
|
||||
}
|
||||
|
||||
function readBlobAsText(blob) {
|
||||
var reader = new FileReader()
|
||||
reader.readAsText(blob)
|
||||
return fileReaderReady(reader)
|
||||
}
|
||||
|
||||
function Body() {
|
||||
this.bodyUsed = false
|
||||
|
||||
this._initBody = function(body) {
|
||||
this._bodyInit = body
|
||||
if (typeof body === 'string') {
|
||||
this._bodyText = body
|
||||
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
|
||||
this._bodyBlob = body
|
||||
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
|
||||
this._bodyFormData = body
|
||||
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
||||
this._bodyText = body.toString()
|
||||
} else if (!body) {
|
||||
this._bodyText = ''
|
||||
} else if (support.arrayBuffer && ArrayBuffer.prototype.isPrototypeOf(body)) {
|
||||
// Only support ArrayBuffers for POST method.
|
||||
// Receiving ArrayBuffers happens via Blobs, instead.
|
||||
} else {
|
||||
throw new Error('unsupported BodyInit type')
|
||||
}
|
||||
|
||||
if (!this.headers.get('content-type')) {
|
||||
if (typeof body === 'string') {
|
||||
this.headers.set('content-type', 'text/plain;charset=UTF-8')
|
||||
} else if (this._bodyBlob && this._bodyBlob.type) {
|
||||
this.headers.set('content-type', this._bodyBlob.type)
|
||||
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
||||
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (support.blob) {
|
||||
this.blob = function() {
|
||||
var rejected = consumed(this)
|
||||
if (rejected) {
|
||||
return rejected
|
||||
}
|
||||
|
||||
if (this._bodyBlob) {
|
||||
return Promise.resolve(this._bodyBlob)
|
||||
} else if (this._bodyFormData) {
|
||||
throw new Error('could not read FormData body as blob')
|
||||
} else {
|
||||
return Promise.resolve(new Blob([this._bodyText]))
|
||||
}
|
||||
}
|
||||
|
||||
this.arrayBuffer = function() {
|
||||
return this.blob().then(readBlobAsArrayBuffer)
|
||||
}
|
||||
|
||||
this.text = function() {
|
||||
var rejected = consumed(this)
|
||||
if (rejected) {
|
||||
return rejected
|
||||
}
|
||||
|
||||
if (this._bodyBlob) {
|
||||
return readBlobAsText(this._bodyBlob)
|
||||
} else if (this._bodyFormData) {
|
||||
throw new Error('could not read FormData body as text')
|
||||
} else {
|
||||
return Promise.resolve(this._bodyText)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.text = function() {
|
||||
var rejected = consumed(this)
|
||||
return rejected ? rejected : Promise.resolve(this._bodyText)
|
||||
}
|
||||
}
|
||||
|
||||
if (support.formData) {
|
||||
this.formData = function() {
|
||||
return this.text().then(decode)
|
||||
}
|
||||
}
|
||||
|
||||
this.json = function() {
|
||||
return this.text().then(JSON.parse)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
// HTTP methods whose capitalization should be normalized
|
||||
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']
|
||||
|
||||
function normalizeMethod(method) {
|
||||
var upcased = method.toUpperCase()
|
||||
return (methods.indexOf(upcased) > -1) ? upcased : method
|
||||
}
|
||||
|
||||
function Request(input, options) {
|
||||
options = options || {}
|
||||
var body = options.body
|
||||
if (Request.prototype.isPrototypeOf(input)) {
|
||||
if (input.bodyUsed) {
|
||||
throw new TypeError('Already read')
|
||||
}
|
||||
this.url = input.url
|
||||
this.credentials = input.credentials
|
||||
if (!options.headers) {
|
||||
this.headers = new Headers(input.headers)
|
||||
}
|
||||
this.method = input.method
|
||||
this.mode = input.mode
|
||||
if (!body) {
|
||||
body = input._bodyInit
|
||||
input.bodyUsed = true
|
||||
}
|
||||
} else {
|
||||
this.url = input
|
||||
}
|
||||
|
||||
this.credentials = options.credentials || this.credentials || 'omit'
|
||||
if (options.headers || !this.headers) {
|
||||
this.headers = new Headers(options.headers)
|
||||
}
|
||||
this.method = normalizeMethod(options.method || this.method || 'GET')
|
||||
this.mode = options.mode || this.mode || null
|
||||
this.referrer = null
|
||||
|
||||
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
|
||||
throw new TypeError('Body not allowed for GET or HEAD requests')
|
||||
}
|
||||
this._initBody(body)
|
||||
}
|
||||
|
||||
Request.prototype.clone = function() {
|
||||
return new Request(this)
|
||||
}
|
||||
|
||||
function decode(body) {
|
||||
var form = new FormData()
|
||||
body.trim().split('&').forEach(function(bytes) {
|
||||
if (bytes) {
|
||||
var split = bytes.split('=')
|
||||
var name = split.shift().replace(/\+/g, ' ')
|
||||
var value = split.join('=').replace(/\+/g, ' ')
|
||||
form.append(decodeURIComponent(name), decodeURIComponent(value))
|
||||
}
|
||||
})
|
||||
return form
|
||||
}
|
||||
|
||||
function headers(xhr) {
|
||||
var head = new Headers()
|
||||
var pairs = (xhr.getAllResponseHeaders() || '').trim().split('\n')
|
||||
pairs.forEach(function(header) {
|
||||
var split = header.trim().split(':')
|
||||
var key = split.shift().trim()
|
||||
var value = split.join(':').trim()
|
||||
head.append(key, value)
|
||||
})
|
||||
return head
|
||||
}
|
||||
|
||||
Body.call(Request.prototype)
|
||||
|
||||
function Response(bodyInit, options) {
|
||||
if (!options) {
|
||||
options = {}
|
||||
}
|
||||
|
||||
this.type = 'default'
|
||||
this.status = options.status
|
||||
this.ok = this.status >= 200 && this.status < 300
|
||||
this.statusText = options.statusText
|
||||
this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers)
|
||||
this.url = options.url || ''
|
||||
this._initBody(bodyInit)
|
||||
}
|
||||
|
||||
Body.call(Response.prototype)
|
||||
|
||||
Response.prototype.clone = function() {
|
||||
return new Response(this._bodyInit, {
|
||||
status: this.status,
|
||||
statusText: this.statusText,
|
||||
headers: new Headers(this.headers),
|
||||
url: this.url
|
||||
})
|
||||
}
|
||||
|
||||
Response.error = function() {
|
||||
var response = new Response(null, {status: 0, statusText: ''})
|
||||
response.type = 'error'
|
||||
return response
|
||||
}
|
||||
|
||||
var redirectStatuses = [301, 302, 303, 307, 308]
|
||||
|
||||
Response.redirect = function(url, status) {
|
||||
if (redirectStatuses.indexOf(status) === -1) {
|
||||
throw new RangeError('Invalid status code')
|
||||
}
|
||||
|
||||
return new Response(null, {status: status, headers: {location: url}})
|
||||
}
|
||||
|
||||
self.Headers = Headers
|
||||
self.Request = Request
|
||||
self.Response = Response
|
||||
|
||||
self.fetch = function(input, init) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var request
|
||||
if (Request.prototype.isPrototypeOf(input) && !init) {
|
||||
request = input
|
||||
} else {
|
||||
request = new Request(input, init)
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest()
|
||||
|
||||
function responseURL() {
|
||||
if ('responseURL' in xhr) {
|
||||
return xhr.responseURL
|
||||
}
|
||||
|
||||
// Avoid security warnings on getResponseHeader when not allowed by CORS
|
||||
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
|
||||
return xhr.getResponseHeader('X-Request-URL')
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
xhr.onload = function() {
|
||||
var options = {
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText,
|
||||
headers: headers(xhr),
|
||||
url: responseURL()
|
||||
}
|
||||
var body = 'response' in xhr ? xhr.response : xhr.responseText
|
||||
resolve(new Response(body, options))
|
||||
}
|
||||
|
||||
xhr.onerror = function() {
|
||||
reject(new TypeError('Network request failed'))
|
||||
}
|
||||
|
||||
xhr.ontimeout = function() {
|
||||
reject(new TypeError('Network request failed'))
|
||||
}
|
||||
|
||||
xhr.open(request.method, request.url, true)
|
||||
|
||||
if (request.credentials === 'include') {
|
||||
xhr.withCredentials = true
|
||||
}
|
||||
|
||||
if ('responseType' in xhr && support.blob) {
|
||||
xhr.responseType = 'blob'
|
||||
}
|
||||
|
||||
request.headers.forEach(function(value, name) {
|
||||
xhr.setRequestHeader(name, value)
|
||||
})
|
||||
|
||||
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)
|
||||
})
|
||||
}
|
||||
self.fetch.polyfill = true
|
||||
})(typeof self !== 'undefined' ? self : this);
|
|
@ -0,0 +1,43 @@
|
|||
function testmediasource(config) {
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
// Fetch the media resources
|
||||
var fetches = [config.audioPath, config.videoPath].map(function(path) {
|
||||
return fetch(path).then(function(response) {
|
||||
if (!response.ok) throw new Error('Resource fetch failed');
|
||||
return response.arrayBuffer();
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all(fetches).then(function(resources) {
|
||||
config.audioMedia = resources[0];
|
||||
config.videoMedia = resources[1];
|
||||
|
||||
// Create media source
|
||||
var source = new MediaSource();
|
||||
|
||||
// Create and fill source buffers when the media source is opened
|
||||
source.addEventListener('sourceopen', onSourceOpen);
|
||||
|
||||
function onSourceOpen(event) {
|
||||
var audioSourceBuffer = source.addSourceBuffer(config.audioType),
|
||||
videoSourceBuffer = source.addSourceBuffer(config.videoType);
|
||||
|
||||
audioSourceBuffer.appendBuffer(config.audioMedia);
|
||||
videoSourceBuffer.appendBuffer(config.videoMedia);
|
||||
|
||||
function endOfStream() {
|
||||
if (audioSourceBuffer.updating || videoSourceBuffer.updating) {
|
||||
setTimeout(endOfStream, 250);
|
||||
} else {
|
||||
source.endOfStream();
|
||||
}
|
||||
}
|
||||
|
||||
endOfStream();
|
||||
}
|
||||
|
||||
resolve(source);
|
||||
});
|
||||
});
|
||||
}
|
22
tests/wpt/web-platform-tests/encrypted-media/util/utf8.js
Normal file
22
tests/wpt/web-platform-tests/encrypted-media/util/utf8.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
if ( typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined" )
|
||||
{
|
||||
utf8encoder = new TextEncoder('utf-8');
|
||||
utf8decoder = new TextDecoder('utf-8');
|
||||
}
|
||||
else
|
||||
{
|
||||
utf8encoder = { encode: function( text )
|
||||
{
|
||||
var result = new Uint8Array(text.length);
|
||||
for(var i = 0; i < text.length; i++) { result[i] = text.charCodeAt(i); }
|
||||
return result;
|
||||
} };
|
||||
|
||||
utf8decoder = { decode: function( buffer )
|
||||
{
|
||||
return String.fromCharCode.apply(null, new Uint8Array(buffer));
|
||||
} };
|
||||
}
|
||||
|
||||
toUtf8 = function( o ) { return utf8encoder.encode( JSON.stringify( o ) ); }
|
||||
fromUtf8 = function( t ) { return JSON.parse( utf8decoder.decode( t ) ); }
|
228
tests/wpt/web-platform-tests/encrypted-media/util/utils.js
Normal file
228
tests/wpt/web-platform-tests/encrypted-media/util/utils.js
Normal file
|
@ -0,0 +1,228 @@
|
|||
function testnamePrefix( qualifier, keysystem ) {
|
||||
return ( qualifier || '' ) + ( keysystem === 'org.w3.clearkey' ? keysystem : 'drm' );
|
||||
}
|
||||
|
||||
function getInitData(initDataType) {
|
||||
|
||||
// FIXME: This is messed up, because here we are hard coding the key ids for the different content
|
||||
// that we use for clearkey testing: webm and mp4. For keyids we return the mp4 one
|
||||
//
|
||||
// The content used with the DRM today servers has a different key id altogether
|
||||
|
||||
if (initDataType == 'webm') {
|
||||
return new Uint8Array([
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
|
||||
]);
|
||||
}
|
||||
|
||||
if (initDataType == 'cenc') {
|
||||
return new Uint8Array([
|
||||
0x00, 0x00, 0x00, 0x34, // size
|
||||
0x70, 0x73, 0x73, 0x68, // 'pssh'
|
||||
0x01, // version = 1
|
||||
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, 0x01, // key count
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0xd2, 0xfc, 0x41, // key id
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 // datasize
|
||||
]);
|
||||
}
|
||||
if (initDataType == 'keyids') {
|
||||
var keyId = new Uint8Array([
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0xd2, 0xfc, 0x41,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
]);
|
||||
return stringToUint8Array(createKeyIDs(keyId));
|
||||
}
|
||||
throw 'initDataType ' + initDataType + ' not supported.';
|
||||
}
|
||||
|
||||
function stringToUint8Array(str)
|
||||
{
|
||||
var result = new Uint8Array(str.length);
|
||||
for(var i = 0; i < str.length; i++) {
|
||||
result[i] = str.charCodeAt(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Encodes |data| into base64url string. There is no '=' padding, and the
|
||||
// characters '-' and '_' must be used instead of '+' and '/', respectively.
|
||||
function base64urlEncode(data) {
|
||||
var result = btoa(String.fromCharCode.apply(null, data));
|
||||
return result.replace(/=+$/g, '').replace(/\+/g, "-").replace(/\//g, "_");
|
||||
}
|
||||
// Decode |encoded| using base64url decoding.
|
||||
function base64urlDecode(encoded) {
|
||||
return atob(encoded.replace(/\-/g, "+").replace(/\_/g, "/"));
|
||||
}
|
||||
// Decode |encoded| using base64 to a Uint8Array
|
||||
function base64DecodeToUnit8Array(encoded) {
|
||||
return new Uint8Array( atob( encoded ).split('').map( function(c){return c.charCodeAt(0);} ) );
|
||||
}
|
||||
// Clear Key can also support Key IDs Initialization Data.
|
||||
// ref: http://w3c.github.io/encrypted-media/keyids-format.html
|
||||
// Each parameter is expected to be a key id in an Uint8Array.
|
||||
function createKeyIDs() {
|
||||
var keyIds = '{"kids":["';
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
if (i != 0) keyIds += '","';
|
||||
keyIds += base64urlEncode(arguments[i]);
|
||||
}
|
||||
keyIds += '"]}';
|
||||
return keyIds;
|
||||
}
|
||||
|
||||
function getSupportedKeySystem() {
|
||||
var userAgent = navigator.userAgent.toLowerCase();
|
||||
var keysystem = undefined;
|
||||
if (userAgent.indexOf('edge') > -1 ) {
|
||||
keysystem = 'com.microsoft.playready';
|
||||
} else if ( userAgent.indexOf('chrome') > -1 || userAgent.indexOf('firefox') > -1 ) {
|
||||
keysystem = 'com.widevine.alpha';
|
||||
}
|
||||
return keysystem;
|
||||
}
|
||||
|
||||
function waitForEventAndRunStep(eventName, element, func, stepTest)
|
||||
{
|
||||
var eventCallback = function(event) {
|
||||
if (func)
|
||||
func(event);
|
||||
}
|
||||
|
||||
element.addEventListener(eventName, stepTest.step_func(eventCallback), true);
|
||||
}
|
||||
|
||||
var consoleDiv = null;
|
||||
|
||||
function consoleWrite(text)
|
||||
{
|
||||
if (!consoleDiv && document.body) {
|
||||
consoleDiv = document.createElement('div');
|
||||
document.body.appendChild(consoleDiv);
|
||||
}
|
||||
var span = document.createElement('span');
|
||||
span.appendChild(document.createTextNode(text));
|
||||
span.appendChild(document.createElement('br'));
|
||||
consoleDiv.appendChild(span);
|
||||
}
|
||||
|
||||
function forceTestFailureFromPromise(test, error, message)
|
||||
{
|
||||
// Promises convert exceptions into rejected Promises. Since there is
|
||||
// currently no way to report a failed test in the test harness, errors
|
||||
// are reported using force_timeout().
|
||||
if (message)
|
||||
consoleWrite(message + ': ' + error.message);
|
||||
else if (error)
|
||||
consoleWrite(error);
|
||||
|
||||
test.force_timeout();
|
||||
test.done();
|
||||
}
|
||||
|
||||
// Returns an array of audioCapabilities that includes entries for a set of
|
||||
// codecs that should cover all user agents.
|
||||
function getPossibleAudioCapabilities()
|
||||
{
|
||||
return [
|
||||
{ contentType: 'audio/mp4; codecs="mp4a.40.2"' },
|
||||
{ contentType: 'audio/webm; codecs="opus"' },
|
||||
];
|
||||
}
|
||||
|
||||
// Returns a trivial MediaKeySystemConfiguration that should be accepted,
|
||||
// possibly as a subset of the specified capabilities, by all user agents.
|
||||
function getSimpleConfiguration()
|
||||
{
|
||||
return [ {
|
||||
initDataTypes : [ 'webm', 'cenc', 'keyids' ],
|
||||
audioCapabilities: getPossibleAudioCapabilities()
|
||||
} ];
|
||||
}
|
||||
|
||||
// Returns a MediaKeySystemConfiguration for |initDataType| that should be
|
||||
// accepted, possibly as a subset of the specified capabilities, by all
|
||||
// user agents.
|
||||
function getSimpleConfigurationForInitDataType(initDataType)
|
||||
{
|
||||
return [ {
|
||||
initDataTypes: [ initDataType ],
|
||||
audioCapabilities: getPossibleAudioCapabilities()
|
||||
} ];
|
||||
}
|
||||
|
||||
// Returns a promise that is fulfilled with true if |initDataType| is supported,
|
||||
// by keysystem or false if not.
|
||||
function isInitDataTypeSupported(keysystem,initDataType)
|
||||
{
|
||||
return navigator.requestMediaKeySystemAccess(
|
||||
keysystem, getSimpleConfigurationForInitDataType(initDataType))
|
||||
.then(function() { return true; }, function() { return false; });
|
||||
}
|
||||
|
||||
function getSupportedInitDataTypes( keysystem )
|
||||
{
|
||||
return [ 'cenc', 'keyids', 'webm' ].filter( isInitDataTypeSupported.bind( null, keysystem ) );
|
||||
}
|
||||
|
||||
function arrayBufferAsString(buffer)
|
||||
{
|
||||
var array = [];
|
||||
Array.prototype.push.apply( array, new Uint8Array( buffer ) );
|
||||
return '0x' + array.map( function( x ) { return x < 16 ? '0'+x.toString(16) : x.toString(16); } ).join('');
|
||||
}
|
||||
|
||||
function dumpKeyStatuses(keyStatuses)
|
||||
{
|
||||
consoleWrite("for (var entry of keyStatuses)");
|
||||
for (var entry of keyStatuses) {
|
||||
consoleWrite(arrayBufferAsString(entry[0]) + ": " + entry[1]);
|
||||
}
|
||||
consoleWrite("for (var keyId of keyStatuses.keys())");
|
||||
for (var keyId of keyStatuses.keys()) {
|
||||
consoleWrite(arrayBufferAsString(keyId));
|
||||
}
|
||||
consoleWrite("for (var status of keyStatuses.values())");
|
||||
for (var status of keyStatuses.values()) {
|
||||
consoleWrite(status);
|
||||
}
|
||||
consoleWrite("for (var entry of keyStatuses.entries())");
|
||||
for (var entry of keyStatuses.entries()) {
|
||||
consoleWrite(arrayBufferAsString(entry[0]) + ": " + entry[1]);
|
||||
}
|
||||
consoleWrite("keyStatuses.forEach()");
|
||||
keyStatuses.forEach(function(status, keyId) {
|
||||
consoleWrite(arrayBufferAsString(keyId) + ": " + status);
|
||||
});
|
||||
}
|
||||
|
||||
// Verify that |keyStatuses| contains just the keys in |keys.expected|
|
||||
// and none of the keys in |keys.unexpected|. All keys should have status
|
||||
// 'usable'. Example call: verifyKeyStatuses(mediaKeySession.keyStatuses,
|
||||
// { expected: [key1], unexpected: [key2] });
|
||||
function verifyKeyStatuses(keyStatuses, keys)
|
||||
{
|
||||
var expected = keys.expected || [];
|
||||
var unexpected = keys.unexpected || [];
|
||||
|
||||
// |keyStatuses| should have same size as number of |keys.expected|.
|
||||
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), "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), "keystatuses should not have unexpected keys");
|
||||
assert_equals(keyStatuses.get(key), undefined, "keystatus for unexpected key should be undefined");
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue