Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compositor/test/test_layer_animation_observer.h" | 5 #include "ui/compositor/test/test_layer_animation_observer.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 namespace ui { | 9 namespace ui { |
| 10 | 10 |
| 11 TestLayerAnimationObserver::TestLayerAnimationObserver() | 11 TestLayerAnimationObserver::TestLayerAnimationObserver() |
| 12 : last_ended_sequence_(NULL), | 12 : next_epoch_(0), |
| 13 last_scheduled_sequence_(NULL), | 13 last_attached_sequence_(nullptr), |
| 14 last_aborted_sequence_(NULL), | 14 last_attached_sequence_epoch_(-1), |
| 15 requires_notification_when_animator_destroyed_(false) { | 15 last_scheduled_sequence_(nullptr), |
| 16 last_scheduled_sequence_epoch_(-1), | |
| 17 last_started_sequence_(nullptr), | |
| 18 last_started_sequence_epoch_(-1), | |
| 19 last_aborted_sequence_(nullptr), | |
| 20 last_aborted_sequence_epoch_(-1), | |
| 21 last_ended_sequence_(nullptr), | |
| 22 last_ended_sequence_epoch_(-1), | |
| 23 last_detached_sequence_(nullptr), | |
| 24 last_detached_sequence_epoch_(-1), | |
| 25 requires_notification_when_animator_destroyed_(false) {} | |
| 26 | |
| 27 TestLayerAnimationObserver::~TestLayerAnimationObserver() { | |
| 16 } | 28 } |
| 17 | 29 |
| 18 TestLayerAnimationObserver::~TestLayerAnimationObserver() { | 30 void TestLayerAnimationObserver::ResetLayerAnimationObserverations() { |
| 31 next_epoch_ = 0; | |
| 32 last_attached_sequence_ = nullptr; | |
| 33 last_attached_sequence_epoch_ = -1; | |
| 34 last_scheduled_sequence_ = nullptr; | |
| 35 last_scheduled_sequence_epoch_ = -1; | |
| 36 last_started_sequence_ = nullptr; | |
| 37 last_started_sequence_epoch_ = -1; | |
| 38 last_aborted_sequence_ = nullptr; | |
| 39 last_aborted_sequence_epoch_ = -1; | |
| 40 last_ended_sequence_ = nullptr; | |
| 41 last_ended_sequence_epoch_ = -1; | |
| 42 last_detached_sequence_ = nullptr; | |
| 43 last_detached_sequence_epoch_ = -1; | |
| 44 } | |
| 45 | |
| 46 void TestLayerAnimationObserver::OnAttachedToSequence( | |
| 47 LayerAnimationSequence* sequence) { | |
| 48 last_attached_sequence_ = sequence; | |
| 49 last_attached_sequence_epoch_ = next_epoch_++; | |
| 50 } | |
| 51 | |
| 52 void TestLayerAnimationObserver::OnLayerAnimationScheduled( | |
| 53 LayerAnimationSequence* sequence) { | |
| 54 last_scheduled_sequence_ = sequence; | |
| 55 last_scheduled_sequence_epoch_ = next_epoch_++; | |
| 56 } | |
| 57 | |
| 58 void TestLayerAnimationObserver::OnLayerAnimationStarted( | |
| 59 LayerAnimationSequence* sequence) { | |
| 60 last_started_sequence_ = sequence; | |
| 61 last_started_sequence_epoch_ = next_epoch_++; | |
| 62 } | |
| 63 | |
| 64 void TestLayerAnimationObserver::OnLayerAnimationAborted( | |
| 65 LayerAnimationSequence* sequence) { | |
| 66 last_aborted_sequence_ = sequence; | |
| 67 last_aborted_sequence_epoch_ = next_epoch_++; | |
| 19 } | 68 } |
| 20 | 69 |
| 21 void TestLayerAnimationObserver::OnLayerAnimationEnded( | 70 void TestLayerAnimationObserver::OnLayerAnimationEnded( |
| 22 LayerAnimationSequence* sequence) { | 71 LayerAnimationSequence* sequence) { |
| 23 last_ended_sequence_ = sequence; | 72 last_ended_sequence_ = sequence; |
| 73 last_ended_sequence_epoch_ = next_epoch_++; | |
| 24 } | 74 } |
| 25 | 75 |
| 26 void TestLayerAnimationObserver::OnLayerAnimationAborted( | 76 void TestLayerAnimationObserver::OnDetachedFromSequence( |
| 27 LayerAnimationSequence* sequence) { | 77 LayerAnimationSequence* sequence) { |
| 28 last_aborted_sequence_ = sequence; | 78 last_detached_sequence_ = sequence; |
| 29 } | 79 last_detached_sequence_epoch_ = next_epoch_++; |
| 30 | |
| 31 void TestLayerAnimationObserver::OnLayerAnimationScheduled( | |
| 32 LayerAnimationSequence* sequence) { | |
| 33 last_scheduled_sequence_ = sequence; | |
| 34 } | 80 } |
| 35 | 81 |
| 36 bool | 82 bool |
| 37 TestLayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed() const { | 83 TestLayerAnimationObserver::RequiresNotificationWhenAnimatorDestroyed() const { |
| 38 return requires_notification_when_animator_destroyed_; | 84 return requires_notification_when_animator_destroyed_; |
| 39 } | 85 } |
| 40 | 86 |
| 87 testing::AssertionResult TestLayerAnimationObserver::NoEventsObserved() { | |
| 88 if (!last_attached_sequence_ && !last_scheduled_sequence_ && | |
| 89 !last_started_sequence_ && !last_aborted_sequence_ && | |
| 90 !last_ended_sequence_ && !last_detached_sequence_) { | |
| 91 return testing::AssertionSuccess(); | |
| 92 } else { | |
| 93 testing::AssertionResult assertion_failure = testing::AssertionFailure(); | |
| 94 assertion_failure << "The following events have been observed:"; | |
| 95 if (last_attached_sequence_) { | |
| 96 assertion_failure << "\n\tlast_attached_sequence_=" | |
| 97 << last_attached_sequence_; | |
|
Ian Vollick
2015/10/07 17:52:13
This is so cool.
| |
| 98 } | |
| 99 if (last_scheduled_sequence_) { | |
| 100 assertion_failure << "\n\tlast_scheduled_sequence_=" | |
| 101 << last_scheduled_sequence_; | |
| 102 } | |
| 103 if (last_started_sequence_) { | |
| 104 assertion_failure << "\n\tlast_started_sequence_=" | |
| 105 << last_started_sequence_; | |
| 106 } | |
| 107 if (last_aborted_sequence_) { | |
| 108 assertion_failure << "\n\tlast_aborted_sequence_=" | |
| 109 << last_aborted_sequence_; | |
| 110 } | |
| 111 if (last_ended_sequence_) { | |
| 112 assertion_failure << "\n\tlast_ended_sequence_" << last_ended_sequence_; | |
| 113 } | |
| 114 if (last_detached_sequence_) { | |
| 115 assertion_failure << "\n\tlast_detached_sequence_=" | |
| 116 << last_detached_sequence_; | |
| 117 } | |
| 118 return assertion_failure; | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 testing::AssertionResult | |
| 123 TestLayerAnimationObserver::AttachedEpochIsBeforeScheduledEpoch() { | |
| 124 if (last_attached_sequence_epoch_ < last_scheduled_sequence_epoch_) { | |
| 125 return testing::AssertionSuccess(); | |
| 126 } else { | |
| 127 return testing::AssertionFailure() | |
| 128 << "The attached epoch=" << last_attached_sequence_epoch_ | |
| 129 << " is NOT before the scheduled epoch=" | |
| 130 << last_scheduled_sequence_epoch_; | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 testing::AssertionResult | |
| 135 TestLayerAnimationObserver::ScheduledEpochIsBeforeStartedEpoch() { | |
| 136 if (last_scheduled_sequence_epoch_ < last_started_sequence_epoch_) { | |
| 137 return testing::AssertionSuccess(); | |
| 138 } else { | |
| 139 return testing::AssertionFailure() | |
| 140 << "The scheduled epoch=" << last_scheduled_sequence_epoch_ | |
| 141 << " is NOT before the started epoch=" | |
| 142 << last_started_sequence_epoch_; | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 testing::AssertionResult | |
| 147 TestLayerAnimationObserver::StartedEpochIsBeforeEndedEpoch() { | |
| 148 if (last_started_sequence_epoch_ < last_ended_sequence_epoch_) { | |
| 149 return testing::AssertionSuccess(); | |
| 150 } else { | |
| 151 return testing::AssertionFailure() | |
| 152 << "The started epoch=" << last_started_sequence_epoch_ | |
| 153 << " is NOT before the ended epoch=" << last_ended_sequence_epoch_; | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 testing::AssertionResult | |
| 158 TestLayerAnimationObserver::StartedEpochIsBeforeAbortedEpoch() { | |
| 159 if (last_started_sequence_epoch_ < last_aborted_sequence_epoch_) { | |
| 160 return testing::AssertionSuccess(); | |
| 161 } else { | |
| 162 return testing::AssertionFailure() | |
| 163 << "The started epoch=" << last_started_sequence_epoch_ | |
| 164 << " is NOT before the aborted epoch=" | |
| 165 << last_aborted_sequence_epoch_; | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 testing::AssertionResult | |
| 170 TestLayerAnimationObserver::AbortedEpochIsBeforeStartedEpoch() { | |
| 171 if (last_aborted_sequence_epoch_ < last_started_sequence_epoch_) { | |
| 172 return testing::AssertionSuccess(); | |
| 173 } else { | |
| 174 return testing::AssertionFailure() | |
| 175 << "The aborted epoch=" << last_aborted_sequence_epoch_ | |
| 176 << " is NOT before the started epoch=" | |
| 177 << last_started_sequence_epoch_; | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 testing::AssertionResult | |
| 182 TestLayerAnimationObserver::AbortedEpochIsBeforeDetachedEpoch() { | |
| 183 if (last_aborted_sequence_epoch_ < last_detached_sequence_epoch_) { | |
| 184 return testing::AssertionSuccess(); | |
| 185 } else { | |
| 186 return testing::AssertionFailure() | |
| 187 << "The aborted epoch=" << last_aborted_sequence_epoch_ | |
| 188 << " is NOT before the detached epoch=" | |
| 189 << last_detached_sequence_epoch_; | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 testing::AssertionResult | |
| 194 TestLayerAnimationObserver::EndedEpochIsBeforeStartedEpoch() { | |
| 195 if (last_ended_sequence_epoch_ < last_started_sequence_epoch_) { | |
| 196 return testing::AssertionSuccess(); | |
| 197 } else { | |
| 198 return testing::AssertionFailure() | |
| 199 << "The ended epoch=" << last_ended_sequence_epoch_ | |
| 200 << " is NOT before the started epoch=" | |
| 201 << last_started_sequence_epoch_; | |
| 202 } | |
| 203 } | |
| 204 | |
| 205 testing::AssertionResult | |
| 206 TestLayerAnimationObserver::EndedEpochIsBeforeDetachedEpoch() { | |
| 207 if (last_ended_sequence_epoch_ < last_detached_sequence_epoch_) { | |
| 208 return testing::AssertionSuccess(); | |
| 209 } else { | |
| 210 return testing::AssertionFailure() | |
| 211 << "The ended epoch=" << last_ended_sequence_epoch_ | |
| 212 << " is NOT before the detached epoch=" | |
| 213 << last_detached_sequence_epoch_; | |
| 214 } | |
| 215 } | |
| 216 | |
| 41 } // namespace ui | 217 } // namespace ui |
| OLD | NEW |