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 == "change") |
| 19 return; |
| 20 |
| 21 if (e.type == "addtrack") { |
| 22 // Verify that the track property matches the first trac
k in the list. |
| 23 assert_equals(e.track, e.target[0]); |
| 24 } |
| 25 } |
| 26 |
| 27 function setupTrackListHandlers(t, trackList, actualEventList) |
| 28 { |
| 29 trackList.addEventListener('addtrack', t.step_func(onTrackLi
stEvent.bind(this, actualEventList))); |
| 30 trackList.addEventListener('change', t.step_func(onTrackList
Event.bind(this, actualEventList))); |
| 31 trackList.addEventListener('removetrack', t.step_func(onTrac
kListEvent.bind(this, actualEventList))); |
| 32 } |
| 33 |
| 34 async_test(function(t) |
| 35 { |
| 36 var e = document.createElement(tagName); |
| 37 e.src = src; |
| 38 e.preload = "none"; |
| 39 |
| 40 var expectedEvents = ['addtrack', 'change']; |
| 41 var actualAudioEvents = []; |
| 42 var actualVideoEvents = []; |
| 43 setupTrackListHandlers(t, e.audioTracks, actualAudioEvents,
"audioTracks events"); |
| 44 setupTrackListHandlers(t, e.videoTracks, actualVideoEvents,
"videoTracks events"); |
| 45 |
| 46 e.load(); |
| 47 |
| 48 e.addEventListener('loadedmetadata', t.step_func(function() |
| 49 { |
| 50 assert_array_equals(actualAudioEvents, expectedEvents); |
| 51 |
| 52 if (e.videoTracks.length > 0) { |
| 53 assert_equals(label, "audio-video"); |
| 54 assert_array_equals(actualVideoEvents, expectedEvent
s); |
| 55 } else { |
| 56 assert_equals(label, "audio-only"); |
| 57 assert_equals(actualVideoEvents.length, 0); |
| 58 } |
| 59 |
| 60 t.done(); |
| 61 })); |
| 62 }, tagName + " : " + label); |
| 63 } |
| 64 |
| 65 basic_tracklist_test('audio', findMediaFile('audio', 'content/test')
, "audio-only"); |
| 66 basic_tracklist_test('audio', findMediaFile('video', 'content/test')
, "audio-video"); |
| 67 basic_tracklist_test('video', findMediaFile('audio', 'content/test')
, "audio-only"); |
| 68 basic_tracklist_test('video', findMediaFile('video', 'content/test')
, "audio-video"); |
| 69 |
| 70 async_test(function(t) |
| 71 { |
| 72 var e = document.createElement('video'); |
| 73 e.src = findMediaFile('video', 'content/test'); |
| 74 e.preload = "none"; |
| 75 var expectedEvents = ['addtrack', 'change']; |
| 76 var actualAudioEvents = []; |
| 77 var actualVideoEvents = []; |
| 78 |
| 79 e.load(); |
| 80 |
| 81 e.addEventListener('loadedmetadata', t.step_func(function() |
| 82 { |
| 83 assert_equals(e.audioTracks.length, 1, "audioTracks.length")
; |
| 84 assert_equals(e.videoTracks.length, 1, "videoTracks.length")
; |
| 85 |
| 86 // Clear the source and verify that the track lists are clea
red. |
| 87 e.src = ""; |
| 88 e.load(); |
| 89 |
| 90 assert_equals(e.audioTracks.length, 0, "audioTracks.length")
; |
| 91 assert_equals(e.videoTracks.length, 0, "videoTracks.length")
; |
| 92 t.done(); |
| 93 })); |
| 94 }, "Verify audioTracks & videoTracks are cleared."); |
| 95 </script> |
| 96 </body> |
| 97 </html> |
OLD | NEW |