haikuwebkit/LayoutTests/intersection-observer/intersection-observer-callb...

100 lines
2.5 KiB
HTML
Raw Permalink Normal View History

Timestamps should be the same for all rendering update steps https://bugs.webkit.org/show_bug.cgi?id=207153 Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2020-04-27 Reviewed by Simon Fraser. Source/WebCore: The HTML 5 event loop sepcs states that timestamps should be the same for all rendering update steps. Specs link (step 9): https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model This patch also fixes some issues in IntersectionObserver. Test: intersection-observer/intersection-observer-callback-timestamp.html * dom/Document.cpp: (WebCore::Document::updateIntersectionObservations): (WebCore::Document::notifyIntersectionObserversTimerFired): Deleted. * dom/Document.h: -- Handle the case when two floats are areEssentiallyEqual(). -- Execute the IntersectionObserver immediately and do not wait until the next CFRunLoop event since this does not implement the specs. * page/DOMWindow.cpp: (WebCore::DOMWindow::freezeNowTimestamp): (WebCore::DOMWindow::unfreezeNowTimestamp): (WebCore::DOMWindow::frozenNowTimestamp const): * page/DOMWindow.h: Provide a frozen now() timestamp in seconds to be used internally only. * page/IntersectionObserver.cpp: (WebCore::IntersectionObserver::nowTimestamp const): Use the frozenNowTimestamp(). * page/Page.cpp: (WebCore::Page::updateRendering): Freeze the timestamps while serving the rendering update steps. LayoutTests: * animations/animation-callback-timestamp-expected.txt: * animations/animation-callback-timestamp.html: Ensure the rAF callback timestamp is less than Performance.now(). * animations/animation-multiple-callbacks-timestamp-expected.txt: * animations/animation-multiple-callbacks-timestamp.html: Ensure the rAF callbacks receive the same timestamps. * intersection-observer/intersection-observer-callback-timestamp-expected.txt: Added. * intersection-observer/intersection-observer-callback-timestamp.html: Added. A new test to ensure the IntersectionObsever and the rAF callbacks receive the same timestamps. * platform/ios-wk2/TestExpectations: * platform/mac-wk1/TestExpectations: Canonical link: https://commits.webkit.org/223995@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@260800 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-04-28 00:22:49 +00:00
<!DOCTYPE HTML>
<html>
<head>
<script src="../resources/js-test-pre.js"></script>
<style>
#scrollable {
width: 100px;
height: 100px;
border: 1px solid black;
overflow-y: auto;
}
#container {
width: 100px;
height: 200px;
}
#box {
position: relative;
top: 100px;
width: 100px;
height: 100px;
background-color: green;
}
</style>
</head>
<body>
<div id="scrollable">
<div id="container">
<div id="box"></div>
</div>
</div>
<script>
var animateTimestamp = 0;
var intersectTimestamp = 0;
var MaxFrames = 2;
var currentFrame = 0;
function scrollBox()
{
var scrollable = document.querySelector("#scrollable");
var height = scrollable.clientHeight;
scrollable.scroll(0, (height / MaxFrames) * currentFrame);
document.body.offsetHeight;
}
function handleAnimate(timestamp)
{
if (++currentFrame > MaxFrames) {
finishJSTest();
return;
}
animateTimestamp = timestamp;
scrollBox();
requestAnimationFrame(handleAnimate);
}
function handleIntersect(entries, observer)
{
entries.forEach((entry) => {
intersectTimestamp = entry.time;
shouldBe("Math.round(animateTimestamp)", "Math.round(intersectTimestamp)");
});
}
function buildThresholdList()
{
let thresholds = [];
for (let i = 1.0; i <= MaxFrames; i++) {
let ratio = i / MaxFrames;
thresholds.push(ratio);
}
return thresholds;
}
function createObserver()
{
let observer;
let options = {
root: document.querySelector("#scrollable"),
rootMargin: "0px",
threshold: buildThresholdList()
};
observer = new IntersectionObserver(handleIntersect, options);
observer.observe(document.querySelector("#box"));
}
window.jsTestIsAsync = true;
description("Test the IntersectionObserver timestamp is the same as the timestamp of the rAF callback.");
createObserver();
requestAnimationFrame(handleAnimate);
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>