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