haikuwebkit/LayoutTests/fast/dom/rangeContainsRange.html

90 lines
2.8 KiB
HTML
Raw Permalink Normal View History

Start removing functions that implicitly use composed tree https://bugs.webkit.org/show_bug.cgi?id=218424 Reviewed by Ryosuke Niwa. Source/WebCore: Tests: fast/dom/rangeContainsNode.html fast/dom/rangeContainsRange.html fast/dom/treeOrder.html Ryosuke pointed out that most clients should not be using the composed tree, so this is a step in work to make the use of the composed tree explicit. After that we can more easily find and correct call sites where use of the composed tree is incorrect. Likely that most or all cases of treeOrder<ComposedTree> can be changed to just treeOrder and contains<ComposedTree> to just contains; will do those in follow-ups. * Modules/highlight/Highlight.cpp: (WebCore::repaintRange): Simplified code to use boundary points, and changed to use treeOrder<ComposedTree>. * dom/AbstractRange.h: Export makeSimpleRange so it can be used in Internals. * dom/AbstractRange.idl: Export the class so it can be used in Internals. * dom/Node.cpp: (WebCore::parent<ShadowIncludingTree>): Added. (WebCore::treeOrderForTesting): Added. (WebCore::documentOrder): Deleted. * dom/Node.h: Updated for the above. * dom/RadioButtonGroups.cpp: (WebCore::RadioButtonGroup::members const): Use treeOrder<ComposedTree>. * dom/SimpleRange.cpp: (WebCore::contains): Removed a couple contains functions that implicitly use composed tree. (WebCore::containsForTesting): Added. * dom/SimpleRange.h: Updated for the above. Should also make contains<Tree> the default and remove the <Tree> at all call sites, but it's safer to do that in a separate patch after this is landed and builds on all platforms. * editing/Editing.cpp: (WebCore::isNodeVisiblyContainedWithin): Use contains<ComposedTree>. * page/DragController.cpp: (WebCore::DragController::draggableElement const): Ditto. * page/EventHandler.cpp: (WebCore::EventHandler::dispatchMouseEvent): Ditto. Note that this has a call to isDescendantOf right next to it, which does not use the composed tree. * page/Page.cpp: (WebCore::Page::findTextMatches): Use treeOrder<ComposedTree>. (WebCore::replaceRanges): Ditto. * page/mac/ServicesOverlayController.mm: (WebCore::ServicesOverlayController::findTelephoneNumberHighlightContainingSelectionHighlight): Use contains<ComposedTree>. * testing/Internals.cpp: (WebCore::string): Added. (WebCore::convertType): Added. (WebCore::Internals::treeOrder): Added. (WebCore::Internals::rangeContainsNode): Added. (WebCore::Internals::rangeContainsRange): Added. * testing/Internals.h: Updated for added functions above. * testing/Internals.idl: Ditto. These functions were tested in a TestWebKitAPI test, but we plan to move those types of tests to internals-based tests instead. Source/WebKit: * WebProcess/WebPage/glib/WebPageGLib.cpp: (WebKit::WebPage::getPlatformEditorState const): Use contains<ComposedTree>. Tools: * TestWebKitAPI/Tests/WebCore/DocumentOrder.cpp: Moved the tests of documentOrder for two nodes and contains for range/range or range/node into internals-based tests in the LayoutTests directory. Eventually we'll move the rest of these tests, too. LayoutTests: * fast/dom/rangeContainsNode-expected.txt: Added. * fast/dom/rangeContainsNode.html: Added. * fast/dom/rangeContainsRange-expected.txt: Added. * fast/dom/rangeContainsRange.html: Added. * fast/dom/treeOrder-expected.txt: Added. * fast/dom/treeOrder.html: Added. These tests were formerly part of TestWebKitAPI, although treeOrder was named documentOrder. Moving to internals-style tests at Ryosuke's suggestion since these are not something exposed as API or even SPI. Canonical link: https://commits.webkit.org/231111@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269253 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-02 18:53:36 +00:00
<html><head></head><body>
<script src="../../resources/js-test.js"></script>
<script>
description("Test the contains function that checks if a range contains another range.")
function range(startContainer, startOffset, endContainer, endOffset)
{
return new StaticRange({ startContainer: startContainer, startOffset: startOffset, endContainer: endContainer, endOffset: endOffset })
}
function collapsedRange(container, offset)
{
return range(container, offset, container, offset)
}
function contentsRange(node)
{
return range(node, 0, node, node.childNodes.length)
}
function shouldContainSelf(a)
{
shouldBeTrue("internals.rangeContainsRange(" + a + ", " + a + ", 'ComposedTree')")
}
function shouldBeNested(a, b)
{
shouldBeTrue("internals.rangeContainsRange(" + a + ", " + b + ", 'ComposedTree')")
shouldBeFalse("internals.rangeContainsRange(" + b + ", " + a + ", 'ComposedTree')")
}
function shouldNotContain(a, b)
{
shouldBeFalse("internals.rangeContainsRange(" + a + ", " + b + ", 'ComposedTree')")
shouldBeFalse("internals.rangeContainsRange(" + b + ", " + a + ", 'ComposedTree')")
}
let documentElement = document.documentElement;
let body = document.body;
shouldContainSelf("contentsRange(document)")
shouldContainSelf("contentsRange(documentElement)")
shouldContainSelf("contentsRange(body)")
shouldBeNested("contentsRange(document)", "contentsRange(documentElement)")
shouldBeNested("contentsRange(document)", "contentsRange(body)")
shouldBeNested("contentsRange(documentElement)", "contentsRange(body)")
shouldBeNested("contentsRange(document)", "contentsRange(documentElement)")
shouldBeNested("contentsRange(documentElement)", "contentsRange(body)")
shouldBeNested("contentsRange(document)", "collapsedRange(document, 0)")
shouldBeNested("contentsRange(document)", "collapsedRange(document, 1)")
shouldNotContain("contentsRange(document)", "collapsedRange(document, 2)")
shouldBeNested("range(document, 0, document, 2)", "contentsRange(document)")
shouldNotContain("contentsRange(document)", "range(document, 1, document, 2)")
shouldNotContain("range(document, 0, documentElement, 0)", "contentsRange(body)")
shouldBeNested("range(document, 0, body, 0)", "collapsedRange(body, 0)")
let a = document.createElement("div")
shouldNotContain("contentsRange(document)", "contentsRange(a)")
body.appendChild(a)
let b = document.createElement("div")
body.appendChild(b)
let c = document.createElement("div")
b.appendChild(c)
let d = document.createElement("div")
a.appendChild(d)
let e = document.createElement("div")
let f = document.createElement("div")
e.appendChild(f)
shouldNotContain("contentsRange(body)", "contentsRange(f)")
let g = document.createElement("textarea");
c.appendChild(g)
let h = internals.ensureUserAgentShadowRoot(g).firstChild
shouldBeNested("contentsRange(body)", "contentsRange(h)")
</script>
</body></html>