Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM: Add basic moveBefore() MutationObserver tests #49846

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions dom/nodes/moveBefore/tentative/mutation-observer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<title>slotchanged event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>

<div id=oldParent>
<p id=target></p>
</div>
<div id=newParent></div>

<script>
async function runTest(oldParent, target, newParent) {
const observations = [];
const observer = new MutationObserver(mutationList => observations.push(mutationList));

observer.observe(oldParent, {childList: true});
observer.observe(target, {childList: true});
observer.observe(newParent, {childList: true});

newParent.moveBefore(target, null);

// Wait for microtasks to settle.
await new Promise(resolve => queueMicrotask(resolve));

assert_equals(observations.length, 1, "MutationObserver has emitted a single mutation list");
assert_equals(observations[0].length, 2, "Mutation list has two MutationRecords");

const removalRecord = observations[0][0];
const insertionRecord = observations[0][1];
assert_equals(removalRecord.target, oldParent, "removalRecord target is correct");
assert_equals(removalRecord.removedNodes[0], target, "removedNodes contains the moved node");
assert_equals(insertionRecord.target, newParent, "insertionRecord target is correct");
assert_equals(insertionRecord.addedNodes[0], target, "addedNodes contains the moved node");
observer.disconnect();
}

promise_test(async t => {
await runTest(oldParent, target, newParent);
}, "[Connected move] MutationObserver removal + insertion is tracked by moveBefore()");

promise_test(async t => {
const oldParent = document.createElement('div');
const target = document.createElement('p');
const newParent = document.createElement('div');
// We must append `newParent` as well, since the origin and destination nodes
// must share the same shadow-including root.
oldParent.append(target, newParent);

await runTest(oldParent, target, newParent);
}, "[Disconnected move] MutationObserver removal + insertion is tracked by moveBefore()");
</script>