|
| 1 | +<!DOCTYPE html> |
| 2 | +<script src="../../../testing.js"></script> |
| 3 | + |
| 4 | +<script id=force_async> |
| 5 | +{ |
| 6 | + // Dynamically created scripts have async=true by default |
| 7 | + let s = document.createElement('script'); |
| 8 | + testing.expectEqual(true, s.async); |
| 9 | + |
| 10 | + // Setting async=false clears the force async flag and removes attribute |
| 11 | + s.async = false; |
| 12 | + testing.expectEqual(false, s.async); |
| 13 | + testing.expectEqual(false, s.hasAttribute('async')); |
| 14 | + |
| 15 | + // Setting async=true adds the attribute |
| 16 | + s.async = true; |
| 17 | + testing.expectEqual(true, s.async); |
| 18 | + testing.expectEqual(true, s.hasAttribute('async')); |
| 19 | +} |
| 20 | +</script> |
| 21 | + |
| 22 | +<script></script> |
| 23 | +<script id=empty> |
| 24 | +{ |
| 25 | + // Empty parser-inserted script should have async=true (force async retained) |
| 26 | + let scripts = document.getElementsByTagName('script'); |
| 27 | + let emptyScript = scripts[scripts.length - 2]; |
| 28 | + testing.expectEqual(true, emptyScript.async); |
| 29 | +} |
| 30 | +</script> |
| 31 | + |
| 32 | +<script id=text_content> |
| 33 | +{ |
| 34 | + let s = document.createElement('script'); |
| 35 | + s.appendChild(document.createComment('COMMENT')); |
| 36 | + s.appendChild(document.createTextNode(' TEXT ')); |
| 37 | + s.appendChild(document.createProcessingInstruction('P', 'I')); |
| 38 | + let a = s.appendChild(document.createElement('a')); |
| 39 | + a.appendChild(document.createTextNode('ELEMENT')); |
| 40 | + |
| 41 | + // script.text should return only direct Text node children |
| 42 | + testing.expectEqual(' TEXT ', s.text); |
| 43 | + // script.textContent should return all descendant text |
| 44 | + testing.expectEqual(' TEXT ELEMENT', s.textContent); |
| 45 | +} |
| 46 | +</script> |
| 47 | + |
| 48 | +<script id=lazy_inline> |
| 49 | +{ |
| 50 | + // Empty script in DOM, then append text - should execute |
| 51 | + window.lazyScriptRan = false; |
| 52 | + let s = document.createElement('script'); |
| 53 | + document.head.appendChild(s); |
| 54 | + // Script is in DOM but empty, so not yet executed |
| 55 | + testing.expectEqual(false, window.lazyScriptRan); |
| 56 | + // Append text node with code |
| 57 | + s.appendChild(document.createTextNode('window.lazyScriptRan = true;')); |
| 58 | + // Now it should have executed |
| 59 | + testing.expectEqual(true, window.lazyScriptRan); |
| 60 | +} |
| 61 | +</script> |
0 commit comments