test_layer_animation_observer.cc 7.9 KB

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