summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_seamless_looping_media_element_state.html
blob: c94de0491293760ba85a4062bf8006fc0ea40a60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE HTML>
<html>
<head>
<title>Seamless looping media element state</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript" src="manifest.js"></script>
</head>
<script type="application/javascript">

/**
 * This test aims to check if the media element would change its ready state
 * under `HAVE_CURRENT_DATA` when the seamless looping is performed. Because
 * during seamless looping, we should always have current frame.
 */
add_task(async function testSeamlessLoopingMediaElementState() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["media.seamless-looping-video", true],
    ],
  });

  info(`create video`);
  let video = document.createElement('video');
  video.loop = true;
  video.src = "gizmo-short.mp4";
  document.body.appendChild(video);
  await video.play();

  info(`test seamless looping multiples times`);
  let MAX_LOOPING_COUNT = 10;
  for (let count = 0; count < MAX_LOOPING_COUNT; count++) {
    await once(video, "seeking");
    // If the video looping is not seamless, when playback reaches to the end,
    // MDSM would trigger a seek in order to get the new frame from the start
    // position. That would notify the media element that the status of the next
    // frame is not available now due to seeking (NEXT_FRAME_UNAVAILABLE_SEEKING)
    // and causes the media element dispatching `waiting` event.
    video.onwaiting = () => {
      ok(false, "should not get waiting event");
    }
    await once(video, "seeked");
    video.onwaiting = null;
    ok(true, `the round ${count} of the seamless looping succeeds`);
  }
});

</script>
<body>
</body>
</html>