File: RTCPeerConnection-getStats-timestamp.https.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (78 lines) | stat: -rw-r--r-- 3,213 bytes parent folder | download | duplicates (12)
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
<!doctype html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';

// It is not possible to make `Date.now()` and `performance.timeOrigin +
// performance.now()` diverge inside of WPTs, so implementers beware that these
// tests may give FALSE positives if `timestamp` is implemented as Wall Clock.

// TODO: crbug.com/372749742 - Timestamps from RTCStats differs slightly from
// performance.timeOrigin + performance.now(). We add an epsilon to the
// timestamp checks as a workaround to avoid making the tests flaky.
const kTimeEpsilon = 0.2;

promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());

  const t0 = performance.timeOrigin + performance.now();
  const report = await pc.getStats();
  const t1 = performance.timeOrigin + performance.now();

  // Any locally sourced RTCStats would do for this test but we have to pick one
  // for consistency between test runs and make no assumption about stats report
  // iteration order.
  const peerConnectionStats =
      report.values().find(stats => stats.type == 'peer-connection');

  assert_less_than_equal(t0, peerConnectionStats.timestamp + kTimeEpsilon,
      't0 < timestamp');
  assert_less_than_equal(peerConnectionStats.timestamp, t1 + kTimeEpsilon,
      'timestamp < t1');
}, 'RTCStats.timestamp is expressed as Performance time');

promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());

  // Media is needed for RTCP reports.
  const stream = await getNoiseStream({video: true});
  const [track] = stream.getTracks();
  t.add_cleanup(() => track.stop());
  pc1.addTrack(track);

  // Negotiate and ICE connect.
  pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
  pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);
  await pc1.setLocalDescription();
  await pc2.setRemoteDescription(pc1.localDescription);
  await pc2.setLocalDescription();
  await pc1.setRemoteDescription(pc2.localDescription);

  // The report won't contain RTCP stats objects until the first RTCP report is
  // received. This can take several seconds so we poll `getStats()` in a loop.
  const t0 = performance.timeOrigin + performance.now();
  let remoteInboundRtp = null;
  while (remoteInboundRtp == null) {
    // When https://crbug.com/369369568 is fixed consider clearing stats cache
    // here (e.g. SLD) and then making the interval tighter by updating `t0` to
    // "now" if `remoteInboundRtp` was missing.
    const report = await pc1.getStats();
    remoteInboundRtp =
        report.values().find(stats => stats.type == 'remote-inbound-rtp');
  }
  const t1 = performance.timeOrigin + performance.now();

  assert_less_than_equal(t0, remoteInboundRtp.timestamp + kTimeEpsilon,
      't0 < timestamp');
  assert_less_than_equal(remoteInboundRtp.timestamp, t1 + kTimeEpsilon,
      'timestamp < t1');
}, 'RTCRemoteInboundRtpStats.timestamp is expressed as Performance time');
</script>