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 "ash/wm/window_animations.h" | 5 #include "ash/wm/window_animations.h" |
6 | 6 |
7 #include "ash/shell_window_ids.h" | 7 #include "ash/shell_window_ids.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/wm/window_state.h" | |
9 #include "ash/wm/workspace_controller.h" | 10 #include "ash/wm/workspace_controller.h" |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
11 #include "ui/aura/test/test_windows.h" | 12 #include "ui/aura/test/test_windows.h" |
12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
13 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
15 #include "ui/compositor/layer_animation_observer.h" | |
14 #include "ui/compositor/layer_animator.h" | 16 #include "ui/compositor/layer_animator.h" |
15 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
18 #include "ui/compositor/scoped_layer_animation_settings.h" | |
16 #include "ui/gfx/animation/animation_container_element.h" | 19 #include "ui/gfx/animation/animation_container_element.h" |
17 | 20 |
18 using aura::Window; | 21 using aura::Window; |
19 using ui::Layer; | 22 using ui::Layer; |
20 | 23 |
21 namespace ash { | 24 namespace ash { |
22 namespace internal { | 25 namespace internal { |
23 | 26 |
24 class WindowAnimationsTest : public ash::test::AshTestBase { | 27 class WindowAnimationsTest : public ash::test::AshTestBase { |
25 public: | 28 public: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 // New layer animates in to the identity transform. | 129 // New layer animates in to the identity transform. |
127 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 130 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
128 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); | 131 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); |
129 | 132 |
130 static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( | 133 static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( |
131 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | 134 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); |
132 static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> | 135 static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> |
133 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | 136 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); |
134 } | 137 } |
135 | 138 |
139 TEST_F(WindowAnimationsTest, LockAnimationDuration) { | |
140 ui::ScopedAnimationDurationScaleMode long_duration( | |
James Cook
2013/12/02 18:33:51
Did you mean normal_duration? Or is this long rela
varkha
2013/12/02 20:18:09
I was meaning to do something else and ended up le
| |
141 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | |
142 | |
143 scoped_ptr<Window> window(CreateTestWindowInShellWithId(0)); | |
144 Layer* layer = window->layer(); | |
145 window->SetBounds(gfx::Rect(5, 10, 320, 240)); | |
146 window->Show(); | |
147 | |
148 // Test that it is possible to override transition duration when it is not | |
149 // locked. | |
150 { | |
151 ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator()); | |
152 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
153 { | |
154 ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator()); | |
155 // Duration is not locked so it gets overridden. | |
156 settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50)); | |
157 wm::GetWindowState(window.get())->Minimize(); | |
158 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
159 // Expect duration from the inner scope | |
160 EXPECT_EQ(50, | |
161 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
162 } | |
163 window->Show(); | |
164 layer->GetAnimator()->StopAnimating(); | |
165 } | |
166 | |
167 // Test that it is possible to lock transition duration | |
168 { | |
169 ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator()); | |
170 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
171 // Duration is locked in outer scope. | |
172 settings1.LockTransitionDuration(); | |
173 { | |
174 ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator()); | |
175 // Transition duration setting is ignored. | |
176 settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50)); | |
177 wm::GetWindowState(window.get())->Minimize(); | |
178 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
179 // Expect duration from the outer scope | |
180 EXPECT_EQ(1000, | |
181 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
182 } | |
183 window->Show(); | |
184 layer->GetAnimator()->StopAnimating(); | |
185 } | |
186 | |
187 // Listens to animation scheduled notifications. Remembers the transition | |
188 // duration of the first sequence. | |
189 class MinimizeAnimationObserver : public ui::LayerAnimationObserver { | |
James Cook
2013/12/02 18:33:51
optional nit: It's unusual to see classes declared
varkha
2013/12/02 20:18:09
Done.
| |
190 public: | |
191 MinimizeAnimationObserver(ui::LayerAnimator* animator) | |
James Cook
2013/12/02 18:33:51
nit: explicit
varkha
2013/12/02 20:18:09
Done.
| |
192 : animator_(animator) { | |
193 animator_->AddObserver(this); | |
194 }; | |
195 virtual ~MinimizeAnimationObserver() { | |
196 animator_->RemoveObserver(this); | |
197 }; | |
198 base::TimeDelta duration() { return duration_; } | |
199 | |
200 protected: | |
201 // ui::LayerAnimationObserver: | |
202 virtual void OnLayerAnimationScheduled( | |
203 ui::LayerAnimationSequence* sequence) OVERRIDE { | |
204 duration_ = animator_->GetTransitionDuration(); | |
205 animator_->RemoveObserver(this); | |
James Cook
2013/12/02 18:33:51
Do you need to remove the observer in two places?
varkha
2013/12/02 20:18:09
I wanted to add an assert about !HasObserver in th
| |
206 } | |
207 virtual void OnLayerAnimationEnded( | |
208 ui::LayerAnimationSequence* sequence) OVERRIDE {} | |
209 virtual void OnLayerAnimationAborted( | |
210 ui::LayerAnimationSequence* sequence) OVERRIDE {} | |
211 | |
212 private: | |
213 ui::LayerAnimator* animator_; | |
214 base::TimeDelta duration_; | |
215 }; | |
216 | |
217 // Test that duration respects default. | |
218 { | |
219 // Query default duration. | |
220 MinimizeAnimationObserver observer(layer->GetAnimator()); | |
221 wm::GetWindowState(window.get())->Minimize(); | |
222 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
223 base::TimeDelta default_duration(observer.duration()); | |
224 window->Show(); | |
225 layer->GetAnimator()->StopAnimating(); | |
226 | |
227 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | |
228 settings.LockTransitionDuration(); | |
229 // Setting transition duration is ignored since duration is locked | |
230 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
231 wm::GetWindowState(window.get())->Minimize(); | |
232 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
233 // Expect default duration (200ms for stock ash minimizing animation). | |
234 EXPECT_EQ(default_duration.InMilliseconds(), | |
235 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
236 window->Show(); | |
237 layer->GetAnimator()->StopAnimating(); | |
238 } | |
239 } | |
240 | |
136 } // namespace internal | 241 } // namespace internal |
137 } // namespace ash | 242 } // namespace ash |
OLD | NEW |