diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/mozilla/tests/selection | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/mozilla/tests/selection')
-rw-r--r-- | testing/web-platform/mozilla/tests/selection/Selection-addRange-same-instance.html | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/testing/web-platform/mozilla/tests/selection/Selection-addRange-same-instance.html b/testing/web-platform/mozilla/tests/selection/Selection-addRange-same-instance.html new file mode 100644 index 0000000000..c374b8ecdf --- /dev/null +++ b/testing/web-platform/mozilla/tests/selection/Selection-addRange-same-instance.html @@ -0,0 +1,56 @@ +<!doctype html> +<html> +<head> +<meta charset="utf-8"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +"use strict"; + +promise_test(async () => { + await new Promise(resolve => document.addEventListener("DOMContentLoaded", resolve)); + + getSelection().removeAllRanges(); + const range = document.createRange(); + range.setStart(document.querySelector("span"), 0); + getSelection().addRange(range); + getSelection().addRange(range); + assert_equals(getSelection().rangeCount, 1, "Adding same collapsed range twice should not clone the range"); + assert_equals(getSelection().getRangeAt(0), range, "The first range should be the added range"); + assert_equals(getSelection().focusNode, document.querySelector("span"), "Focus node should be the <span>"); + assert_equals(getSelection().focusOffset, 0, "Focus offset should be 0"); + assert_true(getSelection().isCollapsed, "Selection should be collapsed"); +}, "Adding same collapsed range should not change selections"); + +promise_test(async () => { + getSelection().removeAllRanges(); + const range = document.createRange(); + range.selectNodeContents(document.querySelector("div")); + getSelection().addRange(range); + getSelection().addRange(range); + assert_equals(getSelection().rangeCount, 1, "Adding same range twice should not clone the range"); + assert_equals(getSelection().getRangeAt(0), range, "The first range should be the added range"); + assert_equals(getSelection().anchorNode, document.querySelector("div"), "Anchor node should be the <div>"); + assert_equals(getSelection().anchorOffset, 0, "Anchor offset should be 0"); + assert_equals(getSelection().focusNode, document.querySelector("div"), "Focus node should be the <div>"); + assert_equals(getSelection().focusOffset, 1, "Focus offset should be 1"); +}, "Adding non-collapsed range after updating the range should not change selections"); + +promise_test(async () => { + getSelection().removeAllRanges(); + const range = document.createRange(); + range.collapse(document.querySelector("span"), 0); + getSelection().addRange(range); + range.selectNodeContents(document.querySelector("div")); + getSelection().addRange(range); + assert_equals(getSelection().rangeCount, 1, "Adding same range twice should not clone the range"); + assert_equals(getSelection().getRangeAt(0), range, "The first range should be the added range"); + assert_equals(getSelection().anchorNode, document.querySelector("div"), "Anchor node should be the <div>"); + assert_equals(getSelection().anchorOffset, 0, "Anchor offset should be 0"); + assert_equals(getSelection().focusNode, document.querySelector("div"), "Focus node should be the <div>"); + assert_equals(getSelection().focusOffset, 1, "Focus offset should be 1"); +}, "Adding same collapsed range after updating the range should not change selections"); +</script> +</head> +<body><div><span></span></div></body> +</html> |