mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Update web-platform-tests to revision b'468d01bbd84da2babf265c6af46947be68713440'
This commit is contained in:
parent
35e95f55a1
commit
58e8ee674b
9438 changed files with 266112 additions and 106976 deletions
|
@ -0,0 +1,78 @@
|
|||
<!DOCTYPE html>
|
||||
<title>CSP for subresource WebBundle (allowed cases)</title>
|
||||
<link
|
||||
rel="help"
|
||||
href="https://github.com/WICG/webpackage/blob/master/explainers/subresource-loading.md"
|
||||
/>
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="
|
||||
script-src
|
||||
https://web-platform.test:8444/web-bundle/resources/wbn/urn-uuid.wbn
|
||||
https://web-platform.test:8444/resources/testharness.js
|
||||
https://web-platform.test:8444/resources/testharnessreport.js
|
||||
'unsafe-inline';
|
||||
img-src
|
||||
https://web-platform.test:8444/web-bundle/resources/wbn/pass.png;
|
||||
frame-src
|
||||
https://web-platform.test:8444/web-bundle/resources/wbn/urn-uuid.wbn"
|
||||
>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<link rel="webbundle" href="../resources/wbn/subresource.wbn"
|
||||
resources="https://web-platform.test:8444/web-bundle/resources/wbn/pass.png" />
|
||||
<link rel="webbundle" href="../resources/wbn/urn-uuid.wbn"
|
||||
resources="urn:uuid:020111b3-437a-4c5c-ae07-adb6bbffb720
|
||||
urn:uuid:429fcc4e-0696-4bad-b099-ee9175f023ae" />
|
||||
<script>
|
||||
promise_test(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = document.createElement('img');
|
||||
img.src = 'https://web-platform.test:8444/web-bundle/resources/wbn/pass.png';
|
||||
img.onload = resolve;
|
||||
img.onerror = reject;
|
||||
document.body.appendChild(img);
|
||||
});
|
||||
}, 'URL matching of CSP should be done based on the subresource URL ' +
|
||||
'when the subresource URL is HTTPS URL.');
|
||||
|
||||
promise_test(async () => {
|
||||
const result = await new Promise((resolve) => {
|
||||
// This function will be called from the script.
|
||||
window.report_result = resolve;
|
||||
const script = document.createElement('script');
|
||||
script.src = 'urn:uuid:020111b3-437a-4c5c-ae07-adb6bbffb720';
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
assert_equals(result, 'OK');
|
||||
}, 'URL matching of script-src CSP should be done based on the bundle URL ' +
|
||||
'when the subresource URL is urn:uuid URL.');
|
||||
|
||||
promise_test(async () => {
|
||||
const frame_url = 'urn:uuid:429fcc4e-0696-4bad-b099-ee9175f023ae';
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = frame_url;
|
||||
const load_promise = new Promise((resolve) => {
|
||||
iframe.addEventListener('load', resolve);
|
||||
});
|
||||
document.body.appendChild(iframe);
|
||||
await load_promise;
|
||||
assert_equals(
|
||||
await evalInIframe(iframe, 'location.href'),
|
||||
frame_url);
|
||||
}, 'URL matching of frame-src CSP should be done based on the bundle URL ' +
|
||||
'when the frame URL is urn:uuid URL.');
|
||||
|
||||
async function evalInIframe(iframe, code) {
|
||||
const message_promise = new Promise((resolve) => {
|
||||
window.addEventListener(
|
||||
'message',
|
||||
(e) => { resolve(e.data); },
|
||||
{ once : true });
|
||||
});
|
||||
iframe.contentWindow.postMessage(code,'*');
|
||||
return message_promise;
|
||||
}
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,137 @@
|
|||
<!DOCTYPE html>
|
||||
<title>CSP for subresource WebBundle (blocked cases)</title>
|
||||
<link
|
||||
rel="help"
|
||||
href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md"
|
||||
/>
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="
|
||||
script-src
|
||||
urn:
|
||||
https://web-platform.test:8444/resources/testharness.js
|
||||
https://web-platform.test:8444/resources/testharnessreport.js
|
||||
'unsafe-inline';
|
||||
img-src
|
||||
https://web-platform.test:8444/web-bundle/resources/wbn/subresource.wbn;
|
||||
frame-src
|
||||
urn:;
|
||||
report-to
|
||||
csp-group"
|
||||
>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<link rel="webbundle" href="../resources/wbn/subresource.wbn"
|
||||
resources="https://web-platform.test:8444/web-bundle/resources/wbn/fail.png" />
|
||||
<link rel="webbundle" href="../resources/wbn/urn-uuid.wbn"
|
||||
resources="urn:uuid:020111b3-437a-4c5c-ae07-adb6bbffb720
|
||||
urn:uuid:429fcc4e-0696-4bad-b099-ee9175f023ae" />
|
||||
<script>
|
||||
const bundle_url = 'https://web-platform.test:8444/web-bundle/resources/wbn/urn-uuid.wbn';
|
||||
|
||||
function expect_violation() {
|
||||
return new Promise(resolve => {
|
||||
document.addEventListener('securitypolicyviolation', (e) => {
|
||||
e.stopPropagation();
|
||||
resolve(e);
|
||||
}, {once: true});
|
||||
});
|
||||
}
|
||||
|
||||
function getReportID() {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
const name_value = cookies[i].split('=');
|
||||
const cookieName = name_value[0].trim();
|
||||
if (cookieName === 'csp-blocked-report-id') {
|
||||
return name_value[1].trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sortReportsByEffectiveDirective(reports) {
|
||||
reports.sort(function(report1, report2) {
|
||||
return report1.body.effectiveDirective.localeCompare(
|
||||
report2.body.effectiveDirective);
|
||||
});
|
||||
}
|
||||
|
||||
promise_test(async () => {
|
||||
const p = expect_violation();
|
||||
const img = document.createElement('img');
|
||||
const error_promise = new Promise(resolve => {
|
||||
img.onerror = resolve;
|
||||
});
|
||||
img.src = 'https://web-platform.test:8444/web-bundle/resources/wbn/fail.png';
|
||||
document.body.appendChild(img);
|
||||
const e = await p;
|
||||
assert_equals(e.blockedURI, img.src);
|
||||
await error_promise;
|
||||
}, 'URL matching of CSP should be done based on the subresource URL, ' +
|
||||
'not on the bundle URL, when the subresource URL is HTTPS URL.');
|
||||
|
||||
promise_test(async () => {
|
||||
const urn_uuid = 'urn:uuid:020111b3-437a-4c5c-ae07-adb6bbffb720';
|
||||
const p = expect_violation();
|
||||
const script = document.createElement('script');
|
||||
script.src = urn_uuid;
|
||||
document.body.appendChild(script);
|
||||
const e = await p;
|
||||
// Currently Chromium is reporting the bundle URL.
|
||||
// TODO(crbug.com/1208659): Consider deeper integration with CSP for
|
||||
// providing the both URLs.
|
||||
assert_equals(e.blockedURI, bundle_url);
|
||||
assert_equals(e.violatedDirective, 'script-src-elem');
|
||||
}, 'URL matching of script-src CSP should be done based on the bundle URL ' +
|
||||
'when the subresource URL is urn:uuid URL.');
|
||||
|
||||
promise_test(async () => {
|
||||
const urn_uuid = 'urn:uuid:429fcc4e-0696-4bad-b099-ee9175f023ae';
|
||||
const p = expect_violation();
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = urn_uuid;
|
||||
const load_promise = new Promise(resolve => {
|
||||
iframe.addEventListener('load', resolve);
|
||||
});
|
||||
document.body.appendChild(iframe);
|
||||
const e = await p;
|
||||
// Currently Chromium is reporting the bundle URL.
|
||||
// TODO(crbug.com/1208659): Consider deeper integration with CSP for
|
||||
// providing the both URLs.
|
||||
assert_equals(e.blockedURI, bundle_url);
|
||||
assert_equals(e.violatedDirective, 'frame-src');
|
||||
|
||||
// Make sure that the blocked iframe load is finished.
|
||||
await load_promise;
|
||||
|
||||
// The blocked iframe is cross-origin. So accessing
|
||||
// iframe.contentWindow.location should throw a SecurityError.
|
||||
assert_throws_dom(
|
||||
"SecurityError",
|
||||
() => { iframe.contentWindow.location.href; });
|
||||
}, 'URL matching of frame-src CSP should be done based on the bundle URL ' +
|
||||
'when the frame URL is urn:uuid URL.');
|
||||
|
||||
promise_test(async () => {
|
||||
const retrieve_report_url =
|
||||
"/reporting/resources/report.py?op=retrieve_report&timeout=3&reportID=" +
|
||||
getReportID();
|
||||
const reports = await (await fetch(retrieve_report_url)).json();
|
||||
sortReportsByEffectiveDirective(reports);
|
||||
|
||||
assert_equals(reports.length, 3, "Report count.");
|
||||
|
||||
assert_equals(reports[0].body.blockedURL, bundle_url);
|
||||
assert_equals(reports[0].body.effectiveDirective, 'frame-src');
|
||||
|
||||
assert_equals(
|
||||
reports[1].body.blockedURL,
|
||||
'https://web-platform.test:8444/web-bundle/resources/wbn/fail.png');
|
||||
assert_equals(reports[1].body.effectiveDirective, 'img-src',);
|
||||
|
||||
assert_equals(reports[2].body.blockedURL, bundle_url);
|
||||
assert_equals(reports[2].body.effectiveDirective, 'script-src-elem');
|
||||
}, 'Check the CSP violation reports.');
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,6 @@
|
|||
Expires: Mon, 26 Jul 1997 05:00:00 GMT
|
||||
Cache-Control: no-store, no-cache, must-revalidate
|
||||
Cache-Control: post-check=0, pre-check=0, false
|
||||
Pragma: no-cache
|
||||
Set-Cookie: csp-blocked-report-id={{$id:uuid()}}; Path=/web-bundle/subresource-loading/
|
||||
Report-To: { "group": "csp-group", "max_age": 10886400, "endpoints": [{ "url": "https://{{host}}:{{ports[https][0]}}/reporting/resources/report.py?op=put&reportID={{$id}}" }] }
|
|
@ -11,6 +11,15 @@
|
|||
|
||||
const frame_url = 'urn:uuid:429fcc4e-0696-4bad-b099-ee9175f023ae';
|
||||
|
||||
promise_test(async (t) => {
|
||||
const iframe = await createLinkAndIframe(t);
|
||||
// The urn:uuid URL iframe is cross-origin. So accessing
|
||||
// iframe.contentWindow.location should throws a SecurityError.
|
||||
assert_throws_dom(
|
||||
"SecurityError",
|
||||
() => { iframe.contentWindow.location.href; });
|
||||
}, 'The urn:uuid URL iframe must be cross-origin.');
|
||||
|
||||
urn_uuid_iframe_test(
|
||||
'location.href',
|
||||
frame_url,
|
||||
|
@ -70,25 +79,30 @@ urn_uuid_iframe_test(
|
|||
'window.caches should be undefined.');
|
||||
|
||||
function urn_uuid_iframe_test(code, expected, name) {
|
||||
promise_test(async () => {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'webbundle';
|
||||
link.href = '../resources/wbn/urn-uuid.wbn';
|
||||
link.resources = frame_url;
|
||||
document.body.appendChild(link);
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = frame_url;
|
||||
const load_promise = new Promise((resolve) => {
|
||||
iframe.addEventListener('load', resolve);
|
||||
});
|
||||
document.body.appendChild(iframe);
|
||||
await load_promise;
|
||||
assert_equals(
|
||||
await evalInIframe(iframe, code),
|
||||
expected);
|
||||
promise_test(async (t) => {
|
||||
const iframe = await createLinkAndIframe(t);
|
||||
assert_equals(await evalInIframe(iframe, code), expected);
|
||||
}, name);
|
||||
}
|
||||
|
||||
async function createLinkAndIframe(t) {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'webbundle';
|
||||
link.href = '../resources/wbn/urn-uuid.wbn';
|
||||
link.resources = frame_url;
|
||||
document.body.appendChild(link);
|
||||
const iframe = document.createElement('iframe');
|
||||
t.add_cleanup(() => {
|
||||
document.body.removeChild(link);
|
||||
document.body.removeChild(iframe);
|
||||
}, name);
|
||||
});
|
||||
iframe.src = frame_url;
|
||||
const load_promise = new Promise((resolve) => {
|
||||
iframe.addEventListener('load', resolve);
|
||||
});
|
||||
document.body.appendChild(iframe);
|
||||
await load_promise;
|
||||
return iframe;
|
||||
}
|
||||
|
||||
async function evalInIframe(iframe, code) {
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Accept: request header in webbundle requests</title>
|
||||
<link
|
||||
rel="help"
|
||||
href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md"
|
||||
/>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/test-helpers.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
promise_test(async () => {
|
||||
const link = document.createElement("link");
|
||||
link.rel = "webbundle";
|
||||
link.href = "../resources/check-accept-header-and-return-bundle.py";
|
||||
await addElementAndWaitForLoad(link);
|
||||
link.remove();
|
||||
}, '"Accept:" header in a request for a bundle should contain application/webbundle MIME type');
|
||||
|
||||
</script>
|
||||
</body>
|
|
@ -35,7 +35,7 @@
|
|||
for (const crossorigin_attribute_value of [
|
||||
undefined, // crossorigin attribute is not set
|
||||
"anonymous",
|
||||
"use-credential",
|
||||
"use-credentials",
|
||||
]) {
|
||||
const link = await addLinkAndWaitForError(
|
||||
prefix + "cross-origin.wbn",
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
for (const crossorigin_attribute_value of [
|
||||
undefined, // crossorigin attribute is not set
|
||||
"anonymous",
|
||||
"use-credential",
|
||||
"use-credentials",
|
||||
]) {
|
||||
const link = await addLinkAndWaitForLoad(
|
||||
prefix + "cross-origin.wbn",
|
||||
|
|
|
@ -79,6 +79,56 @@
|
|||
'classic script from network');
|
||||
}, 'Dynamically loading classic script from web bundle with link.resources');
|
||||
|
||||
promise_test(async (t) => {
|
||||
// To avoid caching mechanism, this test is using fetch() API with
|
||||
// { cache: 'no-store' } to load the resource.
|
||||
const classic_script_url = 'https://web-platform.test:8444/web-bundle/resources/wbn/dynamic/classic_script.js';
|
||||
|
||||
assert_equals(
|
||||
await (await fetch(classic_script_url)).text(),
|
||||
'window.report_result(\'classic script from network\');\n');
|
||||
|
||||
const link1 = document.createElement("link");
|
||||
link1.rel = "webbundle";
|
||||
link1.href = "../resources/wbn/dynamic1.wbn";
|
||||
link1.resources.add(classic_script_url);
|
||||
document.body.appendChild(link1);
|
||||
t.add_cleanup(() => {
|
||||
if (link1.parentElement)
|
||||
link1.parentElement.removeChild(link1);
|
||||
});
|
||||
|
||||
assert_equals(
|
||||
await (await fetch(classic_script_url, { cache: 'no-store' })).text(),
|
||||
'window.report_result(\'classic script from dynamic1.wbn\');\n');
|
||||
|
||||
const link2 = document.createElement("link");
|
||||
link2.rel = "webbundle";
|
||||
link2.href = "../resources/wbn/dynamic2.wbn";
|
||||
link2.resources.add(classic_script_url);
|
||||
document.body.appendChild(link2);
|
||||
t.add_cleanup(() => {
|
||||
if (link2.parentElement)
|
||||
link2.parentElement.removeChild(link2);
|
||||
});
|
||||
|
||||
assert_equals(
|
||||
await (await fetch(classic_script_url, { cache: 'no-store' })).text(),
|
||||
'window.report_result(\'classic script from dynamic2.wbn\');\n');
|
||||
|
||||
document.body.removeChild(link2);
|
||||
|
||||
assert_equals(
|
||||
await (await fetch(classic_script_url, { cache: 'no-store' })).text(),
|
||||
'window.report_result(\'classic script from dynamic1.wbn\');\n');
|
||||
|
||||
document.body.removeChild(link1);
|
||||
|
||||
assert_equals(
|
||||
await (await fetch(classic_script_url, { cache: 'no-store' })).text(),
|
||||
'window.report_result(\'classic script from network\');\n');
|
||||
}, 'Multiple web bundle links. The last added link must be refered.');
|
||||
|
||||
promise_test(async () => {
|
||||
const classic_script_url = 'https://web-platform.test:8444/web-bundle/resources/wbn/dynamic/classic_script.js';
|
||||
const scope = 'https://web-platform.test:8444/web-bundle/resources/wbn/dynamic/';
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<title>On-going subresource loading should fail immediately when a link element is removed</title>
|
||||
<link rel="help" href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
promise_test(async () => {
|
||||
const link = document.createElement("link");
|
||||
link.rel = "webbundle";
|
||||
link.href = "/xhr/resources/delay.py?ms=100000";
|
||||
link.resources.add("https://web-platform.test:8444/xhr/resources/dummy");
|
||||
document.body.appendChild(link);
|
||||
const waitUntilFail = new Promise((resolve) => {
|
||||
fetch("https://web-platform.test:8444/xhr/resources/dummy").then(() => {},
|
||||
resolve);
|
||||
});
|
||||
document.body.removeChild(link);
|
||||
await waitUntilFail;
|
||||
}, "On-going subresource loading should fail immediately when a link element is removed.");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Web Bundle fetching failed due to a network error</title>
|
||||
<link rel="help" href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/test-helpers.js"></script>
|
||||
|
||||
<body>
|
||||
<!--
|
||||
This test uses a non-existing WebBundle from a non-existent host, which makes
|
||||
Web Bundle fetching fail due to a network error. The intent of is to chech if
|
||||
failing to fetch a WebBundle also makes subresource fetch requests fail.
|
||||
-->
|
||||
<script>
|
||||
promise_test(async () => {
|
||||
const prefix =
|
||||
"https://{{hosts[][nonexistent]}}/";
|
||||
const resources = [
|
||||
prefix + "resource.js",
|
||||
];
|
||||
const link = await addLinkAndWaitForError(
|
||||
prefix + "non-existing.wbn",
|
||||
resources,
|
||||
undefined
|
||||
);
|
||||
|
||||
// Can not fetch a subresource because Web Bundle fetch failed.
|
||||
await fetchAndWaitForReject(prefix + "resource.js");
|
||||
}, "Subresource fetch requests for non-existing Web Bundle should fail.");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="euc-jp"/>
|
||||
<title>WebBundle subresource loading with non utf-8 query encoding and encoded src</title>
|
||||
<link
|
||||
rel="help"
|
||||
href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md"
|
||||
/>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<link
|
||||
rel="webbundle"
|
||||
href="../resources/wbn/non-utf8-query-encoding.wbn"
|
||||
resources="https://web-platform.test:8444/web-bundle/resources/wbn/static-element/resources/script.js?x=<3D><>"
|
||||
/>
|
||||
|
||||
<script id="script" src="/web-bundle/resources/wbn/static-element/resources/script.js?x=%A4%A2"></script>
|
||||
|
||||
<script>
|
||||
// This test is using a non-ascii character whose Unicode point is U+3042.
|
||||
// URL encode (in EUC-JP) of the character is "%A4%A2".
|
||||
|
||||
const onLoadPromise = new Promise((resolve) => {
|
||||
window.addEventListener('load', resolve, false);
|
||||
});
|
||||
|
||||
promise_test(async () => {
|
||||
await onLoadPromise;
|
||||
assert_equals(resources_script_result, 'loaded from webbundle');
|
||||
}, "Query encoding should be correctly handled in non utf-8 encoding " +
|
||||
"document when script src is encoded.");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="euc-jp"/>
|
||||
<title>WebBundle subresource loading with non utf-8 query encoding</title>
|
||||
<link
|
||||
rel="help"
|
||||
href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md"
|
||||
/>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<link
|
||||
rel="webbundle"
|
||||
href="../resources/wbn/non-utf8-query-encoding.wbn"
|
||||
resources="https://web-platform.test:8444/web-bundle/resources/wbn/static-element/resources/script.js?x=<3D><>"
|
||||
/>
|
||||
|
||||
<script id="script" src="/web-bundle/resources/wbn/static-element/resources/script.js?x=<3D><>"></script>
|
||||
|
||||
<script>
|
||||
const onLoadPromise = new Promise((resolve) => {
|
||||
window.addEventListener('load', resolve, false);
|
||||
});
|
||||
|
||||
promise_test(async () => {
|
||||
await onLoadPromise;
|
||||
assert_equals(resources_script_result, 'loaded from webbundle');
|
||||
}, "Query encoding should be correctly handled in non utf-8 encoding document.");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Subresource loading using relative URLs in the 'resources' attribute with a base element</title>
|
||||
<base href="../resources/wbn/static-element/">
|
||||
<link rel="help" href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/test-helpers.js"></script>
|
||||
|
||||
<body>
|
||||
<link
|
||||
rel="webbundle"
|
||||
href="../static-element.wbn"
|
||||
resources="resources/script.js"/>
|
||||
<script id="script" src="resources/script.js"></script>
|
||||
|
||||
<script>
|
||||
const onLoadPromise = new Promise((resolve) => {
|
||||
window.addEventListener('load', resolve, false);
|
||||
});
|
||||
|
||||
promise_test(async () => {
|
||||
await onLoadPromise;
|
||||
|
||||
assert_equals(resources_script_result, 'loaded from webbundle');
|
||||
}, "A subresource script.js should be loaded from WebBundle using the relative URL and a base element.");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,60 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Subresource loading using relative URLs in the 'resources' attribute</title>
|
||||
<link rel="help" href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/test-helpers.js"></script>
|
||||
|
||||
<body>
|
||||
<link
|
||||
rel="webbundle"
|
||||
href="../resources/wbn/static-element.wbn"
|
||||
resources="/web-bundle/resources/wbn/static-element/resources/script.js"/>
|
||||
<script id="script" src="/web-bundle/resources/wbn/static-element/resources/script.js"></script>
|
||||
|
||||
<script>
|
||||
const onLoadPromise = new Promise((resolve) => {
|
||||
window.addEventListener('load', resolve, false);
|
||||
});
|
||||
|
||||
/*
|
||||
This test tries to load 'script.js' subresource from a static-element.wbn, using
|
||||
a relative URL instead of an absolute one with a <link> and <script> elements
|
||||
directly in the document (they are used only for this test).
|
||||
*/
|
||||
promise_test(async () => {
|
||||
await onLoadPromise;
|
||||
|
||||
assert_equals(resources_script_result, 'loaded from webbundle');
|
||||
}, "A subresource script.js should be loaded from WebBundle using the relative URL.");
|
||||
|
||||
// Simple load of a root.js subresource from subresource.wbn using a relative URL.
|
||||
promise_test(async () => {
|
||||
const link = document.createElement("link");
|
||||
const resource_url = '/web-bundle/resources/wbn/root.js';
|
||||
link.rel = "webbundle";
|
||||
link.href = "../resources/wbn/subresource.wbn";
|
||||
link.resources.add(resource_url);
|
||||
document.body.appendChild(link);
|
||||
|
||||
const response = await fetch(resource_url);
|
||||
assert_true(response.ok);
|
||||
const root = await response.text();
|
||||
assert_equals(root, "export * from './submodule.js';\n");
|
||||
}, "Subresources with relative URLs should be loaded from the WebBundle.");
|
||||
|
||||
// Simple load of a root.js subresource from subresource.wbn using an
|
||||
// incorrect relative URL leading to a failed fetch.
|
||||
promise_test(async () => {
|
||||
const link = document.createElement("link");
|
||||
const resource_url = 'web-bundle/resources/wbn/root.js';
|
||||
link.rel = "webbundle";
|
||||
link.href = "../resources/wbn/subresource.wbn";
|
||||
link.resources.add(resource_url);
|
||||
document.body.appendChild(link);
|
||||
|
||||
const response = await fetch(resource_url);
|
||||
assert_false(response.ok);
|
||||
}, "Wrong relative URL should result in a failed fetch.");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE HTML>
|
||||
<meta charset=utf-8>
|
||||
<title>Resource timing attributes are consistent for the same-origin subresources.</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
const link = document.createElement("link");
|
||||
link.rel = "webbundle";
|
||||
link.href = "../resources/wbn/dynamic1.wbn?pipe=trickle(d0.5)";
|
||||
link.resources.add('https://web-platform.test:8444/web-bundle/resources/wbn/dynamic/resource1.js');
|
||||
const script_id = 'https://web-platform.test:8444/web-bundle/resources/wbn/dynamic/resource1.js';
|
||||
document.body.appendChild(link);
|
||||
var script_entries = 0;
|
||||
var web_bundle_entries = 0;
|
||||
var web_bundle_entry, script_entry;
|
||||
const promise = new Promise(resolve => {
|
||||
new PerformanceObserver(t.step_func(entryList => {
|
||||
var entries = entryList.getEntriesByType("resource");
|
||||
for (var i = 0; i < entries.length; ++i) {
|
||||
if (entries[i].name === script_id) {
|
||||
script_entry = entries[i];
|
||||
script_entries++;
|
||||
}
|
||||
|
||||
if (entries[i].name === 'https://web-platform.test:8444/web-bundle/resources/wbn/dynamic1.wbn?pipe=trickle(d0.5)') {
|
||||
web_bundle_entry = entries[i];
|
||||
web_bundle_entries++;
|
||||
}
|
||||
}
|
||||
|
||||
if (web_bundle_entries > 0 && script_entries > 0) {
|
||||
// Check timestamps.
|
||||
assert_greater_than_equal(script_entry.responseStart, script_entry.requestStart + 500);
|
||||
assert_greater_than_equal(script_entry.responseStart, web_bundle_entry.responseStart);
|
||||
assert_greater_than_equal(script_entry.responseEnd, script_entry.responseStart);
|
||||
assert_greater_than_equal(script_entry.requestStart, script_entry.connectEnd);
|
||||
assert_greater_than_equal(script_entry.responseEnd, script_entry.responseStart);
|
||||
// Check sizes.
|
||||
assert_greater_than(script_entry.encodedBodySize, 0);
|
||||
assert_equals(script_entry.transferSize, script_entry.encodedBodySize + 300);
|
||||
assert_equals(script_entry.encodedBodySize, script_entry.decodedBodySize);
|
||||
resolve();
|
||||
}
|
||||
})).observe({entryTypes: ["resource"]});
|
||||
});
|
||||
const script = document.createElement("script");
|
||||
script.type = "module";
|
||||
script.src = script_id;
|
||||
document.body.appendChild(script);
|
||||
return promise;
|
||||
}, '"Timestamp attributes filled in resource timing entries should be consistent."');
|
||||
</script>
|
||||
<h1>Resource timing attributes are consistent</h1>
|
||||
<p>
|
||||
This test verifies that attributes filled in the PerformanceResourceTiming entries for subresources
|
||||
loaded from the WebBundle are consistent.
|
||||
</p>
|
||||
<div id="log"></div>
|
||||
</body>
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<!DOCTYPE HTML>
|
||||
<meta charset=utf-8>
|
||||
<title>Resource timing entries present for urn:uuid resources</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
const frame_id = 'urn:uuid:429fcc4e-0696-4bad-b099-ee9175f023ae';
|
||||
const script_id = 'urn:uuid:020111b3-437a-4c5c-ae07-adb6bbffb720';
|
||||
const link = document.createElement("link");
|
||||
link.rel = "webbundle";
|
||||
link.href = "../resources/wbn/urn-uuid.wbn";
|
||||
link.resources.add(frame_id, script_id);
|
||||
document.body.appendChild(link);
|
||||
var iframe_entries = 0;
|
||||
var script_entries = 0;
|
||||
// Declare the report_result function as outputting into stderr
|
||||
// because it is used in the WebBundle script to report the script load.
|
||||
window.report_result = console.error;
|
||||
const promise = new Promise(resolve => {
|
||||
new PerformanceObserver(t.step_func(entryList => {
|
||||
var entries = entryList.getEntriesByType("resource");
|
||||
for (var i = 0; i < entries.length; ++i) {
|
||||
// Ignore any entries for the test harness files if present.
|
||||
if (/testharness(report)?\.js/.test(entries[i].name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entries[i].name === frame_id)
|
||||
++iframe_entries;
|
||||
if (entries[i].name === script_id)
|
||||
++script_entries;
|
||||
}
|
||||
if (iframe_entries == 1 && script_entries == 1) {
|
||||
resolve();
|
||||
}
|
||||
})).observe({entryTypes: ["resource"]});
|
||||
});
|
||||
// Add iframe and the script so we get the ResourceTiming
|
||||
const iframe = document.createElement("iframe");
|
||||
iframe.src = frame_id;
|
||||
document.body.appendChild(iframe);
|
||||
const script = document.createElement("script");
|
||||
script.src = script_id;
|
||||
document.body.appendChild(script);
|
||||
return promise;
|
||||
}, '"Each urn:uuid resource should have exactly 1 ResourceTiming entry."');
|
||||
</script>
|
||||
<h1>Resource timing entries present for urn:uuid resources</h1>
|
||||
<p>
|
||||
This test makes sure that ResourceTiming entries (exactly 1 per resource) are created for urn:uuid resources served from a webbundle.
|
||||
</p>
|
||||
<div id="log"></div>
|
||||
</body>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Web Bundle fetching failed due to not found error</title>
|
||||
<link rel="help" href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/test-helpers.js"></script>
|
||||
|
||||
<body>
|
||||
<!--
|
||||
This test uses a non-existing WebBundle,
|
||||
https://web-platform.test:8444/web-bundle/resources/wbn/cors/non-existing.wbn.
|
||||
|
||||
The intent of this test is to check if failing to fetch a WebBundle due to not
|
||||
found error also makes subresource fetch requests fail.
|
||||
-->
|
||||
<script>
|
||||
promise_test(async () => {
|
||||
const prefix =
|
||||
"https://web-platform.test:8444/web-bundle/resources/wbn/";
|
||||
const resources = [
|
||||
prefix + "resource.js",
|
||||
];
|
||||
const link = await addLinkAndWaitForError(
|
||||
prefix + "non-existing.wbn",
|
||||
resources,
|
||||
undefined
|
||||
);
|
||||
|
||||
// Can not fetch a subresource because Web Bundle fetch failed.
|
||||
await fetchAndWaitForReject(prefix + "resource.js");
|
||||
}, "Subresource fetch requests for non-existing Web Bundle should fail.");
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue