raf-coarsened-time.https.html (1596B)
1 <!doctype html> 2 <html> 3 <head> 4 <link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 </head> 8 <body> 9 <script> 10 /* Coarsen to 5 microseconds or coarser */ 11 const COARSE_RESOLUTION = 0.005; 12 13 const CUSTOM_TIMELINE_DELTA = 0.002; 14 const FLOATING_POINT_ERROR_EPSILON = 0.01; 15 16 // Note that this test would fail if the platform introduces a jitter. 17 // It is recommended that platforms that implement jitter run this test 18 // with a flag that turns jitter off, if possible. 19 20 const customTimeline = new DocumentTimeline({originTime: CUSTOM_TIMELINE_DELTA}); 21 promise_test(async t => { 22 for (let i = 0; i < 32; ++i) { 23 const timestamp = await new Promise(resolve => requestAnimationFrame(ts => resolve(ts))); 24 const coarse_timestamp = Math.round(timestamp / COARSE_RESOLUTION) * COARSE_RESOLUTION; 25 assert_approx_equals(timestamp, coarse_timestamp, FLOATING_POINT_ERROR_EPSILON, 26 "timestamp should be coarsened"); 27 assert_approx_equals(timestamp, document.timeline.currentTime, FLOATING_POINT_ERROR_EPSILON, 28 "document.timeline.currentTimeline should be the same as the rAF callback"); 29 assert_approx_equals(customTimeline.currentTime + CUSTOM_TIMELINE_DELTA, 30 timestamp, FLOATING_POINT_ERROR_EPSILON, 31 "originTime for custom timeline should not be coarsened"); 32 } 33 }); 34 </script> 35 </body> 36 </html>