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/workspace_controller.h" | 9 #include "ash/wm/workspace_controller.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 virtual void TearDown() OVERRIDE { | 27 virtual void TearDown() OVERRIDE { |
28 ui::LayerAnimator::set_disable_animations_for_test(true); | 28 ui::LayerAnimator::set_disable_animations_for_test(true); |
29 AshTestBase::TearDown(); | 29 AshTestBase::TearDown(); |
30 } | 30 } |
31 | 31 |
32 private: | 32 private: |
33 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); | 33 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); |
34 }; | 34 }; |
35 | 35 |
36 TEST_F(WindowAnimationsTest, HideShow) { | |
37 scoped_ptr<aura::Window> window( | |
38 aura::test::CreateTestWindowWithId(0, NULL)); | |
39 window->Show(); | |
40 EXPECT_TRUE(window->layer()->visible()); | |
41 // Hiding. | |
42 SetWindowVisibilityAnimationType( | |
43 window.get(), | |
44 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE); | |
45 ash::internal::AnimateOnChildWindowVisibilityChanged( | |
46 window.get(), false); | |
47 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | |
48 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | |
49 EXPECT_FALSE(window->layer()->visible()); | |
50 // Showing. | |
51 SetWindowVisibilityAnimationType( | |
52 window.get(), | |
53 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_SHOW); | |
54 ash::internal::AnimateOnChildWindowVisibilityChanged( | |
55 window.get(), true); | |
56 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | |
57 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
58 EXPECT_TRUE(window->layer()->visible()); | |
59 // Stays showing. | |
60 ui::AnimationContainerElement* element = | |
61 static_cast<ui::AnimationContainerElement*>( | |
62 window->layer()->GetAnimator()); | |
63 element->Step(base::TimeTicks::Now() + | |
64 base::TimeDelta::FromSeconds(5)); | |
65 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | |
66 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
67 EXPECT_TRUE(window->layer()->visible()); | |
68 } | |
69 | |
70 TEST_F(WindowAnimationsTest, ShowHide) { | |
71 scoped_ptr<aura::Window> window( | |
72 aura::test::CreateTestWindowWithId(0, NULL)); | |
73 window->Show(); | |
74 EXPECT_TRUE(window->layer()->visible()); | |
75 // Showing -- should be a no-op. | |
76 SetWindowVisibilityAnimationType( | |
77 window.get(), | |
78 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_SHOW); | |
79 ash::internal::AnimateOnChildWindowVisibilityChanged( | |
80 window.get(), true); | |
81 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | |
82 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
83 EXPECT_TRUE(window->layer()->visible()); | |
84 // Hiding. | |
85 SetWindowVisibilityAnimationType( | |
86 window.get(), | |
87 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE); | |
88 ash::internal::AnimateOnChildWindowVisibilityChanged( | |
89 window.get(), false); | |
90 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | |
91 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | |
92 EXPECT_FALSE(window->layer()->visible()); | |
93 // Stays hidden. | |
94 ui::AnimationContainerElement* element = | |
95 static_cast<ui::AnimationContainerElement*>( | |
96 window->layer()->GetAnimator()); | |
97 element->Step(base::TimeTicks::Now() + | |
98 base::TimeDelta::FromSeconds(5)); | |
99 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | |
100 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | |
101 EXPECT_FALSE(window->layer()->visible()); | |
102 } | |
103 | |
104 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { | 36 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { |
105 scoped_ptr<aura::Window> window( | 37 scoped_ptr<aura::Window> window( |
106 aura::test::CreateTestWindowWithId(0, NULL)); | 38 aura::test::CreateTestWindowWithId(0, NULL)); |
107 window->Show(); | 39 window->Show(); |
108 EXPECT_TRUE(window->layer()->visible()); | 40 EXPECT_TRUE(window->layer()->visible()); |
109 | 41 |
110 // Hiding. | 42 // Hiding. |
111 SetWindowVisibilityAnimationType( | 43 SetWindowVisibilityAnimationType( |
112 window.get(), | 44 window.get(), |
113 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); | 45 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // New layer animates in to the identity transform. | 130 // New layer animates in to the identity transform. |
199 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 131 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
200 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); | 132 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); |
201 | 133 |
202 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step( | 134 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step( |
203 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | 135 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); |
204 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())-> | 136 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())-> |
205 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | 137 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); |
206 } | 138 } |
207 | 139 |
208 TEST_F(WindowAnimationsTest, GetCrossFadeDuration) { | |
209 if (WorkspaceController::IsWorkspace2Enabled()) | |
210 return; | |
211 | |
212 gfx::Rect empty; | |
213 gfx::Rect screen(0, 0, 1000, 500); | |
214 | |
215 // No change takes no time. | |
216 EXPECT_EQ(0, GetCrossFadeDuration(empty, empty).InMilliseconds()); | |
217 EXPECT_EQ(0, GetCrossFadeDuration(screen, screen).InMilliseconds()); | |
218 | |
219 // Small changes are fast. | |
220 const int kMinimum = 100; | |
221 const int kRange = 300; | |
222 gfx::Rect almost_screen(10, 10, 1000, 450); // 90% of screen area | |
223 EXPECT_EQ(kMinimum + kRange / 10, | |
224 GetCrossFadeDuration(almost_screen, screen).InMilliseconds()); | |
225 EXPECT_EQ(kMinimum + kRange / 10, | |
226 GetCrossFadeDuration(screen, almost_screen).InMilliseconds()); | |
227 | |
228 // Large changes are slow. | |
229 gfx::Rect ten_percent(10, 10, 100, 500); // 10% of screen area | |
230 EXPECT_EQ(kMinimum + kRange * 9 / 10, | |
231 GetCrossFadeDuration(ten_percent, screen).InMilliseconds()); | |
232 EXPECT_EQ(kMinimum + kRange * 9 / 10, | |
233 GetCrossFadeDuration(screen, ten_percent).InMilliseconds()); | |
234 | |
235 // Medium changes take medium time. | |
236 gfx::Rect half_screen(10, 10, 500, 250); | |
237 EXPECT_EQ(kMinimum + kRange * 3 / 4, | |
238 GetCrossFadeDuration(half_screen, screen).InMilliseconds()); | |
239 EXPECT_EQ(kMinimum + kRange * 3 / 4, | |
240 GetCrossFadeDuration(screen, half_screen).InMilliseconds()); | |
241 } | |
242 | |
243 } // namespace internal | 140 } // namespace internal |
244 } // namespace ash | 141 } // namespace ash |
OLD | NEW |