relative-url-scopes.https.tentative.html (2624B)
1 <!DOCTYPE html> 2 <title>Subresource loading using relative URLs in the 'scopes'</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(scope) { 27 return createWebBundleElement( 28 "../resources/wbn/relative-url.wbn", 29 /*resources=*/ [], 30 { scopes: [scope] } 31 ); 32 } 33 34 async function assertResourceCanBeFetched() { 35 const response = await fetch( 36 "../resources/wbn/relative-url/subdirectory-path.js" 37 ); 38 const text = await response.text(); 39 assert_equals(text, "scriptLoaded('subdirectory-path.js');"); 40 } 41 42 async function assertResourceNotFound() { 43 const response = await fetch( 44 "../resources/wbn/relative-url/subdirectory-path.js" 45 ); 46 const status = await response.status; 47 assert_equals(status, 404); 48 } 49 50 promise_test(async (t) => { 51 t.add_cleanup(cleanUp); 52 script = createScriptWebBundle("relative-url"); 53 document.body.append(script); 54 await assertResourceCanBeFetched(); 55 }, "A relative URL, 'relative-url', should be resolved on the bundle's URL"); 56 57 promise_test(async (t) => { 58 t.add_cleanup(cleanUp); 59 script = createScriptWebBundle("./relative-url"); 60 document.body.append(script); 61 await assertResourceCanBeFetched(); 62 }, "Use './relative-url', starting with dot"); 63 64 promise_test(async (t) => { 65 t.add_cleanup(cleanUp); 66 script = createScriptWebBundle("../wbn/relative-url"); 67 document.body.append(script); 68 await assertResourceCanBeFetched(); 69 }, "Use '../wbn/relative-url', starting with two dots"); 70 71 promise_test(async (t) => { 72 t.add_cleanup(cleanUp); 73 script = createScriptWebBundle("/web-bundle/resources/wbn/relative-url"); 74 document.body.append(script); 75 await assertResourceCanBeFetched(); 76 }, "Use '/web-bundle/resources/wbn/relative-url', starting with slash"); 77 78 promise_test(async (t) => { 79 t.add_cleanup(cleanUp); 80 script = createScriptWebBundle("unrelated-scope"); 81 document.body.append(script); 82 await assertResourceNotFound(); 83 }, "A resource should not be found"); 84 </script> 85 </body>