| 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 #ifndef UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ | 5 #ifndef UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ |
| 6 #define UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ | 6 #define UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/views/animation/ink_drop_animation_observer.h" | 9 #include "ui/views/animation/ink_drop_animation_observer.h" |
| 10 #include "ui/views/animation/ink_drop_state.h" | 10 #include "ui/views/animation/ink_drop_state.h" |
| 11 #include "ui/views/animation/test/test_ink_drop_animation_observer_helper.h" |
| 11 | 12 |
| 12 namespace views { | 13 namespace views { |
| 13 class InkDropAnimation; | 14 class InkDropAnimation; |
| 14 | 15 |
| 15 namespace test { | 16 namespace test { |
| 16 | 17 |
| 17 // Simple InkDropAnimationObserver test double that tracks if | 18 // Simple InkDropAnimationObserver test double that tracks if |
| 18 // InkDropAnimationObserver methods are invoked and the parameters used for the | 19 // InkDropAnimationObserver methods are invoked and the parameters used for the |
| 19 // last invocation. | 20 // last invocation. |
| 20 class TestInkDropAnimationObserver : public InkDropAnimationObserver { | 21 class TestInkDropAnimationObserver |
| 22 : public InkDropAnimationObserver, |
| 23 public TestInkDropAnimationObserverHelper<InkDropState> { |
| 21 public: | 24 public: |
| 22 TestInkDropAnimationObserver(); | 25 TestInkDropAnimationObserver(); |
| 23 ~TestInkDropAnimationObserver() override; | 26 ~TestInkDropAnimationObserver() override; |
| 24 | 27 |
| 25 void set_ink_drop_animation(InkDropAnimation* ink_drop_animation) { | 28 void set_ink_drop_animation(InkDropAnimation* ink_drop_animation) { |
| 26 ink_drop_animation_ = ink_drop_animation; | 29 ink_drop_animation_ = ink_drop_animation; |
| 27 } | 30 } |
| 28 | 31 |
| 29 int last_animation_started_ordinal() const { | |
| 30 return last_animation_started_ordinal_; | |
| 31 } | |
| 32 | |
| 33 int last_animation_ended_ordinal() const { | |
| 34 return last_animation_ended_ordinal_; | |
| 35 } | |
| 36 | |
| 37 InkDropState last_animation_state_started() const { | |
| 38 return last_animation_state_started_; | |
| 39 } | |
| 40 | |
| 41 InkDropState last_animation_state_ended() const { | |
| 42 return last_animation_state_ended_; | |
| 43 } | |
| 44 | |
| 45 InkDropAnimationEndedReason last_animation_ended_reason() const { | |
| 46 return last_animation_ended_reason_; | |
| 47 } | |
| 48 | |
| 49 InkDropState target_state_at_last_animation_started() const { | 32 InkDropState target_state_at_last_animation_started() const { |
| 50 return target_state_at_last_animation_started_; | 33 return target_state_at_last_animation_started_; |
| 51 } | 34 } |
| 52 | 35 |
| 53 InkDropState target_state_at_last_animation_ended() const { | 36 InkDropState target_state_at_last_animation_ended() const { |
| 54 return target_state_at_last_animation_ended_; | 37 return target_state_at_last_animation_ended_; |
| 55 } | 38 } |
| 56 | 39 |
| 57 // | 40 // InkDropAnimationObserver: |
| 58 // Collection of assertion predicates to be used with GTest test assertions. | 41 void AnimationStarted(InkDropState ink_drop_state) override; |
| 59 // i.e. EXPECT_TRUE/EXPECT_FALSE and the ASSERT_ counterparts. | 42 void AnimationEnded(InkDropState ink_drop_state, |
| 60 // | 43 InkDropAnimationEndedReason reason) override; |
| 61 // Example: | |
| 62 // | |
| 63 // TestInkDropAnimationObserver observer; | |
| 64 // observer.set_ink_drop_animation(ink_drop_animation); | |
| 65 // EXPECT_TRUE(observer.AnimationHasNotStarted()); | |
| 66 // | |
| 67 | |
| 68 // Passes *_TRUE assertions when an InkDropAnimationStarted() event has been | |
| 69 // observed. | |
| 70 testing::AssertionResult AnimationHasStarted(); | |
| 71 | |
| 72 // Passes *_TRUE assertions when an InkDropAnimationStarted() event has NOT | |
| 73 // been observed. | |
| 74 testing::AssertionResult AnimationHasNotStarted(); | |
| 75 | |
| 76 // Passes *_TRUE assertions when an InkDropAnimationEnded() event has been | |
| 77 // observed. | |
| 78 testing::AssertionResult AnimationHasEnded(); | |
| 79 | |
| 80 // Passes *_TRUE assertions when an InkDropAnimationEnded() event has NOT been | |
| 81 // observed. | |
| 82 testing::AssertionResult AnimationHasNotEnded(); | |
| 83 | |
| 84 // InkDropAnimation: | |
| 85 void InkDropAnimationStarted(InkDropState ink_drop_state) override; | |
| 86 void InkDropAnimationEnded(InkDropState ink_drop_state, | |
| 87 InkDropAnimationEndedReason reason) override; | |
| 88 | 44 |
| 89 private: | 45 private: |
| 90 // Returns the next event ordinal. The first returned ordinal will be 1. | 46 // The type as this inherits from. Reduces verbosity in .cc file. |
| 91 int GetNextOrdinal() const; | 47 using ObserverHelper = TestInkDropAnimationObserverHelper<InkDropState>; |
| 92 | |
| 93 // The ordinal time of the last InkDropAnimationStarted() event. | |
| 94 int last_animation_started_ordinal_; | |
| 95 | |
| 96 // The ordinal time of the last InkDropAnimationended() event. | |
| 97 int last_animation_ended_ordinal_; | |
| 98 | |
| 99 // The |ink_drop_state| parameter used for the last invocation of | |
| 100 // InkDropAnimationStarted(). Only valid if |animation_started_| is true. | |
| 101 InkDropState last_animation_state_started_; | |
| 102 | |
| 103 // The |ink_drop_state| parameter used for the last invocation of | |
| 104 // InkDropAnimationEnded(). Only valid if |animation_ended_| is true. | |
| 105 InkDropState last_animation_state_ended_; | |
| 106 | |
| 107 // The |reason| parameter used for the last invocation of | |
| 108 // InkDropAnimationEnded(). Only valid if |animation_ended_| is true. | |
| 109 InkDropAnimationEndedReason last_animation_ended_reason_; | |
| 110 | 48 |
| 111 // The value of InkDropAnimation::GetTargetInkDropState() the last time an | 49 // The value of InkDropAnimation::GetTargetInkDropState() the last time an |
| 112 // InkDropAnimationStarted() event was handled. This is only valid if | 50 // InkDropAnimationStarted() event was handled. This is only valid if |
| 113 // |ink_drop_animation_| is not null. | 51 // |ink_drop_animation_| is not null. |
| 114 InkDropState target_state_at_last_animation_started_; | 52 InkDropState target_state_at_last_animation_started_; |
| 115 | 53 |
| 116 // The value of InkDropAnimation::GetTargetInkDropState() the last time an | 54 // The value of InkDropAnimation::GetTargetInkDropState() the last time an |
| 117 // InkDropAnimationEnded() event was handled. This is only valid if | 55 // AnimationEnded() event was handled. This is only valid if |
| 118 // |ink_drop_animation_| is not null. | 56 // |ink_drop_animation_| is not null. |
| 119 InkDropState target_state_at_last_animation_ended_; | 57 InkDropState target_state_at_last_animation_ended_; |
| 120 | 58 |
| 121 // An InkDropAnimation to spy info from when notifications are handled. | 59 // An InkDropAnimation to spy info from when notifications are handled. |
| 122 InkDropAnimation* ink_drop_animation_; | 60 InkDropAnimation* ink_drop_animation_; |
| 123 | 61 |
| 124 DISALLOW_COPY_AND_ASSIGN(TestInkDropAnimationObserver); | 62 DISALLOW_COPY_AND_ASSIGN(TestInkDropAnimationObserver); |
| 125 }; | 63 }; |
| 126 | 64 |
| 127 } // namespace test | 65 } // namespace test |
| 128 } // namespace views | 66 } // namespace views |
| 129 | 67 |
| 130 #endif // UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ | 68 #endif // UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ |
| OLD | NEW |