OLD | NEW |
---|---|
(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 class NGBlockChildIteratorTest : public RenderingTest {}; | |
16 | |
17 TEST_F(NGBlockChildIteratorTest, testNullFirstChild) { | |
Gleb Lanbin
2017/02/22 20:52:10
1) testNullFirstChild is a function name, so it sh
ikilpatrick
2017/02/22 22:25:22
Done.
| |
18 NGBlockChildIterator iterator(nullptr, nullptr); | |
19 EXPECT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr), | |
20 iterator.NextChild()); | |
21 } | |
22 | |
23 TEST_F(NGBlockChildIteratorTest, testNoBreakToken) { | |
24 setBodyInnerHTML(R"HTML( | |
25 <div id='child1'></div> | |
26 <div id='child2'></div> | |
27 <div id='child3'></div> | |
28 )HTML"); | |
29 NGLayoutInputNode* node1 = | |
30 new NGBlockNode(toLayoutBlockFlow(getLayoutObjectByElementId("child1"))); | |
31 NGLayoutInputNode* node2 = node1->NextSibling(); | |
32 NGLayoutInputNode* node3 = node2->NextSibling(); | |
33 | |
34 // The iterator should loop through three children. | |
35 NGBlockChildIterator iterator(node1, nullptr); | |
36 EXPECT_EQ(NGBlockChildIterator::Entry(node1, nullptr), iterator.NextChild()); | |
Gleb Lanbin
2017/02/22 20:52:10
.nit
s/EXPECT_EQ/ASSERT_EQ/g "Assert" will halt t
ikilpatrick
2017/02/22 22:25:22
Done.
| |
37 EXPECT_EQ(NGBlockChildIterator::Entry(node2, nullptr), iterator.NextChild()); | |
38 EXPECT_EQ(NGBlockChildIterator::Entry(node3, nullptr), iterator.NextChild()); | |
39 EXPECT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr), | |
40 iterator.NextChild()); | |
41 } | |
42 | |
43 TEST_F(NGBlockChildIteratorTest, testBreakTokenWithFinishedChild) { | |
44 setBodyInnerHTML(R"HTML( | |
45 <div id='container'> | |
46 <div id='child1'></div> | |
47 <div id='child2'></div> | |
48 <div id='child3'></div> | |
49 </div> | |
50 )HTML"); | |
51 NGBlockNode* container = new NGBlockNode( | |
52 toLayoutBlockFlow(getLayoutObjectByElementId("container"))); | |
53 NGLayoutInputNode* node1 = container->FirstChild(); | |
54 NGLayoutInputNode* node2 = node1->NextSibling(); | |
55 NGLayoutInputNode* node3 = node2->NextSibling(); | |
56 | |
57 HeapVector<Member<NGBreakToken>> child_break_tokens; | |
58 child_break_tokens.push_back(new NGBlockBreakToken(toNGBlockNode(node1))); | |
59 NGBlockBreakToken* parent_token = | |
60 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens); | |
61 | |
62 // The iterator should loop through two children. | |
63 NGBlockChildIterator iterator(node1, parent_token); | |
64 EXPECT_EQ(NGBlockChildIterator::Entry(node2, nullptr), iterator.NextChild()); | |
65 EXPECT_EQ(NGBlockChildIterator::Entry(node3, nullptr), iterator.NextChild()); | |
66 EXPECT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr), | |
67 iterator.NextChild()); | |
68 | |
69 child_break_tokens.push_back(new NGBlockBreakToken(toNGBlockNode(node2))); | |
70 parent_token = | |
71 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens); | |
72 | |
73 // The iterator should loop through two children. | |
74 NGBlockChildIterator iterator2(node1, parent_token); | |
75 EXPECT_EQ(NGBlockChildIterator::Entry(node1, nullptr), iterator2.NextChild()); | |
76 EXPECT_EQ(NGBlockChildIterator::Entry(node3, nullptr), iterator2.NextChild()); | |
77 EXPECT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr), | |
78 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(NGBlockChildIterator::Entry(node1, child_token), | |
105 iterator.NextChild()); | |
106 EXPECT_EQ(NGBlockChildIterator::Entry(node2, nullptr), iterator.NextChild()); | |
107 EXPECT_EQ(NGBlockChildIterator::Entry(node3, nullptr), iterator.NextChild()); | |
108 EXPECT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr), | |
109 iterator.NextChild()); | |
110 | |
111 child_token = new NGBlockBreakToken(toNGBlockNode(node2), LayoutUnit(), | |
112 child_break_tokens); | |
113 child_break_tokens.push_back(child_token); | |
114 parent_token = | |
115 new NGBlockBreakToken(container, LayoutUnit(50), child_break_tokens); | |
116 | |
117 // The iterator should loop through three children, one with a break token. | |
118 NGBlockChildIterator iterator2(node1, parent_token); | |
119 EXPECT_EQ(NGBlockChildIterator::Entry(node1, nullptr), iterator2.NextChild()); | |
120 EXPECT_EQ(NGBlockChildIterator::Entry(node2, child_token), | |
121 iterator2.NextChild()); | |
122 EXPECT_EQ(NGBlockChildIterator::Entry(node3, nullptr), iterator2.NextChild()); | |
123 EXPECT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr), | |
124 iterator2.NextChild()); | |
125 } | |
126 | |
127 } // namespace | |
128 } // namespace blink | |
OLD | NEW |