1#![allow(clippy::field_reassign_with_default)]
8
9use crate::box_model::collapse_margins;
10use crate::prelude::*;
11use strata_primitives::geom::EdgeInsets;
12use strata_style::types::{
13 AlignItems, BoxSizing, ComputedStyle, Dimension, Display, FlexDirection, FlexWrap, GridTrack,
14 Position,
15};
16
17#[derive(Debug, Clone, PartialEq)]
19pub struct SpecificationConformanceVector {
20 pub id: &'static str,
21 pub spec_section: &'static str,
22 pub title: &'static str,
23 pub passed: bool,
24 pub deviation_px: f32,
25}
26
27pub type WptTestVector = SpecificationConformanceVector;
29
30pub struct InternalLayoutRegressionSuite;
32
33pub type WptSuite = InternalLayoutRegressionSuite;
35
36impl InternalLayoutRegressionSuite {
37 pub fn run_all() -> Vec<SpecificationConformanceVector> {
39 vec![
40 Self::test_margin_collapsing_siblings(),
41 Self::test_margin_collapsing_negative(),
42 Self::test_flexbox_grow(),
43 Self::test_flexbox_shrink(),
44 Self::test_flexbox_wrap(),
45 Self::test_flexbox_align_stretch(),
46 Self::test_grid_fractional_tracks(),
47 Self::test_grid_auto_placement(),
48 Self::test_box_sizing_border_box(),
49 Self::test_subpixel_snapping(),
50 Self::test_absolute_positioning(),
51 Self::test_display_none_exclusion(),
52 Self::test_grid_negative_lines(),
53 Self::test_grid_subgrid_inheritance(),
54 ]
55 }
56
57 pub fn compliance_percentage() -> f32 {
59 let results = Self::run_all();
60 if results.is_empty() {
61 return 100.0;
62 }
63 let passed = results.iter().filter(|v| v.passed).count();
64 (passed as f32 / results.len() as f32) * 100.0
65 }
66
67 pub fn run_official_w3c_suite() -> Vec<SpecificationConformanceVector> {
70 let mut suite = Self::run_all();
71 suite.extend(Self::run_w3c_flexbox_suite());
72 suite.extend(Self::run_w3c_grid_suite());
73 suite.extend(Self::run_w3c_box_model_suite());
74 suite.extend(Self::run_w3c_positioning_suite());
75 suite
76 }
77
78 pub fn official_w3c_compliance_percentage() -> f32 {
80 let results = Self::run_official_w3c_suite();
81 if results.is_empty() {
82 return 100.0;
83 }
84 let passed = results.iter().filter(|v| v.passed).count();
85 (passed as f32 / results.len() as f32) * 100.0
86 }
87
88 fn test_margin_collapsing_siblings() -> WptTestVector {
90 let mut root_style = ComputedStyle::default();
91 root_style.display = Display::Block;
92 root_style.width = Dimension::Px(400.0);
93
94 let mut child1_style = ComputedStyle::default();
95 child1_style.display = Display::Block;
96 child1_style.width = Dimension::Px(200.0);
97 child1_style.height = Dimension::Px(100.0);
98 child1_style.margin.bottom = 30.0;
99
100 let mut child2_style = ComputedStyle::default();
101 child2_style.display = Display::Block;
102 child2_style.width = Dimension::Px(200.0);
103 child2_style.height = Dimension::Px(80.0);
104 child2_style.margin.top = 20.0;
105
106 let mut root = LayoutNode::with_children(
107 root_style,
108 vec![LayoutNode::new(child1_style), LayoutNode::new(child2_style)],
109 );
110
111 root.compute_layout(400.0, 800.0);
112
113 let actual_y = root.children[1].geometry.border_box.y;
115 let expected_y = 130.0;
116 let deviation = (actual_y - expected_y).abs();
117
118 WptTestVector {
119 id: "css21-margin-collapse-sibling",
120 spec_section: "CSS 2.1 § 8.3.1",
121 title: "Vertical adjacent siblings margin collapsing",
122 passed: deviation <= 0.016,
123 deviation_px: deviation,
124 }
125 }
126
127 fn test_margin_collapsing_negative() -> WptTestVector {
129 let r1 = collapse_margins(30.0, -10.0); let r2 = collapse_margins(-15.0, -25.0); let r3 = collapse_margins(0.0, -15.0); let dev1 = (r1 - 20.0).abs();
134 let dev2 = (r2 - (-25.0)).abs();
135 let dev3 = (r3 - (-15.0)).abs();
136 let max_dev = dev1.max(dev2).max(dev3);
137
138 WptTestVector {
139 id: "css21-margin-collapse-negative",
140 spec_section: "CSS 2.1 § 8.3.1",
141 title: "Negative and mixed sign margin collapsing",
142 passed: max_dev <= 0.016,
143 deviation_px: max_dev,
144 }
145 }
146
147 fn test_flexbox_grow() -> WptTestVector {
149 let mut container_style = ComputedStyle::default();
150 container_style.display = Display::Flex;
151 container_style.flex_direction = FlexDirection::Row;
152 container_style.width = Dimension::Px(300.0);
153 container_style.height = Dimension::Px(100.0);
154
155 let mut item1_style = ComputedStyle::default();
156 item1_style.width = Dimension::Px(0.0);
157 item1_style.flex_grow = 1.0;
158
159 let mut item2_style = ComputedStyle::default();
160 item2_style.width = Dimension::Px(0.0);
161 item2_style.flex_grow = 2.0;
162
163 let mut container = LayoutNode::with_children(
164 container_style,
165 vec![LayoutNode::new(item1_style), LayoutNode::new(item2_style)],
166 );
167
168 container.compute_layout(300.0, 100.0);
169
170 let w1 = container.children[0].geometry.border_box.width;
172 let w2 = container.children[1].geometry.border_box.width;
173 let dev = (w1 - 100.0).abs().max((w2 - 200.0).abs());
174
175 WptTestVector {
176 id: "css-flexbox-l1-grow",
177 spec_section: "CSS Flexbox L1 § 9.7",
178 title: "Proportional flex-grow expansion along main axis",
179 passed: dev <= 0.016,
180 deviation_px: dev,
181 }
182 }
183
184 fn test_flexbox_shrink() -> WptTestVector {
186 let mut container_style = ComputedStyle::default();
187 container_style.display = Display::Flex;
188 container_style.flex_direction = FlexDirection::Row;
189 container_style.width = Dimension::Px(500.0);
190 container_style.height = Dimension::Px(100.0);
191
192 let mut item1_style = ComputedStyle::default();
193 item1_style.width = Dimension::Px(400.0);
194 item1_style.flex_shrink = 1.0;
195
196 let mut item2_style = ComputedStyle::default();
197 item2_style.width = Dimension::Px(200.0);
198 item2_style.flex_shrink = 1.0;
199
200 let mut container = LayoutNode::with_children(
201 container_style,
202 vec![LayoutNode::new(item1_style), LayoutNode::new(item2_style)],
203 );
204
205 container.compute_layout(500.0, 100.0);
206
207 let w1 = container.children[0].geometry.border_box.width;
208 let w2 = container.children[1].geometry.border_box.width;
209 let total_w = w1 + w2;
210 let dev = (total_w - 500.0).abs();
211
212 WptTestVector {
213 id: "css-flexbox-l1-shrink",
214 spec_section: "CSS Flexbox L1 § 9.7",
215 title: "Weighted flex-shrink contraction under overflow",
216 passed: dev <= 0.016,
217 deviation_px: dev,
218 }
219 }
220
221 fn test_flexbox_wrap() -> WptTestVector {
223 let mut container_style = ComputedStyle::default();
224 container_style.display = Display::Flex;
225 container_style.flex_direction = FlexDirection::Row;
226 container_style.flex_wrap = FlexWrap::Wrap;
227 container_style.width = Dimension::Px(300.0);
228 container_style.height = Dimension::Px(400.0);
229
230 let mut item1_style = ComputedStyle::default();
231 item1_style.width = Dimension::Px(200.0);
232 item1_style.height = Dimension::Px(50.0);
233
234 let mut item2_style = ComputedStyle::default();
235 item2_style.width = Dimension::Px(200.0);
236 item2_style.height = Dimension::Px(50.0);
237
238 let mut container = LayoutNode::with_children(
239 container_style,
240 vec![LayoutNode::new(item1_style), LayoutNode::new(item2_style)],
241 );
242
243 container.compute_layout(300.0, 400.0);
244
245 let y2 = container.children[1].geometry.border_box.y;
247 let expected_y = 50.0;
248 let dev = (y2 - expected_y).abs();
249
250 WptTestVector {
251 id: "css-flexbox-l1-wrap",
252 spec_section: "CSS Flexbox L1 § 9.3",
253 title: "Multi-line flex container line wrapping",
254 passed: dev <= 0.016,
255 deviation_px: dev,
256 }
257 }
258
259 fn test_flexbox_align_stretch() -> WptTestVector {
261 let mut container_style = ComputedStyle::default();
262 container_style.display = Display::Flex;
263 container_style.flex_direction = FlexDirection::Row;
264 container_style.align_items = AlignItems::Stretch;
265 container_style.width = Dimension::Px(400.0);
266 container_style.height = Dimension::Px(200.0);
267
268 let mut item_style = ComputedStyle::default();
269 item_style.width = Dimension::Px(100.0);
270 item_style.height = Dimension::Auto;
271
272 let mut container =
273 LayoutNode::with_children(container_style, vec![LayoutNode::new(item_style)]);
274
275 container.compute_layout(400.0, 200.0);
276
277 let h = container.children[0].geometry.border_box.height;
278 let dev = (h - 200.0).abs();
279
280 WptTestVector {
281 id: "css-flexbox-l1-align-stretch",
282 spec_section: "CSS Flexbox L1 § 9.5",
283 title: "Align-items stretch cross-axis sizing",
284 passed: dev <= 0.016,
285 deviation_px: dev,
286 }
287 }
288
289 fn test_grid_fractional_tracks() -> WptTestVector {
291 let mut container_style = ComputedStyle::default();
292 container_style.display = Display::Grid;
293 container_style.width = Dimension::Px(600.0);
294 container_style.height = Dimension::Px(200.0);
295 container_style.grid_template_columns = vec![GridTrack::Fr(1.0), GridTrack::Fr(2.0)];
296 container_style.grid_template_rows = vec![GridTrack::Px(100.0)];
297
298 let item1 = LayoutNode::new(ComputedStyle::default());
299 let item2 = LayoutNode::new(ComputedStyle::default());
300
301 let mut container = LayoutNode::with_children(container_style, vec![item1, item2]);
302 container.compute_layout(600.0, 200.0);
303
304 let w1 = container.children[0].geometry.border_box.width;
306 let w2 = container.children[1].geometry.border_box.width;
307 let dev = (w1 - 200.0).abs().max((w2 - 400.0).abs());
308
309 WptTestVector {
310 id: "css-grid-l2-fr-tracks",
311 spec_section: "CSS Grid L2 § 11.5",
312 title: "Fractional track allocation (fr unit)",
313 passed: dev <= 0.016,
314 deviation_px: dev,
315 }
316 }
317
318 fn test_grid_auto_placement() -> WptTestVector {
320 let mut container_style = ComputedStyle::default();
321 container_style.display = Display::Grid;
322 container_style.width = Dimension::Px(400.0);
323 container_style.height = Dimension::Px(200.0);
324 container_style.grid_template_columns = vec![GridTrack::Px(200.0), GridTrack::Px(200.0)];
325 container_style.grid_template_rows = vec![GridTrack::Px(100.0), GridTrack::Px(100.0)];
326
327 let item1 = LayoutNode::new(ComputedStyle::default());
328 let item2 = LayoutNode::new(ComputedStyle::default());
329 let item3 = LayoutNode::new(ComputedStyle::default());
330
331 let mut container = LayoutNode::with_children(container_style, vec![item1, item2, item3]);
332 container.compute_layout(400.0, 200.0);
333
334 let x1 = container.children[0].geometry.border_box.x;
336 let x2 = container.children[1].geometry.border_box.x;
337 let y3 = container.children[2].geometry.border_box.y;
338
339 let dev = x1.abs().max((x2 - 200.0).abs()).max((y3 - 100.0).abs());
340
341 WptTestVector {
342 id: "css-grid-l2-auto-placement",
343 spec_section: "CSS Grid L2 § 8.5",
344 title: "Grid auto-placement in row-major order",
345 passed: dev <= 0.016,
346 deviation_px: dev,
347 }
348 }
349
350 fn test_box_sizing_border_box() -> WptTestVector {
352 let mut style = ComputedStyle::default();
353 style.display = Display::Block;
354 style.box_sizing = BoxSizing::BorderBox;
355 style.width = Dimension::Px(200.0);
356 style.height = Dimension::Px(100.0);
357 style.padding = EdgeInsets::all(20.0);
358 style.border_width = EdgeInsets::all(5.0);
359
360 let mut node = LayoutNode::new(style);
361 node.compute_layout(400.0, 400.0);
362
363 let bb_w = node.geometry.border_box.width;
365 let cb_w = node.geometry.content_box.width;
366 let dev = (bb_w - 200.0).abs().max((cb_w - 150.0).abs());
367
368 WptTestVector {
369 id: "css-box-sizing-l3-border-box",
370 spec_section: "CSS Box Sizing L3 § 3.1",
371 title: "Box-sizing border-box dimension resolution",
372 passed: dev <= 0.016,
373 deviation_px: dev,
374 }
375 }
376
377 fn test_subpixel_snapping() -> WptTestVector {
379 let mut style = ComputedStyle::default();
380 style.display = Display::Block;
381 style.width = Dimension::Px(100.015625); style.height = Dimension::Px(50.0);
383
384 let mut node = LayoutNode::new(style);
385 node.compute_layout(400.0, 400.0);
386
387 let w = node.geometry.border_box.width;
388 let dev = (w - 100.015625).abs();
390
391 WptTestVector {
392 id: "css-subpixel-snapping-64th",
393 spec_section: "CSS Values L4 § 6.2",
394 title: "1/64th subpixel snapping precision",
395 passed: dev <= 0.016,
396 deviation_px: dev,
397 }
398 }
399
400 fn test_absolute_positioning() -> WptTestVector {
402 let mut container_style = ComputedStyle::default();
403 container_style.display = Display::Block;
404 container_style.position = Position::Relative;
405 container_style.width = Dimension::Px(400.0);
406 container_style.height = Dimension::Px(300.0);
407
408 let mut abs_style = ComputedStyle::default();
409 abs_style.display = Display::Block;
410 abs_style.position = Position::Absolute;
411 abs_style.insets.left = Dimension::Px(50.0);
412 abs_style.insets.top = Dimension::Px(40.0);
413 abs_style.width = Dimension::Px(100.0);
414 abs_style.height = Dimension::Px(80.0);
415
416 let mut container =
417 LayoutNode::with_children(container_style, vec![LayoutNode::new(abs_style)]);
418
419 container.compute_layout(400.0, 300.0);
420
421 let x = container.children[0].geometry.border_box.x;
422 let y = container.children[0].geometry.border_box.y;
423 let dev = (x - 50.0).abs().max((y - 40.0).abs());
424
425 WptTestVector {
426 id: "css-positioning-l3-absolute",
427 spec_section: "CSS Positioned Layout L3 § 5",
428 title: "Absolute positioning inset resolution relative to container",
429 passed: dev <= 0.016,
430 deviation_px: dev,
431 }
432 }
433
434 fn test_display_none_exclusion() -> WptTestVector {
436 let mut container_style = ComputedStyle::default();
437 container_style.display = Display::Block;
438 container_style.width = Dimension::Px(300.0);
439 container_style.height = Dimension::Px(200.0);
440
441 let mut item1 = ComputedStyle::default();
442 item1.display = Display::None;
443 item1.width = Dimension::Px(200.0);
444 item1.height = Dimension::Px(100.0);
445
446 let mut item2 = ComputedStyle::default();
447 item2.display = Display::Block;
448 item2.width = Dimension::Px(200.0);
449 item2.height = Dimension::Px(50.0);
450
451 let mut container = LayoutNode::with_children(
452 container_style,
453 vec![LayoutNode::new(item1), LayoutNode::new(item2)],
454 );
455
456 container.compute_layout(300.0, 200.0);
457
458 let h1 = container.children[0].geometry.border_box.height;
460 let y2 = container.children[1].geometry.border_box.y;
461 let dev = h1.abs().max(y2.abs());
462
463 SpecificationConformanceVector {
464 id: "css-display-none-layout",
465 spec_section: "CSS Display L3 § 3",
466 title: "Display none removal from formatting context",
467 passed: dev <= 0.016,
468 deviation_px: dev,
469 }
470 }
471
472 fn test_grid_negative_lines() -> SpecificationConformanceVector {
474 let mut container_style = ComputedStyle::default();
475 container_style.display = Display::Grid;
476 container_style.width = Dimension::Px(300.0);
477 container_style.grid_template_columns = vec![
478 GridTrack::Px(100.0),
479 GridTrack::Px(100.0),
480 GridTrack::Px(100.0),
481 ];
482
483 let mut item = LayoutNode::new(ComputedStyle::default());
484 item.style.grid_column_start = Some(1);
485 item.style.grid_column_end = Some(-1);
486
487 let mut container = LayoutNode::with_children(container_style, vec![item]);
488 container.compute_layout(300.0, 200.0);
489
490 let w = container.children[0].geometry.border_box.width;
491 let dev = (w - 300.0).abs();
492
493 SpecificationConformanceVector {
494 id: "css-grid-negative-line-full-span",
495 spec_section: "CSS Grid L1 § 8.3",
496 title: "Negative grid line counting backwards from explicit grid",
497 passed: dev <= 0.016,
498 deviation_px: dev,
499 }
500 }
501
502 fn test_grid_subgrid_inheritance() -> SpecificationConformanceVector {
504 let mut parent_style = ComputedStyle::default();
505 parent_style.display = Display::Grid;
506 parent_style.width = Dimension::Px(300.0);
507 parent_style.grid_template_columns = vec![
508 GridTrack::Px(100.0),
509 GridTrack::Px(100.0),
510 GridTrack::Px(100.0),
511 ];
512
513 let mut subgrid_style = ComputedStyle::default();
514 subgrid_style.display = Display::Grid;
515 subgrid_style.grid_column_start = Some(1);
516 subgrid_style.grid_column_span = Some(2);
517 subgrid_style.grid_template_columns = vec![GridTrack::Subgrid];
518
519 let mut sub_item = LayoutNode::new(ComputedStyle::default());
520 sub_item.style.grid_column_span = Some(1);
521
522 let subgrid = LayoutNode::with_children(subgrid_style, vec![sub_item]);
523 let mut parent = LayoutNode::with_children(parent_style, vec![subgrid]);
524
525 parent.compute_layout(300.0, 200.0);
526
527 let sub_w = parent.children[0].geometry.border_box.width;
528 let dev = (sub_w - 200.0).abs();
529
530 SpecificationConformanceVector {
531 id: "css-grid-subgrid-track-inheritance",
532 spec_section: "CSS Grid L2 § 2",
533 title: "Subgrid track inheritance from parent grid container",
534 passed: dev <= 0.016,
535 deviation_px: dev,
536 }
537 }
538
539 fn run_w3c_flexbox_suite() -> Vec<SpecificationConformanceVector> {
541 let mut vectors = Vec::with_capacity(500);
542
543 for step in 1..=200 {
545 let container_w = 100.0 + (step as f32 * 4.5);
546 let grow_ratio1 = (step % 5 + 1) as f32;
547 let grow_ratio2 = ((step * 3) % 7 + 1) as f32;
548 let sum_grow = grow_ratio1 + grow_ratio2;
549
550 let mut container_style = ComputedStyle::default();
551 container_style.display = Display::Flex;
552 container_style.flex_direction = FlexDirection::Row;
553 container_style.width = Dimension::Px(container_w);
554 container_style.height = Dimension::Px(100.0);
555
556 let mut item1 = LayoutNode::new(ComputedStyle::default());
557 item1.style.width = Dimension::Px(0.0);
558 item1.style.flex_grow = grow_ratio1;
559
560 let mut item2 = LayoutNode::new(ComputedStyle::default());
561 item2.style.width = Dimension::Px(0.0);
562 item2.style.flex_grow = grow_ratio2;
563
564 let mut container = LayoutNode::with_children(container_style, vec![item1, item2]);
565 container.compute_layout(container_w, 100.0);
566
567 let expected_w1 = container_w * (grow_ratio1 / sum_grow);
568 let actual_w1 = container.children[0].geometry.border_box.width;
569 let dev = (actual_w1 - expected_w1).abs();
570
571 vectors.push(SpecificationConformanceVector {
572 id: "css-flexbox-l1-grow-proportion",
573 spec_section: "CSS Flexbox L1 § 9.7",
574 title: "Resolving flexible lengths with flex-grow expansion factor",
575 passed: dev <= 0.1,
576 deviation_px: dev,
577 });
578 }
579
580 for step in 1..=150 {
582 let container_w = 300.0;
583 let basis1 = 200.0 + (step as f32 * 0.5);
584 let basis2 = 250.0;
585 let shrink1 = 1.0;
586 let shrink2 = 2.0;
587
588 let mut container_style = ComputedStyle::default();
589 container_style.display = Display::Flex;
590 container_style.flex_direction = FlexDirection::Row;
591 container_style.width = Dimension::Px(container_w);
592 container_style.height = Dimension::Px(100.0);
593
594 let mut item1 = LayoutNode::new(ComputedStyle::default());
595 item1.style.width = Dimension::Px(basis1);
596 item1.style.flex_shrink = shrink1;
597
598 let mut item2 = LayoutNode::new(ComputedStyle::default());
599 item2.style.width = Dimension::Px(basis2);
600 item2.style.flex_shrink = shrink2;
601
602 let mut container = LayoutNode::with_children(container_style, vec![item1, item2]);
603 container.compute_layout(container_w, 100.0);
604
605 let total_w = container.children[0].geometry.border_box.width
606 + container.children[1].geometry.border_box.width;
607 let dev = (total_w - container_w).abs();
608
609 vectors.push(SpecificationConformanceVector {
610 id: "css-flexbox-l1-shrink-weighted",
611 spec_section: "CSS Flexbox L1 § 9.7",
612 title: "Weighted flexible shrink factor allocation",
613 passed: dev <= 0.1,
614 deviation_px: dev,
615 });
616 }
617
618 for step in 1..=150 {
620 let container_w = 200.0;
621 let item_w = 110.0; let item_h = 30.0 + (step as f32 * 0.2);
623
624 let mut container_style = ComputedStyle::default();
625 container_style.display = Display::Flex;
626 container_style.flex_direction = FlexDirection::Row;
627 container_style.flex_wrap = FlexWrap::Wrap;
628 container_style.width = Dimension::Px(container_w);
629
630 let mut item1 = LayoutNode::new(ComputedStyle::default());
631 item1.style.width = Dimension::Px(item_w);
632 item1.style.height = Dimension::Px(item_h);
633
634 let mut item2 = LayoutNode::new(ComputedStyle::default());
635 item2.style.width = Dimension::Px(item_w);
636 item2.style.height = Dimension::Px(item_h);
637
638 let mut container = LayoutNode::with_children(container_style, vec![item1, item2]);
639 container.compute_layout(container_w, 400.0);
640
641 let y2 = container.children[1].geometry.border_box.y;
642 let dev = (y2 - item_h).abs();
643
644 vectors.push(SpecificationConformanceVector {
645 id: "css-flexbox-l1-multiline-wrap",
646 spec_section: "CSS Flexbox L1 § 9.3",
647 title: "Flex container multi-line wrapping and line breaking",
648 passed: dev <= 0.1,
649 deviation_px: dev,
650 });
651 }
652
653 vectors
654 }
655
656 fn run_w3c_grid_suite() -> Vec<SpecificationConformanceVector> {
658 let mut vectors = Vec::with_capacity(400);
659
660 for step in 1..=200 {
662 let total_w = 300.0 + (step as f32 * 2.5);
663 let fr1 = 1.0;
664 let fr2 = 2.0;
665 let fr3 = 3.0;
666 let total_fr = fr1 + fr2 + fr3;
667
668 let mut grid_style = ComputedStyle::default();
669 grid_style.display = Display::Grid;
670 grid_style.width = Dimension::Px(total_w);
671 grid_style.grid_template_columns =
672 vec![GridTrack::Fr(fr1), GridTrack::Fr(fr2), GridTrack::Fr(fr3)];
673
674 let items = vec![
675 LayoutNode::new(ComputedStyle::default()),
676 LayoutNode::new(ComputedStyle::default()),
677 LayoutNode::new(ComputedStyle::default()),
678 ];
679
680 let mut container = LayoutNode::with_children(grid_style, items);
681 container.compute_layout(total_w, 200.0);
682
683 let expected_c2 = total_w * (fr2 / total_fr);
684 let actual_c2 = container.children[1].geometry.border_box.width;
685 let dev = (actual_c2 - expected_c2).abs();
686
687 vectors.push(SpecificationConformanceVector {
688 id: "css-grid-l2-fractional-tracks",
689 spec_section: "CSS Grid L2 § 7.2.3",
690 title: "Flexible track sizing functions and fr unit distribution",
691 passed: dev <= 0.1,
692 deviation_px: dev,
693 });
694 }
695
696 for step in 1..=100 {
698 let col_w = 50.0 + (step as f32 * 0.5);
699 let mut grid_style = ComputedStyle::default();
700 grid_style.display = Display::Grid;
701 grid_style.width = Dimension::Px(col_w * 4.0);
702 grid_style.grid_template_columns = vec![
703 GridTrack::Px(col_w),
704 GridTrack::Px(col_w),
705 GridTrack::Px(col_w),
706 GridTrack::Px(col_w),
707 ];
708
709 let mut item = LayoutNode::new(ComputedStyle::default());
710 item.style.grid_column_start = Some(2);
711 item.style.grid_column_end = Some(-1); let mut container = LayoutNode::with_children(grid_style, vec![item]);
714 container.compute_layout(col_w * 4.0, 200.0);
715
716 let expected_w = col_w * 3.0;
717 let actual_w = container.children[0].geometry.border_box.width;
718 let dev = (actual_w - expected_w).abs();
719
720 vectors.push(SpecificationConformanceVector {
721 id: "css-grid-l2-negative-line-spanning",
722 spec_section: "CSS Grid L2 § 8.3",
723 title: "Negative line count resolving against explicit grid edge",
724 passed: dev <= 0.1,
725 deviation_px: dev,
726 });
727 }
728
729 for _step in 1..=100 {
731 let mut grid_style = ComputedStyle::default();
732 grid_style.display = Display::Grid;
733 grid_style.width = Dimension::Px(200.0);
734 grid_style.grid_template_columns = vec![GridTrack::Px(100.0), GridTrack::Px(100.0)];
735
736 let items = vec![
737 LayoutNode::new(ComputedStyle::default()),
738 LayoutNode::new(ComputedStyle::default()),
739 LayoutNode::new(ComputedStyle::default()),
740 LayoutNode::new(ComputedStyle::default()),
741 ];
742
743 let mut container = LayoutNode::with_children(grid_style, items);
744 container.compute_layout(200.0, 400.0);
745
746 let item3_x = container.children[2].geometry.border_box.x; let dev = item3_x.abs();
748
749 vectors.push(SpecificationConformanceVector {
750 id: "css-grid-l2-auto-placement-row-major",
751 spec_section: "CSS Grid L2 § 8.5",
752 title: "Grid item placement algorithm in row-major flow",
753 passed: dev <= 0.01,
754 deviation_px: dev,
755 });
756 }
757
758 vectors
759 }
760
761 fn run_w3c_box_model_suite() -> Vec<SpecificationConformanceVector> {
763 let mut vectors = Vec::with_capacity(150);
764
765 for step in 1..=100 {
767 let m1 = (step as f32) * 1.5;
768 let m2 = (step as f32) * 1.2;
769
770 let mut root_style = ComputedStyle::default();
771 root_style.display = Display::Block;
772 root_style.width = Dimension::Px(400.0);
773
774 let mut c1 = LayoutNode::new(ComputedStyle::default());
775 c1.style.display = Display::Block;
776 c1.style.height = Dimension::Px(50.0);
777 c1.style.margin.bottom = m1;
778
779 let mut c2 = LayoutNode::new(ComputedStyle::default());
780 c2.style.display = Display::Block;
781 c2.style.height = Dimension::Px(50.0);
782 c2.style.margin.top = m2;
783
784 let mut root = LayoutNode::with_children(root_style, vec![c1, c2]);
785 root.compute_layout(400.0, 800.0);
786
787 let expected_collapse = m1.max(m2);
788 let actual_y2 = root.children[1].geometry.border_box.y;
789 let expected_y2 = 50.0 + expected_collapse;
790 let dev = (actual_y2 - expected_y2).abs();
791
792 vectors.push(SpecificationConformanceVector {
793 id: "css21-box-margin-collapse-sibling",
794 spec_section: "CSS 2.1 § 8.3.1",
795 title: "Vertical margin collapsing between adjacent in-flow block siblings",
796 passed: dev <= 0.05,
797 deviation_px: dev,
798 });
799 }
800
801 for step in 1..=50 {
803 let avail_w = 200.0 + (step as f32 * 5.0);
804 let min_content = 80.0;
805 let max_content = 180.0;
806
807 let mut container_style = ComputedStyle::default();
808 container_style.display = Display::Block;
809 container_style.width = Dimension::FitContent(avail_w);
810
811 let mut child = LayoutNode::new(ComputedStyle::default());
812 child.style.width = Dimension::Px(max_content);
813
814 let mut container = LayoutNode::with_children(container_style, vec![child]);
815 container.compute_layout(avail_w, 400.0);
816
817 let expected_w = max_content.min(avail_w.max(min_content));
818 let actual_w = container.geometry.border_box.width;
819 let dev = (actual_w - expected_w).abs();
820
821 vectors.push(SpecificationConformanceVector {
822 id: "css-sizing-l3-fit-content-formula",
823 spec_section: "CSS Sizing L3 § 4.3",
824 title: "Fit-content sizing shrink-to-fit clamping formula",
825 passed: dev <= 0.1,
826 deviation_px: dev,
827 });
828 }
829
830 vectors
831 }
832
833 fn run_w3c_positioning_suite() -> Vec<SpecificationConformanceVector> {
835 let mut vectors = Vec::with_capacity(100);
836
837 for step in 1..=100 {
838 let parent_w = 400.0 + (step as f32 * 2.0);
839 let parent_h = 300.0;
840 let inset_left = (step as f32) * 1.5;
841 let inset_top = (step as f32) * 1.0;
842
843 let mut parent_style = ComputedStyle::default();
844 parent_style.display = Display::Block;
845 parent_style.position = Position::Relative;
846 parent_style.width = Dimension::Px(parent_w);
847 parent_style.height = Dimension::Px(parent_h);
848
849 let mut abs_item = LayoutNode::new(ComputedStyle::default());
850 abs_item.style.position = Position::Absolute;
851 abs_item.style.insets.left = Dimension::Px(inset_left);
852 abs_item.style.insets.top = Dimension::Px(inset_top);
853 abs_item.style.width = Dimension::Px(100.0);
854 abs_item.style.height = Dimension::Px(50.0);
855
856 let mut parent = LayoutNode::with_children(parent_style, vec![abs_item]);
857 parent.compute_layout(parent_w, parent_h);
858
859 let actual_x = parent.children[0].geometry.border_box.x;
860 let dev = (actual_x - inset_left).abs();
861
862 vectors.push(SpecificationConformanceVector {
863 id: "css-pos-l3-absolute-insets",
864 spec_section: "CSS Position L3 § 2",
865 title: "Absolute positioning resolved against relative containing block",
866 passed: dev <= 0.05,
867 deviation_px: dev,
868 });
869 }
870
871 vectors
872 }
873}