OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
5 | 5 |
6 <script src=../media-file.js></script> | 6 <script src="../media-file.js"></script> |
7 <script src=../video-test.js></script> | 7 <script src="../video-test.js"></script> |
| 8 <script src="../../resources/testharness.js"></script> |
| 9 <script src="../../resources/testharnessreport.js"></script> |
| 10 </head> |
| 11 <body> |
8 <script> | 12 <script> |
| 13 async_test(function(test) |
| 14 { |
| 15 var video = document.createElement("video"); |
| 16 var track; |
9 | 17 |
10 var trackElement; | 18 function trackRemoved() |
11 var track; | 19 { |
| 20 assert_equals(event.target, video.textTracks); |
| 21 assert_equals(event instanceof window.TrackEvent, true); |
| 22 assert_equals(event.track, track); |
| 23 test.done(); |
| 24 } |
12 | 25 |
13 function trackRemoved() | 26 var trackElement = document.createElement('track'); |
14 { | 27 video.appendChild(trackElement); |
15 consoleWrite("EVENT(" + event.type + ")"); | |
16 | 28 |
17 testExpected("event.target", video.textTracks); | 29 trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt'; |
18 testExpected("event instanceof window.TrackEvent", true); | 30 trackElement.track.mode = 'hidden'; |
19 testExpected("event.track", track); | |
20 | 31 |
21 consoleWrite(""); | 32 assert_equals(video.textTracks.length, 1); |
22 endTest(); | |
23 } | |
24 | |
25 function start() | |
26 { | |
27 findMediaElement(); | |
28 | |
29 consoleWrite("** Test a TextTrack created for a <track> el
ement."); | |
30 run("trackElement = document.createElement('track')"); | |
31 run("video.appendChild(trackElement)"); | |
32 | |
33 run("trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt'"
); | |
34 run("trackElement.track.mode = 'hidden'"); | |
35 testExpected("video.textTracks.length", 1); | |
36 | 33 |
37 track = video.textTracks[0]; | 34 track = video.textTracks[0]; |
38 video.removeChild(trackElement); | 35 video.removeChild(trackElement); |
| 36 video.textTracks.addEventListener("removetrack", test.step_func(
trackRemoved)); |
| 37 }, "Tests that the 'removetrack' event is fired when an out-of-band
TextTrack is removed."); |
39 | 38 |
40 video.textTracks.addEventListener("removetrack", trackRemoved); | 39 async_test(function(test) |
41 } | 40 { |
| 41 var video = document.createElement("video"); |
| 42 |
| 43 // Create an out-of-band text track by adding a track element. |
| 44 var trackElement = document.createElement('track'); |
| 45 |
| 46 trackElement.addEventListener("error", test.step_func(function() |
| 47 { |
| 48 assert_unreached("'error' event on track element should not
fire.") |
| 49 })); |
| 50 |
| 51 video.appendChild(trackElement); |
| 52 trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt'; |
| 53 trackElement.track.mode = 'hidden'; |
| 54 |
| 55 assert_equals(video.textTracks.length, 1); |
| 56 var outOfBandTrack = video.textTracks[0]; |
| 57 |
| 58 // Load a media file with an inband text track. |
| 59 var inbandTrack = null; |
| 60 var url = "../content/test-vp8-vorbis-webvtt.webm" |
| 61 |
| 62 var firstAddTrackHandler = test.step_func(function() |
| 63 { |
| 64 assert_equals(event.target, video.textTracks); |
| 65 assert_equals(event instanceof window.TrackEvent, true); |
| 66 if (event.track == outOfBandTrack) { |
| 67 return; |
| 68 } |
| 69 |
| 70 assert_equals(inbandTrack, null); |
| 71 assert_equals(video.textTracks.length, 2); |
| 72 assert_equals(event.track, video.textTracks[1]); |
| 73 inbandTrack = event.track; |
| 74 |
| 75 video.textTracks.removeEventListener("addtrack", firstAddTra
ckHandler); |
| 76 |
| 77 // Clear .src to force the inband track to get destroyed. |
| 78 video.src = ""; |
| 79 |
| 80 // Verify that the inband track was removed. |
| 81 assert_not_equals(inbandTrack, null); |
| 82 assert_equals(video.textTracks.length, 1); |
| 83 assert_equals(video.textTracks[0], outOfBandTrack); |
| 84 |
| 85 // Load the URL again to trigger another 'addtrack' event to
make sure |
| 86 // no 'removetrack' event was queued. |
| 87 video.src = url; |
| 88 video.textTracks.addEventListener("addtrack", test.step_func
(function() |
| 89 { |
| 90 assert_equals(video.textTracks.length, 2); |
| 91 test.done(); |
| 92 })); |
| 93 }); |
| 94 video.textTracks.addEventListener("addtrack", firstAddTrackHandl
er); |
| 95 |
| 96 video.textTracks.addEventListener("removetrack", test.step_func(
function() |
| 97 { |
| 98 assert_unreached("'removetrack' event should not fire.") |
| 99 })); |
| 100 |
| 101 video.src = url; |
| 102 }, "Tests that the 'removetrack' event is NOT fired for inband TextT
rack on a failed load."); |
42 | 103 |
43 </script> | 104 </script> |
44 </head> | 105 <div id="log"></div> |
45 <body onload="start()"> | |
46 <p>Tests that the 'removetrack' event is fired when a TextTrack is remov
ed.</p> | |
47 <video> | |
48 </video> | |
49 </body> | 106 </body> |
50 </html> | 107 </html> |
OLD | NEW |