summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasource/test/test_LiveSeekable.html
blob: f48852f6af989fe34cb757596d3d50649ac11ede (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE HTML>
<html>
<head>
  <title>MSE: live seekable range</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="mediasource.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();

runWithMSE(async (ms, v) => {
  await once(ms, "sourceopen");
  const sb = ms.addSourceBuffer("video/webm");

  // Load data with a +2 offset so that we can distinguish buffered range start
  // and seekable range start.
  sb.timestampOffset = 2;
  const p = once(v, "loadedmetadata");
  await fetchAndLoad(sb, "seek", [""], ".webm");
  await p;
  ms.duration = Infinity;
  sb.abort();
  is(sb.buffered.length, 1, "continuous buffered range");
  is(sb.buffered.start(0), 2, "buffered range start at timestamp offset");
  is(sb.buffered.end(0), 6.001, "buffered range end at original duration + timestamp offset");
  is(v.seekable.length, 1, "continuous seekable range");
  is(v.seekable.start(0), 0, "seekable range start at 0");
  is(v.seekable.end(0), sb.buffered.end(0), "seekable range end at buffered end");

  // LiveSeekableRange.start < buffered.start
  ms.setLiveSeekableRange(1, 5);
  is(v.seekable.length, 1, "continuous seekable range");
  is(v.seekable.start(0), 1, "seekable range start at live range start");
  is(v.seekable.end(0), sb.buffered.end(0), "seekable range end at buffered end");

  ms.clearLiveSeekableRange();
  is(v.seekable.length, 1, "continuous seekable range");
  is(v.seekable.start(0), 0, "seekable range start at 0");
  is(v.seekable.end(0), sb.buffered.end(0), "seekable range end at buffered end");

  // LiveSeekableRange.end > buffered.end
  ms.setLiveSeekableRange(1, 8);
  is(v.seekable.start(0), 1, "seekable range start at live range start");
  is(v.seekable.end(0), 8, "seekable range end at live range end");

  // LiveSeekableRange.start > buffered.start
  // LiveSeekableRange.end < buffered.end
  ms.setLiveSeekableRange(3, 5);
  is(v.seekable.start(0), sb.buffered.start(0), "seekable range start at buffered start");
  is(v.seekable.end(0), sb.buffered.end(0), "seekable range end at live range end");

  // LiveSeekableRange.start > buffered.end
  ms.setLiveSeekableRange(8, 10);
  is(v.seekable.start(0), sb.buffered.start(0), "seekable range start at buffered start");
  is(v.seekable.end(0), 10, "seekable range end at live range end");

  // LiveSeekableRange.end < buffered.start
  ms.setLiveSeekableRange(0, 2);
  is(v.seekable.start(0), 0, "seekable range start at live range start");
  is(v.seekable.end(0), sb.buffered.end(0), "seekable range end at buffered end");

  must_throw(() => ms.setLiveSeekableRange(2, 0),
             "must thow if start > end",
             "TypeError");

  must_throw(() => ms.setLiveSeekableRange(2, 0),
             "must thow if start > end",
             "TypeError");

  ms.setLiveSeekableRange(0, 1e300);
  is(v.seekable.start(0), 0, "seekable range start at live range start");
  is(v.seekable.end(0), 1e300, "seekable range end at specified time");

  SimpleTest.finish();
});

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