| rmcilroy | 9d39ad8 | 2016-11-16 16:32:22 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <title>window.requestIdleCallback callback behavior during idle periods.</title> |
| 3 | <link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" /> |
| 4 | <script src="/resources/testharness.js"></script> |
| 5 | <script src="/resources/testharnessreport.js"></script> |
| 6 | <script> |
| 7 | |
| 8 | async_test(function() { |
| rmcilroy | 9d39ad8 | 2016-11-16 16:32:22 | [diff] [blame] | 9 | // Check that if an idle callback calls requestIdleCallback, the new callback |
| 10 | // doesn't get the same deadline (i.e., runs in a new idle period). |
| 11 | var previous_deadline = undefined; |
| 12 | var idle_callbacks_remaining = 10; |
| 13 | var rIC = this.step_func(function(deadline) { |
| 14 | var now = performance.now(); |
| 15 | var remaining = deadline.timeRemaining(); |
| 16 | var new_deadline = now + remaining; |
| 17 | if (previous_deadline != undefined) { |
| 18 | assert_true(new_deadline > previous_deadline, "A requestIdleCallback scheduled during an idle period should be called back with a deadline greater than that in the current idle period."); |
| 19 | } |
| 20 | |
| 21 | // Schedule a new requestIdleCallback. |
| 22 | if (--idle_callbacks_remaining > 0) { |
| 23 | previous_deadline = new_deadline; |
| 24 | requestIdleCallback(rIC); |
| 25 | } else { |
| 26 | this.done(); |
| 27 | } |
| 28 | }); |
| 29 | |
| 30 | // Spin an empty rAF loop to cause an idle period each frame. |
| 31 | var idle_task_posted = false; |
| 32 | requestAnimationFrame(function rAFLoop() { |
| 33 | if (!idle_task_posted) { |
| 34 | requestIdleCallback(rIC); |
| 35 | idle_task_posted = true; |
| 36 | } |
| 37 | requestAnimationFrame(rAFLoop); |
| 38 | }); |
| 39 | }, 'Check that if an idle callback calls requestIdleCallback the new callback doesn\'t run in the current idle period.'); |
| 40 | </script> |
| 41 | <h1>Test of requestIdleCallback idle period behavior</h1> |
| 42 | <p>This test validates that window.requestIdleCallback deals with callbacks during idle periods correctly.</p> |
| 43 | <div id="log"></div> |