summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_trackless_sender_stats.html
blob: f0356f56555ee4fdb1fd507d49c56c9bb36835fb (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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="application/javascript" src="stats.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1452673",
    title: "Trackless RTCRtpSender.getStats()",
    visible: true
  });

  // Calling getstats() on a trackless RTCRtpSender should yield an empty
  // stats report.  When track stats are added in the future, the stats
  // for the removed tracks should continue to appear.

  runNetworkTest(function (options) {
    const test = new PeerConnectionTest(options);
    test.chain.removeAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW");
    test.chain.append(
      async function PC_LOCAL_AND_REMOTE_TRACKLESS_SENDER_STATS(test) {
        await Promise.all([
          waitForSyncedRtcp(test.pcLocal._pc),
          waitForSyncedRtcp(test.pcRemote._pc),
        ]);
        let senders = test.pcLocal.getSenders();
        let receivers = test.pcRemote.getReceivers();
        is(senders.length, 2, "Have exactly two senders.");
        is(receivers.length, 2, "Have exactly two receivers.");
        for(let kind of ["audio", "video"]) {
          is(senders.filter(s => s.track.kind == kind).length, 1,
              "Exactly 1 sender of kind " + kind);
          is(receivers.filter(r => r.track.kind == kind).length, 1,
              "Exactly 1 receiver of kind " + kind);
        }
        // Remove tracks from senders
        for (const sender of senders) {
          await sender.replaceTrack(null);
          is(sender.track, null, "Sender track removed");
          let stats = await sender.getStats();
          ok(stats instanceof window.RTCStatsReport, "Stats is instance of RTCStatsReport");
          // Number of stats in the report. This should be 0.
          is(stats.size, 0, "Trackless sender stats report is empty");
        }
      }
    );
    test.setMediaConstraints([{audio: true}, {video: true}], []);
    return test.run();
  });
</script>
</pre>
</body>
</html>