summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/requestidlecallback/callback-idle-periods.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/requestidlecallback/callback-idle-periods.html
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/requestidlecallback/callback-idle-periods.html')
-rw-r--r--testing/web-platform/tests/requestidlecallback/callback-idle-periods.html44
1 files changed, 44 insertions, 0 deletions
diff --git a/testing/web-platform/tests/requestidlecallback/callback-idle-periods.html b/testing/web-platform/tests/requestidlecallback/callback-idle-periods.html
new file mode 100644
index 0000000000..3c2de61bfe
--- /dev/null
+++ b/testing/web-platform/tests/requestidlecallback/callback-idle-periods.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<title>window.requestIdleCallback callback behavior during idle periods.</title>
+<meta name="timeout" content="long">
+<link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+async_test(function() {
+ // Check that if an idle callback calls requestIdleCallback, the new callback
+ // doesn't get the same deadline (i.e., runs in a new idle period).
+ var previous_deadline = undefined;
+ var idle_callbacks_remaining = 10;
+ var rIC = this.step_func(function(deadline) {
+ var now = performance.now();
+ var remaining = deadline.timeRemaining();
+ var new_deadline = now + remaining;
+ if (previous_deadline != undefined) {
+ 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.");
+ }
+
+ // Schedule a new requestIdleCallback.
+ if (--idle_callbacks_remaining > 0) {
+ previous_deadline = new_deadline;
+ requestIdleCallback(rIC);
+ } else {
+ this.done();
+ }
+ });
+
+ // Spin an empty rAF loop to cause an idle period each frame.
+ var idle_task_posted = false;
+ requestAnimationFrame(function rAFLoop() {
+ if (!idle_task_posted) {
+ requestIdleCallback(rIC);
+ idle_task_posted = true;
+ }
+ requestAnimationFrame(rAFLoop);
+ });
+}, 'Check that if an idle callback calls requestIdleCallback the new callback doesn\'t run in the current idle period.');
+</script>
+<h1>Test of requestIdleCallback idle period behavior</h1>
+<p>This test validates that window.requestIdleCallback deals with callbacks during idle periods correctly.</p>
+<div id="log"></div>