|
| 1 | +<!DOCTYPE html> |
| 2 | +<title>slotchanged event</title> |
| 3 | +<script src="/resources/testharness.js"></script> |
| 4 | +<script src="/resources/testharnessreport.js"></script> |
| 5 | +<body> |
| 6 | + |
| 7 | +<div id=oldParent> |
| 8 | + <p id=target></p> |
| 9 | +</div> |
| 10 | +<div id=newParent></div> |
| 11 | + |
| 12 | +<script> |
| 13 | +async function runTest(oldParent, target, newParent) { |
| 14 | + const observations = []; |
| 15 | + const observer = new MutationObserver(mutationList => observations.push(mutationList)); |
| 16 | + |
| 17 | + observer.observe(oldParent, {childList: true}); |
| 18 | + observer.observe(target, {childList: true}); |
| 19 | + observer.observe(newParent, {childList: true}); |
| 20 | + |
| 21 | + newParent.moveBefore(target, null); |
| 22 | + |
| 23 | + // Wait for microtasks to settle. |
| 24 | + await new Promise(resolve => queueMicrotask(resolve)); |
| 25 | + |
| 26 | + assert_equals(observations.length, 1, "MutationObserver has emitted a single mutation list"); |
| 27 | + assert_equals(observations[0].length, 2, "Mutation list has two MutationRecords"); |
| 28 | + |
| 29 | + const removalRecord = observations[0][0]; |
| 30 | + const insertionRecord = observations[0][1]; |
| 31 | + assert_equals(removalRecord.target, oldParent, "removalRecord target is correct"); |
| 32 | + assert_equals(removalRecord.removedNodes[0], target, "removedNodes contains the moved node"); |
| 33 | + assert_equals(insertionRecord.target, newParent, "insertionRecord target is correct"); |
| 34 | + assert_equals(insertionRecord.addedNodes[0], target, "addedNodes contains the moved node"); |
| 35 | + observer.disconnect(); |
| 36 | +} |
| 37 | + |
| 38 | +promise_test(async t => { |
| 39 | + await runTest(oldParent, target, newParent); |
| 40 | +}, "[Connected move] MutationObserver removal + insertion is tracked by moveBefore()"); |
| 41 | + |
| 42 | +promise_test(async t => { |
| 43 | + const oldParent = document.createElement('div'); |
| 44 | + const target = document.createElement('p'); |
| 45 | + const newParent = document.createElement('div'); |
| 46 | + // We must append `newParent` as well, since the origin and destination nodes |
| 47 | + // must share the same shadow-including root. |
| 48 | + oldParent.append(target, newParent); |
| 49 | + |
| 50 | + await runTest(oldParent, target, newParent); |
| 51 | +}, "[Disconnected move] MutationObserver removal + insertion is tracked by moveBefore()"); |
| 52 | +</script> |
0 commit comments