Commit 2f71ad5d authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Dump layout selection test result as text.

This patch implements |std::string DumpSelectionInfo()| so that
we can check a SelectionStatus tree with text diff.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Ib42cebfc5a7f1908a4e748f622bbdae9c24987c6
Reviewed-on: https://chromium-review.googlesource.com/1136335Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575948}
parent 9eb6d796
...@@ -134,33 +134,58 @@ class LayoutSelectionTest : public EditingTestBase { ...@@ -134,33 +134,58 @@ class LayoutSelectionTest : public EditingTestBase {
PrintLayoutObjectForSelection(stream, runner); PrintLayoutObjectForSelection(stream, runner);
} }
} }
#ifndef NDEBUG
void PrintDOMTreeInternal(std::stringstream& stream, void PrintText(std::ostream& ostream, const Text& text) {
const Node& node, ostream << "'" << text.data().Utf8().data() << "'";
size_t stack) { }
stream << '\n';
for (size_t s = 0; s < stack; s++) { void PrintSelectionInfo(std::ostream& ostream, LayoutObject* layout_object) {
stream << " "; if (!layout_object) {
ostream << "<null>";
return;
} }
stream << node << ", layout: "; if (const LayoutTextFragment* fragment =
PrintLayoutObjectForSelection(stream, node.GetLayoutObject()); ToLayoutTextFragmentOrNull(*layout_object)) {
// TODO(yoichio): Treat LayoutQuote which may generate LayoutTextFragment
// that's neither first-letter nor remaining text.
if (fragment->IsRemainingTextLayoutObject())
ostream << "remaining part of ";
else
ostream << "first-letter of ";
PrintText(ostream, *fragment->AssociatedTextNode());
} else {
if (Text* text = ToTextOrNull(layout_object->GetNode()))
PrintText(ostream, *text);
else
ostream << layout_object->GetNode();
}
ostream << ", " << layout_object->GetSelectionState()
<< (layout_object->ShouldInvalidateSelection()
? ", ShouldInvalidate "
: ", NotInvalidate ");
}
void PrintDOMTreeInternal(std::ostream& ostream,
const Node& node,
size_t depth) {
ostream << RepeatString(" ", depth).Utf8().data();
PrintSelectionInfo(ostream, node.GetLayoutObject());
if (ShadowRoot* shadow_root = node.GetShadowRoot()) { if (ShadowRoot* shadow_root = node.GetShadowRoot()) {
stream << '\n'; ostream << std::endl << RepeatString(" ", depth + 1).Utf8().data();
for (size_t s = 0; s < stack + 1; s++) { ostream << "#shadow-root";
stream << " ";
}
stream << "#shadow-root";
for (Node* child = shadow_root->firstChild(); child; for (Node* child = shadow_root->firstChild(); child;
child = child->nextSibling()) { child = child->nextSibling()) {
PrintDOMTreeInternal(stream, *child, stack + 2); PrintDOMTreeInternal(ostream, *child, depth + 2);
} }
} }
for (Node* child = node.firstChild(); child; child = child->nextSibling()) { for (Node* child = node.firstChild(); child; child = child->nextSibling()) {
PrintDOMTreeInternal(stream, *child, stack + 1); ostream << std::endl;
PrintDOMTreeInternal(ostream, *child, depth + 1);
} }
} }
#ifndef NDEBUG
void PrintDOMTreeForDebug() { void PrintDOMTreeForDebug() {
std::stringstream stream; std::stringstream stream;
stream << "\nPrintDOMTreeForDebug"; stream << "\nPrintDOMTreeForDebug";
...@@ -169,6 +194,12 @@ class LayoutSelectionTest : public EditingTestBase { ...@@ -169,6 +194,12 @@ class LayoutSelectionTest : public EditingTestBase {
} }
#endif #endif
std::string DumpSelectionInfo() {
std::stringstream stream;
PrintDOMTreeInternal(stream, *GetDocument().body(), 0u);
return stream.str();
}
private: private:
LayoutObject* current_ = nullptr; LayoutObject* current_ = nullptr;
}; };
...@@ -298,12 +329,12 @@ TEST_F(LayoutSelectionTest, TraverseLayoutObject) { ...@@ -298,12 +329,12 @@ TEST_F(LayoutSelectionTest, TraverseLayoutObject) {
.SelectAllChildren(*GetDocument().body()) .SelectAllChildren(*GetDocument().body())
.Build()); .Build());
Selection().CommitAppearanceIfNeeded(); Selection().CommitAppearanceIfNeeded();
TEST_RESET(); EXPECT_EQ(
TEST_NEXT(IsLayoutBlock, kContain, NotInvalidate); "BODY, Contain, NotInvalidate \n"
TEST_NEXT("foo", kStart, ShouldInvalidate); " 'foo', Start, ShouldInvalidate \n"
TEST_NEXT(IsBR, kInside, ShouldInvalidate); " BR, Inside, ShouldInvalidate \n"
TEST_NEXT("bar", kEnd, ShouldInvalidate); " 'bar', End, ShouldInvalidate ",
TEST_CHECK(); DumpSelectionInfo());
} }
TEST_F(LayoutSelectionTest, TraverseLayoutObjectTruncateVisibilityHidden) { TEST_F(LayoutSelectionTest, TraverseLayoutObjectTruncateVisibilityHidden) {
......
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