blob: a5d818fe7bdfbea1f6acf301cbf9935ec47e2ca4 [file] [log] [blame]
<!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>