OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>AudioTrackList & VideoTrackList addtrack event</title> | 4 <title>AudioTrackList & VideoTrackList addtrack event</title> |
5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
7 <script src="../media-file.js"></script> | 7 <script src="../media-file.js"></script> |
8 </head> | 8 </head> |
9 <body> | 9 <body> |
10 <div id="log"></div> | |
11 <script> | 10 <script> |
12 function addtrack_test(tagName, src, label) | 11 function addtrack_test(tagName, src, label) |
13 { | 12 { |
14 function onTrackListEvent(actualEventList, e) | 13 function onTrackListEvent(actualEventList, e) |
15 { | 14 { |
16 actualEventList.push(e.type); | 15 actualEventList.push(e.type); |
17 | 16 |
18 if (e.type == "addtrack") { | 17 if (e.type == "addtrack") { |
19 assert_equals(e.track, e.target[0], "Track property matc
hes first track in list."); | 18 assert_equals(e.track, e.target[0], "Track property matc
hes first track in list."); |
20 } | 19 } |
21 } | 20 } |
22 | 21 |
23 function setupTrackListHandlers(t, trackList, actualEventList) | 22 function setupTrackListHandlers(t, trackList, actualEventList) |
24 { | 23 { |
25 trackList.addEventListener("addtrack", t.step_func(onTrackLi
stEvent.bind(this, actualEventList))); | 24 trackList.addEventListener("addtrack", t.step_func(onTrackLi
stEvent.bind(this, actualEventList))); |
26 trackList.addEventListener("change", t.step_func(onTrackList
Event.bind(this, actualEventList))); | 25 trackList.addEventListener("change", t.step_func(onTrackList
Event.bind(this, actualEventList))); |
27 trackList.addEventListener("removetrack", t.step_func(onTrac
kListEvent.bind(this, actualEventList))); | 26 trackList.addEventListener("removetrack", t.step_func(onTrac
kListEvent.bind(this, actualEventList))); |
28 } | 27 } |
29 | 28 |
30 async_test(function(t) | 29 async_test(function(t) |
31 { | 30 { |
32 var e = document.createElement(tagName); | 31 var media = document.createElement(tagName); |
33 e.src = src; | 32 media.src = src; |
34 | 33 |
35 var expectedEvents = ["addtrack"]; | 34 var expectedEvents = ["addtrack"]; |
36 var actualAudioEvents = []; | 35 var actualAudioEvents = []; |
37 var actualVideoEvents = []; | 36 var actualVideoEvents = []; |
38 setupTrackListHandlers(t, e.audioTracks, actualAudioEvents,
"audioTracks events"); | 37 setupTrackListHandlers(t, media.audioTracks, actualAudioEven
ts, "audioTracks events"); |
39 setupTrackListHandlers(t, e.videoTracks, actualVideoEvents,
"videoTracks events"); | 38 setupTrackListHandlers(t, media.videoTracks, actualVideoEven
ts, "videoTracks events"); |
40 | 39 |
41 e.load(); | 40 media.load(); |
42 | 41 |
43 e.addEventListener("loadedmetadata", t.step_func(function() | 42 media.addEventListener("loadedmetadata", t.step_func_done(fu
nction() |
44 { | 43 { |
45 assert_array_equals(actualAudioEvents, expectedEvents); | 44 assert_array_equals(actualAudioEvents, expectedEvents); |
46 | 45 |
47 if (e.videoTracks.length > 0) { | 46 if (media.videoTracks.length > 0) { |
48 assert_equals(label, "audio-video"); | 47 assert_equals(label, "audio-video"); |
49 assert_array_equals(actualVideoEvents, expectedEvent
s); | 48 assert_array_equals(actualVideoEvents, expectedEvent
s); |
50 } else { | 49 } else { |
51 assert_equals(label, "audio-only"); | 50 assert_equals(label, "audio-only"); |
52 assert_equals(actualVideoEvents.length, 0); | 51 assert_equals(actualVideoEvents.length, 0); |
53 } | 52 } |
54 | |
55 t.done(); | |
56 })); | 53 })); |
57 }, tagName + " : " + label); | 54 }, tagName + " : " + label); |
58 } | 55 } |
59 | 56 |
60 addtrack_test("audio", findMediaFile("audio", "../content/test"), "a
udio-only"); | 57 addtrack_test("audio", findMediaFile("audio", "../content/test"), "a
udio-only"); |
61 addtrack_test("audio", findMediaFile("video", "../content/test"), "a
udio-video"); | 58 addtrack_test("audio", findMediaFile("video", "../content/test"), "a
udio-video"); |
62 addtrack_test("video", findMediaFile("audio", "../content/test"), "a
udio-only"); | 59 addtrack_test("video", findMediaFile("audio", "../content/test"), "a
udio-only"); |
63 addtrack_test("video", findMediaFile("video", "../content/test"), "a
udio-video"); | 60 addtrack_test("video", findMediaFile("video", "../content/test"), "a
udio-video"); |
64 </script> | 61 </script> |
65 </body> | 62 </body> |
66 </html> | 63 </html> |
OLD | NEW |