From f3add3dd72a303969bb19989cfb7400c2af0bd93 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 12 Sep 2023 16:36:10 +0100 Subject: [PATCH] WebContent: Add "load-reference-page" debug request This attempts to load the URL of the first `` it finds. If that tag is missing, we load an error page to make sure the ref-test fails. (And to provide some feedback if someone looks at the screenshot somehow.) Wrong URLs will instead end up loading the default 404 error page. --- .../Services/WebContent/ConnectionFromClient.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index c4c0360895..ca847d9a1f 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -459,6 +459,21 @@ void ConnectionFromClient::debug_request(DeprecatedString const& request, Deprec document->window().local_storage().release_value_but_fixme_should_propagate_errors()->dump(); return; } + + if (request == "load-reference-page") { + if (auto* document = page().top_level_browsing_context().active_document()) { + auto maybe_link = document->query_selector("link[rel=match]"sv); + if (maybe_link.is_error() || !maybe_link.value()) { + // To make sure that we fail the ref-test if the link is missing, load the error page. + load_html("

Failed to find <link rel="match" /> in ref test page!

Make sure you added it.", "about:blank"sv); + } else { + auto link = maybe_link.release_value(); + auto url = document->parse_url(link->get_attribute(Web::HTML::AttributeNames::href)); + load_url(url); + } + } + return; + } } void ConnectionFromClient::get_source()