From 444b9f5a59abb9752a71175646b7c4852de86849 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Tue, 3 Oct 2023 11:12:27 +0000 Subject: [PATCH] Bug 1856013 [wpt PR 42249] - Add test for insertion of new
elements into a group., a=testonly Automatic update from web-platform-tests Add test for insertion of new
elements into a group. I realized this test was missing due to https://github.com/whatwg/html/pull/9400#discussion_r1341386811 Bug: 1444057 Change-Id: I18d5b553d2ab20543b37e190c1768703b43ac843 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4903590 Auto-Submit: David Baron Reviewed-by: Joey Arhar Commit-Queue: Joey Arhar Cr-Commit-Position: refs/heads/main@{#1203408} -- wpt-commits: 59cd10c8c3296f14addd02e7ad2c35da7b6afb1a wpt-pr: 42249 --- .../name-attribute.tentative.html | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/testing/web-platform/tests/html/semantics/interactive-elements/the-details-element/name-attribute.tentative.html b/testing/web-platform/tests/html/semantics/interactive-elements/the-details-element/name-attribute.tentative.html index 9dcfdee5589bd..6f45b3da089e3 100644 --- a/testing/web-platform/tests/html/semantics/interactive-elements/the-details-element/name-attribute.tentative.html +++ b/testing/web-platform/tests/html/semantics/interactive-elements/the-details-element/name-attribute.tentative.html @@ -359,5 +359,61 @@ assert_element_states(elements, [1, 0, 0], "states after insertion by parser"); }, "closing as a result of parsing doesn't depend on attribute order"); +promise_test(async t => { + container.innerHTML = ` +
+
+ `; + let elements = [ document.getElementById("e0"), + document.getElementById("e1") ]; + + assert_element_states(elements, [1, 0], "states before first mutation"); + + let make_details = () => { + let e = document.createElement("details"); + e.setAttribute("name", "a"); + return e; + }; + + let watch_e0 = new EventWatcher(t, elements[0], ['toggle']); + let watch_e1 = new EventWatcher(t, elements[1], ['toggle']); + + let expect_opening = async (watcher) => { + await watcher.wait_for(['toggle'], {record: 'all'}).then((events) => { + assert_equals(events[0].oldState, "closed"); + assert_equals(events[0].newState, "open"); + }); + }; + + let expect_closing = async (watcher) => { + await watcher.wait_for(['toggle'], {record: 'all'}).then((events) => { + assert_equals(events[0].oldState, "open"); + assert_equals(events[0].newState, "closed"); + }); + }; + + await expect_opening(watch_e0); + + // Test appending an open element in the group. + let new1 = make_details(); + let watch_new1 = new EventWatcher(t, new1, ['toggle']); + new1.open = true; + await expect_opening(watch_new1); + container.appendChild(new1); + await expect_closing(watch_new1); + + // Test appending a closed element in the group. + let new2 = make_details(); + let watch_new2 = new EventWatcher(t, new2, ['toggle']); + container.appendChild(new2); + + // Test inserting an open element at the start of the group. + let new3 = make_details(); + new3.open = true; // this time do this before creating the EventWatcher + let watch_new3 = new EventWatcher(t, new3, ['toggle']); + await expect_opening(watch_new3); + container.insertBefore(new3, elements[0]); + await expect_closing(watch_new3); +}, "handling of insertion of elements into group");