diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/dom/ranges/Range-intersectsNode.html | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/dom/ranges/Range-intersectsNode.html')
-rw-r--r-- | testing/web-platform/tests/dom/ranges/Range-intersectsNode.html | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/ranges/Range-intersectsNode.html b/testing/web-platform/tests/dom/ranges/Range-intersectsNode.html new file mode 100644 index 0000000000..97e10f6f0d --- /dev/null +++ b/testing/web-platform/tests/dom/ranges/Range-intersectsNode.html @@ -0,0 +1,70 @@ +<!doctype html> +<title>Range.intersectsNode() tests</title> +<link rel="author" title="Aryeh Gregor" href=ayg@aryeh.name> +<meta name=timeout content=long> +<div id=log></div> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../common.js></script> +<script> +"use strict"; + +// Will be filled in on the first run for that range +var testRangesCached = []; + +for (var i = 0; i < testNodes.length; i++) { + var node = eval(testNodes[i]); + + for (var j = 0; j < testRanges.length; j++) { + test(function() { + if (testRangesCached[j] === undefined) { + try { + testRangesCached[j] = rangeFromEndpoints(eval(testRanges[i])); + } catch(e) { + testRangesCached[j] = null; + } + } + assert_not_equals(testRangesCached[j], null, + "Setting up the range failed"); + + var range = testRangesCached[j].cloneRange(); + + // "If node's root is different from the context object's root, + // return false and terminate these steps." + if (furthestAncestor(node) !== furthestAncestor(range.startContainer)) { + assert_equals(range.intersectsNode(node), false, + "Must return false if node and range have different roots"); + return; + } + + // "Let parent be node's parent." + var parent_ = node.parentNode; + + // "If parent is null, return true and terminate these steps." + if (!parent_) { + assert_equals(range.intersectsNode(node), true, + "Must return true if node's parent is null"); + return; + } + + // "Let offset be node's index." + var offset = indexOf(node); + + // "If (parent, offset) is before end and (parent, offset + 1) is + // after start, return true and terminate these steps." + if (getPosition(parent_, offset, range.endContainer, range.endOffset) === "before" + && getPosition(parent_, offset + 1, range.startContainer, range.startOffset) === "after") { + assert_equals(range.intersectsNode(node), true, + "Must return true if (parent, offset) is before range end and (parent, offset + 1) is after range start"); + return; + } + + // "Return false." + assert_equals(range.intersectsNode(node), false, + "Must return false if (parent, offset) is not before range end or (parent, offset + 1) is not after range start"); + }, "Node " + i + " " + testNodes[i] + ", range " + j + " " + testRanges[j]); + } +} + +testDiv.style.display = "none"; +</script> |