Skip to content

The headless browser for AI agents and web scraping

test: gate absolute static position

SGavrl20d31938a13c
diff --git a/crates/obscura-render/tests/layout_test.rs b/crates/obscura-render/tests/layout_test.rs
index ec85ca71..a0061aab 100644
--- a/crates/obscura-render/tests/layout_test.rs
+++ b/crates/obscura-render/tests/layout_test.rs
@@ -162,6 +162,36 @@ fn inset_absolute_uses_nearest_positioned_ancestor() {
assert!((fixed.y - 40.0).abs() < 1.0, "fixed box did not use viewport y: {fixed:?}");
}
+#[test]
+fn absolute_auto_axes_preserve_static_position_after_reparenting() {
+ let tree = parse_html(include_str!("../../../render-repros/absolute-static-position.html"));
+ let layout = layout_dom(&tree, (900.0, 1000.0));
+ let rect = |id| layout.rects[&tree.get_element_by_id(id).unwrap()];
+ let static_inline = rect("top-static-inline");
+ let static_block = rect("left-static-block");
+ let outer_static = rect("outer-static");
+ let nested_static = rect("nested-static");
+ assert!(
+ (static_inline.x - 125.0).abs() < 0.01
+ && (static_inline.y - 60.0).abs() < 0.01,
+ "static inline axis: {static_inline:?}"
+ );
+ assert!(
+ (static_block.x - 210.0).abs() < 0.01
+ && (static_block.y - 97.0).abs() < 0.01,
+ "static block axis: {static_block:?}"
+ );
+ assert!(
+ (outer_static.x - 84.0).abs() < 0.01 && (outer_static.y - 390.0).abs() < 0.01,
+ "outer static candidate: {outer_static:?}"
+ );
+ assert!(
+ (nested_static.x - 154.0).abs() < 0.01
+ && (nested_static.y - 413.0).abs() < 0.01,
+ "nested static candidate: {nested_static:?}"
+ );
+}
+
#[test]
fn transforms_establish_absolute_and_fixed_containing_blocks() {
let html = r##"
diff --git a/render-repros/absolute-static-position.html b/render-repros/absolute-static-position.html
new file mode 100644
index 00000000..005ff255
--- /dev/null
+++ b/render-repros/absolute-static-position.html
@@ -0,0 +1,112 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>absolute auto axes preserve static position</title>
+ <style>
+ html, body { margin: 0; }
+ #cb {
+ position: relative;
+ width: 400px;
+ height: 300px;
+ box-sizing: border-box;
+ border: 10px solid #f08c00;
+ background: #ffd43b;
+ }
+ #spacer {
+ width: 1px;
+ height: 80px;
+ }
+ #flow {
+ width: 200px;
+ height: 120px;
+ margin-left: 80px;
+ padding-left: 30px;
+ background: #d0ebff;
+ }
+ #top-static-inline {
+ position: absolute;
+ top: 50px;
+ margin-left: 5px;
+ width: 40px;
+ height: 30px;
+ background: #087f5b;
+ }
+ #left-static-block {
+ position: absolute;
+ left: 200px;
+ margin-top: 7px;
+ width: 50px;
+ height: 20px;
+ background: #1971c2;
+ }
+ #nested-cb {
+ position: relative;
+ width: 400px;
+ height: 300px;
+ margin-top: 40px;
+ box-sizing: border-box;
+ border: 10px solid #e8590c;
+ background: #ffe8cc;
+ }
+ #nested-spacer {
+ width: 1px;
+ height: 60px;
+ }
+ #outer-flow {
+ width: 220px;
+ height: 140px;
+ margin-left: 50px;
+ padding-left: 20px;
+ background: #e5dbff;
+ }
+ #outer-static {
+ position: absolute;
+ top: 40px;
+ margin-left: 4px;
+ width: 160px;
+ height: 100px;
+ background: #862e9c;
+ }
+ #inner-spacer {
+ width: 1px;
+ height: 20px;
+ }
+ #inner-flow {
+ width: 100px;
+ height: 50px;
+ margin-left: 30px;
+ padding-left: 10px;
+ background: #f3d9fa;
+ }
+ #nested-static {
+ position: absolute;
+ left: 70px;
+ margin-top: 3px;
+ width: 20px;
+ height: 20px;
+ background: #0b7285;
+ }
+ </style>
+</head>
+<body>
+ <div id="cb">
+ <div id="spacer"></div>
+ <div id="flow">
+ <div id="top-static-inline"></div>
+ <div id="left-static-block"></div>
+ </div>
+ </div>
+ <div id="nested-cb">
+ <div id="nested-spacer"></div>
+ <div id="outer-flow">
+ <div id="outer-static">
+ <div id="inner-spacer"></div>
+ <div id="inner-flow">
+ <div id="nested-static"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/render-repros/checks.json b/render-repros/checks.json
index 750209fe..b8b4c3ba 100644
--- a/render-repros/checks.json
+++ b/render-repros/checks.json
@@ -10,6 +10,12 @@
{"name": "percent insets use padding box", "color": "#f08c00", "x": 260, "y": 160, "width": 30, "height": 30},
{"name": "fixed viewport containing block", "color": "#a61e4d", "x": 520, "y": 40, "width": 90, "height": 55}
],
+ "absolute-static-position": [
+ {"name": "absolute top uses real containing block and keeps static inline position", "color": "#087f5b", "x": 125, "y": 60, "width": 40, "height": 30},
+ {"name": "absolute left uses real containing block and keeps static block position", "color": "#1971c2", "x": 210, "y": 97, "width": 50, "height": 20},
+ {"name": "outer static candidate is reparented after coordinate harvest", "color": "#862e9c", "x": 84, "y": 390, "width": 160, "height": 100},
+ {"name": "nested static candidate survives outer reparenting", "color": "#0b7285", "x": 154, "y": 413, "width": 20, "height": 20}
+ ],
"block-auto-margins": [
{"name": "two auto margins center a fixed-width block", "color": "#087f5b", "x": 300, "y": 20, "width": 300, "height": 40},
{"name": "two auto margins center a max-width block", "color": "#1971c2", "x": 200, "y": 100, "width": 500, "height": 40},