tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_texttrack_mode_change_during_loading.html (2398B)


      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.
     17 */
     18 async function startTest() {
     19  const video = createVideo();
     20  const trackElement = createAndAppendtrackElemententToVideo(video);
     21 
     22  await changeTrackModeDuringLoading(trackElement);
     23  await waitUntilTrackLoaded(trackElement);
     24 
     25  removeNodeAndSource(video);
     26  SimpleTest.finish();
     27 }
     28 
     29 SimpleTest.waitForExplicitFinish();
     30 SpecialPowers.pushPrefEnv({"set": [["media.webvtt.testing.events", true]]},
     31                            startTest);
     32 
     33 /**
     34 * The following are test helper functions.
     35 */
     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;
     42 }
     43 
     44 function createAndAppendtrackElemententToVideo(video) {
     45  let trackElement = document.createElement("track");
     46  trackElement.default = true;
     47  video.append(trackElement);
     48  return trackElement;
     49 }
     50 
     51 async function changeTrackModeDuringLoading(trackElement) {
     52  info(`set src to start loading`);
     53  trackElement.src = "basic.vtt";
     54 
     55  info(`wait until starting loading resource.`);
     56  await once(trackElement, "mozStartedLoadingTextTrack");
     57 
     58  info(`changeing track's mode during loading should not cause loading failed.`);
     59  trackElement.onerror = () => {
     60    ok(false, `Should not get error event!`);
     61  }
     62  trackElement.track.mode = "hidden";
     63 }
     64 
     65 async function waitUntilTrackLoaded(trackElement) {
     66  if (trackElement.readyState != 2) {
     67    info(`wait until the track finishes loading`);
     68    await once(trackElement, "load");
     69  }
     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.");
     72 }
     73 </script>
     74 </body>
     75 </html>