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

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: . 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(
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
28 <div id='child1'></div>
29 <div id='child2'></div>
30 <div id='child3'></div>
31 )HTML");
32 NGLayoutInputNode* node1 = new NGBlockNode(
33 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.
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(toLayoutBlockFlow(
54 document().getElementById("container")->layoutObject()));
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 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.
71 child_break_tokens.push_back(new NGBlockBreakToken(toNGBlockNode(node2)));
72 parent_token =
73 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens);
74
75 // The iterator should loop through two children.
76 NGBlockChildIterator iterator2(node1, parent_token);
77 EXPECT_EQ(CHILD_TOKEN_PAIR(node1, nullptr), iterator2.NextChild());
78 EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator2.NextChild());
79 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator2.NextChild());
80 }
81
82 TEST_F(NGBlockChildIteratorTest, testBreakTokenWithUnFinishedChild) {
83 setBodyInnerHTML(R"HTML(
84 <div id='container'>
85 <div id='child1'></div>
86 <div id='child2'></div>
87 <div id='child3'></div>
88 </div>
89 )HTML");
90 NGBlockNode* container = new NGBlockNode(toLayoutBlockFlow(
91 document().getElementById("container")->layoutObject()));
92 NGLayoutInputNode* node1 = container->FirstChild();
93 NGLayoutInputNode* node2 = node1->NextSibling();
94 NGLayoutInputNode* node3 = node2->NextSibling();
95
96 HeapVector<Member<NGBreakToken>> child_break_tokens;
97 NGBreakToken* child_token = new NGBlockBreakToken(
98 toNGBlockNode(node1), LayoutUnit(), child_break_tokens);
99 child_break_tokens.push_back(child_token);
100 NGBlockBreakToken* parent_token =
101 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens);
102
103 // The iterator should loop through three children, one with a break token.
104 NGBlockChildIterator iterator(node1, parent_token);
105 EXPECT_EQ(CHILD_TOKEN_PAIR(node1, child_token), iterator.NextChild());
106 EXPECT_EQ(CHILD_TOKEN_PAIR(node2, nullptr), iterator.NextChild());
107 EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator.NextChild());
108 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator.NextChild());
109
110 HeapVector<Member<NGBreakToken>> child_break_tokens2;
111 child_token = new NGBlockBreakToken(toNGBlockNode(node2), LayoutUnit(),
112 child_break_tokens2);
113 child_break_tokens2.push_back(child_token);
114 parent_token =
115 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens2);
116
117 // The iterator should loop through three children, one with a break token.
118 NGBlockChildIterator iterator2(node1, parent_token);
119 EXPECT_EQ(CHILD_TOKEN_PAIR(node1, nullptr), iterator2.NextChild());
120 EXPECT_EQ(CHILD_TOKEN_PAIR(node2, child_token), iterator2.NextChild());
121 EXPECT_EQ(CHILD_TOKEN_PAIR(node3, nullptr), iterator2.NextChild());
122 EXPECT_EQ(CHILD_TOKEN_PAIR(nullptr, nullptr), iterator2.NextChild());
123 }
124
125 } // namespace
126 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698