Skip to content

Truly independent web browser

LibWeb: Report resource timing for unread fetch bodies

Andreas Klinged495ce5e851
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index 51ee9ce61e5..2a6145f0897 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -915,12 +915,18 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// and failure, and specs like HTML's preload algorithm expect to be able to call reportTiming from
// within processResponseConsumeBody. So we ensure report_timing_steps is set on error too, which allows
// reportTiming to work without asserting, and still produces useful timing data for failed fetches.
- auto setup_report_timing_steps = [&response, &fetch_params, timing_info] {
+ auto timing_reported = RefCountedFlag::create(false);
+ auto setup_report_timing_steps = [&response, &fetch_params, timing_info, timing_reported] {
// 1. Let unsafeEndTime be the unsafe shared current time.
auto unsafe_end_time = HighResolutionTime::unsafe_shared_current_time();
// 2. Set fetchParams’s controller’s report timing steps to the following steps given a global object global:
- fetch_params.controller()->set_report_timing_steps([&response, &fetch_params, timing_info, unsafe_end_time](JS::Object& global) mutable {
+ fetch_params.controller()->set_report_timing_steps([&response, &fetch_params, timing_info, unsafe_end_time, timing_reported](JS::Object& global) mutable {
+ // NB: Network completion and consuming the response body can both request a timing report.
+ if (timing_reported->value())
+ return;
+ timing_reported->set_value(true);
+
// 1. If fetchParams’s request’s URL’s scheme is not an HTTP(S) scheme, then return.
if (!Infrastructure::is_http_or_https_scheme(fetch_params.request()->url().scheme()))
return;
@@ -973,13 +979,28 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
});
};
- // 3. Let processResponseEndOfBody be the following steps:
- auto process_response_end_of_body = [&fetch_params, &response, setup_report_timing_steps] {
+ // NB: Share step 3 of processResponseEndOfBodyTask with the network-completion timing path.
+ auto report_timing_if_appropriate = [&fetch_params] {
+ // 3. If fetchParams’s request’s initiator type is non-null and fetchParams’s request’s client’s global
+ // object is fetchParams’s task destination, then run fetchParams’s controller’s report timing steps
+ // given fetchParams’s request’s client’s global object.
+ // AD-HOC: Not when this fetch consumed a preload that reports its own timing. Other engines report a single
+ // entry for a preloaded resource and its consumer.
+ auto client = fetch_params.request()->client();
+ auto const* task_destination_global_object = fetch_params.task_destination().get_pointer<GC::Ref<JS::Object>>();
+ if (client != nullptr && task_destination_global_object != nullptr && !fetch_params.preload_reports_timing()) {
+ if (fetch_params.request()->initiator_type().has_value() && &client->global_object() == task_destination_global_object->ptr())
+ fetch_params.controller()->report_timing(client->global_object());
+ }
+ };
+
+ // 4. Let processResponseEndOfBody be the following steps:
+ auto process_response_end_of_body = [&fetch_params, &response, setup_report_timing_steps, report_timing_if_appropriate] {
// 1-2. (See setup_report_timing_steps above)
setup_report_timing_steps();
- // 4. Let processResponseEndOfBodyTask be the following steps:
- auto process_response_end_of_body_task = GC::create_function(GC::Heap::the(), [&fetch_params, &response] {
+ // 3. Let processResponseEndOfBodyTask be the following steps:
+ auto process_response_end_of_body_task = GC::create_function(GC::Heap::the(), [&fetch_params, &response, report_timing_if_appropriate] {
// 1. Set fetchParams’s request’s done flag.
fetch_params.request()->set_done(true);
end_rendering_pending_operation(fetch_params.controller().ptr());
@@ -989,24 +1010,14 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
if (fetch_params.algorithms()->process_response_end_of_body())
(fetch_params.algorithms()->process_response_end_of_body())(response);
- // 3. If fetchParams’s request’s initiator type is non-null and fetchParams’s request’s client’s global
- // object is fetchParams’s task destination, then run fetchParams’s controller’s report timing steps
- // given fetchParams’s request’s client’s global object.
- // AD-HOC: Not when this fetch consumed a preload that reports its own timing. Other engines report a single
- // entry for a preloaded resource and its consumer.
- auto client = fetch_params.request()->client();
- auto const* task_destination_global_object = fetch_params.task_destination().get_pointer<GC::Ref<JS::Object>>();
- if (client != nullptr && task_destination_global_object != nullptr && !fetch_params.preload_reports_timing()) {
- if (fetch_params.request()->initiator_type().has_value() && &client->global_object() == task_destination_global_object->ptr())
- fetch_params.controller()->report_timing(client->global_object());
- }
+ report_timing_if_appropriate();
});
- // 5. Queue a fetch task to run processResponseEndOfBodyTask with fetchParams’s task destination.
+ // 4. Queue a fetch task to run processResponseEndOfBodyTask with fetchParams’s task destination.
Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), move(process_response_end_of_body_task));
};
- // 4. If fetchParams’s process response is non-null, then queue a fetch task to run fetchParams’s process response
+ // 5. If fetchParams’s process response is non-null, then queue a fetch task to run fetchParams’s process response
// given response, with fetchParams’s task destination.
if (fetch_params.algorithms()->process_response()) {
Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [&fetch_params, &response]() {
@@ -1014,9 +1025,18 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
}));
}
- // 5. Let internalResponse be response, if response is a network error; otherwise response’s internal response.
+ // 6. Let internalResponse be response, if response is a network error; otherwise response’s internal response.
auto internal_response = response.is_network_error() ? GC::Ref { response } : response.unsafe_response();
+ // NB: The network can finish while an unread response body still has buffered bytes. Its timing must not
+ // wait for the consumer to drain the stream.
+ if (internal_response->body() && fetch_params.request()->initiator_type().has_value()) {
+ internal_response->body()->when_network_complete(GC::create_function(GC::Heap::the(), [setup_report_timing_steps, report_timing_if_appropriate] {
+ setup_report_timing_steps();
+ report_timing_if_appropriate();
+ }));
+ }
+
if (Core::StatsLog::the() && internal_response->body())
track_rendering_pending_stream(fetch_params.controller().ptr(), *internal_response->body()->stream());
@@ -1048,11 +1068,11 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
VERIFY(!algorithms->process_response_end_of_body());
}
- // 6. If internalResponse’s body is null, then run processResponseEndOfBody.
+ // 7. If internalResponse’s body is null, then run processResponseEndOfBody.
if (!internal_response->body()) {
process_response_end_of_body();
}
- // 7. Otherwise:
+ // 8. Otherwise:
else {
switch (body_intent) {
case Engine::BodyIntent::DeliverStreamToConsumerAgent:
@@ -1127,7 +1147,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
}
}
- // 8. If fetchParams’s process response consume body is non-null, then:
+ // 9. If fetchParams’s process response consume body is non-null, then:
if (algorithms->process_response_consume_body()) {
// 1. Let processBody given nullOrBytes be this step: run fetchParams’s process response consume body given
// response and nullOrBytes.
@@ -1174,7 +1194,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
HTML::TemporaryExecutionContext const execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
auto success_steps = GC::create_function(GC::Heap::the(), [process_body, process_response_end_of_body](ByteBuffer bytes) {
- // NB: processResponseEndOfBody runs first, as step 7's flush algorithm would have: It sets up the fetch
+ // NB: processResponseEndOfBody runs first, as step 8's flush algorithm would have: It sets up the fetch
// controller's report timing steps, which the caller may invoke as soon as processBody has run.
process_response_end_of_body();
process_body->function()(move(bytes));
diff --git a/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp b/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
index e7616cada72..08a0a46e345 100644
--- a/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
@@ -36,8 +36,10 @@ void NetworkBodyPump::set_body(GC::Ref<Fetch::Infrastructure::Body> body)
}
// If the stream already completed before the body was set,
// we missed the terminal sniff call in handle_network_complete / handle_network_error.
- if (m_network_complete)
+ if (m_network_complete) {
m_body->set_sniff_bytes_complete();
+ m_body->set_network_complete();
+ }
if (m_network_failed)
m_body->set_sniff_bytes_failed();
}
@@ -124,6 +126,8 @@ void NetworkBodyPump::handle_network_complete()
finalize_cache_entry();
m_channel->close();
+ if (m_body)
+ m_body->set_network_complete();
}
void NetworkBodyPump::handle_network_error(StringView error_message)
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
index 94782996a45..ee3537e4a26 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
@@ -113,9 +113,11 @@ GC::Ref<Body> Body::create_from_source(JS::Realm& realm, FetchBody fetch_body)
return create(stream, move(fetch_body));
}
+// NB: Source-backed bodies are complete even when their streams still have queued bytes.
Body::Body(GC::Ref<Streams::ReadableStream> stream, FetchBody fetch_body)
: m_stream(stream)
, m_fetch_body(move(fetch_body))
+ , m_network_complete(m_fetch_body.source().has_value() || stream->is_closed())
{
}
@@ -124,6 +126,7 @@ void Body::visit_edges(Cell::Visitor& visitor)
Base::visit_edges(visitor);
visitor.visit(m_stream);
visitor.visit(m_sniff_bytes_callback);
+ visitor.visit(m_network_complete_callback);
}
void Body::set_source(Core::ImmutableBytes source, Optional<u64> length)
@@ -172,6 +175,23 @@ void Body::notify_sniff_bytes_waiter()
callback->function()(sniff_bytes.value());
}
+void Body::when_network_complete(ProcessEndOfBodyCallback callback)
+{
+ if (m_network_complete) {
+ callback->function()();
+ return;
+ }
+ VERIFY(!m_network_complete_callback);
+ m_network_complete_callback = callback;
+}
+
+void Body::set_network_complete()
+{
+ m_network_complete = true;
+ if (auto callback = exchange(m_network_complete_callback, nullptr))
+ callback->function()();
+}
+
// https://fetch.spec.whatwg.org/#concept-body-clone
GC::Ref<Body> Body::clone(JS::Realm& realm)
{
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h
index 10ac764c1e0..2eada85926b 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h
@@ -107,6 +107,9 @@ public:
void set_sniff_bytes_complete();
void set_sniff_bytes_failed();
+ void when_network_complete(ProcessEndOfBodyCallback);
+ void set_network_complete();
+
[[nodiscard]] GC::Ref<Body> clone(JS::Realm&);
void fully_read(JS::Realm&, ProcessBodyCallback process_body, ProcessBodyErrorCallback process_body_error, TaskDestination) const;
@@ -128,6 +131,8 @@ private:
FetchBody m_fetch_body;
GC::Ptr<GC::Function<void(FetchBody::SniffBytes)>> m_sniff_bytes_callback;
+ GC::Ptr<GC::Function<void()>> m_network_complete_callback;
+ bool m_network_complete { false };
};
// https://fetch.spec.whatwg.org/#body-with-type
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 385c4d7489e..f020eed588b 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -446,6 +446,8 @@ Text/input/wpt-import/permissions/idlharness.any.html
Text/input/wpt-import/permissions/idlharness.any.worker.html
Text/input/wpt-import/scroll-animations/scroll-timelines/idlharness.window.html
Text/input/wpt-import/serial/idlharness.https.any.html
+Text/input/wpt-import/server-timing/idlharness.https.any.html
+Text/input/wpt-import/server-timing/idlharness.https.any.worker.html
Text/input/wpt-import/speech-api/idlharness.https.window.html
Text/input/wpt-import/streams/idlharness.any.html
Text/input/wpt-import/svg/idlharness.window.html
diff --git a/Tests/LibWeb/Text/expected/Fetch/fetch-unread-resource-timing.txt b/Tests/LibWeb/Text/expected/Fetch/fetch-unread-resource-timing.txt
new file mode 100644
index 00000000000..342b9fd7d21
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Fetch/fetch-unread-resource-timing.txt
@@ -0,0 +1,16 @@
+body used before timing: false
+timing duration is nonnegative: true
+server timing entries: 1
+metric name: db
+metric duration: 12.5
+metric description: cache
+body content retained: true
+resource entries: true
+body used before timing: false
+timing duration is nonnegative: true
+server timing entries: 1
+metric name: db
+metric duration: 12.5
+metric description: cache
+body content retained: true
+resource entries: true
diff --git a/Tests/LibWeb/Text/expected/wpt-import/server-timing/idlharness.https.any.txt b/Tests/LibWeb/Text/expected/wpt-import/server-timing/idlharness.https.any.txt
new file mode 100644
index 00000000000..fb848a9a9aa
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/server-timing/idlharness.https.any.txt
@@ -0,0 +1,103 @@
+Harness status: OK
+
+Found 97 tests
+
+86 Pass
+11 Fail
+Pass idl_test setup
+Pass idl_test validation
+Pass Partial interface Performance: original interface defined
+Pass Partial interface Performance: member names are unique
+Pass Partial interface PerformanceResourceTiming: original interface defined
+Pass Partial interface PerformanceResourceTiming: valid exposure set
+Pass Partial interface PerformanceResourceTiming: member names are unique
+Pass Partial interface Performance[2]: member names are unique
+Pass PerformanceResourceTiming interface: existence and properties of interface object
+Pass PerformanceResourceTiming interface object length
+Pass PerformanceResourceTiming interface object name
+Pass PerformanceResourceTiming interface: existence and properties of interface prototype object
+Pass PerformanceResourceTiming interface: existence and properties of interface prototype object's "constructor" property
+Pass PerformanceResourceTiming interface: existence and properties of interface prototype object's @@unscopables property
+Pass PerformanceResourceTiming interface: attribute initiatorType
+Pass PerformanceResourceTiming interface: attribute deliveryType
+Pass PerformanceResourceTiming interface: attribute nextHopProtocol
+Pass PerformanceResourceTiming interface: attribute workerStart
+Pass PerformanceResourceTiming interface: attribute redirectStart
+Pass PerformanceResourceTiming interface: attribute redirectEnd
+Pass PerformanceResourceTiming interface: attribute fetchStart
+Pass PerformanceResourceTiming interface: attribute domainLookupStart
+Pass PerformanceResourceTiming interface: attribute domainLookupEnd
+Pass PerformanceResourceTiming interface: attribute connectStart
+Pass PerformanceResourceTiming interface: attribute connectEnd
+Pass PerformanceResourceTiming interface: attribute secureConnectionStart
+Pass PerformanceResourceTiming interface: attribute requestStart
+Pass PerformanceResourceTiming interface: attribute finalResponseHeadersStart
+Pass PerformanceResourceTiming interface: attribute firstInterimResponseStart
+Pass PerformanceResourceTiming interface: attribute responseStart
+Pass PerformanceResourceTiming interface: attribute responseEnd
+Fail PerformanceResourceTiming interface: attribute workerRouterEvaluationStart
+Fail PerformanceResourceTiming interface: attribute workerCacheLookupStart
+Fail PerformanceResourceTiming interface: attribute workerMatchedRouterSource
+Fail PerformanceResourceTiming interface: attribute workerFinalRouterSource
+Pass PerformanceResourceTiming interface: attribute transferSize
+Pass PerformanceResourceTiming interface: attribute encodedBodySize
+Pass PerformanceResourceTiming interface: attribute decodedBodySize
+Pass PerformanceResourceTiming interface: attribute responseStatus
+Pass PerformanceResourceTiming interface: attribute renderBlockingStatus
+Pass PerformanceResourceTiming interface: attribute contentType
+Fail PerformanceResourceTiming interface: attribute contentEncoding
+Pass PerformanceResourceTiming interface: operation toJSON()
+Pass PerformanceResourceTiming interface: attribute serverTiming
+Pass PerformanceResourceTiming must be primary interface of resource
+Pass Stringification of resource
+Pass PerformanceResourceTiming interface: resource must inherit property "initiatorType" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "deliveryType" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "nextHopProtocol" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "workerStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "redirectStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "redirectEnd" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "fetchStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "domainLookupStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "domainLookupEnd" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "connectStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "connectEnd" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "secureConnectionStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "requestStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "finalResponseHeadersStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "firstInterimResponseStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "responseStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "responseEnd" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "workerRouterEvaluationStart" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "workerCacheLookupStart" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "workerMatchedRouterSource" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "workerFinalRouterSource" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "transferSize" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "encodedBodySize" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "decodedBodySize" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "responseStatus" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "renderBlockingStatus" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "contentType" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "contentEncoding" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "toJSON()" with the proper type
+Fail PerformanceResourceTiming interface: default toJSON operation on resource
+Pass PerformanceResourceTiming interface: resource must inherit property "serverTiming" with the proper type
+Pass PerformanceServerTiming interface: existence and properties of interface object
+Pass PerformanceServerTiming interface object length
+Pass PerformanceServerTiming interface object name
+Pass PerformanceServerTiming interface: existence and properties of interface prototype object
+Pass PerformanceServerTiming interface: existence and properties of interface prototype object's "constructor" property
+Pass PerformanceServerTiming interface: existence and properties of interface prototype object's @@unscopables property
+Pass PerformanceServerTiming interface: attribute name
+Pass PerformanceServerTiming interface: attribute duration
+Pass PerformanceServerTiming interface: attribute description
+Pass PerformanceServerTiming interface: operation toJSON()
+Pass PerformanceServerTiming must be primary interface of server
+Pass Stringification of server
+Pass PerformanceServerTiming interface: server must inherit property "name" with the proper type
+Pass PerformanceServerTiming interface: server must inherit property "duration" with the proper type
+Pass PerformanceServerTiming interface: server must inherit property "description" with the proper type
+Pass PerformanceServerTiming interface: server must inherit property "toJSON()" with the proper type
+Pass PerformanceServerTiming interface: default toJSON operation on server
+Pass Performance interface: operation clearResourceTimings()
+Pass Performance interface: operation setResourceTimingBufferSize(unsigned long)
+Pass Performance interface: attribute onresourcetimingbufferfull
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/server-timing/idlharness.https.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/server-timing/idlharness.https.any.worker.txt
new file mode 100644
index 00000000000..fb848a9a9aa
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/server-timing/idlharness.https.any.worker.txt
@@ -0,0 +1,103 @@
+Harness status: OK
+
+Found 97 tests
+
+86 Pass
+11 Fail
+Pass idl_test setup
+Pass idl_test validation
+Pass Partial interface Performance: original interface defined
+Pass Partial interface Performance: member names are unique
+Pass Partial interface PerformanceResourceTiming: original interface defined
+Pass Partial interface PerformanceResourceTiming: valid exposure set
+Pass Partial interface PerformanceResourceTiming: member names are unique
+Pass Partial interface Performance[2]: member names are unique
+Pass PerformanceResourceTiming interface: existence and properties of interface object
+Pass PerformanceResourceTiming interface object length
+Pass PerformanceResourceTiming interface object name
+Pass PerformanceResourceTiming interface: existence and properties of interface prototype object
+Pass PerformanceResourceTiming interface: existence and properties of interface prototype object's "constructor" property
+Pass PerformanceResourceTiming interface: existence and properties of interface prototype object's @@unscopables property
+Pass PerformanceResourceTiming interface: attribute initiatorType
+Pass PerformanceResourceTiming interface: attribute deliveryType
+Pass PerformanceResourceTiming interface: attribute nextHopProtocol
+Pass PerformanceResourceTiming interface: attribute workerStart
+Pass PerformanceResourceTiming interface: attribute redirectStart
+Pass PerformanceResourceTiming interface: attribute redirectEnd
+Pass PerformanceResourceTiming interface: attribute fetchStart
+Pass PerformanceResourceTiming interface: attribute domainLookupStart
+Pass PerformanceResourceTiming interface: attribute domainLookupEnd
+Pass PerformanceResourceTiming interface: attribute connectStart
+Pass PerformanceResourceTiming interface: attribute connectEnd
+Pass PerformanceResourceTiming interface: attribute secureConnectionStart
+Pass PerformanceResourceTiming interface: attribute requestStart
+Pass PerformanceResourceTiming interface: attribute finalResponseHeadersStart
+Pass PerformanceResourceTiming interface: attribute firstInterimResponseStart
+Pass PerformanceResourceTiming interface: attribute responseStart
+Pass PerformanceResourceTiming interface: attribute responseEnd
+Fail PerformanceResourceTiming interface: attribute workerRouterEvaluationStart
+Fail PerformanceResourceTiming interface: attribute workerCacheLookupStart
+Fail PerformanceResourceTiming interface: attribute workerMatchedRouterSource
+Fail PerformanceResourceTiming interface: attribute workerFinalRouterSource
+Pass PerformanceResourceTiming interface: attribute transferSize
+Pass PerformanceResourceTiming interface: attribute encodedBodySize
+Pass PerformanceResourceTiming interface: attribute decodedBodySize
+Pass PerformanceResourceTiming interface: attribute responseStatus
+Pass PerformanceResourceTiming interface: attribute renderBlockingStatus
+Pass PerformanceResourceTiming interface: attribute contentType
+Fail PerformanceResourceTiming interface: attribute contentEncoding
+Pass PerformanceResourceTiming interface: operation toJSON()
+Pass PerformanceResourceTiming interface: attribute serverTiming
+Pass PerformanceResourceTiming must be primary interface of resource
+Pass Stringification of resource
+Pass PerformanceResourceTiming interface: resource must inherit property "initiatorType" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "deliveryType" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "nextHopProtocol" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "workerStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "redirectStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "redirectEnd" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "fetchStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "domainLookupStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "domainLookupEnd" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "connectStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "connectEnd" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "secureConnectionStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "requestStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "finalResponseHeadersStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "firstInterimResponseStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "responseStart" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "responseEnd" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "workerRouterEvaluationStart" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "workerCacheLookupStart" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "workerMatchedRouterSource" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "workerFinalRouterSource" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "transferSize" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "encodedBodySize" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "decodedBodySize" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "responseStatus" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "renderBlockingStatus" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "contentType" with the proper type
+Fail PerformanceResourceTiming interface: resource must inherit property "contentEncoding" with the proper type
+Pass PerformanceResourceTiming interface: resource must inherit property "toJSON()" with the proper type
+Fail PerformanceResourceTiming interface: default toJSON operation on resource
+Pass PerformanceResourceTiming interface: resource must inherit property "serverTiming" with the proper type
+Pass PerformanceServerTiming interface: existence and properties of interface object
+Pass PerformanceServerTiming interface object length
+Pass PerformanceServerTiming interface object name
+Pass PerformanceServerTiming interface: existence and properties of interface prototype object
+Pass PerformanceServerTiming interface: existence and properties of interface prototype object's "constructor" property
+Pass PerformanceServerTiming interface: existence and properties of interface prototype object's @@unscopables property
+Pass PerformanceServerTiming interface: attribute name
+Pass PerformanceServerTiming interface: attribute duration
+Pass PerformanceServerTiming interface: attribute description
+Pass PerformanceServerTiming interface: operation toJSON()
+Pass PerformanceServerTiming must be primary interface of server
+Pass Stringification of server
+Pass PerformanceServerTiming interface: server must inherit property "name" with the proper type
+Pass PerformanceServerTiming interface: server must inherit property "duration" with the proper type
+Pass PerformanceServerTiming interface: server must inherit property "description" with the proper type
+Pass PerformanceServerTiming interface: server must inherit property "toJSON()" with the proper type
+Pass PerformanceServerTiming interface: default toJSON operation on server
+Pass Performance interface: operation clearResourceTimings()
+Pass Performance interface: operation setResourceTimingBufferSize(unsigned long)
+Pass Performance interface: attribute onresourcetimingbufferfull
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/Fetch/fetch-unread-resource-timing.html b/Tests/LibWeb/Text/input/Fetch/fetch-unread-resource-timing.html
new file mode 100644
index 00000000000..73b21198f42
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Fetch/fetch-unread-resource-timing.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ asyncTest(async done => {
+ const server = httpTestServer();
+ const body = "An unread response still has resource timing.";
+ const url = await server.createEcho("GET", `/unread-timing-${crypto.randomUUID()}`, {
+ status: 200,
+ headers: {
+ "Content-Type": "text/plain",
+ "Cache-Control": "max-age=3600",
+ "Access-Control-Allow-Origin": "*",
+ "Access-Control-Expose-Headers": "Server-Timing",
+ "Timing-Allow-Origin": "*",
+ "Server-Timing": 'db;dur=12.5;desc="cache"',
+ },
+ body,
+ });
+ for (let attempt = 1; attempt <= 2; ++attempt) {
+ const observed = new Promise(resolve => {
+ const observer = new PerformanceObserver(list => {
+ const entry = list.getEntries().find(entry => entry.name === url);
+ if (entry) {
+ observer.disconnect();
+ resolve(entry);
+ }
+ });
+ observer.observe({ entryTypes: ["resource"] });
+ });
+
+ const response = await fetch(url);
+ const entry = await observed;
+ println(`body used before timing: ${response.bodyUsed}`);
+ println(`timing duration is nonnegative: ${entry.duration >= 0}`);
+ println(`server timing entries: ${entry.serverTiming.length}`);
+ println(`metric name: ${entry.serverTiming[0].name}`);
+ println(`metric duration: ${entry.serverTiming[0].duration}`);
+ println(`metric description: ${entry.serverTiming[0].description}`);
+ println(`body content retained: ${await response.text() === body}`);
+ println(`resource entries: ${performance.getEntriesByName(url).length === attempt}`);
+ }
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/interfaces/performance-timeline.idl b/Tests/LibWeb/Text/input/wpt-import/interfaces/performance-timeline.idl
new file mode 100644
index 00000000000..f06ed9adb6c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/interfaces/performance-timeline.idl
@@ -0,0 +1,51 @@
+// GENERATED CONTENT - DO NOT EDIT
+// Content was automatically extracted by Reffy into webref
+// (https://github.com/w3c/webref)
+// Source: Performance Timeline (https://w3c.github.io/performance-timeline/)
+
+partial interface Performance {
+ PerformanceEntryList getEntries ();
+ PerformanceEntryList getEntriesByType (DOMString type);
+ PerformanceEntryList getEntriesByName (DOMString name, optional DOMString type);
+};
+typedef sequence<PerformanceEntry> PerformanceEntryList;
+
+[Exposed=(Window,Worker)]
+interface PerformanceEntry {
+ readonly attribute unsigned long long id;
+ readonly attribute DOMString name;
+ readonly attribute DOMString entryType;
+ readonly attribute DOMHighResTimeStamp startTime;
+ readonly attribute DOMHighResTimeStamp duration;
+ readonly attribute unsigned long long navigationId;
+ [Default] object toJSON();
+};
+
+callback PerformanceObserverCallback = undefined (PerformanceObserverEntryList entries,
+ PerformanceObserver observer,
+ optional PerformanceObserverCallbackOptions options = {});
+[Exposed=(Window,Worker)]
+interface PerformanceObserver {
+ constructor(PerformanceObserverCallback callback);
+ undefined observe (optional PerformanceObserverInit options = {});
+ undefined disconnect ();
+ PerformanceEntryList takeRecords();
+ [SameObject] static readonly attribute FrozenArray<DOMString> supportedEntryTypes;
+};
+
+dictionary PerformanceObserverCallbackOptions {
+ unsigned long long droppedEntriesCount;
+};
+
+dictionary PerformanceObserverInit {
+ sequence<DOMString> entryTypes;
+ DOMString type;
+ boolean buffered;
+};
+
+[Exposed=(Window,Worker)]
+interface PerformanceObserverEntryList {
+ PerformanceEntryList getEntries();
+ PerformanceEntryList getEntriesByType (DOMString type);
+ PerformanceEntryList getEntriesByName (DOMString name, optional DOMString type);
+};
diff --git a/Tests/LibWeb/Text/input/wpt-import/interfaces/resource-timing.idl b/Tests/LibWeb/Text/input/wpt-import/interfaces/resource-timing.idl
new file mode 100644
index 00000000000..1391b09022e
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/interfaces/resource-timing.idl
@@ -0,0 +1,48 @@
+// GENERATED CONTENT - DO NOT EDIT
+// Content was automatically extracted by Reffy into webref
+// (https://github.com/w3c/webref)
+// Source: Resource Timing (https://w3c.github.io/resource-timing/)
+
+[Exposed=(Window,Worker)]
+interface PerformanceResourceTiming : PerformanceEntry {
+ readonly attribute DOMString initiatorType;
+ readonly attribute DOMString deliveryType;
+ readonly attribute ByteString nextHopProtocol;
+ readonly attribute DOMHighResTimeStamp workerStart;
+ readonly attribute DOMHighResTimeStamp redirectStart;
+ readonly attribute DOMHighResTimeStamp redirectEnd;
+ readonly attribute DOMHighResTimeStamp fetchStart;
+ readonly attribute DOMHighResTimeStamp domainLookupStart;
+ readonly attribute DOMHighResTimeStamp domainLookupEnd;
+ readonly attribute DOMHighResTimeStamp connectStart;
+ readonly attribute DOMHighResTimeStamp connectEnd;
+ readonly attribute DOMHighResTimeStamp secureConnectionStart;
+ readonly attribute DOMHighResTimeStamp requestStart;
+ readonly attribute DOMHighResTimeStamp finalResponseHeadersStart;
+ readonly attribute DOMHighResTimeStamp firstInterimResponseStart;
+ readonly attribute DOMHighResTimeStamp responseStart;
+ readonly attribute DOMHighResTimeStamp responseEnd;
+ readonly attribute DOMHighResTimeStamp workerRouterEvaluationStart;
+ readonly attribute DOMHighResTimeStamp workerCacheLookupStart;
+ readonly attribute DOMString workerMatchedRouterSource;
+ readonly attribute DOMString workerFinalRouterSource;
+ readonly attribute unsigned long long transferSize;
+ readonly attribute unsigned long long encodedBodySize;
+ readonly attribute unsigned long long decodedBodySize;
+ readonly attribute unsigned short responseStatus;
+ readonly attribute RenderBlockingStatusType renderBlockingStatus;
+ readonly attribute DOMString contentType;
+ readonly attribute DOMString contentEncoding;
+ [Default] object toJSON();
+};
+
+enum RenderBlockingStatusType {
+ "blocking",
+ "non-blocking"
+};
+
+partial interface Performance {
+ undefined clearResourceTimings ();
+ undefined setResourceTimingBufferSize (unsigned long maxSize);
+ attribute EventHandler onresourcetimingbufferfull;
+ };
diff --git a/Tests/LibWeb/Text/input/wpt-import/interfaces/server-timing.idl b/Tests/LibWeb/Text/input/wpt-import/interfaces/server-timing.idl
new file mode 100644
index 00000000000..ef2a761dfca
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/interfaces/server-timing.idl
@@ -0,0 +1,17 @@
+// GENERATED CONTENT - DO NOT EDIT
+// Content was automatically extracted by Reffy into webref
+// (https://github.com/w3c/webref)
+// Source: Server Timing (https://w3c.github.io/server-timing/)
+
+[Exposed=(Window,Worker)]
+interface PerformanceServerTiming {
+ readonly attribute DOMString name;
+ readonly attribute DOMHighResTimeStamp duration;
+ readonly attribute DOMString description;
+ [Default] object toJSON();
+};
+
+[Exposed=(Window,Worker)]
+partial interface PerformanceResourceTiming {
+ readonly attribute FrozenArray<PerformanceServerTiming> serverTiming;
+};
diff --git a/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.html b/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.html
new file mode 100644
index 00000000000..f393dd2e4ad
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<script>
+self.GLOBAL = {
+ isWindow: function() { return true; },
+ isWorker: function() { return false; },
+ isShadowRealm: function() { return false; },
+};
+</script>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="../resources/WebIDLParser.js"></script>
+<script src="../resources/idlharness.js"></script>
+<div id=log></div>
+<script src="../server-timing/idlharness.https.any.js"></script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.js b/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.js
new file mode 100644
index 00000000000..44bffcf59e6
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.js
@@ -0,0 +1,29 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+// META: timeout=long
+
+'use strict';
+
+// https://w3c.github.io/server-timing/
+
+idl_test(
+ ['resource-timing', 'server-timing'],
+ ['performance-timeline', 'hr-time', 'dom'],
+ idl_array => new Promise((resolve, reject) => {
+ new PerformanceObserver(entries => {
+ entries.getEntries().forEach(e => {
+ if (!e.name.endsWith('blue.png'))
+ return;
+
+ self.resource = e;
+ self.server = e.serverTiming[0];
+ idl_array.add_objects({
+ PerformanceResourceTiming: ['resource'],
+ PerformanceServerTiming: ['server']
+ });
+ resolve();
+ })
+ }).observe({entryTypes: ['resource']});
+ fetch('resources/blue.png');
+ })
+);
diff --git a/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.worker.html b/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.worker.html
new file mode 100644
index 00000000000..f47097bfe46
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.worker.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<div id=log></div>
+<script>
+fetch_tests_from_worker(new Worker("../server-timing/idlharness.https.any.worker.js"));
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.worker.js b/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.worker.js
new file mode 100644
index 00000000000..2ce8f760b66
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/server-timing/idlharness.https.any.worker.js
@@ -0,0 +1,11 @@
+
+self.GLOBAL = {
+ isWindow: function() { return false; },
+ isWorker: function() { return true; },
+ isShadowRealm: function() { return false; },
+};
+importScripts("/resources/testharness.js");
+importScripts("/resources/WebIDLParser.js")
+importScripts("/resources/idlharness.js")
+importScripts("/server-timing/idlharness.https.any.js");
+done();
diff --git a/Tests/LibWeb/Text/input/wpt-import/server-timing/resources/blue.png b/Tests/LibWeb/Text/input/wpt-import/server-timing/resources/blue.png
new file mode 100644
index 00000000000..4498dd258a2
Binary files /dev/null and b/Tests/LibWeb/Text/input/wpt-import/server-timing/resources/blue.png differ
diff --git a/Tests/LibWeb/Text/input/wpt-import/server-timing/resources/blue.png.sub.headers b/Tests/LibWeb/Text/input/wpt-import/server-timing/resources/blue.png.sub.headers
new file mode 100644
index 00000000000..948e7f0190a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/server-timing/resources/blue.png.sub.headers
@@ -0,0 +1 @@
+Server-Timing: metric2; dur=2.1; desc=blue.png