Skip to content

Commit

Permalink
Bug 1761164 [wpt PR 33337] - Add WPT for Early Hints preload is in-fl…
Browse files Browse the repository at this point in the history
…ight when consumed, a=testonly

Automatic update from web-platform-tests
Add WPT for Early Hints preload is in-flight when consumed

The test page sends an Early Hints with a resource preload. The response
of the resource is delayed until the final response consumes the
resource.

The purpose of this test is to make sure the resource is added to the
document's map of preloads [1].

[1] whatwg/html#7675

Bug: 1305896
Change-Id: I39371b41860190936991799fb6457f142e7ffef2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3545997
Reviewed-by: Yutaka Hirano <[email protected]>
Commit-Queue: Kenichi Ishibashi <[email protected]>
Cr-Commit-Position: refs/heads/main@{#984778}

--

wpt-commits: 850fd2b4dbf5c21ebb649f6d889caa140b8b29db
wpt-pr: 33337
  • Loading branch information
bashi authored and moz-wptsync-bot committed Apr 1, 2022
1 parent d8d20af commit aa25412
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: script=/common/utils.js
// META: script=resources/early-hints-helpers.sub.js

test(() => {
const params = new URLSearchParams();
const id = token();
params.set("resource-url", SAME_ORIGIN_RESOURCES_URL + "/delayed-js.h2.py?id=" + id);
params.set("resource-id", id);
const test_url = "resources/preload-in-flight-when-consumed.h2.py?" + params.toString();
window.location.replace(new URL(test_url, window.location));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import time


def main(request, response):
id = request.GET.first(b"id")
url_dir = u'/'.join(request.url_parts.path.split(u'/')[:-1]) + u'/'
# Wait until the id is set via resume-delayed-js.h2.py.
while True:
if request.server.stash.take(id, url_dir):
break
time.sleep(0.1)

headers = [
("Content-Type", "text/javascript"),
("Cache-Control", "max-age=600"),
]
body = "/*empty script*/"
return (200, "OK"), headers, body
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os


def handle_headers(frame, request, response):
resource_url = request.GET.first(b"resource-url").decode()
link_header_value = "<{}>; rel=preload; as=script".format(resource_url)
early_hints = [
(b":status", b"103"),
(b"link", link_header_value),
]
response.writer.write_raw_header_frame(headers=early_hints,
end_headers=True)

response.status = 200
response.headers[b"content-type"] = "text/html"
response.write_status_headers()


def main(request, response):
current_dir = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(current_dir, "preload-in-flight-when-consumed.html")
with open(file_path, "r") as f:
test_content = f.read()
response.writer.write_data(item=test_content, last=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="early-hints-helpers.sub.js"></script>
<body>
<script>
promise_test(async (t) => {
const params = new URLSearchParams(window.location.search);
const resource_id = params.get("resource-id");
const resource_url = params.get("resource-url");

const promise = fetchScript(resource_url);
await fetch("resume-delayed-js.h2.py?id=" + resource_id);
await promise;
assert_true(isPreloadedByEarlyHints(resource_url));
}, "Early hints preload is in-flight when consumed.");
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def main(request, response):
id = request.GET.first(b"id")
url_dir = u'/'.join(request.url_parts.path.split(u'/')[:-1]) + u'/'
request.server.stash.put(id, True, url_dir)
headers = [
("Content-Type", "text/plain"),
]
body = "OK"
return (200, "OK"), headers, body

0 comments on commit aa25412

Please sign in to comment.