Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(705)

Side by Side Diff: ui/views/animation/ink_drop_hover_unittest.cc

Issue 1951593002: Add MD Ink Drop to host only when a ripple/hover is active. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Replaced unique_ptr with scoped_ptr. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/views/animation/ink_drop_hover.h" 5 #include "ui/views/animation/ink_drop_hover.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 11 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
11 #include "ui/gfx/geometry/size.h" 12 #include "ui/gfx/geometry/size.h"
13 #include "ui/views/animation/test/ink_drop_hover_test_api.h"
14 #include "ui/views/animation/test/test_ink_drop_hover_observer.h"
12 15
13 namespace views { 16 namespace views {
14 namespace test { 17 namespace test {
15 18
16 class InkDropHoverTest : public testing::Test { 19 class InkDropHoverTest : public testing::Test {
17 public: 20 public:
18 InkDropHoverTest(); 21 InkDropHoverTest();
19 ~InkDropHoverTest() override; 22 ~InkDropHoverTest() override;
20 23
21 protected: 24 protected:
22 scoped_ptr<InkDropHover> CreateInkDropHover() const; 25 // The test target.
26 scoped_ptr<InkDropHover> ink_drop_hover_;
27
28 // Allows privileged access to the the |ink_drop_hover_|.
29 InkDropHoverTestApi test_api_;
30
31 // Observer of the test target.
32 TestInkDropHoverObserver observer_;
23 33
24 private: 34 private:
25 // Enables zero duration animations during the tests.
26 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
27
28 DISALLOW_COPY_AND_ASSIGN(InkDropHoverTest); 35 DISALLOW_COPY_AND_ASSIGN(InkDropHoverTest);
29 }; 36 };
30 37
31 InkDropHoverTest::InkDropHoverTest() { 38 InkDropHoverTest::InkDropHoverTest()
32 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 39 : ink_drop_hover_(
33 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 40 new InkDropHover(gfx::Size(10, 10), 3, gfx::Point(), SK_ColorBLACK)),
41 test_api_(ink_drop_hover_.get()) {
42 ink_drop_hover_->set_observer(&observer_);
43
44 test_api_.SetDisableAnimationTimers(true);
34 } 45 }
35 46
36 InkDropHoverTest::~InkDropHoverTest() {} 47 InkDropHoverTest::~InkDropHoverTest() {}
37 48
38 scoped_ptr<InkDropHover> InkDropHoverTest::CreateInkDropHover() const {
39 return make_scoped_ptr(
40 new InkDropHover(gfx::Size(10, 10), 3, gfx::Point(), SK_ColorBLACK));
41 }
42
43 TEST_F(InkDropHoverTest, InitialStateAfterConstruction) { 49 TEST_F(InkDropHoverTest, InitialStateAfterConstruction) {
44 scoped_ptr<InkDropHover> ink_drop_hover = CreateInkDropHover(); 50 EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
45 EXPECT_FALSE(ink_drop_hover->IsFadingInOrVisible());
46 } 51 }
47 52
48 TEST_F(InkDropHoverTest, IsHoveredStateTransitions) { 53 TEST_F(InkDropHoverTest, IsHoveredStateTransitions) {
49 scoped_ptr<InkDropHover> ink_drop_hover = CreateInkDropHover(); 54 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
55 EXPECT_TRUE(ink_drop_hover_->IsFadingInOrVisible());
50 56
51 ink_drop_hover->FadeIn(base::TimeDelta::FromMilliseconds(0)); 57 test_api_.CompleteAnimations();
52 EXPECT_TRUE(ink_drop_hover->IsFadingInOrVisible()); 58 EXPECT_TRUE(ink_drop_hover_->IsFadingInOrVisible());
53 59
54 ink_drop_hover->FadeOut(base::TimeDelta::FromMilliseconds(0), 60 ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
55 false /* explode */); 61 false /* explode */);
56 EXPECT_FALSE(ink_drop_hover->IsFadingInOrVisible()); 62 EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
63
64 test_api_.CompleteAnimations();
65 EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
66 }
67
68 TEST_F(InkDropHoverTest, VerifyObserversAreNotified) {
69 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
70
71 EXPECT_EQ(1, observer_.last_animation_started_ordinal());
72 EXPECT_FALSE(observer_.AnimationHasEnded());
73
74 test_api_.CompleteAnimations();
75
76 EXPECT_TRUE(observer_.AnimationHasEnded());
77 EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
78 }
79
80 TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedWithCorrectAnimationType) {
81 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
82
83 EXPECT_TRUE(observer_.AnimationHasStarted());
84 EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_started_context());
85
86 test_api_.CompleteAnimations();
87 EXPECT_TRUE(observer_.AnimationHasEnded());
88 EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_started_context());
89
90 ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
91 false /* explode */);
92 EXPECT_EQ(InkDropHover::FADE_OUT, observer_.last_animation_started_context());
93
94 test_api_.CompleteAnimations();
95 EXPECT_EQ(InkDropHover::FADE_OUT, observer_.last_animation_started_context());
96 }
97
98 TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) {
99 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
100 test_api_.CompleteAnimations();
101
102 EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
103 EXPECT_EQ(InkDropAnimationEndedReason::SUCCESS,
104 observer_.last_animation_ended_reason());
105 }
106
107 TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfPreemptedAnimations) {
108 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
109 ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
110 false /* explode */);
111
112 EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
113 EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_ended_context());
114 EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
115 observer_.last_animation_ended_reason());
116 }
117
118 // Confirms there is no crash.
119 TEST_F(InkDropHoverTest, NullObserverIsSafe) {
120 ink_drop_hover_->set_observer(nullptr);
121
122 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
123 test_api_.CompleteAnimations();
124
125 ink_drop_hover_->FadeOut(base::TimeDelta::FromMilliseconds(0),
126 false /* explode */);
127 test_api_.CompleteAnimations();
128 EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
129 }
130
131 // Verify animations are aborted during deletion and the InkDropHoverObservers
132 // are notified.
133 TEST_F(InkDropHoverTest, AnimationsAbortedDuringDeletion) {
134 ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
135 ink_drop_hover_.reset();
136 EXPECT_EQ(1, observer_.last_animation_started_ordinal());
137 EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
138 EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_ended_context());
139 EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
140 observer_.last_animation_ended_reason());
57 } 141 }
58 142
59 } // namespace test 143 } // namespace test
60 } // namespace views 144 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_hover_observer.h ('k') | ui/views/animation/test/ink_drop_animation_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698