relative-url-resources.https.tentative.html (2490B)
1 <!DOCTYPE html> 2 <title>Subresource loading using relative URLs in the 'resources'</title> 3 <link 4 rel="help" 5 href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md" 6 /> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="../resources/test-helpers.js"></script> 10 11 <script> 12 setup(() => { 13 assert_true(HTMLScriptElement.supports("webbundle")); 14 }); 15 </script> 16 <body> 17 <script> 18 let script; 19 20 function cleanUp() { 21 if (script) { 22 script.remove(); 23 } 24 } 25 26 function createScriptWebBundle(resource) { 27 return createWebBundleElement( 28 "../resources/wbn/subresource.wbn", 29 /*resources=*/ [resource] 30 ); 31 } 32 33 async function assertResourceCanBeFetched() { 34 const response = await fetch(`../resources/wbn/root.js`); 35 const text = await response.text(); 36 assert_equals(text, "export * from './submodule.js';\n"); 37 } 38 39 async function assertResourceNotFound() { 40 const response = await fetch(`../resources/wbn/root.js`); 41 const status = await response.status; 42 assert_equals(status, 404); 43 } 44 45 promise_test(async (t) => { 46 t.add_cleanup(cleanUp); 47 script = createScriptWebBundle("root.js"); 48 document.body.append(script); 49 await assertResourceCanBeFetched(); 50 }, "A relative URL, 'root.js', should be resolved on the bundle's URL"); 51 52 promise_test(async (t) => { 53 t.add_cleanup(cleanUp); 54 script = createScriptWebBundle("./root.js"); 55 document.body.append(script); 56 await assertResourceCanBeFetched(); 57 }, "Use './root.js', starting with dot"); 58 59 promise_test(async (t) => { 60 t.add_cleanup(cleanUp); 61 script = createScriptWebBundle("../wbn/root.js"); 62 document.body.append(script); 63 await assertResourceCanBeFetched(); 64 }, "Use '../wbn/root.js', starting with two dots"); 65 66 promise_test(async (t) => { 67 t.add_cleanup(cleanUp); 68 script = createScriptWebBundle("/web-bundle/resources/wbn/root.js"); 69 document.body.append(script); 70 await assertResourceCanBeFetched(); 71 }, "Use '/web-bundle/resources/wbn/root.js', starting with slash"); 72 73 promise_test(async (t) => { 74 t.add_cleanup(cleanUp); 75 script = createScriptWebBundle("unrelated-relative-url.js"); 76 document.body.append(script); 77 await assertResourceNotFound(); 78 }, "A resource should not be found"); 79 </script> 80 </body>