gecko-dev/dom/media/test/test_eme_playback.html

120 строки
3.9 KiB
HTML

<!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="http://test1.mochi.test:8888/tests/dom/media/test/eme.js"></script>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var manager = new MediaTestManager;
function KeysChangeFunc(session, keys, token) {
session.keyIdsReceived = [];
for (var keyid in keys) {
Log(token, "Set " + keyid + " to false in session[" + session.sessionId + "].keyIdsReceived");
session.keyIdsReceived[keyid] = false;
}
return function(ev) {
var session = ev.target;
session.gotKeysChanged = true;
var map = session.keyStatuses;
for (var [key, val] of map.entries()) {
is(val, "usable", token + ": key status should be usable");
var kid = Base64ToHex(window.btoa(ArrayBufferToString(key)));
ok(kid in session.keyIdsReceived, TimeStamp(token) + " session[" + session.sessionId + "].keyIdsReceived contained " + kid + " as expected.");
session.keyIdsReceived[kid] = true;
}
}
}
function startTest(test, token)
{
manager.started(token);
var sessions = [];
var v = SetupEME(test, token,
{
onsessioncreated: function(session) {
sessions.push(session);
session.addEventListener("keystatuseschange", KeysChangeFunc(session, test.keys, token), false);
}
}
);
document.body.appendChild(v);
var gotEncrypted = 0;
v.addEventListener("encrypted", function(ev) {
gotEncrypted += 1;
});
v.addEventListener("loadedmetadata", function() {
ok(SpecialPowers.do_lookupGetter(v, "isEncrypted").apply(v),
TimeStamp(token) + " isEncrypted should be true");
is(v.isEncrypted, undefined, "isEncrypted should not be accessible from content");
});
v.addEventListener("ended", function(ev) {
ok(true, TimeStamp(token) + " got ended event");
is(gotEncrypted, test.sessionCount,
TimeStamp(token) + " encrypted events expected: " + test.sessionCount
+ ", actual: " + gotEncrypted);
ok(Math.abs(test.duration - v.duration) < 0.1,
TimeStamp(token) + " Duration of video should be corrrect");
ok(Math.abs(test.duration - v.currentTime) < 0.1,
TimeStamp(token) + " Current time should be same as duration");
// Verify all sessions had all keys went sent to the CDM usable, and thus
// that we received keystatuseschange event(s).
is(sessions.length, test.sessionCount, TimeStamp(token) + " should have "
+ test.sessionCount
+ " session" + (test.sessionCount === 1 ? "" : "s"));
var keyIdsReceived = [];
for (var keyid in test.keys) { keyIdsReceived[keyid] = false; }
for (var i = 0; i < sessions.length; i++) {
var session = sessions[i];
ok(session.gotKeysChanged,
TimeStamp(token) + " session[" + session.sessionId
+ "] should have received at least one keychange event");
for (var kid in session.keyIdsReceived) {
Log(token, "session[" + session.sessionId + "] key " + kid + " = " + (session.keyIdsReceived[kid] ? "true" : "false"));
if (session.keyIdsReceived[kid]) { keyIdsReceived[kid] = true; }
}
}
for (var kid in keyIdsReceived) {
ok(keyIdsReceived[kid], TimeStamp(token) + " key with id " + kid + " was usable as expected");
}
manager.finished(token);
});
LoadTest(test, v, token)
.then(function() {
v.play();
}).catch(function() {
ok(false, token + " failed to load");
manager.finished(token);
});
}
function beginTest() {
manager.runTests(gEMETests, startTest);
}
SimpleTest.waitForExplicitFinish();
SetupEMEPref(beginTest);
</script>
</pre>
</body>
</html>