summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-highlight-api/Highlight-setlike.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/css/css-highlight-api/Highlight-setlike.html
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.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/css/css-highlight-api/Highlight-setlike.html')
-rw-r--r--testing/web-platform/tests/css/css-highlight-api/Highlight-setlike.html106
1 files changed, 106 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-highlight-api/Highlight-setlike.html b/testing/web-platform/tests/css/css-highlight-api/Highlight-setlike.html
new file mode 100644
index 0000000000..0093f9be23
--- /dev/null
+++ b/testing/web-platform/tests/css/css-highlight-api/Highlight-setlike.html
@@ -0,0 +1,106 @@
+<!doctype html>
+<title> Highlight has a setlike interface </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 priority = 123;
+
+ test(() => {
+ let customHighlight = new Highlight();
+ assert_equals(customHighlight.priority, 0, 'Highlight uses 0 as priority by default.');
+
+ customHighlight.priority = priority;
+ assert_equals(customHighlight.priority, priority, 'Highlight sets priority correctly.');
+
+ assert_equals(customHighlight.size, 0, 'Highlight starts empty');
+ }, 'Highlight initializes empty (if no ranges are provided) and with priority 0.');
+
+ let range0 = new Range();
+ let range1 = new Range();
+ let range2 = new Range();
+
+ let container = document.getElementById('testDiv');
+ let staticRange0 = new StaticRange({startContainer: container, startOffset: 0, endContainer: container, endOffset: 0});
+ let staticRange1 = new StaticRange({startContainer: container, startOffset: 0, endContainer: container, endOffset: 0});
+ let staticRange2 = new StaticRange({startContainer: container, startOffset: 0, endContainer: container, endOffset: 0});
+
+ let rangeCollections = [[range0,range1,range2], [staticRange0,staticRange1,staticRange2], [range0,staticRange1,range2], [staticRange0,range1,staticRange2]]
+
+ var i;
+ for(i=0; i<rangeCollections.length; i++){
+ let rangesCombinationDescription = " (using the following combination of ranges [";
+ var j;
+ for(j=0; j<rangeCollections[i].length; j++){
+ if(j!=0) rangesCombinationDescription += ", ";
+ rangesCombinationDescription = rangesCombinationDescription + Object.prototype.toString.call(rangeCollections[i][j]);
+ }
+ rangesCombinationDescription += "])";
+
+ test(() => {
+ let customHighlight = new Highlight();
+ assert_false(customHighlight.has(rangeCollections[i][0]), 'Highlight.has returns false when it doesn\'t contain the range which is passed as the argument');
+ assert_false(customHighlight.has(rangeCollections[i][1]), 'Highlight.has returns false when it doesn\'t contain the range which is passed as the argument');
+ assert_false(customHighlight.has(rangeCollections[i][2]), 'Highlight.has returns false when it doesn\'t contain the range which is passed as the argument');
+ customHighlight.add(rangeCollections[i][0]);
+ assert_true(customHighlight.has(rangeCollections[i][0]), 'Highlight.has returns true when it contains the range which is passed as the argument');
+ assert_false(customHighlight.has(rangeCollections[i][1]), 'Highlight.has returns false when it doesn\'t contain the range which is passed as the argument');
+ assert_false(customHighlight.has(rangeCollections[i][2]), 'Highlight.has returns false when it doesn\'t contain the range which is passed as the argument');
+
+ assert_equals(customHighlight.size, 1, 'Highlight.size is 1 after only adding 1 range');
+ customHighlight.add(rangeCollections[i][0]);
+ assert_equals(customHighlight.size, 1, 'Highlight.size is 1 after only adding same range twice');
+
+ customHighlight.add(rangeCollections[i][1]);
+ assert_true(customHighlight.has(rangeCollections[i][0]), 'Highlight.has returns true when it contains the range which is passed as the argument');
+ assert_true(customHighlight.has(rangeCollections[i][1]), 'Highlight.has returns true when it contains the range which is passed as the argument');
+ assert_false(customHighlight.has(rangeCollections[i][2]), 'Highlight.has returns false when it doesn\'t contain the range which is passed as the argument');
+
+ assert_equals(customHighlight.size, 2, 'Highlight.size is 2 after only adding two different ranges');
+ }, 'Highlight add and has methods work as expected' + rangesCombinationDescription);
+
+ test(() => {
+ let customHighlight = new Highlight(rangeCollections[i][0], rangeCollections[i][1]);
+ assert_false(customHighlight.delete(rangeCollections[i][2]), 'Highlight.delete returns false when trying to delete a range that is not in the highlight');
+ assert_true(customHighlight.delete(rangeCollections[i][1]), 'Highlight.delete returns true when trying to delete a range that is in the highlight');
+ assert_false(customHighlight.delete(rangeCollections[i][1]), 'Highlight.delete returns false when trying to delete a range that was in the highlight before but it\'s not there anymore');
+ assert_true(customHighlight.delete(rangeCollections[i][0]), 'Highlight.delete returns true when trying to delete a range that is in the highlight');
+ assert_false(customHighlight.delete(rangeCollections[i][0]), 'Highlight.delete returns false when trying to delete a range that was in the highlight before but it\'s not there anymore');
+ }, 'Highlight delete method works as expected' + rangesCombinationDescription);
+
+ test(() => {
+ let customHighlight = new Highlight(rangeCollections[i][0], rangeCollections[i][0]);
+ assert_true(customHighlight.has(rangeCollections[i][0]), 'Highlight.has returns true when it is called with the range used twice in the constructor');
+ assert_equals(customHighlight.size, 1, 'Highlight behaves like a set when constructing it with two equal ranges.');
+
+ customHighlight = new Highlight(rangeCollections[i][0], rangeCollections[i][1], rangeCollections[i][0], rangeCollections[i][1]);
+ assert_true(customHighlight.has(rangeCollections[i][0]), 'Highlight.has returns true when it is called with one of the ranges used twice in the constructor');
+ assert_true(customHighlight.has(rangeCollections[i][1]), 'Highlight.has returns true when it is called with the other range used twice in the constructor');
+ assert_equals(customHighlight.size, 2, 'Highlight behaves like a set when constructing it with two pairs of equal ranges.');
+ }, 'Highlight constructor behaves like a set when using equal ranges' + rangesCombinationDescription);
+
+ test(() => {
+ let customHighlight = new Highlight(rangeCollections[i][0]);
+ assert_true(customHighlight.has(rangeCollections[i][0]), 'Highlight.has returns true when it is called with the range used in its constructor');
+ assert_equals(customHighlight.size, 1, 'Highlight.size is 1 after constructing it with one range');
+ }, 'Highlight constructor works as expected when called with one range' + rangesCombinationDescription);
+
+ test(() => {
+ let customHighlight = new Highlight(rangeCollections[i][0], rangeCollections[i][1]);
+ assert_true(customHighlight.has(rangeCollections[i][0]), 'Highlight.has returns true when it is called with the first range used in its constructor');
+ assert_true(customHighlight.has(rangeCollections[i][1]), 'Highlight.has returns true when it is called with the second range used in its constructor');
+ assert_equals(customHighlight.size, 2, 'Highlight.size is 2 after constructing it with two ranges');
+ }, 'Highlight constructor works as expected when called with two ranges' + rangesCombinationDescription);
+
+ test(() => {
+ let customHighlight = new Highlight(rangeCollections[i][0], rangeCollections[i][1]);
+ assert_equals(customHighlight.size, 2, 'Highlight has size 2 after constructing it with two ranges');
+ customHighlight.clear();
+ assert_equals(customHighlight.size, 0, 'Highlight becomes empty after executing clear()');
+ customHighlight.clear();
+ assert_equals(customHighlight.size, 0, 'Highlight is still empty after executing clear() twice');
+ }, 'Highlight clear method works as expected' + rangesCombinationDescription);
+ }
+</script>