dynamic-adding-preload-imagesrcset.html (1509B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/preload/resources/preload_helper.js"></script> 5 <script> 6 var t = async_test('Makes sure that a dynamically added preload with imagesrcset works'); 7 </script> 8 <body> 9 <script> 10 t.step(function() { 11 verifyPreloadAndRTSupport(); 12 var expectation = new Array(4).fill(0); 13 if (window.devicePixelRatio < 1.5) { 14 expectation[2] = 1; 15 } else if (window.devicePixelRatio >= 1.5) { 16 expectation[3] = 1; 17 } 18 var link = document.createElement("link"); 19 link.as = "image"; 20 link.rel = "preload"; 21 link.href = "resources/square.png?default"; 22 link.imageSrcset = "resources/square.png?200 200w, resources/square.png?400 400w, resources/square.png?800 800w"; 23 link.imageSizes = "400px"; 24 link.onload = t.step_func(function() { 25 t.step_timeout(function() { 26 verifyNumberOfResourceTimingEntries("resources/square.png?default", expectation[0]); 27 verifyNumberOfResourceTimingEntries("resources/square.png?200", expectation[1]); 28 verifyNumberOfResourceTimingEntries("resources/square.png?400", expectation[2]); 29 verifyNumberOfResourceTimingEntries("resources/square.png?800", expectation[3]); 30 t.done(); 31 }, 0); 32 }); 33 document.body.appendChild(link); 34 }); 35 </script> 36 </body>