Commit 69f62439 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[LayoutNG] Parameterize NGOffsetMappingTest with LayoutNGPaintFragments

Since offset mapping must work with inline painting enabled, its unit
tests must also work. This patch parameterizes the unit tests to verify
this.

Bug: 699017
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: Ifcb03aa1992498b973e2cf9e59e136be0e93fe63
Reviewed-on: https://chromium-review.googlesource.com/777724Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517739}
parent a46b8b57
...@@ -86,6 +86,19 @@ class NGOffsetMappingTest : public NGLayoutTest { ...@@ -86,6 +86,19 @@ class NGOffsetMappingTest : public NGLayoutTest {
FontCachePurgePreventer purge_preventer_; FontCachePurgePreventer purge_preventer_;
}; };
class ParameterizedNGOffsetMappingTest
: public ::testing::WithParamInterface<bool>,
private ScopedLayoutNGPaintFragmentsForTest,
public NGOffsetMappingTest {
public:
ParameterizedNGOffsetMappingTest()
: ScopedLayoutNGPaintFragmentsForTest(GetParam()) {}
};
INSTANTIATE_TEST_CASE_P(All,
ParameterizedNGOffsetMappingTest,
::testing::Bool());
#define TEST_UNIT(unit, type, owner, dom_start, dom_end, text_content_start, \ #define TEST_UNIT(unit, type, owner, dom_start, dom_end, text_content_start, \
text_content_end) \ text_content_end) \
EXPECT_EQ(type, unit.GetType()); \ EXPECT_EQ(type, unit.GetType()); \
...@@ -100,14 +113,14 @@ class NGOffsetMappingTest : public NGLayoutTest { ...@@ -100,14 +113,14 @@ class NGOffsetMappingTest : public NGLayoutTest {
EXPECT_EQ(start, ranges.at(owner).first); \ EXPECT_EQ(start, ranges.at(owner).first); \
EXPECT_EQ(end, ranges.at(owner).second) EXPECT_EQ(end, ranges.at(owner).second)
TEST_F(NGOffsetMappingTest, StoredResult) { TEST_P(ParameterizedNGOffsetMappingTest, StoredResult) {
SetupHtml("t", "<div id=t>foo</div>"); SetupHtml("t", "<div id=t>foo</div>");
EXPECT_FALSE(IsOffsetMappingStored()); EXPECT_FALSE(IsOffsetMappingStored());
GetOffsetMapping(); GetOffsetMapping();
EXPECT_TRUE(IsOffsetMappingStored()); EXPECT_TRUE(IsOffsetMappingStored());
} }
TEST_F(NGOffsetMappingTest, OneTextNode) { TEST_P(ParameterizedNGOffsetMappingTest, OneTextNode) {
SetupHtml("t", "<div id=t>foo</div>"); SetupHtml("t", "<div id=t>foo</div>");
const Node* foo_node = layout_object_->GetNode(); const Node* foo_node = layout_object_->GetNode();
const NGOffsetMapping& result = GetOffsetMapping(); const NGOffsetMapping& result = GetOffsetMapping();
...@@ -170,7 +183,7 @@ TEST_F(NGOffsetMappingTest, OneTextNode) { ...@@ -170,7 +183,7 @@ TEST_F(NGOffsetMappingTest, OneTextNode) {
EXPECT_TRUE(IsAfterNonCollapsedContent(Position(foo_node, 3))); EXPECT_TRUE(IsAfterNonCollapsedContent(Position(foo_node, 3)));
} }
TEST_F(NGOffsetMappingTest, TwoTextNodes) { TEST_P(ParameterizedNGOffsetMappingTest, TwoTextNodes) {
SetupHtml("t", "<div id=t>foo<span id=s>bar</span></div>"); SetupHtml("t", "<div id=t>foo<span id=s>bar</span></div>");
const LayoutText* foo = ToLayoutText(layout_object_); const LayoutText* foo = ToLayoutText(layout_object_);
const LayoutText* bar = GetLayoutTextUnder("s"); const LayoutText* bar = GetLayoutTextUnder("s");
...@@ -238,7 +251,7 @@ TEST_F(NGOffsetMappingTest, TwoTextNodes) { ...@@ -238,7 +251,7 @@ TEST_F(NGOffsetMappingTest, TwoTextNodes) {
EXPECT_TRUE(IsAfterNonCollapsedContent(Position(bar_node, 3))); EXPECT_TRUE(IsAfterNonCollapsedContent(Position(bar_node, 3)));
} }
TEST_F(NGOffsetMappingTest, BRBetweenTextNodes) { TEST_P(ParameterizedNGOffsetMappingTest, BRBetweenTextNodes) {
SetupHtml("t", u"<div id=t>foo<br>bar</div>"); SetupHtml("t", u"<div id=t>foo<br>bar</div>");
const LayoutText* foo = ToLayoutText(layout_object_); const LayoutText* foo = ToLayoutText(layout_object_);
const LayoutText* br = ToLayoutText(foo->NextSibling()); const LayoutText* br = ToLayoutText(foo->NextSibling());
...@@ -293,7 +306,7 @@ TEST_F(NGOffsetMappingTest, BRBetweenTextNodes) { ...@@ -293,7 +306,7 @@ TEST_F(NGOffsetMappingTest, BRBetweenTextNodes) {
EXPECT_EQ(Position(bar_node, 0), GetLastPosition(4)); EXPECT_EQ(Position(bar_node, 0), GetLastPosition(4));
} }
TEST_F(NGOffsetMappingTest, OneTextNodeWithCollapsedSpace) { TEST_P(ParameterizedNGOffsetMappingTest, OneTextNodeWithCollapsedSpace) {
SetupHtml("t", "<div id=t>foo bar</div>"); SetupHtml("t", "<div id=t>foo bar</div>");
const Node* node = layout_object_->GetNode(); const Node* node = layout_object_->GetNode();
const NGOffsetMapping& result = GetOffsetMapping(); const NGOffsetMapping& result = GetOffsetMapping();
...@@ -366,7 +379,7 @@ TEST_F(NGOffsetMappingTest, OneTextNodeWithCollapsedSpace) { ...@@ -366,7 +379,7 @@ TEST_F(NGOffsetMappingTest, OneTextNodeWithCollapsedSpace) {
EXPECT_TRUE(IsAfterNonCollapsedContent(Position(node, 8))); EXPECT_TRUE(IsAfterNonCollapsedContent(Position(node, 8)));
} }
TEST_F(NGOffsetMappingTest, FullyCollapsedWhiteSpaceNode) { TEST_P(ParameterizedNGOffsetMappingTest, FullyCollapsedWhiteSpaceNode) {
SetupHtml("t", SetupHtml("t",
"<div id=t>" "<div id=t>"
"<span id=s1>foo </span>" "<span id=s1>foo </span>"
...@@ -432,7 +445,7 @@ TEST_F(NGOffsetMappingTest, FullyCollapsedWhiteSpaceNode) { ...@@ -432,7 +445,7 @@ TEST_F(NGOffsetMappingTest, FullyCollapsedWhiteSpaceNode) {
StartOfNextNonCollapsedContent(Position(space_node, 0u)).IsNull()); StartOfNextNonCollapsedContent(Position(space_node, 0u)).IsNull());
} }
TEST_F(NGOffsetMappingTest, ReplacedElement) { TEST_P(ParameterizedNGOffsetMappingTest, ReplacedElement) {
SetupHtml("t", "<div id=t>foo <img> bar</div>"); SetupHtml("t", "<div id=t>foo <img> bar</div>");
const LayoutText* foo = ToLayoutText(layout_object_); const LayoutText* foo = ToLayoutText(layout_object_);
const LayoutObject* img = foo->NextSibling(); const LayoutObject* img = foo->NextSibling();
...@@ -489,7 +502,7 @@ TEST_F(NGOffsetMappingTest, ReplacedElement) { ...@@ -489,7 +502,7 @@ TEST_F(NGOffsetMappingTest, ReplacedElement) {
EXPECT_EQ(Position(bar_node, 0), GetLastPosition(5)); EXPECT_EQ(Position(bar_node, 0), GetLastPosition(5));
} }
TEST_F(NGOffsetMappingTest, FirstLetter) { TEST_P(ParameterizedNGOffsetMappingTest, FirstLetter) {
SetupHtml("t", SetupHtml("t",
"<style>div:first-letter{color:red}</style>" "<style>div:first-letter{color:red}</style>"
"<div id=t>foo</div>"); "<div id=t>foo</div>");
...@@ -519,7 +532,7 @@ TEST_F(NGOffsetMappingTest, FirstLetter) { ...@@ -519,7 +532,7 @@ TEST_F(NGOffsetMappingTest, FirstLetter) {
EXPECT_EQ(Position(foo_node, 1), GetLastPosition(1)); EXPECT_EQ(Position(foo_node, 1), GetLastPosition(1));
} }
TEST_F(NGOffsetMappingTest, FirstLetterWithLeadingSpace) { TEST_P(ParameterizedNGOffsetMappingTest, FirstLetterWithLeadingSpace) {
SetupHtml("t", SetupHtml("t",
"<style>div:first-letter{color:red}</style>" "<style>div:first-letter{color:red}</style>"
"<div id=t> foo</div>"); "<div id=t> foo</div>");
...@@ -555,7 +568,7 @@ TEST_F(NGOffsetMappingTest, FirstLetterWithLeadingSpace) { ...@@ -555,7 +568,7 @@ TEST_F(NGOffsetMappingTest, FirstLetterWithLeadingSpace) {
EXPECT_EQ(Position(foo_node, 2), GetLastPosition(0)); EXPECT_EQ(Position(foo_node, 2), GetLastPosition(0));
} }
TEST_F(NGOffsetMappingTest, FirstLetterWithoutRemainingText) { TEST_P(ParameterizedNGOffsetMappingTest, FirstLetterWithoutRemainingText) {
SetupHtml("t", SetupHtml("t",
"<style>div:first-letter{color:red}</style>" "<style>div:first-letter{color:red}</style>"
"<div id=t> f</div>"); "<div id=t> f</div>");
...@@ -586,7 +599,7 @@ TEST_F(NGOffsetMappingTest, FirstLetterWithoutRemainingText) { ...@@ -586,7 +599,7 @@ TEST_F(NGOffsetMappingTest, FirstLetterWithoutRemainingText) {
EXPECT_EQ(Position(text_node, 2), GetLastPosition(0)); EXPECT_EQ(Position(text_node, 2), GetLastPosition(0));
} }
TEST_F(NGOffsetMappingTest, FirstLetterInDifferentBlock) { TEST_P(ParameterizedNGOffsetMappingTest, FirstLetterInDifferentBlock) {
SetupHtml("t", SetupHtml("t",
"<style>:first-letter{float:right}</style><div id=t>foo</div>"); "<style>:first-letter{float:right}</style><div id=t>foo</div>");
Element* div = GetDocument().getElementById("t"); Element* div = GetDocument().getElementById("t");
...@@ -650,7 +663,7 @@ TEST_F(NGOffsetMappingTest, FirstLetterInDifferentBlock) { ...@@ -650,7 +663,7 @@ TEST_F(NGOffsetMappingTest, FirstLetterInDifferentBlock) {
EXPECT_EQ(Position(text_node, 1), remaining_text_result.GetLastPosition(1)); EXPECT_EQ(Position(text_node, 1), remaining_text_result.GetLastPosition(1));
} }
TEST_F(NGOffsetMappingTest, WhiteSpaceTextNodeWithoutLayoutText) { TEST_P(ParameterizedNGOffsetMappingTest, WhiteSpaceTextNodeWithoutLayoutText) {
SetupHtml("t", "<div id=t> <span>foo</span></div>"); SetupHtml("t", "<div id=t> <span>foo</span></div>");
Element* div = GetDocument().getElementById("t"); Element* div = GetDocument().getElementById("t");
const Node* text_node = div->firstChild(); const Node* text_node = div->firstChild();
...@@ -659,7 +672,8 @@ TEST_F(NGOffsetMappingTest, WhiteSpaceTextNodeWithoutLayoutText) { ...@@ -659,7 +672,8 @@ TEST_F(NGOffsetMappingTest, WhiteSpaceTextNodeWithoutLayoutText) {
EXPECT_TRUE(StartOfNextNonCollapsedContent(Position(text_node, 0u)).IsNull()); EXPECT_TRUE(StartOfNextNonCollapsedContent(Position(text_node, 0u)).IsNull());
} }
TEST_F(NGOffsetMappingTest, OneContainerWithLeadingAndTrailingSpaces) { TEST_P(ParameterizedNGOffsetMappingTest,
OneContainerWithLeadingAndTrailingSpaces) {
SetupHtml("t", "<div id=t><span id=s> foo </span></div>"); SetupHtml("t", "<div id=t><span id=s> foo </span></div>");
const Node* span = GetElementById("s"); const Node* span = GetElementById("s");
const Node* text = span->firstChild(); const Node* text = span->firstChild();
...@@ -683,7 +697,7 @@ TEST_F(NGOffsetMappingTest, OneContainerWithLeadingAndTrailingSpaces) { ...@@ -683,7 +697,7 @@ TEST_F(NGOffsetMappingTest, OneContainerWithLeadingAndTrailingSpaces) {
EXPECT_EQ(3u, *GetTextContentOffset(Position::AfterNode(*span))); EXPECT_EQ(3u, *GetTextContentOffset(Position::AfterNode(*span)));
} }
TEST_F(NGOffsetMappingTest, ContainerWithGeneratedContent) { TEST_P(ParameterizedNGOffsetMappingTest, ContainerWithGeneratedContent) {
SetupHtml("t", SetupHtml("t",
"<style>#s::before{content:'bar'} #s::after{content:'baz'}</style>" "<style>#s::before{content:'bar'} #s::after{content:'baz'}</style>"
"<div id=t><span id=s>foo</span></div>"); "<div id=t><span id=s>foo</span></div>");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment