Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit f3383ab

Browse files
dbaronmoz-wptsync-bot
authored andcommitted
Bug 1856976 [wpt PR 42335] - Update mutation event suppression for <details name> to revised spec rules., a=testonly
Automatic update from web-platform-tests Update mutation event suppression for <details name> to revised spec rules. The rules for mutation event suppression for <details name> were revised during the process of reviewing the spec PR, based on the discussion starting at whatwg/html#9400 (comment) . The updated spec says that mutation events are suppressed during the "ensure details exclusivity by closing other elements if needed" and "ensure details exclusivity by closing the given element if needed" algorithms. This updates the implementation and tests to follow that rule. (The "handling of insertion of elements into group" test is testing the case where the events were already suppressed.) This also renames the test to remove "tentative" from the name, since the spec PR is landed and the test is now (with this change) up-to-date with the spec. Bug: 1444057 Change-Id: I9078beeb3527f2515f6e10efbf93a94232221238 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4912273 Commit-Queue: David Baron <[email protected]> Reviewed-by: Joey Arhar <[email protected]> Cr-Commit-Position: refs/heads/main@{#1205367} -- wpt-commits: a4288b9d453a8c48078b3e93a58c86cf97ac3551 wpt-pr: 42335
1 parent 2953d19 commit f3383ab

File tree

1 file changed

+54
-4
lines changed
  • testing/web-platform/tests/html/semantics/interactive-elements/the-details-element

1 file changed

+54
-4
lines changed
Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
if (mutation_event_received_ids.length == 0) {
154154
// ok if mutation events are not supported
155155
} else {
156-
assert_array_equals(mutation_event_received_ids, ["e0", "e1"],
157-
"removal event followed by addition event");
156+
assert_array_equals(mutation_event_received_ids, ["e1"],
157+
"mutation events received only for open attribute mutation and not for closing other element");
158158
}
159159
assert_element_states(elements, [0, 1, 0, 0], "states after mutation");
160160
assert_array_equals(toggle_event_received_ids, [], "toggle events received before awaiting promises");
@@ -205,8 +205,8 @@
205205
assert_array_equals(received_ids, []);
206206
assert_element_states(elements, [1, 0, 0], "states before mutation");
207207
elements[1].open = true;
208-
assert_array_equals(received_ids, ["e0", "e1"],
209-
"removal events received in tree order, followed by addition event, despite changes to name during mutation event");
208+
assert_array_equals(received_ids, ["e1"],
209+
"mutation events received only for open attribute mutation and not for closing other element");
210210
assert_element_states(elements, [0, 1, 0], "states after mutation");
211211
}, "interaction of open attribute changes with mutation events");
212212

@@ -336,14 +336,47 @@
336336
document.getElementById("e1"),
337337
document.getElementById("e2") ];
338338

339+
let mutation_received_ids = [];
340+
let listener = event => {
341+
mutation_received_ids.push(event.target.id);
342+
};
343+
for (let element of elements) {
344+
element.addEventListener("DOMSubtreeModified", listener);
345+
}
346+
339347
assert_element_states(elements, [1, 0, 1], "states before first mutation");
348+
assert_array_equals(mutation_received_ids, [], "mutation events received before first mutation");
340349
elements[2].name = "a";
341350
assert_element_states(elements, [1, 0, 0], "states after first mutation");
351+
if (mutation_received_ids.length != 0) {
352+
// OK to not support mutation events, or to send DOMSubtreeModified
353+
// only for attribute addition/removal (open) but not for attribute
354+
// change (name)
355+
assert_array_equals(mutation_received_ids, ["e2"], "mutation events received after first mutation");
356+
}
342357
elements[0].name = "c";
343358
elements[2].open = true;
344359
assert_element_states(elements, [1, 0, 1], "states before second mutation");
360+
if (mutation_received_ids.length != 0) { // OK to not support mutation events
361+
if (mutation_received_ids.length == 1) {
362+
// OK to receive DOMSubtreeModified for attribute addition/removal
363+
// (open) but not for attribute change (name)
364+
assert_array_equals(mutation_received_ids, ["e2"], "mutation events received before second mutation");
365+
} else {
366+
assert_array_equals(mutation_received_ids, ["e2", "e0", "e2"], "mutation events received before second mutation");
367+
}
368+
}
345369
elements[0].name = "a";
346370
assert_element_states(elements, [0, 0, 1], "states after second mutation");
371+
if (mutation_received_ids.length != 0) { // OK to not support mutation events
372+
if (mutation_received_ids.length == 1) {
373+
// OK to receive DOMSubtreeModified for attribute addition/removal
374+
// (open) but not for attribute change (name)
375+
assert_array_equals(mutation_received_ids, ["e2"], "mutation events received before second mutation");
376+
} else {
377+
assert_array_equals(mutation_received_ids, ["e2", "e0", "e2", "e0"], "mutation events received after second mutation");
378+
}
379+
}
347380
}, "handling of name attribute changes");
348381

349382
promise_test(async t => {
@@ -392,28 +425,45 @@
392425
});
393426
};
394427

428+
let track_mutations = (element) => {
429+
let result = { count: 0 };
430+
let listener = event => {
431+
++result.count;
432+
};
433+
element.addEventListener("DOMSubtreeModified", listener);
434+
return result;
435+
}
436+
395437
await expect_opening(watch_e0);
396438

397439
// Test appending an open element in the group.
398440
let new1 = make_details();
441+
let mutations1 = track_mutations(new1);
399442
let watch_new1 = new EventWatcher(t, new1, ['toggle']);
400443
new1.open = true;
444+
assert_in_array(mutations1.count, [0, 1], "mutation events count before inserting new1");
401445
await expect_opening(watch_new1);
402446
container.appendChild(new1);
403447
await expect_closing(watch_new1);
448+
assert_in_array(mutations1.count, [0, 1], "mutation events count after inserting new1");
404449

405450
// Test appending a closed element in the group.
406451
let new2 = make_details();
452+
let mutations2 = track_mutations(new2);
407453
let watch_new2 = new EventWatcher(t, new2, ['toggle']);
408454
container.appendChild(new2);
455+
assert_equals(mutations2.count, 0, "mutation events count after inserting new2");
409456

410457
// Test inserting an open element at the start of the group.
411458
let new3 = make_details();
459+
let mutations3 = track_mutations(new3);
412460
new3.open = true; // this time do this before creating the EventWatcher
413461
let watch_new3 = new EventWatcher(t, new3, ['toggle']);
462+
assert_in_array(mutations3.count, [0, 1], "mutation events count before inserting new3");
414463
await expect_opening(watch_new3);
415464
container.insertBefore(new3, elements[0]);
416465
await expect_closing(watch_new3);
466+
assert_in_array(mutations3.count, [0, 1], "mutation events count after inserting new3");
417467
}, "handling of insertion of elements into group");
418468

419469
</script>

0 commit comments

Comments
 (0)