test_layer_animation_observer.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #ifndef UI_COMPOSITOR_TEST_TEST_LAYER_ANIMATION_OBSERVER_H_
  5. #define UI_COMPOSITOR_TEST_TEST_LAYER_ANIMATION_OBSERVER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #include "ui/compositor/layer_animation_observer.h"
  9. namespace ui {
  10. class LayerAnimationSequence;
  11. // Listens to animation ended notifications. Remembers the last sequence that
  12. // it was notified about.
  13. class TestLayerAnimationObserver : public LayerAnimationObserver {
  14. public:
  15. TestLayerAnimationObserver();
  16. ~TestLayerAnimationObserver() override;
  17. // Resets all the data tracking LayerAnimationObserver observations.
  18. void ResetLayerAnimationObserverations();
  19. // LayerAnimationObserver:
  20. void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override;
  21. void OnLayerAnimationStarted(LayerAnimationSequence* sequence) override;
  22. void OnLayerAnimationAborted(LayerAnimationSequence* sequence) override;
  23. void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override;
  24. void OnLayerAnimationWillRepeat(LayerAnimationSequence* sequence) override;
  25. bool RequiresNotificationWhenAnimatorDestroyed() const override;
  26. const LayerAnimationSequence* last_attached_sequence() const {
  27. return last_attached_sequence_;
  28. }
  29. int last_attached_sequence_epoch() const {
  30. return last_attached_sequence_epoch_;
  31. }
  32. const LayerAnimationSequence* last_scheduled_sequence() const {
  33. return last_scheduled_sequence_;
  34. }
  35. int last_scheduled_sequence_epoch() const {
  36. return last_scheduled_sequence_epoch_;
  37. }
  38. const LayerAnimationSequence* last_started_sequence() const {
  39. return last_started_sequence_;
  40. }
  41. int last_started_sequence_epoch() const {
  42. return last_started_sequence_epoch_;
  43. }
  44. const LayerAnimationSequence* last_aborted_sequence() const {
  45. return last_aborted_sequence_;
  46. }
  47. int last_aborted_sequence_epoch() const {
  48. return last_aborted_sequence_epoch_;
  49. }
  50. const LayerAnimationSequence* last_ended_sequence() const {
  51. return last_ended_sequence_;
  52. }
  53. int last_ended_sequence_epoch() const { return last_ended_sequence_epoch_; }
  54. const LayerAnimationSequence* last_repetition_ended_sequence() const {
  55. return last_repetition_ended_sequence_;
  56. }
  57. int last_repetition_ended_sequence_epoch() const {
  58. return last_repetition_ended_sequence_epoch_;
  59. }
  60. const LayerAnimationSequence* last_detached_sequence() const {
  61. return last_detached_sequence_;
  62. }
  63. int last_detached_sequence_epoch() const {
  64. return last_detached_sequence_epoch_;
  65. }
  66. void set_requires_notification_when_animator_destroyed(bool value) {
  67. requires_notification_when_animator_destroyed_ = value;
  68. }
  69. testing::AssertionResult NoEventsObserved();
  70. testing::AssertionResult AttachedEpochIsBeforeScheduledEpoch();
  71. testing::AssertionResult ScheduledEpochIsBeforeStartedEpoch();
  72. testing::AssertionResult StartedEpochIsBeforeEndedEpoch();
  73. testing::AssertionResult StartedEpochIsBeforeAbortedEpoch();
  74. testing::AssertionResult AbortedEpochIsBeforeStartedEpoch();
  75. testing::AssertionResult AbortedEpochIsBeforeDetachedEpoch();
  76. testing::AssertionResult EndedEpochIsBeforeStartedEpoch();
  77. testing::AssertionResult EndedEpochIsBeforeDetachedEpoch();
  78. protected:
  79. // LayerAnimationObserver:
  80. void OnAttachedToSequence(LayerAnimationSequence* sequence) override;
  81. void OnDetachedFromSequence(LayerAnimationSequence* sequence) override;
  82. private:
  83. int next_epoch_;
  84. // TODO(crbug.com/1298696): Breaks compositor_unittests.
  85. raw_ptr<const LayerAnimationSequence, DegradeToNoOpWhenMTE>
  86. last_attached_sequence_;
  87. int last_attached_sequence_epoch_;
  88. raw_ptr<const LayerAnimationSequence, DegradeToNoOpWhenMTE>
  89. last_scheduled_sequence_;
  90. int last_scheduled_sequence_epoch_;
  91. raw_ptr<const LayerAnimationSequence, DegradeToNoOpWhenMTE>
  92. last_started_sequence_;
  93. int last_started_sequence_epoch_;
  94. raw_ptr<const LayerAnimationSequence, DegradeToNoOpWhenMTE>
  95. last_aborted_sequence_;
  96. int last_aborted_sequence_epoch_;
  97. raw_ptr<const LayerAnimationSequence, DegradeToNoOpWhenMTE>
  98. last_ended_sequence_;
  99. int last_ended_sequence_epoch_;
  100. raw_ptr<const LayerAnimationSequence, DegradeToNoOpWhenMTE>
  101. last_repetition_ended_sequence_;
  102. int last_repetition_ended_sequence_epoch_;
  103. raw_ptr<const LayerAnimationSequence, DegradeToNoOpWhenMTE>
  104. last_detached_sequence_;
  105. int last_detached_sequence_epoch_;
  106. bool requires_notification_when_animator_destroyed_;
  107. // Copy and assign are allowed.
  108. };
  109. } // namespace ui
  110. #endif // UI_COMPOSITOR_TEST_TEST_LAYER_ANIMATION_OBSERVER_H_