Skip to content

Commit 49b670b

Browse files
AnhelinaMiText-CI
authored andcommitted
Add tests for flex base size determination algorithm
DEVSIX-8768 Autoported commit. Original commit hash: [222c265b4]
1 parent 0cc8343 commit 49b670b

File tree

76 files changed

+894
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+894
-13
lines changed

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/FloatTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ public virtual void PlainTextIndentAfterBlockAndFloatTest() {
679679

680680
[NUnit.Framework.Test]
681681
public virtual void FloatElementInDivTest() {
682-
//TODO DEVSIX-5291 change cmp file
682+
// TODO DEVSIX-5291 floating elements are not included in the div
683683
RunTest("floatElementInDiv", "diff_floatElementInDiv_");
684684
}
685685

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/FontFamilyTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public virtual void SelectFontFromTTCTest() {
5959
String pdfPath = DESTINATION_FOLDER + "selectFontInGroup.pdf";
6060
String cmpPdfPath = SOURCE_FOLDER + "cmp_selectFontInGroup.pdf";
6161
HtmlConverter.ConvertToPdf(new FileInfo(htmlPath), new FileInfo(pdfPath));
62-
//TODO DEVSIX-1104: Change cmp file after supporting ttc#id when selecting font from ttc
63-
//Currently it will look for a font file where #{id} is part of the font path.
62+
// TODO DEVSIX-1104: Change cmp file after supporting ttc#id when selecting font from ttc
63+
// Currently it will look for a font file where #{id} is part of the font path.
6464
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(pdfPath, cmpPdfPath, DESTINATION_FOLDER,
6565
"diff_"));
6666
}

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/LineHeightTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public virtual void TextAreaLineHeightShortTest() {
150150

151151
[NUnit.Framework.Test]
152152
public virtual void InlineElementLineHeightTest() {
153-
// TODO DEVSIX-2485 change cmp after fixing the ticket
153+
// TODO DEVSIX-2485 Html2Pdf inline context handling: support phrasing content in HTML+CSS way
154154
TestLineHeight("inlineElementLineHeightTest");
155155
}
156156

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/flex/DisplayFlexTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public virtual void FlexBasisAuto() {
301301

302302
[NUnit.Framework.Test]
303303
public virtual void FlexBasisContentMaxWidth() {
304-
// TODO DEVSIX-5091 change cmp file when working on the thicket
304+
// TODO DEVSIX-5091 Support flex-basis: content
305305
ConvertToPdfAndCompare("flexBasisContentMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER);
306306
}
307307

@@ -650,6 +650,16 @@ public virtual void FlexWithPageBreakInsideAvoidAndPageSplit2Test() {
650650
ConvertToPdfAndCompare("flexWithPageBreakInsideAvoidAndPageSplit2", SOURCE_FOLDER, DESTINATION_FOLDER);
651651
}
652652

653+
[NUnit.Framework.Test]
654+
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
655+
public virtual void ImageSizeTest() {
656+
// Result for image width differs from browser, although min width and flexible lengths are determined according
657+
// to the CSS specification algorithms. Not sure why browser behaves like this: min main size is calculated based on
658+
// transferred size suggestion instead of content size suggestion and aspect ratio is based on specified properties
659+
// (we calculate it based on original image width / height).
660+
ConvertToPdfAndCompare("imageSize", SOURCE_FOLDER, DESTINATION_FOLDER);
661+
}
662+
653663
private static IList<IElement> ConvertToElements(String name) {
654664
String sourceHtml = SOURCE_FOLDER + name + ".html";
655665
ConverterProperties converterProperties = new ConverterProperties().SetBaseUri(SOURCE_FOLDER);
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2025 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System;
24+
using iText.Html2pdf;
25+
using iText.Html2pdf.Logs;
26+
using iText.Layout.Logs;
27+
using iText.Test.Attributes;
28+
29+
namespace iText.Html2pdf.Css.Flex {
30+
[NUnit.Framework.Category("IntegrationTest")]
31+
public class FlexBaseSizeTest : ExtendedHtmlConversionITextTest {
32+
// TODO DEVSIX-5091 Support flex-basis: content
33+
// TODO DEVSIX-5001 Support content, min-content, max-content as width values
34+
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
35+
.CurrentContext.TestDirectory) + "/resources/itext/html2pdf/css/flex/FlexBaseSizeTest/";
36+
37+
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
38+
+ "/test/itext/html2pdf/css/flex/FlexBaseSizeTest/";
39+
40+
[NUnit.Framework.OneTimeSetUp]
41+
public static void BeforeClass() {
42+
CreateDestinationFolder(DESTINATION_FOLDER);
43+
}
44+
45+
// A and E – most common cases from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (flex base size algorithm)
46+
[NUnit.Framework.Test]
47+
public virtual void FlexBasisAutoWidthNumTest() {
48+
ConvertToPdfAndCompare("flexBasisAutoWidthNum", SOURCE_FOLDER, DESTINATION_FOLDER);
49+
}
50+
51+
[NUnit.Framework.Test]
52+
public virtual void FlexBasisAutoHeightNumTest() {
53+
ConvertToPdfAndCompare("flexBasisAutoHeightNum", SOURCE_FOLDER, DESTINATION_FOLDER);
54+
}
55+
56+
[NUnit.Framework.Test]
57+
public virtual void FlexBasisAutoWidthPercentageTest() {
58+
ConvertToPdfAndCompare("flexBasisAutoWidthPercentage", SOURCE_FOLDER, DESTINATION_FOLDER);
59+
}
60+
61+
[NUnit.Framework.Test]
62+
public virtual void FlexBasisAutoHeightPercentageTest() {
63+
ConvertToPdfAndCompare("flexBasisAutoHeightPercentage", SOURCE_FOLDER, DESTINATION_FOLDER);
64+
}
65+
66+
[NUnit.Framework.Test]
67+
public virtual void FlexBasisAutoWidthContentTest() {
68+
ConvertToPdfAndCompare("flexBasisAutoWidthContent", SOURCE_FOLDER, DESTINATION_FOLDER);
69+
}
70+
71+
[NUnit.Framework.Test]
72+
public virtual void FlexBasisAutoHeightContentTest() {
73+
ConvertToPdfAndCompare("flexBasisAutoHeightContent", SOURCE_FOLDER, DESTINATION_FOLDER);
74+
}
75+
76+
[NUnit.Framework.Test]
77+
public virtual void FlexBasisAutoWidthMinContentTest() {
78+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
79+
ConvertToPdfAndCompare("flexBasisAutoWidthMinContent", SOURCE_FOLDER, DESTINATION_FOLDER);
80+
}
81+
82+
[NUnit.Framework.Test]
83+
public virtual void FlexBasisAutoWidthMaxContentTest() {
84+
ConvertToPdfAndCompare("flexBasisAutoWidthMaxContent", SOURCE_FOLDER, DESTINATION_FOLDER);
85+
}
86+
87+
[NUnit.Framework.Test]
88+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 12)]
89+
public virtual void FlexBasisContentTest() {
90+
ConvertToPdfAndCompare("flexBasisContent", SOURCE_FOLDER, DESTINATION_FOLDER);
91+
}
92+
93+
[NUnit.Framework.Test]
94+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 9)]
95+
public virtual void FlexBasisContentAspectRatioTest() {
96+
// TODO DEVSIX-5255 Support aspect-ratio property
97+
ConvertToPdfAndCompare("flexBasisContentAspectRatio", SOURCE_FOLDER, DESTINATION_FOLDER);
98+
}
99+
100+
[NUnit.Framework.Test]
101+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 9)]
102+
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
103+
public virtual void FlexBasisContentAspectRatioImageTest() {
104+
// Result for image width differs from browser, although min width and flexible lengths are determined according
105+
// to the CSS specification algorithms. Not sure why browser behaves like this: min main size is calculated based on
106+
// transferred size suggestion instead of content size suggestion and main size property is ignored.
107+
ConvertToPdfAndCompare("flexBasisContentAspectRatioImage", SOURCE_FOLDER, DESTINATION_FOLDER);
108+
}
109+
110+
[NUnit.Framework.Test]
111+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 9)]
112+
public virtual void FlexBasisContentAspectRatioImageBrowserTest() {
113+
// flexBasisContentAspectRatioImageTest alternative
114+
ConvertToPdfAndCompare("flexBasisContentAspectRatioImageBrowser", SOURCE_FOLDER, DESTINATION_FOLDER);
115+
}
116+
117+
[NUnit.Framework.Test]
118+
public virtual void SplitMaxSizesTest() {
119+
ConvertToPdfAndCompare("splitMaxSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
120+
}
121+
122+
[NUnit.Framework.Test]
123+
public virtual void SplitMinSizesTest() {
124+
ConvertToPdfAndCompare("splitMinSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
125+
}
126+
127+
[NUnit.Framework.Test]
128+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 10)]
129+
public virtual void FlexBasisContentIgnoreMinMaxWidthTest() {
130+
ConvertToPdfAndCompare("flexBasisContentIgnoreMinMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER);
131+
}
132+
133+
[NUnit.Framework.Test]
134+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 5)]
135+
public virtual void FlexBasisContentIgnoreMinMaxHeightTest() {
136+
ConvertToPdfAndCompare("flexBasisContentIgnoreMinMaxHeight", SOURCE_FOLDER, DESTINATION_FOLDER);
137+
}
138+
139+
[NUnit.Framework.Test]
140+
public virtual void FlexBasisContentMaxWidthTest() {
141+
ConvertToPdfAndCompare("flexBasisContentMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER);
142+
}
143+
144+
[NUnit.Framework.Test]
145+
public virtual void FlexItemWithPercentageMaxWidthTest() {
146+
ConvertToPdfAndCompare("flexItemWithPercentageMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER);
147+
}
148+
149+
// B from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm)
150+
[NUnit.Framework.Test]
151+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET)]
152+
public virtual void FlexBasisContentAspectRatioDefiniteCrossSizeTest() {
153+
// TODO DEVSIX-5255 Support aspect-ratio property
154+
ConvertToPdfAndCompare("flexBasisContentAspectRatioDefiniteCrossSize", SOURCE_FOLDER, DESTINATION_FOLDER);
155+
}
156+
157+
[NUnit.Framework.Test]
158+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET)]
159+
public virtual void FlexBasisContentAspectRatioDefiniteCrossSizeColumnTest() {
160+
// TODO DEVSIX-5255 Support aspect-ratio property
161+
ConvertToPdfAndCompare("flexBasisContentAspectRatioDefiniteCrossSizeColumn", SOURCE_FOLDER, DESTINATION_FOLDER
162+
);
163+
}
164+
165+
// C from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm)
166+
[NUnit.Framework.Test]
167+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 2)]
168+
public virtual void FlexBasisContentInsideMinContentTest() {
169+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
170+
ConvertToPdfAndCompare("flexBasisContentInsideMinContent", SOURCE_FOLDER, DESTINATION_FOLDER);
171+
}
172+
173+
[NUnit.Framework.Test]
174+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 4)]
175+
public virtual void FlexBasisContentInsideMaxContentTest() {
176+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
177+
ConvertToPdfAndCompare("flexBasisContentInsideMaxContent", SOURCE_FOLDER, DESTINATION_FOLDER);
178+
}
179+
180+
[NUnit.Framework.Test]
181+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 2)]
182+
public virtual void FlexBasisContentInsideMinContentColumnTest() {
183+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
184+
ConvertToPdfAndCompare("flexBasisContentInsideMinContentColumn", SOURCE_FOLDER, DESTINATION_FOLDER);
185+
}
186+
187+
[NUnit.Framework.Test]
188+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 2)]
189+
public virtual void FlexBasisContentInsideMaxContentColumnTest() {
190+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
191+
ConvertToPdfAndCompare("flexBasisContentInsideMaxContentColumn", SOURCE_FOLDER, DESTINATION_FOLDER);
192+
}
193+
194+
// D from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm)
195+
[NUnit.Framework.Test]
196+
[LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET)]
197+
public virtual void FlexBasisContentOrthogonalFlowTest() {
198+
// TODO DEVSIX-5182 Support writing-mode property
199+
// E.g. infinite height + vertical main axe for flex container (column) + vertical-writing-mode flex item
200+
ConvertToPdfAndCompare("flexBasisContentOrthogonalFlow", SOURCE_FOLDER, DESTINATION_FOLDER);
201+
}
202+
}
203+
}

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/flex/FlexContainerTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ public virtual void UlWideTest() {
376376
ConvertToPdfAndCompare("ulWide", SOURCE_FOLDER, DESTINATION_FOLDER);
377377
}
378378

