blob: 3c1b7acfdc8515a00a34dfbedbb9a5430feb487f [file] [log] [blame] [edit]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing monotonically increasing WebRTC stats timestamps</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<script src ="routines.js"></script>
<script>
// Get stats object of type that is expected to be
// found in the statsReport
function getRequiredStats(statsReport, type) {
for(const stats of statsReport.values()) {
if(stats.type === type) {
return stats;
}
}
assert_unreached(`required stats of type ${type} is not found in stats report`);
}
promise_test(async t => {
const kMinimumTimeElapsedBetweenGetStatsCallsMs = 500;
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const t0 = Math.floor(performance.now());
const t0Stats = getRequiredStats(await pc.getStats(), 'peer-connection');
assert_greater_than(t0Stats.timestamp, window.performance.timeOrigin + window.performance.now() - 100);
await new Promise(
r => t.step_timeout(r, kMinimumTimeElapsedBetweenGetStatsCallsMs));
const t1Stats = getRequiredStats(await pc.getStats(), 'peer-connection');
const t1 = Math.ceil(performance.now());
const maximumTimeElapsedBetweenGetStatsCallsMs = t1 - t0;
const deltaTimestampMs = t1Stats.timestamp - t0Stats.timestamp;
// The delta must be at least the time we waited between calls.
assert_greater_than_equal(deltaTimestampMs,
kMinimumTimeElapsedBetweenGetStatsCallsMs);
// The delta must be at most the time elapsed before the first getStats()
// call and after the second getStats() call.
// We increase a bit maximumTimeElapsedBetweenGetStatsCallsMs as we reduce
// stat timestamp resolution by 1 ms.
assert_less_than_equal(deltaTimestampMs,
maximumTimeElapsedBetweenGetStatsCallsMs + 2);
}, `RTCStats.timestamp increases with time passing`);
</script>
</body>
</html>