summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-streams/MediaStream-clone.https.html
blob: 0fe6f3498b4d2e6041045a7b503e4fdfb9c461e0 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!doctype html>
<html>
<head>
<title>MediaStream and MediaStreamTrack clone()</title>
<link rel="help" href="https://w3c.github.io/mediacapture-main/#dom-mediastream-clone">
<link rel="help" href="https://w3c.github.io/mediacapture-main/#dom-mediastreamtrack-clone">
</head>
<body>
<p class="instructions">When prompted, accept to give permission to use your audio and video devices.</p>
<h1 class="instructions">Description</h1>
<p class="instructions">This test checks that cloning MediaStreams and MediaStreamTracks works as expected.</p>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src=permission-helper.js></script>
<script>

promise_test(async t => {
  await setMediaPermission();
  const stream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});
  assert_equals(stream.getAudioTracks().length, 1);
  assert_equals(stream.getVideoTracks().length, 1);

  const clone1 = stream.clone();
  assert_equals(clone1.getAudioTracks().length, 1);
  assert_equals(clone1.getVideoTracks().length, 1);
  assert_not_equals(stream.getAudioTracks()[0].id, clone1.getAudioTracks()[0].id);
  assert_not_equals(stream.getVideoTracks()[0].id, clone1.getVideoTracks()[0].id);

  stream.getTracks().forEach(track => track.stop());
  assert_false(stream.active);
  assert_equals(stream.getAudioTracks()[0].readyState, "ended");
  assert_equals(stream.getVideoTracks()[0].readyState, "ended");
  assert_true(clone1.active);
  assert_equals(clone1.getAudioTracks()[0].readyState, "live");
  assert_equals(clone1.getVideoTracks()[0].readyState, "live");

  clone1.getAudioTracks()[0].stop();
  assert_true(clone1.active);
  assert_equals(clone1.getAudioTracks()[0].readyState, "ended");
  assert_equals(clone1.getVideoTracks()[0].readyState, "live");

  const clone2 = clone1.clone();
  assert_true(clone2.active);
  assert_equals(clone2.getAudioTracks()[0].readyState, "ended");
  assert_equals(clone2.getVideoTracks()[0].readyState, "live");

  clone1.getVideoTracks()[0].stop();
  clone2.getVideoTracks()[0].stop();

  const clone3 = clone2.clone();
  assert_false(clone3.active);
  assert_equals(clone3.getAudioTracks()[0].readyState, "ended");
  assert_equals(clone3.getVideoTracks()[0].readyState, "ended");
  assert_not_equals(clone1.getAudioTracks()[0].id, clone2.getAudioTracks()[0].id);
  assert_not_equals(clone1.getVideoTracks()[0].id, clone2.getVideoTracks()[0].id);
  assert_not_equals(clone2.getAudioTracks()[0].id, clone3.getAudioTracks()[0].id);
  assert_not_equals(clone2.getVideoTracks()[0].id, clone3.getVideoTracks()[0].id);
  assert_not_equals(clone1.getAudioTracks()[0].id, clone3.getAudioTracks()[0].id);
  assert_not_equals(clone1.getVideoTracks()[0].id, clone3.getVideoTracks()[0].id);
}, "Tests that cloning MediaStream objects works as expected");

promise_test(async t => {
  const stream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});
  assert_equals(stream.getAudioTracks().length, 1);
  assert_equals(stream.getVideoTracks().length, 1);
  assert_equals(stream.getAudioTracks()[0].readyState, "live");
  assert_equals(stream.getVideoTracks()[0].readyState, "live");
  assert_true(stream.active);

  const audio_clone = stream.getAudioTracks()[0].clone();
  const video_clone = stream.getVideoTracks()[0].clone();
  assert_equals(audio_clone.readyState, "live");
  assert_equals(video_clone.readyState, "live");
  assert_not_equals(stream.getAudioTracks()[0].id, audio_clone.id);
  assert_not_equals(stream.getVideoTracks()[0].id, video_clone.id);

  stream.getTracks().forEach(track => track.stop());
  assert_false(stream.active);
  assert_equals(stream.getAudioTracks()[0].readyState, "ended");
  assert_equals(stream.getVideoTracks()[0].readyState, "ended");
  assert_equals(audio_clone.readyState, "live");
  assert_equals(video_clone.readyState, "live");

  stream.addTrack(audio_clone);
  stream.addTrack(video_clone);
  assert_true(stream.active);

  stream.getTracks().forEach(track => track.stop());
  assert_false(stream.active);
  assert_equals(audio_clone.readyState, "ended");
  assert_equals(video_clone.readyState, "ended");
}, "Tests that cloning MediaStreamTrack objects works as expected");

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