4 <title>WebVTT : changing track's mode during loading
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <script src=
"manifest.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
10 <script class=
"testbody" type=
"text/javascript">
12 * This test is to ensure that we won't get `error` event when we change track's
13 * mode during loading. In this test, track element starts loading after setting
14 * the src and we would start another load later just after the channel which is
15 * used to fetch data starts. The second load is triggered by mode changes, and
16 * it should stop the prevous load and won't generate any error.
18 async function startTest() {
19 const video = createVideo();
20 const trackElement = createAndAppendtrackElemententToVideo(video);
22 await changeTrackModeDuringLoading(trackElement);
23 await waitUntilTrackLoaded(trackElement);
25 removeNodeAndSource(video);
29 SimpleTest.waitForExplicitFinish();
30 SpecialPowers.pushPrefEnv({
"set": [[
"media.webvtt.testing.events", true]]},
34 * The following are test helper functions.
36 function createVideo() {
38 let video = document.createElement(
"video");
39 video.src =
"gizmo.mp4";
40 document.body.appendChild(video);
44 function createAndAppendtrackElemententToVideo(video) {
45 let trackElement = document.createElement(
"track");
46 trackElement.default = true;
47 video.append(trackElement);
51 async function changeTrackModeDuringLoading(trackElement) {
52 info(`set src to start loading`);
53 trackElement.src =
"basic.vtt";
55 info(`wait until starting loading resource.`);
56 await once(trackElement,
"mozStartedLoadingTextTrack");
58 info(`changeing track's mode during loading should not cause loading failed.`);
59 trackElement.onerror = () =
> {
60 ok(false, `Should not get error event!`);
62 trackElement.track.mode =
"hidden";
65 async function waitUntilTrackLoaded(trackElement) {
66 if (trackElement.readyState !=
2) {
67 info(`wait until the track finishes loading`);
68 await once(trackElement,
"load");
70 is(trackElement.readyState,
2,
"Track::ReadyState should be set to LOADED.");
71 is(trackElement.track.cues.length,
6,
"Cue list length should be 6.");