|
| 1 | +<!doctype html> |
| 2 | +<meta charset=utf-8> |
| 3 | +<link rel=help href=https://github.com/whatwg/html/pull/10188#discussion_r1719338657> |
| 4 | +<title>Adding/changing src attribute does "prepare the script"</title> |
| 5 | +<script src="/resources/testharness.js"></script> |
| 6 | +<script src="/resources/testharnessreport.js"></script> |
| 7 | + |
| 8 | +<body> |
| 9 | +<script> |
| 10 | +// The "old" HTML Standard specification text around `src` attribute mutation |
| 11 | +// for non-parser-inserted scripts *ONLY* "prepared"/run the script iff the src |
| 12 | +// attribute "previously had no such attribute". This changed in |
| 13 | +// https://github.com/whatwg/html/pull/10188 to align with a majority of |
| 14 | +// browsers. This test ensures that `src` mutations on these kinds of scripts |
| 15 | +// *where a previous valid `src` attribute existed* do indeed "prepare" the |
| 16 | +// script. |
| 17 | +promise_test(async () => { |
| 18 | + window.didExecute = false; |
| 19 | + |
| 20 | + const script = document.createElement('script'); |
| 21 | + // Invalid type, so the script won't execute upon insertion. |
| 22 | + script.type = 'invalid'; |
| 23 | + script.src = 'resources/flag-setter.js'; |
| 24 | + document.body.append(script); |
| 25 | + assert_false(window.didExecute); |
| 26 | + |
| 27 | + // Make script valid, but don't immediately execute it. |
| 28 | + script.type = ''; |
| 29 | + |
| 30 | + const scriptPromise = new Promise(resolve => { |
| 31 | + script.onload = resolve; |
| 32 | + }); |
| 33 | + |
| 34 | + // Mutating the `src` attribute, which has an existing valid value, triggers |
| 35 | + // the "prepare a script" algorithm via the post-connection steps. |
| 36 | + script.src = 'resources/flag-setter.js?different'; |
| 37 | + |
| 38 | + await scriptPromise; |
| 39 | + assert_true(window.didExecute); |
| 40 | +}, "Mutating `src` attribute from an already-valid value does 'prepare' the script"); |
| 41 | +</script> |
| 42 | +</body> |
0 commit comments