| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "ui/views/animation/ink_drop_impl.h" | 7 #include "ui/views/animation/ink_drop_impl.h" |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/test/test_simple_task_runner.h" | 11 #include "base/test/test_simple_task_runner.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 14 #include "ui/views/animation/test/ink_drop_impl_test_api.h" | 15 #include "ui/views/animation/test/ink_drop_impl_test_api.h" |
| 15 #include "ui/views/animation/test/test_ink_drop_host.h" | 16 #include "ui/views/animation/test/test_ink_drop_host.h" |
| 16 | 17 |
| 17 namespace views { | 18 namespace views { |
| 18 | 19 |
| 19 // NOTE: The InkDropImpl class is also tested by the InkDropFactoryTest tests. | 20 // NOTE: The InkDropImpl class is also tested by the InkDropFactoryTest tests. |
| 20 class InkDropImplTest : public testing::Test { | 21 class InkDropImplTest : public testing::Test { |
| 21 public: | 22 public: |
| 22 InkDropImplTest(); | 23 InkDropImplTest(); |
| 23 ~InkDropImplTest() override; | 24 ~InkDropImplTest() override; |
| 24 | 25 |
| 25 protected: | 26 protected: |
| 26 TestInkDropHost* ink_drop_host() { return ink_drop_host_.get(); } | 27 TestInkDropHost* ink_drop_host() { return ink_drop_host_.get(); } |
| 27 | 28 |
| 28 InkDropImpl* ink_drop() { return ink_drop_.get(); } | 29 InkDropImpl* ink_drop() { return ink_drop_.get(); } |
| 29 | 30 |
| 30 test::InkDropImplTestApi* test_api() { return test_api_.get(); } | 31 test::InkDropImplTestApi* test_api() { return test_api_.get(); } |
| 31 | 32 |
| 32 // Runs all the pending tasks in |task_runner_|. This can be used to progress | 33 // Runs all the pending tasks in |task_runner_|. This can be used to progress |
| 33 // timers. e.g. HideHighlightOnRippleHiddenState's | 34 // timers. e.g. HideHighlightOnRippleHiddenState's |
| 34 // |highlight_after_ripple_timer_|. | 35 // |highlight_after_ripple_timer_|. |
| 35 void RunPendingTasks(); | 36 void RunPendingTasks(); |
| 36 | 37 |
| 37 // Returns true if the ink drop layers have been added to |ink_drop_host_|. | 38 // Returns true if the ink drop layers have been added to |ink_drop_host_|. |
| 38 bool AreLayersAddedToHost() const; | 39 bool AreLayersAddedToHost() const; |
| 39 | 40 |
| 40 // Destroyes the |ink_drop_| and assocated |test_api_|. | 41 // Destroys the |ink_drop_| and associated |test_api_|. |
| 41 void DestroyInkDrop(); | 42 void DestroyInkDrop(); |
| 42 | 43 |
| 43 // Used to control the tasks scheduled by the InkDropImpl's Timer. | 44 // Used to control the tasks scheduled by the InkDropImpl's Timer. |
| 44 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 45 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 45 | 46 |
| 46 // Required by base::Timer's. | 47 // Required by base::Timer's. |
| 47 std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; | 48 std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 std::unique_ptr<TestInkDropHost> ink_drop_host_; | 51 std::unique_ptr<TestInkDropHost> ink_drop_host_; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 248 |
| 248 // Verifies there is no use after free errors. | 249 // Verifies there is no use after free errors. |
| 249 TEST_F(InkDropImplTest, | 250 TEST_F(InkDropImplTest, |
| 250 TearingDownHighlightStateThatAccessesTheStateFactoryIsSafe) { | 251 TearingDownHighlightStateThatAccessesTheStateFactoryIsSafe) { |
| 251 test::InkDropImplTestApi::AccessFactoryOnExitHighlightState::Install( | 252 test::InkDropImplTestApi::AccessFactoryOnExitHighlightState::Install( |
| 252 test_api()->state_factory()); | 253 test_api()->state_factory()); |
| 253 test::InkDropImplTestApi::AccessFactoryOnExitHighlightState::Install( | 254 test::InkDropImplTestApi::AccessFactoryOnExitHighlightState::Install( |
| 254 test_api()->state_factory()); | 255 test_api()->state_factory()); |
| 255 } | 256 } |
| 256 | 257 |
| 258 // Tests that if during destruction, a rippl animation is successfully ended, no |
| 259 // crash happens (see https://crbug.com/663579). |
| 260 TEST_F(InkDropImplTest, SuccessfulAnimationEndedDuringDestruction) { |
| 261 // Start a ripple animation with non-zero duration. |
| 262 ink_drop()->AnimateToState(InkDropState::ACTION_PENDING); |
| 263 { |
| 264 // Start another ripple animation with zero duration that would be queued |
| 265 // until the previous one is finished/aborted. |
| 266 ui::ScopedAnimationDurationScaleMode duration_mode( |
| 267 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 268 ink_drop()->AnimateToState(InkDropState::ACTION_TRIGGERED); |
| 269 } |
| 270 // Abort the first animation, so that the queued animation is started (and |
| 271 // finished immediately since it has zero duration). No crash should happen. |
| 272 DestroyInkDrop(); |
| 273 } |
| 274 |
| 257 //////////////////////////////////////////////////////////////////////////////// | 275 //////////////////////////////////////////////////////////////////////////////// |
| 258 // | 276 // |
| 259 // Common AutoHighlightMode tests | 277 // Common AutoHighlightMode tests |
| 260 // | 278 // |
| 261 | 279 |
| 262 typedef InkDropImplAutoHighlightTest InkDropImplCommonAutoHighlightTest; | 280 typedef InkDropImplAutoHighlightTest InkDropImplCommonAutoHighlightTest; |
| 263 // Note: First argument is optional and intentionally left blank. | 281 // Note: First argument is optional and intentionally left blank. |
| 264 // (it's a prefix for the generated test cases) | 282 // (it's a prefix for the generated test cases) |
| 265 INSTANTIATE_TEST_CASE_P( | 283 INSTANTIATE_TEST_CASE_P( |
| 266 , | 284 , |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 EXPECT_TRUE(test_api()->IsHighlightFadingInOrVisible()); | 558 EXPECT_TRUE(test_api()->IsHighlightFadingInOrVisible()); |
| 541 | 559 |
| 542 ink_drop()->SetHovered(false); | 560 ink_drop()->SetHovered(false); |
| 543 ink_drop()->SetFocused(false); | 561 ink_drop()->SetFocused(false); |
| 544 | 562 |
| 545 EXPECT_TRUE(test_api()->IsHighlightFadingInOrVisible()); | 563 EXPECT_TRUE(test_api()->IsHighlightFadingInOrVisible()); |
| 546 EXPECT_FALSE(test_api()->ShouldHighlight()); | 564 EXPECT_FALSE(test_api()->ShouldHighlight()); |
| 547 } | 565 } |
| 548 | 566 |
| 549 } // namespace views | 567 } // namespace views |
| OLD | NEW |