OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/layout/ng/ng_block_node.h" | 5 #include "core/layout/ng/ng_block_node.h" |
6 | 6 |
7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
8 #include "core/layout/ng/ng_box_fragment.h" | 8 #include "core/layout/ng/ng_box_fragment.h" |
9 #include "core/layout/ng/ng_min_max_content_size.h" | 9 #include "core/layout/ng/ng_min_max_content_size.h" |
10 #include "core/style/ComputedStyle.h" | 10 #include "core/style/ComputedStyle.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 namespace { | 14 namespace { |
15 class NGBlockNodeForTest : public RenderingTest { | 15 class NGBlockNodeForTest : public RenderingTest { |
16 public: | 16 public: |
17 NGBlockNodeForTest() { RuntimeEnabledFeatures::setLayoutNGEnabled(true); } | 17 NGBlockNodeForTest() { RuntimeEnabledFeatures::setLayoutNGEnabled(true); } |
18 ~NGBlockNodeForTest() { RuntimeEnabledFeatures::setLayoutNGEnabled(false); }; | 18 ~NGBlockNodeForTest() { RuntimeEnabledFeatures::setLayoutNGEnabled(false); }; |
19 }; | 19 }; |
20 | 20 |
| 21 TEST_F(NGBlockNodeForTest, ChildInlineAndBlock) { |
| 22 SetBodyInnerHTML(R"HTML( |
| 23 <!DOCTYPE html> |
| 24 <div id=container>Hello!<div></div></div> |
| 25 )HTML"); |
| 26 NGBlockNode* container = |
| 27 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 28 NGLayoutInputNode* child1 = container->FirstChild(); |
| 29 EXPECT_TRUE(child1 && child1->IsBlock()); |
| 30 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 31 EXPECT_TRUE(child2 && child2->IsBlock()); |
| 32 NGLayoutInputNode* child3 = child2->NextSibling(); |
| 33 EXPECT_EQ(child3, nullptr); |
| 34 } |
| 35 |
| 36 TEST_F(NGBlockNodeForTest, ChildBlockAndInline) { |
| 37 SetBodyInnerHTML(R"HTML( |
| 38 <!DOCTYPE html> |
| 39 <div id=container><div></div>Hello!</div> |
| 40 )HTML"); |
| 41 NGBlockNode* container = |
| 42 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 43 NGLayoutInputNode* child1 = container->FirstChild(); |
| 44 EXPECT_TRUE(child1 && child1->IsBlock()); |
| 45 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 46 EXPECT_TRUE(child2 && child2->IsBlock()); |
| 47 NGLayoutInputNode* child3 = child2->NextSibling(); |
| 48 EXPECT_EQ(child3, nullptr); |
| 49 } |
| 50 |
| 51 TEST_F(NGBlockNodeForTest, ChildFloatBeforeBlock) { |
| 52 SetBodyInnerHTML(R"HTML( |
| 53 <!DOCTYPE html> |
| 54 <style> |
| 55 float { float: left; } |
| 56 </style> |
| 57 <div id=container><float></float><div></div></div> |
| 58 )HTML"); |
| 59 NGBlockNode* container = |
| 60 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 61 NGLayoutInputNode* child1 = container->FirstChild(); |
| 62 EXPECT_TRUE(child1 && child1->IsBlock()); |
| 63 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 64 EXPECT_TRUE(child2 && child2->IsBlock()); |
| 65 NGLayoutInputNode* child3 = child2->NextSibling(); |
| 66 EXPECT_EQ(child3, nullptr); |
| 67 } |
| 68 |
| 69 TEST_F(NGBlockNodeForTest, ChildFloatBeforeInline) { |
| 70 SetBodyInnerHTML(R"HTML( |
| 71 <!DOCTYPE html> |
| 72 <style> |
| 73 float { float: left; } |
| 74 </style> |
| 75 <div id=container><float></float>Hello!</div> |
| 76 )HTML"); |
| 77 NGBlockNode* container = |
| 78 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 79 NGLayoutInputNode* child1 = container->FirstChild(); |
| 80 EXPECT_TRUE(child1 && child1->IsInline()); |
| 81 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 82 EXPECT_EQ(child2, nullptr); |
| 83 } |
| 84 |
| 85 TEST_F(NGBlockNodeForTest, ChildFloatAfterInline) { |
| 86 SetBodyInnerHTML(R"HTML( |
| 87 <!DOCTYPE html> |
| 88 <style> |
| 89 float { float: left; } |
| 90 </style> |
| 91 <div id=container>Hello<float></float></div> |
| 92 )HTML"); |
| 93 NGBlockNode* container = |
| 94 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 95 NGLayoutInputNode* child1 = container->FirstChild(); |
| 96 EXPECT_TRUE(child1 && child1->IsInline()); |
| 97 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 98 EXPECT_EQ(child2, nullptr); |
| 99 } |
| 100 |
| 101 TEST_F(NGBlockNodeForTest, ChildFloatOnly) { |
| 102 SetBodyInnerHTML(R"HTML( |
| 103 <!DOCTYPE html> |
| 104 <style> |
| 105 float { float: left; } |
| 106 </style> |
| 107 <div id=container><float></float></div> |
| 108 )HTML"); |
| 109 NGBlockNode* container = |
| 110 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 111 NGLayoutInputNode* child1 = container->FirstChild(); |
| 112 EXPECT_TRUE(child1 && child1->IsBlock()); |
| 113 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 114 EXPECT_EQ(child2, nullptr); |
| 115 } |
| 116 |
| 117 TEST_F(NGBlockNodeForTest, ChildFloatWithSpaces) { |
| 118 SetBodyInnerHTML(R"HTML( |
| 119 <!DOCTYPE html> |
| 120 <style> |
| 121 float { float: left; } |
| 122 </style> |
| 123 <div id=container> |
| 124 <float></float> |
| 125 </div> |
| 126 )HTML"); |
| 127 NGBlockNode* container = |
| 128 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 129 NGLayoutInputNode* child1 = container->FirstChild(); |
| 130 EXPECT_TRUE(child1 && child1->IsBlock()); |
| 131 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 132 EXPECT_EQ(child2, nullptr); |
| 133 } |
| 134 |
| 135 TEST_F(NGBlockNodeForTest, ChildOofBeforeInline) { |
| 136 SetBodyInnerHTML(R"HTML( |
| 137 <!DOCTYPE html> |
| 138 <style> |
| 139 oof { position: absolute; } |
| 140 </style> |
| 141 <div id=container><oof></oof>Hello!</div> |
| 142 )HTML"); |
| 143 NGBlockNode* container = |
| 144 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 145 NGLayoutInputNode* child1 = container->FirstChild(); |
| 146 EXPECT_TRUE(child1 && child1->IsInline()); |
| 147 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 148 EXPECT_EQ(child2, nullptr); |
| 149 } |
| 150 |
| 151 TEST_F(NGBlockNodeForTest, ChildOofAfterInline) { |
| 152 SetBodyInnerHTML(R"HTML( |
| 153 <!DOCTYPE html> |
| 154 <style> |
| 155 oof { position: absolute; } |
| 156 </style> |
| 157 <div id=container>Hello!<oof></oof></div> |
| 158 )HTML"); |
| 159 NGBlockNode* container = |
| 160 new NGBlockNode(GetLayoutObjectByElementId("container")); |
| 161 NGLayoutInputNode* child1 = container->FirstChild(); |
| 162 EXPECT_TRUE(child1 && child1->IsInline()); |
| 163 NGLayoutInputNode* child2 = child1->NextSibling(); |
| 164 EXPECT_EQ(child2, nullptr); |
| 165 } |
| 166 |
21 TEST_F(NGBlockNodeForTest, MinAndMaxContent) { | 167 TEST_F(NGBlockNodeForTest, MinAndMaxContent) { |
22 SetBodyInnerHTML(R"HTML( | 168 SetBodyInnerHTML(R"HTML( |
23 <div id="box" > | 169 <div id="box" > |
24 <div id="first_child" style="width:30px"> | 170 <div id="first_child" style="width:30px"> |
25 </div> | 171 </div> |
26 </div> | 172 </div> |
27 )HTML"); | 173 )HTML"); |
28 const int kWidth = 30; | 174 const int kWidth = 30; |
29 | 175 |
30 NGBlockNode* box = new NGBlockNode(GetLayoutObjectByElementId("box")); | 176 NGBlockNode* box = new NGBlockNode(GetLayoutObjectByElementId("box")); |
31 MinMaxContentSize sizes = box->ComputeMinMaxContentSize(); | 177 MinMaxContentSize sizes = box->ComputeMinMaxContentSize(); |
32 EXPECT_EQ(LayoutUnit(kWidth), sizes.min_content); | 178 EXPECT_EQ(LayoutUnit(kWidth), sizes.min_content); |
33 EXPECT_EQ(LayoutUnit(kWidth), sizes.max_content); | 179 EXPECT_EQ(LayoutUnit(kWidth), sizes.max_content); |
34 } | 180 } |
35 } // namespace | 181 } // namespace |
36 } // namespace blink | 182 } // namespace blink |
OLD | NEW |