fetch-public-http-wrong-address-space.html (1359B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Fetch HTTP public targetAddress local resource</title> 4 5 <script src="/resources/testdriver.js"></script> 6 <script src="/resources/testdriver-vendor.js"></script> 7 <script src="support.sub.js"></script> 8 <script> 9 "use strict"; 10 11 // Fetch a public address over HTTP. Fetch is annotated with a 12 // targetAddressSpace of local to try to bypass mixed content, but should 13 // fail because the address space of the resource does not match the target 14 // address space. 15 // 16 // TODO(crbug.com/406991278): consolidate with fetch-local.html adding 17 // options to minimize # of resources needed. 18 Promise.resolve().then(async () => { 19 test_driver.set_test_context(opener); 20 await test_driver.set_permission({ name: 'local-network-access' }, 'granted'); 21 22 const target = { 23 server: Server.HTTP_PUBLIC, 24 behavior: { response: ResponseBehavior.allowCrossOrigin() }, 25 }; 26 const targetUrl = resolveTargetUrl(target); 27 28 fetch(targetUrl, {targetAddressSpace: 'local'}) 29 .then(async function(response) { 30 const body = await response.text(); 31 const message = { 32 ok: response.ok, 33 type: response.type, 34 body: body, 35 }; 36 opener.postMessage(message, "*"); 37 }) 38 .catch(error => { 39 opener.postMessage({ error: error.toString() }, "*"); 40 }); 41 }); 42 </script>