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