| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| |
| <script src="../media-file.js"></script> |
| <script src="../video-test.js"></script> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| </head> |
| <body> |
| <script> |
| async_test(function(test) |
| { |
| var video = document.createElement("video"); |
| var track; |
| |
| function trackRemoved() |
| { |
| assert_equals(event.target, video.textTracks); |
| assert_equals(event instanceof window.TrackEvent, true); |
| assert_equals(event.track, track); |
| test.done(); |
| } |
| |
| var trackElement = document.createElement('track'); |
| video.appendChild(trackElement); |
| |
| trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt'; |
| trackElement.track.mode = 'hidden'; |
| |
| assert_equals(video.textTracks.length, 1); |
| |
| track = video.textTracks[0]; |
| video.removeChild(trackElement); |
| video.textTracks.addEventListener("removetrack", test.step_func(trackRemoved)); |
| }, "Tests that the 'removetrack' event is fired when an out-of-band TextTrack is removed."); |
| |
| async_test(function(test) |
| { |
| var video = document.createElement("video"); |
| |
| // Create an out-of-band text track by adding a track element. |
| var trackElement = document.createElement('track'); |
| |
| trackElement.addEventListener("error", test.step_func(function() |
| { |
| assert_unreached("'error' event on track element should not fire.") |
| })); |
| |
| video.appendChild(trackElement); |
| trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt'; |
| trackElement.track.mode = 'hidden'; |
| |
| assert_equals(video.textTracks.length, 1); |
| var outOfBandTrack = video.textTracks[0]; |
| |
| // Load a media file with an inband text track. |
| var inbandTrack = null; |
| var url = "../content/counting-captioned.mov" |
| |
| var firstAddTrackHandler = test.step_func(function() |
| { |
| assert_equals(event.target, video.textTracks); |
| assert_equals(event instanceof window.TrackEvent, true); |
| if (event.track == outOfBandTrack) { |
| return; |
| } |
| |
| assert_equals(inbandTrack, null); |
| assert_equals(video.textTracks.length, 2); |
| assert_equals(event.track, video.textTracks[1]); |
| inbandTrack = event.track; |
| |
| video.textTracks.removeEventListener("addtrack", firstAddTrackHandler); |
| |
| // Clear .src to force the inband track to get destroyed. |
| video.src = ""; |
| |
| // Verify that the inband track was removed. |
| assert_not_equals(inbandTrack, null); |
| assert_equals(video.textTracks.length, 1); |
| assert_equals(video.textTracks[0], outOfBandTrack); |
| |
| // Load the URL again to trigger another 'addtrack' event to make sure |
| // no 'removetrack' event was queued. |
| video.src = url; |
| video.textTracks.addEventListener("addtrack", test.step_func(function() |
| { |
| assert_equals(video.textTracks.length, 2); |
| test.done(); |
| })); |
| }); |
| video.textTracks.addEventListener("addtrack", firstAddTrackHandler); |
| |
| video.textTracks.addEventListener("removetrack", test.step_func(function() |
| { |
| assert_unreached("'removetrack' event should not fire.") |
| })); |
| |
| video.src = url; |
| }, "Tests that the 'removetrack' event is NOT fired for inband TextTrack on a failed load."); |
| |
| </script> |
| <div id="log"></div> |
| </body> |
| </html> |