Skip to content

Commit

Permalink
Fix WPT CSS Counters test
Browse files Browse the repository at this point in the history
As per:
https://drafts.csswg.org/css-contain/#example-6932a400
and
w3c/csswg-drafts#9116
counter() and counters() can cross the style containment boundary,
so the result should be 13 from the body's counter-reset.

Bug: 990657
Change-Id: Iee313a5ed6f487865b1b7c754aa45b736f6b8f15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4836162
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Commit-Queue: Daniil Sakhapov <sakhapov@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1204571}
  • Loading branch information
danielsakhapov authored and chromium-wpt-export-bot committed Oct 3, 2023
1 parent e9faf2c commit dcb79ca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 71 deletions.
99 changes: 30 additions & 69 deletions css/css-contain/contain-style-counters-004.html
Original file line number Diff line number Diff line change
@@ -1,71 +1,32 @@
<!DOCTYPE html>

<meta charset="UTF-8">

<title>CSS Containment Test: 'contain: style' for counters (span descendants of &lt;body&gt;)</title>

<link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/">
<link rel="help" href="https://www.w3.org/TR/css-contain-1/#containment-style">
<link rel="match" href="reference/contain-style-counters-004-ref.html">


<style>
body
{
counter-reset: counter-of-span 13;
}

/*
This creates a new counter identified as "counter-of-span"
and initially sets such counter to 13 (an entirely
arbitrary number)
*/

body
{
contain: style;
}

/*
This will reset the counter to 0.
*/

body span
{
counter-increment: counter-of-span 5;
}

/*
This increments the counter identified as "counter-of-span"
of the step value of 5 (an entirely arbitrary number) each
and every time there is a <span> descendant within the subtree
of body
*/

div
{
font-size: 3em;
}

div::after
{
content: counter(counter-of-span);
}

/*
Now, the generated content after the span is set to the
current value of the counter identified as "counter-of-span"
*/
</style>

<body>

<p> <span></span> <span></span> <span></span> <span></span>

<!-- 4 span inside the <p>. However, since div isn't a sibling of spans,
it creates a new counter.
-->

<p>Test passes if there is the number 0.

<meta charset="UTF-8">
<title>CSS Containment Test: 'contain: style' for counters (span descendants of &lt;body&gt;)</title>
<link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/">
<link rel="help" href="https://www.w3.org/TR/css-contain-1/#containment-style">
<link rel="match" href="reference/contain-style-counters-004-ref.html">
<style>
body {
counter-reset: counter-of-span 13;
contain: style;
}
body span {
counter-increment: counter-of-span 5;
}
div {
font-size: 3em;
}
div::after {
content: counter(counter-of-span);
}
</style>
<body>
<p><span></span> <span></span> <span></span> <span></span></p>

<!-- The <span>s aren't allowed to modify the counter instantiated on the <body>,
so a new instance of the counter is created.
Since the <div> isn't a sibling of the <span>, it will not inherit this new instance,
and instead it will read the original counter from the <body>, with value 13.
This is per example at: https://drafts.csswg.org/css-contain/#containment-style -->
<p>Test passes if there is the number 13.</p>
<div></div>
</body>
4 changes: 2 additions & 2 deletions css/css-contain/reference/contain-style-counters-004-ref.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
}
</style>

<p>Test passes if there is the number 0.
<p>Test passes if there is the number 13.

<div>0</div>
<div>13</div>

0 comments on commit dcb79ca

Please sign in to comment.