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