-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
speculation-rules prefetch WPT tests
- speculation-rules base prefetch logic should be able to prefetch multiple urls. To pass the test at least two urls should be prefetched. Bug: 1302365 Change-Id: I1a333f6c8ab350a1a09e7f389d7bb444dc8d6dfa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3577359 Reviewed-by: Jeremy Roman <jbroman@chromium.org> Commit-Queue: Iman Saboori <isaboori@google.com> Cr-Commit-Position: refs/heads/main@{#990788}
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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,21 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="resources/utils.sub.js"></script> | ||
|
||
<script> | ||
promise_test(async t => { | ||
assert_implements(HTMLScriptElement.supports('speculationrules'), "Speculation Rules not supported"); | ||
|
||
let urls = getPrefetchUrlList(5); | ||
insertSpeculationRules({ prefetch: [{ source: 'list', urls: urls }] }); | ||
await new Promise(resolve => t.step_timeout(resolve, 3000)); | ||
|
||
let prefetched_count = (await Promise.all(urls.map(isUrlPrefetched))).reduce( | ||
(count, was_prefetched) => count + (was_prefetched ? 1 : 0), 0); | ||
|
||
assert_greater_than_equal(prefetched_count, 2, "At least two urls should be prefetched to pass the test."); | ||
}, "browser should be able to prefetch multiple urls"); | ||
</script> |
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,17 @@ | ||
from wptserve.handlers import json_handler | ||
|
||
|
||
@json_handler | ||
def main(request, response): | ||
uuid = request.GET[b"uuid"] | ||
prefetch = request.headers.get( | ||
"Sec-Purpose", b"").decode("utf-8").startswith("prefetch") | ||
|
||
n = request.server.stash.take(uuid) | ||
if n is None: | ||
n = 0 | ||
if prefetch: | ||
n += 1 | ||
request.server.stash.put(uuid, n) | ||
|
||
return n |
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