summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_streams_element_capture_twice.html
blob: 0e30be18019a02dc2419a7cd6fc689103a012115 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test that capturing a media element, then reloading and capturing again, works</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>
<body>
<video id="v"></video>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();

const v = document.getElementById('v');

function dumpEvent(event) {
  const video = event.target;
  info(video.name + " GOT EVENT " + event.type +
       " currentTime=" + video.currentTime +
       " paused=" + video.paused +
       " ended=" + video.ended +
       " readyState=" + video.readyState);
}

const events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"];
for (let i = 0; i < events.length; ++i) {
  v.addEventListener(events[i], dumpEvent);
}

async function startTest(src) {
  v.preload = "metadata";
  v.src = src;
  await new Promise(r => v.onloadedmetadata = r);
  const s1 = v.mozCaptureStream();
  const tracks = s1.getTracks();
  is(tracks.length, 2, "Expected total tracks, s1, capture 1");
  is(s1.getAudioTracks().length, 1, "Expected audio tracks, s1, capture 1");
  is(s1.getVideoTracks().length, 1, "Expected video tracks, s1, capture 1");
  is(s1.getAudioTracks()[0].readyState, "live", "Live audio, s1, capture 1");
  is(s1.getVideoTracks()[0].readyState, "live", "Live video, s1, capture 1");

  v.src = null;
  for (let i = 0; i < tracks.length; ++i) {
    await Promise.race(tracks.map(t => new Promise(r => t.onended = r)));
    await new Promise(r => s1.onremovetrack = r);
  }
  is(s1.getTracks().length, 0, "Expected total tracks, s1, metadata 2");

  v.src = src;
  await new Promise(r => v.onloadedmetadata = r);
  is(s1.getTracks().length, 2, "Expected total tracks, s1, metadata 2");
  is(s1.getAudioTracks().length, 1, "Expected audio tracks, s1, metadata 2");
  is(s1.getVideoTracks().length, 1, "Expected video tracks, s1, metadata 2");
  is(s1.getAudioTracks()[0].readyState, "live", "Live audio, s1, metadata 2");
  is(s1.getVideoTracks()[0].readyState, "live", "Live video, s1, metadata 2");

  const s2 = v.mozCaptureStream();
  is(s1.getTracks().length, 2, "Expected total tracks remains, s1, capture 2");
  is(s2.getTracks().length, 2, "Expected total tracks, s2, capture 2");
  is(s2.getAudioTracks().length, 1, "Expected audio tracks, s2, capture 2");
  is(s2.getVideoTracks().length, 1, "Expected video tracks, s2, capture 2");
  is(s2.getAudioTracks()[0].readyState, "live", "Live audio, s2, capture 2");
  is(s2.getVideoTracks()[0].readyState, "live", "Live video, s2, capture 2");
}

(async function() {
  try {
    await startTest("short-video.ogv");
  } catch(e) {
    ok(false, `Caught error: ${e}${e.stack ? '\n' + e.stack : ''}`);
  } finally {
    SimpleTest.finish();
  }
})();
</script>
</pre>
</body>
</html>