summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_trackevent.html
blob: e09db8336807b1fb8e963568c05ec3e7199acc04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Bug 893309 - Implement TrackEvent</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" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();

var video = document.createElement("video");
isnot(video.textTracks, undefined, "HTMLMediaElement::TextTrack() property should be available.")
ok(typeof video.addTextTrack == "function", "HTMLMediaElement::AddTextTrack() function should be available.")

var trackList = video.textTracks;
is(trackList.length, 0, "Length should be 0.");

var evtTextTrack, numOfCalls = 0, tt;
trackList.onaddtrack = function(event) {
  ok(event instanceof TrackEvent, "Fired event from onaddtrack should be a TrackEvent");
  is(event.type, "addtrack", "Event type should be addtrack");
  ok(event.isTrusted, "Event should be trusted!");
  ok(!event.bubbles, "Event shouldn't bubble!");
  ok(!event.cancelable, "Event shouldn't be cancelable!");

  evtTextTrack = event.track;
  tt = textTrack[numOfCalls].track || textTrack[numOfCalls];

  ok(tt === evtTextTrack, "Text tracks should be the same");
  is(evtTextTrack.label, label[numOfCalls], "Label should be set to "+ label[numOfCalls]);
  is(evtTextTrack.language, language[numOfCalls], "Language should be " + language[numOfCalls]);
  is(evtTextTrack.kind, kind[numOfCalls], "Kind should be " + kind[numOfCalls]);

  if (++numOfCalls == 4) {
    SimpleTest.finish();
  }
};

var label = ["Oasis", "Coldplay", "t.A.T.u", ""];
language = ["en-CA", "en-GB", "ru", ""];
kind = ["subtitles", "captions", "chapters", "subtitles"];

var textTrack = new Array(4);
for (var i = 0; i < 3; ++i) {
  textTrack[i] = video.addTextTrack(kind[i], label[i], language[i]);
  is(trackList.length, i + 1, "Length should be " + (i+1));
}

video.src = "seek.webm";
video.preload = "auto";
var trackElement = document.createElement("track");
trackElement.src = "basic.vtt";
textTrack[3] = trackElement;

document.getElementById("content").appendChild(video);
video.appendChild(trackElement);

//TODO: Tests for removetrack event to be added along with bug 882677
</script>
</pre>
</body>
</html>