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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/animation/ink_drop_highlight.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/animation/ink_drop_highlight_unittest.cc
diff --git a/ui/views/animation/ink_drop_highlight_unittest.cc b/ui/views/animation/ink_drop_highlight_unittest.cc
index 500476de716d399f57571d9d5836f426b28264dd..fa5cc88058660d7bbdd3d0568ac5ccb41001bb4c 100644
--- a/ui/views/animation/ink_drop_highlight_unittest.cc
+++ b/ui/views/animation/ink_drop_highlight_unittest.cc
@@ -24,131 +24,161 @@ class InkDropHighlightTest : public testing::Test {
~InkDropHighlightTest() override;
protected:
+ InkDropHighlight* ink_drop_highlight() { return ink_drop_highlight_.get(); }
+
+ InkDropHighlightTestApi* test_api() { return test_api_.get(); }
+
+ // Observer of the test target.
+ TestInkDropHighlightObserver* observer() { return &observer_; }
+
+ // Initializes |ink_drop_highlight_| and attaches |test_api_| and |observer_|
+ // to the new instance.
+ void InitHighlight(std::unique_ptr<InkDropHighlight> new_highlight);
+
+ // Destroys the |ink_drop_highlight_| and the attached |test_api_|.
+ void DestroyHighlight();
+
+ private:
// The test target.
std::unique_ptr<InkDropHighlight> ink_drop_highlight_;
// Allows privileged access to the the |ink_drop_highlight_|.
- InkDropHighlightTestApi test_api_;
+ std::unique_ptr<InkDropHighlightTestApi> test_api_;
// Observer of the test target.
TestInkDropHighlightObserver observer_;
- private:
DISALLOW_COPY_AND_ASSIGN(InkDropHighlightTest);
};
-InkDropHighlightTest::InkDropHighlightTest()
- : ink_drop_highlight_(new InkDropHighlight(gfx::Size(10, 10),
- 3,
- gfx::PointF(),
- SK_ColorBLACK)),
- test_api_(ink_drop_highlight_.get()) {
- ink_drop_highlight_->set_observer(&observer_);
-
- test_api_.SetDisableAnimationTimers(true);
+InkDropHighlightTest::InkDropHighlightTest() {
+ InitHighlight(base::MakeUnique<InkDropHighlight>(
+ gfx::Size(10, 10), 3, gfx::PointF(), SK_ColorBLACK));
}
InkDropHighlightTest::~InkDropHighlightTest() {}
+void InkDropHighlightTest::InitHighlight(
+ std::unique_ptr<InkDropHighlight> new_highlight) {
+ ink_drop_highlight_ = std::move(new_highlight);
+ test_api_ =
+ base::MakeUnique<InkDropHighlightTestApi>(ink_drop_highlight_.get());
+ test_api()->SetDisableAnimationTimers(true);
+ ink_drop_highlight()->set_observer(&observer_);
+}
+
+void InkDropHighlightTest::DestroyHighlight() {
+ test_api_.reset();
+ ink_drop_highlight_.reset();
+}
+
TEST_F(InkDropHighlightTest, InitialStateAfterConstruction) {
- EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible());
+ EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
}
TEST_F(InkDropHighlightTest, IsHighlightedStateTransitions) {
- ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
- EXPECT_TRUE(ink_drop_highlight_->IsFadingInOrVisible());
+ ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
+ EXPECT_TRUE(ink_drop_highlight()->IsFadingInOrVisible());
- test_api_.CompleteAnimations();
- EXPECT_TRUE(ink_drop_highlight_->IsFadingInOrVisible());
+ test_api()->CompleteAnimations();
+ EXPECT_TRUE(ink_drop_highlight()->IsFadingInOrVisible());
- ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1),
- false /* explode */);
- EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible());
+ ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
+ false /* explode */);
+ EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
- test_api_.CompleteAnimations();
- EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible());
+ test_api()->CompleteAnimations();
+ EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
}
TEST_F(InkDropHighlightTest, VerifyObserversAreNotified) {
- ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
+ ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
- EXPECT_EQ(1, observer_.last_animation_started_ordinal());
- EXPECT_FALSE(observer_.AnimationHasEnded());
+ EXPECT_EQ(1, observer()->last_animation_started_ordinal());
+ EXPECT_FALSE(observer()->AnimationHasEnded());
- test_api_.CompleteAnimations();
+ test_api()->CompleteAnimations();
- EXPECT_TRUE(observer_.AnimationHasEnded());
- EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
+ EXPECT_TRUE(observer()->AnimationHasEnded());
+ EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
}
TEST_F(InkDropHighlightTest,
VerifyObserversAreNotifiedWithCorrectAnimationType) {
- ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
+ ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
- EXPECT_TRUE(observer_.AnimationHasStarted());
+ EXPECT_TRUE(observer()->AnimationHasStarted());
EXPECT_EQ(InkDropHighlight::FADE_IN,
- observer_.last_animation_started_context());
+ observer()->last_animation_started_context());
- test_api_.CompleteAnimations();
- EXPECT_TRUE(observer_.AnimationHasEnded());
+ test_api()->CompleteAnimations();
+ EXPECT_TRUE(observer()->AnimationHasEnded());
EXPECT_EQ(InkDropHighlight::FADE_IN,
- observer_.last_animation_started_context());
+ observer()->last_animation_started_context());
- ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1),
- false /* explode */);
+ ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
+ false /* explode */);
EXPECT_EQ(InkDropHighlight::FADE_OUT,
- observer_.last_animation_started_context());
+ observer()->last_animation_started_context());
- test_api_.CompleteAnimations();
+ test_api()->CompleteAnimations();
EXPECT_EQ(InkDropHighlight::FADE_OUT,
- observer_.last_animation_started_context());
+ observer()->last_animation_started_context());
}
TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) {
- ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
- test_api_.CompleteAnimations();
+ ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
+ test_api()->CompleteAnimations();
- EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
+ EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
EXPECT_EQ(InkDropAnimationEndedReason::SUCCESS,
- observer_.last_animation_ended_reason());
+ observer()->last_animation_ended_reason());
}
TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfPreemptedAnimations) {
- ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
- ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1),
- false /* explode */);
+ ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
+ ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
+ false /* explode */);
- EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
+ EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
EXPECT_EQ(InkDropHighlight::FADE_IN,
- observer_.last_animation_ended_context());
+ observer()->last_animation_ended_context());
EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
- observer_.last_animation_ended_reason());
+ observer()->last_animation_ended_reason());
}
// Confirms there is no crash.
TEST_F(InkDropHighlightTest, NullObserverIsSafe) {
- ink_drop_highlight_->set_observer(nullptr);
+ ink_drop_highlight()->set_observer(nullptr);
- ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
- test_api_.CompleteAnimations();
+ ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
+ test_api()->CompleteAnimations();
- ink_drop_highlight_->FadeOut(base::TimeDelta::FromMilliseconds(0),
- false /* explode */);
- test_api_.CompleteAnimations();
- EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible());
+ ink_drop_highlight()->FadeOut(base::TimeDelta::FromMilliseconds(0),
+ false /* explode */);
+ test_api()->CompleteAnimations();
+ EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
}
// Verify animations are aborted during deletion and the
// InkDropHighlightObservers are notified.
TEST_F(InkDropHighlightTest, AnimationsAbortedDuringDeletion) {
- ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
- ink_drop_highlight_.reset();
- EXPECT_EQ(1, observer_.last_animation_started_ordinal());
- EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
+ ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
+ DestroyHighlight();
+ EXPECT_EQ(1, observer()->last_animation_started_ordinal());
+ EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
EXPECT_EQ(InkDropHighlight::FADE_IN,
- observer_.last_animation_ended_context());
+ observer()->last_animation_ended_context());
EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
- observer_.last_animation_ended_reason());
+ observer()->last_animation_ended_reason());
+}
+
+// Confirms a zero sized highlight doesn't crash.
+TEST_F(InkDropHighlightTest, AnimatingAZeroSizeHighlight) {
+ InitHighlight(base::MakeUnique<InkDropHighlight>(
+ gfx::Size(0, 0), 3, gfx::PointF(), SK_ColorBLACK));
+ ink_drop_highlight()->FadeOut(base::TimeDelta::FromMilliseconds(0),
+ false /* explode */);
}
} // namespace test
« 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