| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test/test_ink_drop_animation_observer.h" | 5 #include "ui/views/animation/test/test_ink_drop_animation_observer.h" |
| 6 | 6 |
| 7 #include "ui/views/animation/ink_drop_animation.h" | 7 #include "ui/views/animation/ink_drop_animation.h" |
| 8 | 8 |
| 9 namespace views { | 9 namespace views { |
| 10 namespace test { | 10 namespace test { |
| 11 | 11 |
| 12 TestInkDropAnimationObserver::TestInkDropAnimationObserver() | 12 TestInkDropAnimationObserver::TestInkDropAnimationObserver() |
| 13 : last_animation_started_ordinal_(-1), | 13 : target_state_at_last_animation_started_(InkDropState::HIDDEN), |
| 14 last_animation_ended_ordinal_(-1), | |
| 15 last_animation_state_started_(InkDropState::HIDDEN), | |
| 16 last_animation_state_ended_(InkDropState::HIDDEN), | |
| 17 last_animation_ended_reason_(InkDropAnimationEndedReason::SUCCESS), | |
| 18 target_state_at_last_animation_started_(InkDropState::HIDDEN), | |
| 19 target_state_at_last_animation_ended_(InkDropState::HIDDEN) {} | 14 target_state_at_last_animation_ended_(InkDropState::HIDDEN) {} |
| 20 | 15 |
| 21 TestInkDropAnimationObserver::~TestInkDropAnimationObserver() {} | 16 TestInkDropAnimationObserver::~TestInkDropAnimationObserver() {} |
| 22 | 17 |
| 23 testing::AssertionResult TestInkDropAnimationObserver::AnimationHasStarted() { | 18 void TestInkDropAnimationObserver::AnimationStarted( |
| 24 if (last_animation_started_ordinal() > 0) { | |
| 25 return testing::AssertionSuccess() << "Animations were started at ordinal=" | |
| 26 << last_animation_started_ordinal() | |
| 27 << "."; | |
| 28 } | |
| 29 return testing::AssertionFailure() << "Animations have not started."; | |
| 30 } | |
| 31 | |
| 32 testing::AssertionResult | |
| 33 TestInkDropAnimationObserver::AnimationHasNotStarted() { | |
| 34 if (last_animation_started_ordinal() < 0) | |
| 35 return testing::AssertionSuccess(); | |
| 36 return testing::AssertionFailure() << "Animations were started at ordinal=" | |
| 37 << last_animation_started_ordinal() << "."; | |
| 38 } | |
| 39 | |
| 40 testing::AssertionResult TestInkDropAnimationObserver::AnimationHasEnded() { | |
| 41 if (last_animation_ended_ordinal() > 0) { | |
| 42 return testing::AssertionSuccess() << "Animations were ended at ordinal=" | |
| 43 << last_animation_ended_ordinal() << "."; | |
| 44 } | |
| 45 return testing::AssertionFailure() << "Animations have not ended."; | |
| 46 } | |
| 47 | |
| 48 testing::AssertionResult TestInkDropAnimationObserver::AnimationHasNotEnded() { | |
| 49 if (last_animation_ended_ordinal() < 0) | |
| 50 return testing::AssertionSuccess(); | |
| 51 return testing::AssertionFailure() << "Animations were ended at ordinal=" | |
| 52 << last_animation_ended_ordinal() << "."; | |
| 53 } | |
| 54 | |
| 55 void TestInkDropAnimationObserver::InkDropAnimationStarted( | |
| 56 InkDropState ink_drop_state) { | 19 InkDropState ink_drop_state) { |
| 57 last_animation_started_ordinal_ = GetNextOrdinal(); | 20 ObserverHelper::OnAnimationStarted(ink_drop_state); |
| 58 last_animation_state_started_ = ink_drop_state; | |
| 59 if (ink_drop_animation_) { | 21 if (ink_drop_animation_) { |
| 60 target_state_at_last_animation_started_ = | 22 target_state_at_last_animation_started_ = |
| 61 ink_drop_animation_->target_ink_drop_state(); | 23 ink_drop_animation_->target_ink_drop_state(); |
| 62 } | 24 } |
| 63 } | 25 } |
| 64 | 26 |
| 65 void TestInkDropAnimationObserver::InkDropAnimationEnded( | 27 void TestInkDropAnimationObserver::AnimationEnded( |
| 66 InkDropState ink_drop_state, | 28 InkDropState ink_drop_state, |
| 67 InkDropAnimationEndedReason reason) { | 29 InkDropAnimationEndedReason reason) { |
| 68 last_animation_ended_ordinal_ = GetNextOrdinal(); | 30 ObserverHelper::OnAnimationEnded(ink_drop_state, reason); |
| 69 last_animation_state_ended_ = ink_drop_state; | |
| 70 last_animation_ended_reason_ = reason; | |
| 71 if (ink_drop_animation_) { | 31 if (ink_drop_animation_) { |
| 72 target_state_at_last_animation_ended_ = | 32 target_state_at_last_animation_ended_ = |
| 73 ink_drop_animation_->target_ink_drop_state(); | 33 ink_drop_animation_->target_ink_drop_state(); |
| 74 } | 34 } |
| 75 } | 35 } |
| 76 | 36 |
| 77 int TestInkDropAnimationObserver::GetNextOrdinal() const { | |
| 78 return std::max(1, std::max(last_animation_started_ordinal_, | |
| 79 last_animation_ended_ordinal_) + | |
| 80 1); | |
| 81 } | |
| 82 | |
| 83 } // namespace test | 37 } // namespace test |
| 84 } // namespace views | 38 } // namespace views |
| OLD | NEW |