Truly independent web browser
LibWeb: Synchronize isolated iframe reference screenshots
Andreas Kling1b465a5c2767
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 6013a70eee8..c4936c6eb52 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -643,6 +643,11 @@ static void let_compositor_take_in_every_rendered_frame(HTML::Window& window)compositor_context->synchronize_for_testing();}+void Internals::synchronize_compositor()+{+ let_compositor_take_in_every_rendered_frame(window());+}+void Internals::send_text_through_ui_process(Utf16String const& text){let_compositor_take_in_every_rendered_frame(window());diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.hindex 4707292be98..73e3faf8d32 100644--- a/Libraries/LibWeb/Internals/Internals.h+++ b/Libraries/LibWeb/Internals/Internals.h@@ -260,6 +260,7 @@ public:void set_manual_rendering_opportunities(bool enabled);void inject_rendering_opportunity(double frame_time_ms);Utf16String frame_scheduler_state() const;+ void synchronize_compositor();void hold_next_frame(Utf16String const& hold);Utf16String last_frame_presented_by(DOM::Document&);void inject_clock_tick(double frame_time_ms, Optional<double> viewport_scroll_y);diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idlindex f844e94a28b..1dd537d29ec 100644--- a/Libraries/LibWeb/Internals/Internals.idl+++ b/Libraries/LibWeb/Internals/Internals.idl@@ -305,6 +305,9 @@ interface Internals {// "landed" once the event loop took the frame in and the update has not run its steps from its style and layout on// yet, "idle" otherwise.DOMString frameSchedulerState();+ // Waits until the compositor has received every frame already rendered for this page in this process. This does+ // not start a rendering update or wait for frames hosted by another process.+ undefined synchronizeCompositor();// Keeps the next recording that flies in flight, before it reads its frame, until releaseHeldFrame(), or until a// read waits for it. With "layout", only the next rendering update's layout that flies, or recording, is held,// before it reads anything.diff --git a/Tests/LibWeb/Ref/input/isolated-iframe-compositor-synchronization.html b/Tests/LibWeb/Ref/input/isolated-iframe-compositor-synchronization.htmlnew file mode 100644index 00000000000..eeb1f031f39--- /dev/null+++ b/Tests/LibWeb/Ref/input/isolated-iframe-compositor-synchronization.html@@ -0,0 +1,42 @@+<!doctype html>+<html class="reftest-wait">+ <link rel="match" href="../expected/isolated-iframe-is-composited-into-its-parent-ref.html" />+ <style>+ body {+ margin: 0;+ }+ iframe {+ display: block;+ width: 100px;+ height: 100px;+ border: 0;+ }+ </style>+ <script>+ // The child's recording stays held until the synchronization takes it in. Animation frame callbacks alone do+ // not publish it, so the screenshot would be blank if the child reported before the barrier completed.+ const request = new XMLHttpRequest();+ const path = `/echo/isolated-iframe-composited-${crypto.randomUUID()}`;+ request.open("POST", "/echo", false);+ request.setRequestHeader("Content-Type", "application/json");+ request.send(+ JSON.stringify({+ method: "GET",+ path,+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><style>html, body { margin: 0; height: 100%; background: green; }</style>+ <script>+ internals.holdNextFrame();+ requestAnimationFrame(() => requestAnimationFrame(() => {+ internals.synchronizeCompositor();+ parent.postMessage("painted", "*");+ }));<\/script>`,+ })+ );++ const host = `oop-iframe-composited-${crypto.randomUUID()}.localhost`;+ window.addEventListener("message", () => document.documentElement.classList.remove("reftest-wait"));+ document.write(`<iframe src="http://${host}:${location.port}${path}"></iframe>`);+ </script>+</html>diff --git a/Tests/LibWeb/Ref/input/isolated-iframe-compositor-synchronization.html.headers b/Tests/LibWeb/Ref/input/isolated-iframe-compositor-synchronization.html.headersnew file mode 100644index 00000000000..156209f9c81--- /dev/null+++ b/Tests/LibWeb/Ref/input/isolated-iframe-compositor-synchronization.html.headers@@ -0,0 +1 @@+Content-Type: text/htmldiff --git a/Tests/LibWeb/Ref/input/isolated-iframe-is-composited-into-its-parent.html b/Tests/LibWeb/Ref/input/isolated-iframe-is-composited-into-its-parent.htmlindex 9da8da97691..e9a311ab60b 100644--- a/Tests/LibWeb/Ref/input/isolated-iframe-is-composited-into-its-parent.html+++ b/Tests/LibWeb/Ref/input/isolated-iframe-is-composited-into-its-parent.html@@ -1,29 +1,49 @@-<!DOCTYPE html>+<!doctype html><html class="reftest-wait">-<link rel="match" href="../expected/isolated-iframe-is-composited-into-its-parent-ref.html">-<style>- body { margin: 0; }- iframe { display: block; width: 100px; height: 100px; border: 0; }-</style>-<script>- // The frame's document is cross-site, so another process hosts it and paints it through a compositor context of- // its own. That context is composited into this page's, where the frame's box is. The screenshot composites- // whatever that process last published, and the frame's load event says nothing about whether it has painted, so- // the frame reports once a rendering update has painted it.- const request = new XMLHttpRequest();- const path = `/echo/isolated-iframe-composited-${crypto.randomUUID()}`;- request.open("POST", "/echo", false);- request.setRequestHeader("Content-Type", "application/json");- request.send(JSON.stringify({- method: "GET",- path,- status: 200,- headers: { "Content-Type": "text/html" },- body: `<!DOCTYPE html><style>html, body { margin: 0; height: 100%; background: green; }</style>- <script>requestAnimationFrame(() => requestAnimationFrame(() => parent.postMessage("painted", "*")));<\/script>`,- }));+ <link rel="match" href="../expected/isolated-iframe-is-composited-into-its-parent-ref.html" />+ <style>+ body {+ margin: 0;+ }+ iframe {+ display: block;+ width: 100px;+ height: 100px;+ border: 0;+ }+ </style>+ <script>+ // The frame's document is cross-site, so another process hosts it and paints it through a compositor context of+ // its own. That context is composited into this page's, where the frame's box is. The screenshot composites+ // whatever that process last published, and the frame's load event says nothing about whether it has painted, so+ // the frame reports once its rendering update has finished and the compositor has received its frame.+ const request = new XMLHttpRequest();+ const path = `/echo/isolated-iframe-composited-${crypto.randomUUID()}`;+ request.open("POST", "/echo", false);+ request.setRequestHeader("Content-Type", "application/json");+ request.send(+ JSON.stringify({+ method: "GET",+ path,+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><style>html, body { margin: 0; height: 100%; background: green; }</style>+ <script>requestAnimationFrame(() => requestAnimationFrame(async () => {+ const nextTask = () => new Promise(resolve => {+ const channel = new MessageChannel();+ channel.port1.onmessage = resolve;+ channel.port2.postMessage(null);+ });+ do await nextTask();+ while (internals.frameSchedulerState() !== "idle");+ internals.synchronizeCompositor();+ parent.postMessage("painted", "*");+ }));<\/script>`,+ })+ );- const host = `oop-iframe-composited-${crypto.randomUUID()}.localhost`;- window.addEventListener("message", () => document.documentElement.classList.remove("reftest-wait"));- document.write(`<iframe src="http://${host}:${location.port}${path}"></iframe>`);-</script>+ const host = `oop-iframe-composited-${crypto.randomUUID()}.localhost`;+ window.addEventListener("message", () => document.documentElement.classList.remove("reftest-wait"));+ document.write(`<iframe src="http://${host}:${location.port}${path}"></iframe>`);+ </script>+</html>