Truly independent web browser
Tests/LibWeb: Import CSS Custom Highlight API WPT tests
Andreas Kling7f9713563632
diff --git a/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/Highlight-invalid-static-range-crash.html b/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/Highlight-invalid-static-range-crash.htmlnew file mode 100644index 00000000000..63c08fe2854--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/Highlight-invalid-static-range-crash.html@@ -0,0 +1,23 @@+<!DOCTYPE html>++<body onload="boom()">+ <p id="A"></p>+ <p id="B"></p>+</body>++<script>+function boom() {+ let highlight0 = new Highlight();++ let range = new StaticRange({+ endContainer: document.getElementById("A"),+ startOffset: 1,+ startContainer: document.getElementById("B"),+ endOffset: 1,+ });+ CSS.highlights.set("highlight0", highlight0);++ document.getElementById("A").remove();+ highlight0.add(range);+}+</script>diff --git a/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-first-letter-float-crash.html b/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-first-letter-float-crash.htmlnew file mode 100644index 00000000000..ea374295496--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-first-letter-float-crash.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<html contenteditable>+<style>+div::first-letter {+ float: right;+}+::highlight(test) { background-color: purple; }+</style>+<div><span id="span1">a<span>bc</span></span></div>+<script>+const span1 = document.getElementById("span1");+const text_node = span1.firstChild;+const range = document.createRange();+range.setStart(text_node, 0);+range.setEnd(text_node, 1);+const highlight = new Highlight(range);+CSS.highlights.set("test", highlight);+</script>diff --git a/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-image-multiple-crash.html b/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-image-multiple-crash.htmlnew file mode 100644index 00000000000..395804ace88--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-image-multiple-crash.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<style>+::highlight(h1) { background-color: rgba(255,0,0,.5); }+::highlight(h2) { background-color: rgba(0,0,255,.5); }+</style>+<div id="t"><img src="../../../images/blank-highlight.png"></div>+<script>+const range = new StaticRange({startContainer: t, startOffset: 0, endContainer: t, endOffset: 1});+CSS.highlights.set("h1", new Highlight(range));+CSS.highlights.set("h2", new Highlight(range));+</script>diff --git a/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-overlap-with-aria-invalid-crash.html b/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-overlap-with-aria-invalid-crash.htmlnew file mode 100644index 00000000000..a85c5cc02d7--- /dev/null+++ b/Tests/LibWeb/Crash/wpt-import/css/css-highlight-api/crashtests/highlight-overlap-with-aria-invalid-crash.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<style>+ ::highlight(test) { background-color: yellow; }+</style>+<div aria-invalid="grammar" id="div1">This are a dog</div>+<script>+ const div1 = document.getElementById("div1");+ const text_node = div1.firstChild;+ const range = document.createRange();+ range.setStart(div1, 0);+ range.setEnd(div1, 1);+ const highlight = new Highlight(range);+ CSS.highlights.set("test", highlight);+</script>\ No newline at end of filediff --git a/Tests/LibWeb/Crash/wpt-import/images/blank-highlight.png b/Tests/LibWeb/Crash/wpt-import/images/blank-highlight.pngnew file mode 100644index 00000000000..6dbee091749Binary files /dev/null and b/Tests/LibWeb/Crash/wpt-import/images/blank-highlight.png differdiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.txtnew file mode 100644index 00000000000..c8fb3019255--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.txt@@ -0,0 +1,11 @@+Harness status: OK++Found 6 tests++6 Fail+Fail Highlight iteration includes ranges added after starting the iteration (Set-like behavior)+Fail Highlight iteration includes ranges added after starting the iteration when there were already ranges (Set-like behavior)+Fail Highlight iteration skips ranges deleted before being visited (Set-like behavior)+Fail Highlight iteration skips ranges deleted before being visited even when other ranges remain (Set-like behavior)+Fail Highlight iteration is not modified when a range that was already visited is deleted and there are still ranges to visit+Fail Highlight iteration skips all ranges when .clear() is called before visiting them (Set-like behavior)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration.txtnew file mode 100644index 00000000000..6bc0845be58--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration.txt@@ -0,0 +1,30 @@+Harness status: OK++Found 25 tests++25 Fail+Fail Highlight can be iterated when it's empty initializing the iterator with customHighlight[Symbol.iterator]()+Fail Highlight can be iterated when it's empty initializing the iterator with customHighlight.values()+Fail Highlight can be iterated when it's empty initializing the iterator with customHighlight.keys()+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding a range by passing it to the constructor+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding two ranges by passing them to the constructor+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding a range by passing it to the constructor+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding two ranges by passing them to the constructor+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding a range by passing it to the constructor+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding two ranges by passing them to the constructor+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding a range by passing it to the add function+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding two ranges by passing them to the add function+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding a range by passing it to the add function+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding two ranges by passing them to the add function+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding a range by passing it to the add function+Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding two ranges by passing them to the add function+Fail Highlight can be iterated when it's empty initializing the iterator with .entries()+Fail Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding a range by passing it to the constructor+Fail Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding two ranges by passing them to the constructor+Fail Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding a range by passing it to the add function+Fail Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding two ranges by passing them to the add function+Fail Highlight can be iterated through when it's empty using forEach.+Fail Highlight can be iterated through using forEach when it has one range that was added by passing it to the constructor+Fail Highlight can be iterated through using forEach when it has two ranges that were added by passing them to the constructor+Fail Highlight can be iterated through using forEach when it has one range that was added by passing it to the add function+Fail Highlight can be iterated through using forEach when it has two ranges that were added by passing them to the add function\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.txtnew file mode 100644index 00000000000..22618176b2a--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail Highlight type has a limited set of types\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.txtnew file mode 100644index 00000000000..c777dcc5092--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail Highlight is a setlike interface that works as expected even if Set.prototype is tampered.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike.txtnew file mode 100644index 00000000000..a111d661bf9--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike.txt@@ -0,0 +1,34 @@+Harness status: OK++Found 29 tests++29 Fail+Fail Highlight initializes empty (if no ranges are provided) and with priority 0.+Fail Highlight add and has methods work as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])+Fail Highlight add method is chainable (using the following combination of ranges [[object Range], [object Range], [object Range]])+Fail Highlight delete method works as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])+Fail Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object Range], [object Range], [object Range]])+Fail Highlight constructor works as expected when called with one range (using the following combination of ranges [[object Range], [object Range], [object Range]])+Fail Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object Range], [object Range], [object Range]])+Fail Highlight clear method works as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])+Fail Highlight add and has methods work as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])+Fail Highlight add method is chainable (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])+Fail Highlight delete method works as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])+Fail Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])+Fail Highlight constructor works as expected when called with one range (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])+Fail Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])+Fail Highlight clear method works as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])+Fail Highlight add and has methods work as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])+Fail Highlight add method is chainable (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])+Fail Highlight delete method works as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])+Fail Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])+Fail Highlight constructor works as expected when called with one range (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])+Fail Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])+Fail Highlight clear method works as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])+Fail Highlight add and has methods work as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])+Fail Highlight add method is chainable (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])+Fail Highlight delete method works as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])+Fail Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])+Fail Highlight constructor works as expected when called with one range (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])+Fail Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])+Fail Highlight clear method works as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.txtnew file mode 100644index 00000000000..3a1f804d49b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail CSS.highlights.highlightsFromPoint() returns HighlightHitResults with the Highlights and their corresponding Ranges and StaticRanges present at the given point in the right order on multi-line text.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.txtnew file mode 100644index 00000000000..fa4b6a08990--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 8 tests++1 Pass+7 Fail+Pass CSS.highlights.highlightsFromPoint() should throw when called with incorrect parameters.+Fail CSS.highlights.highlightsFromPoint() should return an empty array when called with a point outside the document.+Fail CSS.highlights.highlightsFromPoint() returns the Highlights with their corresponding ranges present at the given point in the right order.+Fail CSS.highlights.highlightsFromPoint() returns empty array when called on a display:none iframe document.+Fail CSS.highlights.highlightsFromPoint() returns empty array for coordinates outside the viewport.+Fail CSS.highlights.highlightsFromPoint() does not return highlights with only collapsed ranges.+Fail CSS.highlights.highlightsFromPoint() skips invalid StaticRanges.+Fail CSS.highlights.highlightsFromPoint() returns all overlapping ranges within the same highlight.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.txtnew file mode 100644index 00000000000..6055c864758--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.txt@@ -0,0 +1,3 @@+Harness status: Error++Found 0 testsdiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.txtnew file mode 100644index 00000000000..6055c864758--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.txt@@ -0,0 +1,3 @@+Harness status: Error++Found 0 testsdiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.txtnew file mode 100644index 00000000000..11f8b2e2f2e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail HighlightRegistry is a maplike interface that works as expected even if Map.prototype is tampered.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.txtnew file mode 100644index 00000000000..df03b953805--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.txt@@ -0,0 +1,8 @@+Harness status: OK++Found 3 tests++3 Fail+Fail HighlightRegistry initializes as it should.+Fail HighlightRegistry has a maplike interface.+Fail HighlightRegistry.set() with an existing name preserves the insertion order (Map-like behavior)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-priority.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-priority.txtnew file mode 100644index 00000000000..fa6495ae3ab--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-priority.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail Highlight priority attribute is mutable\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-computed.txtnew file mode 100644index 00000000000..512bd0fdbb7--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-computed.txt@@ -0,0 +1,18 @@+Harness status: OK++Found 12 tests++10 Pass+2 Fail+Fail getComputedStyle() for ::highlight(foo)+Fail Different getComputedStyle() for ::highlight(bar) and same element+Pass getComputedStyle() for ::highlight(foo): should not return a style.+Pass getComputedStyle() for ::highlight(foo)) should not return a style.+Pass getComputedStyle() for ::highlight(foo)( should not return a style.+Pass getComputedStyle() for ::highlight should not return a style.+Pass getComputedStyle() for ::highlight(foo)(foo) should not return a style.+Pass getComputedStyle() for ::highlight(foo)() should not return a style.+Pass getComputedStyle() for :::highlight(foo) should not return a style.+Pass getComputedStyle() for ::highlight(foo). should not return a style.+Pass getComputedStyle() for ::highlight(foo,bar) should not return a style.+Pass getComputedStyle() for ::highlight(foo bar) should not return a style.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.txtnew file mode 100644index 00000000000..6055c864758--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.txt@@ -0,0 +1,3 @@+Harness status: Error++Found 0 testsdiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.txtnew file mode 100644index 00000000000..4ca2a0dedcd--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.txt@@ -0,0 +1,22 @@+Harness status: OK++Found 16 tests++7 Pass+9 Fail+Fail "::highlight(foo)" should be a valid selector+Fail ".a::highlight(foo)" should be a valid selector+Fail "div ::highlight(foo)" should be a valid selector+Fail "::part(my-part)::highlight(foo)" should be a valid selector+Fail "::highlight(multi\\ word)" should be a valid selector+Fail "::highlight(\\31\\32\\33)" should be a valid selector+Fail "::highlight(\\*)" should be a valid selector+Fail "div::highlight(\\*)" should be a valid selector+Fail ":root::highlight(\\*)" should be a valid selector+Pass "::highlight" should be an invalid selector+Pass "::before::highlight(foo)" should be an invalid selector+Pass "::highlight(foo).a" should be an invalid selector+Pass "::highlight(foo) div" should be an invalid selector+Pass "::highlight(foo)::after" should be an invalid selector+Pass "::highlight(foo):hover" should be an invalid selector+Pass ":not(::highlight(foo))" should be an invalid selector\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/historical.window.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/historical.window.txtnew file mode 100644index 00000000000..f297c186007--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/historical.window.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass HighlightRegister was renamed\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/idlharness.window.txtnew file mode 100644index 00000000000..c9e0f148032--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/idlharness.window.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail idl_test setup\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/highlight-pseudos.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/highlight-pseudos.txtnew file mode 100644index 00000000000..007c01f57d8--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/highlight-pseudos.txt@@ -0,0 +1,46 @@+Harness status: OK++Found 40 tests++28 Pass+12 Fail+Pass "::selection" should be a valid selector+Pass ".a::selection" should be a valid selector+Pass "div ::selection" should be a valid selector+Pass "::part(my-part)::selection" should be a valid selector+Pass "::before::selection" should be an invalid selector+Fail "::selection.a" should be an invalid selector+Pass "::selection div" should be an invalid selector+Pass "::selection::after" should be an invalid selector+Fail "::selection:hover" should be an invalid selector+Pass ":not(::selection)" should be an invalid selector+Fail "::target-text" should be a valid selector+Fail ".a::target-text" should be a valid selector+Fail "div ::target-text" should be a valid selector+Fail "::part(my-part)::target-text" should be a valid selector+Pass "::before::target-text" should be an invalid selector+Pass "::target-text.a" should be an invalid selector+Pass "::target-text div" should be an invalid selector+Pass "::target-text::after" should be an invalid selector+Pass "::target-text:hover" should be an invalid selector+Pass ":not(::target-text)" should be an invalid selector+Pass "::spelling-error" should be a valid selector+Pass ".a::spelling-error" should be a valid selector+Pass "div ::spelling-error" should be a valid selector+Pass "::part(my-part)::spelling-error" should be a valid selector+Pass "::before::spelling-error" should be an invalid selector+Fail "::spelling-error.a" should be an invalid selector+Pass "::spelling-error div" should be an invalid selector+Pass "::spelling-error::after" should be an invalid selector+Fail "::spelling-error:hover" should be an invalid selector+Pass ":not(::spelling-error)" should be an invalid selector+Fail "::grammar-error" should be a valid selector+Fail ".a::grammar-error" should be a valid selector+Fail "div ::grammar-error" should be a valid selector+Fail "::part(my-part)::grammar-error" should be a valid selector+Pass "::before::grammar-error" should be an invalid selector+Pass "::grammar-error.a" should be an invalid selector+Pass "::grammar-error div" should be an invalid selector+Pass "::grammar-error::after" should be an invalid selector+Pass "::grammar-error:hover" should be an invalid selector+Pass ":not(::grammar-error)" should be an invalid selector\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.htmlnew file mode 100644index 00000000000..222de39ece7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.html@@ -0,0 +1,88 @@+<!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_false(element.done, 'The iteration continues when a new range is added after starting the iteration');+ assert_equals(element.value, range1, 'A range added after starting the iteration is found during the current iteration, following Set semantics');+ element = iterator.next();+ assert_true(element.done, 'The iteration ends after visiting the added range');+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');+ }, 'Highlight iteration includes ranges added after starting the iteration (Set-like behavior)');++ test(() => {+ let customHighlight = new Highlight(range1);+ let iterator = customHighlight[Symbol.iterator]();+ customHighlight.add(range2);+ let element = iterator.next();+ assert_false(element.done, 'The iteration continues with the first range');+ assert_equals(element.value, range1, 'The first range is returned');+ element = iterator.next();+ assert_false(element.done, 'The iteration continues to the range added after starting the iteration, following Set semantics');+ assert_equals(element.value, range2, 'The range added after starting the iteration is visited');+ element = iterator.next();+ assert_true(element.done, 'The iteration ends after visiting both ranges');+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');+ }, 'Highlight iteration includes ranges added after starting the iteration when there were already ranges (Set-like behavior)');++ // Test deletions using .delete+ test(() => {+ let customHighlight = new Highlight(range1);+ let iterator = customHighlight[Symbol.iterator]();+ customHighlight.delete(range1);+ let element = iterator.next();+ assert_true(element.done, 'The iteration ends when the only range is deleted before visiting it, following Set semantics');+ assert_equals(element.value, undefined, 'A range deleted before being visited is not returned during iteration');+ }, 'Highlight iteration skips ranges deleted before being visited (Set-like behavior)');++ 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 continues with the first range');+ assert_equals(element.value, range1, 'The first range is returned');+ element = iterator.next();+ assert_true(element.done, 'The iteration ends after the first range since the second range was deleted before being visited, following Set semantics');+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');+ }, 'Highlight iteration skips ranges deleted before being visited even when other ranges remain (Set-like behavior)');++ 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_true(element.done, 'The iteration ends when all ranges are cleared before visiting them, following Set semantics');+ assert_equals(element.value, undefined, '.clear() removes all ranges before iteration visits them');+ }, 'Highlight iteration skips all ranges when .clear() is called before visiting them (Set-like behavior)');++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-iteration.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-iteration.htmlnew file mode 100644index 00000000000..67897a3774b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-iteration.html@@ -0,0 +1,201 @@+<!doctype html>+<title>Highlight iteration</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 range1 = new Range();+ let container = document.getElementById('testDiv');+ let range2 = new StaticRange({startContainer: container, startOffset: 0, endContainer: container, endOffset: 0});++ let rangeAdditionModeCollection = ["constructor", "add function"];+ let iterationInitializationCollection = ["customHighlight[Symbol.iterator]()", "customHighlight.values()", "customHighlight.keys()"];++ function getIterator(customHighlight, iterationInitialization){+ var iterator;+ if(iterationInitialization === "customHighlight[Symbol.iterator]()"){+ iterator = customHighlight[Symbol.iterator]();+ }+ else if(iterationInitialization === "customHighlight.values()"){+ iterator = customHighlight.values();+ }+ else if(iterationInitialization === "customHighlight.keys()"){+ iterator = customHighlight.keys();+ }+ return iterator;+ }++ // Test .keys, .values, [Symbol.iterator]++ for(let iterationInitialization of iterationInitializationCollection){+ test(() => {+ let customHighlight = new Highlight();+ let iterator = getIterator(customHighlight, iterationInitialization);+ let element = iterator.next();+ assert_true(element.done, 'Highlight is iterable and .next() returns an element with .done===true when there are no more ranges to iterate');+ assert_equals(element.value, undefined, 'Highlight is iterable and .next() returns an element with .value undefined when there are no more ranges to iterate.');+ }, 'Highlight can be iterated when it\'s empty initializing the iterator with ' + iterationInitialization);+ }++ for(let rangeAdditionMode of rangeAdditionModeCollection){+ for(let iterationInitialization of iterationInitializationCollection){+ test(() => {+ var customHighlight;+ if(rangeAdditionMode === "constructor"){+ customHighlight = new Highlight(range1);+ }+ else if(rangeAdditionMode === "add function"){+ customHighlight = new Highlight();+ customHighlight.add(range1);+ }++ let iterator = getIterator(customHighlight, iterationInitialization);+ let element = iterator.next();+ assert_false(element.done, 'Highlight is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last range');+ assert_equals(element.value, range1, '.next() returns an element with .value corresponding to the first range added to the Highlight');+ element = iterator.next();+ assert_true(element.done, 'Highlight is iterable and .next() returns an element with .done===true when there are no more ranges to iterate');+ assert_equals(element.value, undefined, 'Highlight is iterable and .next() returns an element with .value undefined when there are no more ranges to iterate.');+ }, 'Highlight can be iterated over all of its ranges initializing the iterator with ' + iterationInitialization + ' and adding a range by passing it to the ' + rangeAdditionMode);++ test(() => {+ var customHighlight;+ if(rangeAdditionMode === "constructor"){+ customHighlight = new Highlight(range1, range2);+ }+ else if(rangeAdditionMode === "add function"){+ customHighlight = new Highlight();+ customHighlight.add(range1);+ customHighlight.add(range2);+ }++ let iterator = getIterator(customHighlight, iterationInitialization);+ let element = iterator.next();+ assert_false(element.done, 'Highlight is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last range');+ assert_equals(element.value, range1, '.next() returns an element with .value corresponding to the first range added to the Highlight');+ element = iterator.next();+ assert_false(element.done, 'Highlight is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last range');+ assert_equals(element.value, range2, '.next() returns an element with .value corresponding to the second range added to the Highlight');+ element = iterator.next();+ assert_true(element.done, 'Highlight is iterable and .next() returns an element with .done===true when there are no more ranges to iterate');+ assert_equals(element.value, undefined, 'Highlight is iterable and .next() returns an element with .value undefined when there are no more ranges to iterate.');+ }, 'Highlight can be iterated over all of its ranges initializing the iterator with ' + iterationInitialization + ' and adding two ranges by passing them to the ' + rangeAdditionMode);+ }+ }++ // Test .entries()++ test(() => {+ let customHighlight = new Highlight();+ let iterator = customHighlight.entries();+ let element = iterator.next();+ assert_true(element.done, 'Highlight is iterable and .next() returns an element with .done===true when there are no more ranges to iterate');+ assert_equals(element.value, undefined, 'Highlight is iterable and .next() returns an element with .value undefined when there are no more ranges to iterate.');+ }, 'Highlight can be iterated when it\'s empty initializing the iterator with .entries()');++ for(let rangeAdditionMode of rangeAdditionModeCollection){+ test(() => {+ var customHighlight;+ if(rangeAdditionMode === "constructor"){+ customHighlight = new Highlight(range1);+ }+ else if(rangeAdditionMode === "add function"){+ customHighlight = new Highlight();+ customHighlight.add(range1);+ }++ let iterator = customHighlight.entries();+ let element = iterator.next();+ assert_false(element.done, 'Highlight is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last range');+ assert_equals(element.value[0], range1, '.next() returns an element with .value[0] corresponding to the first range added to the Highlight');+ assert_equals(element.value[1], range1, '.next() returns an element with .value[1] corresponding to the first range added to the Highlight');+ element = iterator.next();+ assert_true(element.done, 'Highlight is iterable and .next() returns an element with .done===true when there are no more ranges to iterate');+ assert_equals(element.value, undefined, 'Highlight is iterable and .next() returns an element with .value undefined when there are no more ranges to iterate.');+ }, 'Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding a range by passing it to the ' + rangeAdditionMode);++ test(() => {+ var customHighlight;+ if(rangeAdditionMode === "constructor"){+ customHighlight = new Highlight(range1, range2);+ }+ else if(rangeAdditionMode === "add function"){+ customHighlight = new Highlight();+ customHighlight.add(range1);+ customHighlight.add(range2);+ }++ let iterator = customHighlight.entries();+ let element = iterator.next();+ assert_false(element.done, 'Highlight is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value[0], range1, '.next() returns an element with .value[0] corresponding to the first range added to the Highlight');+ assert_equals(element.value[1], range1, '.next() returns an element with .value[1] corresponding to the first range added to the Highlight');+ element = iterator.next();+ assert_false(element.done, 'Highlight is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value[0], range2, '.next() returns an element with .value[0] corresponding to the second range added to the Highlight');+ assert_equals(element.value[1], range2, '.next() returns an element with .value[1] corresponding to the second range added to the Highlight');+ element = iterator.next();+ assert_true(element.done, 'Highlight is iterable and .next() returns an element with .done===true when there are no more ranges to iterate');+ assert_equals(element.value, undefined, 'Highlight is iterable and .next() returns an element with .value undefined when there are no more ranges to iterate.');+ }, 'Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding two ranges by passing them to the ' + rangeAdditionMode);+ }++ // Test .forEach++ function compareArrays(array1, array2){+ if(array1.length != array2.length){+ return false;+ }+ for(let index=0; index<array1.length; ++index){+ if(array1[index] != array2[index])+ return false;+ }+ return true;+ }++ test(() => {+ let customHighlight = new Highlight();+ let expectedResult = [];+ let actualResult = [];+ customHighlight.forEach((range) => {actualResult.push(range);});+ assert_true(compareArrays(actualResult, expectedResult), 'The ranges seen match the ranges added');+ }, 'Highlight can be iterated through when it\'s empty using forEach.');++ for(let rangeAdditionMode of rangeAdditionModeCollection){+ test(() => {+ var customHighlight;+ if(rangeAdditionMode === "constructor"){+ customHighlight = new Highlight(range1);+ }+ else if(rangeAdditionMode === "add function"){+ customHighlight = new Highlight();+ customHighlight.add(range1);+ }++ let expectedResult = [range1];+ let actualResult = [];+ customHighlight.forEach((range) => {actualResult.push(range);});+ assert_true(compareArrays(actualResult, expectedResult), 'The ranges seen match the ranges added');+ }, 'Highlight can be iterated through using forEach when it has one range that was added by passing it to the ' + rangeAdditionMode);++ test(() => {+ var customHighlight;+ if(rangeAdditionMode === "constructor"){+ customHighlight = new Highlight(range1, range2);+ }+ else if(rangeAdditionMode === "add function"){+ customHighlight = new Highlight();+ customHighlight.add(range1);+ customHighlight.add(range2);+ }++ let expectedResult = [range1, range2];+ let actualResult = [];+ customHighlight.forEach((range) => {actualResult.push(range);});+ assert_true(compareArrays(actualResult, expectedResult), 'The ranges seen match the ranges added');+ }, 'Highlight can be iterated through using forEach when it has two ranges that were added by passing them to the ' + rangeAdditionMode);+ }++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.htmlnew file mode 100644index 00000000000..c4cf3195456--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.html@@ -0,0 +1,47 @@+<!DOCTYPE html>+<html>+<head>+ <title>Highlight type has a limited set of types</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>+ <style>+ #one::highlight(yellow-highlight) {+ background-color: yellow;+ }+ #two::highlight(green-highlight) {+ background-color: green;+ }+ </style>+</head>+<body>+ <span id="one">One </span><span id="two">two </span>+ <script>+ test(() => {+ let highlightYellow = new Highlight(new StaticRange({startContainer: document.body, startOffset: 1, endContainer: document.body, endOffset: 2}));+ let highlightGreen = new Highlight(new StaticRange({startContainer: document.body, startOffset: 2, endContainer: document.body, endOffset: 3}));++ CSS.highlights.set("yellow-highlight", highlightYellow);+ CSS.highlights.set("green-highlight", highlightGreen);++ assert_equals(highlightYellow.type, "highlight");+ assert_equals(highlightGreen.type, "highlight");++ highlightGreen.type = "grammar-error";++ assert_equals(highlightYellow.type, "highlight");+ assert_equals(highlightGreen.type, "grammar-error");++ highlightGreen.type = "Spelling-error";++ assert_equals(highlightYellow.type, "highlight");+ assert_equals(highlightGreen.type, "grammar-error");++ highlightYellow.type = "ergeoirgjgeerror";++ assert_equals(highlightYellow.type, "highlight");+ assert_equals(highlightGreen.type, "grammar-error");+ });+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.htmlnew file mode 100644index 00000000000..85adcc91cf1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.html@@ -0,0 +1,55 @@+<!doctype html>+<title>Highlight is a setlike interface that works as expected even if Set.prototype is tampered</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>++<body>+<script>+"use strict";++function tamperSetPrototype() {+ delete Set.prototype.size;++ Set.prototype.entries = null;+ Set.prototype.forEach = undefined;+ Set.prototype.has = "foo";+ Set.prototype.keys = 0;+ Set.prototype.values = Symbol();+ Set.prototype[Symbol.iterator] = 1;+ Set.prototype.add = true;+ Set.prototype.clear = "";+ Set.prototype.delete = -1.5;++ Object.freeze(Set.prototype);+}++test(() => {+ tamperSetPrototype();++ const staticRange = new StaticRange({startContainer: document.body, endContainer: document.body, startOffset: 0, endOffset: 0});+ const highlight = new Highlight(staticRange);++ assert_equals(highlight.size, 1);+ assert_true(highlight.has(staticRange));+ assert_equals([...highlight.entries()][0][0], staticRange);++ highlight.clear();+ assert_equals(highlight.size, 0);++ highlight.add(staticRange);+ assert_equals(highlight.size, 1);++ highlight.delete(staticRange);+ assert_equals(highlight.size, 0);+ assert_false(highlight.has(staticRange));++ highlight.add(staticRange);+ assert_equals([...highlight.keys()][0], staticRange);+ assert_equals([...highlight.values()][0], staticRange);++ let callbackCalled = false;+ highlight.forEach(() => { callbackCalled = true; });+ assert_true(callbackCalled);+}, "Highlight is a setlike interface that works as expected even if Set.prototype is tampered.");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-setlike.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-setlike.htmlnew file mode 100644index 00000000000..f282acdb5d0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/Highlight-setlike.html@@ -0,0 +1,115 @@+<!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();+ customHighlight.add(rangeCollections[i][0]).add(rangeCollections[i][1]);+ assert_true(customHighlight.has(rangeCollections[i][0]), 'Highlight.has returns true when it contains the first range added');+ assert_true(customHighlight.has(rangeCollections[i][1]), 'Highlight.has returns true when it contains the second range added');+ 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 adding two different ranges by chaining the add method');+ }, "Highlight add method is chainable" + 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>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.htmlnew file mode 100644index 00000000000..045b4d729f7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.html@@ -0,0 +1,110 @@+<!doctype html>+<meta name="author" title="Fernando Fiori" href="mailto:[email protected]">+<meta name="assert" content="HighlightRegistry.highlightsFromPoint returns the Highlights and their corresponding Ranges and StaticRanges present at the coordinates provided as argument in the right order in multi-line text.">+<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/#interactions">+<link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-range-getclientrects">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<style>+::highlight(example-highlight) {+ background-color: rgba(0, 255, 255, 0.5);+}+body {+ font-family: monospace;+}+</style>+<span id="example-span-1">0123456789</span><br>+<span id="example-span-2">0123456789</span>+<script>+ const textNode1 = document.querySelector("#example-span-1");+ const textNode2 = document.querySelector("#example-span-2");++ function test_ranges(ranges) {+ assert_equals(ranges.length, 2, 'test_ranges() should be called with exactly two ranges.');+ let big_range = ranges[0].startOffset < ranges[1].startOffset ? ranges[0] : ranges[1];++ let highlight = new Highlight(...ranges);+ CSS.highlights.set("example-highlight", highlight);++ const rect = textNode1.getBoundingClientRect();+ const characterWidth = rect.width / textNode1.textContent.length;+ const characterHeight = rect.height;++ // No Highlights outside of text contents.+ let x = rect.left - 1;+ let y = rect.top - 1;+ let highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 0, 'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are outside of the text contents');++ // Get x and y coordinates between characters '0' and '1' on the first line (not highlighted).+ x = rect.left + characterWidth;+ y = rect.top + characterHeight / 2;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 0, 'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are outside of the highlighted ranges');++ // Get x and y coordinates between characters '2' and '3' on the first line.+ x = rect.left + 3 * characterWidth;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 1, 'CSS.highlights.highlightsFromPoint() returns exactly one HighlightHitResult when the coordinates provided point at one Highlight');+ assert_equals(highlight_hit_results[0].highlight, highlight, 'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the Highlight present at the coordinates provided');+ assert_array_equals(highlight_hit_results[0].ranges, [big_range], 'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the ranges of the Highlight present at the coordinates provided');++ // Get x and y coordinates between characters '6' and '7' on the first line.+ x = rect.left + 7 * characterWidth;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 1, 'CSS.highlights.highlightsFromPoint() returns exactly one HighlightHitResult when the coordinates provided point at one Highlight');+ assert_equals(highlight_hit_results[0].highlight, highlight, 'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the Highlight present at the coordinates provided');+ assert_array_equals(highlight_hit_results[0].ranges, ranges, 'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the ranges of the Highlight present at the coordinates provided in the right order');++ // Get x and y coordinates to the right of the last character of the first line.+ x = rect.left + 12 * characterWidth;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 0, 'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are to the right of the text contents');++ // Get x and y coordinates between characters '0' and '1' on the second line.+ x = rect.left + characterWidth;+ y = rect.top + 1.5 * characterHeight;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 1, 'CSS.highlights.highlightsFromPoint() returns exactly one HighlightHitResult when the coordinates provided point at one Highlight');+ assert_equals(highlight_hit_results[0].highlight, highlight, 'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the Highlight present at the coordinates provided');+ assert_array_equals(highlight_hit_results[0].ranges, [big_range], 'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the ranges of the Highlight present at the coordinates provided');++ // Get x and y coordinates between characters '8' and '9' on the second line (not highlighted).+ x = rect.left + 9 * characterWidth;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 0, 'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are outside of the highlighted ranges');++ // Get x and y coordinates to the right of the last character of the second line.+ x = rect.left + 12 * characterWidth;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 0, 'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are to the right of the text contents');++ // Get x and y coordinates below the second line.+ x = rect.left + 5 * characterWidth;+ y = rect.top + 3 * characterHeight;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 0, 'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are below the text contents');+ }++ test(() => {+ // Set a Highlight with two nested ranges in this way:+ // 01[234(56789)+ // 01234567]89+ let range1 = new Range();+ range1.setStart(textNode1.childNodes[0], 5);+ range1.setEnd(textNode1.childNodes[0], 10);+ let range2 = new Range();+ range2.setStart(textNode1.childNodes[0], 2);+ range2.setEnd(textNode2.childNodes[0], 8);++ let static_range1 = new StaticRange({startContainer: textNode1.childNodes[0], startOffset: 5, endContainer: textNode1.childNodes[0], endOffset: 10})+ let static_range2 = new StaticRange({startContainer: textNode1.childNodes[0], startOffset: 2, endContainer: textNode2.childNodes[0], endOffset: 8})++ test_ranges([range1, range2]);+ test_ranges([range2, range1]);+ test_ranges([static_range1, static_range2]);+ test_ranges([static_range2, static_range1]);+ test_ranges([static_range1, range2]);+ test_ranges([range1, static_range2]);+ }, 'CSS.highlights.highlightsFromPoint() returns HighlightHitResults with the Highlights and their corresponding Ranges and StaticRanges present at the given point in the right order on multi-line text.');+</script>\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.htmlnew file mode 100644index 00000000000..48fec9cd900--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.html@@ -0,0 +1,251 @@+<!doctype html>+<meta name="author" title="Fernando Fiori" href="mailto:[email protected]">+<meta name="assert" content="HighlightRegistry.highlightsFromPoint returns the Highlights present at the coordinates provided as argument in the right order.">+<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/#interactions">+<link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-range-getclientrects">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<style>+::highlight(example-highlight) {+ background-color: rgba(0, 255, 255, 0.5);+}+::highlight(example-highlight-2) {+ background-color: rgba(255, 255, 0, 0.5);+}+body {+ font-family: monospace;+}+</style>+<span id="example-span">0123456789</span>+<script>+ test(() => {+ assert_throws_js(TypeError, () => { CSS.highlights.highlightsFromPoint("asdf", 10); });+ assert_throws_js(TypeError, () => { CSS.highlights.highlightsFromPoint(10); });+ assert_throws_js(TypeError, () => { CSS.highlights.highlightsFromPoint(); });+ assert_throws_js(TypeError, () => { CSS.highlights.highlightsFromPoint(10, 10, "asdf"); });+ }, 'CSS.highlights.highlightsFromPoint() should throw when called with incorrect parameters.');++ test(() => {+ assert_equals(CSS.highlights.highlightsFromPoint(-1,-1).length, 0);+ }, 'CSS.highlights.highlightsFromPoint() should return an empty array when called with a point outside the document.');++ test(() => {+ // Set two Highlights in this way: 01[234[56789]]+ const textNode = document.querySelector("#example-span");+ let range1 = new Range();+ range1.setStart(textNode.childNodes[0], 2);+ range1.setEnd(textNode.childNodes[0], 10);+ let range2 = new Range();+ range2.setStart(textNode.childNodes[0], 5);+ range2.setEnd(textNode.childNodes[0], 10);++ let highlight1 = new Highlight(range1);+ CSS.highlights.set("example-highlight", highlight1);+ let highlight2 = new Highlight(range2);+ CSS.highlights.set("example-highlight-2", highlight2);++ const rect = textNode.getBoundingClientRect();+ const characterWidth = rect.width / textNode.textContent.length;++ // No Highlights outside of text contents.+ let x = rect.left - 1;+ let y = rect.top - 1;+ let highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 0, 'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are outside of the text contents');++ // Get x and y coordinates between '0' and '1'.+ x = rect.left + characterWidth;+ y = rect.top + rect.height / 2;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 0, 'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided point at no Highlights');++ // Get x and y coordinates between '2' and '3'.+ x = rect.left + 3 * characterWidth;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 1, 'CSS.highlights.highlightsFromPoint() returns exactly one HighlightHitResult when the coordinates provided point at one Highlight');+ assert_equals(highlight_hit_results[0].highlight, highlight1, 'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the Highlight present at the coordinates provided');+ assert_array_equals(highlight_hit_results[0].ranges, [range1], 'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the ranges of the Highlight present at the coordinates provided');++ // Get x and y coordinates between '6' and '7'.+ // Same priority for the Highlights, break tie by order of registration.+ x = rect.left + 7 * characterWidth;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 2, 'CSS.highlights.highlightsFromPoint() returns exactly two HighlightHitResults when the coordinates provided point at two overlapping Highlights');+ assert_equals(highlight_hit_results[0].highlight, highlight2, 'CSS.highlights.highlightsFromPoint() returns first a HighlightHitResult with the Highlight registered last when both Highlights present at the point provided have the same priority');+ assert_equals(highlight_hit_results[1].highlight, highlight1, 'CSS.highlights.highlightsFromPoint() returns last a HighlightHitResult with the Highlight registered first when both Highlights present at the point provided have the same priority');+ assert_array_equals(highlight_hit_results[0].ranges, [range2], 'CSS.highlights.highlightsFromPoint() returns first a HighlightHitResult with the ranges of the Highlight present on top at the coordinates provided');+ assert_array_equals(highlight_hit_results[1].ranges, [range1], 'CSS.highlights.highlightsFromPoint() returns last a HighlightHitResult with the ranges of the Highlight present at the bottom at the coordinates provided');++ // Now highlight1 should be first because it's got higher priority.+ highlight1.priority = 2;+ highlight2.priority = 1;+ highlight_hit_results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(highlight_hit_results.length, 2, 'CSS.highlights.highlightsFromPoint() returns exactly two HighlightHitResults when the coordinates provided point at two overlapping Highlights');+ assert_equals(highlight_hit_results[0].highlight, highlight1, 'CSS.highlights.highlightsFromPoint() returns first a HighlightHitResult with the Highlight with higher priority when there are two Highlights present at the point provided');+ assert_equals(highlight_hit_results[1].highlight, highlight2, 'CSS.highlights.highlightsFromPoint() returns last a HighlightHitResult with the Highlight with lower priority when there are two Highlights present at the point provided');+ }, 'CSS.highlights.highlightsFromPoint() returns the Highlights with their corresponding ranges present at the given point in the right order.');++ test(() => {+ const iframe = document.createElement("iframe");+ iframe.style.display = "none";+ document.body.appendChild(iframe);++ const iframeWindow = iframe.contentWindow;+ const iframeDoc = iframeWindow.document;+ const span = iframeDoc.createElement("span");+ span.textContent = "0123456789";+ iframeDoc.body.appendChild(span);++ const range = iframeDoc.createRange();+ range.setStart(span.childNodes[0], 0);+ range.setEnd(span.childNodes[0], 10);++ const highlight = new iframeWindow.Highlight(range);+ iframeWindow.CSS.highlights.set("example-highlight", highlight);++ const results = iframeWindow.CSS.highlights.highlightsFromPoint(5, 5);+ assert_equals(results.length, 0,+ 'highlightsFromPoint() returns empty array on a display:none iframe');++ document.body.removeChild(iframe);+ }, 'CSS.highlights.highlightsFromPoint() returns empty array when called on a display:none iframe document.');++ test(() => {+ CSS.highlights.clear();++ const textNode = document.querySelector("#example-span");+ const range = new Range();+ range.setStart(textNode.childNodes[0], 0);+ range.setEnd(textNode.childNodes[0], 10);++ const highlight = new Highlight(range);+ CSS.highlights.set("example-highlight", highlight);++ const viewportWidth = document.documentElement.clientWidth;+ const viewportHeight = document.documentElement.clientHeight;++ // Query a point just outside the right edge of the viewport.+ let results = CSS.highlights.highlightsFromPoint(viewportWidth + 1, 5);+ assert_equals(results.length, 0,+ 'highlightsFromPoint() returns empty for x beyond viewport width');++ // Query a point just outside the bottom edge of the viewport.+ results = CSS.highlights.highlightsFromPoint(5, viewportHeight + 1);+ assert_equals(results.length, 0,+ 'highlightsFromPoint() returns empty for y beyond viewport height');++ // Verify the highlight is actually found at a valid point inside the viewport.+ const rect = textNode.getBoundingClientRect();+ const characterWidth = rect.width / textNode.textContent.length;+ const x = rect.left + 3 * characterWidth;+ const y = rect.top + rect.height / 2;+ results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(results.length, 1,+ 'highlightsFromPoint() returns the highlight at valid coordinates inside the viewport');+ }, 'CSS.highlights.highlightsFromPoint() returns empty array for coordinates outside the viewport.');++ test(() => {+ CSS.highlights.clear();++ const textNode = document.querySelector("#example-span");+ const range = new Range();+ range.setStart(textNode.childNodes[0], 5);+ range.setEnd(textNode.childNodes[0], 5);+ assert_true(range.collapsed, 'range should be collapsed');++ const highlight = new Highlight(range);+ CSS.highlights.set("example-highlight", highlight);++ const rect = textNode.getBoundingClientRect();+ const characterWidth = rect.width / textNode.textContent.length;+ const x = rect.left + 5 * characterWidth;+ const y = rect.top + rect.height / 2;++ const results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(results.length, 0,+ 'highlightsFromPoint() does not return a highlight whose only range is collapsed');+ }, 'CSS.highlights.highlightsFromPoint() does not return highlights with only collapsed ranges.');++ test(() => {+ CSS.highlights.clear();++ // Create a valid StaticRange, add it to a highlight, then invalidate it+ // by shortening its text container below the retained end offset.+ const tempSpan = document.createElement("span");+ tempSpan.textContent = "temporary";+ document.body.appendChild(tempSpan);++ const staticRange = new StaticRange({+ startContainer: tempSpan.childNodes[0],+ startOffset: 0,+ endContainer: tempSpan.childNodes[0],+ endOffset: 9+ });++ const liveRange = new Range();+ liveRange.selectNodeContents(tempSpan);++ const highlight = new Highlight(staticRange, liveRange);+ CSS.highlights.set("example-highlight", highlight);+ try {+ let rect = liveRange.getClientRects()[0];+ let x = rect.left + rect.width / 2;+ let y = rect.top + rect.height / 2;+ let results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(results.length, 1);+ assert_array_equals(results[0].ranges, [staticRange, liveRange],+ 'both overlapping ranges are returned before invalidation');++ // The StaticRange retains endOffset 9, which is now out of bounds.+ tempSpan.firstChild.data = "x";+ rect = liveRange.getClientRects()[0];+ x = rect.left + rect.width / 2;+ y = rect.top + rect.height / 2;+ results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(results.length, 1);+ assert_array_equals(results[0].ranges, [liveRange],+ 'the invalid StaticRange is omitted at overlapping geometry');+ } finally {+ CSS.highlights.clear();+ tempSpan.remove();+ }+ }, 'CSS.highlights.highlightsFromPoint() skips invalid StaticRanges.');++ test(() => {+ CSS.highlights.clear();++ const textNode = document.querySelector("#example-span");++ // Create two overlapping ranges: [0123456789] and [012345]6789+ const range1 = new Range();+ range1.setStart(textNode.childNodes[0], 0);+ range1.setEnd(textNode.childNodes[0], 10);++ const range2 = new Range();+ range2.setStart(textNode.childNodes[0], 0);+ range2.setEnd(textNode.childNodes[0], 6);++ const highlight = new Highlight(range1, range2);+ CSS.highlights.set("example-highlight", highlight);++ const rect = textNode.getBoundingClientRect();+ const characterWidth = rect.width / textNode.textContent.length;++ // Query at character '3' -- both ranges cover this point.+ let x = rect.left + 3 * characterWidth;+ let y = rect.top + rect.height / 2;+ let results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(results.length, 1,+ 'highlightsFromPoint() returns exactly one HighlightHitResult for a single highlight');+ assert_array_equals(results[0].ranges, [range1, range2],+ 'both overlapping ranges are returned when both cover the queried point');++ // Query at character '8' -- only range1 covers this point.+ x = rect.left + 8 * characterWidth;+ results = CSS.highlights.highlightsFromPoint(x, y);+ assert_equals(results.length, 1,+ 'highlightsFromPoint() returns the highlight');+ assert_array_equals(results[0].ranges, [range1],+ 'only the range that covers the queried point is returned');+ }, 'CSS.highlights.highlightsFromPoint() returns all overlapping ranges within the same highlight.');+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.htmlnew file mode 100644index 00000000000..e1aae5c14f1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.html@@ -0,0 +1,154 @@+<!doctype html>+<title>HighlightRegistry 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>+<script>+ 'use strict';+ let customHighlight1 = new Highlight();+ let customHighlight2 = new Highlight();+ let highlightName1 = "example1";+ let highlightName2 = "example2";++ // Test insertions using .set+ test(() => {+ let iterator = CSS.highlights[Symbol.iterator]();+ CSS.highlights.set(highlightName1, customHighlight1);+ let element = iterator.next();+ assert_false(element.done, 'The iteration continues when a new Highlight is added after starting the iteration');+ assert_equals(element.value[0], highlightName1, 'The highlight name added after starting the iteration is found during the current iteration, following Map semantics');+ assert_equals(element.value[1], customHighlight1, 'The Highlight added after starting the iteration is found during the current iteration, following Map semantics');+ element = iterator.next();+ assert_true(element.done, 'The iteration ends after visiting the added Highlight');+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');+ }, 'HighlightRegistry iteration includes Highlights added after starting the iteration (Map-like behavior)');++ CSS.highlights.clear();++ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ let iterator = CSS.highlights[Symbol.iterator]();+ CSS.highlights.set(highlightName2, customHighlight2);+ let element = iterator.next();+ assert_false(element.done, 'The iteration continues with the first Highlight');+ assert_equals(element.value[0], highlightName1, 'The first highlight name is returned');+ assert_equals(element.value[1], customHighlight1, 'The first Highlight is returned');++ element = iterator.next();+ assert_false(element.done, 'The iteration continues to the Highlight added after starting the iteration, following Map semantics');+ assert_equals(element.value[0], highlightName2, 'The highlight name added after starting the iteration is visited');+ assert_equals(element.value[1], customHighlight2, 'The Highlight added after starting the iteration is visited');+ element = iterator.next();+ assert_true(element.done, 'The iteration ends after visiting both Highlights');+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');+ }, 'HighlightRegistry iteration includes Highlights added after starting the iteration when there were already Highlights (Map-like behavior)');++ CSS.highlights.clear();++ // Test deletions using .delete+ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ let iterator = CSS.highlights[Symbol.iterator]();+ CSS.highlights.delete(highlightName1);+ let element = iterator.next();+ assert_true(element.done, 'The iteration ends when the only Highlight is deleted before visiting it, following Map semantics');+ assert_equals(element.value, undefined, 'A Highlight deleted before being visited is not returned during iteration');+ }, 'HighlightRegistry iteration skips Highlights deleted before being visited (Map-like behavior)');++ CSS.highlights.clear();++ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ CSS.highlights.set(highlightName2, customHighlight2);+ let iterator = CSS.highlights[Symbol.iterator]();+ CSS.highlights.delete(highlightName2);+ let element = iterator.next();+ assert_false(element.done, 'The iteration doesn\'t end although the Highlight following to the one that was pointed to by the iterator was deleted');+ assert_equals(element.value[0], highlightName1, 'The highlight name that was pointed to by the iterator is returned as it should although the next Highlight was deleted immediately after starting the iteration');+ assert_equals(element.value[1], customHighlight1, 'The Highlight that was pointed to by the iterator is returned as it should although the next Highlight was deleted immediately after starting the iteration');+ element = iterator.next();+ assert_true(element.done, 'The iteration ends after the first Highlight since the second Highlight was deleted before being visited, following Map semantics');+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');+ }, 'HighlightRegistry iteration skips Highlights deleted before being visited even when other Highlights remain (Map-like behavior)');++ CSS.highlights.clear();++ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ CSS.highlights.set(highlightName2, customHighlight2);+ let iterator = CSS.highlights[Symbol.iterator]();+ let element = iterator.next();+ assert_false(element.done, 'The iteration doesn\'t end when there are still two Highlights to visit');+ assert_equals(element.value[0], highlightName1, 'The highlight name that was pointed to by the iterator is returned as it should');+ assert_equals(element.value[1], customHighlight1, 'The Highlight that was pointed to by the iterator is returned as it should');+ CSS.highlights.delete(highlightName1);+ element = iterator.next();+ assert_false(element.done, 'The iteration doesn\'t end when the Highlight previously visited is deleted and there is still a Highlight to visit');+ assert_equals(element.value[0], highlightName2, 'The highlight name that was pointed to by the iterator is returned as it should although the previous Highlight was deleted after calling .next');+ assert_equals(element.value[1], customHighlight2, 'The Highlight that was pointed to by the iterator is returned as it should although the previous Highlight was deleted after calling .next');+ element = iterator.next();+ assert_true(element.done, 'The iteration ends after going through all the highlights although the first Highlight was deleted after the first call to .next');+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');+ }, 'HighlightRegistry iteration is not modified when a Highlight that was already visited is deleted and there are still Highlights to visit');++ CSS.highlights.clear();++ // Test deletions using .clear+ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ let iterator = CSS.highlights[Symbol.iterator]();+ CSS.highlights.clear();+ let element = iterator.next();+ assert_true(element.done, 'The iteration ends when all Highlights are cleared before visiting them, following Map semantics');+ assert_equals(element.value, undefined, '.clear() removes all Highlights before iteration visits them');+ }, 'HighlightRegistry iteration skips all Highlights when .clear() is called before visiting them (Map-like behavior)');++ CSS.highlights.clear();++ // Test overwriting an existing highlight name using .set+ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ CSS.highlights.set(highlightName2, customHighlight2);+ let iterator = CSS.highlights[Symbol.iterator]();+ let element = iterator.next();+ assert_false(element.done, 'The iteration doesn\'t end when there are still two Highlights to visit');+ assert_equals(element.value[0], highlightName1, 'The first highlight name is returned');++ // Overwriting an existing name replaces its Highlight in place, so the+ // entry keeps its position and is not visited again.+ let newHighlight = new Highlight();+ CSS.highlights.set(highlightName1, newHighlight);++ element = iterator.next();+ assert_false(element.done, 'The iteration continues with the second Highlight after overwriting the first one');+ assert_equals(element.value[0], highlightName2, 'The second highlight name is returned after overwriting the highlight name that was already visited');+ assert_equals(element.value[1], customHighlight2, 'The second Highlight is returned after overwriting the highlight name that was already visited');+ element = iterator.next();+ assert_true(element.done, 'The iteration ends without visiting the overwritten highlight name a second time, following Map semantics');+ assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');+ }, 'HighlightRegistry iteration doesn\'t visit a highlight name again when it is overwritten with .set() after being visited (Map-like behavior)');++ CSS.highlights.clear();++ test(() => {+ let names = ["example1", "example2", "example3", "example4", "example5"];+ for (let name of names)+ CSS.highlights.set(name, new Highlight());++ // Overwriting the highlight name the iterator is pointing at must not move+ // it to the end of the registry, otherwise the iteration never terminates.+ let visited = [];+ for (let [name] of CSS.highlights) {+ visited.push(name);+ assert_less_than_equal(visited.length, names.length,+ 'The iteration terminates when every visited highlight name is overwritten with .set()');+ CSS.highlights.set(name, new Highlight());+ }++ assert_array_equals(visited, names,+ 'Every highlight name is visited exactly once and in insertion order, following Map semantics');+ }, 'HighlightRegistry iteration terminates when every visited highlight name is overwritten with .set() (Map-like behavior)');++ CSS.highlights.clear();++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.htmlnew file mode 100644index 00000000000..5c8a6faa416--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.html@@ -0,0 +1,186 @@+<!doctype html>+<title>HighlightRegistry iteration</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>+<script>+ 'use strict';+ let customHighlight1 = new Highlight();+ let customHighlight2 = new Highlight();+ let highlightName1 = "example1";+ let highlightName2 = "example2";++ function getIterator(iterationInitialization){+ var iterator;+ if(iterationInitialization === "CSS.highlights[Symbol.iterator]()"){+ iterator = CSS.highlights[Symbol.iterator]();+ }+ else if(iterationInitialization === "CSS.highlights.entries()"){+ iterator = CSS.highlights.entries();+ }+ else if(iterationInitialization === "CSS.highlights.values()"){+ iterator = CSS.highlights.values();+ }+ else if(iterationInitialization === "CSS.highlights.keys()"){+ iterator = CSS.highlights.keys();+ }+ return iterator;+ }+++ // Test .keys()++ let iterationInitialization = "CSS.highlights.keys()";+ test(() => {+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlight names to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlight names to iterate.');+ }, 'HighlightRegistry can be iterated when it\'s empty initializing the iterator with ' + iterationInitialization);++ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight name');+ assert_equals(element.value, highlightName1, '.next() returns an element with .value corresponding to the first highlight name added to the HighlightRegistry');+ element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlight names to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlight names to iterate.');+ }, 'HighlightRegistry can be iterated over all of its highlight names after adding one of them initializing the iterator with ' + iterationInitialization);++ test(() => {+ CSS.highlights.set(highlightName2, customHighlight2);+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value, highlightName1, '.next() returns an element with .value corresponding to the first highlight name added to the HighlightRegistry');+ element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value, highlightName2, '.next() returns an element with .value corresponding to the second highlight name added to the HighlightRegistry');+ element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlight names to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlight names to iterate.');+ }, 'HighlightRegistry can be iterated over all of its highlight names after adding two of them initializing the iterator with ' + iterationInitialization);++ CSS.highlights.clear();+++ // Test .values()++ iterationInitialization = "CSS.highlights.values()";+ test(() => {+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlights to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlights to iterate.');+ }, 'HighlightRegistry can be iterated when it\'s empty initializing the iterator with ' + iterationInitialization);++ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value, customHighlight1, '.next() returns an element with .value corresponding to the first Highlight added to the HighlightRegistry');+ element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlights to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlights to iterate.');+ }, 'HighlightRegistry can be iterated over all of its Highlights after adding one of them initializing the iterator with ' + iterationInitialization);++ test(() => {+ CSS.highlights.set(highlightName2, customHighlight2);+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value, customHighlight1, '.next() returns an element with .value corresponding to the first Highlight added to the HighlightRegistry');+ element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value, customHighlight2, '.next() returns an element with .value corresponding to the second Highlight added to the HighlightRegistry');+ element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlights to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlights to iterate.');+ }, 'HighlightRegistry can be iterated over all of its Highlights after adding two of them initializing the iterator with ' + iterationInitialization);++ CSS.highlights.clear();+++ // Test [Symbol.iterator]() and .entries()++ let iterationInitializationCollection = ["CSS.highlights[Symbol.iterator]()", "CSS.highlights.entries()"];+ for(let iterationInitialization of iterationInitializationCollection){+ test(() => {+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlights to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlights to iterate.');+ }, 'HighlightRegistry can be iterated when it\'s empty initializing the iterator with ' + iterationInitialization);++ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value[0], highlightName1, '.next() returns an element with .value[0] corresponding to the first Highlight name added to the HighlightRegistry');+ assert_equals(element.value[1], customHighlight1, '.next() returns an element with .value[1] corresponding to the first Highlight added to the HighlightRegistry');+ element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlights to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlights to iterate.');+ }, 'HighlightRegistry can be iterated over all of its Highlights after adding one of them initializing the iterator with ' + iterationInitialization);++ test(() => {+ CSS.highlights.set(highlightName2, customHighlight2);+ let iterator = getIterator(iterationInitialization);+ let element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value[0], highlightName1, '.next() returns an element with .value[0] corresponding to the first Highlight name added to the HighlightRegistry');+ assert_equals(element.value[1], customHighlight1, '.next() returns an element with .value[1] corresponding to the first Highlight added to the HighlightRegistry');+ element = iterator.next();+ assert_false(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===false when the iteration didn\'t go past the last highlight');+ assert_equals(element.value[0], highlightName2, '.next() returns an element with .value[0] corresponding to the second Highlight name added to the HighlightRegistry');+ assert_equals(element.value[1], customHighlight2, '.next() returns an element with .value[1] corresponding to the second Highlight added to the HighlightRegistry');+ element = iterator.next();+ assert_true(element.done, 'HighlightRegistry is iterable and .next() returns an element with .done===true when there are no more highlights to iterate');+ assert_equals(element.value, undefined, 'HighlightRegistry is iterable and .next() returns an element with .value undefined when there are no more highlights to iterate.');+ }, 'HighlightRegistry can be iterated over all of its Highlights after adding two of them initializing the iterator with ' + iterationInitialization);++ CSS.highlights.clear();+ }+++ // Test .forEach++ function compareArrays(array1, array2){+ if(array1.length != array2.length){+ return false;+ }+ for(let index=0; index<array1.length; ++index){+ if(array1[index] != array2[index])+ return false;+ }+ return true;+ }++ let expectedResult = [];++ test(() => {+ let actualResult = [];+ CSS.highlights.forEach((highlight) => {actualResult.push(highlight);});+ assert_true(compareArrays(actualResult, expectedResult), 'The highlights seen match the highlights added');+ }, 'HighlightRegistry can be iterated through when it\'s empty using forEach.');++ test(() => {+ CSS.highlights.set(highlightName1, customHighlight1);+ expectedResult.push(customHighlight1);+ let actualResult = [];+ CSS.highlights.forEach((highlight) => {actualResult.push(highlight);});+ assert_true(compareArrays(actualResult, expectedResult), 'The highlights seen match the highlights added');+ }, 'HighlightRegistry can be iterated through when it has one Highlight using forEach.');++ test(() => {+ CSS.highlights.set(highlightName2, customHighlight2);+ expectedResult.push(customHighlight2);+ let actualResult = [];+ CSS.highlights.forEach((highlight) => {actualResult.push(highlight);});+ assert_true(compareArrays(actualResult, expectedResult), 'The highlights seen match the highlights added');+ }, 'HighlightRegistry can be iterated through when it has two Highlights using forEach.');+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.htmlnew file mode 100644index 00000000000..cbcf1741c20--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html@@ -0,0 +1,91 @@+<!doctype html>+<title>HighlightRegistry is a maplike interface that works as expected even if Map.prototype is tampered</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>+<body>+<script>+"use strict";++function tamperMapPrototype() {+ delete Map.prototype.size;++ Map.prototype.entries = null;+ Map.prototype.forEach = undefined;+ Map.prototype.get = "foo";+ Map.prototype.has = 0;+ Map.prototype.keys = Symbol();+ Map.prototype.values = 1;+ Map.prototype[Symbol.iterator] = true;+ Map.prototype.clear = false;+ Map.prototype.delete = "";+ Map.prototype.set = 3.14;++ Object.freeze(Map.prototype);+}++function restoreMapPrototype(originalDescriptors) {+ // Create a new object with the original descriptors+ const newProto = Object.create(Object.prototype);++ for (const [key, descriptor] of Object.entries(originalDescriptors)) {+ if (descriptor) {+ Object.defineProperty(newProto, key, descriptor);+ }+ }+ // Replace the frozen prototype with the restored one+ Object.setPrototypeOf(Map, newProto);+}++test(() => {+ const originalDescriptors = {+ size: Object.getOwnPropertyDescriptor(Map.prototype, 'size'),+ entries: Object.getOwnPropertyDescriptor(Map.prototype, 'entries'),+ forEach: Object.getOwnPropertyDescriptor(Map.prototype, 'forEach'),+ get: Object.getOwnPropertyDescriptor(Map.prototype, 'get'),+ has: Object.getOwnPropertyDescriptor(Map.prototype, 'has'),+ keys: Object.getOwnPropertyDescriptor(Map.prototype, 'keys'),+ values: Object.getOwnPropertyDescriptor(Map.prototype, 'values'),+ [Symbol.iterator]: Object.getOwnPropertyDescriptor(Map.prototype, Symbol.iterator),+ clear: Object.getOwnPropertyDescriptor(Map.prototype, 'clear'),+ delete: Object.getOwnPropertyDescriptor(Map.prototype, 'delete'),+ set: Object.getOwnPropertyDescriptor(Map.prototype, 'set')+ };++ tamperMapPrototype();++ const highlight = new Highlight(new StaticRange({startContainer: document.body, endContainer: document.body, startOffset: 0, endOffset: 0}));+ const highlightRegistry = CSS.highlights;++ assert_equals(highlightRegistry.size, 0);+ highlightRegistry.set("foo", highlight);+ assert_equals(highlightRegistry.size, 1);++ assert_true(highlightRegistry.has("foo"));+ assert_equals([...highlightRegistry.entries()][0][0], "foo");++ highlightRegistry.clear();+ assert_equals(highlightRegistry.size, 0);+ assert_equals(highlightRegistry.get("foo"), undefined);++ highlightRegistry.set("bar", highlight);+ assert_equals(highlightRegistry.get("bar"), highlight);+ assert_equals([...highlightRegistry][0][1], highlight);++ highlightRegistry.delete("bar");+ assert_equals(highlightRegistry.size, 0);+ assert_false(highlightRegistry.has("bar"));++ highlightRegistry.set("baz", highlight);+ assert_equals([...highlightRegistry.keys()][0], "baz");+ assert_equals([...highlightRegistry.values()][0], highlight);++ let callbackCalled = false;+ highlightRegistry.forEach(() => { callbackCalled = true; });+ assert_true(callbackCalled);++ highlightRegistry.clear();+ restoreMapPrototype(originalDescriptors);+}, "HighlightRegistry is a maplike interface that works as expected even if Map.prototype is tampered.");+</script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.htmlnew file mode 100644index 00000000000..a86f1a421b4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.html@@ -0,0 +1,110 @@+<!doctype html>+<title>HighlightRegistry has a maplike 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>+<script>+ 'use strict';++ test(() => {+ assert_not_equals(window.HighlightRegistry, undefined, 'HighlightRegistry is in window');+ assert_equals(typeof HighlightRegistry, 'function', 'HighlightRegistry is a function');+ assert_throws_js(TypeError, function () { var x = new HighlightRegistry(); },+ 'HighlightRegistry constructor throws');++ assert_not_equals(CSS.highlights, undefined, 'CSS.highlights exists');+ assert_equals(CSS.highlights.__proto__, window.HighlightRegistry.prototype,+ 'CSS.highlights and window.HighlightRegistry have same prototype');++ assert_equals(CSS.highlights.size, 0, 'HighlightRegistry starts empty');+ }, 'HighlightRegistry initializes as it should.');++ test(() => {+ let name1 = "example1";+ let name2 = "example2";+ let h1 = new Highlight();+ let h2 = new Highlight();++ assert_false(CSS.highlights.has(name1), 'HighlightRegistry.has returns false when it doesn\'t have the key which is called with as argument.');+ CSS.highlights.set(name1, h1);+ assert_true(CSS.highlights.has(name1), 'HighlightRegistry.has returns true when it has the key which is called with as argument.');+ assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size is 1 after only inserting 1 key.');++ assert_false(CSS.highlights.delete(name2), 'HighlightRegistry.delete returns false when trying to delete an key that is not in the map.');+ assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size stays the same after trying to delete a non-existing key.');++ CSS.highlights.set(name2, h2);+ assert_true(CSS.highlights.has(name1), 'HighlightRegistry.has returns true when it is called with the key inserted first');+ assert_true(CSS.highlights.has(name2), 'HighlightRegistry.has returns true when it is called with the key inserted second');+ assert_equals(CSS.highlights.get(name1), h1, 'HighlightRegistry.get returns the first Highlight when it is called with the key inserted first');+ assert_equals(CSS.highlights.get(name2), h2, 'HighlightRegistry.get returns the second Highlight when it is called with the key inserted second');+ assert_equals(CSS.highlights.size, 2, 'HighlightRegistry.size is 2 after only inserting two different keys.');++ assert_true(CSS.highlights.delete(name2), 'HighlightRegistry.delete returns true when trying to delete a key that is in the group.');+ assert_true(CSS.highlights.has(name1), 'HighlightRegistry.has returns true when it is called with the key inserted first');+ assert_false(CSS.highlights.has(name2), 'HighlightRegistry.has returns true when it is called with the key that was deleted');+ assert_equals(CSS.highlights.get(name1), h1, 'HighlightRegistry.get still returns the first Highlight when it is called with the key inserted first');+ assert_equals(CSS.highlights.get(name2), undefined, 'HighlightRegistry.get returns undefined when it is called with a key that was deleted');+ assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size decreases in 1 after deleting an existing key.');++ assert_false(CSS.highlights.delete(name2), 'HighlightRegistry.delete returns false when trying to delete a key that was already deleted.');+ assert_true(CSS.highlights.has(name1), 'HighlightRegistry.has returns true when it is called with the key inserted first');+ assert_false(CSS.highlights.has(name2), 'HighlightRegistry.has returns false when it is called with a key that was deleted twice');+ assert_equals(CSS.highlights.get(name1), h1, 'HighlightRegistry.get still returns the first Highlight when it is called with the key inserted first');+ assert_equals(CSS.highlights.get(name2), undefined, 'HighlightRegistry.get still returns undefined when it is called with a key that was deleted');+ assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size stays the same after trying to delete the same key for a second time.');++ assert_true(CSS.highlights.delete(name1), 'HighlightRegistry.delete returns true when trying to delete the remaining key');+ assert_false(CSS.highlights.has(name1), 'HighlightRegistry.has returns false when it is called with the key inserted first and then deleted');+ assert_false(CSS.highlights.has(name2), 'HighlightRegistry.has returns false when it is called with the key inserted second and then deleted');+ assert_equals(CSS.highlights.get(name1), undefined, 'HighlightRegistry.get returns undefined when it is called with a key that was deleted');+ assert_equals(CSS.highlights.get(name2), undefined, 'HighlightRegistry.get returns undefined when it is called with a key that was deleted');+ assert_equals(CSS.highlights.size, 0, 'HighlightRegistry.size decreases in 1 after deleting an existing key.');++ CSS.highlights.set(name1, h1);+ CSS.highlights.set(name1, h2);+ assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size keeps the same after an insertion of a Highlight with an existing name');+ assert_equals(CSS.highlights.get(name1), h2, 'The Highlight inserted with the same name as an existing one was effectively inserted into the registry');++ CSS.highlights.clear();+ assert_equals(CSS.highlights.size, 0, 'HighlightRegistry.clear empties the map.');+ CSS.highlights.clear();+ assert_equals(CSS.highlights.size, 0, 'HighlightRegistry.clear called with an empty registry keeps it empty.');++ CSS.highlights.set(name1, h1).set(name2, h2);+ assert_equals(CSS.highlights.size, 2, 'HighlightRegistry.size is 2 after inserting two different Highlights by chaining the set method.');+ }, 'HighlightRegistry has a maplike interface.');++ test(() => {+ let name1 = "example1";+ let name2 = "example2";+ let name3 = "example3";+ let h1 = new Highlight();+ let h2 = new Highlight();+ let h3 = new Highlight();+ let h4 = new Highlight();++ // A Map with the same operations applied to it, used as the reference for+ // the expected ordering.+ let map = new Map();++ CSS.highlights.clear();+ for (let [name, highlight] of [[name1, h1], [name2, h2], [name3, h3]]) {+ CSS.highlights.set(name, highlight);+ map.set(name, highlight);+ }++ CSS.highlights.set(name1, h4);+ map.set(name1, h4);++ assert_array_equals([...CSS.highlights.keys()], [name1, name2, name3],+ 'Setting an existing name doesn\'t change the order of the highlight names');+ assert_array_equals([...CSS.highlights.keys()], [...map.keys()],+ 'The highlight names are in the same order as the keys of a Map with the same insertions, following Map semantics');+ assert_array_equals([...CSS.highlights.values()], [...map.values()],+ 'Setting an existing name replaces its Highlight without changing the order, following Map semantics');+ assert_equals(CSS.highlights.size, map.size,+ 'Setting an existing name doesn\'t change the size of the registry');+ }, 'HighlightRegistry.set() with an existing name preserves the insertion order (Map-like behavior)');++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-priority.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-priority.htmlnew file mode 100644index 00000000000..0dc19e26aed--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-priority.html@@ -0,0 +1,77 @@+<!DOCTYPE html>+<html>+<head>+ <title>Highlight priority attribute is mutable</title>+ <link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/#priorities">+ <script src="../../resources/testharness.js"></script>+ <script src="../../resources/testharnessreport.js"></script>+ <style>+ ::highlight(yellow-highlight) {+ background-color: yellow;+ }+ ::highlight(green-highlight) {+ background-color: green;+ }+ ::highlight(blue-highlight) {+ background-color: blue;+ }+ </style>+</head>+<body>+ <span id="green-highlight">Green</span>+ <span id="yellow-highlight">Yellow</span>+ <span id="blue-highlight">Blue</span>+ <span id="yellow-blue-highlight">Yellow-Blue</span>++ <script>+ test(() => {+ let yellowBlue = document.getElementById("yellow-blue-highlight");++ let green = document.getElementById("green-highlight");+ let highlightGreen = new Highlight(new StaticRange({+ startContainer: green.childNodes[0],+ startOffset: 0,+ endContainer: green.childNodes[0],+ endOffset: 6+ }));++ let yellow = document.getElementById("yellow-highlight");+ let highlightYellow = new Highlight(new StaticRange({+ startContainer: yellow.childNodes[0],+ startOffset: 0,+ endContainer: yellow.childNodes[0],+ endOffset: 6+ }), new StaticRange({+ startContainer: yellowBlue.childNodes[0],+ startOffset: 0,+ endContainer: yellowBlue.childNodes[0],+ endOffset: 6+ }));++ let blue = document.getElementById("blue-highlight");+ let highlightBlue = new Highlight(new StaticRange({+ startContainer: blue.childNodes[0],+ startOffset: 0,+ endContainer: blue.childNodes[0],+ endOffset: 4+ }), new StaticRange({+ startContainer: yellowBlue.childNodes[0],+ startOffset: 0,+ endContainer: yellowBlue.childNodes[0],+ endOffset: 11+ }));++ CSS.highlights.set("yellow-highlight", highlightYellow);+ CSS.highlights.set("green-highlight", highlightGreen);+ CSS.highlights.set("blue-highlight", highlightBlue);++ highlightYellow.priority = 10;+ highlightBlue.priority = -1;++ assert_equals(highlightYellow.priority, 10);+ assert_equals(highlightGreen.priority, 0);+ assert_equals(highlightBlue.priority, -1);+ });+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-computed.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-computed.htmlnew file mode 100644index 00000000000..9359a0453a1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-computed.html@@ -0,0 +1,40 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS ::highlight Pseudo-Element Test: ::highlight selector getComputedStyle</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>+<style>+ #target::highlight(foo) {+ background-color: green;+ color: lime;+ }++ #target::highlight(bar) {+ background-color: cyan;+ color: fuchsia;+ }+</style>+<div id="target"></div>+<script>+ let highlightPseudo = "::highlight(foo)";+ test(() => {+ let style = getComputedStyle(target, highlightPseudo);+ assert_equals(style.backgroundColor, "rgb(0, 128, 0)", "Background color is green.");+ assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");+ }, `getComputedStyle() for ${highlightPseudo}`);++ highlightPseudo = "::highlight(bar)";+ test(() => {+ let style = getComputedStyle(target, highlightPseudo);+ assert_equals(style.backgroundColor, "rgb(0, 255, 255)", "Background color is cyan.");+ assert_equals(style.color, "rgb(255, 0, 255)", "Color is fuchsia.");+ }, `Different getComputedStyle() for ${highlightPseudo} and same element`);++ for (const illHighlightPseudo of ["::highlight(foo):", "::highlight(foo))", "::highlight(foo)(", "::highlight", "::highlight(foo)(foo)", "::highlight(foo)()", ":::highlight(foo)", "::highlight(foo).", "::highlight(foo,bar)", "::highlight(foo bar)"]) {+ test(() => {+ let style = getComputedStyle(target, illHighlightPseudo);+ assert_equals(style.length, 0, "Invalid pseudo identifiers should not return a style.");+ }, `getComputedStyle() for ${illHighlightPseudo} should not return a style.`);+ }+</script>\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.htmlnew file mode 100644index 00000000000..840b4c9474e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.html@@ -0,0 +1,59 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS ::highlight Pseudo-Element Test: ::highlight selector getComputedStyle</title>+<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">+<meta name="assert" value="Font relative units are correctly reported in getComputedStyle">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<style>+ :root {+ font-size: 16px;+ }+ div {+ margin: 40px;+ font-size: 20px;+ }+ ::highlight(highlight1) {+ text-underline-offset: 0.5em;+ text-decoration-line: underline;+ text-decoration-color: green;+ text-decoration-thickness: 0.25rem;+ }+ #h2::highlight(highlight1) {+ text-underline-offset: 1.0em;+ text-decoration-line: underline;+ text-decoration-color: blue;+ text-decoration-thickness: 0.125rem;+ }+</style>+<div id="h1">A green 10px offset underline 4px thick</div>+<div id="h2">A blue 20px offset underline 2px thick</div>+<script>+ let r1 = new Range();+ r1.setStart(h1, 0);+ r1.setEnd(h1, 1);+ let r2 = new Range();+ r2.setStart(h2, 0);+ r2.setEnd(h2, 1);+ CSS.highlights.set("highlight1", new Highlight(r1, r2));++ let highlightPseudo = "::highlight(highlight1)";+ test(() => {+ let style = getComputedStyle(document.documentElement, highlightPseudo);+ assert_equals(style.textUnderlineOffset, "8px", "Text underline offset is 8px.");+ assert_equals(style.textDecorationThickness, "4px", "Text decoration thickness is 4px.");+ }, `getComputedStyle() for root element`);++ test(() => {+ let style = getComputedStyle(h1, highlightPseudo);+ assert_equals(style.textUnderlineOffset, "10px", "Text underline offset is 10px.");+ assert_equals(style.textDecorationThickness, "4px", "Text decoration thickness is 4px.");+ }, `getComputedStyle() for root highlight applied to div`);++ test(() => {+ let style = getComputedStyle(h2, highlightPseudo);+ assert_equals(style.textUnderlineOffset, "20px", "Text underline offset is 20px.");+ assert_equals(style.textDecorationThickness, "2px", "Text decoration thickness is 2px.");+ }, `getComputedStyle() for div specific highlight`);++</script>\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.htmlnew file mode 100644index 00000000000..15548f4bcd5--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.html@@ -0,0 +1,29 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS ::highlight Pseudo-Element Test: ::highlight selector parsing</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>+<script src="../../css/support/parsing-testcommon.js"></script>+<script>+ const pseudo = "::highlight(foo)";+ test_valid_selector(pseudo);+ test_valid_selector(`.a${pseudo}`);+ test_valid_selector(`div ${pseudo}`);+ test_valid_selector(`::part(my-part)${pseudo}`);++ test_valid_selector("::highlight(multi\\ word)");+ test_valid_selector("::highlight(\\31\\32\\33)", "::highlight(\\31 23)");++ test_valid_selector("::highlight(\\*)");+ test_valid_selector("div::highlight(\\*)");+ test_valid_selector(":root::highlight(\\*)");++ test_invalid_selector("::highlight");+ test_invalid_selector(`::before${pseudo}`);+ test_invalid_selector(`${pseudo}.a`);+ test_invalid_selector(`${pseudo} div`);+ test_invalid_selector(`${pseudo}::after`);+ test_invalid_selector(`${pseudo}:hover`);+ test_invalid_selector(`:not(${pseudo})`);+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/historical.window.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/historical.window.htmlnew file mode 100644index 00000000000..f3efbb560c5--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/historical.window.html@@ -0,0 +1,8 @@+<!doctype html>+<meta charset=utf-8>++<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../../css/css-highlight-api/historical.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/historical.window.js b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/historical.window.jsnew file mode 100644index 00000000000..9b735f855dc--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/historical.window.js@@ -0,0 +1,7 @@+// https://drafts.csswg.org/css-highlight-api-1/++"use strict";++test(() => {+ assert_equals(self.HighlightRegister, undefined);+}, "HighlightRegister was renamed");diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/idlharness.window.html b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/idlharness.window.htmlnew file mode 100644index 00000000000..a1963c6c886--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/idlharness.window.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>++<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/WebIDLParser.js"></script>+<script src="../../resources/idlharness.js"></script>+<div id=log></div>+<script src="../../css/css-highlight-api/idlharness.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/idlharness.window.js b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/idlharness.window.jsnew file mode 100644index 00000000000..7e9f3c44047--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-highlight-api/idlharness.window.js@@ -0,0 +1,17 @@+// META: script=/resources/WebIDLParser.js+// META: script=/resources/idlharness.js++// https://drafts.csswg.org/css-highlight-api-1/++'use strict';++idl_test(+ ['css-highlight-api'],+ ['cssom'],+ idl_array => {+ idl_array.add_objects({+ Highlight: ['new Highlight(new Range())'],+ HighlightRegistry: ['CSS.highlights'],+ });+ }+);diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/parsing/highlight-pseudos.html b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/parsing/highlight-pseudos.htmlnew file mode 100644index 00000000000..26c4a62abde--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/parsing/highlight-pseudos.html@@ -0,0 +1,22 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS Pseudo-Elements Test: highlight selectors parsing</title>+<link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>+<script src="../../../css/support/parsing-testcommon.js"></script>+<script>+ for (const pseudo of ["::selection", "::target-text", "::spelling-error", "::grammar-error"]) {+ test_valid_selector(`${pseudo}`);+ test_valid_selector(`.a${pseudo}`);+ test_valid_selector(`div ${pseudo}`);+ test_valid_selector(`::part(my-part)${pseudo}`);++ test_invalid_selector(`::before${pseudo}`);+ test_invalid_selector(`${pseudo}.a`);+ test_invalid_selector(`${pseudo} div`);+ test_invalid_selector(`${pseudo}::after`);+ test_invalid_selector(`${pseudo}:hover`);+ test_invalid_selector(`:not(${pseudo})`);+ }+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/interfaces/css-highlight-api.idl b/Tests/LibWeb/Text/input/wpt-import/interfaces/css-highlight-api.idlnew file mode 100644index 00000000000..8d98b1230f1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/interfaces/css-highlight-api.idl@@ -0,0 +1,40 @@+// GENERATED CONTENT - DO NOT EDIT+// Content was automatically extracted by Reffy into webref+// (https://github.com/w3c/webref)+// Source: CSS Custom Highlight API Module Level 1 (https://drafts.csswg.org/css-highlight-api-1/)++enum HighlightType {+ "highlight",+ "spelling-error",+ "grammar-error"+};++[Exposed=Window]+interface Highlight {+ constructor(AbstractRange... initialRanges);+ setlike<AbstractRange>;+ attribute long priority;+ attribute HighlightType type;+};++partial namespace CSS {+ readonly attribute HighlightRegistry highlights;+};++[Exposed=Window]+interface HighlightRegistry {+ maplike<DOMString, Highlight>;+};++partial interface HighlightRegistry {+ sequence<HighlightHitResult> highlightsFromPoint(float x, float y, optional HighlightsFromPointOptions options = {});+};++dictionary HighlightHitResult {+ Highlight highlight;+ sequence<AbstractRange> ranges;+};++dictionary HighlightsFromPointOptions {+ sequence<ShadowRoot> shadowRoots = [];+};