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) { | |
varkha
2013/11/28 21:50:43
I thought a test for the new ability would be usef
| |
140 ui::ScopedAnimationDurationScaleMode long_duration( | |
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 } | |
165 | |
166 // Test that it is possible to lock transition duration | |
167 { | |
168 ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator()); | |
169 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
170 // Duration is locked in outer scope. | |
171 settings1.SetTransitionDurationLocked(true); | |
172 { | |
173 ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator()); | |
174 // Transition duration setting is ignored. | |
175 settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50)); | |
176 wm::GetWindowState(window.get())->Minimize(); | |
177 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
178 // Expect duration from the outer scope | |
179 EXPECT_EQ(1000, | |
180 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
181 } | |
182 window->Show(); | |
183 } | |
184 | |
185 // Test that it is possible to unlock transition duration | |
186 { | |
187 ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator()); | |
188 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
189 settings1.SetTransitionDurationLocked(true); | |
190 { | |
191 ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator()); | |
192 // Duration is unlocked in inner scope. | |
193 settings2.SetTransitionDurationLocked(false); | |
194 // Transition duration is properly set. | |
195 settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50)); | |
196 wm::GetWindowState(window.get())->Minimize(); | |
197 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
198 // Expect duration from the inner scope | |
199 EXPECT_EQ(50, | |
200 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
201 } | |
202 window->Show(); | |
203 } | |
204 | |
205 // Observer class to query default animation duration when animation starts. | |
206 class MinimizeAnimationObserver : public ui::LayerAnimationObserver { | |
207 public: | |
208 MinimizeAnimationObserver(ui::LayerAnimator* animator) | |
209 : animator_(animator) {}; | |
210 base::TimeDelta duration() { return duration_; } | |
211 | |
212 protected: | |
213 // ui::LayerAnimationObserver: | |
214 virtual void OnLayerAnimationEnded( | |
215 ui::LayerAnimationSequence* sequence) OVERRIDE {} | |
216 virtual void OnLayerAnimationAborted( | |
217 ui::LayerAnimationSequence* sequence) OVERRIDE {} | |
218 virtual void OnLayerAnimationScheduled( | |
219 ui::LayerAnimationSequence* sequence) OVERRIDE { | |
220 duration_ = animator_->GetTransitionDuration(); | |
221 } | |
222 | |
223 private: | |
224 ui::LayerAnimator* animator_; | |
225 base::TimeDelta duration_; | |
226 DISALLOW_COPY_AND_ASSIGN(MinimizeAnimationObserver); | |
227 }; | |
228 | |
229 // Test that duration respects default. | |
230 { | |
231 MinimizeAnimationObserver observer(layer->GetAnimator()); | |
232 layer->GetAnimator()->AddObserver(&observer); | |
233 wm::GetWindowState(window.get())->Minimize(); | |
234 layer->GetAnimator()->RemoveObserver(&observer); | |
235 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
236 base::TimeDelta default_duration(observer.duration()); | |
237 LOG(INFO) << "default " << default_duration.InMilliseconds(); | |
238 layer->GetAnimator()->StopAnimating(); | |
239 window->Show(); | |
240 | |
241 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | |
242 settings.SetTransitionDurationLocked(true); | |
243 // Setting transition duration is ignored since duration is locked | |
244 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
245 wm::GetWindowState(window.get())->Minimize(); | |
246 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
247 // Expect default duration (200ms for stock ash minimizing animation). | |
248 EXPECT_EQ(default_duration.InMilliseconds(), | |
249 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
250 } | |
251 } | |
252 | |
136 } // namespace internal | 253 } // namespace internal |
137 } // namespace ash | 254 } // namespace ash |
OLD | NEW |