1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_
6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/base/test/material_design_controller_test_api.h"
12 #include "ui/views/animation/ink_drop_animation_controller.h"
13 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
14 #include "ui/views/animation/ink_drop_host.h"
15 #include "ui/views/animation/ink_drop_state.h"
16 #include "ui/views/animation/test/test_ink_drop_host.h"
20 // Macro that will execute |test_code| against all derivatives of the
21 // InkDropAnimationController returned by the InkDropAnimationControllerFactory.
22 #define TEST_ALL_INK_DROPS(test_name, test_code) \
23 TEST_F(InkDropAnimationControllerFactoryTest, test_name) \
24 test_code TEST_F(MDInkDropAnimationControllerFactoryTest, test_name) test_code
26 // Test fixture to test the non material design InkDropAnimationController.
27 class InkDropAnimationControllerFactoryTest
: public testing::Test
{
29 InkDropAnimationControllerFactoryTest() {}
30 ~InkDropAnimationControllerFactoryTest() override
{}
33 void SetUp() override
;
34 void TearDown() override
;
37 // A dummy InkDropHost required to create an InkDropAnimationController.
38 TestInkDropHost test_ink_drop_host_
;
40 // The InkDropAnimationController returned by the
41 // InkDropAnimationControllerFactory test target.
42 scoped_ptr
<InkDropAnimationController
> ink_drop_animation_controller_
;
45 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest
);
48 void InkDropAnimationControllerFactoryTest::SetUp() {
49 // Any call by a previous test to MaterialDesignController::GetMode() will
50 // initialize and cache the mode. This ensures that these tests will run from
51 // a non-initialized state.
52 ui::test::MaterialDesignControllerTestAPI::UninitializeMode();
54 ink_drop_animation_controller_
=
55 InkDropAnimationControllerFactory::CreateInkDropAnimationController(
56 &test_ink_drop_host_
);
59 void InkDropAnimationControllerFactoryTest::TearDown() {
60 ui::test::MaterialDesignControllerTestAPI::UninitializeMode();
63 // Test fixture to test the material design InkDropAnimationController.
64 class MDInkDropAnimationControllerFactoryTest
65 : public InkDropAnimationControllerFactoryTest
{
67 MDInkDropAnimationControllerFactoryTest() {}
69 // InkDropAnimationControllerFactoryTest:
70 void SetUp() override
;
73 DISALLOW_COPY_AND_ASSIGN(MDInkDropAnimationControllerFactoryTest
);
76 void MDInkDropAnimationControllerFactoryTest::SetUp() {
77 ui::test::MaterialDesignControllerTestAPI::SetMode(
78 ui::MaterialDesignController::MATERIAL_NORMAL
);
79 InkDropAnimationControllerFactoryTest::SetUp();
82 TEST_ALL_INK_DROPS(StateIsHiddenInitially
,
86 ink_drop_animation_controller_
->GetInkDropState());
89 TEST_ALL_INK_DROPS(TypicalQuickAction
,
91 ink_drop_animation_controller_
->AnimateToState(
92 InkDropState::ACTION_PENDING
);
93 ink_drop_animation_controller_
->AnimateToState(
94 InkDropState::QUICK_ACTION
);
97 ink_drop_animation_controller_
->GetInkDropState());
100 TEST_ALL_INK_DROPS(CancelQuickAction
,
102 ink_drop_animation_controller_
->AnimateToState(
103 InkDropState::ACTION_PENDING
);
104 ink_drop_animation_controller_
->AnimateToState(
105 InkDropState::HIDDEN
);
107 InkDropState::HIDDEN
,
108 ink_drop_animation_controller_
->GetInkDropState());
111 TEST_ALL_INK_DROPS(TypicalSlowAction
,
113 ink_drop_animation_controller_
->AnimateToState(
114 InkDropState::ACTION_PENDING
);
115 ink_drop_animation_controller_
->AnimateToState(
116 InkDropState::SLOW_ACTION_PENDING
);
117 ink_drop_animation_controller_
->AnimateToState(
118 InkDropState::SLOW_ACTION
);
120 InkDropState::HIDDEN
,
121 ink_drop_animation_controller_
->GetInkDropState());
124 TEST_ALL_INK_DROPS(CancelSlowAction
,
126 ink_drop_animation_controller_
->AnimateToState(
127 InkDropState::ACTION_PENDING
);
128 ink_drop_animation_controller_
->AnimateToState(
129 InkDropState::SLOW_ACTION_PENDING
);
130 ink_drop_animation_controller_
->AnimateToState(
131 InkDropState::HIDDEN
);
133 InkDropState::HIDDEN
,
134 ink_drop_animation_controller_
->GetInkDropState());
138 TypicalQuickActivated
,
140 ink_drop_animation_controller_
->AnimateToState(
141 InkDropState::ACTION_PENDING
);
142 ink_drop_animation_controller_
->AnimateToState(InkDropState::ACTIVATED
);
143 ink_drop_animation_controller_
->AnimateToState(InkDropState::DEACTIVATED
);
144 EXPECT_EQ(InkDropState::HIDDEN
,
145 ink_drop_animation_controller_
->GetInkDropState());
149 TypicalSlowActivated
,
151 ink_drop_animation_controller_
->AnimateToState(
152 InkDropState::ACTION_PENDING
);
153 ink_drop_animation_controller_
->AnimateToState(
154 InkDropState::SLOW_ACTION_PENDING
);
155 ink_drop_animation_controller_
->AnimateToState(InkDropState::ACTIVATED
);
156 ink_drop_animation_controller_
->AnimateToState(InkDropState::DEACTIVATED
);
157 EXPECT_EQ(InkDropState::HIDDEN
,
158 ink_drop_animation_controller_
->GetInkDropState());
163 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_