Bug 1943761 - Add class alignment to the mozsearch analysis file. r=asuth
[gecko.git] / dom / media / webvtt / test / mochitest / test_texttrack_mode_change_during_loading.html
blob974f452092387ddc9e781ec6d9192689b50418f8
1 <!DOCTYPE HTML>
2 <html>
3 <head>
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"/>
8 </head>
9 <body>
10 <script class="testbody" type="text/javascript">
11 /**
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);
26 SimpleTest.finish();
29 SimpleTest.waitForExplicitFinish();
30 SpecialPowers.pushPrefEnv({"set": [["media.webvtt.testing.events", true]]},
31 startTest);
33 /**
34 * The following are test helper functions.
36 function createVideo() {
37 info(`create video`);
38 let video = document.createElement("video");
39 video.src = "gizmo.mp4";
40 document.body.appendChild(video);
41 return video;
44 function createAndAppendtrackElemententToVideo(video) {
45 let trackElement = document.createElement("track");
46 trackElement.default = true;
47 video.append(trackElement);
48 return 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.");
73 </script>
74 </body>
75 </html>