From aea81603b8b06065734c279dea9caaa414643ee4 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 16 Jun 2023 01:55:51 +0000 Subject: [PATCH] Bug 1837275 [wpt PR 40429] - Test order of toggle events in addition to order of DOMSubtreeModified events., a=testonly Automatic update from web-platform-tests Test order of toggle events in addition to order of DOMSubtreeModified events. I realized while writing https://github.com/whatwg/html/pull/9400#discussion_r1221692104 that the ordering of the `open` attribute manipulation is also exposed through `toggle` events, so this tests those events in addition to `DOMSubtreeModified` events. Bug: 1444057 Change-Id: I6d3c65f5402053d77e4f6c488aa07209181a8cdd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4599204 Reviewed-by: Mason Freed Commit-Queue: David Baron Cr-Commit-Position: refs/heads/main{#1154716} -- wpt-commits: a61c7604859be25ba8fb24ac863ea15d51385e4f wpt-pr: 40429 UltraBlame original commit: c64a32b114f7e14f7ce9cfb33e513b7fc870c5e5 --- .../name-attribute.tentative.html | 435 ++++++++++++------ 1 file changed, 291 insertions(+), 144 deletions(-) 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 2276b2d36d61b..22cecfe4dc018 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 @@ -1004,133 +1004,6 @@ " ) ; -/ -/ -The -next -two -tests -test -characteristics -of -the -design -that -are -only -/ -/ -exposed -via -mutation -events -. -If -mutation -events -( -for -attribute -/ -/ -addition -/ -removal -) -are -removed -from -the -web -these -tests -could -be -/ -/ -removed -and -some -small -simplifications -could -be -made -to -the -code -/ -/ -implementing -this -feature -. -function -mutation_events_for_attribute_removal_supported -( -) -{ -container -. -innerHTML -= -< -div -id -= -" -event -- -removal -- -test -" -> -< -/ -div -> -; -let -element -= -container -. -firstChild -; -let -event_fired -= -false -; -element -. -addEventListener -( -" -DOMSubtreeModified -" -event -= -> -event_fired -= -true -) -; -element -. -removeAttribute -( -" -id -" -) -; -return -event_fired -; -} promise_test ( async @@ -1138,17 +1011,6 @@ = > { -if -( -! -mutation_events_for_attribute_removal_supported -( -) -) -{ -return -; -} container . innerHTML @@ -1284,13 +1146,13 @@ ) ; let -received_ids +mutation_event_received_ids = [ ] ; let -listener +mutation_listener = event = @@ -1335,7 +1197,7 @@ " ) ; -received_ids +mutation_event_received_ids . push ( @@ -1346,6 +1208,18 @@ ; } ; +let +toggle_event_received_ids += +[ +] +; +let +toggle_event_promises += +[ +] +; for ( let @@ -1361,13 +1235,77 @@ " DOMSubtreeModified " -listener +mutation_listener +) +; +toggle_event_promises +. +push +( +new +Promise +( +( +resolve +reject +) += +> +{ +element +. +addEventListener +( +" +toggle +" +event += +> +{ +assert_equals +( +event +. +type +" +toggle +" +) +; +assert_equals +( +event +. +target +element +) +; +toggle_event_received_ids +. +push +( +element +. +id +) +; +resolve +( +undefined +) +; +} +) +; +} +) ) ; } assert_array_equals ( -received_ids +mutation_event_received_ids [ ] ) @@ -1397,9 +1335,31 @@ = true ; +if +( +mutation_event_received_ids +. +length += += +0 +) +{ +/ +/ +ok +if +mutation +events +are +not +supported +} +else +{ assert_array_equals ( -received_ids +mutation_event_received_ids [ " e0 @@ -1429,6 +1389,7 @@ " ) ; +} assert_element_states ( elements @@ -1445,10 +1406,63 @@ " ) ; +assert_array_equals +( +toggle_event_received_ids +[ +] +" +toggle +events +received +before +awaiting +promises +" +) +; +await +Promise +. +all +( +toggle_event_promises +) +; +assert_array_equals +( +toggle_event_received_ids +[ +" +e1 +" +" +e0 +" +" +e3 +" +" +e2 +" +] +" +toggle +events +received +after +awaiting +promises +" +) +; } " mutation event +and +toggle +event order matches order @@ -1462,6 +1476,139 @@ " ) ; +/ +/ +This +function +is +used +to +guard +tests +that +test +behavior +that +is +/ +/ +relevant +only +because +of +Mutation +Events +. +If +mutation +events +( +for +/ +/ +attribute +addition +/ +removal +) +are +removed +from +the +web +the +tests +using +/ +/ +this +function +can +be +removed +. +function +mutation_events_for_attribute_removal_supported +( +) +{ +if +( +! +( +" +MutationEvent +" +in +window +) +) +{ +return +false +; +} +container +. +innerHTML += +< +div +id += +" +event +- +removal +- +test +" +> +< +/ +div +> +; +let +element += +container +. +firstChild +; +let +event_fired += +false +; +element +. +addEventListener +( +" +DOMSubtreeModified +" +event += +> +event_fired += +true +) +; +element +. +removeAttribute +( +" +id +" +) +; +return +event_fired +; +} promise_test ( async