| 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_hover.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/macros.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/time/time.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
| 14 #include "ui/gfx/geometry/size.h" | |
| 15 #include "ui/views/animation/test/ink_drop_hover_test_api.h" | |
| 16 #include "ui/views/animation/test/test_ink_drop_hover_observer.h" | |
| 17 | |
| 18 namespace views { | |
| 19 namespace test { | |
| 20 | |
| 21 class InkDropHoverTest : public testing::Test { | |
| 22 public: | |
| 23 InkDropHoverTest(); | |
| 24 ~InkDropHoverTest() override; | |
| 25 | |
| 26 protected: | |
| 27 // The test target. | |
| 28 std::unique_ptr<InkDropHover> ink_drop_hover_; | |
| 29 | |
| 30 // Allows privileged access to the the |ink_drop_hover_|. | |
| 31 InkDropHoverTestApi test_api_; | |
| 32 | |
| 33 // Observer of the test target. | |
| 34 TestInkDropHoverObserver observer_; | |
| 35 | |
| 36 private: | |
| 37 DISALLOW_COPY_AND_ASSIGN(InkDropHoverTest); | |
| 38 }; | |
| 39 | |
| 40 InkDropHoverTest::InkDropHoverTest() | |
| 41 : ink_drop_hover_( | |
| 42 new InkDropHover(gfx::Size(10, 10), 3, gfx::Point(), SK_ColorBLACK)), | |
| 43 test_api_(ink_drop_hover_.get()) { | |
| 44 ink_drop_hover_->set_observer(&observer_); | |
| 45 | |
| 46 test_api_.SetDisableAnimationTimers(true); | |
| 47 } | |
| 48 | |
| 49 InkDropHoverTest::~InkDropHoverTest() {} | |
| 50 | |
| 51 TEST_F(InkDropHoverTest, InitialStateAfterConstruction) { | |
| 52 EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible()); | |
| 53 } | |
| 54 | |
| 55 TEST_F(InkDropHoverTest, IsHoveredStateTransitions) { | |
| 56 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1)); | |
| 57 EXPECT_TRUE(ink_drop_hover_->IsFadingInOrVisible()); | |
| 58 | |
| 59 test_api_.CompleteAnimations(); | |
| 60 EXPECT_TRUE(ink_drop_hover_->IsFadingInOrVisible()); | |
| 61 | |
| 62 ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1), | |
| 63 false /* explode */); | |
| 64 EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible()); | |
| 65 | |
| 66 test_api_.CompleteAnimations(); | |
| 67 EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible()); | |
| 68 } | |
| 69 | |
| 70 TEST_F(InkDropHoverTest, VerifyObserversAreNotified) { | |
| 71 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1)); | |
| 72 | |
| 73 EXPECT_EQ(1, observer_.last_animation_started_ordinal()); | |
| 74 EXPECT_FALSE(observer_.AnimationHasEnded()); | |
| 75 | |
| 76 test_api_.CompleteAnimations(); | |
| 77 | |
| 78 EXPECT_TRUE(observer_.AnimationHasEnded()); | |
| 79 EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); | |
| 80 } | |
| 81 | |
| 82 TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedWithCorrectAnimationType) { | |
| 83 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1)); | |
| 84 | |
| 85 EXPECT_TRUE(observer_.AnimationHasStarted()); | |
| 86 EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_started_context()); | |
| 87 | |
| 88 test_api_.CompleteAnimations(); | |
| 89 EXPECT_TRUE(observer_.AnimationHasEnded()); | |
| 90 EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_started_context()); | |
| 91 | |
| 92 ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1), | |
| 93 false /* explode */); | |
| 94 EXPECT_EQ(InkDropHover::FADE_OUT, observer_.last_animation_started_context()); | |
| 95 | |
| 96 test_api_.CompleteAnimations(); | |
| 97 EXPECT_EQ(InkDropHover::FADE_OUT, observer_.last_animation_started_context()); | |
| 98 } | |
| 99 | |
| 100 TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) { | |
| 101 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1)); | |
| 102 test_api_.CompleteAnimations(); | |
| 103 | |
| 104 EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); | |
| 105 EXPECT_EQ(InkDropAnimationEndedReason::SUCCESS, | |
| 106 observer_.last_animation_ended_reason()); | |
| 107 } | |
| 108 | |
| 109 TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfPreemptedAnimations) { | |
| 110 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1)); | |
| 111 ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1), | |
| 112 false /* explode */); | |
| 113 | |
| 114 EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); | |
| 115 EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_ended_context()); | |
| 116 EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED, | |
| 117 observer_.last_animation_ended_reason()); | |
| 118 } | |
| 119 | |
| 120 // Confirms there is no crash. | |
| 121 TEST_F(InkDropHoverTest, NullObserverIsSafe) { | |
| 122 ink_drop_hover_->set_observer(nullptr); | |
| 123 | |
| 124 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1)); | |
| 125 test_api_.CompleteAnimations(); | |
| 126 | |
| 127 ink_drop_hover_->FadeOut(base::TimeDelta::FromMilliseconds(0), | |
| 128 false /* explode */); | |
| 129 test_api_.CompleteAnimations(); | |
| 130 EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible()); | |
| 131 } | |
| 132 | |
| 133 // Verify animations are aborted during deletion and the InkDropHoverObservers | |
| 134 // are notified. | |
| 135 TEST_F(InkDropHoverTest, AnimationsAbortedDuringDeletion) { | |
| 136 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1)); | |
| 137 ink_drop_hover_.reset(); | |
| 138 EXPECT_EQ(1, observer_.last_animation_started_ordinal()); | |
| 139 EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); | |
| 140 EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_ended_context()); | |
| 141 EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED, | |
| 142 observer_.last_animation_ended_reason()); | |
| 143 } | |
| 144 | |
| 145 } // namespace test | |
| 146 } // namespace views | |
| OLD | NEW |