1 // Copyright 2014 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.
5 #ifndef ASH_TEST_TEST_SESSION_STATE_ANIMATOR_H_
6 #define ASH_TEST_TEST_SESSION_STATE_ANIMATOR_H_
11 #include "ash/ash_export.h"
12 #include "ash/wm/session_state_animator.h"
13 #include "base/basictypes.h"
14 #include "base/time/time.h"
19 // A SessionStateAnimator that offers control over the lifetime of active
21 // NOTE: The TestSessionStateAnimator limits each
22 // SessionStateAnimator::Container to a single active animation at any one time.
23 // If a new animation is started on a container the existing one will be
25 class TestSessionStateAnimator
: public SessionStateAnimator
{
27 TestSessionStateAnimator();
28 ~TestSessionStateAnimator() override
;
30 int last_animation_epoch() {
31 return last_animation_epoch_
;
34 // Resets the current animation epoch back to 0 and aborts all currently
36 void ResetAnimationEpoch();
38 // Advances all contained animations by the specified |duration|. Any
39 // animations that will have completed after |duration| will have its
41 void Advance(const base::TimeDelta
& duration
);
43 // Simulates running all of the contained animations to completion. Each
44 // contained AnimationSequence will have OnAnimationCompleted called if
45 // |completed_successfully| is true and OnAnimationAborted called if false.
46 void CompleteAnimations(int animation_epoch
, bool completed_successfully
);
48 // Convenience method that calls CompleteAnimations with the last
49 // |animation_epoch|. In effect this will complete all animations.
50 // See CompleteAnimations for more documenation on |completed_succesffully|.
51 void CompleteAllAnimations(bool completed_successfully
);
53 // Returns true if there is an animation active with |type| for the given
55 bool IsContainerAnimated(SessionStateAnimator::Container container
,
56 SessionStateAnimator::AnimationType type
) const;
58 // Returns true if there is an animation active with |type| for all the given
59 // containers specified by |container_mask|.
60 bool AreContainersAnimated(int container_mask
,
61 SessionStateAnimator::AnimationType type
) const;
63 // Returns the number of active animations.
64 size_t GetAnimationCount() const;
66 // ash::SessionStateAnimator:
67 void StartAnimation(int container_mask
,
69 AnimationSpeed speed
) override
;
70 void StartAnimationWithCallback(int container_mask
,
73 base::Closure callback
) override
;
74 AnimationSequence
* BeginAnimationSequence(base::Closure callback
) override
;
75 bool IsBackgroundHidden() const override
;
76 void ShowBackground() override
;
77 void HideBackground() override
;
80 class AnimationSequence
;
81 friend class AnimationSequence
;
83 // Data structure to track the currently active animations and their
85 struct ActiveAnimation
{
88 base::TimeDelta duration
,
89 SessionStateAnimator::Container container
,
92 base::Closure success_callback
,
93 base::Closure failed_callback
);
94 virtual ~ActiveAnimation();
96 // The time epoch that this animation was scheduled.
99 // The time remaining for this animation.
100 base::TimeDelta remaining_duration
;
102 // The container which is being animated.
103 SessionStateAnimator::Container container
;
105 // The animation type that is being done.
108 // The speed at which the animation is being done.
109 AnimationSpeed speed
;
111 // The callback to be invoked upon a successful completion.
112 base::Closure success_callback
;
114 // The callback to be invoked upon an unsuccessful completion.
115 base::Closure failed_callback
;
118 typedef std::vector
<ActiveAnimation
> AnimationList
;
119 typedef std::map
<SessionStateAnimator::Container
, AnimationList
>
122 // Starts an animation in the |animation_sequence| for each container
123 // specified by |container_mask| with the given |type| and |speed|.
124 virtual void StartAnimationInSequence(
127 AnimationSpeed speed
,
128 AnimationSequence
* animation_sequence
);
130 // Adds a single animation to the currently active animations. If an
131 // animation is already active for the given |container| then it will be
132 // replaced by the new one. The existing animation will be aborted by calling
133 // OnAnimationAborted.
134 void AddAnimation(SessionStateAnimator::Container container
,
136 AnimationSpeed speed
,
137 base::Closure success_callback
,
138 base::Closure failed_callback
);
140 // If an animation is currently active for the given |container| it will be
141 // aborted by invoking OnAnimationAborted and removed from the list of active
143 void AbortAnimation(SessionStateAnimator::Container container
);
145 // Used for easy iteration over all the containers.
146 static const SessionStateAnimator::Container kAllContainers
[];
148 // A map of currently active animations.
149 ActiveAnimationsMap active_animations_
;
151 // A time counter that tracks the last scheduled animation or animation
153 int last_animation_epoch_
;
155 // Tracks whether the background is hidden or not.
156 bool is_background_hidden_
;
158 DISALLOW_COPY_AND_ASSIGN(TestSessionStateAnimator
);
164 #endif // ASH_TEST_TEST_SESSION_STATE_ANIMATOR_H_