379+
[NUnit.Framework.Test]
380+
public virtual void FlexNestedTest() {
381+
ConvertToPdfAndCompare("flexNested", SOURCE_FOLDER, DESTINATION_FOLDER);
382+
}
383+
379384
[NUnit.Framework.Test]
380385
public virtual void DeepNestingTest() {
381386
ConvertToPdfAndCompare("deepNesting", SOURCE_FOLDER, DESTINATION_FOLDER);

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/flex/FlexGapTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ public virtual void ColGapMarginTest() {
367367

368368
[NUnit.Framework.Test]
369369
public virtual void ColGapMixedSizesTest() {
370-
// TODO DEVSIX-9477 Fix issue on page split: cross-size calculated incorrectly
371370
ConvertToPdfAndCompare("colGapMixedSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
372371
}
373372

@@ -476,7 +475,6 @@ public virtual void RowGapMarginTest() {
476475

477476
[NUnit.Framework.Test]
478477
public virtual void RowGapMixedSizesTest() {
479-
// TODO DEVSIX-9477 Fix issue on page split: cross-size calculated incorrectly
480478
ConvertToPdfAndCompare("rowGapMixedSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
481479
}
482480

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/flex/PageSplitTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public static void BeforeClass() {
4040

4141
[NUnit.Framework.Test]
4242
public virtual void MixedSizesTest() {
43-
// TODO DEVSIX-9477 Fix issue on page split
4443
ConvertToPdfAndCompare("mixedSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
4544
}
4645

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/w3c/css21/linebox/LineHeight126Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ You should have received a copy of the GNU Affero General Public License
2424
using iText.Html2pdf.Css.W3c;
2525

2626
namespace iText.Html2pdf.Css.W3c.Css21.Linebox {
27-
// TODO DEVSIX-3757 change cmp file after completing the ticket
27+
// TODO DEVSIX-3757 Support vertical-align css property
2828
public class LineHeight126Test : W3CCssTest {
2929
protected internal override String GetHtmlFileName() {
3030
return "line-height-126.xht";

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/w3c/css21/linebox/LineHeight129Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ You should have received a copy of the GNU Affero General Public License
2424
using iText.Html2pdf.Css.W3c;
2525

2626
namespace iText.Html2pdf.Css.W3c.Css21.Linebox {
27-
// TODO DEVSIX-3757 change cmp file after completing the ticket
27+
// TODO DEVSIX-3757 Support vertical-align css property
2828
public class LineHeight129Test : W3CCssTest {
2929
protected internal override String GetHtmlFileName() {
3030
return "line-height-129.xht";

0 commit comments

Comments
 (0)