RTCPeerConnection-getStats-timestamp.https.html (3213B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <meta name="timeout" content="long"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="RTCPeerConnection-helper.js"></script> 7 <script> 8 'use strict'; 9 10 // It is not possible to make `Date.now()` and `performance.timeOrigin + 11 // performance.now()` diverge inside of WPTs, so implementers beware that these 12 // tests may give FALSE positives if `timestamp` is implemented as Wall Clock. 13 14 // TODO: crbug.com/372749742 - Timestamps from RTCStats differs slightly from 15 // performance.timeOrigin + performance.now(). We add an epsilon to the 16 // timestamp checks as a workaround to avoid making the tests flaky. 17 const kTimeEpsilon = 0.2; 18 19 promise_test(async t => { 20 const pc = new RTCPeerConnection(); 21 t.add_cleanup(() => pc.close()); 22 23 const t0 = performance.timeOrigin + performance.now(); 24 const report = await pc.getStats(); 25 const t1 = performance.timeOrigin + performance.now(); 26 27 // Any locally sourced RTCStats would do for this test but we have to pick one 28 // for consistency between test runs and make no assumption about stats report 29 // iteration order. 30 const peerConnectionStats = 31 report.values().find(stats => stats.type == 'peer-connection'); 32 33 assert_less_than_equal(t0, peerConnectionStats.timestamp + kTimeEpsilon, 34 't0 < timestamp'); 35 assert_less_than_equal(peerConnectionStats.timestamp, t1 + kTimeEpsilon, 36 'timestamp < t1'); 37 }, 'RTCStats.timestamp is expressed as Performance time'); 38 39 promise_test(async t => { 40 const pc1 = new RTCPeerConnection(); 41 t.add_cleanup(() => pc1.close()); 42 const pc2 = new RTCPeerConnection(); 43 t.add_cleanup(() => pc1.close()); 44 45 // Media is needed for RTCP reports. 46 const stream = await getNoiseStream({video: true}); 47 const [track] = stream.getTracks(); 48 t.add_cleanup(() => track.stop()); 49 pc1.addTrack(track); 50 51 // Negotiate and ICE connect. 52 pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate); 53 pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate); 54 await pc1.setLocalDescription(); 55 await pc2.setRemoteDescription(pc1.localDescription); 56 await pc2.setLocalDescription(); 57 await pc1.setRemoteDescription(pc2.localDescription); 58 59 // The report won't contain RTCP stats objects until the first RTCP report is 60 // received. This can take several seconds so we poll `getStats()` in a loop. 61 const t0 = performance.timeOrigin + performance.now(); 62 let remoteInboundRtp = null; 63 while (remoteInboundRtp == null) { 64 // When https://crbug.com/369369568 is fixed consider clearing stats cache 65 // here (e.g. SLD) and then making the interval tighter by updating `t0` to 66 // "now" if `remoteInboundRtp` was missing. 67 const report = await pc1.getStats(); 68 remoteInboundRtp = 69 report.values().find(stats => stats.type == 'remote-inbound-rtp'); 70 } 71 const t1 = performance.timeOrigin + performance.now(); 72 73 assert_less_than_equal(t0, remoteInboundRtp.timestamp + kTimeEpsilon, 74 't0 < timestamp'); 75 assert_less_than_equal(remoteInboundRtp.timestamp, t1 + kTimeEpsilon, 76 'timestamp < t1'); 77 }, 'RTCRemoteInboundRtpStats.timestamp is expressed as Performance time'); 78 </script>