2014-10-29 16:31:43 +00:00
|
|
|
<!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>
|
2015-01-29 07:30:38 +00:00
|
|
|
<script type="text/javascript" src="http://test1.mochi.test:8888/tests/dom/media/test/eme.js"></script>
|
2014-10-29 16:31:43 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
var manager = new MediaTestManager;
|
|
|
|
|
|
|
|
|
2014-10-28 00:21:12 +00:00
|
|
|
function KeysChangeFunc(session, keys, token) {
|
2014-10-29 16:31:43 +00:00
|
|
|
session.keyIdsReceived = [];
|
|
|
|
for (var keyid in keys) {
|
2014-11-05 02:11:44 +00:00
|
|
|
Log(token, "Set " + keyid + " to false in session.keyIdsReceived");
|
2014-10-29 16:31:43 +00:00
|
|
|
session.keyIdsReceived[keyid] = false;
|
|
|
|
}
|
|
|
|
return function(ev) {
|
|
|
|
var session = ev.target;
|
|
|
|
session.gotKeysChanged = true;
|
2015-01-31 00:23:19 +00:00
|
|
|
|
|
|
|
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.keyIdsReceived contained " + kid + " as expected.");
|
|
|
|
session.keyIdsReceived[kid] = true;
|
|
|
|
}
|
2014-10-29 16:31:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function startTest(test, token)
|
|
|
|
{
|
2014-10-28 00:21:12 +00:00
|
|
|
manager.started(token);
|
2014-10-29 16:31:43 +00:00
|
|
|
|
2014-10-28 00:21:11 +00:00
|
|
|
var sessions = [];
|
|
|
|
|
|
|
|
var v = SetupEME(test, token,
|
|
|
|
{
|
|
|
|
onsessioncreated: function(session) {
|
|
|
|
sessions.push(session);
|
2015-02-03 08:53:36 +00:00
|
|
|
session.addEventListener("keystatuseschange", KeysChangeFunc(session, test.keys, token), false);
|
2014-10-28 00:21:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2014-10-28 00:21:12 +00:00
|
|
|
|
2014-10-29 16:31:43 +00:00
|
|
|
var gotEncrypted = false;
|
|
|
|
var gotPlaying = false;
|
|
|
|
|
|
|
|
v.addEventListener("encrypted", function(ev) {
|
2014-10-28 00:21:11 +00:00
|
|
|
gotEncrypted = true;
|
2014-10-29 16:31:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
v.addEventListener("playing", function () { gotPlaying = true; });
|
|
|
|
|
2015-01-27 06:10:11 +00:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
|
2014-10-29 16:31:43 +00:00
|
|
|
v.addEventListener("ended", function(ev) {
|
2014-11-05 02:11:44 +00:00
|
|
|
ok(true, TimeStamp(token) + " got ended event");
|
2014-10-29 16:31:43 +00:00
|
|
|
|
2014-11-05 02:11:44 +00:00
|
|
|
ok(gotEncrypted, TimeStamp(token) + " encrypted event should have fired");
|
|
|
|
ok(gotPlaying, TimeStamp(token) + " playing event should have fired");
|
2014-10-29 16:31:43 +00:00
|
|
|
|
|
|
|
ok(Math.abs(test.duration - v.duration) < 0.1,
|
2014-11-05 02:11:44 +00:00
|
|
|
TimeStamp(token) + " Duration of video should be corrrect");
|
2014-10-29 16:31:43 +00:00
|
|
|
ok(Math.abs(test.duration - v.currentTime) < 0.1,
|
2014-11-05 02:11:44 +00:00
|
|
|
TimeStamp(token) + " Current time should be same as duration");
|
2014-10-28 00:21:11 +00:00
|
|
|
|
2014-10-29 16:31:43 +00:00
|
|
|
// Verify all sessions had all keys went sent the to the CDM usable, and thus
|
2015-02-03 08:53:36 +00:00
|
|
|
// that we received keystatuseschange event(s).
|
2014-11-05 02:11:44 +00:00
|
|
|
is(sessions.length, 1, TimeStamp(token) + " should have 1 session");
|
2014-10-29 16:31:43 +00:00
|
|
|
for (var i = 0; i < sessions.length; i++) {
|
|
|
|
var session = sessions[i];
|
2014-11-05 02:11:44 +00:00
|
|
|
ok(session.gotKeysChanged, TimeStamp(token) + " should have received at least one keychange event");
|
2014-10-29 16:31:43 +00:00
|
|
|
for (var kid in session.keyIdsReceived) {
|
2014-11-05 02:11:44 +00:00
|
|
|
ok(session.keyIdsReceived[kid], TimeStamp(token) + " key with id " + kid + " was usable as expected");
|
2014-10-29 16:31:43 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-28 00:21:11 +00:00
|
|
|
|
2014-10-30 02:05:49 +00:00
|
|
|
manager.finished(token);
|
2014-10-28 00:21:11 +00:00
|
|
|
});
|
2014-10-29 16:31:43 +00:00
|
|
|
|
2014-11-05 02:11:44 +00:00
|
|
|
LoadTest(test, v, token).then(function(){v.play();}, bail(token + " failed to load"));
|
2014-10-29 16:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function beginTest() {
|
|
|
|
manager.runTests(gEMETests, startTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
var prefs = [
|
|
|
|
[ "media.mediasource.enabled", true ],
|
2015-01-08 16:57:11 +00:00
|
|
|
[ "media.mediasource.youtubeonly", false ],
|
2014-10-31 10:09:49 +00:00
|
|
|
[ "media.mediasource.mp4.enabled", true ],
|
2014-10-29 16:31:43 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (/Linux/.test(navigator.userAgent) ||
|
|
|
|
!document.createElement('video').canPlayType("video/mp4")) {
|
|
|
|
// XXX remove once we have mp4 PlatformDecoderModules on all platforms.
|
|
|
|
prefs.push([ "media.fragmented-mp4.exposed", true ]);
|
|
|
|
prefs.push([ "media.fragmented-mp4.use-blank-decoder", true ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
SpecialPowers.pushPrefEnv({ "set" : prefs }, beginTest);
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|