Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: ui/views/animation/ink_drop_animation_controller_factory_unittest.cc

Issue 1937353002: Rename of InkDropAnimationController classes to InkDrop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed tdanderson@ comments from patch set 2. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
6
7 #include <memory>
8
9 #include "base/macros.h"
10 #include "base/test/test_mock_time_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "base/timer/timer.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/base/test/material_design_controller_test_api.h"
16 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
17 #include "ui/views/animation/ink_drop_animation_controller.h"
18 #include "ui/views/animation/ink_drop_animation_controller_impl.h"
19 #include "ui/views/animation/ink_drop_host.h"
20 #include "ui/views/animation/ink_drop_state.h"
21 #include "ui/views/animation/test/test_ink_drop_host.h"
22
23 namespace views {
24
25 class InkDropAnimationControllerFactoryTest
26 : public testing::TestWithParam<
27 testing::tuple<ui::MaterialDesignController::Mode>> {
28 public:
29 InkDropAnimationControllerFactoryTest();
30 ~InkDropAnimationControllerFactoryTest();
31
32 protected:
33 // A dummy InkDropHost required to create an InkDropAnimationController.
34 TestInkDropHost test_ink_drop_host_;
35
36 // The InkDropAnimationController returned by the
37 // InkDropAnimationControllerFactory test target.
38 std::unique_ptr<InkDropAnimationController> ink_drop_animation_controller_;
39
40 private:
41 // Extracts and returns the material design mode from the test parameters.
42 ui::MaterialDesignController::Mode GetMaterialMode() const;
43
44 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
45
46 // Required by base::Timer's.
47 std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
48
49 std::unique_ptr<ui::test::MaterialDesignControllerTestAPI>
50 material_design_state_;
51
52 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest);
53 };
54
55 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest()
56 : ink_drop_animation_controller_(nullptr) {
57 // Any call by a previous test to MaterialDesignController::GetMode() will
58 // initialize and cache the mode. This ensures that these tests will run from
59 // a non-initialized state.
60 material_design_state_.reset(
61 new ui::test::MaterialDesignControllerTestAPI(GetMaterialMode()));
62 ink_drop_animation_controller_.reset(
63 InkDropAnimationControllerFactory::CreateInkDropAnimationController(
64 &test_ink_drop_host_)
65 .release());
66
67 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
68 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
69
70 switch (GetMaterialMode()) {
71 case ui::MaterialDesignController::NON_MATERIAL:
72 break;
73 case ui::MaterialDesignController::MATERIAL_NORMAL:
74 case ui::MaterialDesignController::MATERIAL_HYBRID:
75 // The Timer's used by the InkDropAnimationControllerImpl class require a
76 // base::ThreadTaskRunnerHandle instance.
77 scoped_refptr<base::TestMockTimeTaskRunner> task_runner(
78 new base::TestMockTimeTaskRunner);
79 thread_task_runner_handle_.reset(
80 new base::ThreadTaskRunnerHandle(task_runner));
81 break;
82 }
83 }
84
85 InkDropAnimationControllerFactoryTest::
86 ~InkDropAnimationControllerFactoryTest() {
87 material_design_state_.reset();
88 }
89
90 ui::MaterialDesignController::Mode
91 InkDropAnimationControllerFactoryTest::GetMaterialMode() const {
92 return testing::get<0>(GetParam());
93 }
94
95 // Note: First argument is optional and intentionally left blank.
96 // (it's a prefix for the generated test cases)
97 INSTANTIATE_TEST_CASE_P(
98 ,
99 InkDropAnimationControllerFactoryTest,
100 testing::Values(ui::MaterialDesignController::NON_MATERIAL,
101 ui::MaterialDesignController::MATERIAL_NORMAL,
102 ui::MaterialDesignController::MATERIAL_HYBRID));
103
104 TEST_P(InkDropAnimationControllerFactoryTest,
105 VerifyInkDropLayersRemovedAfterDestructionWhenRippleIsActive) {
106 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
107 ink_drop_animation_controller_.reset();
108 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers());
109 }
110
111 TEST_P(InkDropAnimationControllerFactoryTest,
112 VerifyInkDropLayersRemovedAfterDestructionWhenHoverIsActive) {
113 test_ink_drop_host_.set_should_show_hover(true);
114 ink_drop_animation_controller_->SetHovered(true);
115 ink_drop_animation_controller_.reset();
116 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers());
117 }
118
119 TEST_P(InkDropAnimationControllerFactoryTest, StateIsHiddenInitially) {
120 EXPECT_EQ(InkDropState::HIDDEN,
121 ink_drop_animation_controller_->GetTargetInkDropState());
122 }
123
124 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickAction) {
125 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
126 ink_drop_animation_controller_->AnimateToState(
127 InkDropState::ACTION_TRIGGERED);
128 EXPECT_EQ(InkDropState::HIDDEN,
129 ink_drop_animation_controller_->GetTargetInkDropState());
130 }
131
132 TEST_P(InkDropAnimationControllerFactoryTest, CancelQuickAction) {
133 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
134 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN);
135 EXPECT_EQ(InkDropState::HIDDEN,
136 ink_drop_animation_controller_->GetTargetInkDropState());
137 }
138
139 TEST_P(InkDropAnimationControllerFactoryTest, TypicalSlowAction) {
140 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
141 ink_drop_animation_controller_->AnimateToState(
142 InkDropState::ALTERNATE_ACTION_PENDING);
143 ink_drop_animation_controller_->AnimateToState(
144 InkDropState::ALTERNATE_ACTION_TRIGGERED);
145 EXPECT_EQ(InkDropState::HIDDEN,
146 ink_drop_animation_controller_->GetTargetInkDropState());
147 }
148
149 TEST_P(InkDropAnimationControllerFactoryTest, CancelSlowAction) {
150 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
151 ink_drop_animation_controller_->AnimateToState(
152 InkDropState::ALTERNATE_ACTION_PENDING);
153 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN);
154 EXPECT_EQ(InkDropState::HIDDEN,
155 ink_drop_animation_controller_->GetTargetInkDropState());
156 }
157
158 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickActivated) {
159 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
160 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED);
161 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED);
162 EXPECT_EQ(InkDropState::HIDDEN,
163 ink_drop_animation_controller_->GetTargetInkDropState());
164 }
165
166 TEST_P(InkDropAnimationControllerFactoryTest, TypicalSlowActivated) {
167 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
168 ink_drop_animation_controller_->AnimateToState(
169 InkDropState::ALTERNATE_ACTION_PENDING);
170 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED);
171 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED);
172 EXPECT_EQ(InkDropState::HIDDEN,
173 ink_drop_animation_controller_->GetTargetInkDropState());
174 }
175
176 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_animation_controller_factory.cc ('k') | ui/views/animation/ink_drop_animation_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698