| 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 #ifndef UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ | 4 #ifndef UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ |
| 5 #define UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ | 5 #define UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 ContextType last_animation_ended_context() const { | 42 ContextType last_animation_ended_context() const { |
| 43 return last_animation_ended_context_; | 43 return last_animation_ended_context_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 InkDropAnimationEndedReason last_animation_ended_reason() const { | 46 InkDropAnimationEndedReason last_animation_ended_reason() const { |
| 47 return last_animation_ended_reason_; | 47 return last_animation_ended_reason_; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void OnAnimationStarted(ContextType context) { | 50 void OnAnimationStarted(ContextType context) { |
| 51 animation_started_contexts_.push_back(context); |
| 51 last_animation_started_context_ = context; | 52 last_animation_started_context_ = context; |
| 52 last_animation_started_ordinal_ = GetNextOrdinal(); | 53 last_animation_started_ordinal_ = GetNextOrdinal(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void OnAnimationEnded(ContextType context, | 56 void OnAnimationEnded(ContextType context, |
| 56 InkDropAnimationEndedReason reason) { | 57 InkDropAnimationEndedReason reason) { |
| 58 animation_ended_contexts_.push_back(context); |
| 57 last_animation_ended_context_ = context; | 59 last_animation_ended_context_ = context; |
| 58 last_animation_ended_ordinal_ = GetNextOrdinal(); | 60 last_animation_ended_ordinal_ = GetNextOrdinal(); |
| 59 last_animation_ended_reason_ = reason; | 61 last_animation_ended_reason_ = reason; |
| 60 } | 62 } |
| 61 | 63 |
| 62 // | 64 // |
| 63 // Collection of assertion predicates to be used with GTest test assertions. | 65 // Collection of assertion predicates to be used with GTest test assertions. |
| 64 // i.e. EXPECT_TRUE/EXPECT_FALSE and the ASSERT_ counterparts. | 66 // i.e. EXPECT_TRUE/EXPECT_FALSE and the ASSERT_ counterparts. |
| 65 // | 67 // |
| 66 // Example: | 68 // Example: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 105 |
| 104 // Passes *_TRUE assertions when an AnimationEnded() event has NOT been | 106 // Passes *_TRUE assertions when an AnimationEnded() event has NOT been |
| 105 // observed. | 107 // observed. |
| 106 testing::AssertionResult AnimationHasNotEnded() { | 108 testing::AssertionResult AnimationHasNotEnded() { |
| 107 if (last_animation_ended_ordinal() < 0) | 109 if (last_animation_ended_ordinal() < 0) |
| 108 return testing::AssertionSuccess(); | 110 return testing::AssertionSuccess(); |
| 109 return testing::AssertionFailure() << "Animations were ended at ordinal=" | 111 return testing::AssertionFailure() << "Animations were ended at ordinal=" |
| 110 << last_animation_ended_ordinal() << "."; | 112 << last_animation_ended_ordinal() << "."; |
| 111 } | 113 } |
| 112 | 114 |
| 115 // Passes *_TRUE assertions when |animation_started_context_| is the same as |
| 116 // |expected_contexts|. |
| 117 testing::AssertionResult AnimationStartedContextsMatch( |
| 118 const std::vector<ContextType>& expected_contexts) { |
| 119 return ContextsMatch(expected_contexts, animation_started_contexts_); |
| 120 } |
| 121 |
| 122 // Passes *_TRUE assertions when |animation_ended_context_| is the same as |
| 123 // |expected_contexts|. |
| 124 testing::AssertionResult AnimationEndedContextsMatch( |
| 125 const std::vector<ContextType>& expected_contexts) { |
| 126 return ContextsMatch(expected_contexts, animation_ended_contexts_); |
| 127 } |
| 128 |
| 113 private: | 129 private: |
| 130 // Helper function that checks if |actual_contexts| is the same as |
| 131 // |expected_contexts| returning appropriate AssertionResult. |
| 132 testing::AssertionResult ContextsMatch( |
| 133 const std::vector<ContextType>& expected_contexts, |
| 134 const std::vector<ContextType>& actual_contexts) { |
| 135 const bool match = |
| 136 expected_contexts.size() == actual_contexts.size() && |
| 137 std::equal(expected_contexts.begin(), expected_contexts.end(), |
| 138 actual_contexts.begin()); |
| 139 testing::AssertionResult result = |
| 140 match ? (testing::AssertionSuccess() << "Expected == Actual: {") |
| 141 : (testing::AssertionFailure() << "Expected != Actual: {"); |
| 142 for (auto eit = expected_contexts.begin(), ait = actual_contexts.begin(); |
| 143 eit != expected_contexts.end() || ait != actual_contexts.end();) { |
| 144 if (eit != expected_contexts.begin()) |
| 145 result << ", "; |
| 146 const bool eexists = eit != expected_contexts.end(); |
| 147 const bool aexists = ait != actual_contexts.end(); |
| 148 const bool item_match = eexists && aexists && *eit == *ait; |
| 149 result << (eexists ? ToString(*eit) : "<none>") |
| 150 << (item_match ? " == " : " != ") |
| 151 << (aexists ? ToString(*ait) : "<none>"); |
| 152 if (eexists) |
| 153 eit++; |
| 154 if (aexists) |
| 155 ait++; |
| 156 } |
| 157 result << "}"; |
| 158 return result; |
| 159 } |
| 160 |
| 114 // Returns the next event ordinal. The first returned ordinal will be 1. | 161 // Returns the next event ordinal. The first returned ordinal will be 1. |
| 115 int GetNextOrdinal() const { | 162 int GetNextOrdinal() const { |
| 116 return std::max(1, std::max(last_animation_started_ordinal_, | 163 return std::max(1, std::max(last_animation_started_ordinal_, |
| 117 last_animation_ended_ordinal_) + | 164 last_animation_ended_ordinal_) + |
| 118 1); | 165 1); |
| 119 } | 166 } |
| 120 | 167 |
| 121 // The ordinal time of the last AnimationStarted() call. | 168 // The ordinal time of the last AnimationStarted() call. |
| 122 int last_animation_started_ordinal_; | 169 int last_animation_started_ordinal_; |
| 123 | 170 |
| 171 // List of contexts for which animation is started. |
| 172 std::vector<ContextType> animation_started_contexts_; |
| 173 |
| 124 // The |context| passed to the last call to AnimationStarted(). | 174 // The |context| passed to the last call to AnimationStarted(). |
| 125 ContextType last_animation_started_context_; | 175 ContextType last_animation_started_context_; |
| 126 | 176 |
| 127 // The ordinal time of the last AnimationEnded() call. | 177 // The ordinal time of the last AnimationEnded() call. |
| 128 int last_animation_ended_ordinal_; | 178 int last_animation_ended_ordinal_; |
| 129 | 179 |
| 180 // List of contexts for which animation is ended. |
| 181 std::vector<ContextType> animation_ended_contexts_; |
| 182 |
| 130 // The |context| passed to the last call to AnimationEnded(). | 183 // The |context| passed to the last call to AnimationEnded(). |
| 131 ContextType last_animation_ended_context_; | 184 ContextType last_animation_ended_context_; |
| 132 | 185 |
| 133 InkDropAnimationEndedReason last_animation_ended_reason_; | 186 InkDropAnimationEndedReason last_animation_ended_reason_; |
| 134 | 187 |
| 135 DISALLOW_COPY_AND_ASSIGN(TestInkDropAnimationObserverHelper); | 188 DISALLOW_COPY_AND_ASSIGN(TestInkDropAnimationObserverHelper); |
| 136 }; | 189 }; |
| 137 | 190 |
| 138 } // namespace test | 191 } // namespace test |
| 139 } // namespace views | 192 } // namespace views |
| 140 | 193 |
| 141 #endif // UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ | 194 #endif // UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ |
| OLD | NEW |