-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WPTs for different Early Hints preload finish timings
The test scenarios are: * 103 -> start preload -> preload finished -> 200 -> response body. * 103 -> start preload -> (preload inflight) -> 200 -> preload finished -> response body. The purpose of these tests is to make sure the resource is added to the preload map of the document [1]. Also refer to [2] for the motivation. [1] whatwg/html#7675 [2] #33076 (comment) Bug: 1305896 Change-Id: Id0ba4748f6493bc2c78be6de5769b4d16ce9092f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3552176 Reviewed-by: Yutaka Hirano <[email protected]> Commit-Queue: Kenichi Ishibashi <[email protected]> Cr-Commit-Position: refs/heads/main@{#985847}
- Loading branch information
1 parent
e9c5c4c
commit 2139b60
Showing
9 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
loading/early-hints/preload-finished-before-final-response.h2.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "/fetch-and-record-js.h2.py?id=" + id); | ||
params.set("resource-id", id); | ||
const test_url = "resources/preload-finished-before-final-response.h2.py?" + params.toString(); | ||
window.location.replace(new URL(test_url, window.location)); | ||
}); |
11 changes: 11 additions & 0 deletions
11
loading/early-hints/preload-finished-while-receiving-final-response-body.h2.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "/fetch-and-record-js.h2.py?id=" + id); | ||
params.set("resource-id", id); | ||
const test_url = "resources/preload-finished-while-receiving-final-response-body.h2.py?" + params.toString(); | ||
window.location.replace(new URL(test_url, window.location)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
loading/early-hints/resources/preload-finished-before-final-response.h2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import importlib | ||
import os | ||
|
||
utils = importlib.import_module("loading.early-hints.resources.utils") | ||
|
||
|
||
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) | ||
|
||
# Wait for preload to finish before sending the final response headers. | ||
resource_id = request.GET.first(b"resource-id").decode() | ||
utils.wait_for_preload_to_finish(request, resource_id) | ||
|
||
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-finished-before-final-response.html") | ||
with open(file_path, "r") as f: | ||
test_content = f.read() | ||
response.writer.write_data(item=test_content, last=True) |
15 changes: 15 additions & 0 deletions
15
loading/early-hints/resources/preload-finished-before-final-response.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!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_url = params.get("resource-url"); | ||
await fetchScript(resource_url); | ||
assert_true(isPreloadedByEarlyHints(resource_url)); | ||
}, "Early hints preload finished before the final response."); | ||
</script> | ||
</body> |
31 changes: 31 additions & 0 deletions
31
loading/early-hints/resources/preload-finished-while-receiving-final-response-body.h2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import importlib | ||
import os | ||
|
||
utils = importlib.import_module("loading.early-hints.resources.utils") | ||
|
||
|
||
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): | ||
# Wait for preload to finish before sending the response body. | ||
resource_id = request.GET.first(b"resource-id").decode() | ||
utils.wait_for_preload_to_finish(request, resource_id) | ||
|
||
current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
file_path = os.path.join(current_dir, "preload-finished-while-receiving-final-response-body.html") | ||
with open(file_path, "r") as f: | ||
test_content = f.read() | ||
response.writer.write_data(item=test_content, last=True) |
15 changes: 15 additions & 0 deletions
15
loading/early-hints/resources/preload-finished-while-receiving-final-response-body.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!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_url = params.get("resource-url"); | ||
await fetchScript(resource_url); | ||
assert_true(isPreloadedByEarlyHints(resource_url)); | ||
}, "Early hints preload finished while loading the final response body."); | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters