Repository navigation
Expand file tree
/
Copy pathAtomicInlineLevelBoxCorrectionTests.cs
More file actions
85 lines (76 loc) · 4.7 KB
/
Copy pathAtomicInlineLevelBoxCorrectionTests.cs
File metadata and controls
85 lines (76 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using HtmlRenderer.IntegrationTest.TestSupport;
namespace HtmlRenderer.IntegrationTest.BoxModel;
/// <summary>
/// DomParser's "block inside inline" DOM-correction pass (CorrectBlockInsideInline) should never look through an
/// inline-level box that establishes its own independent formatting context (inline-block/inline-table both do)
/// when deciding whether an ANCESTOR box needs splitting - DomUtils.ContainsInlinesOnly is meant to make such a
/// box opaque for that purpose. A child whose own resolved display is "none" (not "inline") should not make the
/// correction pass misclassify the box's content as containing a "block", incorrectly splitting the child out of
/// its real parent entirely.
/// </summary>
/// <remarks>
/// The triage note for this file claimed both cases already pass on this fork. Direct testing shows otherwise
/// for the inline-block case: dumping the box tree for the <select>/<option> markup below shows
/// <c>opt1</c> (the FIRST display:none <option>) gets hoisted out from under <select> entirely and
/// becomes a sibling of the anonymous block box CorrectInlineBoxesParent wraps <select> in, while
/// <c>opt2</c> (the second, otherwise-identical <option>) correctly stays nested. That first-child-only
/// asymmetry is exactly the atomic-inline-level gap the class doc describes - it just was not caught by the
/// triage pass. The inline-table case genuinely does pass, so only the inline-block test method is ignored
/// (with the real, faithfully-ported assertions kept, to document the target behavior).
/// </remarks>
[DoNotParallelize]
[TestClass]
public sealed class AtomicInlineLevelBoxCorrectionTests
{
[Ignore("Confirmed real bug on this fork, not a porting mistake: dumping the box tree shows opt1 (the " +
"FIRST display:none <option> child of an inline-block <select>) gets hoisted out from under " +
"<select> and becomes a sibling of the anonymous block wrapper CorrectInlineBoxesParent creates, " +
"while opt2 (second, otherwise-identical child) stays correctly nested. DomUtils.ContainsInlinesOnly " +
"does not treat inline-block as opaque the way an atomic-inline-level check should.")]
[TestMethod]
public void DisplayNoneChildOfInlineBlockBox_StaysNestedUnderItsRealParent()
{
var html = LayoutHarness.Wrap(
"<select id='sel'>" +
"<option id='opt1' style='display:none'>Red</option>" +
"<option id='opt2' style='display:none'>Green</option>" +
"</select>");
var (root, _) = LayoutHarness.Layout(html);
var select = LayoutHarness.FindById(root, "sel")!;
var opt1 = LayoutHarness.FindById(root, "opt1")!;
var opt2 = LayoutHarness.FindById(root, "opt2")!;
Assert.IsTrue(IsDescendantOf(opt1, select), "opt1 (display:none) must stay nested under its real <select> parent.");
Assert.IsTrue(IsDescendantOf(opt2, select), "opt2 must stay nested under its real <select> parent.");
}
[TestMethod]
public void DisplayNoneChildOfInlineTableBox_StaysNestedUnderItsRealParent()
{
var html = LayoutHarness.Wrap(
"<div id='wrap'>" +
"<div id='it' style='display:inline-table'>" +
"<div style='display:table-row'><div id='cell' style='display:table-cell'>cell</div></div>" +
"<div id='hidden' style='display:none'>hidden</div>" +
"</div>" +
"</div>");
var (root, _) = LayoutHarness.Layout(html);
var inlineTable = LayoutHarness.FindById(root, "it")!;
var hidden = LayoutHarness.FindById(root, "hidden")!;
Assert.IsTrue(IsDescendantOf(hidden, inlineTable), "a display:none sibling inside an inline-table must stay nested under it.");
}
// PeachPDF's source file also has a "DisplayNoneChildOfInlineFlexBox_StillStaysNestedUnderItsRealParent"
// regression case, guarding pre-existing display:inline-flex handling. HTML-Renderer (this fork) implements
// no flexbox layout at all - "flex"/"inline-flex" are not recognized display values anywhere in
// TheArtOfDev.HtmlRenderer.Core (confirmed: no "flex" hits in the Core source tree) - so there is no such
// pre-existing handling to guard, and porting that case would document a feature this fork doesn't have.
// Intentionally dropped rather than ported under a false premise.
private static bool IsDescendantOf(TheArtOfDev.HtmlRenderer.Core.Dom.CssBox box, TheArtOfDev.HtmlRenderer.Core.Dom.CssBox ancestor)
{
var current = box.ParentBox;
while (current != null)
{
if (ReferenceEquals(current, ancestor)) return true;
current = current.ParentBox;
}
return false;
}
}