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

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

Issue 1390113006: Added material design mouse hover feedback support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed pkasting@'s comments from patch set 13. Created 5 years, 1 month 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
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_ 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_
6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/timer/mock_timer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/base/test/material_design_controller_test_api.h" 12 #include "ui/base/test/material_design_controller_test_api.h"
13 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
12 #include "ui/views/animation/ink_drop_animation_controller.h" 14 #include "ui/views/animation/ink_drop_animation_controller.h"
13 #include "ui/views/animation/ink_drop_animation_controller_factory.h" 15 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
16 #include "ui/views/animation/ink_drop_animation_controller_impl.h"
14 #include "ui/views/animation/ink_drop_host.h" 17 #include "ui/views/animation/ink_drop_host.h"
15 #include "ui/views/animation/ink_drop_state.h" 18 #include "ui/views/animation/ink_drop_state.h"
19 #include "ui/views/animation/test/test_ink_drop_consumer.h"
16 #include "ui/views/animation/test/test_ink_drop_host.h" 20 #include "ui/views/animation/test/test_ink_drop_host.h"
17 21
18 namespace views { 22 namespace views {
19 23
20 // Macro that will execute |test_code| against all derivatives of the 24 // Macro that will execute |test_code| against all derivatives of the
21 // InkDropAnimationController returned by the InkDropAnimationControllerFactory. 25 // InkDropAnimationController returned by the InkDropAnimationControllerFactory.
22 #define TEST_ALL_INK_DROPS(test_name, test_code) \ 26 #define TEST_ALL_INK_DROPS(test_name, test_code) \
23 TEST_F(InkDropAnimationControllerFactoryTest, test_name) \ 27 TEST_F(InkDropAnimationControllerFactoryTest, test_name) \
24 test_code TEST_F(MDInkDropAnimationControllerFactoryTest, test_name) test_code 28 test_code TEST_F(MDInkDropAnimationControllerFactoryTest, test_name) test_code
25 29
26 // Test fixture to test the non material design InkDropAnimationController. 30 // Test fixture to test the non material design InkDropAnimationController.
27 class InkDropAnimationControllerFactoryTest : public testing::Test { 31 class InkDropAnimationControllerFactoryTest : public testing::Test {
28 public: 32 public:
29 InkDropAnimationControllerFactoryTest() {} 33 InkDropAnimationControllerFactoryTest() {}
30 ~InkDropAnimationControllerFactoryTest() override {} 34 ~InkDropAnimationControllerFactoryTest() override {}
31 35
32 // testing::Test: 36 // testing::Test:
33 void SetUp() override; 37 void SetUp() override;
34 void TearDown() override; 38 void TearDown() override;
35 39
36 protected: 40 protected:
41 // Template function called during SetUp() that sets the
42 // MaterialDesignController::Mode.
43 virtual void SetMaterialMode();
44
45 // Template method called by SetUp() that can be used to configure the
46 // |ink_drop_animation_controller_| instance.
47 virtual void SetupInkDropAnimationController();
48
37 // A dummy InkDropHost required to create an InkDropAnimationController. 49 // A dummy InkDropHost required to create an InkDropAnimationController.
38 TestInkDropHost test_ink_drop_host_; 50 TestInkDropHost test_ink_drop_host_;
39 51
52 // A dummy InkDropConsumer required to create an InkDropAnimationController.
53 test::TestInkDropConsumer test_ink_drop_consumer_;
54
40 // The InkDropAnimationController returned by the 55 // The InkDropAnimationController returned by the
41 // InkDropAnimationControllerFactory test target. 56 // InkDropAnimationControllerFactory test target.
42 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; 57 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_;
43 58
44 private: 59 private:
45 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); 60 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest);
46 }; 61 };
47 62
48 void InkDropAnimationControllerFactoryTest::SetUp() { 63 void InkDropAnimationControllerFactoryTest::SetUp() {
49 // Any call by a previous test to MaterialDesignController::GetMode() will 64 // Any call by a previous test to MaterialDesignController::GetMode() will
50 // initialize and cache the mode. This ensures that these tests will run from 65 // initialize and cache the mode. This ensures that these tests will run from
51 // a non-initialized state. 66 // a non-initialized state.
52 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); 67 ui::test::MaterialDesignControllerTestAPI::UninitializeMode();
53 68
69 SetMaterialMode();
70
54 ink_drop_animation_controller_ = 71 ink_drop_animation_controller_ =
55 InkDropAnimationControllerFactory::CreateInkDropAnimationController( 72 InkDropAnimationControllerFactory::CreateInkDropAnimationController(
56 &test_ink_drop_host_); 73 &test_ink_drop_host_, &test_ink_drop_consumer_);
74
75 SetupInkDropAnimationController();
57 } 76 }
58 77
59 void InkDropAnimationControllerFactoryTest::TearDown() { 78 void InkDropAnimationControllerFactoryTest::TearDown() {
60 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); 79 ui::test::MaterialDesignControllerTestAPI::UninitializeMode();
61 } 80 }
62 81
82 void InkDropAnimationControllerFactoryTest::SetMaterialMode() {
83 ui::test::MaterialDesignControllerTestAPI::SetMode(
84 ui::MaterialDesignController::NON_MATERIAL);
85 }
86
87 void InkDropAnimationControllerFactoryTest::SetupInkDropAnimationController() {}
88
63 // Test fixture to test the material design InkDropAnimationController. 89 // Test fixture to test the material design InkDropAnimationController.
64 class MDInkDropAnimationControllerFactoryTest 90 class MDInkDropAnimationControllerFactoryTest
65 : public InkDropAnimationControllerFactoryTest { 91 : public InkDropAnimationControllerFactoryTest {
66 public: 92 public:
67 MDInkDropAnimationControllerFactoryTest() {} 93 MDInkDropAnimationControllerFactoryTest() {}
68 94
69 // InkDropAnimationControllerFactoryTest: 95 // InkDropAnimationControllerFactoryTest:
70 void SetUp() override; 96 void SetUp() override;
71 97
98 protected:
99 // InkDropAnimationControllerFactoryTest:
100 void SetMaterialMode() override;
101 void SetupInkDropAnimationController() override;
102
72 private: 103 private:
104 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
105
73 DISALLOW_COPY_AND_ASSIGN(MDInkDropAnimationControllerFactoryTest); 106 DISALLOW_COPY_AND_ASSIGN(MDInkDropAnimationControllerFactoryTest);
74 }; 107 };
75 108
76 void MDInkDropAnimationControllerFactoryTest::SetUp() { 109 void MDInkDropAnimationControllerFactoryTest::SetUp() {
77 ui::test::MaterialDesignControllerTestAPI::SetMode( 110 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
78 ui::MaterialDesignController::MATERIAL_NORMAL); 111 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
79 InkDropAnimationControllerFactoryTest::SetUp(); 112 InkDropAnimationControllerFactoryTest::SetUp();
80 } 113 }
81 114
82 TEST_ALL_INK_DROPS(StateIsHiddenInitially, 115 void MDInkDropAnimationControllerFactoryTest::SetMaterialMode() {
116 ui::test::MaterialDesignControllerTestAPI::SetMode(
117 ui::MaterialDesignController::MATERIAL_NORMAL);
118 }
119
120 void MDInkDropAnimationControllerFactoryTest::
121 SetupInkDropAnimationController() {
122 InkDropAnimationControllerImpl* controller =
123 reinterpret_cast<InkDropAnimationControllerImpl*>(
124 ink_drop_animation_controller_.get());
125 controller->SetTimerForTest(new base::MockTimer(false, false));
126 }
127
128 TEST_ALL_INK_DROPS(InitialState,
83 { 129 {
130 EXPECT_FALSE(ink_drop_animation_controller_->IsHovered());
84 EXPECT_EQ( 131 EXPECT_EQ(
85 InkDropState::HIDDEN, 132 InkDropState::HIDDEN,
86 ink_drop_animation_controller_->GetInkDropState()); 133 ink_drop_animation_controller_->GetInkDropState());
87 }) 134 })
88 135
136 TEST_ALL_INK_DROPS(SetHovered,
137 {
138 ink_drop_animation_controller_->SetHovered(true);
139 EXPECT_TRUE(ink_drop_animation_controller_->IsHovered());
140
141 ink_drop_animation_controller_->SetHovered(false);
142 EXPECT_FALSE(ink_drop_animation_controller_->IsHovered());
143 })
144
145 TEST_ALL_INK_DROPS(HoveredStateAfterAnimateToState,
146 {
147 ink_drop_animation_controller_->SetHovered(true);
148 ink_drop_animation_controller_->AnimateToState(
149 InkDropState::QUICK_ACTION);
150
151 EXPECT_FALSE(ink_drop_animation_controller_->IsHovered());
152 })
153
89 TEST_ALL_INK_DROPS(TypicalQuickAction, 154 TEST_ALL_INK_DROPS(TypicalQuickAction,
90 { 155 {
91 ink_drop_animation_controller_->AnimateToState( 156 ink_drop_animation_controller_->AnimateToState(
92 InkDropState::ACTION_PENDING); 157 InkDropState::ACTION_PENDING);
93 ink_drop_animation_controller_->AnimateToState( 158 ink_drop_animation_controller_->AnimateToState(
94 InkDropState::QUICK_ACTION); 159 InkDropState::QUICK_ACTION);
95 EXPECT_EQ( 160 EXPECT_EQ(
96 InkDropState::HIDDEN, 161 InkDropState::HIDDEN,
97 ink_drop_animation_controller_->GetInkDropState()); 162 ink_drop_animation_controller_->GetInkDropState());
98 }) 163 })
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 InkDropState::SLOW_ACTION_PENDING); 219 InkDropState::SLOW_ACTION_PENDING);
155 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); 220 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED);
156 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); 221 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED);
157 EXPECT_EQ(InkDropState::HIDDEN, 222 EXPECT_EQ(InkDropState::HIDDEN,
158 ink_drop_animation_controller_->GetInkDropState()); 223 ink_drop_animation_controller_->GetInkDropState());
159 }) 224 })
160 225
161 } // namespace views 226 } // namespace views
162 227
163 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ 228 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698