OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <title>AudioTrackList & VideoTrackList tests</title> |
| 5 <script src="../resources/testharness.js"></script> |
| 6 <script src="../resources/testharnessreport.js"></script> |
| 7 <script src="media-file.js"></script> |
| 8 </head> |
| 9 <body> |
| 10 <div id="log"></div> |
| 11 <script> |
| 12 function basic_tracklist_test(tagName, src, label) |
| 13 { |
| 14 function onTrackListEvent(actualEventList, e) |
| 15 { |
| 16 actualEventList.push(e.type); |
| 17 |
| 18 if (e.type == "addtrack") { |
| 19 assert_equals(e.track, e.target[0], "Track property matc
hes first track in list."); |
| 20 } |
| 21 } |
| 22 |
| 23 function setupTrackListHandlers(t, trackList, actualEventList) |
| 24 { |
| 25 trackList.addEventListener('addtrack', t.step_func(onTrackLi
stEvent.bind(this, actualEventList))); |
| 26 trackList.addEventListener('change', t.step_func(onTrackList
Event.bind(this, actualEventList))); |
| 27 trackList.addEventListener('removetrack', t.step_func(onTrac
kListEvent.bind(this, actualEventList))); |
| 28 } |
| 29 |
| 30 async_test(function(t) |
| 31 { |
| 32 var e = document.createElement(tagName); |
| 33 e.src = src; |
| 34 e.preload = "none"; |
| 35 |
| 36 var expectedEvents = ['addtrack', 'change']; |
| 37 var actualAudioEvents = []; |
| 38 var actualVideoEvents = []; |
| 39 setupTrackListHandlers(t, e.audioTracks, actualAudioEvents,
"audioTracks events"); |
| 40 setupTrackListHandlers(t, e.videoTracks, actualVideoEvents,
"videoTracks events"); |
| 41 |
| 42 e.load(); |
| 43 |
| 44 e.addEventListener('loadedmetadata', t.step_func(function() |
| 45 { |
| 46 assert_array_equals(actualAudioEvents, expectedEvents); |
| 47 |
| 48 if (e.videoTracks.length > 0) { |
| 49 assert_equals(label, "audio-video"); |
| 50 assert_array_equals(actualVideoEvents, expectedEvent
s); |
| 51 } else { |
| 52 assert_equals(label, "audio-only"); |
| 53 assert_equals(actualVideoEvents.length, 0); |
| 54 } |
| 55 |
| 56 t.done(); |
| 57 })); |
| 58 }, tagName + " : " + label); |
| 59 } |
| 60 |
| 61 basic_tracklist_test('audio', findMediaFile('audio', 'content/test')
, "audio-only"); |
| 62 basic_tracklist_test('audio', findMediaFile('video', 'content/test')
, "audio-video"); |
| 63 basic_tracklist_test('video', findMediaFile('audio', 'content/test')
, "audio-only"); |
| 64 basic_tracklist_test('video', findMediaFile('video', 'content/test')
, "audio-video"); |
| 65 |
| 66 async_test(function(t) |
| 67 { |
| 68 var e = document.createElement('video'); |
| 69 e.src = findMediaFile('video', 'content/test'); |
| 70 e.preload = "none"; |
| 71 var expectedEvents = ['addtrack', 'change']; |
| 72 var actualAudioEvents = []; |
| 73 var actualVideoEvents = []; |
| 74 |
| 75 e.load(); |
| 76 |
| 77 e.addEventListener('loadedmetadata', t.step_func(function() |
| 78 { |
| 79 assert_equals(e.audioTracks.length, 1, "audioTracks.length")
; |
| 80 assert_equals(e.videoTracks.length, 1, "videoTracks.length")
; |
| 81 |
| 82 // Clear the source and verify that the track lists are clea
red. |
| 83 e.src = ""; |
| 84 e.load(); |
| 85 |
| 86 assert_equals(e.audioTracks.length, 0, "audioTracks.length")
; |
| 87 assert_equals(e.videoTracks.length, 0, "videoTracks.length")
; |
| 88 t.done(); |
| 89 })); |
| 90 }, "Verify audioTracks & videoTracks are cleared."); |
| 91 </script> |
| 92 </body> |
| 93 </html> |
OLD | NEW |