mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 01:40:46 +00:00
Tests: Replace load-reference-page
debug action with internals method
WPT reference tests can add metadata to tests to instruct the test runner how to interpret the results. Because of this, it is not enough to have an action that starts loading the (mis)match reference: we need the test runner to receive the metadata so it can act accordingly. This sets our test runner up for potentially supporting multiple (mis)match references, and fuzzy rendering matches - the latter will be implemented in the following commit.
This commit is contained in:
parent
0f642ecb5c
commit
e4b2253b63
Notes:
github-actions[bot]
2025-07-17 12:00:33 +00:00
Author: https://github.com/gmta
Commit: e4b2253b63
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5470
Reviewed-by: https://github.com/tcl3 ✅
12 changed files with 87 additions and 44 deletions
|
@ -1,9 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/JsonObject.h>
|
||||
#include <LibJS/Runtime/Date.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibUnicode/TimeZone.h>
|
||||
|
@ -12,6 +14,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/DOM/NodeList.h>
|
||||
#include <LibWeb/DOMURL/DOMURL.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
@ -19,7 +22,6 @@
|
|||
#include <LibWeb/Page/InputEvent.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/Painting/PaintableBox.h>
|
||||
#include <LibWeb/Painting/ViewportPaintable.h>
|
||||
|
||||
namespace Web::Internals {
|
||||
|
||||
|
@ -50,6 +52,39 @@ void Internals::set_test_timeout(double milliseconds)
|
|||
page().client().page_did_set_test_timeout(milliseconds);
|
||||
}
|
||||
|
||||
// https://web-platform-tests.org/writing-tests/reftests.html#components-of-a-reftest
|
||||
WebIDL::ExceptionOr<void> Internals::load_reference_test_metadata()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& page = this->page();
|
||||
|
||||
auto* document = page.top_level_browsing_context().active_document();
|
||||
if (!document)
|
||||
return vm.throw_completion<JS::InternalError>("No active document available"sv);
|
||||
|
||||
JsonObject metadata;
|
||||
|
||||
// Collect all <link rel="match"> and <link rel="mismatch"> references.
|
||||
auto collect_references = [&vm, &document](StringView type) -> WebIDL::ExceptionOr<JsonArray> {
|
||||
JsonArray references;
|
||||
auto reference_nodes = TRY(document->query_selector_all(MUST(String::formatted("link[rel={}]", type))));
|
||||
for (size_t i = 0; i < reference_nodes->length(); ++i) {
|
||||
auto const* reference_node = reference_nodes->item(i);
|
||||
auto href = as<DOM::Element>(reference_node)->get_attribute_value(HTML::AttributeNames::href);
|
||||
auto url = document->encoding_parse_url(href);
|
||||
if (!url.has_value())
|
||||
return vm.throw_completion<JS::InternalError>(MUST(String::formatted("Failed to construct URL for '{}'", href)));
|
||||
references.must_append(url->to_string());
|
||||
}
|
||||
return references;
|
||||
};
|
||||
metadata.set("match_references"sv, TRY(collect_references("match"sv)));
|
||||
metadata.set("mismatch_references"sv, TRY(collect_references("mismatch"sv)));
|
||||
|
||||
page.client().page_did_receive_reference_test_metadata(metadata);
|
||||
return {};
|
||||
}
|
||||
|
||||
void Internals::gc()
|
||||
{
|
||||
vm().heap().collect_garbage();
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
|
||||
void signal_test_is_done(String const& text);
|
||||
void set_test_timeout(double milliseconds);
|
||||
WebIDL::ExceptionOr<void> load_reference_test_metadata();
|
||||
|
||||
WebIDL::ExceptionOr<String> set_time_zone(StringView time_zone);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ interface Internals {
|
|||
|
||||
undefined signalTestIsDone(DOMString text);
|
||||
undefined setTestTimeout(double milliseconds);
|
||||
undefined loadReferenceTestMetadata();
|
||||
|
||||
DOMString setTimeZone(DOMString timeZone);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue