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

Side by Side Diff: ui/views/animation/test/test_ink_drop_animation_observer_helper.h

Issue 2615613003: Fix double ripple on activated flood fill ripple (Closed)
Patch Set: Used AssertionResult Created 3 years, 11 months 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/test/flood_fill_ink_drop_ripple_test_api.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 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
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
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 AnimationStartedContextsMatches(
bruthig 2017/01/11 23:18:04 nit: "Match" reads better to me than "Matches", he
mohsen 2017/01/12 19:31:56 Done.
118 const std::vector<ContextType>& expected_contexts) {
119 return ContextsMatches(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 AnimationEndedContextsMatches(
125 const std::vector<ContextType>& expected_contexts) {
126 return ContextsMatches(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 appropraite AssertionResult.
132 testing::AssertionResult ContextsMatches(
133 const std::vector<ContextType>& expected_contexts,
134 const std::vector<ContextType>& actual_contexts) {
135 if (expected_contexts.size() != actual_contexts.size()) {
136 return testing::AssertionFailure()
137 << "Size mismatch. Expected " << expected_contexts.size()
138 << " elements while there are " << actual_contexts.size()
139 << " elements.";
140 }
141 for (size_t i = 0; i < expected_contexts.size(); i++) {
142 if (expected_contexts[i] != actual_contexts[i]) {
143 return testing::AssertionFailure()
bruthig 2017/01/11 23:18:04 nit: Consider capturing log output for the entire
mohsen 2017/01/12 19:31:56 Done.
144 << i << "th elements do not match. Expected "
145 << ToString(expected_contexts[i]) << " while it is "
146 << ToString(actual_contexts[i]) << ".";
147 }
148 }
149 return testing::AssertionSuccess() << "Lists are the same.";
150 }
151
114 // Returns the next event ordinal. The first returned ordinal will be 1. 152 // Returns the next event ordinal. The first returned ordinal will be 1.
115 int GetNextOrdinal() const { 153 int GetNextOrdinal() const {
116 return std::max(1, std::max(last_animation_started_ordinal_, 154 return std::max(1, std::max(last_animation_started_ordinal_,
117 last_animation_ended_ordinal_) + 155 last_animation_ended_ordinal_) +
118 1); 156 1);
119 } 157 }
120 158
121 // The ordinal time of the last AnimationStarted() call. 159 // The ordinal time of the last AnimationStarted() call.
122 int last_animation_started_ordinal_; 160 int last_animation_started_ordinal_;
123 161
162 // List of contexts for which animation is started.
163 std::vector<ContextType> animation_started_contexts_;
164
124 // The |context| passed to the last call to AnimationStarted(). 165 // The |context| passed to the last call to AnimationStarted().
125 ContextType last_animation_started_context_; 166 ContextType last_animation_started_context_;
126 167
127 // The ordinal time of the last AnimationEnded() call. 168 // The ordinal time of the last AnimationEnded() call.
128 int last_animation_ended_ordinal_; 169 int last_animation_ended_ordinal_;
129 170
171 // List of contexts for which animation is ended.
172 std::vector<ContextType> animation_ended_contexts_;
173
130 // The |context| passed to the last call to AnimationEnded(). 174 // The |context| passed to the last call to AnimationEnded().
131 ContextType last_animation_ended_context_; 175 ContextType last_animation_ended_context_;
132 176
133 InkDropAnimationEndedReason last_animation_ended_reason_; 177 InkDropAnimationEndedReason last_animation_ended_reason_;
134 178
135 DISALLOW_COPY_AND_ASSIGN(TestInkDropAnimationObserverHelper); 179 DISALLOW_COPY_AND_ASSIGN(TestInkDropAnimationObserverHelper);
136 }; 180 };
137 181
138 } // namespace test 182 } // namespace test
139 } // namespace views 183 } // namespace views
140 184
141 #endif // UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_ 185 #endif // UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_ANIMATION_OBSERVER_H_
OLDNEW
« no previous file with comments | « ui/views/animation/test/flood_fill_ink_drop_ripple_test_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698