-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These tests are meant to verify that: - UAs must not define any styles for custom highlight pseudo-elements in the default UA stylesheet. - A custom highlight pseudo-element inherits the styles of its originating element. See https://drafts.csswg.org/css-highlight-api-1/#default-styles Bug: 1164461 Change-Id: I955f39ee185fe2282d7599c07ff1cdd7df2d7059 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3273351 Commit-Queue: Fernando Fiori <[email protected]> Reviewed-by: Dan Clark <[email protected]> Cr-Commit-Position: refs/heads/main@{#944166}
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
css/css-highlight-api/painting/custom-highlight-painting-overlapping-highlights-001-ref.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<meta charset="UTF-8"> | ||
<style> | ||
body { | ||
font-size: 3em; | ||
font-weight: bolder; | ||
} | ||
#affected2 { | ||
color: green; | ||
} | ||
</style> | ||
<body><span>This should have default style (black).</span><span id="affected2">This should have 'highlight2' style (green).</span> |
45 changes: 45 additions & 0 deletions
45
css/css-highlight-api/painting/custom-highlight-painting-overlapping-highlights-001.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<meta charset="UTF-8"> | ||
<title>CSS Highlight API Test: Overlapping Highlights</title> | ||
<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/"> | ||
<link rel="match" href="custom-highlight-painting-overlapping-highlights-001-ref.html"> | ||
<meta name="assert" value="UAs must not define any styles for custom highlight pseudo-elements in the default UA stylesheet."> | ||
<style> | ||
body { | ||
font-size: 3em; | ||
font-weight: bolder; | ||
} | ||
#affected1::highlight(highlight1) { | ||
color: red; | ||
} | ||
#affected2::highlight(highlight2) { | ||
color: green; | ||
} | ||
</style> | ||
<body><span id="affected1">This should have default style (black).</span><span id="affected2">This should have 'highlight2' style (green).</span> | ||
<script> | ||
/* | ||
This test is meant to verify that: | ||
- UAs must not define any styles for custom highlight pseudo-elements in | ||
the default UA stylesheet. | ||
- A custom highlight pseudo-element inherits the styles of its originating | ||
element. | ||
In this test, highlight2 has higher priority because it was registered | ||
later, so it is painted over highlight1. This includes painting for | ||
span#affected1, where there is no CSS rule for highlight2. The result is | ||
that highlight2 paints on top for span#affected1, using the originating | ||
element's color. Thus it appears as if no highlight was painted at all for | ||
span#affected1. | ||
See https://drafts.csswg.org/css-highlight-api-1/#default-styles | ||
*/ | ||
|
||
const node = document.body; | ||
let r = new Range(); | ||
r.setStart(node, 0); | ||
r.setEnd(node, 2); | ||
|
||
CSS.highlights.set("highlight1", new Highlight(r)); | ||
CSS.highlights.set("highlight2", new Highlight(r)); | ||
</script> |
16 changes: 16 additions & 0 deletions
16
css/css-highlight-api/painting/custom-highlight-painting-overlapping-highlights-002-ref.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<meta charset="UTF-8"> | ||
<style> | ||
div { | ||
font-size: 3em; | ||
font-weight: bolder; | ||
} | ||
#affected1 { | ||
color: green; | ||
background-color: rgb(0, 255, 0, 0.5); | ||
} | ||
#affected2 { | ||
background-color: rgba(100, 0, 100, 0.5); | ||
} | ||
</style> | ||
<body><div><span id="affected1">Green on lime.</span><span id="affected2">Black on maroon.</span></div> |
56 changes: 56 additions & 0 deletions
56
css/css-highlight-api/painting/custom-highlight-painting-overlapping-highlights-002.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<meta charset="UTF-8"> | ||
<title>CSS Highlight API Test: Overlapping Highlights</title> | ||
<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/"> | ||
<link rel="match" href="custom-highlight-painting-overlapping-highlights-002-ref.html"> | ||
<meta name="assert" value="UAs must not define any styles for custom highlight pseudo-elements in the default UA stylesheet."> | ||
<style> | ||
div { | ||
font-size: 3em; | ||
font-weight: bolder; | ||
} | ||
#affected1::highlight(highlight1) { | ||
color: green; | ||
background-color: rgb(0, 255, 0, 0.5); | ||
} | ||
#affected2::highlight(highlight2) { | ||
color: red; | ||
background-color: rgba(100, 0, 100, 0.5); | ||
} | ||
</style> | ||
<body><div><span id="affected1">Green on lime.</span><span id="affected2">Black on maroon.</span></div> | ||
<script> | ||
/* | ||
This test is meant to verify that: | ||
- UAs must not define any styles for custom highlight pseudo-elements in | ||
the default UA stylesheet. | ||
- A custom highlight pseudo-element inherits the styles of its originating | ||
element. | ||
In this test, highlight1 has higher priority, so it is painted over | ||
highlight2. This includes painting for span#affected2, where there is no CSS | ||
rule for highlight1. The result is that highlight1 paints on top for | ||
span#affected2, using the originating element's color (black) and background | ||
color (transparent). Thus, span#affected2 gets text color black, and the | ||
background remains the same color as that applied by highlight2 (maroon). | ||
See https://drafts.csswg.org/css-highlight-api-1/#default-styles | ||
*/ | ||
|
||
const div = document.querySelector("div"); | ||
|
||
let r = new Range(); | ||
r.setStart(div, 0); | ||
r.setEnd(div, 2); | ||
let r2 = new Range(); | ||
r2.setStart(div, 0); | ||
r2.setEnd(div, 2); | ||
|
||
let h = new Highlight(r); | ||
h.priority = 3; | ||
let h2 = new Highlight(r2); | ||
h2.priority = 2; | ||
|
||
CSS.highlights.set("highlight1", h); | ||
CSS.highlights.set("highlight2", h2); | ||
</script> |