Chromium Code Reviews| Index: LayoutTests/virtual/threaded/fast/idle-callback/idle_periods.html |
| diff --git a/LayoutTests/virtual/threaded/fast/idle-callback/idle_periods.html b/LayoutTests/virtual/threaded/fast/idle-callback/idle_periods.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1f7e6846cab0c4d7d0995217c9b91922c5421a4a |
| --- /dev/null |
| +++ b/LayoutTests/virtual/threaded/fast/idle-callback/idle_periods.html |
| @@ -0,0 +1,65 @@ |
| +<!DOCTYPE html> |
| +<title>window.requestIdleCallback callback behavior during idle periods.</title> |
| +<link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" /> |
| +<link rel="help" href="http://www.w3.org/TR/requestidlecallback/"/> |
| +<script src="../../../../resources/testharness.js"></script> |
| +<script src="../../../../resources/testharnessreport.js"></script> |
| +<link rel="stylesheet" href="../../../..//resources/testharness.css" /> |
| +<script> |
| + |
| +async_test(function() { |
| + // Check whether separate calls to requestIdleCallbacks can run in the same |
|
Sami
2015/09/14 15:55:37
nit: This description is a little vague in the sen
rmcilroy
2015/09/14 16:24:32
Done.
|
| + // idle period. |
| + var callback_1_deadline; |
| + var callback_1_has_run = false; |
| + var callback_1 = function(deadline) { |
| + callback_1_has_run = true; |
| + var remaining = deadline.timeRemaining(); |
| + if (remaining >= 5) { |
| + // Should be enough time to run the next callback in the current idle |
| + // period. |
| + callback_1_deadline = performance.now() + remaining; |
| + } |
| + }; |
| + var callback_2 = this.step_func(function(deadline) { |
| + assert_true(callback_1_has_run, "Should run callbacks in order of posting if they don't have a timeout."); |
| + if (callback_1_deadline != undefined) { |
|
Sami
2015/09/14 15:55:37
I'm wondering if we should do this in a loop until
rmcilroy
2015/09/14 16:24:33
Added a loop if we weren't able to do the check. D
|
| + assert_true(performance.now() < callback_1_deadline, "Should be able to run both callbacks in the same idle period."); |
| + } |
| + this.done(); |
| + }); |
| + requestIdleCallback(callback_1); |
| + requestIdleCallback(callback_2); |
| +}, 'requestIdleCallback can run multiple different requestIdleCallback callbacks in the same idle period.'); |
| + |
| +async_test(function() { |
| + // Check that if an idle callback calls requestIdleCallback the new callback |
| + // doesn't run in the current idle period. |
| + var previous_deadline; |
| + var idle_callbacks_remaining = 10; |
| + var self = this; |
| + requestIdleCallback(this.step_func(function rIC(deadline) { |
| + var remaining = deadline.timeRemaining(); |
| + var now = performance.now(); |
| + if (previous_deadline != undefined) { |
| + assert_true(now >= previous_deadline, "A requestIdleCallback called during an idle period should not be run until the next idle period."); |
| + } |
| + |
| + // Schedule a new requestIdleCallback. |
| + if (--idle_callbacks_remaining > 0) { |
| + previous_deadline = now + remaining; |
| + requestIdleCallback(rIC); |
| + } else { |
| + self.done(); |
| + } |
| + })); |
| + |
| + // Spin an empty rAF loop to cause an idle period each frame. |
| + requestAnimationFrame(this.step_func(function rAFLoop() { |
| + requestAnimationFrame(rAFLoop); |
| + })); |
| +}, 'Check that if an idle callback calls requestIdleCallback the new callback doesn\'t run in the current idle period.'); |
| +</script> |
| +<h1>Description</h1> |
| +<p>This test validates that window.requestIdleCallback deals with callbacks during idle periods correctly.</p> |
| +<div id="log"></div> |