OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ | |
6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ | |
7 | |
8 #include "base/macros.h" | 5 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/base/resource/material_design/material_design_controller.h" |
11 #include "ui/base/test/material_design_controller_test_api.h" | 9 #include "ui/base/test/material_design_controller_test_api.h" |
| 10 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
12 #include "ui/views/animation/ink_drop_animation_controller.h" | 11 #include "ui/views/animation/ink_drop_animation_controller.h" |
13 #include "ui/views/animation/ink_drop_animation_controller_factory.h" | 12 #include "ui/views/animation/ink_drop_animation_controller_factory.h" |
14 #include "ui/views/animation/ink_drop_host.h" | 13 #include "ui/views/animation/ink_drop_host.h" |
15 #include "ui/views/animation/ink_drop_state.h" | 14 #include "ui/views/animation/ink_drop_state.h" |
16 #include "ui/views/animation/test/test_ink_drop_host.h" | 15 #include "ui/views/animation/test/test_ink_drop_host.h" |
17 | 16 |
18 namespace views { | 17 namespace views { |
19 | 18 |
20 // Macro that will execute |test_code| against all derivatives of the | 19 class InkDropAnimationControllerFactoryTest |
21 // InkDropAnimationController returned by the InkDropAnimationControllerFactory. | 20 : public testing::TestWithParam<ui::MaterialDesignController::Mode> { |
22 // TODO(bruthig): Refactor these tests to use TEST_P and | |
23 // INSTANTIATE_TEST_CASE_P. | |
24 #define TEST_ALL_INK_DROPS(test_name, test_code) \ | |
25 TEST_F(InkDropAnimationControllerFactoryTest, test_name) \ | |
26 test_code TEST_F(MDInkDropAnimationControllerFactoryTest, test_name) test_code | |
27 | |
28 // Test fixture to test the non material design InkDropAnimationController. | |
29 class InkDropAnimationControllerFactoryTest : public testing::Test { | |
30 public: | 21 public: |
31 InkDropAnimationControllerFactoryTest() {} | 22 InkDropAnimationControllerFactoryTest(); |
32 ~InkDropAnimationControllerFactoryTest() override {} | 23 ~InkDropAnimationControllerFactoryTest(); |
33 | |
34 // testing::Test: | |
35 void SetUp() override; | |
36 void TearDown() override; | |
37 | 24 |
38 protected: | 25 protected: |
39 // A dummy InkDropHost required to create an InkDropAnimationController. | 26 // A dummy InkDropHost required to create an InkDropAnimationController. |
40 TestInkDropHost test_ink_drop_host_; | 27 TestInkDropHost test_ink_drop_host_; |
41 | 28 |
42 // The InkDropAnimationController returned by the | 29 // The InkDropAnimationController returned by the |
43 // InkDropAnimationControllerFactory test target. | 30 // InkDropAnimationControllerFactory test target. |
44 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; | 31 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; |
45 | 32 |
46 private: | 33 private: |
| 34 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; |
| 35 |
47 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); | 36 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); |
48 }; | 37 }; |
49 | 38 |
50 void InkDropAnimationControllerFactoryTest::SetUp() { | 39 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest() |
| 40 : ink_drop_animation_controller_(nullptr) { |
51 // Any call by a previous test to MaterialDesignController::GetMode() will | 41 // Any call by a previous test to MaterialDesignController::GetMode() will |
52 // initialize and cache the mode. This ensures that these tests will run from | 42 // initialize and cache the mode. This ensures that these tests will run from |
53 // a non-initialized state. | 43 // a non-initialized state. |
54 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 44 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
| 45 ui::test::MaterialDesignControllerTestAPI::SetMode(GetParam()); |
| 46 ink_drop_animation_controller_.reset( |
| 47 InkDropAnimationControllerFactory::CreateInkDropAnimationController( |
| 48 &test_ink_drop_host_) |
| 49 .release()); |
| 50 ink_drop_animation_controller_->SetInkDropSize(gfx::Size(10, 10), 4, |
| 51 gfx::Size(8, 8), 2); |
55 | 52 |
56 ink_drop_animation_controller_ = | 53 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
57 InkDropAnimationControllerFactory::CreateInkDropAnimationController( | 54 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
58 &test_ink_drop_host_); | |
59 } | 55 } |
60 | 56 |
61 void InkDropAnimationControllerFactoryTest::TearDown() { | 57 InkDropAnimationControllerFactoryTest:: |
| 58 ~InkDropAnimationControllerFactoryTest() { |
62 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 59 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
63 } | 60 } |
64 | 61 |
65 // Test fixture to test the material design InkDropAnimationController. | 62 // Note: First argument is optional and intentionally left blank. |
66 class MDInkDropAnimationControllerFactoryTest | 63 // (it's a prefix for the generated test cases) |
67 : public InkDropAnimationControllerFactoryTest { | 64 INSTANTIATE_TEST_CASE_P( |
68 public: | 65 , |
69 MDInkDropAnimationControllerFactoryTest() {} | 66 InkDropAnimationControllerFactoryTest, |
| 67 testing::Values(ui::MaterialDesignController::NON_MATERIAL, |
| 68 ui::MaterialDesignController::MATERIAL_NORMAL)); |
70 | 69 |
71 // InkDropAnimationControllerFactoryTest: | 70 TEST_P(InkDropAnimationControllerFactoryTest, |
72 void SetUp() override; | 71 VerifyAllInkDropLayersRemovedAfterDestruction) { |
73 | 72 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
74 private: | 73 ink_drop_animation_controller_.reset(); |
75 DISALLOW_COPY_AND_ASSIGN(MDInkDropAnimationControllerFactoryTest); | 74 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); |
76 }; | |
77 | |
78 void MDInkDropAnimationControllerFactoryTest::SetUp() { | |
79 ui::test::MaterialDesignControllerTestAPI::SetMode( | |
80 ui::MaterialDesignController::MATERIAL_NORMAL); | |
81 InkDropAnimationControllerFactoryTest::SetUp(); | |
82 } | 75 } |
83 | 76 |
84 TEST_ALL_INK_DROPS(VerifyAllInkDropLayersRemovedAfterDestruction, | 77 TEST_P(InkDropAnimationControllerFactoryTest, StateIsHiddenInitially) { |
85 { | 78 EXPECT_EQ(InkDropState::HIDDEN, |
86 ink_drop_animation_controller_->AnimateToState( | 79 ink_drop_animation_controller_->GetInkDropState()); |
87 InkDropState::ACTION_PENDING); | 80 } |
88 ink_drop_animation_controller_.reset(); | |
89 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); | |
90 }) | |
91 | 81 |
92 TEST_ALL_INK_DROPS(StateIsHiddenInitially, | 82 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickAction) { |
93 { | 83 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
94 EXPECT_EQ( | 84 ink_drop_animation_controller_->AnimateToState(InkDropState::QUICK_ACTION); |
95 InkDropState::HIDDEN, | 85 EXPECT_EQ(InkDropState::HIDDEN, |
96 ink_drop_animation_controller_->GetInkDropState()); | 86 ink_drop_animation_controller_->GetInkDropState()); |
97 }) | 87 } |
98 | 88 |
99 TEST_ALL_INK_DROPS(TypicalQuickAction, | 89 TEST_P(InkDropAnimationControllerFactoryTest, CancelQuickAction) { |
100 { | 90 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
101 ink_drop_animation_controller_->AnimateToState( | 91 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); |
102 InkDropState::ACTION_PENDING); | 92 EXPECT_EQ(InkDropState::HIDDEN, |
103 ink_drop_animation_controller_->AnimateToState( | 93 ink_drop_animation_controller_->GetInkDropState()); |
104 InkDropState::QUICK_ACTION); | 94 } |
105 EXPECT_EQ( | |
106 InkDropState::HIDDEN, | |
107 ink_drop_animation_controller_->GetInkDropState()); | |
108 }) | |
109 | 95 |
110 TEST_ALL_INK_DROPS(CancelQuickAction, | 96 TEST_P(InkDropAnimationControllerFactoryTest, TypicalSlowAction) { |
111 { | 97 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
112 ink_drop_animation_controller_->AnimateToState( | 98 ink_drop_animation_controller_->AnimateToState( |
113 InkDropState::ACTION_PENDING); | 99 InkDropState::SLOW_ACTION_PENDING); |
114 ink_drop_animation_controller_->AnimateToState( | 100 ink_drop_animation_controller_->AnimateToState(InkDropState::SLOW_ACTION); |
115 InkDropState::HIDDEN); | 101 EXPECT_EQ(InkDropState::HIDDEN, |
116 EXPECT_EQ( | 102 ink_drop_animation_controller_->GetInkDropState()); |
117 InkDropState::HIDDEN, | 103 } |
118 ink_drop_animation_controller_->GetInkDropState()); | |
119 }) | |
120 | 104 |
121 TEST_ALL_INK_DROPS(TypicalSlowAction, | 105 TEST_P(InkDropAnimationControllerFactoryTest, CancelSlowAction) { |
122 { | 106 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
123 ink_drop_animation_controller_->AnimateToState( | 107 ink_drop_animation_controller_->AnimateToState( |
124 InkDropState::ACTION_PENDING); | 108 InkDropState::SLOW_ACTION_PENDING); |
125 ink_drop_animation_controller_->AnimateToState( | 109 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); |
126 InkDropState::SLOW_ACTION_PENDING); | 110 EXPECT_EQ(InkDropState::HIDDEN, |
127 ink_drop_animation_controller_->AnimateToState( | 111 ink_drop_animation_controller_->GetInkDropState()); |
128 InkDropState::SLOW_ACTION); | 112 } |
129 EXPECT_EQ( | |
130 InkDropState::HIDDEN, | |
131 ink_drop_animation_controller_->GetInkDropState()); | |
132 }) | |
133 | 113 |
134 TEST_ALL_INK_DROPS(CancelSlowAction, | 114 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickActivated) { |
135 { | 115 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
136 ink_drop_animation_controller_->AnimateToState( | 116 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); |
137 InkDropState::ACTION_PENDING); | 117 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); |
138 ink_drop_animation_controller_->AnimateToState( | 118 EXPECT_EQ(InkDropState::HIDDEN, |
139 InkDropState::SLOW_ACTION_PENDING); | 119 ink_drop_animation_controller_->GetInkDropState()); |
140 ink_drop_animation_controller_->AnimateToState( | 120 } |
141 InkDropState::HIDDEN); | |
142 EXPECT_EQ( | |
143 InkDropState::HIDDEN, | |
144 ink_drop_animation_controller_->GetInkDropState()); | |
145 }) | |
146 | 121 |
147 TEST_ALL_INK_DROPS( | 122 TEST_P(InkDropAnimationControllerFactoryTest, TypicalSlowActivated) { |
148 TypicalQuickActivated, | 123 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
149 { | 124 ink_drop_animation_controller_->AnimateToState( |
150 ink_drop_animation_controller_->AnimateToState( | 125 InkDropState::SLOW_ACTION_PENDING); |
151 InkDropState::ACTION_PENDING); | 126 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); |
152 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); | 127 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); |
153 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); | 128 EXPECT_EQ(InkDropState::HIDDEN, |
154 EXPECT_EQ(InkDropState::HIDDEN, | 129 ink_drop_animation_controller_->GetInkDropState()); |
155 ink_drop_animation_controller_->GetInkDropState()); | 130 } |
156 }) | |
157 | |
158 TEST_ALL_INK_DROPS( | |
159 TypicalSlowActivated, | |
160 { | |
161 ink_drop_animation_controller_->AnimateToState( | |
162 InkDropState::ACTION_PENDING); | |
163 ink_drop_animation_controller_->AnimateToState( | |
164 InkDropState::SLOW_ACTION_PENDING); | |
165 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); | |
166 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); | |
167 EXPECT_EQ(InkDropState::HIDDEN, | |
168 ink_drop_animation_controller_->GetInkDropState()); | |
169 }) | |
170 | 131 |
171 } // namespace views | 132 } // namespace views |
172 | |
173 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ | |
OLD | NEW |