Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator_test.cc

Issue 2706353004: [LayoutNG] Introduce block child iterator. (Closed)
Patch Set: address comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/layout/ng/ng_block_child_iterator.h"
6
7 #include "core/layout/LayoutTestHelper.h"
8 #include "core/layout/ng/ng_block_break_token.h"
9 #include "core/layout/ng/ng_block_node.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace blink {
13 namespace {
14
15 #define CHILD_TOKEN_PAIR(child, token) \
16 std::make_pair(static_cast<NGLayoutInputNode*>(child), \
17 static_cast<NGBreakToken*>(token))
18
19 class NGBlockChildIteratorTest : public RenderingTest {};
20
21 TEST_F(NGBlockChildIteratorTest, testNullFirstChild) {
22 NGBlockChildIterator iterator(nullptr, nullptr);
23 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild());
24 }
25
26 TEST_F(NGBlockChildIteratorTest, testNoBreakToken) {
27 setBodyInnerHTML(R"HTML(
28 <div id='child1'></div>
29 <div id='child2'></div>
30 <div id='child3'></div>
31 )HTML");
32 NGLayoutInputNode* node1 =
33 new NGBlockNode(toLayoutBlockFlow(getLayoutObjectByElementId("child1")));
34 NGLayoutInputNode* node2 = node1->NextSibling();
35 NGLayoutInputNode* node3 = node2->NextSibling();
36
37 // The iterator should loop through three children.
38 NGBlockChildIterator iterator(node1, nullptr);
39 EXPECT_EQ(CHILD_TOKEN_PAIR(node1, nullptr), iterator.NextChild());
40 EXPECT_EQ(CHILD_TOKEN_PAIR(node2, nullptr), iterator.NextChild());
41 EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator.NextChild());
42 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild());
43 }
44
45 TEST_F(NGBlockChildIteratorTest, testBreakTokenWithFinishedChild) {
46 setBodyInnerHTML(R"HTML(
47 <div id='container'>
48 <div id='child1'></div>
49 <div id='child2'></div>
50 <div id='child3'></div>
51 </div>
52 )HTML");
53 NGBlockNode* container = new NGBlockNode(
54 toLayoutBlockFlow(getLayoutObjectByElementId("container")));
55 NGLayoutInputNode* node1 = container->FirstChild();
56 NGLayoutInputNode* node2 = node1->NextSibling();
57 NGLayoutInputNode* node3 = node2->NextSibling();
58
59 HeapVector<Member<NGBreakToken>> child_break_tokens;
60 child_break_tokens.push_back(new NGBlockBreakToken(toNGBlockNode(node1)));
61 NGBlockBreakToken* parent_token =
62 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens);
63
64 // The iterator should loop through two children.
65 NGBlockChildIterator iterator(node1, parent_token);
66 EXPECT_EQ(CHILD_TOKEN_PAIR(node2, nullptr), iterator.NextChild());
67 EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator.NextChild());
68 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild());
69
70 child_break_tokens.push_back(new NGBlockBreakToken(toNGBlockNode(node2)));
71 parent_token =
72 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens);
73
74 // The iterator should loop through two children.
75 NGBlockChildIterator iterator2(node1, parent_token);
76 EXPECT_EQ(CHILD_TOKEN_PAIR(node1, nullptr), iterator2.NextChild());
77 EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator2.NextChild());
78 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator2.NextChild());
79 }
80
81 TEST_F(NGBlockChildIteratorTest, testBreakTokenWithUnFinishedChild) {
82 setBodyInnerHTML(R"HTML(
83 <div id='container'>
84 <div id='child1'></div>
85 <div id='child2'></div>
86 <div id='child3'></div>
87 </div>
88 )HTML");
89 NGBlockNode* container = new NGBlockNode(
90 toLayoutBlockFlow(getLayoutObjectByElementId("container")));
91 NGLayoutInputNode* node1 = container->FirstChild();
92 NGLayoutInputNode* node2 = node1->NextSibling();
93 NGLayoutInputNode* node3 = node2->NextSibling();
94
95 HeapVector<Member<NGBreakToken>> child_break_tokens;
96 NGBreakToken* child_token = new NGBlockBreakToken(
97 toNGBlockNode(node1), LayoutUnit(), child_break_tokens);
98 child_break_tokens.push_back(child_token);
99 NGBlockBreakToken* parent_token =
100 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens);
101
102 // The iterator should loop through three children, one with a break token.
103 NGBlockChildIterator iterator(node1, parent_token);
104 EXPECT_EQ(CHILD_TOKEN_PAIR(node1, child_token), iterator.NextChild());
105 EXPECT_EQ(CHILD_TOKEN_PAIR(node2, nullptr), iterator.NextChild());
106 EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator.NextChild());
107 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild());
108
109 child_token = new NGBlockBreakToken(toNGBlockNode(node2), LayoutUnit(),
110 child_break_tokens);
111 child_break_tokens.push_back(child_token);
112 parent_token =
113 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens);
114
115 // The iterator should loop through three children, one with a break token.
116 NGBlockChildIterator iterator2(node1, parent_token);
117 EXPECT_EQ(CHILD_TOKEN_PAIR(node1, nullptr), iterator2.NextChild());
118 EXPECT_EQ(CHILD_TOKEN_PAIR(node2, child_token), iterator2.NextChild());
119 EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator2.NextChild());
120 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator2.NextChild());
121 }
122
123 } // namespace
124 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698