From 6ae31b2052754cb7645ba0e4c7c8ec43681d4a36 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Wed, 13 Apr 2022 17:46:15 +0300 Subject: [PATCH] Tests for requestIdleCallback deadline computation (#31177) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Tests for requestIdleCallback deadline computation Deadline should be: - capped at 50ms - capped at 1000/60 (~16ms) when there is a pending rAF callback - capped at the time of the next timeout - be updated when the above conditions change, during the callback itself See https://github.com/whatwg/html/pull/7166 Co-authored-by: Philip Jägenstedt --- .../deadline-max-rAF-dynamic.html | 31 +++++++++++++++++++ requestidlecallback/deadline-max-rAF.html | 21 +++++++++++++ .../deadline-max-timeout-dynamic.html | 31 +++++++++++++++++++ requestidlecallback/deadline-max.html | 20 ++++++++++++ requestidlecallback/resources/ric-utils.js | 14 +++++++++ 5 files changed, 117 insertions(+) create mode 100644 requestidlecallback/deadline-max-rAF-dynamic.html create mode 100644 requestidlecallback/deadline-max-rAF.html create mode 100644 requestidlecallback/deadline-max-timeout-dynamic.html create mode 100644 requestidlecallback/deadline-max.html create mode 100644 requestidlecallback/resources/ric-utils.js diff --git a/requestidlecallback/deadline-max-rAF-dynamic.html b/requestidlecallback/deadline-max-rAF-dynamic.html new file mode 100644 index 00000000000000..43eebd7641be01 --- /dev/null +++ b/requestidlecallback/deadline-max-rAF-dynamic.html @@ -0,0 +1,31 @@ + +window.requestIdleCallback max idle period deadline (requestAnimationFrame). + + + + + + +

Test of requestIdleCallback deadline behavior

+

The test can pass accidentally as idle deadlines have a maximum but they can always be shorter. +It runs multiple times to expose potential failures.

+
diff --git a/requestidlecallback/deadline-max-rAF.html b/requestidlecallback/deadline-max-rAF.html new file mode 100644 index 00000000000000..314f250254f953 --- /dev/null +++ b/requestidlecallback/deadline-max-rAF.html @@ -0,0 +1,21 @@ + +window.requestIdleCallback max idle period deadline (requestAnimationFrame). + + + + + + +

Test of requestIdleCallback deadline behavior

+

The test can pass accidentally as idle deadlines have a maximum but they can always be shorter. +It runs multiple times to expose potential failures.

+
diff --git a/requestidlecallback/deadline-max-timeout-dynamic.html b/requestidlecallback/deadline-max-timeout-dynamic.html new file mode 100644 index 00000000000000..169e6db548530d --- /dev/null +++ b/requestidlecallback/deadline-max-timeout-dynamic.html @@ -0,0 +1,31 @@ + +window.requestIdleCallback max idle period deadline (dynamic timoeout). + + + + + + +

Test of requestIdleCallback deadline behavior

+

The test can pass accidentally as idle deadlines have a maximum but they can always be shorter. +It runs multiple times to expose potential failures.

+
diff --git a/requestidlecallback/deadline-max.html b/requestidlecallback/deadline-max.html new file mode 100644 index 00000000000000..e33341ac9dd977 --- /dev/null +++ b/requestidlecallback/deadline-max.html @@ -0,0 +1,20 @@ + +window.requestIdleCallback max idle period deadline. + + + + + + +

Test of requestIdleCallback deadline behavior

+

This test validates that deadlines returned for requestIdleCallback are less than 50ms.

+

The test can pass accidentally as idle deadlines have a maximum but they can always be shorter. +It runs multiple times to expose potential failures.

+
diff --git a/requestidlecallback/resources/ric-utils.js b/requestidlecallback/resources/ric-utils.js new file mode 100644 index 00000000000000..d6d22767a98eee --- /dev/null +++ b/requestidlecallback/resources/ric-utils.js @@ -0,0 +1,14 @@ +function getDeadlineForNextIdleCallback() { + return new Promise( + resolve => + requestIdleCallback(deadline => resolve(deadline.timeRemaining())) + ); +} + +function getPendingRenderDeadlineCap() { + return 1000 / 60; +} + +function getRICRetryCount() { + return 10; +} \ No newline at end of file