|
153 | 153 | if (mutation_event_received_ids.length == 0) {
|
154 | 154 | // ok if mutation events are not supported
|
155 | 155 | } 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"); |
158 | 158 | }
|
159 | 159 | assert_element_states(elements, [0, 1, 0, 0], "states after mutation");
|
160 | 160 | assert_array_equals(toggle_event_received_ids, [], "toggle events received before awaiting promises");
|
|
205 | 205 | assert_array_equals(received_ids, []);
|
206 | 206 | assert_element_states(elements, [1, 0, 0], "states before mutation");
|
207 | 207 | 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"); |
210 | 210 | assert_element_states(elements, [0, 1, 0], "states after mutation");
|
211 | 211 | }, "interaction of open attribute changes with mutation events");
|
212 | 212 |
|
|
336 | 336 | document.getElementById("e1"),
|
337 | 337 | document.getElementById("e2") ];
|
338 | 338 |
|
| 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 | + |
339 | 347 | assert_element_states(elements, [1, 0, 1], "states before first mutation");
|
| 348 | + assert_array_equals(mutation_received_ids, [], "mutation events received before first mutation"); |
340 | 349 | elements[2].name = "a";
|
341 | 350 | 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 | + } |
342 | 357 | elements[0].name = "c";
|
343 | 358 | elements[2].open = true;
|
344 | 359 | 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 | + } |
345 | 369 | elements[0].name = "a";
|
346 | 370 | 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 | + } |
347 | 380 | }, "handling of name attribute changes");
|
348 | 381 |
|
349 | 382 | promise_test(async t => {
|
|
392 | 425 | });
|
393 | 426 | };
|
394 | 427 |
|
| 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 | + |
395 | 437 | await expect_opening(watch_e0);
|
396 | 438 |
|
397 | 439 | // Test appending an open element in the group.
|
398 | 440 | let new1 = make_details();
|
| 441 | + let mutations1 = track_mutations(new1); |
399 | 442 | let watch_new1 = new EventWatcher(t, new1, ['toggle']);
|
400 | 443 | new1.open = true;
|
| 444 | + assert_in_array(mutations1.count, [0, 1], "mutation events count before inserting new1"); |
401 | 445 | await expect_opening(watch_new1);
|
402 | 446 | container.appendChild(new1);
|
403 | 447 | await expect_closing(watch_new1);
|
| 448 | + assert_in_array(mutations1.count, [0, 1], "mutation events count after inserting new1"); |
404 | 449 |
|
405 | 450 | // Test appending a closed element in the group.
|
406 | 451 | let new2 = make_details();
|
| 452 | + let mutations2 = track_mutations(new2); |
407 | 453 | let watch_new2 = new EventWatcher(t, new2, ['toggle']);
|
408 | 454 | container.appendChild(new2);
|
| 455 | + assert_equals(mutations2.count, 0, "mutation events count after inserting new2"); |
409 | 456 |
|
410 | 457 | // Test inserting an open element at the start of the group.
|
411 | 458 | let new3 = make_details();
|
| 459 | + let mutations3 = track_mutations(new3); |
412 | 460 | new3.open = true; // this time do this before creating the EventWatcher
|
413 | 461 | let watch_new3 = new EventWatcher(t, new3, ['toggle']);
|
| 462 | + assert_in_array(mutations3.count, [0, 1], "mutation events count before inserting new3"); |
414 | 463 | await expect_opening(watch_new3);
|
415 | 464 | container.insertBefore(new3, elements[0]);
|
416 | 465 | await expect_closing(watch_new3);
|
| 466 | + assert_in_array(mutations3.count, [0, 1], "mutation events count after inserting new3"); |
417 | 467 | }, "handling of insertion of elements into group");
|
418 | 468 |
|
419 | 469 | </script>
|
0 commit comments