Commit e91d8938 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Add more NGInlineCursor tests

This patch:
* Adds tests for enumerating fragments for a |LayoutObject|.
  These tests were created for crrev.com/c/2332083 but missed
  to include in the CL.
* Added |LayoutObjectToDebugStringList| helper function.
* Move some helper functions out of the test class so that
  they can be used in other than member functions.
  crrev.com/c/2313736 needs to create a separate class to
  use different runtime flag.

Bug: 982194
Change-Id: I4236c4251242b5790ba62388177a14d46958aa61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337196
Auto-Submit: Koji Ishii <kojii@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794790}
parent 76b28728
...@@ -13,8 +13,44 @@ ...@@ -13,8 +13,44 @@
namespace blink { namespace blink {
namespace {
using ::testing::ElementsAre; using ::testing::ElementsAre;
String ToDebugString(const NGInlineCursor& cursor) {
if (cursor.Current().IsLineBox())
return "#linebox";
if (cursor.Current().IsLayoutGeneratedText()) {
StringBuilder result;
result.Append("#'");
result.Append(cursor.CurrentText());
result.Append("'");
return result.ToString();
}
if (cursor.Current().IsText())
return cursor.CurrentText().ToString().StripWhiteSpace();
if (const LayoutObject* layout_object = cursor.Current().GetLayoutObject()) {
if (const Element* element = DynamicTo<Element>(layout_object->GetNode())) {
if (const AtomicString& id = element->GetIdAttribute())
return "#" + id;
}
return layout_object->DebugName();
}
return "#null";
}
Vector<String> LayoutObjectToDebugStringList(NGInlineCursor cursor) {
Vector<String> list;
for (; cursor; cursor.MoveToNextForSameLayoutObject())
list.push_back(ToDebugString(cursor));
return list;
}
class NGInlineCursorTest : public NGLayoutTest, class NGInlineCursorTest : public NGLayoutTest,
private ScopedLayoutNGFragmentItemForTest, private ScopedLayoutNGFragmentItemForTest,
public testing::WithParamInterface<bool> { public testing::WithParamInterface<bool> {
...@@ -73,35 +109,6 @@ class NGInlineCursorTest : public NGLayoutTest, ...@@ -73,35 +109,6 @@ class NGInlineCursorTest : public NGLayoutTest,
EXPECT_THAT(backwards, forwards); EXPECT_THAT(backwards, forwards);
} }
String ToDebugString(const NGInlineCursor& cursor) {
if (cursor.Current().IsLineBox())
return "#linebox";
if (cursor.Current().IsLayoutGeneratedText()) {
StringBuilder result;
result.Append("#'");
result.Append(cursor.CurrentText());
result.Append("'");
return result.ToString();
}
if (cursor.Current().IsText())
return cursor.CurrentText().ToString().StripWhiteSpace();
if (const LayoutObject* layout_object =
cursor.Current().GetLayoutObject()) {
if (const Element* element =
DynamicTo<Element>(layout_object->GetNode())) {
if (const AtomicString& id = element->GetIdAttribute())
return "#" + id;
}
return layout_object->DebugName();
}
return "#null";
}
Vector<String> ToDebugStringListWithBidiLevel(const NGInlineCursor& start) { Vector<String> ToDebugStringListWithBidiLevel(const NGInlineCursor& start) {
Vector<String> list; Vector<String> list;
for (NGInlineCursor cursor(start); cursor; cursor.MoveToNext()) { for (NGInlineCursor cursor(start); cursor; cursor.MoveToNext()) {
...@@ -215,12 +222,8 @@ TEST_P(NGInlineCursorTest, CulledInlineWithAtomicInline) { ...@@ -215,12 +222,8 @@ TEST_P(NGInlineCursorTest, CulledInlineWithAtomicInline) {
"</div>"); "</div>");
NGInlineCursor cursor; NGInlineCursor cursor;
cursor.MoveToIncludingCulledInline(*GetLayoutObjectByElementId("culled")); cursor.MoveToIncludingCulledInline(*GetLayoutObjectByElementId("culled"));
Vector<String> list; EXPECT_THAT(LayoutObjectToDebugStringList(cursor),
while (cursor) { ElementsAre("abc", "ABC", "", "XYZ", "xyz"));
list.push_back(ToDebugString(cursor));
cursor.MoveToNextForSameLayoutObject();
}
EXPECT_THAT(list, ElementsAre("abc", "ABC", "", "XYZ", "xyz"));
} }
// We should not have float:right fragment, because it isn't in-flow in // We should not have float:right fragment, because it isn't in-flow in
...@@ -233,12 +236,43 @@ TEST_P(NGInlineCursorTest, CulledInlineWithFloat) { ...@@ -233,12 +236,43 @@ TEST_P(NGInlineCursorTest, CulledInlineWithFloat) {
"</div>"); "</div>");
NGInlineCursor cursor; NGInlineCursor cursor;
cursor.MoveToIncludingCulledInline(*GetLayoutObjectByElementId("culled")); cursor.MoveToIncludingCulledInline(*GetLayoutObjectByElementId("culled"));
Vector<String> list; EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("abc", "xyz"));
while (cursor) { }
list.push_back(ToDebugString(cursor));
cursor.MoveToNextForSameLayoutObject(); TEST_P(NGInlineCursorTest, CulledInlineWithOOF) {
} SetBodyInnerHTML(R"HTML(
EXPECT_THAT(list, ElementsAre("abc", "xyz")); <div id=root>
<b id=culled>abc<span style="position:absolute"></span>xyz</b>
</div>
)HTML");
NGInlineCursor cursor;
cursor.MoveToIncludingCulledInline(*GetLayoutObjectByElementId("culled"));
EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("abc", "xyz"));
}
TEST_P(NGInlineCursorTest, CulledInlineNested) {
SetBodyInnerHTML(R"HTML(
<div id=root>
<b id=culled><span>abc</span> xyz</b>
</div>
)HTML");
NGInlineCursor cursor;
cursor.MoveToIncludingCulledInline(*GetLayoutObjectByElementId("culled"));
EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("abc", "xyz"));
}
TEST_P(NGInlineCursorTest, CulledInlineBlockChild) {
SetBodyInnerHTML(R"HTML(
<div id=root>
<b id=culled>
<div>block</div>
<span>abc</span> xyz
</b>
</div>
)HTML");
NGInlineCursor cursor;
cursor.MoveToIncludingCulledInline(*GetLayoutObjectByElementId("culled"));
EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("#culled"));
} }
TEST_P(NGInlineCursorTest, CulledInlineWithRoot) { TEST_P(NGInlineCursorTest, CulledInlineWithRoot) {
...@@ -247,12 +281,8 @@ TEST_P(NGInlineCursorTest, CulledInlineWithRoot) { ...@@ -247,12 +281,8 @@ TEST_P(NGInlineCursorTest, CulledInlineWithRoot) {
)HTML"); )HTML");
const LayoutObject* layout_inline_a = GetLayoutObjectByElementId("a"); const LayoutObject* layout_inline_a = GetLayoutObjectByElementId("a");
cursor.MoveToIncludingCulledInline(*layout_inline_a); cursor.MoveToIncludingCulledInline(*layout_inline_a);
Vector<String> list; EXPECT_THAT(LayoutObjectToDebugStringList(cursor),
while (cursor) { ElementsAre("abc", "", "xyz"));
list.push_back(ToDebugString(cursor));
cursor.MoveToNextForSameLayoutObject();
}
EXPECT_THAT(list, ElementsAre("abc", "", "xyz"));
} }
TEST_P(NGInlineCursorTest, CulledInlineWithoutRoot) { TEST_P(NGInlineCursorTest, CulledInlineWithoutRoot) {
...@@ -262,12 +292,8 @@ TEST_P(NGInlineCursorTest, CulledInlineWithoutRoot) { ...@@ -262,12 +292,8 @@ TEST_P(NGInlineCursorTest, CulledInlineWithoutRoot) {
const LayoutObject* layout_inline_a = GetLayoutObjectByElementId("a"); const LayoutObject* layout_inline_a = GetLayoutObjectByElementId("a");
NGInlineCursor cursor; NGInlineCursor cursor;
cursor.MoveToIncludingCulledInline(*layout_inline_a); cursor.MoveToIncludingCulledInline(*layout_inline_a);
Vector<String> list; EXPECT_THAT(LayoutObjectToDebugStringList(cursor),
while (cursor) { ElementsAre("abc", "", "xyz"));
list.push_back(ToDebugString(cursor));
cursor.MoveToNextForSameLayoutObject();
}
EXPECT_THAT(list, ElementsAre("abc", "", "xyz"));
} }
TEST_P(NGInlineCursorTest, FirstChild) { TEST_P(NGInlineCursorTest, FirstChild) {
...@@ -620,12 +646,8 @@ TEST_P(NGInlineCursorTest, NextWithInlineBox) { ...@@ -620,12 +646,8 @@ TEST_P(NGInlineCursorTest, NextWithInlineBox) {
TEST_P(NGInlineCursorTest, NextForSameLayoutObject) { TEST_P(NGInlineCursorTest, NextForSameLayoutObject) {
NGInlineCursor cursor = SetupCursor("<pre id=root>abc\ndef\nghi</pre>"); NGInlineCursor cursor = SetupCursor("<pre id=root>abc\ndef\nghi</pre>");
cursor.MoveTo(*GetLayoutObjectByElementId("root")->SlowFirstChild()); cursor.MoveTo(*GetLayoutObjectByElementId("root")->SlowFirstChild());
Vector<String> list; EXPECT_THAT(LayoutObjectToDebugStringList(cursor),
while (cursor) { ElementsAre("abc", "", "def", "", "ghi"));
list.push_back(ToDebugString(cursor));
cursor.MoveToNextForSameLayoutObject();
}
EXPECT_THAT(list, ElementsAre("abc", "", "def", "", "ghi"));
} }
// Test |NextForSameLayoutObject| with limit range set. // Test |NextForSameLayoutObject| with limit range set.
...@@ -660,12 +682,8 @@ TEST_P(NGInlineCursorTest, NextForSameLayoutObjectWithRange) { ...@@ -660,12 +682,8 @@ TEST_P(NGInlineCursorTest, NextForSameLayoutObjectWithRange) {
// Now |line2| is limited to the 2nd line. There should be only one framgnet // Now |line2| is limited to the 2nd line. There should be only one framgnet
// for `<span>` if we search using `line2`. // for `<span>` if we search using `line2`.
LayoutObject* span1 = GetLayoutObjectByElementId("span1"); LayoutObject* span1 = GetLayoutObjectByElementId("span1");
wtf_size_t count = 0; line2.MoveTo(*span1);
for (line2.MoveTo(*span1); line2; line2.MoveToNextForSameLayoutObject()) { EXPECT_THAT(LayoutObjectToDebugStringList(line2), ElementsAre("#span1"));
DCHECK_EQ(line2.Current().GetLayoutObject(), span1);
++count;
}
EXPECT_EQ(count, 1u);
} }
TEST_P(NGInlineCursorTest, Sibling) { TEST_P(NGInlineCursorTest, Sibling) {
...@@ -1038,4 +1056,6 @@ TEST_P(NGInlineCursorTest, CursorForDescendants) { ...@@ -1038,4 +1056,6 @@ TEST_P(NGInlineCursorTest, CursorForDescendants) {
ElementsAre("text3")); ElementsAre("text3"));
} }
} // namespace
} // namespace blink } // namespace blink
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