-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement timeout for idle callbacks
https://bugs.webkit.org/show_bug.cgi?id=259866 Reviewed by Chris Dumez. This PR adds the support for idle callbacks' timeout. It also moves the logic of computing the idle deadline to WindowEventLoop, which now keeps track of WeakHashMap of Page to its next rendering update time. * LayoutTests/imported/w3c/web-platform-tests/requestidlecallback/basic-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/requestidlecallback/callback-timeout-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/requestidlecallback/callback-timeout-when-busy-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/requestidlecallback/deadline-after-expired-timer-expected.txt: * LayoutTests/platform/ios-wk2/TestExpectations: * LayoutTests/platform/mac-wk2/TestExpectations: * LayoutTests/requestidlecallback/requestidlecallback-deadline-expected.txt: Added. * LayoutTests/requestidlecallback/requestidlecallback-deadline-shortened-by-rendering-update-expected.txt: Added. * LayoutTests/requestidlecallback/requestidlecallback-deadline-shortened-by-rendering-update.html: Added. * LayoutTests/requestidlecallback/requestidlecallback-deadline.html: Added. * Source/WebCore/dom/IdleCallbackController.cpp: * Source/WebCore/dom/IdleCallbackController.cpp: (WebCore::IdleCallbackController::queueIdleCallback): Schedule a timer for the timeout. (WebCore::IdleCallbackController::startIdlePeriod): (WebCore::IdleCallbackController::queueTaskToInvokeIdleCallbacks): (WebCore::IdleCallbackController::invokeIdleCallbacks): (WebCore::IdleCallbackController::invokeIdleCallbackTimeout): Added. * Source/WebCore/dom/IdleCallbackController.h: * Source/WebCore/dom/IdleDeadline.cpp: (WebCore::IdleDeadline::timeRemaining const): (WebCore::IdleDeadline::didTimeout const): Moved to the header file. * Source/WebCore/dom/IdleDeadline.h: (WebCore::IdleDeadline::create): Now takes DidTimeout enum class. (WebCore::IdleDeadline::IdleDeadline): Ditto. (WebCore::IdleDeadline::didTimeout const): Moved. Now trivially checks m_didTimeout. * Source/WebCore/dom/WindowEventLoop.cpp: (WebCore::WindowEventLoop::didScheduleRenderingUpdate): Moved from the header. Now takes a Page adds to the map of pages with pending rendering opportunities. (WebCore::WindowEventLoop::didFinishRenderingUpdate): Ditto removes it from the map. (WebCore::WindowEventLoop::opportunisticallyRunIdleCallbacks): (WebCore::WindowEventLoop::shouldEndIdlePeriod): (WebCore::WindowEventLoop::computeIdleDeadline): Added. * Source/WebCore/dom/WindowEventLoop.h: * Source/WebCore/page/Page.cpp: (WebCore::Page::scheduleRenderingUpdateInternal): (WebCore::Page::renderingUpdateCompleted): * Source/WebCore/testing/Internals.cpp: (WebCore::Internals::preferredRenderingUpdateInterval): * Source/WebCore/testing/Internals.h: * Source/WebCore/testing/Internals.idl: Canonical link: https://commits.webkit.org/266745@main
- Loading branch information
Showing
20 changed files
with
220 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...utTests/imported/w3c/web-platform-tests/requestidlecallback/callback-timeout-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
FAIL requestIdleCallback callback should time out assert_false: expected false got true | ||
FAIL requestIdleCallback callback should not time out assert_false: expected false got true | ||
PASS requestIdleCallback callback should time out | ||
PASS requestIdleCallback callback should not time out | ||
|
4 changes: 2 additions & 2 deletions
4
...ported/w3c/web-platform-tests/requestidlecallback/callback-timeout-when-busy-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Test of requestIdleCallback timeout behavior | ||
|
||
|
||
FAIL requestIdleCallback not scheduled when event loop is busy. assert_false: IdleDeadline.didTimeout MUST be false if requestIdleCallback wasn't scheduled due to a timeout expected false got true | ||
FAIL requestIdleCallback scheduled with timeout when event loop is busy. assert_true: IdleDeadline.timeRemaining MUST be equal to zero if requestIdleCallback was scheduled due to a timeout expected true got false | ||
PASS requestIdleCallback not scheduled when event loop is busy. | ||
PASS requestIdleCallback scheduled with timeout when event loop is busy. | ||
|
2 changes: 1 addition & 1 deletion
2
...rted/w3c/web-platform-tests/requestidlecallback/deadline-after-expired-timer-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
FAIL The deadline after an expired timer must not be negative assert_false: expected false got true | ||
PASS The deadline after an expired timer must not be negative | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
LayoutTests/requestidlecallback/requestidlecallback-deadline-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
This tests that the deadline can be reached. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS idleDeadline.timeRemaining() is 0 | ||
PASS idleDeadline.didTimeout is true | ||
PASS didRunIdleCallback is true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
12 changes: 12 additions & 0 deletions
12
...questidlecallback/requestidlecallback-deadline-shortened-by-rendering-update-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
This tests that the deadline can be reached. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS idleDeadline.timeRemaining() > preferredRenderingUpdateInterval is true | ||
PASS idleDeadline.timeRemaining() <= preferredRenderingUpdateInterval + 0.5 is true | ||
PASS didRunIdleCallback is true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
hello |
34 changes: 34 additions & 0 deletions
34
...Tests/requestidlecallback/requestidlecallback-deadline-shortened-by-rendering-update.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html><!-- webkit-test-runner [ RequestIdleCallbackEnabled=true ] --> | ||
<html> | ||
<body> | ||
<script src="../resources/js-test.js"></script> | ||
<script> | ||
|
||
description('This tests that the deadline can be reached.'); | ||
|
||
jsTestIsAsync = true; | ||
|
||
let didRunIdleCallback = false; | ||
onload = () => { | ||
requestIdleCallback((idleDeadline) => { | ||
didRunIdleCallback = true; | ||
window.idleDeadline = idleDeadline; | ||
window.preferredRenderingUpdateInterval = internals.preferredRenderingUpdateInterval(); | ||
shouldBeTrue('idleDeadline.timeRemaining() > preferredRenderingUpdateInterval'); | ||
|
||
document.body.appendChild(document.createElement('span')).textContent = 'hello'; | ||
requestAnimationFrame(() => { }); | ||
|
||
shouldBeTrue('idleDeadline.timeRemaining() <= preferredRenderingUpdateInterval + 0.5'); | ||
if (idleDeadline.timeRemaining() > preferredRenderingUpdateInterval + 0.5) | ||
console.log(idleDeadline.timeRemaining() + ' > ' + preferredRenderingUpdateInterval); | ||
}); | ||
setTimeout(() => { | ||
shouldBeTrue('didRunIdleCallback'); | ||
finishJSTest(); | ||
}, 200); | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
33 changes: 33 additions & 0 deletions
33
LayoutTests/requestidlecallback/requestidlecallback-deadline.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html><!-- webkit-test-runner [ RequestIdleCallbackEnabled=true ] --> | ||
<html> | ||
<body> | ||
<script src="../resources/js-test.js"></script> | ||
<script> | ||
|
||
description('This tests that the deadline can be reached.'); | ||
|
||
jsTestIsAsync = true; | ||
|
||
function synchronouslyWait(milliseconds) { | ||
let start = performance.now(); | ||
while (performance.now() - start < milliseconds); | ||
} | ||
|
||
let didRunIdleCallback = false; | ||
onload = () => { | ||
requestIdleCallback((idleDeadline) => { | ||
window.idleDeadline = idleDeadline; | ||
shouldBe('idleDeadline.timeRemaining()', '0'); | ||
shouldBeTrue('idleDeadline.didTimeout'); | ||
didRunIdleCallback = true; | ||
}, {timeout: 20}); | ||
synchronouslyWait(50); | ||
setTimeout(() => { | ||
shouldBeTrue('didRunIdleCallback'); | ||
finishJSTest(); | ||
}, 100); | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.