Bug 1278198 - Fix tests to work with new EME API. r=gerald

MozReview-Commit-ID: WTWyYu2Zgp

--HG--
extra : rebase_source : 618abe352d2802e883a5f118055d32ed93c80323
This commit is contained in:
Chris Pearce 2016-07-11 16:46:21 +12:00
Родитель 06a7c88a23
Коммит 0117a54ea5
9 изменённых файлов: 154 добавлений и 126 удалений

Просмотреть файл

@ -1,4 +1,10 @@
const KEYSYSTEM_TYPE = "org.w3.clearkey";
const CLEARKEY_KEYSYSTEM = "org.w3.clearkey";
const gCencMediaKeySystemConfig = [{
initDataTypes: ['cenc'],
videoCapabilities: [{ contentType: 'video/mp4' }],
audioCapabilities: [{ contentType: 'audio/mp4' }],
}];
function IsMacOSSnowLeopardOrEarlier() {
var re = /Mac OS X (\d+)\.(\d+)/;
@ -376,7 +382,7 @@ function SetupEME(test, token, params)
options.audioCapabilities = [{contentType: streamType("audio")}];
}
var p = navigator.requestMediaKeySystemAccess(KEYSYSTEM_TYPE, [options]);
var p = navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, [options]);
var r = bail(token + " Failed to request key system access.");
chain(p, r)
.then(function(keySystemAccess) {

Просмотреть файл

@ -14,18 +14,18 @@
SimpleTest.waitForExplicitFinish();
const keysystem = 'org.w3.clearkey';
function createAndSet() {
return new Promise(function(resolve, reject) {
var m;
navigator.requestMediaKeySystemAccess(keysystem, [{initDataTypes: ['cenc']}])
navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, gCencMediaKeySystemConfig)
.then(function (access) {
return access.createMediaKeys();
}).then(function (mediaKeys) {
})
.then(function (mediaKeys) {
m = mediaKeys;
return document.getElementById("v").setMediaKeys(mediaKeys);
}).then(function() {
})
.then(function() {
resolve(m);
});
}

Просмотреть файл

@ -39,9 +39,9 @@ var tests = [
{
name: "Two keyIds, persistent session, type before kids",
initDataType: 'keyids',
initData: '{"type":"persistent", "kids":["LwVHf8JLtPrv2GUXFW2v_A", "0DdtU9od-Bh5L3xbv0Xf_A"]}',
expectedRequest: '{"kids":["LwVHf8JLtPrv2GUXFW2v_A","0DdtU9od-Bh5L3xbv0Xf_A"],"type":"persistent"}',
sessionType: 'persistent',
initData: '{"type":"persistent-license", "kids":["LwVHf8JLtPrv2GUXFW2v_A", "0DdtU9od-Bh5L3xbv0Xf_A"]}',
expectedRequest: '{"kids":["LwVHf8JLtPrv2GUXFW2v_A","0DdtU9od-Bh5L3xbv0Xf_A"],"type":"persistent-license"}',
sessionType: 'persistent-license',
expectPass: true,
},
{
@ -62,7 +62,7 @@ var tests = [
name: "SessionType in license doesn't match MediaKeySession's sessionType",
initDataType: 'keyids',
initData: '{"kids":["LwVHf8JLtPrv2GUXFW2v_A"]}',
sessionType: 'persistent',
sessionType: 'persistent-license',
expectPass: false,
},
{
@ -108,10 +108,13 @@ function PrepareInitData(initDataType, initData)
function Test(test) {
return new Promise(function(resolve, reject) {
navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{initDataTypes: [test.initDataType]}]).then(
(access) => access.createMediaKeys()
).then(
(mediaKeys) => {
var configs = [{
initDataTypes: [test.initDataType],
videoCapabilities: [{contentType: 'video/mp4' }],
}];
navigator.requestMediaKeySystemAccess('org.w3.clearkey', configs)
.then((access) => access.createMediaKeys())
.then((mediaKeys) => {
var session = mediaKeys.createSession(test.sessionType);
session.addEventListener("message", function(event) {
is(event.messageType, "license-request", "'" + test.name + "' MediaKeyMessage type should be license-request.");

Просмотреть файл

@ -20,7 +20,7 @@ function DoSetMediaKeys(v, test)
videoCapabilities: [{contentType: test.videoType}],
}];
return navigator.requestMediaKeySystemAccess("org.w3.clearkey", options)
return navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, options)
.then(function(keySystemAccess) {
return keySystemAccess.createMediaKeys();

Просмотреть файл

@ -86,7 +86,7 @@ function startTest(test, token)
// Once the session is closed, reload the MediaKeys and reload the session
.then(function() {
return navigator.requestMediaKeySystemAccess(KEYSYSTEM_TYPE, [{initDataTypes:["cenc"]}]);
return navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, gCencMediaKeySystemConfig);
})
.then(function(requestedKeySystemAccess) {
@ -96,7 +96,7 @@ function startTest(test, token)
.then(function(mediaKeys) {
Log(token, "re-created MediaKeys object ok");
recreatedSession = mediaKeys.createSession("persistent");
recreatedSession = mediaKeys.createSession("persistent-license");
Log(token, "Created recreatedSession, loading sessionId=" + sessionId);
return recreatedSession.load(sessionId);
})
@ -127,7 +127,7 @@ function startTest(test, token)
.then(function(mediaKeys) {
Log(token, "re-re-created MediaKeys object ok");
// Trying to load the removed persistent session should fail.
return mediaKeys.createSession("persistent").load(sessionId);
return mediaKeys.createSession("persistent-license").load(sessionId);
})
.then(function(suceeded) {
@ -142,7 +142,7 @@ function startTest(test, token)
});
},
sessionType: "persistent",
sessionType: "persistent-license",
}
);

Просмотреть файл

@ -11,7 +11,6 @@
<pre id="test">
<script class="testbody" type="text/javascript">
const CLEARKEY_ID = 'org.w3.clearkey';
const SUPPORTED_LABEL = "pass label";
function ValidateConfig(name, expected, observed) {
@ -36,6 +35,12 @@ function ValidateConfig(name, expected, observed) {
ok(observed.videoCapabilities.length == 1, "Test function can only handle one capability.");
is(observed.videoCapabilities[0].contentType, expected.videoCapabilities[0].contentType, name + " videoCapabilities should match.");
}
if (expected.sessionTypes) {
is(expected.sessionTypes.length, observed.sessionTypes.length, "Should have expected number of sessionTypes");
for (var i = 0; i < expected.sessionTypes.length; i++) {
is(expected[i], observed[i], "Session type " + i + " should match");
}
}
}
function Test(test) {
@ -43,14 +48,15 @@ function Test(test) {
return new Promise(function(resolve, reject) {
var p;
if (test.options) {
p = navigator.requestMediaKeySystemAccess(test.keySystem, test.options);
var keySystem = (test.keySystem !== undefined) ? test.keySystem : CLEARKEY_KEYSYSTEM;
p = navigator.requestMediaKeySystemAccess(keySystem, test.options);
} else {
p = navigator.requestMediaKeySystemAccess(test.keySystem);
p = navigator.requestMediaKeySystemAccess(keySystem);
}
p.then(
function(keySystemAccess) {
ok(test.shouldPass, name + " passed and was expected to " + (test.shouldPass ? "pass" : "fail"));
is(keySystemAccess.keySystem, CLEARKEY_ID, "CDM keySystem should be in MediaKeySystemAccess.keySystem");
is(keySystemAccess.keySystem, CLEARKEY_KEYSYSTEM, "CDM keySystem should be in MediaKeySystemAccess.keySystem");
ValidateConfig(name, test.expectedConfig, keySystemAccess.getConfiguration());
resolve();
},
@ -78,28 +84,27 @@ var tests = [
},
{
name: 'Empty options specified',
keySystem: CLEARKEY_ID,
options: [ ],
shouldPass: false,
},
{
name: 'Undefined options',
keySystem: CLEARKEY_ID,
shouldPass: false,
},
{
name: 'Basic MP4 cenc',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
audioCapabilities: [{contentType: 'audio/mp4'}],
videoCapabilities: [{contentType: 'video/mp4'}],
}
],
expectedConfig: {
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
audioCapabilities: [{contentType: 'audio/mp4'}],
videoCapabilities: [{contentType: 'video/mp4'}],
},
shouldPass: true,
@ -117,42 +122,32 @@ var tests = [
},
{
name: 'Invalid initDataType',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['bogus'],
audioCapabilities: [{contentType: 'audio/mp4'}],
}
],
shouldPass: false,
},
{
name: 'Valid initDataType after invalid',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
initDataTypes: ['bogus', 'invalid', 'cenc'],
audioCapabilities: [{contentType: 'audio/mp4'}],
}
],
expectedConfig: {
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
audioCapabilities: [{contentType: 'audio/mp4'}],
},
shouldPass: true,
},
{
name: 'Empty initDataTypes',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: [],
}
],
shouldPass: false,
},
{
name: 'Invalid videoType',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['cenc'],
@ -162,15 +157,57 @@ var tests = [
shouldPass: false,
},
{
name: 'distinctiveIdentifier, persistentState, and robustness ignored',
keySystem: CLEARKEY_ID,
name: 'Invalid distinctiveIdentifier fails',
options: [
{
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4'}],
distinctiveIdentifier: 'bogus',
persistentState: 'bogus',
}
],
shouldPass: false,
},
{
name: 'distinctiveIdentifier is prohibited for ClearKey',
options: [
{
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4'}],
distinctiveIdentifier: 'required',
}
],
shouldPass: false,
},
{
name: 'Invalid persistentState fails',
options: [
{
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4'}],
persistentState: 'bogus',
}
],
shouldPass: false,
},
{
name: 'Invalid robustness unsupported',
options: [
{
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4', robustness: 'very much so'}],
}
],
shouldPass: false,
},
{
name: 'Unexpected config entry should be ignored',
options: [
{
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4', robustness: 'somewhat'}],
distinctiveIdentifier: 'bogus',
persistentState: 'bogus',
videoCapabilities: [{contentType: 'video/mp4'}],
unexpectedEntry: 'this should be ignored',
}
],
expectedConfig: {
@ -180,61 +217,8 @@ var tests = [
},
shouldPass: true,
},
{
name: 'Only unrecognised dict entries specified with unrecognised video type',
keySystem: CLEARKEY_ID,
options: [
{
videoCapabilities: [{robustness: 'very much so'}],
distinctiveIdentifier: 'required',
persistentState: 'required',
}
],
shouldPass: false,
},
{
name: 'Only unrecognised dict entries specified should be ignored',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
distinctiveIdentifier: 'required',
persistentState: 'required',
}
],
expectedConfig: {
label: SUPPORTED_LABEL,
},
shouldPass: true,
},
{
name: 'Empty config dict',
keySystem: CLEARKEY_ID,
options: [{ label: SUPPORTED_LABEL }],
expectedConfig: {
label: SUPPORTED_LABEL
},
shouldPass: true,
},
{
name: 'Unexpected config entry should be ignored',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
unexpectedEntry: 'this should be ignored',
}
],
expectedConfig: {
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
},
shouldPass: true,
},
{
name: 'Invalid option followed by valid',
keySystem: CLEARKEY_ID,
options: [
{
label: "this config should not be supported",
@ -253,9 +237,60 @@ var tests = [
},
shouldPass: true,
},
{
name: 'Persistent sessions; persistence required',
options: [
{
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4'}],
sessionTypes: ['temporary','persistent-license'],
persistentState: 'required',
}
],
expectedConfig: {
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4'}],
sessionTypes: ['temporary','persistent-license'],
persistentState: 'required',
},
shouldPass: true,
},
{
name: 'Persistent sessions not allowed when persistentState prohibited',
options: [
{
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4'}],
sessionTypes: ['temporary','persistent-license'],
persistentState: 'not-allowed',
}
],
shouldPass: false,
},
{
name: 'Persistent sessions; should bump optional persistState to required',
options: [
{
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4'}],
sessionTypes: ['temporary','persistent-license'],
persistentState: 'optional',
}
],
expectedConfig: {
label: SUPPORTED_LABEL,
initDataTypes: ['cenc'],
videoCapabilities: [{contentType: 'video/mp4'}],
sessionTypes: ['temporary','persistent-license'],
persistentState: 'required',
},
shouldPass: true,
},
{
name: 'MP4 audio container',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
@ -272,7 +307,6 @@ var tests = [
},
{
name: 'MP4 audio container with AAC-LC',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
@ -289,7 +323,6 @@ var tests = [
},
{
name: 'MP4 audio container with invalid codecs',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['cenc'],
@ -300,7 +333,6 @@ var tests = [
},
{
name: 'MP4 audio container with mp3 is unsupported',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['cenc'],
@ -311,7 +343,6 @@ var tests = [
},
{
name: 'MP4 video container type with an mp3 codec is unsupported',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['cenc'],
@ -322,7 +353,6 @@ var tests = [
},
{
name: 'MP4 audio container type with a video codec is unsupported',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['cenc'],
@ -333,7 +363,6 @@ var tests = [
},
{
name: 'MP4 video container with constrained baseline h.264',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
@ -350,7 +379,6 @@ var tests = [
},
{
name: 'MP4 video container with invalid codecs',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['cenc'],
@ -361,7 +389,6 @@ var tests = [
},
{
name: 'MP4 video container with both audio and video codec type in videoType',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['cenc'],
@ -372,7 +399,6 @@ var tests = [
},
{
name: 'MP4 audio and video type both specified',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
@ -391,7 +417,6 @@ var tests = [
},
{
name: 'Basic WebM video',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
@ -408,7 +433,6 @@ var tests = [
},
{
name: 'Basic WebM audio',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
@ -425,7 +449,6 @@ var tests = [
},
{
name: 'Webm with Vorbis audio and VP8 video.',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
@ -444,7 +467,6 @@ var tests = [
},
{
name: 'Webm with Vorbis audio and VP9 video.',
keySystem: CLEARKEY_ID,
options: [
{
label: SUPPORTED_LABEL,
@ -463,7 +485,6 @@ var tests = [
},
{
name: 'Webm with bogus video.',
keySystem: CLEARKEY_ID,
options: [
{
initDataTypes: ['webm'],
@ -474,7 +495,7 @@ var tests = [
},
{
name: "CDM version less than",
keySystem: CLEARKEY_ID + ".0",
keySystem: CLEARKEY_KEYSYSTEM + ".0",
options: [
{
label: SUPPORTED_LABEL,
@ -491,7 +512,7 @@ var tests = [
},
{
name: "CDM version equal to",
keySystem: CLEARKEY_ID + ".1",
keySystem: CLEARKEY_KEYSYSTEM + ".1",
options: [
{
label: SUPPORTED_LABEL,
@ -508,7 +529,7 @@ var tests = [
},
{
name: "CDM version greater than",
keySystem: CLEARKEY_ID + ".2",
keySystem: CLEARKEY_KEYSYSTEM + ".2",
options: [
{
initDataTypes: ['cenc'],
@ -519,7 +540,7 @@ var tests = [
},
{
name: "Non-whole number CDM version",
keySystem: CLEARKEY_ID + ".0.1",
keySystem: CLEARKEY_KEYSYSTEM + ".0.1",
options: [
{
initDataTypes: ['cenc'],

Просмотреть файл

@ -36,7 +36,7 @@ function Test(test) {
var name = "'" + test.keySystem + "'";
return p.then(function() {
return new Promise(function(resolve, reject) {
navigator.requestMediaKeySystemAccess(test.keySystem, [{initDataTypes:["cenc"]}])
navigator.requestMediaKeySystemAccess(test.keySystem, gCencMediaKeySystemConfig)
.then(
function(keySystemAccess) {
return keySystemAccess.createMediaKeys();
@ -59,29 +59,27 @@ function Test(test) {
});
}
const CLEARKEY_ID = 'org.w3.clearkey';
var tests = [
{
keySystem: CLEARKEY_ID,
keySystem: CLEARKEY_KEYSYSTEM,
shouldPass: false,
expectedStatus: 'api-disabled',
prefs: [["media.eme.enabled", false], ["media.eme.clearkey.enabled", true]]
},
{
keySystem: CLEARKEY_ID,
keySystem: CLEARKEY_KEYSYSTEM,
shouldPass: false,
expectedStatus: 'cdm-disabled',
prefs: [["media.eme.enabled", true], ["media.eme.clearkey.enabled", false]]
},
{
keySystem: CLEARKEY_ID + '.10000' , // A stupendously high min CDM version, presumably not installed.
keySystem: CLEARKEY_KEYSYSTEM + '.10000' , // A stupendously high min CDM version, presumably not installed.
shouldPass: false,
expectedStatus: 'cdm-insufficient-version',
prefs: [["media.eme.enabled", true], ["media.eme.clearkey.enabled", true]]
},
{
keySystem: CLEARKEY_ID,
keySystem: CLEARKEY_KEYSYSTEM,
shouldPass: true,
expectedStatus: 'cdm-created',
prefs: [["media.eme.enabled", true], ["media.eme.clearkey.enabled", true]]

Просмотреть файл

@ -12,7 +12,7 @@
<script class="testbody" type="text/javascript">
function Test() {
navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{ initDataTypes: ['cenc'] }])
navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, gCencMediaKeySystemConfig)
.then(access => access.createMediaKeys())
.then(mediaKeys => {
var initData = (new TextEncoder()).encode( 'this is an invalid license, and that is ok');

Просмотреть файл

@ -14,7 +14,7 @@
function beginTest() {
var video = document.createElement("video");
navigator.requestMediaKeySystemAccess("org.w3.clearkey", [{initDataTypes: ["cenc"]}])
navigator.requestMediaKeySystemAccess(CLEARKEY_KEYSYSTEM, gCencMediaKeySystemConfig)
.then(function(keySystemAccess) {
return keySystemAccess.createMediaKeys();
})