Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <title>window.requestIdleCallback deals with timeouts correctly</title> | |
|
esprehn
2015/08/21 08:22:20
ditto
rmcilroy
2015/08/21 11:21:52
Done.
| |
| 2 <link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" /> | |
| 3 <link rel="help" href="http://www.w3.org/TR/requestidlecallback/"/> | |
| 4 <script src="../../../../resources/testharness.js"></script> | |
| 5 <script src="../../../../resources/testharnessreport.js"></script> | |
| 6 <link rel="stylesheet" href="../../resources/testharness.css" /> | |
| 7 <script> | |
| 8 | |
| 9 async_test(function() { | |
| 10 // Check whether requestIdleCallback with a timeout works when the event loop | |
| 11 // is busy. | |
| 12 var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms | |
| 13 var idle_callback_scheduled; | |
| 14 var idle_callback = this.step_func(function(deadline) { | |
| 15 assert_false(deadline.didTimeout, "IdleDeadline.didTimeout MUST be false if requestIdleCallback wasn't scheduled due to a timeout"); | |
| 16 assert_equals(busy_raf_loop_iterations_remaining, 0, "Busy rAF loop should b e finished by the time we get scheduled"); | |
| 17 this.done(); | |
| 18 }); | |
| 19 | |
| 20 var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms | |
| 21 requestAnimationFrame(this.step_func(function busyRAFLoop() { | |
| 22 var start_time = performance.now(); | |
| 23 if (!idle_callback_scheduled) { | |
| 24 idle_callback_scheduled = start_time; | |
| 25 requestIdleCallback(idle_callback); | |
| 26 } | |
| 27 | |
| 28 // Use up the whole frame budget. | |
| 29 while (performance.now() - start_time < 40) { } | |
| 30 if (busy_raf_loop_iterations_remaining > 0) { | |
| 31 busy_raf_loop_iterations_remaining--; | |
| 32 requestAnimationFrame(busyRAFLoop); | |
| 33 } | |
| 34 })); | |
| 35 }, 'requestIdleCallback not scheduled when event loop is busy.'); | |
| 36 | |
| 37 async_test(function() { | |
| 38 // Check whether requestIdleCallback with a timeout works when the event loop | |
| 39 // is busy. | |
| 40 var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms | |
| 41 var timeout = 200; | |
| 42 var idle_callback_scheduled; | |
| 43 var idle_callback = this.step_func(function(deadline) { | |
| 44 var time_delta = performance.now() - idle_callback_scheduled; | |
| 45 assert_true(time_delta >= timeout, "Should only have been run after timeout" ); | |
| 46 assert_true(time_delta - timeout <= 80, "Should have been scheduled close to timeout"); | |
| 47 assert_true(deadline.timeRemaining() <= 0, "IdleDeadline.timeRemaining MUST be less than or equal to zero if requestIdleCallback was scheduled due to a time out"); | |
| 48 assert_true(deadline.didTimeout, "IdleDeadline.didTimeout MUST be true if re questIdleCallback was scheduled due to a timeout"); | |
| 49 assert_true(busy_raf_loop_iterations_remaining > 0, "Busy rAF loop should st ill be going"); | |
| 50 this.done(); | |
| 51 }); | |
| 52 | |
| 53 requestAnimationFrame(this.step_func(function busyRAFLoop() { | |
| 54 var start_time = performance.now(); | |
| 55 if (!idle_callback_scheduled) { | |
| 56 idle_callback_scheduled = start_time; | |
| 57 requestIdleCallback(idle_callback, timeout); | |
| 58 } | |
| 59 | |
| 60 // Use up the whole frame budget. | |
| 61 while (performance.now() - start_time < 40) { } | |
| 62 if (busy_raf_loop_iterations_remaining > 0) { | |
| 63 busy_raf_loop_iterations_remaining--; | |
| 64 requestAnimationFrame(busyRAFLoop); | |
| 65 } | |
| 66 })); | |
| 67 }, 'requestIdleCallback scheduled with timeout when event loop is busy.'); | |
| 68 | |
| 69 </script> | |
| 70 <h1>Description</h1> | |
| 71 <p>This test validates that window.requestIdleCallback deals with timeouts corre ctly.</p> | |
| 72 <div id="log"></div> | |
| OLD | NEW |