Index: third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator_test.cc |
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator_test.cc b/third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..620c886b04fc0ffd0e4656f9186b92cfe109890d |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator_test.cc |
@@ -0,0 +1,126 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "core/layout/ng/ng_block_child_iterator.h" |
+ |
+#include "core/layout/LayoutTestHelper.h" |
+#include "core/layout/ng/ng_block_break_token.h" |
+#include "core/layout/ng/ng_block_node.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace blink { |
+namespace { |
+ |
+#define CHILD_TOKEN_PAIR(child, token) \ |
+ std::make_pair(static_cast<NGLayoutInputNode*>(child), \ |
+ static_cast<NGBreakToken*>(token)) |
+ |
+class NGBlockChildIteratorTest : public RenderingTest {}; |
+ |
+TEST_F(NGBlockChildIteratorTest, testNullFirstChild) { |
+ NGBlockChildIterator iterator(nullptr, nullptr); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild()); |
+} |
+ |
+TEST_F(NGBlockChildIteratorTest, testNoBreakToken) { |
+ setBodyInnerHTML(R"HTML( |
mstensho (USE GERRIT)
2017/02/22 13:11:31
I see that setBodyInnerHTML() is used in existing
ikilpatrick
2017/02/22 18:47:19
We may want our own test runner which just updates
mstensho (USE GERRIT)
2017/02/22 20:09:23
Yeah, something like that. Sorry for bringing it u
ikilpatrick
2017/02/22 22:25:21
Np :), I might go through and normalize all our te
|
+ <div id='child1'></div> |
+ <div id='child2'></div> |
+ <div id='child3'></div> |
+ )HTML"); |
+ NGLayoutInputNode* node1 = new NGBlockNode( |
+ toLayoutBlockFlow(document().getElementById("child1")->layoutObject())); |
mstensho (USE GERRIT)
2017/02/22 13:11:31
You can use getLayoutObjectByElementId("id") inste
ikilpatrick
2017/02/22 18:47:20
Done.
|
+ NGLayoutInputNode* node2 = node1->NextSibling(); |
+ NGLayoutInputNode* node3 = node2->NextSibling(); |
+ |
+ // The iterator should loop through three children. |
+ NGBlockChildIterator iterator(node1, nullptr); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node1, nullptr), iterator.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node2, nullptr), iterator.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild()); |
+} |
+ |
+TEST_F(NGBlockChildIteratorTest, testBreakTokenWithFinishedChild) { |
+ setBodyInnerHTML(R"HTML( |
+ <div id='container'> |
+ <div id='child1'></div> |
+ <div id='child2'></div> |
+ <div id='child3'></div> |
+ </div> |
+ )HTML"); |
+ NGBlockNode* container = new NGBlockNode(toLayoutBlockFlow( |
+ document().getElementById("container")->layoutObject())); |
+ NGLayoutInputNode* node1 = container->FirstChild(); |
+ NGLayoutInputNode* node2 = node1->NextSibling(); |
+ NGLayoutInputNode* node3 = node2->NextSibling(); |
+ |
+ HeapVector<Member<NGBreakToken>> child_break_tokens; |
+ child_break_tokens.push_back(new NGBlockBreakToken(toNGBlockNode(node1))); |
+ NGBlockBreakToken* parent_token = |
+ new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens); |
+ |
+ // The iterator should loop through two children. |
+ NGBlockChildIterator iterator(node1, parent_token); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node2, nullptr), iterator.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild()); |
+ |
+ HeapVector<Member<NGBreakToken>> child_break_tokens2; |
mstensho (USE GERRIT)
2017/02/22 13:11:31
Unused. Did you mean to use it below? Otherwise, j
ikilpatrick
2017/02/22 18:47:20
Removed, and from other test.
|
+ child_break_tokens.push_back(new NGBlockBreakToken(toNGBlockNode(node2))); |
+ parent_token = |
+ new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens); |
+ |
+ // The iterator should loop through two children. |
+ NGBlockChildIterator iterator2(node1, parent_token); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node1, nullptr), iterator2.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator2.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator2.NextChild()); |
+} |
+ |
+TEST_F(NGBlockChildIteratorTest, testBreakTokenWithUnFinishedChild) { |
+ setBodyInnerHTML(R"HTML( |
+ <div id='container'> |
+ <div id='child1'></div> |
+ <div id='child2'></div> |
+ <div id='child3'></div> |
+ </div> |
+ )HTML"); |
+ NGBlockNode* container = new NGBlockNode(toLayoutBlockFlow( |
+ document().getElementById("container")->layoutObject())); |
+ NGLayoutInputNode* node1 = container->FirstChild(); |
+ NGLayoutInputNode* node2 = node1->NextSibling(); |
+ NGLayoutInputNode* node3 = node2->NextSibling(); |
+ |
+ HeapVector<Member<NGBreakToken>> child_break_tokens; |
+ NGBreakToken* child_token = new NGBlockBreakToken( |
+ toNGBlockNode(node1), LayoutUnit(), child_break_tokens); |
+ child_break_tokens.push_back(child_token); |
+ NGBlockBreakToken* parent_token = |
+ new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens); |
+ |
+ // The iterator should loop through three children, one with a break token. |
+ NGBlockChildIterator iterator(node1, parent_token); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node1, child_token), iterator.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node2, nullptr), iterator.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild()); |
+ |
+ HeapVector<Member<NGBreakToken>> child_break_tokens2; |
+ child_token = new NGBlockBreakToken(toNGBlockNode(node2), LayoutUnit(), |
+ child_break_tokens2); |
+ child_break_tokens2.push_back(child_token); |
+ parent_token = |
+ new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens2); |
+ |
+ // The iterator should loop through three children, one with a break token. |
+ NGBlockChildIterator iterator2(node1, parent_token); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node1, nullptr), iterator2.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node2, child_token), iterator2.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator2.NextChild()); |
+ EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator2.NextChild()); |
+} |
+ |
+} // namespace |
+} // namespace blink |