| 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_constraint_space.h" | 5 #include "core/layout/ng/ng_constraint_space.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 7 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 static String OpportunityToString(const NGConstraintSpace* opportunity) { | 47 static String OpportunityToString(const NGConstraintSpace* opportunity) { |
| 48 return opportunity ? opportunity->ToString() : String("(null)"); | 48 return opportunity ? opportunity->ToString() : String("(null)"); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { | 51 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { |
| 52 NGPhysicalSize physical_size; | 52 NGPhysicalSize physical_size; |
| 53 physical_size.width = LayoutUnit(600); | 53 physical_size.width = LayoutUnit(600); |
| 54 physical_size.height = LayoutUnit(400); | 54 physical_size.height = LayoutUnit(400); |
| 55 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); | 55 NGPhysicalConstraintSpace physical_space(physical_size); |
| 56 auto* space = | 56 auto* space = |
| 57 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); | 57 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, &physical_space); |
| 58 | 58 |
| 59 bool for_inline_or_bfc = true; | 59 bool for_inline_or_bfc = true; |
| 60 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); | 60 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); |
| 61 | 61 |
| 62 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); | 62 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); |
| 63 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); | 63 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { | 66 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { |
| 67 NGPhysicalSize physical_size; | 67 NGPhysicalSize physical_size; |
| 68 physical_size.width = LayoutUnit(600); | 68 physical_size.width = LayoutUnit(600); |
| 69 physical_size.height = LayoutUnit(400); | 69 physical_size.height = LayoutUnit(400); |
| 70 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); | 70 NGPhysicalConstraintSpace physical_space(physical_size); |
| 71 | 71 |
| 72 // Add a 100x100 exclusion in the top right corner. | 72 // Add a 100x100 exclusion in the top right corner. |
| 73 physical_space->AddExclusion(NGExclusion(LayoutUnit(0), LayoutUnit(600), | 73 physical_space.AddExclusion(NGExclusion(LayoutUnit(0), LayoutUnit(600), |
| 74 LayoutUnit(100), LayoutUnit(500))); | 74 LayoutUnit(100), LayoutUnit(500))); |
| 75 | 75 |
| 76 auto* space = | 76 auto* space = |
| 77 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); | 77 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, &physical_space); |
| 78 bool for_inline_or_bfc = true; | 78 bool for_inline_or_bfc = true; |
| 79 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); | 79 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); |
| 80 | 80 |
| 81 // First opportunity should be to the left of the exclusion. | 81 // First opportunity should be to the left of the exclusion. |
| 82 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); | 82 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); |
| 83 | 83 |
| 84 // Second opportunity should be below the exclusion. | 84 // Second opportunity should be below the exclusion. |
| 85 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 85 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
| 86 | 86 |
| 87 // There should be no third opportunity. | 87 // There should be no third opportunity. |
| 88 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); | 88 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); |
| 89 } | 89 } |
| 90 | 90 |
| 91 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { | 91 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { |
| 92 NGPhysicalSize physical_size; | 92 NGPhysicalSize physical_size; |
| 93 physical_size.width = LayoutUnit(600); | 93 physical_size.width = LayoutUnit(600); |
| 94 physical_size.height = LayoutUnit(400); | 94 physical_size.height = LayoutUnit(400); |
| 95 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); | 95 NGPhysicalConstraintSpace physical_space(physical_size); |
| 96 | 96 |
| 97 // Add a 100x100 exclusion in the top left corner. | 97 // Add a 100x100 exclusion in the top left corner. |
| 98 physical_space->AddExclusion(NGExclusion(LayoutUnit(0), LayoutUnit(100), | 98 physical_space.AddExclusion(NGExclusion(LayoutUnit(0), LayoutUnit(100), |
| 99 LayoutUnit(100), LayoutUnit(0))); | 99 LayoutUnit(100), LayoutUnit(0))); |
| 100 | 100 |
| 101 auto* space = | 101 auto* space = |
| 102 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); | 102 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, &physical_space); |
| 103 bool for_inline_or_bfc = true; | 103 bool for_inline_or_bfc = true; |
| 104 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); | 104 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); |
| 105 | 105 |
| 106 // First opportunity should be to the right of the exclusion. | 106 // First opportunity should be to the right of the exclusion. |
| 107 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); | 107 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); |
| 108 | 108 |
| 109 // Second opportunity should be below the exclusion. | 109 // Second opportunity should be below the exclusion. |
| 110 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 110 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
| 111 | 111 |
| 112 // There should be no third opportunity. | 112 // There should be no third opportunity. |
| 113 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); | 113 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); |
| 114 } | 114 } |
| 115 | 115 |
| 116 // 100 200 300 400 500 | 116 // 100 200 300 400 500 |
| 117 // +----|----|----|----|----|----+ | 117 // +----|----|----|----|----|----+ |
| 118 // 50 | | | 118 // 50 | | |
| 119 // 100 | | | 119 // 100 | | |
| 120 // 150 | | | 120 // 150 | | |
| 121 // 200 | ********** | | 121 // 200 | ********** | |
| 122 // 250 | ********** | | 122 // 250 | ********** | |
| 123 // 300 | | | 123 // 300 | | |
| 124 // 350 | *** | | 124 // 350 | *** | |
| 125 // +-----------------------------+ | 125 // +-----------------------------+ |
| 126 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { | 126 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { |
| 127 NGPhysicalSize physical_size; | 127 NGPhysicalSize physical_size; |
| 128 physical_size.width = LayoutUnit(600); | 128 physical_size.width = LayoutUnit(600); |
| 129 physical_size.height = LayoutUnit(400); | 129 physical_size.height = LayoutUnit(400); |
| 130 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); | 130 NGPhysicalConstraintSpace physical_space(physical_size); |
| 131 | 131 |
| 132 // Add a 200x100 exclusion at 150x200 | 132 // Add a 200x100 exclusion at 150x200 |
| 133 physical_space->AddExclusion(NGExclusion(LayoutUnit(200), LayoutUnit(250), | 133 physical_space.AddExclusion(NGExclusion(LayoutUnit(200), LayoutUnit(250), |
| 134 LayoutUnit(300), LayoutUnit(150))); | 134 LayoutUnit(300), LayoutUnit(150))); |
| 135 // Add a 50x50 exclusion at 500x350 | 135 // Add a 50x50 exclusion at 500x350 |
| 136 physical_space->AddExclusion(NGExclusion(LayoutUnit(350), LayoutUnit(550), | 136 physical_space.AddExclusion(NGExclusion(LayoutUnit(350), LayoutUnit(550), |
| 137 LayoutUnit(400), LayoutUnit(500))); | 137 LayoutUnit(400), LayoutUnit(500))); |
| 138 | 138 |
| 139 auto* space = | 139 auto* space = |
| 140 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); | 140 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, &physical_space); |
| 141 bool for_inline_or_bfc = true; | 141 bool for_inline_or_bfc = true; |
| 142 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); | 142 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); |
| 143 | 143 |
| 144 // First opportunity should be above the first exclusion. | 144 // First opportunity should be above the first exclusion. |
| 145 EXPECT_EQ("0,0 600x200", OpportunityToString(iterator->Next())); | 145 EXPECT_EQ("0,0 600x200", OpportunityToString(iterator->Next())); |
| 146 | 146 |
| 147 // Second opportunity should be full height to the left. | 147 // Second opportunity should be full height to the left. |
| 148 EXPECT_EQ("0,0 150x400", OpportunityToString(iterator->Next())); | 148 EXPECT_EQ("0,0 150x400", OpportunityToString(iterator->Next())); |
| 149 | 149 |
| 150 // Third opportunity should be to the left of the first exclusion. This is a | 150 // Third opportunity should be to the left of the first exclusion. This is a |
| (...skipping 22 matching lines...) Expand all Loading... |
| 173 // Ninth exclusion should be to the right of the last exclusion. | 173 // Ninth exclusion should be to the right of the last exclusion. |
| 174 EXPECT_EQ("550,350 50x50", OpportunityToString(iterator->Next())); | 174 EXPECT_EQ("550,350 50x50", OpportunityToString(iterator->Next())); |
| 175 | 175 |
| 176 // There should be no tenth opportunity. | 176 // There should be no tenth opportunity. |
| 177 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); | 177 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace | 180 } // namespace |
| 181 | 181 |
| 182 } // namespace blink | 182 } // namespace blink |
| OLD | NEW |