| Index: ui/views/animation/ink_drop_hover_unittest.cc
|
| diff --git a/ui/views/animation/ink_drop_hover_unittest.cc b/ui/views/animation/ink_drop_hover_unittest.cc
|
| index 7eded5631310c622383fa22738bcd53096c94e09..5d02ab7f1ed6d235f6ea1161ab0a8ddf97256373 100644
|
| --- a/ui/views/animation/ink_drop_hover_unittest.cc
|
| +++ b/ui/views/animation/ink_drop_hover_unittest.cc
|
| @@ -6,9 +6,12 @@
|
|
|
| #include "base/macros.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/time/time.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/compositor/scoped_animation_duration_scale_mode.h"
|
| #include "ui/gfx/geometry/size.h"
|
| +#include "ui/views/animation/test/ink_drop_hover_test_api.h"
|
| +#include "ui/views/animation/test/test_ink_drop_hover_observer.h"
|
|
|
| namespace views {
|
| namespace test {
|
| @@ -19,41 +22,122 @@ class InkDropHoverTest : public testing::Test {
|
| ~InkDropHoverTest() override;
|
|
|
| protected:
|
| - scoped_ptr<InkDropHover> CreateInkDropHover() const;
|
| + // The test target.
|
| + scoped_ptr<InkDropHover> ink_drop_hover_;
|
|
|
| - private:
|
| - // Enables zero duration animations during the tests.
|
| - scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
|
| + // Allows privileged access to the the |ink_drop_hover_|.
|
| + InkDropHoverTestApi test_api_;
|
| +
|
| + // Observer of the test target.
|
| + TestInkDropHoverObserver observer_;
|
|
|
| + private:
|
| DISALLOW_COPY_AND_ASSIGN(InkDropHoverTest);
|
| };
|
|
|
| -InkDropHoverTest::InkDropHoverTest() {
|
| - zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
|
| - ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
|
| +InkDropHoverTest::InkDropHoverTest()
|
| + : ink_drop_hover_(
|
| + new InkDropHover(gfx::Size(10, 10), 3, gfx::Point(), SK_ColorBLACK)),
|
| + test_api_(ink_drop_hover_.get()) {
|
| + ink_drop_hover_->set_observer(&observer_);
|
| +
|
| + test_api_.SetDisableAnimationTimers(true);
|
| }
|
|
|
| InkDropHoverTest::~InkDropHoverTest() {}
|
|
|
| -scoped_ptr<InkDropHover> InkDropHoverTest::CreateInkDropHover() const {
|
| - return make_scoped_ptr(
|
| - new InkDropHover(gfx::Size(10, 10), 3, gfx::Point(), SK_ColorBLACK));
|
| -}
|
| -
|
| TEST_F(InkDropHoverTest, InitialStateAfterConstruction) {
|
| - scoped_ptr<InkDropHover> ink_drop_hover = CreateInkDropHover();
|
| - EXPECT_FALSE(ink_drop_hover->IsFadingInOrVisible());
|
| + EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
|
| }
|
|
|
| TEST_F(InkDropHoverTest, IsHoveredStateTransitions) {
|
| - scoped_ptr<InkDropHover> ink_drop_hover = CreateInkDropHover();
|
| + ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
|
| + EXPECT_TRUE(ink_drop_hover_->IsFadingInOrVisible());
|
| +
|
| + test_api_.CompleteAnimations();
|
| + EXPECT_TRUE(ink_drop_hover_->IsFadingInOrVisible());
|
| +
|
| + ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
|
| + false /* explode */);
|
| + EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
|
| +
|
| + test_api_.CompleteAnimations();
|
| + EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
|
| +}
|
| +
|
| +TEST_F(InkDropHoverTest, VerifyObserversAreNotified) {
|
| + ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
|
| +
|
| + EXPECT_EQ(1, observer_.last_animation_started_ordinal());
|
| + EXPECT_FALSE(observer_.AnimationHasEnded());
|
| +
|
| + test_api_.CompleteAnimations();
|
| +
|
| + EXPECT_TRUE(observer_.AnimationHasEnded());
|
| + EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
|
| +}
|
|
|
| - ink_drop_hover->FadeIn(base::TimeDelta::FromMilliseconds(0));
|
| - EXPECT_TRUE(ink_drop_hover->IsFadingInOrVisible());
|
| +TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedWithCorrectAnimationType) {
|
| + ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
|
| +
|
| + EXPECT_TRUE(observer_.AnimationHasStarted());
|
| + EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_started_context());
|
| +
|
| + test_api_.CompleteAnimations();
|
| + EXPECT_TRUE(observer_.AnimationHasEnded());
|
| + EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_started_context());
|
| +
|
| + ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
|
| + false /* explode */);
|
| + EXPECT_EQ(InkDropHover::FADE_OUT, observer_.last_animation_started_context());
|
| +
|
| + test_api_.CompleteAnimations();
|
| + EXPECT_EQ(InkDropHover::FADE_OUT, observer_.last_animation_started_context());
|
| +}
|
| +
|
| +TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) {
|
| + ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
|
| + test_api_.CompleteAnimations();
|
| +
|
| + EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
|
| + EXPECT_EQ(InkDropAnimationEndedReason::SUCCESS,
|
| + observer_.last_animation_ended_reason());
|
| +}
|
| +
|
| +TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfPreemptedAnimations) {
|
| + ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
|
| + ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
|
| + false /* explode */);
|
| +
|
| + EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
|
| + EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_ended_context());
|
| + EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
|
| + observer_.last_animation_ended_reason());
|
| +}
|
| +
|
| +// Confirms there is no crash.
|
| +TEST_F(InkDropHoverTest, NullObserverIsSafe) {
|
| + ink_drop_hover_->set_observer(nullptr);
|
| +
|
| + ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
|
| + test_api_.CompleteAnimations();
|
| +
|
| + ink_drop_hover_->FadeOut(base::TimeDelta::FromMilliseconds(0),
|
| + false /* explode */);
|
| + test_api_.CompleteAnimations();
|
| + EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
|
| +}
|
|
|
| - ink_drop_hover->FadeOut(base::TimeDelta::FromMilliseconds(0),
|
| - false /* explode */);
|
| - EXPECT_FALSE(ink_drop_hover->IsFadingInOrVisible());
|
| +// Verify animations are aborted during deletion and the InkDropHoverObservers
|
| +// are notified.
|
| +TEST_F(InkDropHoverTest, AnimationsAbortedDuringDeletion) {
|
| + ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
|
| + ink_drop_hover_.reset();
|
| + EXPECT_EQ(1, observer_.last_animation_started_ordinal());
|
| + EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
|
| + EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_ended_context());
|
| + EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
|
| + observer_.last_animation_ended_reason());
|
| }
|
|
|
| } // namespace test
|
|
|