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/window_state.h" |
10 #include "ash/wm/workspace_controller.h" | 10 #include "ash/wm/workspace_controller.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 WindowAnimationsTest() {} | 29 WindowAnimationsTest() {} |
30 | 30 |
31 virtual void TearDown() OVERRIDE { | 31 virtual void TearDown() OVERRIDE { |
32 AshTestBase::TearDown(); | 32 AshTestBase::TearDown(); |
33 } | 33 } |
34 | 34 |
35 private: | 35 private: |
36 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); | 36 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); |
37 }; | 37 }; |
38 | 38 |
39 // Listens to animation scheduled notifications. Remembers the transition | |
40 // duration of the first sequence. | |
41 class MinimizeAnimationObserver : public ui::LayerAnimationObserver { | |
42 public: | |
43 explicit MinimizeAnimationObserver(ui::LayerAnimator* animator) | |
44 : animator_(animator) { | |
45 animator_->AddObserver(this); | |
46 // RemoveObserver is called when the first animation is scheduled and so | |
47 // there should be no need for now to remove it in destructor. | |
48 }; | |
49 base::TimeDelta duration() { return duration_; } | |
50 | |
51 protected: | |
52 // ui::LayerAnimationObserver: | |
53 virtual void OnLayerAnimationScheduled( | |
54 ui::LayerAnimationSequence* sequence) OVERRIDE { | |
55 duration_ = animator_->GetTransitionDuration(); | |
56 animator_->RemoveObserver(this); | |
57 } | |
58 virtual void OnLayerAnimationEnded( | |
59 ui::LayerAnimationSequence* sequence) OVERRIDE {} | |
60 virtual void OnLayerAnimationAborted( | |
61 ui::LayerAnimationSequence* sequence) OVERRIDE {} | |
62 | |
63 private: | |
64 ui::LayerAnimator* animator_; | |
65 base::TimeDelta duration_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(MinimizeAnimationObserver); | |
68 }; | |
69 | |
70 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { | 39 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { |
71 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 40 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
72 window->Show(); | 41 window->Show(); |
73 EXPECT_TRUE(window->layer()->visible()); | 42 EXPECT_TRUE(window->layer()->visible()); |
74 | 43 |
75 // Hiding. | 44 // Hiding. |
76 views::corewm::SetWindowVisibilityAnimationType( | 45 views::corewm::SetWindowVisibilityAnimationType( |
77 window.get(), | 46 window.get(), |
78 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); | 47 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); |
79 AnimateOnChildWindowVisibilityChanged(window.get(), false); | 48 AnimateOnChildWindowVisibilityChanged(window.get(), false); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // New layer animates in to the identity transform. | 129 // New layer animates in to the identity transform. |
161 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 130 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
162 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); | 131 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); |
163 | 132 |
164 static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( | 133 static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( |
165 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | 134 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); |
166 static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> | 135 static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> |
167 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | 136 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); |
168 } | 137 } |
169 | 138 |
170 TEST_F(WindowAnimationsTest, LockAnimationDuration) { | |
171 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | |
172 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | |
173 | |
174 scoped_ptr<Window> window(CreateTestWindowInShellWithId(0)); | |
175 Layer* layer = window->layer(); | |
176 window->SetBounds(gfx::Rect(5, 10, 320, 240)); | |
177 window->Show(); | |
178 | |
179 // Test that it is possible to override transition duration when it is not | |
180 // locked. | |
181 { | |
182 ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator()); | |
183 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
184 { | |
185 ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator()); | |
186 // Duration is not locked so it gets overridden. | |
187 settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50)); | |
188 wm::GetWindowState(window.get())->Minimize(); | |
189 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
190 // Expect duration from the inner scope | |
191 EXPECT_EQ(50, | |
192 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
193 } | |
194 window->Show(); | |
195 layer->GetAnimator()->StopAnimating(); | |
196 } | |
197 | |
198 // Test that it is possible to lock transition duration | |
199 { | |
200 ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator()); | |
201 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
202 // Duration is locked in outer scope. | |
203 settings1.LockTransitionDuration(); | |
204 { | |
205 ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator()); | |
206 // Transition duration setting is ignored. | |
207 settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50)); | |
208 wm::GetWindowState(window.get())->Minimize(); | |
209 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
210 // Expect duration from the outer scope | |
211 EXPECT_EQ(1000, | |
212 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
213 } | |
214 window->Show(); | |
215 layer->GetAnimator()->StopAnimating(); | |
216 } | |
217 | |
218 // Test that duration respects default. | |
219 { | |
220 // Query default duration. | |
221 MinimizeAnimationObserver observer(layer->GetAnimator()); | |
222 wm::GetWindowState(window.get())->Minimize(); | |
223 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
224 base::TimeDelta default_duration(observer.duration()); | |
225 window->Show(); | |
226 layer->GetAnimator()->StopAnimating(); | |
227 | |
228 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | |
229 settings.LockTransitionDuration(); | |
230 // Setting transition duration is ignored since duration is locked | |
231 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
232 wm::GetWindowState(window.get())->Minimize(); | |
233 EXPECT_TRUE(layer->GetAnimator()->is_animating()); | |
234 // Expect default duration (200ms for stock ash minimizing animation). | |
235 EXPECT_EQ(default_duration.InMilliseconds(), | |
236 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); | |
237 window->Show(); | |
238 layer->GetAnimator()->StopAnimating(); | |
239 } | |
240 } | |
241 | |
242 } // namespace internal | 139 } // namespace internal |
243 } // namespace ash | 140 } // namespace ash |
OLD | NEW |