#include "ui/views/layout/flex_layout.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/test/test_views.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
namespace views {
namespace {
Insets;
Point;
Rect;
Size;
optional;
class MockView : public View { … };
BEGIN_METADATA(…)
Size CustomFlexImpl(bool snap_to_zero,
const View* view,
const SizeBounds& maximum_size) { … }
class FlexLayoutTest : public testing::Test { … };
constexpr Insets FlexLayoutTest::kSmallInsets;
constexpr Insets FlexLayoutTest::kLayoutInsets;
constexpr Insets FlexLayoutTest::kLargeInsets;
constexpr Size FlexLayoutTest::kChild1Size;
constexpr Size FlexLayoutTest::kChild2Size;
constexpr Size FlexLayoutTest::kChild3Size;
const FlexSpecification FlexLayoutTest::kPreferredAdjustHeight = …;
const FlexSpecification FlexLayoutTest::kDropOut = …;
const FlexSpecification FlexLayoutTest::kDropOutHighPriority = …;
const FlexSpecification FlexLayoutTest::kFlex1ScaleToZero = …;
const FlexSpecification FlexLayoutTest::kFlex1ScaleToMinimum = …;
const FlexSpecification FlexLayoutTest::kFlex2ScaleToMinimum = …;
const FlexSpecification FlexLayoutTest::kFlex1ScaleToMinimumHighPriority = …;
const FlexSpecification FlexLayoutTest::kUnbounded = …;
const FlexSpecification FlexLayoutTest::kUnboundedSnapToMinimum = …;
const FlexSpecification FlexLayoutTest::kUnboundedSnapToZero = …;
const FlexSpecification FlexLayoutTest::kUnboundedScaleToMinimumSnapToZero = …;
const FlexSpecification FlexLayoutTest::kUnboundedScaleToZero = …;
const FlexSpecification FlexLayoutTest::kUnboundedScaleToZeroAdjustHeight = …;
const FlexSpecification FlexLayoutTest::kUnboundedScaleToMinimumHighPriority(
MinimumFlexSizeRule::kScaleToMinimum,
MaximumFlexSizeRule::kUnbounded);
const FlexSpecification FlexLayoutTest::kUnboundedScaleToMinimum = …;
const FlexSpecification FlexLayoutTest::kUnboundedSnapToMinimumHorizontal = …;
const FlexSpecification
FlexLayoutTest::kUnboundedScaleToMinimumSnapToZeroHorizontal = …;
const FlexSpecification FlexLayoutTest::kUnboundedScaleToZeroHorizontal = …;
const FlexSpecification FlexLayoutTest::kScaleToMaximum = …;
const FlexSpecification FlexLayoutTest::kCustomFlex = …;
const FlexSpecification FlexLayoutTest::kCustomFlexSnapToZero = …;
}
TEST_F(FlexLayoutTest, GetMinimumSize_Empty) { … }
TEST_F(FlexLayoutTest, GetMinimumSize_Empty_ViewInsets_Horizontal) { … }
TEST_F(FlexLayoutTest, GetMinimumSize_Empty_ViewInsets_Vertical) { … }
TEST_F(FlexLayoutTest, GetMinimumSize_Empty_InternalMargin_Collapsed) { … }
TEST_F(FlexLayoutTest, GetMinimumSize_Empty_InternalMargin_NotCollapsed) { … }
TEST_F(FlexLayoutTest,
GetMinimumSize_Empty_InternalMargin_DefaultMarginHasNoEffect) { … }
TEST_F(FlexLayoutTest, GetMinimumSize_MinimumCross_Horizontal) { … }
TEST_F(FlexLayoutTest, GetMinimumSize_MinimumCross_Vertical) { … }
TEST_F(FlexLayoutTest, Layout_VisibilitySetBeforeInstall) { … }
TEST_F(FlexLayoutTest, Layout_VisibilitySetAfterInstall) { … }
TEST_F(FlexLayoutTest, Layout_VisibilitySetBeforeAdd) { … }
TEST_F(FlexLayoutTest, Layout_VisibilitySetAfterAdd) { … }
TEST_F(FlexLayoutTest,
Layout_ViewVisibilitySetNotContingentOnActualVisibility) { … }
TEST_F(FlexLayoutTest, Layout_Exlcude) { … }
TEST_F(FlexLayoutTest, LayoutSingleView_Horizontal) { … }
TEST_F(FlexLayoutTest, LayoutSingleView_Vertical) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_Horizontal_CrossStart) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_Horizontal_CrossCenter) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_Horizontal_CrossEnd) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_Horizontal_CrossStretch) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_Vertical_CrossStart) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_Vertical_CrossCenter) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_Vertical_CrossEnd) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_Vertical_CrossStretch) { … }
TEST_F(FlexLayoutTest,
LayoutMultipleViews_MarginAndSpacing_NoCollapse_Horizontal) { … }
TEST_F(FlexLayoutTest,
LayoutMultipleViews_MarginAndSpacing_NoCollapse_Vertical) { … }
TEST_F(FlexLayoutTest,
LayoutMultipleViews_MarginAndSpacing_Collapse_Horizontal) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_MarginAndSpacing_Collapse_Vertical) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_InteriorPadding) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_InteriorPadding_Margins) { … }
TEST_F(FlexLayoutTest, LayoutMultipleViews_InteriorPadding_Additive) { … }
TEST_F(FlexLayoutTest, HeightForWidth_Vertical_CrossStart) { … }
TEST_F(FlexLayoutTest,
HeightForWidth_Vertical_CrossStretch_WidthChangesHeight) { … }
TEST_F(FlexLayoutTest, HeightForWidth_Vertical_CrossStretch_FlexPreferredSize) { … }
TEST_F(FlexLayoutTest, HeightForWidth_Vertical_CrossStretch_FlexLarger) { … }
TEST_F(FlexLayoutTest, HeightForWidth_Vertical_CrossStretch_FlexSmaller) { … }
TEST_F(FlexLayoutTest, HeightForWidth_Horizontal_PreferredSize) { … }
TEST_F(FlexLayoutTest, Layout_HostInsets_Horizontal) { … }
TEST_F(FlexLayoutTest, Layout_HostInsets_Vertical) { … }
TEST_F(FlexLayoutTest, Layout_HostInsets_Horizontal_Leading) { … }
TEST_F(FlexLayoutTest, Layout_HostInsets_Vertical_Leading) { … }
TEST_F(FlexLayoutTest, Layout_HostInsets_Horizontal_Center) { … }
TEST_F(FlexLayoutTest, Layout_HostInsets_Vertical_Center) { … }
TEST_F(FlexLayoutTest, Layout_HostInsets_Horizontal_End) { … }
TEST_F(FlexLayoutTest, Layout_HostInsets_Vertical_End) { … }
TEST_F(FlexLayoutTest, SetIncludeHostInsetsInLayout_NoChange) { … }
TEST_F(FlexLayoutTest, SetIncludeHostInsetsInLayout_CollapseIntoInsets) { … }
TEST_F(FlexLayoutTest, SetIncludeHostInsetsInLayout_OverlapInsets) { … }
TEST_F(FlexLayoutTest, SetIgnoreDefaultMainAxisMargins_IgnoresDefaultMargins) { … }
TEST_F(FlexLayoutTest,
SetIgnoreDefaultMainAxisMargins_IncludesExplicitMargins) { … }
TEST_F(FlexLayoutTest, Layout_CrossStart) { … }
TEST_F(FlexLayoutTest, Layout_CrossCenter) { … }
TEST_F(FlexLayoutTest, Layout_CrossEnd) { … }
TEST_F(FlexLayoutTest, Layout_CrossStretch) { … }
TEST_F(FlexLayoutTest, Layout_AlignStart) { … }
TEST_F(FlexLayoutTest, Layout_AlignCenter) { … }
TEST_F(FlexLayoutTest, Layout_AlignEnd) { … }
TEST_F(FlexLayoutTest, Layout_AddDroppedMargins) { … }
TEST_F(FlexLayoutTest, Layout_VerticalAlign_WiderThanTall) { … }
TEST_F(FlexLayoutTest, Layout_IgnoreMinimumSize_DropViews) { … }
TEST_F(FlexLayoutTest, Layout_IgnoreMinimumSize_DropInOrder) { … }
TEST_F(FlexLayoutTest, Layout_IgnoreMinimumSize_DropInOrder_DefaultFlex) { … }
TEST_F(FlexLayoutTest, Layout_IgnoreMinimumSize_DropByPriority) { … }
TEST_F(FlexLayoutTest, Layout_Flex_OneViewScales) { … }
TEST_F(FlexLayoutTest, Layout_Flex_OneViewScales_BelowMinimum) { … }
TEST_F(FlexLayoutTest,
Layout_Flex_OneViewScales_CausesSubsequentControlToDropOut) { … }
TEST_F(FlexLayoutTest,
Layout_Flex_OneViewScales_CausesSubsequentFlexControlToDropOut) { … }
TEST_F(FlexLayoutTest, Layout_Flex_TwoChildViews_EqualWeight) { … }
TEST_F(FlexLayoutTest, Layout_Flex_TwoChildViews_DefaultFlex) { … }
TEST_F(FlexLayoutTest,
Layout_Flex_TwoChildViews_UnequalWeight_FirstHigher_FlexSmaller) { … }
TEST_F(FlexLayoutTest,
Layout_Flex_TwoChildViews_UnequalWeight_SecondHigher_FlexSmaller) { … }
TEST_F(FlexLayoutTest, Layout_Flex_TwoChildViews_UnequalWeight_OneHitsMinimum) { … }
TEST_F(
FlexLayoutTest,
Layout_Flex_TwoChildViews_UnequalWeight_OneDropsOut_OtherExceedsPreferred) { … }
TEST_F(FlexLayoutTest, Layout_Flex_TwoChildViews_FirstViewFillsAvailableSpace) { … }
TEST_F(FlexLayoutTest, Layout_Flex_TwoChildViews_Priority) { … }
TEST_F(FlexLayoutTest,
Layout_Flex_TwoChildViews_Priority_LowerPriorityDropsOut) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_UnboundedSnapToMinimum) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_UnboundedScaleToMinimumSnapToZero) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_UnboundedScaleToZero) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_UnboundedSnapToMinimum1D) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_UnboundedScaleToMinimumSnapToZero1D) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_UnboundedScaleToZero1D) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_ScaleToMaximum) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_ScaleToMaximum_WithOrder) { … }
TEST_F(FlexLayoutTest,
Layout_FlexRule_TwoPassScaling_PreferredSizeTakesPrecedence) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_TwoPassScaling_StopAtPreferredSize) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_TwoPassScaling_GrowPastPreferredSize) { … }
TEST_F(FlexLayoutTest,
Layout_FlexRule_GrowPastPreferredSize_TwoViews_SamePriority) { … }
TEST_F(FlexLayoutTest,
Layout_FlexRule_GrowPastPreferredSize_TwoViews_DifferentPriority) { … }
TEST_F(FlexLayoutTest, Layout_Flex_TwoChildViews_FlexAlignment_Start) { … }
TEST_F(FlexLayoutTest, Layout_Flex_TwoChildViews_FlexAlignment_End) { … }
TEST_F(FlexLayoutTest, Layout_Flex_TwoChildViews_FlexAlignment_Center) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_CustomFlexRule) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_CustomFlexRule_WithNonFlex) { … }
TEST_F(FlexLayoutTest, Layout_FlexRule_CustomFlexRule_ShrinkToZero) { … }
TEST_F(FlexLayoutTest, Layout_OnlyCallsSetViewVisibilityWhenNecessary) { … }
TEST_F(FlexLayoutTest, Layout_Vertical_ZeroWidthNonZeroHeight) { … }
TEST_F(FlexLayoutTest, Layout_Vertical_ZeroWidthZeroHeight) { … }
TEST_F(FlexLayoutTest, GetAvailableSize_NoFlex) { … }
TEST_F(FlexLayoutTest, GetAvailableSize_NoFlex_Margins) { … }
TEST_F(FlexLayoutTest, GetAvailableSize_NoFlex_ExtraSize) { … }
TEST_F(FlexLayoutTest, GetAvailableSize_NoFlex_Vertical) { … }
TEST_F(FlexLayoutTest, GetAvailableSize_Flex_AllSameSize) { … }
TEST_F(FlexLayoutTest, GetAvailableSize_Flex_VariedMinimumSizes) { … }
TEST_F(FlexLayoutTest, GetAvailableSize_Flex_HiddenViews) { … }
TEST_F(FlexLayoutTest, GetAvailableSize_Flex_DifferentWeights) { … }
TEST_F(FlexLayoutTest, FlexAllocationOrderNormal) { … }
TEST_F(FlexLayoutTest, FlexAllocationOrderReverse) { … }
TEST_F(FlexLayoutTest, FlexAllocationOrderNormalWithExcess) { … }
TEST_F(FlexLayoutTest, FlexAllocationOrderReverseWithExcess) { … }
TEST_F(FlexLayoutTest, FlexRuleContradictsPreferredSize) { … }
TEST_F(FlexLayoutTest, PreferredSizeZeroPreventsFlex_Horizontal) { … }
TEST_F(FlexLayoutTest, PreferredSizeZeroPreventsFlex_Vertical) { … }
TEST_F(FlexLayoutTest, LabelPreferredHeightChangesWithWidth) { … }
TEST_F(FlexLayoutTest, VerticalInHorizontalInVertical_HeightForWidth) { … }
namespace {
Size StepwiseFlexRule(int step,
const View* view,
const SizeBounds& maximum_size) { … }
}
TEST_F(FlexLayoutTest, Advanced_ViewDoesNotTakeFullExcess_Reallocation) { … }
TEST_F(FlexLayoutTest, Advanced_PreferredSizeZero_AllOrNothing) { … }
TEST_F(FlexLayoutTest, IndividualCrossAxisAlignmentInHorizontalLayoutTest) { … }
TEST_F(FlexLayoutTest, IndividualCrossAxisAlignmentInVerticalLayoutTest) { … }
TEST_F(FlexLayoutTest, PreferredSizeMutationTest) { … }
TEST_F(FlexLayoutTest, PreferredSizeMutationTest2) { … }
TEST_F(FlexLayoutTest, ZeroPreferedSizeView) { … }
class FlexLayoutCrossAxisFitTest : public FlexLayoutTest { … };
TEST_F(FlexLayoutCrossAxisFitTest, Layout_CrossStretch) { … }
TEST_F(FlexLayoutCrossAxisFitTest, Layout_CrossStart) { … }
TEST_F(FlexLayoutCrossAxisFitTest, Layout_CrossCenter) { … }
TEST_F(FlexLayoutCrossAxisFitTest, Layout_CrossEnd) { … }
class NestedFlexLayoutTest : public FlexLayoutTest { … };
TEST_F(NestedFlexLayoutTest, SetVisible_UpdatesLayout) { … }
TEST_F(NestedFlexLayoutTest, AddChild_UpdatesLayout) { … }
TEST_F(NestedFlexLayoutTest, RemoveChild_UpdatesLayout) { … }
TEST_F(NestedFlexLayoutTest, Layout_OppositeOrientation) { … }
TEST_F(NestedFlexLayoutTest, Layout_SameOrientation) { … }
TEST_F(NestedFlexLayoutTest, Layout_Flex) { … }
TEST_F(NestedFlexLayoutTest, UsingDefaultFlexRule) { … }
TEST_F(NestedFlexLayoutTest, UnboundedZeroSize) { … }
namespace {
struct DirectionalFlexRuleTestParamRules { … };
struct DirectionalFlexRuleTestParam { … };
static const DirectionalFlexRuleTestParamRules kNoCrossFlex = …;
static const DirectionalFlexRuleTestParamRules kMainDropOutCrossFlex = …;
static const DirectionalFlexRuleTestParamRules kFlexUseHeightForWidth = …;
const DirectionalFlexRuleTestParam DirectionalFlexRuleTestParamList[] = …;
}
class FlexLayoutDirectionalRuleTest
: public FlexLayoutTest,
public testing::WithParamInterface<DirectionalFlexRuleTestParam> { … };
TEST_P(FlexLayoutDirectionalRuleTest, TestRules) { … }
INSTANTIATE_TEST_SUITE_P(…);
}