| OLD | NEW |
| (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_impl.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/test/test_simple_task_runner.h" | |
| 9 #include "base/thread_task_runner_handle.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 #include "ui/views/animation/ink_drop_ripple.h" | |
| 12 #include "ui/views/animation/test/ink_drop_animation_controller_impl_test_api.h" | |
| 13 #include "ui/views/animation/test/test_ink_drop_host.h" | |
| 14 | |
| 15 namespace views { | |
| 16 | |
| 17 // NOTE: The InkDropAnimationControllerImpl class is also tested by the | |
| 18 // InkDropAnimationControllerFactoryTest tests. | |
| 19 class InkDropAnimationControllerImplTest : public testing::Test { | |
| 20 public: | |
| 21 InkDropAnimationControllerImplTest(); | |
| 22 ~InkDropAnimationControllerImplTest() override; | |
| 23 | |
| 24 protected: | |
| 25 TestInkDropHost ink_drop_host_; | |
| 26 | |
| 27 // The test target. | |
| 28 InkDropAnimationControllerImpl ink_drop_animation_controller_; | |
| 29 | |
| 30 // Allows privileged access to the the |ink_drop_hover_|. | |
| 31 test::InkDropAnimationControllerImplTestApi test_api_; | |
| 32 | |
| 33 // Used to control the tasks scheduled by the InkDropAnimationControllerImpl's | |
| 34 // Timer. | |
| 35 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | |
| 36 | |
| 37 // Required by base::Timer's. | |
| 38 std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; | |
| 39 | |
| 40 private: | |
| 41 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerImplTest); | |
| 42 }; | |
| 43 | |
| 44 InkDropAnimationControllerImplTest::InkDropAnimationControllerImplTest() | |
| 45 : ink_drop_animation_controller_(&ink_drop_host_), | |
| 46 test_api_(&ink_drop_animation_controller_), | |
| 47 task_runner_(new base::TestSimpleTaskRunner), | |
| 48 thread_task_runner_handle_( | |
| 49 new base::ThreadTaskRunnerHandle(task_runner_)) { | |
| 50 ink_drop_host_.set_disable_timers_for_test(true); | |
| 51 } | |
| 52 | |
| 53 InkDropAnimationControllerImplTest::~InkDropAnimationControllerImplTest() {} | |
| 54 | |
| 55 TEST_F(InkDropAnimationControllerImplTest, SetHoveredIsFadingInOrVisible) { | |
| 56 ink_drop_host_.set_should_show_hover(true); | |
| 57 | |
| 58 ink_drop_animation_controller_.SetHovered(true); | |
| 59 EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible()); | |
| 60 | |
| 61 test_api_.CompleteAnimations(); | |
| 62 | |
| 63 ink_drop_animation_controller_.SetHovered(false); | |
| 64 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible()); | |
| 65 } | |
| 66 | |
| 67 TEST_F(InkDropAnimationControllerImplTest, | |
| 68 HoverDoesntFadeInAfterAnimationIfHoverNotSet) { | |
| 69 ink_drop_host_.set_should_show_hover(true); | |
| 70 ink_drop_animation_controller_.SetHovered(false); | |
| 71 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED); | |
| 72 test_api_.CompleteAnimations(); | |
| 73 | |
| 74 EXPECT_FALSE(task_runner_->HasPendingTask()); | |
| 75 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible()); | |
| 76 } | |
| 77 | |
| 78 TEST_F(InkDropAnimationControllerImplTest, | |
| 79 HoverFadesInAfterAnimationWhenHostIsHovered) { | |
| 80 ink_drop_host_.set_should_show_hover(true); | |
| 81 ink_drop_animation_controller_.SetHovered(true); | |
| 82 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED); | |
| 83 test_api_.CompleteAnimations(); | |
| 84 | |
| 85 EXPECT_TRUE(task_runner_->HasPendingTask()); | |
| 86 | |
| 87 task_runner_->RunPendingTasks(); | |
| 88 | |
| 89 EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible()); | |
| 90 } | |
| 91 | |
| 92 TEST_F(InkDropAnimationControllerImplTest, | |
| 93 HoverDoesntFadeInAfterAnimationWhenHostIsNotHovered) { | |
| 94 ink_drop_host_.set_should_show_hover(false); | |
| 95 ink_drop_animation_controller_.SetHovered(true); | |
| 96 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED); | |
| 97 test_api_.CompleteAnimations(); | |
| 98 | |
| 99 EXPECT_TRUE(task_runner_->HasPendingTask()); | |
| 100 | |
| 101 task_runner_->RunPendingTasks(); | |
| 102 | |
| 103 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible()); | |
| 104 } | |
| 105 | |
| 106 TEST_F(InkDropAnimationControllerImplTest, | |
| 107 HoveredStateNotVisibleOrFadingInAfterAnimateToState) { | |
| 108 ink_drop_host_.set_should_show_hover(true); | |
| 109 | |
| 110 ink_drop_animation_controller_.SetHovered(true); | |
| 111 test_api_.CompleteAnimations(); | |
| 112 EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible()); | |
| 113 | |
| 114 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED); | |
| 115 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible()); | |
| 116 } | |
| 117 | |
| 118 // Verifies that there is not a crash when setting hovered state and the host | |
| 119 // returns null for the hover. | |
| 120 TEST_F(InkDropAnimationControllerImplTest, | |
| 121 SetHoveredFalseWorksWhenNoInkDropHoverExists) { | |
| 122 ink_drop_host_.set_should_show_hover(false); | |
| 123 ink_drop_animation_controller_.SetHovered(true); | |
| 124 EXPECT_FALSE(test_api_.hover()); | |
| 125 ink_drop_animation_controller_.SetHovered(false); | |
| 126 EXPECT_FALSE(test_api_.hover()); | |
| 127 } | |
| 128 | |
| 129 TEST_F(InkDropAnimationControllerImplTest, HoverFadesOutOnSnapToActivated) { | |
| 130 ink_drop_host_.set_should_show_hover(true); | |
| 131 ink_drop_animation_controller_.SetHovered(true); | |
| 132 test_api_.CompleteAnimations(); | |
| 133 | |
| 134 EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible()); | |
| 135 | |
| 136 ink_drop_animation_controller_.SnapToActivated(); | |
| 137 | |
| 138 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible()); | |
| 139 } | |
| 140 | |
| 141 TEST_F(InkDropAnimationControllerImplTest, LayersRemovedFromHostAfterHover) { | |
| 142 ink_drop_host_.set_should_show_hover(true); | |
| 143 | |
| 144 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 145 | |
| 146 ink_drop_animation_controller_.SetHovered(true); | |
| 147 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 148 | |
| 149 test_api_.CompleteAnimations(); | |
| 150 | |
| 151 ink_drop_animation_controller_.SetHovered(false); | |
| 152 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 153 | |
| 154 test_api_.CompleteAnimations(); | |
| 155 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 156 } | |
| 157 | |
| 158 TEST_F(InkDropAnimationControllerImplTest, LayersRemovedFromHostAfterInkDrop) { | |
| 159 ink_drop_host_.set_should_show_hover(true); | |
| 160 | |
| 161 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 162 | |
| 163 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_PENDING); | |
| 164 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 165 | |
| 166 ink_drop_animation_controller_.AnimateToState(InkDropState::HIDDEN); | |
| 167 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 168 | |
| 169 test_api_.CompleteAnimations(); | |
| 170 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 171 } | |
| 172 | |
| 173 TEST_F(InkDropAnimationControllerImplTest, | |
| 174 LayersAddedToHostWhenHoverOrInkDropVisible) { | |
| 175 ink_drop_host_.set_should_show_hover(true); | |
| 176 | |
| 177 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 178 | |
| 179 ink_drop_animation_controller_.SetHovered(true); | |
| 180 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 181 | |
| 182 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_PENDING); | |
| 183 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 184 | |
| 185 ink_drop_animation_controller_.AnimateToState(InkDropState::HIDDEN); | |
| 186 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 187 | |
| 188 test_api_.CompleteAnimations(); | |
| 189 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 190 | |
| 191 EXPECT_TRUE(task_runner_->HasPendingTask()); | |
| 192 task_runner_->RunPendingTasks(); | |
| 193 | |
| 194 // Hover should be fading back in. | |
| 195 EXPECT_TRUE(test_api_.HasActiveAnimations()); | |
| 196 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 197 } | |
| 198 | |
| 199 TEST_F(InkDropAnimationControllerImplTest, | |
| 200 LayersNotAddedToHostWhenHoverTimeFires) { | |
| 201 ink_drop_host_.set_should_show_hover(true); | |
| 202 | |
| 203 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 204 | |
| 205 ink_drop_animation_controller_.SetHovered(true); | |
| 206 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 207 | |
| 208 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_PENDING); | |
| 209 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 210 | |
| 211 ink_drop_animation_controller_.AnimateToState(InkDropState::HIDDEN); | |
| 212 test_api_.CompleteAnimations(); | |
| 213 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 214 | |
| 215 ink_drop_host_.set_should_show_hover(false); | |
| 216 | |
| 217 EXPECT_TRUE(task_runner_->HasPendingTask()); | |
| 218 task_runner_->RunPendingTasks(); | |
| 219 | |
| 220 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 221 } | |
| 222 | |
| 223 TEST_F(InkDropAnimationControllerImplTest, | |
| 224 LayersArentRemovedWhenPreemptingFadeOut) { | |
| 225 ink_drop_host_.set_should_show_hover(true); | |
| 226 | |
| 227 EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers()); | |
| 228 | |
| 229 ink_drop_animation_controller_.SetHovered(true); | |
| 230 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 231 | |
| 232 test_api_.CompleteAnimations(); | |
| 233 | |
| 234 ink_drop_animation_controller_.SetHovered(false); | |
| 235 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 236 | |
| 237 ink_drop_animation_controller_.SetHovered(true); | |
| 238 EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers()); | |
| 239 } | |
| 240 | |
| 241 } // namespace views | |
| OLD | NEW |