| OLD | NEW |
| (Empty) |
| 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 <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 that two separate calls to requestIdleCallbacks can run in the same | |
| 12 // idle period. | |
| 13 var callback_1_deadline; | |
| 14 var callback_1_has_run = false; | |
| 15 var callback_1 = function(deadline) { | |
| 16 callback_1_has_run = true; | |
| 17 var remaining = deadline.timeRemaining(); | |
| 18 if (remaining >= 5) { | |
| 19 // Should be enough time to run the next callback in the current idle | |
| 20 // period. | |
| 21 callback_1_deadline = performance.now() + remaining; | |
| 22 } | |
| 23 }; | |
| 24 var callback_2 = this.step_func(function(deadline) { | |
| 25 assert_true(callback_1_has_run, "Should run callbacks in order of posting if
they don't have a timeout."); | |
| 26 if (callback_1_deadline != undefined) { | |
| 27 assert_true(performance.now() < callback_1_deadline, "Should be able to ru
n both callbacks in the same idle period."); | |
| 28 this.done(); | |
| 29 } else { | |
| 30 // Might not have had enough idle time, so try again. | |
| 31 callback_1_has_run = false; | |
| 32 setTimeout(function() { | |
| 33 requestIdleCallback(callback_1); | |
| 34 requestIdleCallback(callback_2); | |
| 35 }, 0); | |
| 36 } | |
| 37 }); | |
| 38 requestIdleCallback(callback_1); | |
| 39 requestIdleCallback(callback_2); | |
| 40 }, 'requestIdleCallback can run multiple different requestIdleCallback callbacks
in the same idle period.'); | |
| 41 | |
| 42 async_test(function() { | |
| 43 // Check that if an idle callback calls requestIdleCallback the new callback | |
| 44 // doesn't run in the current idle period. | |
| 45 var previous_deadline; | |
| 46 var idle_callbacks_remaining = 10; | |
| 47 var self = this; | |
| 48 requestIdleCallback(this.step_func(function rIC(deadline) { | |
| 49 var remaining = deadline.timeRemaining(); | |
| 50 var now = performance.now(); | |
| 51 if (previous_deadline != undefined) { | |
| 52 assert_true(now >= previous_deadline, "A requestIdleCallback called during
an idle period should not be run until the next idle period."); | |
| 53 } | |
| 54 | |
| 55 // Schedule a new requestIdleCallback. | |
| 56 if (--idle_callbacks_remaining > 0) { | |
| 57 previous_deadline = now + remaining; | |
| 58 requestIdleCallback(rIC); | |
| 59 } else { | |
| 60 self.done(); | |
| 61 } | |
| 62 })); | |
| 63 | |
| 64 // Spin an empty rAF loop to cause an idle period each frame. | |
| 65 requestAnimationFrame(this.step_func(function rAFLoop() { | |
| 66 requestAnimationFrame(rAFLoop); | |
| 67 })); | |
| 68 }, 'Check that if an idle callback calls requestIdleCallback the new callback do
esn\'t run in the current idle period.'); | |
| 69 </script> | |
| 70 <h1>Description</h1> | |
| 71 <p>This test validates that window.requestIdleCallback deals with callbacks duri
ng idle periods correctly.</p> | |
| 72 <div id="log"></div> | |
| OLD | NEW |