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 #include "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "base/timer/timer.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/base/resource/material_design/material_design_controller.h" | 10 #include "ui/base/resource/material_design/material_design_controller.h" |
9 #include "ui/base/test/material_design_controller_test_api.h" | 11 #include "ui/base/test/material_design_controller_test_api.h" |
10 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 12 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
11 #include "ui/views/animation/ink_drop_animation_controller.h" | 13 #include "ui/views/animation/ink_drop_animation_controller.h" |
12 #include "ui/views/animation/ink_drop_animation_controller_factory.h" | 14 #include "ui/views/animation/ink_drop_animation_controller_factory.h" |
| 15 #include "ui/views/animation/ink_drop_animation_controller_impl.h" |
13 #include "ui/views/animation/ink_drop_host.h" | 16 #include "ui/views/animation/ink_drop_host.h" |
14 #include "ui/views/animation/ink_drop_state.h" | 17 #include "ui/views/animation/ink_drop_state.h" |
15 #include "ui/views/animation/test/test_ink_drop_host.h" | 18 #include "ui/views/animation/test/test_ink_drop_host.h" |
16 | 19 |
17 namespace views { | 20 namespace views { |
| 21 typedef void SetupInkDropAnimationControllerFunc(InkDropAnimationController*); |
| 22 |
| 23 // Dummy no-op setup function that can be used with the |
| 24 // InkDropAnimationControllerFactoryTest fixture. |
| 25 void DummySetupInkDropAnimationController(InkDropAnimationController*) {} |
18 | 26 |
19 class InkDropAnimationControllerFactoryTest | 27 class InkDropAnimationControllerFactoryTest |
20 : public testing::TestWithParam<ui::MaterialDesignController::Mode> { | 28 : public testing::TestWithParam< |
| 29 testing::tuple<ui::MaterialDesignController::Mode, |
| 30 SetupInkDropAnimationControllerFunc*>> { |
21 public: | 31 public: |
| 32 // InkDropAnimationController setup function to be used to configure all |
| 33 // Material based controllers. Can be used when instantiating |
| 34 // InkDropAnimationControllerFactoryTest fixtures. |
| 35 // |
| 36 // Note: This is implemented as a static member function because |
| 37 // InkDropAnimationControllerImpl::hover_after_animation_timer_for_test() is |
| 38 // private and is only accessible due to a friend declaration. |
| 39 static void MDSetupInkDropAnimationController( |
| 40 InkDropAnimationController* controller) { |
| 41 InkDropAnimationControllerImpl* controller_impl = |
| 42 reinterpret_cast<InkDropAnimationControllerImpl*>(controller); |
| 43 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
| 44 new base::TestSimpleTaskRunner(); |
| 45 controller_impl->hover_after_animation_timer_for_test()->SetTaskRunner( |
| 46 task_runner); |
| 47 } |
| 48 |
22 InkDropAnimationControllerFactoryTest(); | 49 InkDropAnimationControllerFactoryTest(); |
23 ~InkDropAnimationControllerFactoryTest(); | 50 ~InkDropAnimationControllerFactoryTest(); |
24 | 51 |
25 protected: | 52 protected: |
26 // A dummy InkDropHost required to create an InkDropAnimationController. | 53 // A dummy InkDropHost required to create an InkDropAnimationController. |
27 TestInkDropHost test_ink_drop_host_; | 54 TestInkDropHost test_ink_drop_host_; |
28 | 55 |
29 // The InkDropAnimationController returned by the | 56 // The InkDropAnimationController returned by the |
30 // InkDropAnimationControllerFactory test target. | 57 // InkDropAnimationControllerFactory test target. |
31 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; | 58 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; |
32 | 59 |
33 private: | 60 private: |
34 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; | 61 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; |
35 | 62 |
36 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); | 63 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); |
37 }; | 64 }; |
38 | 65 |
39 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest() | 66 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest() |
40 : ink_drop_animation_controller_(nullptr) { | 67 : ink_drop_animation_controller_(nullptr) { |
41 // Any call by a previous test to MaterialDesignController::GetMode() will | 68 // Any call by a previous test to MaterialDesignController::GetMode() will |
42 // initialize and cache the mode. This ensures that these tests will run from | 69 // initialize and cache the mode. This ensures that these tests will run from |
43 // a non-initialized state. | 70 // a non-initialized state. |
44 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 71 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
45 ui::test::MaterialDesignControllerTestAPI::SetMode(GetParam()); | 72 ui::test::MaterialDesignControllerTestAPI::SetMode( |
| 73 testing::get<0>(GetParam())); |
46 ink_drop_animation_controller_.reset( | 74 ink_drop_animation_controller_.reset( |
47 InkDropAnimationControllerFactory::CreateInkDropAnimationController( | 75 InkDropAnimationControllerFactory::CreateInkDropAnimationController( |
48 &test_ink_drop_host_) | 76 &test_ink_drop_host_) |
49 .release()); | 77 .release()); |
50 ink_drop_animation_controller_->SetInkDropSize(gfx::Size(10, 10), 4, | 78 ink_drop_animation_controller_->SetInkDropSize(gfx::Size(10, 10), 4, |
51 gfx::Size(8, 8), 2); | 79 gfx::Size(8, 8), 2); |
52 | 80 |
53 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 81 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
54 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 82 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
| 83 |
| 84 SetupInkDropAnimationControllerFunc* setup_controller_func = |
| 85 testing::get<1>(GetParam()); |
| 86 (*setup_controller_func)(ink_drop_animation_controller_.get()); |
55 } | 87 } |
56 | 88 |
57 InkDropAnimationControllerFactoryTest:: | 89 InkDropAnimationControllerFactoryTest:: |
58 ~InkDropAnimationControllerFactoryTest() { | 90 ~InkDropAnimationControllerFactoryTest() { |
59 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 91 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
60 } | 92 } |
61 | 93 |
62 // Note: First argument is optional and intentionally left blank. | 94 // Note: First argument is optional and intentionally left blank. |
63 // (it's a prefix for the generated test cases) | 95 // (it's a prefix for the generated test cases) |
64 INSTANTIATE_TEST_CASE_P( | 96 INSTANTIATE_TEST_CASE_P( |
65 , | 97 , |
66 InkDropAnimationControllerFactoryTest, | 98 InkDropAnimationControllerFactoryTest, |
67 testing::Values(ui::MaterialDesignController::NON_MATERIAL, | 99 testing::Values( |
68 ui::MaterialDesignController::MATERIAL_NORMAL)); | 100 testing::make_tuple(ui::MaterialDesignController::NON_MATERIAL, |
| 101 &DummySetupInkDropAnimationController), |
| 102 testing::make_tuple(ui::MaterialDesignController::MATERIAL_NORMAL, |
| 103 &InkDropAnimationControllerFactoryTest:: |
| 104 MDSetupInkDropAnimationController))); |
69 | 105 |
70 TEST_P(InkDropAnimationControllerFactoryTest, | 106 TEST_P(InkDropAnimationControllerFactoryTest, |
71 VerifyAllInkDropLayersRemovedAfterDestruction) { | 107 VerifyAllInkDropLayersRemovedAfterDestruction) { |
72 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); | 108 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
73 ink_drop_animation_controller_.reset(); | 109 ink_drop_animation_controller_.reset(); |
74 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); | 110 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); |
75 } | 111 } |
76 | 112 |
77 TEST_P(InkDropAnimationControllerFactoryTest, StateIsHiddenInitially) { | 113 TEST_P(InkDropAnimationControllerFactoryTest, StateIsHiddenInitially) { |
78 EXPECT_EQ(InkDropState::HIDDEN, | 114 EXPECT_EQ(InkDropState::HIDDEN, |
79 ink_drop_animation_controller_->GetInkDropState()); | 115 ink_drop_animation_controller_->GetInkDropState()); |
80 } | 116 } |
81 | 117 |
| 118 TEST_P(InkDropAnimationControllerFactoryTest, HoveredStateAfterAnimateToState) { |
| 119 ink_drop_animation_controller_->SetHovered(true); |
| 120 ink_drop_animation_controller_->AnimateToState(InkDropState::QUICK_ACTION); |
| 121 |
| 122 EXPECT_FALSE(ink_drop_animation_controller_->IsHovered()); |
| 123 } |
| 124 |
82 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickAction) { | 125 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickAction) { |
83 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); | 126 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
84 ink_drop_animation_controller_->AnimateToState(InkDropState::QUICK_ACTION); | 127 ink_drop_animation_controller_->AnimateToState(InkDropState::QUICK_ACTION); |
85 EXPECT_EQ(InkDropState::HIDDEN, | 128 EXPECT_EQ(InkDropState::HIDDEN, |
86 ink_drop_animation_controller_->GetInkDropState()); | 129 ink_drop_animation_controller_->GetInkDropState()); |
87 } | 130 } |
88 | 131 |
89 TEST_P(InkDropAnimationControllerFactoryTest, CancelQuickAction) { | 132 TEST_P(InkDropAnimationControllerFactoryTest, CancelQuickAction) { |
90 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); | 133 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
91 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); | 134 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); | 166 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
124 ink_drop_animation_controller_->AnimateToState( | 167 ink_drop_animation_controller_->AnimateToState( |
125 InkDropState::SLOW_ACTION_PENDING); | 168 InkDropState::SLOW_ACTION_PENDING); |
126 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); | 169 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); |
127 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); | 170 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); |
128 EXPECT_EQ(InkDropState::HIDDEN, | 171 EXPECT_EQ(InkDropState::HIDDEN, |
129 ink_drop_animation_controller_->GetInkDropState()); | 172 ink_drop_animation_controller_->GetInkDropState()); |
130 } | 173 } |
131 | 174 |
132 } // namespace views | 175 } // namespace views |
OLD | NEW |