From 07c366cbf3a78c44f8fc0084b052141db711079c Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 16 Jan 2025 01:48:45 +0000 Subject: [PATCH] Bug 1939171 [wpt PR 49846] - DOM: Add basic moveBefore() MutationObserver tests, a=testonly Automatic update from web-platform-tests DOM: Add basic moveBefore() MutationObserver tests See /~https://github.com/whatwg/dom/pull/1307#issuecomment-2554793998. R=nrosenthalchromium.org Bug: 40150299 Change-Id: I6be9d91d4e20690694fb20480f0d1d13a766b117 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6108064 Reviewed-by: Noam Rosenthal Commit-Queue: Dominic Farolino Cr-Commit-Position: refs/heads/main{#1400321} -- wpt-commits: a53473e775d7da1c4ccb9e67d5b5a3f72e7223b2 wpt-pr: 49846 UltraBlame original commit: f3c0448263a2e25020e8474c519e842535771a93 --- .../tentative/mutation-observer.html | 450 ++++++++++++++++++ 1 file changed, 450 insertions(+) create mode 100644 testing/web-platform/tests/dom/nodes/moveBefore/tentative/mutation-observer.html diff --git a/testing/web-platform/tests/dom/nodes/moveBefore/tentative/mutation-observer.html b/testing/web-platform/tests/dom/nodes/moveBefore/tentative/mutation-observer.html new file mode 100644 index 000000000000..abc4ef5fb2c7 --- /dev/null +++ b/testing/web-platform/tests/dom/nodes/moveBefore/tentative/mutation-observer.html @@ -0,0 +1,450 @@ +< +! +DOCTYPE +html +> +< +title +> +slotchanged +event +< +/ +title +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +body +> +< +div +id += +oldParent +> +< +p +id += +target +> +< +/ +p +> +< +/ +div +> +< +div +id += +newParent +> +< +/ +div +> +< +script +> +async +function +runTest +( +oldParent +target +newParent +) +{ +const +observations += +[ +] +; +const +observer += +new +MutationObserver +( +mutationList += +> +observations +. +push +( +mutationList +) +) +; +observer +. +observe +( +oldParent +{ +childList +: +true +} +) +; +observer +. +observe +( +target +{ +childList +: +true +} +) +; +observer +. +observe +( +newParent +{ +childList +: +true +} +) +; +newParent +. +moveBefore +( +target +null +) +; +/ +/ +Wait +for +microtasks +to +settle +. +await +new +Promise +( +resolve += +> +queueMicrotask +( +resolve +) +) +; +assert_equals +( +observations +. +length +1 +" +MutationObserver +has +emitted +a +single +mutation +list +" +) +; +assert_equals +( +observations +[ +0 +] +. +length +2 +" +Mutation +list +has +two +MutationRecords +" +) +; +const +removalRecord += +observations +[ +0 +] +[ +0 +] +; +const +insertionRecord += +observations +[ +0 +] +[ +1 +] +; +assert_equals +( +removalRecord +. +target +oldParent +" +removalRecord +target +is +correct +" +) +; +assert_equals +( +removalRecord +. +removedNodes +[ +0 +] +target +" +removedNodes +contains +the +moved +node +" +) +; +assert_equals +( +insertionRecord +. +target +newParent +" +insertionRecord +target +is +correct +" +) +; +assert_equals +( +insertionRecord +. +addedNodes +[ +0 +] +target +" +addedNodes +contains +the +moved +node +" +) +; +observer +. +disconnect +( +) +; +} +promise_test +( +async +t += +> +{ +await +runTest +( +oldParent +target +newParent +) +; +} +" +[ +Connected +move +] +MutationObserver +removal ++ +insertion +is +tracked +by +moveBefore +( +) +" +) +; +promise_test +( +async +t += +> +{ +const +oldParent += +document +. +createElement +( +' +div +' +) +; +const +target += +document +. +createElement +( +' +p +' +) +; +const +newParent += +document +. +createElement +( +' +div +' +) +; +/ +/ +We +must +append +newParent +as +well +since +the +origin +and +destination +nodes +/ +/ +must +share +the +same +shadow +- +including +root +. +oldParent +. +append +( +target +newParent +) +; +await +runTest +( +oldParent +target +newParent +) +; +} +" +[ +Disconnected +move +] +MutationObserver +removal ++ +insertion +is +tracked +by +moveBefore +( +) +" +) +; +< +/ +script +>