2013-06-24 19:23:00 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=833386
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<meta charset='utf-8'>
|
|
|
|
<title>Test for Bug 833386 - HTMLTrackElement</title>
|
|
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]},
|
|
|
|
function() {
|
|
|
|
var video = document.createElement("video");
|
|
|
|
video.src = "seek.webm";
|
2013-06-27 18:05:03 -07:00
|
|
|
video.preload = "auto";
|
2013-06-24 19:23:00 -07:00
|
|
|
var trackElement = document.createElement("track");
|
|
|
|
trackElement.src = "basic.vtt";
|
|
|
|
trackElement.kind = "subtitles";
|
|
|
|
document.getElementById("content").appendChild(video);
|
|
|
|
video.appendChild(trackElement);
|
2013-06-27 18:05:03 -07:00
|
|
|
video.addEventListener("loadedmetadata", function run_tests() {
|
2013-06-24 19:23:00 -07:00
|
|
|
// Re-que run_tests() at the end of the event loop until the track
|
|
|
|
// element has loaded its data.
|
|
|
|
if (trackElement.readyState == 1) {
|
|
|
|
setTimeout(run_tests, 0);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-05 07:57:00 -07:00
|
|
|
is(trackElement.readyState, 2, "Track::ReadyState should be set to LOADED.");
|
2013-06-24 19:23:00 -07:00
|
|
|
|
|
|
|
var cueList = trackElement.track.cues;
|
2013-12-13 07:09:33 -08:00
|
|
|
is(cueList.length, 6, "Cue list length should be 6.");
|
2013-06-24 19:23:00 -07:00
|
|
|
|
2013-08-27 13:07:00 -07:00
|
|
|
// Check that the typedef of TextTrackCue works in Gecko.
|
|
|
|
is(window.TextTrackCue, undefined, "TextTrackCue should be undefined.");
|
|
|
|
isnot(window.VTTCue, undefined, "VTTCue should be defined.");
|
|
|
|
|
2013-06-24 19:23:00 -07:00
|
|
|
// Check if first cue was parsed correctly.
|
|
|
|
var cue = cueList[0];
|
|
|
|
is(cue.id, "1", "Cue's ID should be 1.");
|
|
|
|
is(cue.startTime, 0.5, "Cue's start time should be 0.5.");
|
|
|
|
is(cue.endTime, 0.7, "Cue's end time should be 0.7.");
|
|
|
|
is(cue.pauseOnExit, false, "Cue's pause on exit flag should be false.");
|
|
|
|
is(cue.text, "This", "Cue's text should be set correctly.");
|
|
|
|
// TODO: https://bugzilla.mozilla.org/show_bug.cgi?id=879431
|
|
|
|
// GetTrack() isn't implemented so this *is* returning undefined currently.
|
|
|
|
todo_isnot(cue.track, undefined, "Cue's track should be defined.");
|
|
|
|
|
|
|
|
// Check that all cue times were not rounded
|
|
|
|
is(cueList[1].startTime, 1.2, "Second cue's start time should be 1.2.");
|
|
|
|
is(cueList[1].endTime, 2.4, "Second cue's end time should be 2.4.");
|
2013-12-13 07:09:33 -08:00
|
|
|
is(cueList[2].startTime, 2, "Third cue's start time should be 2.");
|
|
|
|
is(cueList[2].endTime, 3.5, "Third cue's end time should be 3.5.");
|
|
|
|
is(cueList[3].startTime, 2.71, "Fourth cue's start time should be 2.71.");
|
|
|
|
is(cueList[3].endTime, 2.91, "Fourth cue's end time should be 2.91.");
|
|
|
|
is(cueList[4].startTime, 3.217, "Fifth cue's start time should be 3.217.");
|
|
|
|
is(cueList[4].endTime, 3.989, "Fifth cue's end time should be 3.989.");
|
|
|
|
is(cueList[5].startTime, 3.217, "Sixth cue's start time should be 3.217.");
|
|
|
|
is(cueList[5].endTime, 3.989, "Sixth cue's end time should be 3.989.");
|
2013-06-24 19:23:00 -07:00
|
|
|
|
|
|
|
// Check that Cue setters are working correctly.
|
|
|
|
cue.id = "Cue 01";
|
|
|
|
is(cue.id, "Cue 01", "Cue's ID should be 'Cue 01'.");
|
2013-12-13 07:09:33 -08:00
|
|
|
cue.startTime = 0.51;
|
|
|
|
is(cue.startTime, 0.51, "Cue's start time should be 0.51.");
|
|
|
|
cue.endTime = 0.71;
|
|
|
|
is(cue.endTime, 0.71, "Cue's end time should be 0.71.");
|
2013-06-24 19:23:00 -07:00
|
|
|
cue.pauseOnExit = true;
|
|
|
|
is(cue.pauseOnExit, true, "Cue's pause on exit flag should be true.");
|
|
|
|
|
2013-12-13 06:29:15 -08:00
|
|
|
// Check that cue line align works properly
|
|
|
|
is(cue.lineAlign, "start", "Cue's default line alignment should be start.");
|
|
|
|
|
|
|
|
var exceptionHappened = false;
|
|
|
|
try {
|
|
|
|
cue.lineAlign = "left";
|
|
|
|
} catch(e) {
|
|
|
|
exceptionHappened = true;
|
|
|
|
is(e.name, "SyntaxError", "Should have thrown SyntaxError.");
|
|
|
|
}
|
|
|
|
ok(exceptionHappened, "Exception should have happened.");
|
|
|
|
|
|
|
|
exceptionHappened = false;
|
|
|
|
try {
|
|
|
|
cue.lineAlign = "right";
|
|
|
|
} catch(e) {
|
|
|
|
exceptionHappened = true;
|
|
|
|
is(e.name, "SyntaxError", "Should have thrown SyntaxError.");
|
|
|
|
}
|
|
|
|
ok(exceptionHappened, "Exception should have happened.");
|
|
|
|
|
|
|
|
cue.lineAlign = "middle";
|
|
|
|
is(cue.lineAlign, "middle", "Cue's line align should be middle.");
|
|
|
|
cue.lineAlign = "START";
|
|
|
|
is(cue.lineAlign, "middle", "Cue's line align should be middle.");
|
|
|
|
cue.lineAlign = "end";
|
|
|
|
is(cue.lineAlign, "end", "Cue's line align should be end.");
|
|
|
|
|
2013-12-13 09:57:48 -08:00
|
|
|
// Check that cue position align works properly
|
|
|
|
is(cue.positionAlign, "middle", "Cue's default position alignment should be middle.");
|
|
|
|
|
|
|
|
var exceptionHappened = false;
|
|
|
|
try {
|
|
|
|
cue.positionAlign = "left";
|
|
|
|
} catch(e) {
|
|
|
|
exceptionHappened = true;
|
|
|
|
is(e.name, "SyntaxError", "Should have thrown SyntaxError.");
|
|
|
|
}
|
|
|
|
ok(exceptionHappened, "Exception should have happened.");
|
|
|
|
|
|
|
|
exceptionHappened = false;
|
|
|
|
try {
|
|
|
|
cue.positionAlign = "right";
|
|
|
|
} catch(e) {
|
|
|
|
exceptionHappened = true;
|
|
|
|
is(e.name, "SyntaxError", "Should have thrown SyntaxError.");
|
|
|
|
}
|
|
|
|
ok(exceptionHappened, "Exception should have happened.");
|
|
|
|
|
|
|
|
cue.positionAlign = "start";
|
|
|
|
is(cue.positionAlign, "start", "Cue's position align should be start.");
|
|
|
|
cue.positionAlign = "end";
|
|
|
|
is(cue.positionAlign, "end", "Cue's position align should be end.");
|
|
|
|
|
2013-08-27 13:07:00 -07:00
|
|
|
// Check that we can create and add new VTTCues
|
|
|
|
var vttCue = new VTTCue(3.999, 4, "foo");
|
|
|
|
trackElement.track.addCue(vttCue);
|
2013-12-13 07:09:33 -08:00
|
|
|
is(cueList.length, 7, "Cue list length should now be 7.");
|
2013-06-24 19:23:00 -07:00
|
|
|
|
2013-08-27 13:07:00 -07:00
|
|
|
// Check that new VTTCue was added correctly
|
2013-12-13 07:09:33 -08:00
|
|
|
cue = cueList[6];
|
2013-06-24 19:23:00 -07:00
|
|
|
is(cue.startTime, 3.999, "Cue's start time should be 3.999.");
|
|
|
|
is(cue.endTime, 4, "Cue's end time should be 4.");
|
|
|
|
is(cue.text, "foo", "Cue's text should be foo.");
|
|
|
|
|
|
|
|
// Adding the same cue again should not increase the cue count.
|
2013-08-27 13:07:00 -07:00
|
|
|
trackElement.track.addCue(vttCue);
|
2013-12-13 07:09:33 -08:00
|
|
|
is(cueList.length, 7, "Cue list length should be 7.");
|
2013-06-24 19:23:00 -07:00
|
|
|
|
|
|
|
// Check that we are able to remove cues.
|
|
|
|
trackElement.track.removeCue(cue);
|
2013-12-13 07:09:33 -08:00
|
|
|
is(cueList.length, 6, "Cue list length should be 6.");
|
2013-06-24 19:23:00 -07:00
|
|
|
|
2013-12-13 06:29:15 -08:00
|
|
|
exceptionHappened = false;
|
2013-06-24 19:23:00 -07:00
|
|
|
try {
|
|
|
|
// We should not be able to remove a cue that is not in the list.
|
2013-08-27 13:07:00 -07:00
|
|
|
cue = new VTTCue(1, 2, "foo");
|
2013-06-28 10:31:43 -07:00
|
|
|
trackElement.track.removeCue(cue);
|
2013-06-24 19:23:00 -07:00
|
|
|
} catch (e) {
|
|
|
|
// "NotFoundError" should be thrown when trying to remove a cue that is
|
|
|
|
// not in the list.
|
2013-06-28 10:31:43 -07:00
|
|
|
is(e.name, "NotFoundError", "Should have thrown NotFoundError.");
|
2013-06-24 19:23:00 -07:00
|
|
|
exceptionHappened = true;
|
|
|
|
}
|
|
|
|
// If this is false then we did not throw an error and probably removed a cue
|
|
|
|
// when we shouln't have.
|
|
|
|
ok(exceptionHappened, "Exception should have happened.");
|
|
|
|
|
2013-12-13 07:09:33 -08:00
|
|
|
is(cueList.length, 6, "Cue list length should be 6.");
|
2013-12-20 18:32:44 -08:00
|
|
|
|
2013-12-13 07:09:33 -08:00
|
|
|
// Test TextTrack::ActiveCues.
|
|
|
|
var cueInfo = [
|
|
|
|
{ startTime: 0.51, endTime: 0.71, ids: ["Cue 01"] },
|
|
|
|
{ startTime: 0.72, endTime: 1.19, ids: [] },
|
|
|
|
{ startTime: 1.2, endTime: 1.9, ids: [2] },
|
|
|
|
{ startTime: 2, endTime: 2.4, ids: [2, 2.5] },
|
|
|
|
{ startTime: 2.41, endTime: 2.70, ids: [2.5] },
|
|
|
|
{ startTime: 2.71, endTime: 2.91, ids: [2.5, 3] },
|
|
|
|
{ startTime: 2.92, endTime: 3.216, ids: [2.5] },
|
|
|
|
{ startTime: 3.217, endTime: 3.5, ids: [2.5, 4, 5] },
|
|
|
|
{ startTime: 3.51, endTime: 3.989, ids: [4, 5] },
|
|
|
|
{ startTime: 3.99, endTime: 4, ids: [] }
|
|
|
|
];
|
|
|
|
|
|
|
|
video.addEventListener("timeupdate", function() {
|
|
|
|
var activeCues = trackElement.track.activeCues,
|
|
|
|
found = false,
|
|
|
|
playbackTime = video.currentTime;
|
|
|
|
|
|
|
|
for (var i = 0; i < cueInfo.length; i++) {
|
|
|
|
var cue = cueInfo[i];
|
|
|
|
if (playbackTime >= cue.startTime && playbackTime <= cue.endTime) {
|
|
|
|
is(activeCues.length, cue.ids.length, "There should be " + cue.ids.length + " currently active cue(s).");
|
|
|
|
for (var j = 0; j < cue.ids.length; j++) {
|
|
|
|
isnot(activeCues.getCueById(cue.ids[j]), undefined, "The cue with ID " + cue.ids[j] + " should be active.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
video.addEventListener("ended", function(){
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
|
|
|
|
video.play();
|
2013-06-27 18:05:03 -07:00
|
|
|
});
|
2013-06-24 19:23:00 -07:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|