Skip to content

Add tests for Range collapse ordering in deleteContents/extractContents#58008

Open
stevenobiajulu wants to merge 2 commits intoweb-platform-tests:masterfrom
stevenobiajulu:range-collapse-mutation-order-tests
Open

Add tests for Range collapse ordering in deleteContents/extractContents#58008
stevenobiajulu wants to merge 2 commits intoweb-platform-tests:masterfrom
stevenobiajulu:range-collapse-mutation-order-tests

Conversation

@stevenobiajulu
Copy link
Copy Markdown

@stevenobiajulu stevenobiajulu commented Feb 24, 2026

Summary

Add conformance tests for Range collapse position after deleteContents() and extractContents(), covering the spec fix in whatwg/dom#1446.

New test files:

  • dom/ranges/Range-deleteContents-mutation-order.html — 4 tests
  • dom/ranges/Range-extractContents-mutation-order.html — 4 tests

Test scenarios

  • Element children fully contained (start is inclusive ancestor of end)
  • Mixed ancestry with multiple contained nodes (start is not ancestor of end)
  • CharacterData boundary nodes with partial text deletion
  • Same CharacterData node (early return path)

Related

Verify that Range.deleteContents() and Range.extractContents() collapse
the range to the correct position after the operation completes. Tests
cover:
- Element children fully contained (Case 1: start is ancestor of end)
- Mixed ancestry with multiple contained nodes (Case 2)
- CharacterData boundary nodes with partial text deletion
- Same CharacterData node (early return path)

These tests serve as conformance/non-regression tests for the spec fix
that moves range collapse before mutations (whatwg/dom#1446).
Copy link
Copy Markdown
Contributor

@smaug---- smaug---- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do these tests test possible mutation? Like having iframe and the page in it having pagehide and that listener trying to modify DOM

…tents

Address smaug's review: the existing tests only verified final collapse
position without exercising synchronous script during removal. Add a test
to each file that uses a custom element whose disconnectedCallback removes
an earlier sibling mid-operation, verifying the range adjusts correctly.

Tested in Chrome, Firefox, and Safari — all pass (startOffset = 0).
Copy link
Copy Markdown
Author

@stevenobiajulu stevenobiajulu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — the existing tests only check the final collapse position without exercising script during removal. I've pushed a test for each API that uses a custom element whose disconnectedCallback removes an earlier sibling mid-operation and verifies the range adjusts correctly (startOffset = 0). Passes in Chrome, Firefox, and Safari.

AtkinsSJ added a commit to AtkinsSJ/ladybird that referenced this pull request Apr 16, 2026
The spec text has also changed since we implemented it, but moving when
we collapse the range is the only actual behaviour change.

Corresponds to:
whatwg/dom@9363c6d

Also imported a couple of tests for it, from this WPT PR which isn't yet
merged: web-platform-tests/wpt#58008
@AtkinsSJ
Copy link
Copy Markdown

I just tested these in Ladybird, and they pass with or without the changes to Range in whatwg/dom#1452 . (PR is LadybirdBrowser/ladybird#8944 for reference.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants