Skip to content

Commit 9c19db3

Browse files
committed
Add background-color paint-call test coverage
No test anywhere verified background-color actually paints a fill, despite the paint code (CssBox.PaintBackground) already working - only CSS-OM parsing (BackgroundPropertyTests.cs) was covered. Verifies fill geometry, the transparent/default (also transparent) no-op cases, and paint order relative to border/outline per CSS2.1 Appendix E.
1 parent 33b4be6 commit 9c19db3

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System.Linq;
2+
using HtmlRenderer.IntegrationTest.TestSupport;
3+
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
4+
5+
namespace HtmlRenderer.IntegrationTest.Painting;
6+
7+
/// <summary>
8+
/// CSS 2.1 §14.2.1: <c>background-color</c> paints a solid fill behind a box's content, covering the box's
9+
/// padding + content area (border-box minus the border itself). No dedicated background paint-call test
10+
/// existed anywhere in this repo before this - only CSS-OM parsing (<c>BackgroundPropertyTests.cs</c>).
11+
/// </summary>
12+
[DoNotParallelize]
13+
[TestClass]
14+
public sealed class BackgroundPaintIntegrationTests
15+
{
16+
[TestMethod]
17+
public void BackgroundColor_PaintsASolidFillRect()
18+
{
19+
var (root, container) = PaintHarness.Layout(PaintHarness.Wrap(
20+
"<div id='b' style='width:100px;height:50px;background-color:rgb(10,20,30)'>x</div>"));
21+
var div = PaintHarness.FindById(root, "b")!;
22+
23+
var g = PaintHarness.PaintBox(container, div);
24+
var fills = g.Log.OfType<RecordingGraphics.DrawRectCall>()
25+
.Where(r => r.Color == RColor.FromArgb(10, 20, 30)).ToList();
26+
27+
Assert.AreEqual(1, fills.Count);
28+
Assert.AreEqual(100, fills[0].Width, 0.1);
29+
Assert.AreEqual(50, fills[0].Height, 0.1);
30+
}
31+
32+
[TestMethod]
33+
public void BackgroundColorTransparent_PaintsNothing()
34+
{
35+
var (root, container) = PaintHarness.Layout(PaintHarness.Wrap(
36+
"<div id='b' style='width:100px;height:50px;background-color:transparent'>x</div>"));
37+
var div = PaintHarness.FindById(root, "b")!;
38+
39+
var g = PaintHarness.PaintBox(container, div);
40+
41+
Assert.IsFalse(g.Log.OfType<RecordingGraphics.DrawRectCall>().Any());
42+
}
43+
44+
[TestMethod]
45+
public void BackgroundColorDefault_PaintsNothing()
46+
{
47+
// The initial value of background-color is "transparent" - a box with no background-color set at
48+
// all must not paint a fill either.
49+
var (root, container) = PaintHarness.Layout(PaintHarness.Wrap(
50+
"<div id='b' style='width:100px;height:50px;'>x</div>"));
51+
var div = PaintHarness.FindById(root, "b")!;
52+
53+
var g = PaintHarness.PaintBox(container, div);
54+
55+
Assert.IsFalse(g.Log.OfType<RecordingGraphics.DrawRectCall>().Any());
56+
}
57+
58+
[TestMethod]
59+
public void BackgroundColor_PaintsBeforeBorderAndOutline()
60+
{
61+
// CSS 2.1 Appendix E: background paints before border/outline for the same box.
62+
var (root, container) = PaintHarness.Layout(PaintHarness.Wrap(
63+
"<div id='b' style='width:100px;height:50px;background-color:rgb(10,20,30);"
64+
+ "border:3px solid rgb(1,2,3);outline:5px solid rgb(4,5,6)'>x</div>"));
65+
var div = PaintHarness.FindById(root, "b")!;
66+
67+
var g = PaintHarness.PaintBox(container, div);
68+
69+
var backgroundIndex = g.Log.FindIndex(c => c is RecordingGraphics.DrawRectCall r && r.Color == RColor.FromArgb(10, 20, 30));
70+
var borderIndex = g.Log.FindIndex(c => c is RecordingGraphics.DrawLineCall l && l.Color == RColor.FromArgb(1, 2, 3));
71+
var outlineIndex = g.Log.FindIndex(c => c is RecordingGraphics.DrawRectCall r && r.Color == RColor.FromArgb(4, 5, 6));
72+
73+
Assert.IsTrue(backgroundIndex >= 0 && borderIndex >= 0 && outlineIndex >= 0);
74+
Assert.IsTrue(backgroundIndex < borderIndex, "background must paint before the border");
75+
Assert.IsTrue(borderIndex < outlineIndex, "border must paint before the outline");
76+
}
77+
}

0 commit comments

Comments
 (0)