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

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

Issue 2457393006: [ash-md] Added ink drop to system menu rows that inherit from ActionableView. (Closed)
Patch Set: Fixed the failing test: 'SpokenFeedbackTest.NavigateSystemTray' Created 4 years, 1 month 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
« no previous file with comments | « ui/views/animation/ink_drop_highlight.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_highlight.h" 5 #include "ui/views/animation/ink_drop_highlight.h"
6 6
7 #include <memory> 7 #include <memory>
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/time/time.h" 11 #include "base/time/time.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 13 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
14 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
15 #include "ui/views/animation/test/ink_drop_highlight_test_api.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" 16 #include "ui/views/animation/test/test_ink_drop_highlight_observer.h"
17 17
18 namespace views { 18 namespace views {
19 namespace test { 19 namespace test {
20 20
21 class InkDropHighlightTest : public testing::Test { 21 class InkDropHighlightTest : public testing::Test {
22 public: 22 public:
23 InkDropHighlightTest(); 23 InkDropHighlightTest();
24 ~InkDropHighlightTest() override; 24 ~InkDropHighlightTest() override;
25 25
26 protected: 26 protected:
27 InkDropHighlight* ink_drop_highlight() { return ink_drop_highlight_.get(); }
28
29 InkDropHighlightTestApi* test_api() { return test_api_.get(); }
30
31 // Observer of the test target.
32 TestInkDropHighlightObserver* observer() { return &observer_; }
33
34 // Initializes |ink_drop_highlight_| and attaches |test_api_| and |observer_|
35 // to the new instance.
36 void InitHighlight(std::unique_ptr<InkDropHighlight> new_highlight);
37
38 // Destroys the |ink_drop_highlight_| and the attached |test_api_|.
39 void DestroyHighlight();
40
41 private:
27 // The test target. 42 // The test target.
28 std::unique_ptr<InkDropHighlight> ink_drop_highlight_; 43 std::unique_ptr<InkDropHighlight> ink_drop_highlight_;
29 44
30 // Allows privileged access to the the |ink_drop_highlight_|. 45 // Allows privileged access to the the |ink_drop_highlight_|.
31 InkDropHighlightTestApi test_api_; 46 std::unique_ptr<InkDropHighlightTestApi> test_api_;
32 47
33 // Observer of the test target. 48 // Observer of the test target.
34 TestInkDropHighlightObserver observer_; 49 TestInkDropHighlightObserver observer_;
35 50
36 private:
37 DISALLOW_COPY_AND_ASSIGN(InkDropHighlightTest); 51 DISALLOW_COPY_AND_ASSIGN(InkDropHighlightTest);
38 }; 52 };
39 53
40 InkDropHighlightTest::InkDropHighlightTest() 54 InkDropHighlightTest::InkDropHighlightTest() {
41 : ink_drop_highlight_(new InkDropHighlight(gfx::Size(10, 10), 55 InitHighlight(base::MakeUnique<InkDropHighlight>(
42 3, 56 gfx::Size(10, 10), 3, gfx::PointF(), SK_ColorBLACK));
43 gfx::PointF(),
44 SK_ColorBLACK)),
45 test_api_(ink_drop_highlight_.get()) {
46 ink_drop_highlight_->set_observer(&observer_);
47
48 test_api_.SetDisableAnimationTimers(true);
49 } 57 }
50 58
51 InkDropHighlightTest::~InkDropHighlightTest() {} 59 InkDropHighlightTest::~InkDropHighlightTest() {}
52 60
61 void InkDropHighlightTest::InitHighlight(
62 std::unique_ptr<InkDropHighlight> new_highlight) {
63 ink_drop_highlight_ = std::move(new_highlight);
64 test_api_ =
65 base::MakeUnique<InkDropHighlightTestApi>(ink_drop_highlight_.get());
66 test_api()->SetDisableAnimationTimers(true);
67 ink_drop_highlight()->set_observer(&observer_);
68 }
69
70 void InkDropHighlightTest::DestroyHighlight() {
71 test_api_.reset();
72 ink_drop_highlight_.reset();
73 }
74
53 TEST_F(InkDropHighlightTest, InitialStateAfterConstruction) { 75 TEST_F(InkDropHighlightTest, InitialStateAfterConstruction) {
54 EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible()); 76 EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
55 } 77 }
56 78
57 TEST_F(InkDropHighlightTest, IsHighlightedStateTransitions) { 79 TEST_F(InkDropHighlightTest, IsHighlightedStateTransitions) {
58 ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1)); 80 ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
59 EXPECT_TRUE(ink_drop_highlight_->IsFadingInOrVisible()); 81 EXPECT_TRUE(ink_drop_highlight()->IsFadingInOrVisible());
60 82
61 test_api_.CompleteAnimations(); 83 test_api()->CompleteAnimations();
62 EXPECT_TRUE(ink_drop_highlight_->IsFadingInOrVisible()); 84 EXPECT_TRUE(ink_drop_highlight()->IsFadingInOrVisible());
63 85
64 ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1), 86 ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
65 false /* explode */); 87 false /* explode */);
66 EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible()); 88 EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
67 89
68 test_api_.CompleteAnimations(); 90 test_api()->CompleteAnimations();
69 EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible()); 91 EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
70 } 92 }
71 93
72 TEST_F(InkDropHighlightTest, VerifyObserversAreNotified) { 94 TEST_F(InkDropHighlightTest, VerifyObserversAreNotified) {
73 ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1)); 95 ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
74 96
75 EXPECT_EQ(1, observer_.last_animation_started_ordinal()); 97 EXPECT_EQ(1, observer()->last_animation_started_ordinal());
76 EXPECT_FALSE(observer_.AnimationHasEnded()); 98 EXPECT_FALSE(observer()->AnimationHasEnded());
77 99
78 test_api_.CompleteAnimations(); 100 test_api()->CompleteAnimations();
79 101
80 EXPECT_TRUE(observer_.AnimationHasEnded()); 102 EXPECT_TRUE(observer()->AnimationHasEnded());
81 EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); 103 EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
82 } 104 }
83 105
84 TEST_F(InkDropHighlightTest, 106 TEST_F(InkDropHighlightTest,
85 VerifyObserversAreNotifiedWithCorrectAnimationType) { 107 VerifyObserversAreNotifiedWithCorrectAnimationType) {
86 ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1)); 108 ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
87 109
88 EXPECT_TRUE(observer_.AnimationHasStarted()); 110 EXPECT_TRUE(observer()->AnimationHasStarted());
89 EXPECT_EQ(InkDropHighlight::FADE_IN, 111 EXPECT_EQ(InkDropHighlight::FADE_IN,
90 observer_.last_animation_started_context()); 112 observer()->last_animation_started_context());
91 113
92 test_api_.CompleteAnimations(); 114 test_api()->CompleteAnimations();
93 EXPECT_TRUE(observer_.AnimationHasEnded()); 115 EXPECT_TRUE(observer()->AnimationHasEnded());
94 EXPECT_EQ(InkDropHighlight::FADE_IN, 116 EXPECT_EQ(InkDropHighlight::FADE_IN,
95 observer_.last_animation_started_context()); 117 observer()->last_animation_started_context());
96 118
97 ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1), 119 ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
98 false /* explode */); 120 false /* explode */);
99 EXPECT_EQ(InkDropHighlight::FADE_OUT, 121 EXPECT_EQ(InkDropHighlight::FADE_OUT,
100 observer_.last_animation_started_context()); 122 observer()->last_animation_started_context());
101 123
102 test_api_.CompleteAnimations(); 124 test_api()->CompleteAnimations();
103 EXPECT_EQ(InkDropHighlight::FADE_OUT, 125 EXPECT_EQ(InkDropHighlight::FADE_OUT,
104 observer_.last_animation_started_context()); 126 observer()->last_animation_started_context());
105 } 127 }
106 128
107 TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) { 129 TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) {
108 ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1)); 130 ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
109 test_api_.CompleteAnimations(); 131 test_api()->CompleteAnimations();
110 132
111 EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); 133 EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
112 EXPECT_EQ(InkDropAnimationEndedReason::SUCCESS, 134 EXPECT_EQ(InkDropAnimationEndedReason::SUCCESS,
113 observer_.last_animation_ended_reason()); 135 observer()->last_animation_ended_reason());
114 } 136 }
115 137
116 TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfPreemptedAnimations) { 138 TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfPreemptedAnimations) {
117 ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1)); 139 ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
118 ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1), 140 ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
119 false /* explode */); 141 false /* explode */);
120 142
121 EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); 143 EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
122 EXPECT_EQ(InkDropHighlight::FADE_IN, 144 EXPECT_EQ(InkDropHighlight::FADE_IN,
123 observer_.last_animation_ended_context()); 145 observer()->last_animation_ended_context());
124 EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED, 146 EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
125 observer_.last_animation_ended_reason()); 147 observer()->last_animation_ended_reason());
126 } 148 }
127 149
128 // Confirms there is no crash. 150 // Confirms there is no crash.
129 TEST_F(InkDropHighlightTest, NullObserverIsSafe) { 151 TEST_F(InkDropHighlightTest, NullObserverIsSafe) {
130 ink_drop_highlight_->set_observer(nullptr); 152 ink_drop_highlight()->set_observer(nullptr);
131 153
132 ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1)); 154 ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
133 test_api_.CompleteAnimations(); 155 test_api()->CompleteAnimations();
134 156
135 ink_drop_highlight_->FadeOut(base::TimeDelta::FromMilliseconds(0), 157 ink_drop_highlight()->FadeOut(base::TimeDelta::FromMilliseconds(0),
136 false /* explode */); 158 false /* explode */);
137 test_api_.CompleteAnimations(); 159 test_api()->CompleteAnimations();
138 EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible()); 160 EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
139 } 161 }
140 162
141 // Verify animations are aborted during deletion and the 163 // Verify animations are aborted during deletion and the
142 // InkDropHighlightObservers are notified. 164 // InkDropHighlightObservers are notified.
143 TEST_F(InkDropHighlightTest, AnimationsAbortedDuringDeletion) { 165 TEST_F(InkDropHighlightTest, AnimationsAbortedDuringDeletion) {
144 ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1)); 166 ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
145 ink_drop_highlight_.reset(); 167 DestroyHighlight();
146 EXPECT_EQ(1, observer_.last_animation_started_ordinal()); 168 EXPECT_EQ(1, observer()->last_animation_started_ordinal());
147 EXPECT_EQ(2, observer_.last_animation_ended_ordinal()); 169 EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
148 EXPECT_EQ(InkDropHighlight::FADE_IN, 170 EXPECT_EQ(InkDropHighlight::FADE_IN,
149 observer_.last_animation_ended_context()); 171 observer()->last_animation_ended_context());
150 EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED, 172 EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
151 observer_.last_animation_ended_reason()); 173 observer()->last_animation_ended_reason());
174 }
175
176 // Confirms a zero sized highlight doesn't crash.
177 TEST_F(InkDropHighlightTest, AnimatingAZeroSizeHighlight) {
178 InitHighlight(base::MakeUnique<InkDropHighlight>(
179 gfx::Size(0, 0), 3, gfx::PointF(), SK_ColorBLACK));
180 ink_drop_highlight()->FadeOut(base::TimeDelta::FromMilliseconds(0),
181 false /* explode */);
152 } 182 }
153 183
154 } // namespace test 184 } // namespace test
155 } // namespace views 185 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_highlight.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698