Truly independent web browser
LibWeb: Read failed object and image response bodies
Shannon Booth200fe93aa71f
diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cppindex a46c57a128b..1e9cc2029ea 100644--- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp@@ -285,7 +285,20 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()auto& realm = HTML::relevant_realm(*this);auto& global = document().relevant_settings_object().realm().global_object();- if (response->is_network_error() || !Fetch::Infrastructure::is_ok_status(response->status())) {+ if (response->is_network_error()) {+ resource_did_fail();+ return;+ }++ if (!Fetch::Infrastructure::is_ok_status(response->status())) {+ // NB: Fetch only reports the response's timing once its body has been fully read, so read it without+ // holding back the failure.+ if (auto body = response->body()) {+ auto ignore_chunk = GC::create_function(GC::Heap::the(), [](ByteBuffer) { });+ auto ignore_end_of_body = GC::create_function(GC::Heap::the(), [] { });+ auto ignore_body_error = GC::create_function(GC::Heap::the(), [](JS::Value) { });+ (void)body->incrementally_read(realm, ignore_chunk, ignore_end_of_body, ignore_body_error, GC::Ref { global });+ }resource_did_fail();return;}diff --git a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp b/Libraries/LibWeb/HTML/SharedResourceRequest.cppindex b8d7ac080c9..b28e891fb44 100644--- a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp+++ b/Libraries/LibWeb/HTML/SharedResourceRequest.cpp@@ -161,7 +161,18 @@ void SharedResourceRequest::fetch_resource(GC::Ref<Fetch::Infrastructure::Reques});// Check for failed fetch response- if (!Fetch::Infrastructure::is_ok_status(response->status()) || !response->body()) {+ if (!response->body()) {+ self->handle_failed_fetch();+ return;+ }++ if (!Fetch::Infrastructure::is_ok_status(response->status())) {+ // NB: Fetch only reports the response's timing once its body has been fully read, so read it without+ // holding back the failure.+ auto ignore_chunk = GC::create_function(GC::Heap::the(), [](ByteBuffer) { });+ auto ignore_end_of_body = GC::create_function(GC::Heap::the(), [] { });+ auto ignore_body_error = GC::create_function(GC::Heap::the(), [](JS::Value) { });+ (void)response->body()->incrementally_read(realm, ignore_chunk, ignore_end_of_body, ignore_body_error, GC::Ref { realm.global_object() });self->handle_failed_fetch();return;}diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 883d2e810c4..3a07e8028ee 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -573,6 +573,8 @@ Text/input/wpt-import/preload/prefetch-events.htmlText/input/wpt-import/resource-timing/initiator-type/img.htmlText/input/wpt-import/resource-timing/initiator-type/img-srcset.htmlText/input/wpt-import/resource-timing/initiator-type/picture.html+Text/input/wpt-import/resource-timing/object-not-found-adds-entry.html+Text/input/wpt-import/resource-timing/status-codes-create-entry.html[Skipped]; Needs vertical-rl inline geometry fidelity beyond the binary transposediff --git a/Tests/LibWeb/Text/expected/wpt-import/resource-timing/object-not-found-adds-entry.txt b/Tests/LibWeb/Text/expected/wpt-import/resource-timing/object-not-found-adds-entry.txtnew file mode 100644index 00000000000..93ab15c931f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/resource-timing/object-not-found-adds-entry.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 3 tests++3 Pass+Pass Verify that a 200 null-typed object emits an entry.+Pass Verify that a 404 null-typed object emits an entry.+Pass Verify that a 404 img-typed object emits an entry.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/resource-timing/status-codes-create-entry.txt b/Tests/LibWeb/Text/expected/wpt-import/resource-timing/status-codes-create-entry.txtnew file mode 100644index 00000000000..02e2d3da497--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/resource-timing/status-codes-create-entry.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Make sure all status codes are reported\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/resource-timing/object-not-found-adds-entry.html b/Tests/LibWeb/Text/input/wpt-import/resource-timing/object-not-found-adds-entry.htmlnew file mode 100644index 00000000000..dcacb8be16a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/resource-timing/object-not-found-adds-entry.html@@ -0,0 +1,29 @@+<!DOCTYPE html>+<html>+<head>+<meta charset="utf-8" />+<title>This test validates that object resource emit resource timing entries.</title>+<link rel="author" title="Google" href="http://www.google.com/" />+<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming"/>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="resources/entry-invariants.js"></script>+<script src="resources/resource-loaders.js"></script>+</head>+<body>+<script>+attribute_test(+ load.null_object, "resources/status-code.py?status=200&type=none",+ invariants.assert_tao_pass_no_redirect_http,+ "Verify that a 200 null-typed object emits an entry.");++attribute_test(+ load.null_object, "resources/status-code.py?status=404&type=none",+ invariants.assert_tao_pass_no_redirect_http,+ "Verify that a 404 null-typed object emits an entry.");++attribute_test(+ load.image_object, "resources/status-code.py?status=404&type=img",+ invariants.assert_tao_pass_no_redirect_http,+ "Verify that a 404 img-typed object emits an entry.");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/entry-invariants.js b/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/entry-invariants.jsnew file mode 100644index 00000000000..583cda86dd8--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/entry-invariants.js@@ -0,0 +1,522 @@+const await_with_timeout = async (delay, message, promise, cleanup = ()=>{}) => {+ let timeout_id;+ const timeout = new Promise((_, reject) => {+ timeout_id = step_timeout(() =>+ reject(new DOMException(message, "TimeoutError")), delay)+ });+ let result = null;+ try {+ result = await Promise.race([promise, timeout]);+ clearTimeout(timeout_id);+ } finally {+ cleanup();+ }+ return result;+};++// Asserts that the given attributes are present in 'entry' and hold equal+// values.+const assert_all_equal_ = (entry, attributes) => {+ let first = attributes[0];+ attributes.slice(1).forEach(other => {+ assert_equals(entry[first], entry[other],+ `${first} should be equal to ${other}`);+ });+}++// Asserts that the given attributes are present in 'entry' and hold values+// that are sorted in the same order as given in 'attributes'.+const assert_ordered_ = (entry, attributes) => {+ let before = attributes[0];+ attributes.slice(1).forEach(after => {+ assert_greater_than_equal(entry[after], entry[before],+ `${after} should be greater than ${before}`);+ before = after;+ });+}++// Asserts that the given attributes are present in 'entry' and hold a value of+// 0.+const assert_zeroed_ = (entry, attributes) => {+ attributes.forEach(attribute => {+ assert_equals(entry[attribute], 0, `${attribute} should be 0`);+ });+}++// Asserts that the given attributes are present in 'entry' and hold a value of+// 0 or more.+const assert_not_negative_ = (entry, attributes) => {+ attributes.forEach(attribute => {+ assert_greater_than_equal(entry[attribute], 0,+ `${attribute} should be greater than or equal to 0`);+ });+}++// Asserts that the given attributes are present in 'entry' and hold a value+// greater than 0.+const assert_positive_ = (entry, attributes) => {+ attributes.forEach(attribute => {+ assert_greater_than(entry[attribute], 0,+ `${attribute} should be greater than 0`);+ });+}++const invariants = {+ // Asserts that attributes of the given PerformanceResourceTiming entry match+ // what the spec dictates for any resource fetched over HTTP without+ // redirects but passing the Timing-Allow-Origin checks.+ assert_tao_pass_no_redirect_http: entry => {+ assert_ordered_(entry, [+ "fetchStart",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "connectEnd",+ "requestStart",+ "responseStart",+ "responseEnd",+ ]);++ assert_zeroed_(entry, [+ "workerStart",+ "secureConnectionStart",+ "redirectStart",+ "redirectEnd",+ ]);++ assert_not_negative_(entry, [+ "duration",+ ]);++ assert_positive_(entry, [+ "fetchStart",+ "transferSize",+ ]);+ },++ // Like assert_tao_pass_no_redirect_http but for empty response bodies.+ assert_tao_pass_no_redirect_http_empty: entry => {+ assert_ordered_(entry, [+ "fetchStart",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "connectEnd",+ "requestStart",+ "responseStart",+ "responseEnd",+ ]);++ assert_zeroed_(entry, [+ "workerStart",+ "secureConnectionStart",+ "redirectStart",+ "redirectEnd",+ ]);++ assert_not_negative_(entry, [+ "duration",+ ]);++ assert_positive_(entry, [+ "fetchStart",+ "transferSize",+ ]);+ },++ // Like assert_tao_pass_no_redirect_http but for resources fetched over HTTPS+ assert_tao_pass_no_redirect_https: entry => {+ assert_ordered_(entry, [+ "fetchStart",+ "domainLookupStart",+ "domainLookupEnd",+ "secureConnectionStart",+ "connectStart",+ "connectEnd",+ "requestStart",+ "responseStart",+ "responseEnd",+ ]);++ assert_zeroed_(entry, [+ "workerStart",+ "redirectStart",+ "redirectEnd",+ ]);++ assert_not_negative_(entry, [+ "duration",+ ]);++ assert_positive_(entry, [+ "fetchStart",+ "transferSize",+ ]);+ },++ // Like assert_tao_pass_no_redirect_https but for resources that did encounter+ // at least one HTTP redirect.+ assert_tao_pass_with_redirect_https: entry => {+ assert_ordered_(entry, [+ "fetchStart",+ "redirectStart",+ "redirectEnd",+ "domainLookupStart",+ "domainLookupEnd",+ "secureConnectionStart",+ "connectStart",+ "connectEnd",+ "requestStart",+ "responseStart",+ "responseEnd",+ ]);++ assert_zeroed_(entry, [+ "workerStart",+ ]);++ assert_not_negative_(entry, [+ "duration",+ ]);++ assert_positive_(entry, [+ "fetchStart",+ "transferSize",+ ]);+ },++ // Like assert_tao_pass_no_redirect_http but, since the resource's bytes+ // won't be retransmitted, the encoded and decoded sizes must be zero.+ assert_tao_pass_304_not_modified_http: entry => {+ assert_ordered_(entry, [+ "fetchStart",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "connectEnd",+ "requestStart",+ "responseStart",+ "responseEnd",+ ]);++ assert_zeroed_(entry, [+ "workerStart",+ "secureConnectionStart",+ "redirectStart",+ "redirectEnd",+ ]);++ assert_not_negative_(entry, [+ "duration",+ ]);++ assert_positive_(entry, [+ "fetchStart",+ "transferSize",+ ]);+ },++ // Like assert_tao_pass_304_not_modified_http but for resources fetched over+ // HTTPS.+ assert_tao_pass_304_not_modified_https: entry => {+ assert_ordered_(entry, [+ "fetchStart",+ "domainLookupStart",+ "domainLookupEnd",+ "secureConnectionStart",+ "connectStart",+ "connectEnd",+ "requestStart",+ "responseStart",+ "responseEnd",+ ]);++ assert_zeroed_(entry, [+ "workerStart",+ "redirectStart",+ "redirectEnd",+ ]);++ assert_not_negative_(entry, [+ "duration",+ ]);++ assert_positive_(entry, [+ "fetchStart",+ "transferSize",+ ]);+ },++ // Asserts that attributes of the given PerformanceResourceTiming entry match+ // what the spec dictates for any resource subsequently fetched over a+ // persistent connection. When this happens, we expect that certain+ // attributes describing transport layer behaviour will be equal.+ assert_connection_reused: entry => {+ assert_all_equal_(entry, [+ "fetchStart",+ "connectStart",+ "connectEnd",+ "domainLookupStart",+ "domainLookupEnd",+ ]);+ },++ // Asserts that attributes of the given PerformanceResourceTiming entry match+ // what the spec dictates for any resource fetched over HTTP through an HTTP+ // redirect.+ assert_same_origin_redirected_resource: entry => {+ assert_positive_(entry, [+ "redirectStart",+ ]);++ assert_equals(entry.redirectStart, entry.startTime,+ "redirectStart should be equal to startTime");++ assert_ordered_(entry, [+ "redirectStart",+ "redirectEnd",+ "fetchStart",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ ]);+ },++ // Asserts that attributes of the given PerformanceResourceTiming entry match+ // what the spec dictates for any resource fetched over HTTPS through a+ // cross-origin redirect.+ // (e.g. GET http://remote.com/foo => 302 Location: https://remote.com/foo)+ assert_cross_origin_redirected_resource: entry => {+ assert_zeroed_(entry, [+ "redirectStart",+ "redirectEnd",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "connectEnd",+ "secureConnectionStart",+ "requestStart",+ "responseStart",+ ]);++ assert_positive_(entry, [+ "fetchStart",+ "responseEnd",+ ]);++ assert_ordered_(entry, [+ "fetchStart",+ "responseEnd",+ ]);+ },++ // Asserts that attributes of the given PerformanceResourceTiming entry match+ // what the spec dictates when+ // 1. An HTTP request is made for a same-origin resource.+ // 2. The response to 1 is an HTTP redirect (like a 302).+ // 3. The location from 2 is a cross-origin HTTPS URL.+ // 4. The response to fetching the URL from 3 does not set a matching TAO header.+ assert_http_to_cross_origin_redirected_resource: entry => {+ assert_zeroed_(entry, [+ "redirectStart",+ "redirectEnd",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "connectEnd",+ "secureConnectionStart",+ "requestStart",+ "responseStart",+ ]);++ assert_positive_(entry, [+ "fetchStart",+ "responseEnd",+ ]);++ assert_ordered_(entry, [+ "fetchStart",+ "responseEnd",+ ]);+ },++ // Asserts that attributes of the given PerformanceResourceTiming entry match+ // what the spec dictates when+ // 1. An HTTPS request is made for a same-origin resource.+ // 2. The response to 1 is an HTTP redirect (like a 302).+ // 3. The location from 2 is a cross-origin HTTPS URL.+ // 4. The response to fetching the URL from 3 sets a matching TAO header.+ assert_tao_enabled_cross_origin_redirected_resource: entry => {+ assert_positive_(entry, [+ "redirectStart",+ ]);+ assert_ordered_(entry, [+ "redirectStart",+ "redirectEnd",+ "fetchStart",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "secureConnectionStart",+ "connectEnd",+ "requestStart",+ "responseStart",+ "responseEnd",+ ]);+ },++ // Asserts that attributes of the given PerformanceResourceTiming entry match+ // what the spec dictates when+ // 1. An HTTP request is made for a same-origin resource+ // 2. The response to 1 is an HTTP redirect (like a 302).+ // 3. The location from 2 is a cross-origin HTTPS URL.+ // 4. The response to fetching the URL from 3 sets a matching TAO header.+ assert_http_to_tao_enabled_cross_origin_https_redirected_resource: entry => {+ assert_zeroed_(entry, [+ // Note that, according to the spec, the secureConnectionStart attribute+ // should describe the connection for the first resource request when+ // there are redirects. Since the initial request is over HTTP,+ // secureConnectionStart must be 0.+ "secureConnectionStart",+ ]);+ assert_positive_(entry, [+ "redirectStart",+ ]);+ assert_ordered_(entry, [+ "redirectStart",+ "redirectEnd",+ "fetchStart",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "connectEnd",+ "requestStart",+ "responseStart",+ "responseEnd",+ ]);+ },++ assert_same_origin_redirected_from_cross_origin_resource: entry => {+ assert_zeroed_(entry, [+ "workerStart",+ "redirectStart",+ "redirectEnd",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "connectEnd",+ "secureConnectionStart",+ "requestStart",+ "responseStart",+ "transferSize",+ ]);++ assert_ordered_(entry, [+ "fetchStart",+ "responseEnd",+ ]);++ assert_equals(entry.fetchStart, entry.startTime,+ "fetchStart must equal startTime");+ },++ assert_tao_failure_resource: entry => {+ assert_equals(entry.entryType, "resource", "entryType must always be 'resource'");++ assert_positive_(entry, [+ "startTime",+ ]);++ assert_not_negative_(entry, [+ "duration",+ ]);++ assert_zeroed_(entry, [+ "redirectStart",+ "redirectEnd",+ "domainLookupStart",+ "domainLookupEnd",+ "connectStart",+ "connectEnd",+ "secureConnectionStart",+ "requestStart",+ "responseStart",+ "transferSize",+ ]);+ }++};++const attribute_test_internal = (loader, path, validator, run_test, test_label) => {+ promise_test(+ async () => {+ let loaded_entry = new Promise((resolve, reject) => {+ new PerformanceObserver((entry_list, self) => {+ try {+ const name_matches = entry_list.getEntries().forEach(entry => {+ if (entry.name.includes(path)) {+ resolve(entry);+ }+ });+ } catch(e) {+ // By surfacing exceptions through the Promise interface, tests can+ // fail fast with a useful message instead of timing out.+ reject(e);+ }+ }).observe({"type": "resource"});+ });++ await loader(path, validator);+ const entry = await await_with_timeout(2000,+ "Timeout was reached before entry fired",+ loaded_entry);+ assert_not_equals(entry, null, 'No entry was received');+ run_test(entry);+ }, test_label);+};++// Given a resource-loader, a path (a relative path or absolute URL), and a+// PerformanceResourceTiming test, applies the loader to the resource path+// and tests the resulting PerformanceResourceTiming entry.+const attribute_test = (loader, path, run_test, test_label) => {+ attribute_test_internal(loader, path, () => {}, run_test, test_label);+};++// Similar to attribute test, but on top of that, validates the added element,+// to ensure the test does what it intends to do.+const attribute_test_with_validator = (loader, path, validator, run_test, test_label) => {+ attribute_test_internal(loader, path, validator, run_test, test_label);+};++const network_error_entry_test = (originalURL, args, label, loader) => {+ const url = new URL(originalURL, location.href);+ const search = new URLSearchParams(url.search.substr(1));+ const timeBefore = performance.now();++ // Load using `fetch()`, unless we're given a specific loader for this test.+ loader ??= () => new Promise(resolve => fetch(url, args).catch(resolve));++ attribute_test(+ loader, url,+ () => {+ const timeAfter = performance.now();+ const names = performance.getEntriesByType('resource').filter(e => e.initiatorType === 'fetch').map(e => e.name);+ const entries = performance.getEntriesByName(url.toString());+ assert_equals(entries.length, 1, 'resource timing entry for network error');+ const entry = entries[0]+ assert_equals(entry.startTime, entry.fetchStart, 'startTime and fetchStart should be equal');+ assert_greater_than_equal(entry.startTime, timeBefore, 'startTime and fetchStart should be greater than the time before fetching');+ assert_greater_than_equal(timeAfter, entry.responseEnd, 'endTime should be less than the time right after returning from the fetch');+ assert_equals(entry.responseStatus, 0, 'responseStatus should be 0');+ assert_equals(entry.encodedBodySize, 0, 'encodedBodySize should be 0');+ assert_equals(entry.decodedBodySize, 0, 'decodedBodySize should be 0');+ assert_equals(entry.serverTiming.length, 0,+ 'serverTiming should be empty');+ assert_equals(entry.contentType, '', 'contentType should be empty');+ assert_equals(entry.contentEncoding, '',+ 'contentEncoding should be empty');+ assert_equals(entry.nextHopProtocol, '',+ 'nextHopProtocol should be empty');+ invariants.assert_tao_failure_resource(entry);+ }, `A ResourceTiming entry should be created for network error of type ${label}`);+}diff --git a/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/resource-loaders.js b/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/resource-loaders.jsnew file mode 100644index 00000000000..e65c18cebb0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/resource-loaders.js@@ -0,0 +1,187 @@+const load = {++ cache_bust: path => {+ let url = new URL(path, location.origin);+ url.href += (url.href.includes("?")) ? '&' : '?';+ // The `Number` type in Javascript, when interpreted as an integer, can only+ // safely represent [-2^53 + 1, 2^53 - 1] without the loss of precision [1].+ // We do not generate a global value and increment from it, as the increment+ // might not have enough precision to be reflected.+ //+ // [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number+ url.href += "unique=" + Math.random().toString().substring(2);+ return url.href;+ },++ image_with_attrs: async (path, attribute_map) => {+ return new Promise(resolve => {+ const img = new Image();+ for (const key in attribute_map)+ img[key] = attribute_map[key];+ img.onload = img.onerror = resolve;+ img.src = load.cache_bust(path);+ });+ },++ // Returns a promise that settles once the given path has been fetched as an+ // image resource.+ image: path => {+ return load.image_with_attrs(path, undefined);+ },++ // Returns a promise that settles once the given path has been fetched as an+ // image resource.+ image_cors: path => load.image_with_attrs(path, {crossOrigin: 'anonymous'}),++ // Returns a promise that settles once the given path has been fetched as a+ // font resource.+ font: path => {+ const div = document.createElement('div');+ div.innerHTML = `+ <style>+ @font-face {+ font-family: ahem;+ src: url('${load.cache_bust(path)}');+ }+ </style>+ <div style="font-family: ahem;">This fetches ahem font.</div>+ `;+ document.body.appendChild(div);+ return document.fonts.ready.then(() => {+ document.body.removeChild(div);+ });+ },++ stylesheet_with_attrs: async (path, attribute_map) => {+ const link = document.createElement("link");+ if (attribute_map instanceof Object) {+ for (const [key, value] of Object.entries(attribute_map)) {+ link[key] = value;+ }+ }+ link.rel = "stylesheet";+ link.type = "text/css";+ link.href = load.cache_bust(path);++ const loaded = new Promise(resolve => {+ link.onload = link.onerror = resolve;+ });++ document.head.appendChild(link);+ await loaded;+ document.head.removeChild(link);+ },++ // Returns a promise that settles once the given path has been fetched as a+ // stylesheet resource.+ stylesheet: async path => {+ return load.stylesheet_with_attrs(path, undefined);+ },++ iframe_with_attrs: async (path, attribute_map, validator,+ skip_wait_for_navigation) => {+ const frame = document.createElement("iframe");+ if (attribute_map instanceof Object) {+ for (const [key, value] of Object.entries(attribute_map)) {+ frame[key] = value;+ }+ }+ const loaded = new Promise(resolve => {+ frame.onload = frame.onerror = resolve;+ });+ frame.src = load.cache_bust(path);+ document.body.appendChild(frame);+ if ( !skip_wait_for_navigation ) {+ await loaded;+ }+ if (validator instanceof Function) {+ validator(frame);+ }+ // since we skipped the wait for load animation, we cannot+ // remove the iframe here since the request could get cancelled+ if ( !skip_wait_for_navigation ) {+ document.body.removeChild(frame);+ }+ },++ // Returns a promise that settles once the given path has been fetched as an+ // iframe.+ iframe: async (path, validator) => {+ return load.iframe_with_attrs(path, undefined, validator);+ },++ script_with_attrs: async (path, attribute_map) => {+ const script = document.createElement("script");+ if (attribute_map instanceof Object) {+ for (const [key, value] of Object.entries(attribute_map)) {+ script[key] = value;+ }+ }+ const loaded = new Promise(resolve => {+ script.onload = script.onerror = resolve;+ });+ script.src = load.cache_bust(path);+ document.body.appendChild(script);+ await loaded;+ document.body.removeChild(script);+ },++ // Returns a promise that settles once the given path has been fetched as a+ // script.+ script: async path => {+ return load.script_with_attrs(path, undefined);+ },++ // Returns a promise that settles once the given path has been fetched as an+ // object.+ object: async (path, type) => {+ const object = document.createElement("object");+ const object_load_settled = new Promise(resolve => {+ object.onload = object.onerror = resolve;+ });+ object.data = load.cache_bust(path);+ if (type) {+ object.type = type;+ }+ document.body.appendChild(object);+ await await_with_timeout(2000,+ "Timeout was reached before load or error events fired",+ object_load_settled,+ () => { document.body.removeChild(object) }+ );+ },++ // Returns a promise that settles once the given path has been fetched+ // through a synchronous XMLHttpRequest.+ xhr_sync: async (path, headers) => {+ const xhr = new XMLHttpRequest;+ xhr.open("GET", path, /* async = */ false);+ if (headers instanceof Object) {+ for (const [key, value] of Object.entries(headers)) {+ xhr.setRequestHeader(key, value);+ }+ }+ xhr.send();+ },++ xhr_async: path => {+ const xhr = new XMLHttpRequest();+ xhr.open("GET", path)+ xhr.send();+ return new Promise(resolve => {+ xhr.onload = xhr.onerror = resolve;+ });+ },++ image_object: async path => {+ return load.object(path, 'image/png');+ },++ frame_object: async path => {+ return load.object(path, 'text/html');+ },++ null_object: async path => {+ return load.object(path, null);+ }+};diff --git a/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/status-code.py b/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/status-code.pynew file mode 100644index 00000000000..1c6a0216333--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/resource-timing/resources/status-code.py@@ -0,0 +1,8 @@+def main(request, response):+ status = request.GET.first(b'status')+ response.status = (status, b"");+ if b'tao_value' in request.GET:+ response.headers.set(b'timing-allow-origin', request.GET.first(b'tao_value'))+ if b'allow_origin' in request.GET:+ response.headers.set(b'access-control-allow-origin', request.GET.first(b'allow_origin'))+diff --git a/Tests/LibWeb/Text/input/wpt-import/resource-timing/status-codes-create-entry.html b/Tests/LibWeb/Text/input/wpt-import/resource-timing/status-codes-create-entry.htmlnew file mode 100644index 00000000000..82031ade3e1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/resource-timing/status-codes-create-entry.html@@ -0,0 +1,42 @@+<!doctype html>+<html>+<head>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+</head>+<body>+<img src="resources/status-code.py?status=200">+<img src="resources/status-code.py?status=307">+<img src="resources/status-code.py?status=404">+<img src="resources/status-code.py?status=502">+<script src="resources/status-code.py?status=200&script=1"></script>+<script src="resources/status-code.py?status=307&script=1"></script>+<script src="resources/status-code.py?status=404&script=1"></script>+<script src="resources/status-code.py?status=502&script=1"></script>+<script>+async_test(t => {+ window.addEventListener("load", t.step_func_done(() => {+ const images = document.getElementsByTagName("img");+ for (let img of images) {+ const entries = performance.getEntriesByName(img.src);+ assert_greater_than(entries.length, 0, img.src);+ assert_greater_than(entries[0].duration, 0, img.src);+ }+ const scripts = document.getElementsByTagName("script");+ let ignoredScripts = 0;+ for (let script of scripts) {+ if (!script.src || script.src.match(/testharness(report)?\.js$/)) {+ // Ignore this script, which has no src value, and the `testharness*.js`+ // scripts. `testharness*.js` may be cached from a previous test and+ // served quickly enough for a coarsened `duration` to be zero exactly.+ ignoredScripts++;+ } else {+ const entries = performance.getEntriesByName(script.src);+ assert_greater_than(entries.length, 0, script.src);+ assert_greater_than(entries[0].duration, 0, script.src);+ }+ }+ assert_equals(ignoredScripts, 3);+ }));+}, "Make sure all status codes are reported");+</script>