HTMLLinkElement-load-event.html (1563B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>Link element load event doesn't block the parser.</title> 4 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> 5 <link rel="author" title="Mozilla" href="https://mozilla.org"> 6 <link rel="help" href="https://html.spec.whatwg.org/#link-type-stylesheet"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script> 10 let NUM_LOADS = 0; 11 </script> 12 <link rel="stylesheet" href="data:text/css,*{}" onload="++NUM_LOADS"> 13 <script> 14 let t = async_test(document.title); 15 window.addEventListener("load", t.step_func_done(() => { 16 assert_equals(NUM_LOADS, 2, "Load event should've fired for all links"); 17 })); 18 t.step(function() { 19 assert_equals(document.styleSheets.length, 1, "Should expose the sheet to the OM before running script"); 20 // We can't quite assert that NUM_LOADS is zero (even though it almost-always 21 // should be the case), in case the parser yields just before executing the 22 // script but after parsing the link load. 23 let loadsBefore = NUM_LOADS; 24 // Intentionally the same href as above, to test caching behavior. 25 document.write(` 26 <link rel="stylesheet" href="data:text/css,*{}" onload="++NUM_LOADS"> 27 `); 28 assert_equals(document.styleSheets.length, 2, "Should expose both sheets to the OM before running second script"); 29 assert_equals(NUM_LOADS, loadsBefore, "Shouldn't fire the load event sync"); 30 assert_not_equals(document.styleSheets[0], document.styleSheets[1], "Should be different sheets"); 31 }); 32 </script>