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 "base/time.h" | 9 #include "base/time.h" |
10 #include "ui/aura/test/test_windows.h" | 10 #include "ui/aura/test/test_windows.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/base/animation/animation_container_element.h" | 12 #include "ui/base/animation/animation_container_element.h" |
13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/layer_animator.h" | 14 #include "ui/compositor/layer_animator.h" |
15 | 15 |
16 using aura::Window; | 16 using aura::Window; |
17 using ui::Layer; | 17 using ui::Layer; |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 namespace internal { | 20 namespace internal { |
21 | 21 |
22 typedef ash::test::AshTestBase WindowAnimationsTest; | 22 typedef ash::test::AshTestBase WindowAnimationsTest; |
23 | 23 |
24 TEST_F(WindowAnimationsTest, HideShow) { | 24 TEST_F(WindowAnimationsTest, HideShow) { |
25 aura::Window* default_container = | |
26 ash::Shell::GetContainer( | |
27 Shell::GetPrimaryRootWindow(), | |
28 internal::kShellWindowId_DefaultContainer); | |
29 scoped_ptr<aura::Window> window( | 25 scoped_ptr<aura::Window> window( |
30 aura::test::CreateTestWindowWithId(0, default_container)); | 26 aura::test::CreateTestWindowWithId(0, NULL)); |
31 window->Show(); | 27 window->Show(); |
32 EXPECT_TRUE(window->layer()->visible()); | 28 EXPECT_TRUE(window->layer()->visible()); |
33 // Hiding. | 29 // Hiding. |
34 SetWindowVisibilityAnimationType( | 30 SetWindowVisibilityAnimationType( |
35 window.get(), | 31 window.get(), |
36 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE); | 32 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE); |
37 ash::internal::AnimateOnChildWindowVisibilityChanged( | 33 ash::internal::AnimateOnChildWindowVisibilityChanged( |
38 window.get(), false); | 34 window.get(), false); |
39 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | 35 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); |
40 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 36 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
(...skipping 12 matching lines...) Expand all Loading... |
53 static_cast<ui::AnimationContainerElement*>( | 49 static_cast<ui::AnimationContainerElement*>( |
54 window->layer()->GetAnimator()); | 50 window->layer()->GetAnimator()); |
55 element->Step(base::TimeTicks::Now() + | 51 element->Step(base::TimeTicks::Now() + |
56 base::TimeDelta::FromSeconds(5)); | 52 base::TimeDelta::FromSeconds(5)); |
57 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 53 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
58 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 54 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
59 EXPECT_TRUE(window->layer()->visible()); | 55 EXPECT_TRUE(window->layer()->visible()); |
60 } | 56 } |
61 | 57 |
62 TEST_F(WindowAnimationsTest, ShowHide) { | 58 TEST_F(WindowAnimationsTest, ShowHide) { |
63 aura::Window* default_container = | |
64 ash::Shell::GetContainer( | |
65 Shell::GetPrimaryRootWindow(), | |
66 internal::kShellWindowId_DefaultContainer); | |
67 scoped_ptr<aura::Window> window( | 59 scoped_ptr<aura::Window> window( |
68 aura::test::CreateTestWindowWithId(0, default_container)); | 60 aura::test::CreateTestWindowWithId(0, NULL)); |
69 window->Show(); | 61 window->Show(); |
70 EXPECT_TRUE(window->layer()->visible()); | 62 EXPECT_TRUE(window->layer()->visible()); |
71 // Showing -- should be a no-op. | 63 // Showing -- should be a no-op. |
72 SetWindowVisibilityAnimationType( | 64 SetWindowVisibilityAnimationType( |
73 window.get(), | 65 window.get(), |
74 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_SHOW); | 66 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_SHOW); |
75 ash::internal::AnimateOnChildWindowVisibilityChanged( | 67 ash::internal::AnimateOnChildWindowVisibilityChanged( |
76 window.get(), true); | 68 window.get(), true); |
77 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 69 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
78 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 70 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
(...skipping 12 matching lines...) Expand all Loading... |
91 static_cast<ui::AnimationContainerElement*>( | 83 static_cast<ui::AnimationContainerElement*>( |
92 window->layer()->GetAnimator()); | 84 window->layer()->GetAnimator()); |
93 element->Step(base::TimeTicks::Now() + | 85 element->Step(base::TimeTicks::Now() + |
94 base::TimeDelta::FromSeconds(5)); | 86 base::TimeDelta::FromSeconds(5)); |
95 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | 87 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); |
96 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 88 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
97 EXPECT_FALSE(window->layer()->visible()); | 89 EXPECT_FALSE(window->layer()->visible()); |
98 } | 90 } |
99 | 91 |
100 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { | 92 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { |
101 aura::Window* default_container = | |
102 ash::Shell::GetContainer( | |
103 Shell::GetPrimaryRootWindow(), | |
104 internal::kShellWindowId_DefaultContainer); | |
105 scoped_ptr<aura::Window> window( | 93 scoped_ptr<aura::Window> window( |
106 aura::test::CreateTestWindowWithId(0, default_container)); | 94 aura::test::CreateTestWindowWithId(0, NULL)); |
107 window->Show(); | 95 window->Show(); |
108 EXPECT_TRUE(window->layer()->visible()); | 96 EXPECT_TRUE(window->layer()->visible()); |
109 | 97 |
110 // Hiding. | 98 // Hiding. |
111 SetWindowVisibilityAnimationType( | 99 SetWindowVisibilityAnimationType( |
112 window.get(), | 100 window.get(), |
113 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); | 101 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); |
114 ash::internal::AnimateOnChildWindowVisibilityChanged( | 102 ash::internal::AnimateOnChildWindowVisibilityChanged( |
115 window.get(), false); | 103 window.get(), false); |
116 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | 104 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); |
(...skipping 15 matching lines...) Expand all Loading... |
132 static_cast<ui::AnimationContainerElement*>( | 120 static_cast<ui::AnimationContainerElement*>( |
133 window->layer()->GetAnimator()); | 121 window->layer()->GetAnimator()); |
134 element->Step(base::TimeTicks::Now() + | 122 element->Step(base::TimeTicks::Now() + |
135 base::TimeDelta::FromSeconds(5)); | 123 base::TimeDelta::FromSeconds(5)); |
136 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); | 124 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); |
137 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); | 125 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); |
138 EXPECT_TRUE(window->layer()->visible()); | 126 EXPECT_TRUE(window->layer()->visible()); |
139 } | 127 } |
140 | 128 |
141 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { | 129 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { |
142 aura::Window* default_container = | |
143 ash::Shell::GetContainer( | |
144 Shell::GetPrimaryRootWindow(), | |
145 internal::kShellWindowId_DefaultContainer); | |
146 scoped_ptr<aura::Window> window( | 130 scoped_ptr<aura::Window> window( |
147 aura::test::CreateTestWindowWithId(0, default_container)); | 131 aura::test::CreateTestWindowWithId(0, NULL)); |
148 | 132 |
149 // Layer target visibility changes according to Show/Hide. | 133 // Layer target visibility changes according to Show/Hide. |
150 window->Show(); | 134 window->Show(); |
151 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 135 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
152 window->Hide(); | 136 window->Hide(); |
153 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 137 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
154 window->Show(); | 138 window->Show(); |
155 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 139 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
156 } | 140 } |
157 | 141 |
158 TEST_F(WindowAnimationsTest, CrossFadeToBounds) { | 142 TEST_F(WindowAnimationsTest, CrossFadeToBounds) { |
159 internal::SetDelayedOldLayerDeletionInCrossFadeForTest(true); | 143 internal::SetDelayedOldLayerDeletionInCrossFadeForTest(true); |
160 | 144 |
161 Window* default_container = | |
162 ash::Shell::GetContainer( | |
163 Shell::GetPrimaryRootWindow(), | |
164 internal::kShellWindowId_DefaultContainer); | |
165 scoped_ptr<Window> window( | 145 scoped_ptr<Window> window( |
166 aura::test::CreateTestWindowWithId(0, default_container)); | 146 aura::test::CreateTestWindowWithId(0, NULL)); |
167 window->SetBounds(gfx::Rect(5, 10, 320, 240)); | 147 window->SetBounds(gfx::Rect(5, 10, 320, 240)); |
168 window->Show(); | 148 window->Show(); |
169 | 149 |
170 Layer* old_layer = window->layer(); | 150 Layer* old_layer = window->layer(); |
171 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); | 151 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); |
172 | 152 |
173 // Cross fade to a larger size, as in a maximize animation. | 153 // Cross fade to a larger size, as in a maximize animation. |
174 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480)); | 154 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480)); |
175 // Window's layer has been replaced. | 155 // Window's layer has been replaced. |
176 EXPECT_NE(old_layer, window->layer()); | 156 EXPECT_NE(old_layer, window->layer()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // Medium changes take medium time. | 215 // Medium changes take medium time. |
236 gfx::Rect half_screen(10, 10, 500, 250); | 216 gfx::Rect half_screen(10, 10, 500, 250); |
237 EXPECT_EQ(kMinimum + kRange * 3 / 4, | 217 EXPECT_EQ(kMinimum + kRange * 3 / 4, |
238 GetCrossFadeDuration(half_screen, screen).InMilliseconds()); | 218 GetCrossFadeDuration(half_screen, screen).InMilliseconds()); |
239 EXPECT_EQ(kMinimum + kRange * 3 / 4, | 219 EXPECT_EQ(kMinimum + kRange * 3 / 4, |
240 GetCrossFadeDuration(screen, half_screen).InMilliseconds()); | 220 GetCrossFadeDuration(screen, half_screen).InMilliseconds()); |
241 } | 221 } |
242 | 222 |
243 } // namespace internal | 223 } // namespace internal |
244 } // namespace ash | 224 } // namespace ash |
OLD | NEW |