From 68466c59c6930d4b85537430c1d8c31e8ff2ec1c Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 14 Mar 2024 23:01:01 +0000 Subject: [PATCH] Bug 1885162 [wpt PR 45085] - WPT: Script child removal does not trigger execution, a=testonly Automatic update from web-platform-tests WPT: Script child removal does not trigger execution Given the old Chromium change that introduced this behavior: - https://source.chromium.org/chromium/chromium/src/+/604e798ec6ee30f44d57a5c4a44ce3dab3a871ed ... the old discussion in: - https://github.com/whatwg/dom/pull/732#pullrequestreview-328249015 - https://github.com/whatwg/html/pull/4354#issuecomment-476038918 ... and the much newer discussion in: - https://github.com/whatwg/dom/pull/1261 - https://github.com/whatwg/html/pull/10188 This CL upstreams an old test ensuring that removal of a child node from a script node that has not "already started" [1], does not trigger script execution. Only the *insertion* of child nodes (to a non-already-started script node) should trigger that script's execution. [1]: https://html.spec.whatwg.org/C#already-started R=nrosenthal@chromium.org Bug: 40150299 Change-Id: I750ccee0a2be834360c557042e975547c8ddd32c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5367238 Reviewed-by: Noam Rosenthal Commit-Queue: Dominic Farolino Cr-Commit-Position: refs/heads/main@{#1272330} -- wpt-commits: cc99c62762135f7e193941e32c3f738960c256be wpt-pr: 45085 --- ...pt-does-not-run-on-child-removal.window.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 testing/web-platform/tests/dom/nodes/insertion-removing-steps/script-does-not-run-on-child-removal.window.js diff --git a/testing/web-platform/tests/dom/nodes/insertion-removing-steps/script-does-not-run-on-child-removal.window.js b/testing/web-platform/tests/dom/nodes/insertion-removing-steps/script-does-not-run-on-child-removal.window.js new file mode 100644 index 0000000000000..ed5bfbaa60116 --- /dev/null +++ b/testing/web-platform/tests/dom/nodes/insertion-removing-steps/script-does-not-run-on-child-removal.window.js @@ -0,0 +1,33 @@ +// See: +// - https://github.com/whatwg/dom/issues/808 +// - https://github.com/whatwg/dom/pull/1261 +// - https://github.com/whatwg/html/pull/10188 +// - https://source.chromium.org/chromium/chromium/src/+/604e798ec6ee30f44d57a5c4a44ce3dab3a871ed +// - https://github.com/whatwg/dom/pull/732#pullrequestreview-328249015 +// - https://github.com/whatwg/html/pull/4354#issuecomment-476038918 +test(() => { + window.script_did_run = false; + + const script = document.createElement('script'); + // This prevents execution on insertion. + script.type = '0'; + script.textContent = `script_did_run = true;`; + document.body.append(script); + assert_false(script_did_run, + 'Appending script with invalid type does not trigger execution'); + + const div = document.createElement('div'); + script.append(div); + assert_false(script_did_run, + 'Appending a child to an invalid-type script does not trigger execution'); + + // This enables, but does not trigger, execution. + script.type = ''; + assert_false(script_did_run, + 'Unsetting script type does not trigger execution'); + + div.remove(); + assert_false(script_did_run, + 'Removing child from valid script that has not already run, does not ' + + 'trigger execution'); +}, "Script execution is never triggered on child removals");