#include "ui/views/layout/animating_layout_manager.h"
#include <algorithm>
#include <memory>
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/scoped_observation.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "build/build_config.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/animation/animation_test_api.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/layout/normalized_geometry.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"
namespace views {
namespace {
constexpr gfx::Size kChildViewSize{ … };
gfx::Size ConstrainSizeToBounds(const gfx::Size& size,
const SizeBounds& bounds) { … }
class TestView : public View { … };
BEGIN_METADATA(…)
class TestLayoutManager : public LayoutManagerBase { … };
class SmartFillLayout : public FillLayout { … };
class AnimationEventLogger : public AnimatingLayoutManager::Observer { … };
}
class AnimatingLayoutManagerTest : public testing::Test { … };
const FlexSpecification AnimatingLayoutManagerTest::kDropOut = …;
const FlexSpecification AnimatingLayoutManagerTest::kFlex = …;
TEST_F(AnimatingLayoutManagerTest, SetLayoutManager_NoAnimation) { … }
TEST_F(AnimatingLayoutManagerTest, ResetLayout_NoAnimation) { … }
TEST_F(AnimatingLayoutManagerTest, HostInvalidate_TriggersAnimation) { … }
TEST_F(AnimatingLayoutManagerTest,
HostInvalidate_AnimateBounds_AnimationProgresses) { … }
TEST_F(AnimatingLayoutManagerTest, HostInvalidate_NoAnimateBounds_NoAnimation) { … }
TEST_F(AnimatingLayoutManagerTest,
HostInvalidate_NoAnimateBounds_NewLayoutTriggersAnimation) { … }
TEST_F(AnimatingLayoutManagerTest,
HostInvalidate_NoAnimateBounds_AnimationProgresses) { … }
TEST_F(AnimatingLayoutManagerTest, FadeInOutMode_MiddleView_ScaleFromZero) { … }
TEST_F(AnimatingLayoutManagerTest, FadeInOutMode_MiddleView_ScaleFromMinimum) { … }
TEST_F(AnimatingLayoutManagerTest, FadeInOutMode_LeadingView_ScaleFromMinimum) { … }
TEST_F(AnimatingLayoutManagerTest,
FadeInOutMode_TrailingView_ScaleFromMinimum_FadeIn) { … }
TEST_F(AnimatingLayoutManagerTest,
FadeInOutMode_TrailingView_ScaleFromMinimum) { … }
TEST_F(AnimatingLayoutManagerTest,
FadeInOutMode_TrailingView_ScaleFromMinimum_Vertical) { … }
TEST_F(AnimatingLayoutManagerTest,
FadeInOutMode_Hide_HidesViewDuringAnimation) { … }
TEST_F(AnimatingLayoutManagerTest,
FadeInOutMode_Hide_HidesViewDuringAnimation_OneFrame) { … }
TEST_F(AnimatingLayoutManagerTest,
FadeInOutMode_Hide_AnimationResetDuringHide) { … }
TEST_F(AnimatingLayoutManagerTest, FadeInOutMode_SlideFromLeading_LastView) { … }
TEST_F(AnimatingLayoutManagerTest, FadeInOutMode_SlideFromLeading_Vertical) { … }
TEST_F(AnimatingLayoutManagerTest, FadeInOutMode_SlideFromLeading_MiddleView) { … }
TEST_F(AnimatingLayoutManagerTest,
FadeInOutMode_SlideFromLeading_LeadingView_SlidesFromTrailing) { … }
TEST_F(AnimatingLayoutManagerTest, FadeInOutMode_SlideFromTrailing_MiddleView) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_FadeOutOnVisibilitySet) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_FadeInOnVisibilitySet) { … }
TEST_F(AnimatingLayoutManagerTest,
FlexLayout_AnimateOutOnDescendentVisibilitySet) { … }
TEST_F(AnimatingLayoutManagerTest,
FlexLayout_AnimateInOnDescendentVisibilitySet) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_RemoveFadingViewDoesNotCrash) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_RemoveShowingViewDoesNotCrash) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_DoubleSlide) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_RedirectAfterExchangePlaces) { … }
TEST_F(AnimatingLayoutManagerTest,
FlexLayout_PostDelayedActionAfterFadeIn_AnimateNewViewIn) { … }
TEST_F(AnimatingLayoutManagerTest,
FlexLayout_PostDelayedActionAfterFadeIn_SwapTwoViews) { … }
TEST_F(AnimatingLayoutManagerTest,
FlexLayout_PostDelayedActionAfterFadeIn_FadeInHiddenView) { … }
TEST_F(AnimatingLayoutManagerTest, RemoveDuringAnimationDoesntCrash) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_FadeInOnAdded) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_FadeIn) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_FadeOut) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_FadeOut_NoCrashOnRemove) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_FadeOut_IgnoreChildView) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_SlideAfterViewHidden) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_SlideAfterViewRemoved) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_RedirectAnimation) { … }
TEST_F(AnimatingLayoutManagerTest, FlexLayout_ResetAnimation) { … }
TEST_F(AnimatingLayoutManagerTest, TestEvents) { … }
TEST_F(AnimatingLayoutManagerTest, PostOrQueueAction) { … }
TEST_F(AnimatingLayoutManagerTest, PostOrQueueAction_ContinueAnimation) { … }
TEST_F(AnimatingLayoutManagerTest, PostOrQueueAction_NeverFinishes) { … }
TEST_F(AnimatingLayoutManagerTest, PostOrQueueAction_MayPostImmediately) { … }
TEST_F(AnimatingLayoutManagerTest, ZOrder_UnchangedWhenNotAnimating) { … }
TEST_F(AnimatingLayoutManagerTest, ZOrder_UnchangedWhenNotFading) { … }
TEST_F(AnimatingLayoutManagerTest, ZOrder_FadingOutViewMovedToBack) { … }
TEST_F(AnimatingLayoutManagerTest, ZOrder_FadingInViewMovedToBack) { … }
TEST_F(AnimatingLayoutManagerTest, ConstrainedSpace_StopsAnimation) { … }
TEST_F(AnimatingLayoutManagerTest, ConstrainedSpace_TriggersDelayedAction) { … }
TEST_F(AnimatingLayoutManagerTest, ConstrainedSpace_SubsequentAnimation) { … }
class AnimatingLayoutManagerNoAnimationsTest
: public AnimatingLayoutManagerTest { … };
const std::vector<std::pair<AnimatingLayoutManager::FadeInOutMode, const char*>>
AnimatingLayoutManagerNoAnimationsTest::kFadeModes = …;
TEST_F(AnimatingLayoutManagerNoAnimationsTest, ResetNoAnimation) { … }
TEST_F(AnimatingLayoutManagerNoAnimationsTest, ChangeLayoutNoAnimation) { … }
TEST_F(AnimatingLayoutManagerNoAnimationsTest, HideShowViewNoAnimation) { … }
TEST_F(AnimatingLayoutManagerNoAnimationsTest, FadeViewInOutNoAnimation) { … }
TEST_F(AnimatingLayoutManagerNoAnimationsTest, ActionsPostedAfterLayout) { … }
namespace {
constexpr base::TimeDelta kMinimumAnimationTime = …;
class ImmediateLayoutManager : public LayoutManagerBase { … };
class AnimationWatcher : public AnimatingLayoutManager::Observer { … };
}
class AnimatingLayoutManagerRootViewTest : public AnimatingLayoutManagerTest { … };
class AnimatingLayoutManagerAvailableSizeTest
: public AnimatingLayoutManagerRootViewTest { … };
TEST_F(AnimatingLayoutManagerAvailableSizeTest, AvailableSize_LimitsExpansion) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_RestartsAnimation) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_RestartsAnimation_Vertical) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_RedirectsAnimation) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest, AvailableSize_StopsAnimation) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest, AvailableSize_ImmediateResize) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest, AvailableSize_StepDownStepUp) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_ConstraintRemovedStartsAnimation) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_LimitsExpansion_WithFlex) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_RestartsAnimation_WithFlex) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_RedirectsAnimation_WithFlex) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_StopsAnimation_WithFlex) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_ImmediateResize_WithFlex) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_StepDownStepUp_WithFlex) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AvailableSize_ConstraintRemovedStartsAnimation_WithFlex) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AnimateMainAxis_Horizontal_MainAxisAnimates) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AnimateMainAxis_Vertical_MainAxisAnimates) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AnimateMainAxis_Horizontal_CrossAxisSizeChangeResetsLayout) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AnimateMainAxis_Vertical_CrossAxisSizeChangeResetsLayout) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AnimateMainAxis_Horizontal_CrossAxisAlignmentWorks) { … }
TEST_F(AnimatingLayoutManagerAvailableSizeTest,
AnimateMainAxis_Vertical_CrossAxisAlignmentWorks) { … }
class AnimatingLayoutManagerFlexRuleTest : public AnimatingLayoutManagerTest { … };
const FlexSpecification
AnimatingLayoutManagerFlexRuleTest::kScaleToMinimumSnapToZero = …;
TEST_F(AnimatingLayoutManagerFlexRuleTest, ReturnsPreferredSize) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest,
VerticalBounded_ReturnsPreferredSize) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest,
VerticalBounded_ReturnsHeightForWidth) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest, HorizontalBounded_FlexToSize) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest, HorizontalBounded_DropOut) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest, VerticalBounded_FlexToSize) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest, VerticalBounded_DropOut) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest, HorizontalDoubleBounded_DropOut) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest, VerticalDoubleBounded_DropOut) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest, HorizontalMinimumSize) { … }
TEST_F(AnimatingLayoutManagerFlexRuleTest, VerticalMinimumSize) { … }
class AnimatingLayoutManagerInFlexLayoutTest
: public AnimatingLayoutManagerRootViewTest { … };
TEST_F(AnimatingLayoutManagerInFlexLayoutTest, NoAnimation) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
AnimateFullyWithinAvailableSpace) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest, NoAnimationRestart) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest, GrowWithinConstrainedSpace) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
GrowWithinConstrainedSpace_NoAnimationRestart) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
GrowWithinConstrainedSpace_AnimationRedirected) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
GrowWithinConstrainedSpace_AnimationInterrupted) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
ShrinkWithinConstrainedSpace_AnimationProceeds) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
ShrinkWithinConstrainedSpace_ExpandedSpaceHasNoEffect) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
ShrinkWithinConstrainedSpace_SnapToFinalLayout) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
ShrinkWithinConstrainedSpace_SnapToConstrainedLayout) { … }
TEST_F(AnimatingLayoutManagerInFlexLayoutTest,
ShrinkWithinConstrainedSpace_NoRestartOnLargerPreferredSize) { … }
class AnimatingLayoutManagerInFlexLayoutNoAnimationTest
: public AnimatingLayoutManagerInFlexLayoutTest { … };
TEST_F(AnimatingLayoutManagerInFlexLayoutNoAnimationTest, ShrinkAndGrow) { … }
class AnimatingLayoutManagerRealtimeTest
: public AnimatingLayoutManagerRootViewTest { … };
TEST_F(AnimatingLayoutManagerRealtimeTest, TestAnimateSlide) { … }
TEST_F(AnimatingLayoutManagerRealtimeTest, TestAnimateStretch) { … }
TEST_F(AnimatingLayoutManagerRealtimeTest, TestConstrainedSpaceStopsAnimation) { … }
TEST_F(AnimatingLayoutManagerRealtimeTest, TestConstrainedSpaceDoesNotRestart) { … }
TEST_F(AnimatingLayoutManagerRealtimeTest,
TestConstrainedSpaceRestartedAnimationSucceeds) { … }
#if !BUILDFLAG(IS_MAC)
class AnimatingLayoutManagerSequenceTest : public ViewsTestBase { … };
TEST_F(AnimatingLayoutManagerSequenceTest,
AddChild_AddToParent_Configure_AddToWidget) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
AddChild_Configure_AddToParent_AddToWidget) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
Configure_AddChild_AddToParent_AddToWidget) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
Configure_AddToParent_AddChild_AddToWidget) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
AddToParent_Configure_AddChild_AddToWidget) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
AddToParent_AddChild_Configure_AddToWidget) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
AddToWidget_AddToParent_Configure_AddChild) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
AddToParent_AddToWidget_Configure_AddChild) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
Configure_AddToParent_AddToWidget_AddChild) { … }
TEST_F(AnimatingLayoutManagerSequenceTest,
AddToWidget_AddToParent_AddChild_Configure) { … }
#endif
}