chromium/ui/views/layout/composite_layout_tests.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>

#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/test/task_environment.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_container.h"
#include "ui/gfx/animation/animation_test_api.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/layout/animating_layout_manager.h"
#include "ui/views/layout/flex_layout.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"
#include "ui/views/widget/widget.h"

// This test suite simulates the kind of nested layouts we find in e.g. the
// toolbar without actually pulling in browser code. It's designed to test
// interactions between multiple levels of Flex and Animating layouts, in a
// situation that resembles how they are actually used.
//
// The test cases are designed to probe edge cases and interactions that are
// difficult to simulate in either the FlexLayout or AnimatingLayoutManager unit
// tests. They are not browser tests however, and uses TaskEnvironment and
// AnimationContainerTestApi to step animations rather than running them in
// realtime. This makes these tests as quick as unit tests, so they do not incur
// the costs associated with browser tests.
//
// This suite is part of views_unittests.

namespace views {

namespace {

constexpr base::TimeDelta kDefaultAnimationDuration =;
constexpr int kIconDimension =;
constexpr gfx::Size kIconSize(kIconDimension, kIconDimension);
constexpr int kLabelWidth =;
constexpr gfx::Size kLabelSize(kLabelWidth, kIconDimension);
constexpr int kBarMinimumWidth =;
constexpr int kBarPreferredWidth =;
constexpr gfx::Size kBarMinimumSize(kBarMinimumWidth, kIconDimension);
constexpr gfx::Size kBarPreferredSize(kBarPreferredWidth, kIconDimension);
constexpr gfx::Size kDefaultToolbarSize(400, kIconDimension);

// Base class for elements in the toolbar that animate; a stand-in for e.g.
// ToolbarIconContainer.
class SimulatedToolbarElement : public View {};

BEGIN_METADATA()

// Simulates an avatar button on the Chrome toolbar, with a fixed-size icon and
// a label that can animate in and out.
class SimulatedAvatarButton : public SimulatedToolbarElement {};

BEGIN_METADATA()

// Simulates extensions buttons in the new toolbar extensions view, with a fixed
// button on the right and buttons to the left that can animate in and out and
// be hidden if there is insufficient space.
class SimulatedExtensionsContainer : public SimulatedToolbarElement {};

BEGIN_METADATA()

// Simulates a toolbar with buttons on either side, a "location bar", and mock
// versions of the extensions container and avatar button.
class SimulatedToolbar : public View {};

BEGIN_METADATA()

}  // anonymous namespace

// Test suite. Sets up the mock toolbar and ties animation of all child elements
// together so they can be controlled for testing. Use the utility methods here
// as much as possible rather than calling methods on the individual Views.
class CompositeLayoutTest : public testing::Test {};

// ------------
// Basic tests.

TEST_F(CompositeLayoutTest, InitialLayout) {}

TEST_F(CompositeLayoutTest, SmallResize) {}

TEST_F(CompositeLayoutTest, ShrinkLocationBar) {}

TEST_F(CompositeLayoutTest, ShrinkLocationBarTooSmall) {}

TEST_F(CompositeLayoutTest, ProfileAnimates) {}

TEST_F(CompositeLayoutTest, ProfileAnimationInterrupted) {}

TEST_F(CompositeLayoutTest, ProfileAnimationInterruptedImmediately) {}

// ----------------------------------------------------------
// Tests which add/remove extension icons from the container.

TEST_F(CompositeLayoutTest, ExtensionsAnimateOnAdd) {}

TEST_F(CompositeLayoutTest, ExtensionsAnimateOnAddMultiple) {}

TEST_F(CompositeLayoutTest, ExtensionsAnimateOnAddMultipleStaggered) {}

TEST_F(CompositeLayoutTest, ExtensionRemovedDuringAnimation) {}

TEST_F(CompositeLayoutTest, ExtensionRemovedImmediately) {}

TEST_F(CompositeLayoutTest, ExtensionRemovedImmediatelyDuringAnimation) {}

// -----------------------------------------------
// Tests which show/hide existing extension icons.

TEST_F(CompositeLayoutTest, ExtensionsAnimateOnShow) {}

TEST_F(CompositeLayoutTest, ExtensionsAnimateOnShowMultiple) {}

TEST_F(CompositeLayoutTest, ExtensionsAnimateOnShowMultipleStaggered) {}

TEST_F(CompositeLayoutTest, ExtensionHiddenDuringAnimation) {}

TEST_F(CompositeLayoutTest, ExtensionHiddenImmediately) {}

TEST_F(CompositeLayoutTest, ExtensionHiddenImmediatelyDuringAnimation) {}

// ----------------------------------
// Tests where child views are moved.

TEST_F(CompositeLayoutTest, ExtensionOrderChanged) {}

TEST_F(CompositeLayoutTest, ExtensionHiddenAndPoppedOutImmediate) {}

TEST_F(CompositeLayoutTest, ExtensionHiddenAndPoppedOutDelayed) {}

TEST_F(CompositeLayoutTest, ExtensionPinned) {}

TEST_F(CompositeLayoutTest, VisibleExtensionMoved) {}

TEST_F(CompositeLayoutTest, InvisibleExtensionMoved) {}

// -----------------------------------------------
// Tests combining two different animating views.

TEST_F(CompositeLayoutTest, ExtensionsAndAvatarAnimateSimultaneously) {}

TEST_F(CompositeLayoutTest, ExtensionsAndAvatarAnimateStaggered) {}

// -----------------------
// Tests in limited space.

TEST_F(CompositeLayoutTest, ExtensionsNotShownWhenSpaceConstrained) {}

TEST_F(CompositeLayoutTest, SomeExtensionsNotShownWhenSpaceConstrained) {}

TEST_F(CompositeLayoutTest, ExtensionsShownSnapsWhenSpaceShrinks) {}

TEST_F(CompositeLayoutTest,
       ExtensionsShowingAnimationRedirectsDueToSmallerAvailableSpace) {}

TEST_F(CompositeLayoutTest,
       ExtensionsShowingAnimationCancelsDueToSmallerAvailableSpace) {}

TEST_F(CompositeLayoutTest,
       ExtensionsShowingAnimationRedirectsDueToLargerAvailableSpace) {}

TEST_F(CompositeLayoutTest, ExtensionsHiddenWhenAvatarExpands) {}

TEST_F(CompositeLayoutTest, ExtensionsShownWhenAvatarCollapses) {}

TEST_F(CompositeLayoutTest, ExtensionsHideAndShowWhenAvatarAnimates) {}

TEST_F(CompositeLayoutTest, ExtensionsShowAndHideWhenAvatarAnimates) {}

TEST_F(CompositeLayoutTest, MultipleAnimationAndLayoutChanges) {}

}  // namespace views