4 <title>AudioTrackList
& VideoTrackList addtrack event
</title>
5 <script src=
"../../resources/testharness.js"></script>
6 <script src=
"../../resources/testharnessreport.js"></script>
7 <script src=
"../media-file.js"></script>
12 function addtrack_test(tagName
, src
, label
)
14 function onTrackListEvent(actualEventList
, e
)
16 actualEventList
.push(e
.type
);
18 if (e
.type
== "addtrack") {
19 assert_equals(e
.track
, e
.target
[0], "Track property matches first track in list.");
23 function setupTrackListHandlers(t
, trackList
, actualEventList
)
25 trackList
.addEventListener("addtrack", t
.step_func(onTrackListEvent
.bind(this, actualEventList
)));
26 trackList
.addEventListener("change", t
.step_func(onTrackListEvent
.bind(this, actualEventList
)));
27 trackList
.addEventListener("removetrack", t
.step_func(onTrackListEvent
.bind(this, actualEventList
)));
30 async_test(function(t
)
32 var e
= document
.createElement(tagName
);
35 var expectedEvents
= ["addtrack"];
36 var actualAudioEvents
= [];
37 var actualVideoEvents
= [];
38 setupTrackListHandlers(t
, e
.audioTracks
, actualAudioEvents
, "audioTracks events");
39 setupTrackListHandlers(t
, e
.videoTracks
, actualVideoEvents
, "videoTracks events");
43 e
.addEventListener("loadedmetadata", t
.step_func(function()
45 assert_array_equals(actualAudioEvents
, expectedEvents
);
47 if (e
.videoTracks
.length
> 0) {
48 assert_equals(label
, "audio-video");
49 assert_array_equals(actualVideoEvents
, expectedEvents
);
51 assert_equals(label
, "audio-only");
52 assert_equals(actualVideoEvents
.length
, 0);
57 }, tagName
+ " : " + label
);
60 addtrack_test("audio", findMediaFile("audio", "../content/test"), "audio-only");
61 addtrack_test("audio", findMediaFile("video", "../content/test"), "audio-video");
62 addtrack_test("video", findMediaFile("audio", "../content/test"), "audio-only");
63 addtrack_test("video", findMediaFile("video", "../content/test"), "audio-video");