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_ | 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 "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/base/test/material_design_controller_test_api.h" | 11 #include "ui/base/test/material_design_controller_test_api.h" |
| 12 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
12 #include "ui/views/animation/ink_drop_animation_controller.h" | 13 #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_animation_controller_factory.h" |
14 #include "ui/views/animation/ink_drop_host.h" | 15 #include "ui/views/animation/ink_drop_host.h" |
15 #include "ui/views/animation/ink_drop_state.h" | 16 #include "ui/views/animation/ink_drop_state.h" |
16 #include "ui/views/animation/test/test_ink_drop_host.h" | 17 #include "ui/views/animation/test/test_ink_drop_host.h" |
17 | 18 |
18 namespace views { | 19 namespace views { |
19 | 20 |
20 // Macro that will execute |test_code| against all derivatives of the | 21 // Macro that will execute |test_code| against all derivatives of the |
21 // InkDropAnimationController returned by the InkDropAnimationControllerFactory. | 22 // InkDropAnimationController returned by the InkDropAnimationControllerFactory. |
22 #define TEST_ALL_INK_DROPS(test_name, test_code) \ | 23 #define TEST_ALL_INK_DROPS(test_name, test_code) \ |
23 TEST_F(InkDropAnimationControllerFactoryTest, test_name) \ | 24 TEST_F(InkDropAnimationControllerFactoryTest, test_name) \ |
24 test_code TEST_F(MDInkDropAnimationControllerFactoryTest, test_name) test_code | 25 test_code TEST_F(MDInkDropAnimationControllerFactoryTest, test_name) test_code |
25 | 26 |
26 // Test fixture to test the non material design InkDropAnimationController. | 27 // Test fixture to test the non material design InkDropAnimationController. |
27 class InkDropAnimationControllerFactoryTest : public testing::Test { | 28 class InkDropAnimationControllerFactoryTest : public testing::Test { |
28 public: | 29 public: |
29 InkDropAnimationControllerFactoryTest() {} | 30 InkDropAnimationControllerFactoryTest() {} |
30 ~InkDropAnimationControllerFactoryTest() override {} | 31 ~InkDropAnimationControllerFactoryTest() override {} |
31 | 32 |
32 // testing::Test: | 33 // testing::Test: |
33 void SetUp() override; | 34 void SetUp() override; |
34 void TearDown() override; | 35 void TearDown() override; |
35 | 36 |
36 protected: | 37 protected: |
| 38 // Template function called during SetUp() that sets the |
| 39 // MaterialDesignController::Mode. |
| 40 virtual void SetMaterialMode(); |
| 41 |
37 // A dummy InkDropHost required to create an InkDropAnimationController. | 42 // A dummy InkDropHost required to create an InkDropAnimationController. |
38 TestInkDropHost test_ink_drop_host_; | 43 TestInkDropHost test_ink_drop_host_; |
39 | 44 |
40 // The InkDropAnimationController returned by the | 45 // The InkDropAnimationController returned by the |
41 // InkDropAnimationControllerFactory test target. | 46 // InkDropAnimationControllerFactory test target. |
42 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; | 47 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; |
43 | 48 |
44 private: | 49 private: |
45 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); | 50 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); |
46 }; | 51 }; |
47 | 52 |
48 void InkDropAnimationControllerFactoryTest::SetUp() { | 53 void InkDropAnimationControllerFactoryTest::SetUp() { |
49 // Any call by a previous test to MaterialDesignController::GetMode() will | 54 // Any call by a previous test to MaterialDesignController::GetMode() will |
50 // initialize and cache the mode. This ensures that these tests will run from | 55 // initialize and cache the mode. This ensures that these tests will run from |
51 // a non-initialized state. | 56 // a non-initialized state. |
52 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 57 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
53 | 58 |
| 59 SetMaterialMode(); |
| 60 |
54 ink_drop_animation_controller_ = | 61 ink_drop_animation_controller_ = |
55 InkDropAnimationControllerFactory::CreateInkDropAnimationController( | 62 InkDropAnimationControllerFactory::CreateInkDropAnimationController( |
56 &test_ink_drop_host_); | 63 &test_ink_drop_host_); |
57 } | 64 } |
58 | 65 |
59 void InkDropAnimationControllerFactoryTest::TearDown() { | 66 void InkDropAnimationControllerFactoryTest::TearDown() { |
60 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 67 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
61 } | 68 } |
62 | 69 |
| 70 void InkDropAnimationControllerFactoryTest::SetMaterialMode() { |
| 71 ui::test::MaterialDesignControllerTestAPI::SetMode( |
| 72 ui::MaterialDesignController::NON_MATERIAL); |
| 73 } |
| 74 |
63 // Test fixture to test the material design InkDropAnimationController. | 75 // Test fixture to test the material design InkDropAnimationController. |
64 class MDInkDropAnimationControllerFactoryTest | 76 class MDInkDropAnimationControllerFactoryTest |
65 : public InkDropAnimationControllerFactoryTest { | 77 : public InkDropAnimationControllerFactoryTest { |
66 public: | 78 public: |
67 MDInkDropAnimationControllerFactoryTest() {} | 79 MDInkDropAnimationControllerFactoryTest() {} |
68 | 80 |
69 // InkDropAnimationControllerFactoryTest: | 81 // InkDropAnimationControllerFactoryTest: |
70 void SetUp() override; | 82 void SetUp() override; |
71 | 83 |
| 84 protected: |
| 85 // InkDropAnimationControllerFactoryTest: |
| 86 void SetMaterialMode() override; |
| 87 |
72 private: | 88 private: |
| 89 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; |
| 90 |
73 DISALLOW_COPY_AND_ASSIGN(MDInkDropAnimationControllerFactoryTest); | 91 DISALLOW_COPY_AND_ASSIGN(MDInkDropAnimationControllerFactoryTest); |
74 }; | 92 }; |
75 | 93 |
76 void MDInkDropAnimationControllerFactoryTest::SetUp() { | 94 void MDInkDropAnimationControllerFactoryTest::SetUp() { |
77 ui::test::MaterialDesignControllerTestAPI::SetMode( | 95 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
78 ui::MaterialDesignController::MATERIAL_NORMAL); | 96 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
79 InkDropAnimationControllerFactoryTest::SetUp(); | 97 InkDropAnimationControllerFactoryTest::SetUp(); |
80 } | 98 } |
81 | 99 |
82 TEST_ALL_INK_DROPS(StateIsHiddenInitially, | 100 void MDInkDropAnimationControllerFactoryTest::SetMaterialMode() { |
| 101 ui::test::MaterialDesignControllerTestAPI::SetMode( |
| 102 ui::MaterialDesignController::MATERIAL_NORMAL); |
| 103 } |
| 104 |
| 105 TEST_ALL_INK_DROPS(InitialState, |
83 { | 106 { |
| 107 EXPECT_FALSE(ink_drop_animation_controller_->IsHovered()); |
84 EXPECT_EQ( | 108 EXPECT_EQ( |
85 InkDropState::HIDDEN, | 109 InkDropState::HIDDEN, |
86 ink_drop_animation_controller_->GetInkDropState()); | 110 ink_drop_animation_controller_->GetInkDropState()); |
87 }) | 111 }) |
88 | 112 |
| 113 TEST_ALL_INK_DROPS(SetHovered, |
| 114 { |
| 115 ink_drop_animation_controller_->SetHovered(true); |
| 116 EXPECT_TRUE(ink_drop_animation_controller_->IsHovered()); |
| 117 |
| 118 ink_drop_animation_controller_->SetHovered(false); |
| 119 EXPECT_FALSE(ink_drop_animation_controller_->IsHovered()); |
| 120 }) |
| 121 |
| 122 TEST_ALL_INK_DROPS(HoveredStateAfterAnimateToState, |
| 123 { |
| 124 ink_drop_animation_controller_->SetHovered(true); |
| 125 ink_drop_animation_controller_->AnimateToState( |
| 126 InkDropState::QUICK_ACTION); |
| 127 |
| 128 EXPECT_FALSE(ink_drop_animation_controller_->IsHovered()); |
| 129 }) |
| 130 |
89 TEST_ALL_INK_DROPS(TypicalQuickAction, | 131 TEST_ALL_INK_DROPS(TypicalQuickAction, |
90 { | 132 { |
91 ink_drop_animation_controller_->AnimateToState( | 133 ink_drop_animation_controller_->AnimateToState( |
92 InkDropState::ACTION_PENDING); | 134 InkDropState::ACTION_PENDING); |
93 ink_drop_animation_controller_->AnimateToState( | 135 ink_drop_animation_controller_->AnimateToState( |
94 InkDropState::QUICK_ACTION); | 136 InkDropState::QUICK_ACTION); |
95 EXPECT_EQ( | 137 EXPECT_EQ( |
96 InkDropState::HIDDEN, | 138 InkDropState::HIDDEN, |
97 ink_drop_animation_controller_->GetInkDropState()); | 139 ink_drop_animation_controller_->GetInkDropState()); |
98 }) | 140 }) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 InkDropState::SLOW_ACTION_PENDING); | 196 InkDropState::SLOW_ACTION_PENDING); |
155 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); | 197 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); |
156 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); | 198 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); |
157 EXPECT_EQ(InkDropState::HIDDEN, | 199 EXPECT_EQ(InkDropState::HIDDEN, |
158 ink_drop_animation_controller_->GetInkDropState()); | 200 ink_drop_animation_controller_->GetInkDropState()); |
159 }) | 201 }) |
160 | 202 |
161 } // namespace views | 203 } // namespace views |
162 | 204 |
163 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ | 205 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ |
OLD | NEW |