summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/ranges/Range-collapse.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/dom/ranges/Range-collapse.html
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/dom/ranges/Range-collapse.html')
-rw-r--r--testing/web-platform/tests/dom/ranges/Range-collapse.html67
1 files changed, 67 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/ranges/Range-collapse.html b/testing/web-platform/tests/dom/ranges/Range-collapse.html
new file mode 100644
index 0000000000..141dbdf610
--- /dev/null
+++ b/testing/web-platform/tests/dom/ranges/Range-collapse.html
@@ -0,0 +1,67 @@
+<!doctype html>
+<title>Range.collapse() and .collapsed 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";
+
+function testCollapse(rangeEndpoints, toStart) {
+ // Have to account for Ranges involving Documents!
+ var ownerDoc = rangeEndpoints[0].nodeType == Node.DOCUMENT_NODE
+ ? rangeEndpoints[0]
+ : rangeEndpoints[0].ownerDocument;
+ var range = ownerDoc.createRange();
+ range.setStart(rangeEndpoints[0], rangeEndpoints[1]);
+ range.setEnd(rangeEndpoints[2], rangeEndpoints[3]);
+
+ var expectedContainer = toStart ? range.startContainer : range.endContainer;
+ var expectedOffset = toStart ? range.startOffset : range.endOffset;
+
+ assert_equals(range.collapsed, range.startContainer == range.endContainer
+ && range.startOffset == range.endOffset,
+ "collapsed must be true if and only if the start and end are equal");
+
+ if (toStart === undefined) {
+ range.collapse();
+ } else {
+ range.collapse(toStart);
+ }
+
+ assert_equals(range.startContainer, expectedContainer,
+ "Wrong startContainer");
+ assert_equals(range.endContainer, expectedContainer,
+ "Wrong endContainer");
+ assert_equals(range.startOffset, expectedOffset,
+ "Wrong startOffset");
+ assert_equals(range.endOffset, expectedOffset,
+ "Wrong endOffset");
+ assert_true(range.collapsed,
+ ".collapsed must be set after .collapsed()");
+}
+
+var tests = [];
+for (var i = 0; i < testRanges.length; i++) {
+ tests.push([
+ "Range " + i + " " + testRanges[i] + ", toStart true",
+ eval(testRanges[i]),
+ true
+ ]);
+ tests.push([
+ "Range " + i + " " + testRanges[i] + ", toStart false",
+ eval(testRanges[i]),
+ false
+ ]);
+ tests.push([
+ "Range " + i + " " + testRanges[i] + ", toStart omitted",
+ eval(testRanges[i]),
+ undefined
+ ]);
+}
+generate_tests(testCollapse, tests);
+
+testDiv.style.display = "none";
+</script>