Skip to content

The headless browser for AI agents and web scraping

test: gate flex text alignment geometry

SGavrl5b602259c60e
diff --git a/crates/obscura-render/tests/layout_test.rs b/crates/obscura-render/tests/layout_test.rs
index 25967f40..93281b1d 100644
--- a/crates/obscura-render/tests/layout_test.rs
+++ b/crates/obscura-render/tests/layout_test.rs
@@ -426,6 +426,30 @@ fn auto_block_wrapper_contains_percentage_replaced_child() {
);
}
+#[test]
+fn text_alignment_does_not_shrink_flex_items() {
+ let tree = parse_html(include_str!("../../../render-repros/text-align-flex-items.html"));
+ let layout = layout_dom(&tree, (900.0, 1000.0));
+ let rect = |id| layout.rects[&tree.get_element_by_id(id).unwrap()];
+ let stack = rect("stack");
+ let media = rect("media");
+ let label = rect("label");
+ let chip = rect("chip");
+ assert!(
+ (stack.width - 400.0).abs() < 0.01
+ && (media.x - 20.0).abs() < 0.01
+ && (media.width - 360.0).abs() < 0.01,
+ "stack: {stack:?}, media: {media:?}"
+ );
+ assert!(
+ (label.x - 20.0).abs() < 0.01
+ && (label.width - 360.0).abs() < 0.01
+ && (chip.x - 150.0).abs() < 0.01
+ && (chip.width - 100.0).abs() < 0.01,
+ "label: {label:?}, chip: {chip:?}"
+ );
+}
+
#[test]
fn opposing_floats_share_header_band_through_inline_wrapper() {
let tree = parse_html(include_str!("../../../render-repros/opposing-header-floats.html"));
diff --git a/render-repros/checks.json b/render-repros/checks.json
index 2cee9a87..d521fd45 100644
--- a/render-repros/checks.json
+++ b/render-repros/checks.json
@@ -118,6 +118,10 @@
"tables": [
{"name": "content-box fixed cell column", "color": "#ffcc99", "width": 208}
],
+ "text-align-flex-items": [
+ {"name": "text alignment does not shrink a flex item", "color": "#087f5b", "x": 20, "y": 20, "width": 360, "height": 80},
+ {"name": "inherited text alignment centers inline content", "color": "#c2255c", "x": 150, "y": 100, "width": 100, "height": 20}
+ ],
"transform-containing-block": [
{"name": "absolute captured by transform", "color": "#087f5b", "x": 205, "y": 160, "width": 70, "height": 55},
{"name": "fixed captured by transform", "color": "#1971c2", "x": 335, "y": 235, "width": 80, "height": 50},
diff --git a/render-repros/text-align-flex-items.html b/render-repros/text-align-flex-items.html
new file mode 100644
index 00000000..b7d2cef8
--- /dev/null
+++ b/render-repros/text-align-flex-items.html
@@ -0,0 +1,41 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>text alignment does not align flex items</title>
+ <style>
+ html, body { margin: 0; }
+ #stack {
+ display: flex;
+ flex-direction: column;
+ box-sizing: border-box;
+ width: 400px;
+ padding: 20px;
+ text-align: center;
+ background: #f08c00;
+ }
+ #media {
+ width: auto;
+ height: 80px;
+ background: #087f5b;
+ }
+ #label {
+ width: auto;
+ height: 60px;
+ background: #1971c2;
+ }
+ #chip {
+ display: inline-block;
+ width: 100px;
+ height: 20px;
+ background: #c2255c;
+ }
+ </style>
+</head>
+<body>
+ <div id="stack">
+ <div id="media"></div>
+ <div id="label"><span id="chip"></span></div>
+ </div>
+</body>
+</html>