Skip to content

Truly independent web browser

LibWeb: Test a view timeline beside a task on the render clock

Andreas Klingc2fd757f491e
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-samples-a-view-timeline.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-samples-a-view-timeline.txt
new file mode 100644
index 00000000000..a4ef65d3aa8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-samples-a-view-timeline.txt
@@ -0,0 +1,7 @@
+presented width a quarter through the cover range: none
+presented width half through the cover range: none
+presented width past the cover range: none
+presented width scrolled back to half: none
+render clock: ticking
+last frame presented by: clock
+the page holds at the top: true
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-samples-a-view-timeline.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-samples-a-view-timeline.html
new file mode 100644
index 00000000000..5ba55c9d412
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-samples-a-view-timeline.html
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ @keyframes shrink {
+ from { height: 50px; }
+ to { height: 50px; }
+ }
+ @keyframes widen {
+ from { width: 100px; }
+ to { width: 300px; }
+ }
+ body {
+ margin: 0;
+ }
+ #header {
+ height: 50px;
+ animation: shrink linear both;
+ animation-timeline: scroll(root);
+ }
+ #before {
+ height: 950px;
+ }
+ #subject {
+ height: 100px;
+ animation: widen linear both;
+ animation-timeline: view();
+ }
+ #after {
+ height: 2000px;
+ }
+</style>
+<div id="header"></div>
+<div id="before"></div>
+<div id="subject"></div>
+<div id="after"></div>
+<script>
+ // While a task runs, the render clock samples a view timeline where the compositor has scrolled its subject to. The
+ // subject enters at the bottom of the viewport and leaves at the top, each at its own progress.
+ asyncTest(async done => {
+ const presentedWidth = () => {
+ const box = internals.presentedBorderBox(subject);
+ return box === null ? "none" : box.width.toFixed(1);
+ };
+ const result = await whileLaneAnimates(() => subject.getAnimations()[0], frameTime => {
+ const coverStart = 1000 - window.innerHeight;
+ const coverEnd = 1100;
+ const quarter = coverStart + (coverEnd - coverStart) / 4;
+ const half = coverStart + (coverEnd - coverStart) / 2;
+ internals.injectClockTick(frameTime + 16, quarter);
+ const atAQuarter = presentedWidth();
+ internals.injectClockTick(frameTime + 32, half);
+ const atHalf = presentedWidth();
+ internals.injectClockTick(frameTime + 48, coverEnd + 100);
+ const past = presentedWidth();
+ internals.injectClockTick(frameTime + 64, half);
+ const back = presentedWidth();
+ return {
+ atAQuarter,
+ atHalf,
+ past,
+ back,
+ lane: internals.clockLaneState(document),
+ presentedBy: internals.lastFramePresentedBy(document),
+ };
+ });
+ println(`presented width a quarter through the cover range: ${result.atAQuarter}`);
+ println(`presented width half through the cover range: ${result.atHalf}`);
+ println(`presented width past the cover range: ${result.past}`);
+ println(`presented width scrolled back to half: ${result.back}`);
+ println(`render clock: ${result.lane}`);
+ println(`last frame presented by: ${result.presentedBy}`);
+ println(`the page holds at the top: ${window.scrollY === 0 && subject.getBoundingClientRect().width === 100}`);
+ done();
+ });
+</script>