Skip to content

Truly independent web browser

WebContent: Keep uncapped test frames apart by the time resolution

Andreas Kling01863bea5324
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index 7479644bf12..4092221cd53 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -120,6 +120,7 @@ public:
};
bool rendering_opportunity(HighResolutionTime::DOMHighResTimeStamp frame_time, RenderingOpportunitySource);
bool rendering_task_queued_or_running() const { return m_rendering_task_queued || m_running_rendering_task; }
+ double last_render_opportunity_time() const { return m_last_render_opportunity_time; }
void queue_task_to_process_input_events();
bool running_synchronous_rendering_update() const { return m_running_synchronous_rendering_update; }
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index c5dbe46b14b..311535f5a8e 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -714,8 +714,13 @@ void PageClient::request_rendering_opportunity_if_needed()
schedule_local_rendering_opportunity();
return;
}
+ // NB: A frame within the resolution of the time a page reads would repeat the last one's timestamp, and script
+ // would see the document timeline stand still from one frame to the next.
+ static constexpr double maximum_time_resolution_in_milliseconds = 0.1;
+ auto now = Web::HighResolutionTime::unsafe_shared_current_time();
+ auto is_within_time_resolution = now - Web::HTML::main_thread_event_loop().last_render_opportunity_time() < maximum_time_resolution_in_milliseconds;
m_frame_timer_purpose = FrameTimerPurpose::LocalFallback;
- m_frame_timer->restart(AK::Duration::zero());
+ m_frame_timer->restart(is_within_time_resolution ? AK::Duration::from_milliseconds(1) : AK::Duration::zero());
return;
}
diff --git a/Tests/LibWeb/Text/expected/HTML/animation-frame-timestamps-move.txt b/Tests/LibWeb/Text/expected/HTML/animation-frame-timestamps-move.txt
new file mode 100644
index 00000000000..88c845a94b5
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/animation-frame-timestamps-move.txt
@@ -0,0 +1,2 @@
+Frames with the last frame's timestamp: 0
+Frames with the last frame's timeline time: 0
diff --git a/Tests/LibWeb/Text/input/HTML/animation-frame-timestamps-move.html b/Tests/LibWeb/Text/input/HTML/animation-frame-timestamps-move.html
new file mode 100644
index 00000000000..4ae1c983214
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/animation-frame-timestamps-move.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ asyncTest(done => {
+ const frames = 300;
+ let count = 0;
+ let previousTimestamp = -1;
+ let previousTimelineTime = -1;
+ let repeatedTimestamps = 0;
+ let repeatedTimelineTimes = 0;
+ function frame(timestamp) {
+ const timelineTime = document.timeline.currentTime;
+ if (timestamp <= previousTimestamp)
+ ++repeatedTimestamps;
+ if (timelineTime <= previousTimelineTime)
+ ++repeatedTimelineTimes;
+ previousTimestamp = timestamp;
+ previousTimelineTime = timelineTime;
+ if (++count < frames) {
+ requestAnimationFrame(frame);
+ return;
+ }
+ println(`Frames with the last frame's timestamp: ${repeatedTimestamps}`);
+ println(`Frames with the last frame's timeline time: ${repeatedTimelineTimes}`);
+ done();
+ }
+ requestAnimationFrame(frame);
+ });
+</script>