summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_seamless_looping_seek_current_time.html
blob: 888e5437c409f6acd19cc50472a187678c85f2b4 (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
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE HTML>
<html>
<head>
<title>Seamless looping current time after seek</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 is used to ensure that the playback position won't be reset to ZERO
 * incorrectly when performing seek on a looping media.
 */
add_task(async function testSeekVideoOnlyPlayback() {
  info(`create and play a media which contains only video track`);
  let video = createLoopingMedia("video", "gizmo-noaudio.webm");
  await video.play();
  await assertSeekingForwardShouldIncreaseCurrentTime(video);
  removeNodeAndSource(video);
});

add_task(async function testSeekAudioOnlyPlayback() {
  info(`create and play a media which contains only audio track`);
  let audio = createLoopingMedia("audio", "flac-s24.flac");
  await audio.play();
  await assertSeekingForwardShouldIncreaseCurrentTime(audio);
  removeNodeAndSource(audio);
});

add_task(async function testSeekBothTracksPlayback() {
  info(`create and play a media which contains both tracks`);
  let video = createLoopingMedia("video", "gizmo.mp4");
  await video.play();
  await assertSeekingForwardShouldIncreaseCurrentTime(video);
  removeNodeAndSource(video);
});

// Following are helper functions
function createLoopingMedia(type, src) {
  let media = document.createElement(type);
  media.loop = true;
  media.src = src;
  document.body.appendChild(media);
  return media;
}

async function assertSeekingForwardShouldIncreaseCurrentTime(media) {
  const currentTimeBeforeSeek = media.currentTime;
  const target =  media.duration / 2;
  media.currentTime = target;
  await once(media, "seeked");
  const currentTimeAfterSeek = media.currentTime;
  ok(currentTimeAfterSeek > currentTimeBeforeSeek,
    `media current time should keep going forward (target=${target}, ` +
    `currentTime=${currentTimeBeforeSeek} -> ${currentTimeAfterSeek})`);
}

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