Skip to content

Truly independent web browser

LibWeb: Take a wrap-reverse flex container’s baseline from its start

sideshowbarker4a1a0f3471c8
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index a8bb88cc380..0cc8615d596 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -4350,19 +4350,28 @@ impl<'pass> FlexFormattingContext<'pass> {
if self.facts(self.run.box_).has_preferred_aspect_ratio() {
self.in_flow_items_margin_box_block_extent = self.margin_box_block_extent_of_placed_in_flow_items();
}
+ // https://drafts.csswg.org/css-flexbox-1/#flex-baselines
+ // If any of the flex items on the flex container's startmost/endmost flex line participate in baseline
+ // alignment, the flex container's first/last main-axis baseline set is generated from the shared alignment
+ // baseline of those flex items.
+ // NB: The lines are in cross-start to cross-end order, and wrap-reverse puts cross-start at the container's
+ // block-end. So the startmost line is then the last one.
+ let (startmost_line, endmost_line) = match self.flex_lines.len().checked_sub(1) {
+ Some(last_line) if self.used_flex_wrap() == flex_wrap::WRAP_REVERSE => (Some(last_line), Some(0)),
+ Some(last_line) => (Some(0), Some(last_line)),
+ None => (None, None),
+ };
self.derived_baselines_of_root_box = DerivedBaselines {
- inline_alignment: self.flex_lines.len().checked_sub(1).and_then(|line_index| {
+ inline_alignment: endmost_line.and_then(|line_index| {
self.baseline_of_line_for_purpose(
line_index,
formatting_context::BaselineSet::Last,
formatting_context::BaselinePurpose::InlineAlignment,
)
}),
- first: self.baseline_of_line(0, formatting_context::BaselineSet::First),
- last: self
- .flex_lines
- .len()
- .checked_sub(1)
+ first: startmost_line
+ .and_then(|line_index| self.baseline_of_line(line_index, formatting_context::BaselineSet::First)),
+ last: endmost_line
.and_then(|line_index| self.baseline_of_line(line_index, formatting_context::BaselineSet::Last)),
};
}
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-002-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-002-ref.html
new file mode 100644
index 00000000000..491144cc212
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-002-ref.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!-- Reference case, using inline-block instead of inline-flex, and with the
+ baseline-aligned items aligned using specific font-size / line-heights,
+ and with unaligned children taken out of baseline-alignment using
+ "vertical-align:top".
+-->
+<html>
+<head>
+ <title>CSS Reftest Reference</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <meta charset="utf-8">
+ <style>
+ .flexContainer {
+ display: inline-block;
+ width: 40px;
+ /* Split testcase's 40px height into 20px of padding-bottom and 20px of
+ height, to set aside space for the testcase's (invisible) second line. */
+ height: 20px;
+ padding-bottom: 20px;
+ background: lightblue;
+ }
+ .flexContainer > * {
+ width: 20px;
+ display: inline-block;
+ }
+
+ .smallFont {
+ font-size: 8px;
+ line-height: 8px;
+ }
+ .medFont {
+ font-size: 12px;
+ line-height: 12px;
+ }
+ .bigFont {
+ font-size: 16px;
+ line-height: 16px;
+ }
+ .unaligned { vertical-align: top }
+ </style>
+</head>
+<body>
+ a
+ <!-- Flex containers with flex items that have a mix of baselines: -->
+ <div class="flexContainer medFont">
+ <div class="bigFont">d</div
+ ><div class="medFont unaligned">e</div>
+ </div>
+
+ <div class="flexContainer bigFont">
+ <div class="bigFont">h</div
+ ><div class="medFont unaligned">i</div>
+ </div>
+ n
+
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-004-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-004-ref.html
new file mode 100644
index 00000000000..212b3b1e979
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-004-ref.html
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+ <title>CSS Reftest Reference</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <meta charset="utf-8">
+ <style>
+ /* We use an outer vertical flex container, wrapping two single-line
+ flex containers, to match the testcase's multi-line flex container. */
+ .outerFlexContainer {
+ height: 100px;
+ background: lightgray;
+ display: inline-flex;
+ flex-direction: column-reverse;
+ justify-content: center; /* to mimic testcase's "align-content:center" */
+ }
+ .flexContainer {
+ display: flex;
+ width: 40px;
+ }
+ .flexContainer > * {
+ width: 20px;
+ }
+
+ .smallFont {
+ font-size: 8px;
+ line-height: 8px;
+ }
+ .medFont {
+ font-size: 12px;
+ line-height: 12px;
+ }
+ .bigFont {
+ font-size: 16px;
+ line-height: 16px;
+ }
+ </style>
+</head>
+<body>
+ a
+ <!-- Flex container with second item in first line baseline-aligned
+ (should set the container's baseline) -->
+ <div class="outerFlexContainer">
+ <div class="flexContainer">
+ <div class="medFont">b</div>
+ <div class="bigFont" style="align-self: baseline">c</div>
+ </div>
+ <div class="flexContainer">
+ <div class="medFont">d</div>
+ <div class="smallFont">e</div>
+ </div>
+ </div>
+
+ <!-- Flex container with both items in first line baseline-aligned
+ (should set the container's baseline) -->
+ <div class="outerFlexContainer">
+ <div class="flexContainer">
+ <div class="smallFont" style="align-self: baseline">f</div>
+ <div class="medFont" style="align-self: baseline">g</div>
+ </div>
+ <div class="flexContainer">
+ <div class="bigFont">h</div>
+ <div class="smallFont">i</div>
+ </div>
+ </div>
+
+ <!-- Flex container with all items baseline-aligned
+ (only those on first line should set the container's baseline) -->
+ <div class="outerFlexContainer">
+ <div class="flexContainer" style="align-items: baseline">
+ <div class="bigFont">j</div>
+ <div class="smallFont" style="padding-bottom: 20px">k</div>
+ </div>
+ <div class="flexContainer" style="align-items: baseline">
+ <div class="smallFont">l</div>
+ <div class="medFont">m</div>
+ </div>
+ </div>
+ n
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-002.html
new file mode 100644
index 00000000000..e73e00c1d72
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-002.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!-- Testcase for how we compute the baseline of a horizontal flex container
+ with several flex lines (wrapping in the reverse direction).
+ The spec says this about this case:
+ [Given that the first line has no baseline-aligned items:]
+ ...if the flex container has at least one flex item, and its
+ first flex item has a baseline parallel to the flex
+ container's main axis, the flex container's main-axis
+ baseline is that baseline.
+-->
+<html>
+<head>
+ <title>CSS Test: Testing the baseline of a horizontal flex container with multiple flex lines</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <link rel="help" href="http://www.w3.org/TR/css-flexbox-1/#flex-baselines">
+ <link rel="match" href="../../../../expected/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-002-ref.html">
+ <meta charset="utf-8">
+ <style>
+ .flexContainer {
+ display: inline-flex;
+ flex-wrap: wrap-reverse;
+ width: 40px;
+ height: 40px;
+ background: lightblue;
+ }
+ .flexContainer > * {
+ width: 20px;
+ }
+
+ /* We'll make the second flex line not paint anything, so that the
+ reference case doesn't need to bother matching it. */
+ .flexContainer > *:nth-child(1),
+ .flexContainer > *:nth-child(2) {
+ visibility: hidden;
+ }
+
+ .smallFont {
+ font-size: 8px;
+ line-height: 8px;
+ }
+ .medFont {
+ font-size: 12px;
+ line-height: 12px;
+ }
+ .bigFont {
+ font-size: 16px;
+ line-height: 16px;
+ }
+ </style>
+</head>
+<body>
+ a
+ <!-- Flex containers with flex items that have a mix of baselines: -->
+ <div class="flexContainer">
+ <div class="medFont">b</div
+ ><div class="bigFont">c</div
+ ><div class="bigFont">d</div
+ ><div class="medFont">e</div>
+ </div>
+
+ <div class="flexContainer">
+ <div class="bigFont">f</div
+ ><div class="smallFont">g</div
+ ><div class="bigFont">h</div
+ ><div class="medFont">i</div>
+ </div>
+ n
+
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-004.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-004.html
new file mode 100644
index 00000000000..f25ba404969
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-004.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+ <title>CSS Test: Testing the baseline of a horizontal multi-line (wrap-reverse) flex container with baseline-aligned items on first line</title>
+ <link rel="author" title="Daniel Holbert" href="mailto:[email protected]">
+ <link rel="help" href="http://www.w3.org/TR/css-flexbox-1/#flex-baselines">
+ <link rel="match" href="../../../../expected/wpt-import/css/css-flexbox/flexbox-baseline-multi-line-horiz-004-ref.html">
+ <meta charset="utf-8">
+ <style>
+ .flexContainer {
+ display: inline-flex;
+ flex-wrap: wrap-reverse;
+ width: 40px;
+ height: 100px;
+ background: lightgray;
+
+ /* Use "align-content", to test that packing space is considered when
+ getting container's baseline from its first FlexLine:*/
+ align-content: center;
+ }
+ .flexContainer > * {
+ width: 20px;
+ }
+
+ .smallFont {
+ font-size: 8px;
+ line-height: 8px;
+ }
+ .medFont {
+ font-size: 12px;
+ line-height: 12px;
+ }
+ .bigFont {
+ font-size: 16px;
+ line-height: 16px;
+ }
+ </style>
+</head>
+<body>
+ a
+ <!-- Flex container with second item in first line baseline-aligned
+ (should set the container's baseline) -->
+ <div class="flexContainer">
+ <div class="medFont">b</div>
+ <div class="bigFont" style="align-self: baseline">c</div>
+ <div class="medFont">d</div>
+ <div class="smallFont">e</div>
+ </div>
+
+ <!-- Flex container with both items in first line baseline-aligned
+ (should set the container's baseline) -->
+ <div class="flexContainer">
+ <div class="smallFont" style="align-self: baseline">f</div>
+ <div class="medFont" style="align-self: baseline">g</div>
+ <div class="bigFont">h</div>
+ <div class="smallFont">i</div>
+ </div>
+
+ <!-- Flex container with all items baseline-aligned, and with some padding
+ (only those on first line should set the container's baseline) -->
+ <div class="flexContainer" style="align-items: baseline">
+ <div class="bigFont">j</div>
+ <div class="smallFont" style="padding-bottom: 20px">k</div>
+ <div class="smallFont">l</div>
+ <div class="medFont">m</div>
+ </div>
+ n
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/align-self-baseline-with-flex-wrap.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/align-self-baseline-with-flex-wrap.txt
new file mode 100644
index 00000000000..61b3460de1e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/align-self-baseline-with-flex-wrap.txt
@@ -0,0 +1,22 @@
+Harness status: OK
+
+Found 16 tests
+
+4 Pass
+12 Fail
+Fail .box > span 1
+Pass .box > span 2
+Fail .box > span 3
+Fail .box > span 4
+Fail .box > span 5
+Pass .box > span 6
+Fail .box > span 7
+Fail .box > span 8
+Fail .box > span 9
+Pass .box > span 10
+Fail .box > span 11
+Fail .box > span 12
+Fail .box > span 13
+Fail .box > span 14
+Fail .box > span 15
+Pass .box > span 16
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/alignment/flex-align-baseline-flex-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/alignment/flex-align-baseline-flex-001.txt
index ce26be7b44d..6d885c4814b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/alignment/flex-align-baseline-flex-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/alignment/flex-align-baseline-flex-001.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 48 tests
-32 Pass
-16 Fail
+36 Pass
+12 Fail
Pass .target > * 1
Pass .target > * 2
Fail .target > * 3
@@ -36,19 +36,19 @@ Pass .target > * 29
Pass .target > * 30
Fail .target > * 31
Pass .target > * 32
-Fail .target > * 33
+Pass .target > * 33
Pass .target > * 34
Fail .target > * 35
Pass .target > * 36
-Fail .target > * 37
+Pass .target > * 37
Pass .target > * 38
Fail .target > * 39
Pass .target > * 40
-Fail .target > * 41
+Pass .target > * 41
Pass .target > * 42
Fail .target > * 43
Pass .target > * 44
-Fail .target > * 45
+Pass .target > * 45
Pass .target > * 46
Fail .target > * 47
Pass .target > * 48
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/alignment/flex-align-baseline-flex-003.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/alignment/flex-align-baseline-flex-003.txt
index e91c059113f..b95021664a0 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/alignment/flex-align-baseline-flex-003.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/alignment/flex-align-baseline-flex-003.txt
@@ -2,13 +2,13 @@ Harness status: OK
Found 16 tests
-9 Pass
-7 Fail
+10 Pass
+6 Fail
Pass .target > * 1
Pass .target > * 2
Fail .target > * 3
Pass .target > * 4
-Fail .target > * 5
+Pass .target > * 5
Pass .target > * 6
Fail .target > * 7
Pass .target > * 8
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox-baseline-wrap-reverse-unequal-lines.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox-baseline-wrap-reverse-unequal-lines.txt
new file mode 100644
index 00000000000..98b59301a1f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-flexbox/flexbox-baseline-wrap-reverse-unequal-lines.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass A wrap-reverse flex container takes its first baseline from the visually-first flex line
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-align-baseline-flex-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-align-baseline-flex-001.txt
index ce26be7b44d..6d885c4814b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-align-baseline-flex-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-align-baseline-flex-001.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 48 tests
-32 Pass
-16 Fail
+36 Pass
+12 Fail
Pass .target > * 1
Pass .target > * 2
Fail .target > * 3
@@ -36,19 +36,19 @@ Pass .target > * 29
Pass .target > * 30
Fail .target > * 31
Pass .target > * 32
-Fail .target > * 33
+Pass .target > * 33
Pass .target > * 34
Fail .target > * 35
Pass .target > * 36
-Fail .target > * 37
+Pass .target > * 37
Pass .target > * 38
Fail .target > * 39
Pass .target > * 40
-Fail .target > * 41
+Pass .target > * 41
Pass .target > * 42
Fail .target > * 43
Pass .target > * 44
-Fail .target > * 45
+Pass .target > * 45
Pass .target > * 46
Fail .target > * 47
Pass .target > * 48
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-align-baseline-flex-003.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-align-baseline-flex-003.txt
index e91c059113f..b95021664a0 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-align-baseline-flex-003.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/alignment/grid-align-baseline-flex-003.txt
@@ -2,13 +2,13 @@ Harness status: OK
Found 16 tests
-9 Pass
-7 Fail
+10 Pass
+6 Fail
Pass .target > * 1
Pass .target > * 2
Fail .target > * 3
Pass .target > * 4
-Fail .target > * 5
+Pass .target > * 5
Pass .target > * 6
Fail .target > * 7
Pass .target > * 8
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-flexbox/align-self-baseline-with-flex-wrap.html b/Tests/LibWeb/Text/input/wpt-import/css/css-flexbox/align-self-baseline-with-flex-wrap.html
new file mode 100644
index 00000000000..b2ceff7d166
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-flexbox/align-self-baseline-with-flex-wrap.html
@@ -0,0 +1,145 @@
+<!DOCTYPE html>
+<head>
+ <link rel="help" href="https://drafts.csswg.org/css-align-3/#synthesize-baseline">
+ <link rel="help" href="https://drafts.csswg.org/css-writing-modes-4/#logical-to-physical">
+ <link rel="author" href="mailto:[email protected]" title="Simon Wülker">
+ <script src="../../resources/testharness.js"></script>
+ <script src="../../resources/testharnessreport.js"></script>
+ <script src="../../resources/check-layout-th.js"></script>
+ <style>
+ .box {
+ display: flex;
+ outline: 1px solid;
+ position: relative;
+ }
+
+ .row {
+ width: 20px;
+ height: 50px;
+ flex-direction: row;
+
+ .big {
+ width: 10px;
+ height: 30px;
+ margin-top: 2px;
+ margin-bottom: 5px;
+ }
+ }
+
+ .column {
+ flex-direction: column;
+ width: 50px;
+ height: 20px;
+
+ .big {
+ width: 30px;
+ height: 10px;
+ margin-left: 2px;
+ margin-right: 5px;
+ }
+ }
+
+ .reverse {
+ flex-wrap: wrap-reverse;
+ }
+
+ .box span {
+ outline: 1px solid;
+ align-self: baseline;
+ }
+
+ .rtl {
+ direction: rtl;
+ }
+
+ .small {
+ width: 10px;
+ height: 10px;
+ background-color: blue;
+ }
+
+ .big {
+ background-color: blueviolet;
+ }
+
+ th, td {
+ border: 1px solid black;
+ padding: 5px;
+ text-align: center;
+ vertical-align: middle;
+ }
+ div {
+ margin-inline: auto;
+ }
+ </style>
+</head>
+<body onload="checkLayout('.box > span')">
+ <table>
+ <thead>
+ <tr>
+ <th></th>
+ <th><pre>flex-direction: row</pre></th>
+ <th><pre>flex-direction: row-reverse</pre></th>
+ <th><pre>flex-direction: column</pre></th>
+ <th><pre>flex-direction: column-reverse</pre></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <th><pre>direction=ltr</pre></th>
+ <td>
+ <div class="box row">
+ <span class="small" data-offset-x="0" data-offset-y="22"></span>
+ <span class="big" data-offset-x="10" data-offset-y="2"></span>
+ </div>
+ </td>
+ <td>
+ <div class="box row reverse">
+ <span class="small" data-offset-x="0" data-offset-y="35"></span>
+ <span class="big" data-offset-x="10" data-offset-y="15"></span>
+ </div>
+ </td>
+ <td>
+ <div class="box column">
+ <span class="small" data-offset-x="2" data-offset-y="0"></span>
+ <span class="big" data-offset-x="2" data-offset-y="10"></span>
+ </div>
+ </td>
+ <td>
+ <div class="box column reverse">
+ <span class="small" data-offset-x="15" data-offset-y="0"></span>
+ <span class="big" data-offset-x="15" data-offset-y="10"></span>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <th>
+ <pre>direction=rtl</pre>
+ </th>
+ <td>
+ <div class="box rtl row">
+ <span class="small" data-offset-x="10" data-offset-y="22"></span>
+ <span class="big" data-offset-x="0" data-offset-y="2"></span>
+ </div>
+ </td>
+ <td>
+ <div class="box rtl row reverse">
+ <span class="small" data-offset-x="10" data-offset-y="35"></span>
+ <span class="big" data-offset-x="0" data-offset-y="15"></span>
+ </div>
+ </td>
+ <td>
+ <div class="box rtl column">
+ <span class="small" data-offset-x="15" data-offset-y="0"></span>
+ <span class="big" data-offset-x="15" data-offset-y="10"></span>
+ </div>
+ </td>
+ <td>
+ <div class="box rtl column reverse">
+ <span class="small" data-offset-x="2" data-offset-y="0"></span>
+ <span class="big" data-offset-x="2" data-offset-y="10"></span>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-flexbox/flexbox-baseline-wrap-reverse-unequal-lines.html b/Tests/LibWeb/Text/input/wpt-import/css/css-flexbox/flexbox-baseline-wrap-reverse-unequal-lines.html
new file mode 100644
index 00000000000..d54e463ff29
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-flexbox/flexbox-baseline-wrap-reverse-unequal-lines.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Flexbox: first baseline of a wrap-reverse container whose flex lines hold different numbers of items</title>
+<link rel="help" href="https://drafts.csswg.org/css-flexbox/#flex-baselines">
+<meta name="assert" content="A flex container's first baseline set comes from one flex line: the visually-first one, which flex-wrap: wrap-reverse makes the last line in item order. When the lines hold different numbers of items, using the other line's item count selects a range that straddles both lines and the baseline lands on the wrong one.">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<style>
+#line { font: 20px/1 monospace; }
+#probe { display: inline-block; width: 0; height: 0; vertical-align: baseline; }
+#flexbox {
+ display: inline-flex;
+ flex-wrap: wrap-reverse;
+ align-items: flex-start;
+ width: 150px;
+ row-gap: 10px;
+}
+#flexbox > div { width: 50px; height: 20px; }
+#flexbox > .tall { height: 60px; }
+</style>
+<div id="line"><span id="probe"></span><div id="flexbox">
+ <div id="firstInOrder"></div><div></div><div></div><div class="tall"></div><div class="tall"></div>
+</div></div>
+<script>
+test(() => {
+ var baselineY = document.getElementById("probe").getBoundingClientRect().top;
+ var otherLineTop = document.getElementById("firstInOrder").getBoundingClientRect().top;
+ assert_less_than(baselineY, otherLineTop,
+ "first baseline should come from the visually-first flex line, not the line below it");
+}, "A wrap-reverse flex container takes its first baseline from the visually-first flex line");
+</script>