Bug 1307019 - Testcase for encrypted MP4 without PSSH and MDSM waiting-for-CDM. r=jya

Tests that a fragmented MP4 file without a PSSH, but with encrypted valid
tracks with valid TENC boxes, is able to load with EME. This is a test for
the code path added in bug 1300069.

We setup MSE before starting up EME, so that we exercise the "waiting for
cdm" step in the MediaDecoderStateMachine, which was regressed in bug 1300069.

MozReview-Commit-ID: BXgdzAikWoH

--HG--
extra : rebase_source : b03910c96c8f61622ce7bc9fb7b53adc209526a4
This commit is contained in:
Chris Pearce 2016-10-03 16:35:27 +13:00
parent 64e92ab177
commit c5076e76b0
5 changed files with 129 additions and 0 deletions

View File

@ -461,3 +461,35 @@ function SetupEMEPref(callback) {
SpecialPowers.pushPrefEnv({ "set" : prefs }, callback);
}
function fetchWithXHR(uri, onLoadFunction) {
var p = new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open("GET", uri, true);
xhr.responseType = "arraybuffer";
xhr.addEventListener("load", function () {
is(xhr.status, 200, "fetchWithXHR load uri='" + uri + "' status=" + xhr.status);
resolve(xhr.response);
});
xhr.send();
});
if (onLoadFunction) {
p.then(onLoadFunction);
}
return p;
};
function once(target, name, cb) {
var p = new Promise(function(resolve, reject) {
target.addEventListener(name, function onceEvent(arg) {
target.removeEventListener(name, onceEvent);
resolve(arg);
});
});
if (cb) {
p.then(cb);
}
return p;
}

View File

@ -540,6 +540,8 @@ support-files =
sine.webm^headers^
short.mp4
short.mp4^headers^
short-audio-fragmented-cenc-without-pssh.mp4
short-audio-fragmented-cenc-without-pssh.mp4^headers^
short-video.ogv
short-video.ogv^headers^
small-shot-mp3.mp4
@ -688,6 +690,8 @@ skip-if = toolkit == 'android' # bug 1149374
skip-if = toolkit == 'android' # bug 1149374
[test_eme_initDataTypes.html]
skip-if = toolkit == 'android' # bug 1149374
[test_eme_missing_pssh.html]
skip-if = toolkit == 'android' # bug 1149374
[test_eme_non_mse_fails.html]
skip-if = toolkit == 'android' # bug 1149374
[test_eme_request_notifications.html]

View File

@ -0,0 +1 @@
Cache-Control: no-store

View File

@ -0,0 +1,92 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test Encrypted Media Extensions</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="manifest.js"></script>
<script type="text/javascript" src="eme.js"></script>
</head>
<body>
<audio controls id="audio"></audio>
<pre id="test">
<script class="testbody" type="text/javascript">
// Tests that a fragmented MP4 file without a PSSH, but with valid encrypted
// tracks with valid TENC boxes, is able to load with EME.
// We setup MSE before starting up EME, so that we exercise the "waiting for
// cdm" step in the MediaDecoderStateMachine.
SimpleTest.waitForExplicitFinish();
var pssh = [
0x00, 0x00, 0x00, 0x00,
0x70, 0x73, 0x73, 0x68, // BMFF box header (76 bytes, 'pssh')
0x01, 0x00, 0x00, 0x00, // Full box header (version = 1, flags = 0)
0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02, // SystemID
0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b,
0x00, 0x00, 0x00, 0x01, // KID_count (1)
0x2f, 0xef, 0x8a, 0xd8, 0x12, 0xdf, 0x42, 0x97,
0x83, 0xe9, 0xbf, 0x6e, 0x5e, 0x49, 0x3e, 0x53,
0x00, 0x00, 0x00, 0x00 // Size of Data (0)
];
var audio = document.getElementById("audio");
function LoadEME() {
var options = [{
initDataType: 'cenc',
audioType: 'audio/mp4; codecs="mp4a.40.2"',
}];
navigator.requestMediaKeySystemAccess("org.w3.clearkey", options)
.then((keySystemAccess) => {
return keySystemAccess.createMediaKeys();
}, bail("Failed to request key system access."))
.then((mediaKeys) => {
audio.setMediaKeys(mediaKeys);
var session = mediaKeys.createSession();
once(session, "message", (message) => {
is(message.messageType, 'license-request', "Expected a license-request");
var license = new TextEncoder().encode(JSON.stringify({
'keys': [{
'kty':'oct',
'kid':'L--K2BLfQpeD6b9uXkk-Uw',
'k':HexToBase64('7f412f0575f44f718259beef56ec7771')
}],
'type': 'temporary'
}));
session.update(license);
});
session.generateRequest('cenc', new Uint8Array(pssh));
});
}
function DownloadMedia(url, type, mediaSource) {
return new Promise(function(resolve, reject) {
var sourceBuffer = mediaSource.addSourceBuffer(type);
fetchWithXHR(url, (response) => {
once(sourceBuffer, "updateend", resolve);
sourceBuffer.appendBuffer(new Uint8Array(response));
});
});
}
function LoadMSE() {
var ms = new MediaSource();
audio.src = URL.createObjectURL(ms);
once(ms, "sourceopen", ()=>{
DownloadMedia('short-audio-fragmented-cenc-without-pssh.mp4', 'audio/mp4; codecs="mp4a.40.2"', ms)
.then(() => { ms.endOfStream(); LoadEME();});
});
audio.addEventListener("loadeddata", SimpleTest.finish);
}
SetupEMEPref(LoadMSE);
</script>
</pre>
</body>
</html>