deadline-max-timeout-dynamic.html (1292B)
1 <!DOCTYPE html> 2 <title>window.requestIdleCallback max idle period deadline (dynamic timoeout).</title> 3 <meta name="timeout" content="long"> 4 <link rel="author" title="Noam Rosenthal" href="mailto:noam@webkit.org" /> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="resources/ric-utils.js"></script> 8 <script> 9 10 promise_test(async () => { 11 for (let i = 0; i < getRICRetryCount(); ++i) { 12 for (const timeout of [10, 20, 30]) { 13 const {before, after} = await new Promise(resolve => requestIdleCallback(async deadline => { 14 const before = deadline.timeRemaining(); 15 const timerPromise = new Promise(resolve => step_timeout(resolve, timeout)); 16 const after = deadline.timeRemaining(); 17 await timerPromise; 18 resolve({before, after}) 19 })) 20 21 assert_less_than_equal(after, before) 22 assert_less_than_equal(after, timeout) 23 } 24 } 25 26 }, 'Check that the deadline is changed if there is a new timeout from within requestIdleCallback.'); 27 </script> 28 <h1>Test of requestIdleCallback deadline behavior</h1> 29 <p>The test can pass accidentally as idle deadlines have a maximum but they can always be shorter. 30 It runs multiple times to expose potential failures.</p> 31 <div id="log"></div>