Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
preload
/prefetch
tests for Sec-Fetch-*
Bug: 843478 Change-Id: Ie3225e59948f387754dce46d26fd3af5ad63f062 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1556796 Commit-Queue: Mike West <mkwst@chromium.org> Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org> Cr-Commit-Position: refs/heads/master@{#650705}
- Loading branch information
1 parent
065779d
commit b2d2bc7
Showing
3 changed files
with
94 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,36 @@ | ||
<!DOCTYPE html> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/fetch/sec-metadata/resources/helper.js></script> | ||
<script src=/common/utils.js></script> | ||
<body></body> | ||
<script> | ||
test(t => { | ||
assert_true(document.createElement('link').relList.supports('prefetch')); | ||
}, "Browser supports prefetch."); | ||
|
||
function create_test(host, expected) { | ||
async_test(t => { | ||
let nonce = token(); | ||
let key = "prefetch" + nonce; | ||
|
||
let e = document.createElement('link'); | ||
e.rel = "prefetch"; | ||
e.href = `https://${host}/fetch/sec-metadata/resources/record-header.py?file=${key}`; | ||
e.setAttribute("crossorigin", "crossorigin"); | ||
e.onload = t.step_func(e => { | ||
fetch("/fetch/sec-metadata/resources/record-header.py?retrieve=true&file=" + key) | ||
.then(t.step_func(response => response.text())) | ||
.then(t.step_func_done(text => assert_header_equals(text, expected))) | ||
.catch(t.unreached_func("Fetching and verifying the results should succeed.")); | ||
}); | ||
e.onerror = t.unreached_func(); | ||
|
||
document.head.appendChild(e); | ||
}, `<link rel='prefetch' href='https://${host}/...'>`); | ||
} | ||
|
||
create_test("{{host}}:{{ports[https][0]}}", {"dest":"empty", "site":"same-origin", "user":"", "mode": "cors"}); | ||
create_test("{{hosts[][www]}}:{{ports[https][0]}}", {"dest":"empty", "site":"same-site", "user":"", "mode": "cors"}); | ||
create_test("{{hosts[alt][www]}}:{{ports[https][0]}}", {"dest":"empty", "site":"cross-site", "user":"", "mode": "cors"}); | ||
</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,50 @@ | ||
<!DOCTYPE html> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/fetch/sec-metadata/resources/helper.js></script> | ||
<script src=/common/utils.js></script> | ||
<body></body> | ||
<script> | ||
test(t => { | ||
assert_true(document.createElement('link').relList.supports('preload')); | ||
}, "Browser supports preload."); | ||
|
||
function create_test(host, as, expected) { | ||
async_test(t => { | ||
let nonce = token(); | ||
let key = as + nonce; | ||
|
||
let e = document.createElement('link'); | ||
e.rel = "preload"; | ||
e.href = `https://${host}/fetch/sec-metadata/resources/record-header.py?file=${key}`; | ||
e.setAttribute("crossorigin", "crossorigin"); | ||
if (as !== undefined) { | ||
e.setAttribute("as", as); | ||
} | ||
e.onload = e.onerror = t.step_func_done(e => { | ||
fetch("/fetch/sec-metadata/resources/record-header.py?retrieve=true&file=" + key) | ||
.then(t.step_func(response => response.text())) | ||
.then(t.step_func(text => assert_header_equals(text, expected))) | ||
.then(t.step_func_done(_ => resolve())) | ||
.catch(t.unreached_func()); | ||
}); | ||
|
||
document.head.appendChild(e); | ||
}, `<link rel='preload' as='${as}' href='https://${host}/...'>`); | ||
} | ||
|
||
let as_tests = [ | ||
[ "fetch", "empty" ], | ||
[ "font", "font" ], | ||
[ "image", "image" ], | ||
[ "script", "script" ], | ||
[ "style", "style" ], | ||
[ "track", "track" ], | ||
]; | ||
|
||
as_tests.forEach(item => { | ||
create_test("{{host}}:{{ports[https][0]}}", item[0], {"dest":item[1], "site":"same-origin", "user":"", "mode": "cors"}); | ||
create_test("{{hosts[][www]}}:{{ports[https][0]}}", item[0], {"dest":item[1], "site":"same-site", "user":"", "mode": "cors"}); | ||
create_test("{{hosts[alt][www]}}:{{ports[https][0]}}", item[0], {"dest":item[1], "site":"cross-site", "user":"", "mode": "cors"}); | ||
}); | ||
</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