diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/shadow-dom/selection-collapse-and-extend.tentative.html | |
parent | Initial commit. (diff) | |
download | firefox-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/shadow-dom/selection-collapse-and-extend.tentative.html')
-rw-r--r-- | testing/web-platform/tests/shadow-dom/selection-collapse-and-extend.tentative.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shadow-dom/selection-collapse-and-extend.tentative.html b/testing/web-platform/tests/shadow-dom/selection-collapse-and-extend.tentative.html new file mode 100644 index 0000000000..36cc036b38 --- /dev/null +++ b/testing/web-platform/tests/shadow-dom/selection-collapse-and-extend.tentative.html @@ -0,0 +1,82 @@ +<!DOCTYPE html> +<html> +<body> +<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> +<meta name="assert" content="Selection's collapse and extend should abort only when the node's root is not connected"> +<link rel="help" href="https://w3c.github.io/selection-api/#dom-selection-collapse"> +<link rel="help" href="https://w3c.github.io/selection-api/#dom-selection-extend"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="container"></div> +<script> + +test(() => { + const host = document.createElement('div'); + container.appendChild(host); + const shadowRoot = host.attachShadow({mode: 'closed'}); + shadowRoot.innerHTML = '<div contenteditable><p>hello, world</p></div>'; + const textNode = shadowRoot.querySelector('p').firstChild; + getSelection().removeAllRanges(); + getSelection().collapse(textNode, 5); + const ranges = getSelection().getComposedRanges(shadowRoot); + assert_equals(ranges.length, 1); + assert_equals(ranges[0].startContainer, textNode); + assert_equals(ranges[0].startOffset, 5); + assert_equals(ranges[0].endContainer, textNode); + assert_equals(ranges[0].endOffset, 5); + assert_true(ranges[0].collapsed); +}, 'collapse can set selection to a node inside a shadow tree'); + +test(() => { + const host = document.createElement('div'); + const shadowRoot = host.attachShadow({mode: 'closed'}); + shadowRoot.innerHTML = '<div contenteditable><p>hello, world</p></div>'; + const textNode = shadowRoot.querySelector('p').firstChild; + getSelection().removeAllRanges(); + getSelection().collapse(textNode, 5); + const ranges = getSelection().getComposedRanges(shadowRoot); + assert_equals(ranges.length, 0); +}, 'collapse abort steps when called with a disconnected node inside a shadow tree'); + +test(() => { + const host = document.createElement('div'); + container.appendChild(host); + const shadowRoot = host.attachShadow({mode: 'closed'}); + shadowRoot.innerHTML = '<div contenteditable><p>hello, world</p></div>'; + const textNode = shadowRoot.querySelector('p').firstChild; + getSelection().removeAllRanges(); + getSelection().collapse(textNode, 5); + let ranges = getSelection().getComposedRanges(shadowRoot); + assert_equals(ranges.length, 1); + getSelection().extend(textNode, 11); + ranges = getSelection().getComposedRanges(shadowRoot); + assert_equals(ranges.length, 1); + assert_equals(ranges[0].startContainer, textNode); + assert_equals(ranges[0].startOffset, 5); + assert_equals(ranges[0].endContainer, textNode); + assert_equals(ranges[0].endOffset, 11); + assert_false(ranges[0].collapsed); +}, 'extend can set selection to a node inside a shadow tree'); + +test(() => { + const host = document.createElement('div'); + const shadowRoot = host.attachShadow({mode: 'closed'}); + shadowRoot.innerHTML = '<div contenteditable><p>hello, world</p></div>'; + const textNode = shadowRoot.querySelector('p').firstChild; + getSelection().removeAllRanges(); + getSelection().collapse(container, 0); + getSelection().extend(textNode, 5); + const ranges = getSelection().getComposedRanges(shadowRoot); + assert_equals(ranges.length, 1); + assert_equals(ranges[0].startContainer, container); + assert_equals(ranges[0].startOffset, 0); + assert_equals(ranges[0].endContainer, container); + assert_equals(ranges[0].endOffset, 0); + assert_true(ranges[0].collapsed); +}, 'extend abort steps when called with a disconnected node inside a shadow tree'); + +container.remove(); + +</script> +</body> +</html>
\ No newline at end of file |