summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_getUserMedia_getTrackById.html
blob: 161bf631e31c59002dfe8b5eb325ff230b3952f3 (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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    title: "Basic getTrackById test of gUM stream",
    bug: "1208390",
  });

  runTest(() => {
    var constraints = {audio: true, video: true};
    return getUserMedia(constraints).then(stream => {
      is(stream.getTrackById(""), null,
         "getTrackById of non-matching string should return null");

      let audioTrack = stream.getAudioTracks()[0];
      is(stream.getTrackById(audioTrack.id), audioTrack,
         "getTrackById with matching id should return the track");

      let videoTrack = stream.getVideoTracks()[0];
      is(stream.getTrackById(videoTrack.id), videoTrack,
         "getTrackById with matching id should return the track");

      stream.removeTrack(audioTrack);
      is(stream.getTrackById(audioTrack.id), null,
         "getTrackById with id of removed track should return null");

      let newStream = new MediaStream();
      is(newStream.getTrackById(videoTrack.id), null,
         "getTrackById with id of track in other stream should return null");

      newStream.addTrack(audioTrack);
      is(newStream.getTrackById(audioTrack.id), audioTrack,
         "getTrackByid with matching id should return the track");

      newStream.addTrack(videoTrack);
      is(newStream.getTrackById(videoTrack.id), videoTrack,
         "getTrackByid with matching id should return the track");
      [audioTrack, videoTrack].forEach(t => t.stop());
    });
  });

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