preload-invalid-resources.html (1160B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/common/utils.js"></script> 5 <script src="/preload/resources/preload_helper.js"></script> 6 <body> 7 <script> 8 9 const invalidImages = { 10 'invalid data': '/preload/resources/echo-with-cors.py?type=image/svg+xml&content=junk', 11 missing: '/nothing.png' 12 } 13 14 Object.entries(invalidImages).forEach(([name, url]) => { 15 promise_test(async t => { 16 const invalidImageURL = getAbsoluteURL(url) 17 const link = document.createElement('link'); 18 link.rel = 'preload'; 19 link.as = 'image'; 20 link.href = url; 21 document.head.appendChild(link); 22 t.add_cleanup(() => link.remove()); 23 await new Promise(resolve => { 24 const img = document.createElement('img'); 25 img.src = url; 26 img.onerror = resolve; 27 document.body.appendChild(img); 28 t.add_cleanup(() => img.remove()); 29 }); 30 verifyNumberOfResourceTimingEntries(url, 1); 31 }, `Preloading an invalid image (${name}) should preload and not re-fetch`) 32 }) 33 34 </script> 35 </body>