summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-highlight-api/Highlight-iteration-with-modifications.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/css/css-highlight-api/Highlight-iteration-with-modifications.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/css/css-highlight-api/Highlight-iteration-with-modifications.html')
-rw-r--r--testing/web-platform/tests/css/css-highlight-api/Highlight-iteration-with-modifications.html91
1 files changed, 91 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-highlight-api/Highlight-iteration-with-modifications.html b/testing/web-platform/tests/css/css-highlight-api/Highlight-iteration-with-modifications.html
new file mode 100644
index 0000000000..b1f0fb10ee
--- /dev/null
+++ b/testing/web-platform/tests/css/css-highlight-api/Highlight-iteration-with-modifications.html
@@ -0,0 +1,91 @@
+<!doctype html>
+<title>Highlight iteration with insertions and deletions inbetween</title>
+<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id='testDiv'>abc</div>
+<script>
+ 'use strict';
+ let container = document.getElementById('testDiv');
+ let range1 = new StaticRange({startContainer: container, startOffset: 0, endContainer: container, endOffset: 1});
+ let range2 = new Range();
+
+ // Test insertions using .add
+ test(() => {
+ let customHighlight = new Highlight();
+ let iterator = customHighlight[Symbol.iterator]();
+ customHighlight.add(range1);
+ let element = iterator.next();
+ assert_true(element.done, 'The iteration ends although we added a new range after starting the iteration');
+ assert_equals(element.value, undefined, 'A range added after starting the iteration is not found during the current iteration');
+ }, 'Highlight iteration is not modified when a new range is added after starting the iteration');
+
+ test(() => {
+ let customHighlight = new Highlight(range1);
+ let iterator = customHighlight[Symbol.iterator]();
+ customHighlight.add(range2);
+ let element = iterator.next();
+ assert_false(element.done, 'The iteration doesn\'t end although there was a second range added to the Highlight after starting the iteration');
+ assert_equals(element.value, range1, 'The range that was pointed to by the iterator is returned although a second range was added after starting the iteration');
+ element = iterator.next();
+ assert_true(element.done, 'The iteration ends after going through all the ranges that were in the Highlight when the iteration started although there was a range addition after starting the iteration');
+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
+ }, 'Highlight iteration is not modified when a new range is added after starting the iteration with one range in the Highlight');
+
+ // Test deletions using .delete
+ test(() => {
+ let customHighlight = new Highlight(range1);
+ let iterator = customHighlight[Symbol.iterator]();
+ customHighlight.delete(range1);
+ let element = iterator.next();
+ assert_false(element.done, 'The iteration doesn\'t end although the range that was pointed to by the iterator was deleted');
+ assert_equals(element.value, range1, 'The range that was pointed to by the iterator is returned although it was deleted after starting the iteration');
+ element = iterator.next();
+ assert_true(element.done, 'The iteration ends after going through all the ranges although the range that was pointed to by the iterator was deleted after starting the iteration');
+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
+ }, 'Highlight iteration is not modified when the range that was pointed to by the iterator was deleted after starting the iteration');
+
+ test(() => {
+ let customHighlight = new Highlight(range1, range2);
+ let iterator = customHighlight[Symbol.iterator]();
+ customHighlight.delete(range2);
+ let element = iterator.next();
+ assert_false(element.done, 'The iteration doesn\'t end when the range following to the one that was pointed to by the iterator was deleted');
+ assert_equals(element.value, range1, 'The range that was pointed to by the iterator is returned as it should although the next range was deleted immediately after starting the iteration');
+ element = iterator.next();
+ assert_false(element.done, 'The iteration doesn\'t end when you call .next twice since the beginning of the iteration although the second range was deleted');
+ assert_equals(element.value, range2, 'The range that was pointed to by the iterator is returned as it should although the next range was deleted immediately after starting the iteration');
+ element = iterator.next();
+ assert_true(element.done, 'The iteration ends after going through all the ranges although the second range was deleted immediately after starting the iteration');
+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
+ }, 'Highlight iteration is not modified when the range that was immediately after the one pointed to by the iterator was deleted after starting the iteration');
+
+ test(() => {
+ let customHighlight = new Highlight(range1, range2);
+ let iterator = customHighlight[Symbol.iterator]();
+ let element = iterator.next();
+ assert_false(element.done, 'The iteration doesn\'t end when there are still two ranges to visit');
+ assert_equals(element.value, range1, 'The range that was pointed to by the iterator is returned as it should');
+ customHighlight.delete(range1);
+ element = iterator.next();
+ assert_false(element.done, 'The iteration doesn\'t end when the range previously visited is deleted and there is still a range to visit');
+ assert_equals(element.value, range2, 'The range that was pointed to by the iterator is returned as it should although the previous range was deleted after calling .next');
+ element = iterator.next();
+ assert_true(element.done, 'The iteration ends after going through all the ranges although the first range was deleted after the first call to .next');
+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
+ }, 'Highlight iteration is not modified when a range that was already visited is deleted and there are still ranges to visit');
+
+ // Test deletions using .clear
+ test(() => {
+ let customHighlight = new Highlight(range1);
+ let iterator = customHighlight[Symbol.iterator]();
+ customHighlight.clear();
+ let element = iterator.next();
+ assert_false(element.done, 'The iteration doesn\'t end although the range that was pointed to by the iterator was deleted using .clear()');
+ assert_equals(element.value, range1, 'The range that was pointed to by the iterator is returned although it was deleted using .clear() after starting the iteration');
+ element = iterator.next();
+ assert_true(element.done, 'The iteration ends after going through all the ranges although the range that was pointed to by the iterator was deleted using .clear() after starting the iteration');
+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
+ }, 'Highlight iteration is not modified when the range that was pointed to by the iterator was deleted using .clear() after starting the iteration');
+
+</script>