diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index 9c36a255982..ddc25ac7630 100644 --- a/Services/WebContent/ConnectionFromClient.cpp +++ b/Services/WebContent/ConnectionFromClient.cpp @@ -411,13 +411,35 @@ void ConnectionFromClient::debug_request(u64 page_id, ByteString const& request, if (request == "load-reference-page") { if (auto* document = page->page().top_level_browsing_context().active_document()) { - auto maybe_link = document->query_selector("link[rel=match]"sv); + auto has_mismatch_selector = false; + + auto maybe_link = [&]() -> Web::WebIDL::ExceptionOr> { + auto maybe_link = document->query_selector("link[rel=match]"sv); + if (maybe_link.is_error() || maybe_link.value()) + return maybe_link; + + auto maybe_mismatch_link = document->query_selector("link[rel=mismatch]"sv); + if (maybe_mismatch_link.is_error() || maybe_mismatch_link.value()) { + has_mismatch_selector = maybe_mismatch_link.value(); + return maybe_mismatch_link; + } + + return nullptr; + }(); + 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(page_id, "

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

Make sure you added it."); + load_html(page_id, "

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

Make sure you added it."); } else { auto link = maybe_link.release_value(); auto url = document->parse_url(link->get_attribute_value(Web::HTML::AttributeNames::href)); + if (url.query().has_value() && !url.query()->is_empty()) { + load_html(page_id, "

Invalid ref test link - query string must be empty

"); + return; + } + if (has_mismatch_selector) + url.set_query("mismatch"_string); + load_url(page_id, url); } } diff --git a/Tests/LibWeb/Ref/expected/mismatch-test-ref.html b/Tests/LibWeb/Ref/expected/mismatch-test-ref.html new file mode 100644 index 00000000000..87e32b71a0c --- /dev/null +++ b/Tests/LibWeb/Ref/expected/mismatch-test-ref.html @@ -0,0 +1,6 @@ + + diff --git a/Tests/LibWeb/Ref/input/mismatch-test.html b/Tests/LibWeb/Ref/input/mismatch-test.html new file mode 100644 index 00000000000..d47a72dab7c --- /dev/null +++ b/Tests/LibWeb/Ref/input/mismatch-test.html @@ -0,0 +1,7 @@ + + + diff --git a/UI/Headless/Test.cpp b/UI/Headless/Test.cpp index 31b5f2bcec2..9bf4c35cea9 100644 --- a/UI/Headless/Test.cpp +++ b/UI/Headless/Test.cpp @@ -247,7 +247,10 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url, }); auto handle_completed_test = [&test, url]() -> ErrorOr { - if (test.actual_screenshot->visually_equals(*test.expectation_screenshot)) + VERIFY(test.ref_test_expectation_type.has_value()); + auto should_match = test.ref_test_expectation_type == RefTestExpectationType::Match; + auto screenshot_matches = test.actual_screenshot->visually_equals(*test.expectation_screenshot); + if (should_match == screenshot_matches) return TestResult::Pass; if (Application::the().dump_failed_ref_tests) { @@ -291,6 +294,11 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url, view.on_load_finish = [&view, &test, on_test_complete = move(on_test_complete)](auto const&) { if (test.actual_screenshot) { + if (view.url().query().has_value() && view.url().query()->equals_ignoring_ascii_case("mismatch"sv)) { + test.ref_test_expectation_type = RefTestExpectationType::Mismatch; + } else { + test.ref_test_expectation_type = RefTestExpectationType::Match; + } view.take_screenshot()->when_resolved([&test, on_test_complete = move(on_test_complete)](RefPtr screenshot) { test.expectation_screenshot = move(screenshot); on_test_complete(); diff --git a/UI/Headless/Test.h b/UI/Headless/Test.h index d7ee5b78531..b4c9819239e 100644 --- a/UI/Headless/Test.h +++ b/UI/Headless/Test.h @@ -37,6 +37,11 @@ enum class TestResult { Crashed, }; +enum class RefTestExpectationType { + Match, + Mismatch, +}; + static constexpr StringView test_result_to_string(TestResult result) { switch (result) { @@ -69,6 +74,8 @@ struct Test { bool did_finish_test { false }; bool did_finish_loading { false }; + Optional ref_test_expectation_type {}; + RefPtr actual_screenshot {}; RefPtr expectation_screenshot {}; };