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 "ui/wm/core/window_animations.h" | 5 #include "ui/wm/core/window_animations.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "ui/aura/test/aura_test_base.h" | 9 #include "ui/aura/test/aura_test_base.h" |
10 #include "ui/aura/test/test_windows.h" | 10 #include "ui/aura/test/test_windows.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 public: | 48 public: |
49 WindowAnimationsTest() {} | 49 WindowAnimationsTest() {} |
50 | 50 |
51 void TearDown() override { AuraTestBase::TearDown(); } | 51 void TearDown() override { AuraTestBase::TearDown(); } |
52 | 52 |
53 private: | 53 private: |
54 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); | 54 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); |
55 }; | 55 }; |
56 | 56 |
57 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { | 57 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { |
58 scoped_ptr<aura::Window> window( | 58 std::unique_ptr<aura::Window> window( |
59 aura::test::CreateTestWindowWithId(0, NULL)); | 59 aura::test::CreateTestWindowWithId(0, NULL)); |
60 | 60 |
61 // Layer target visibility changes according to Show/Hide. | 61 // Layer target visibility changes according to Show/Hide. |
62 window->Show(); | 62 window->Show(); |
63 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 63 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
64 window->Hide(); | 64 window->Hide(); |
65 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 65 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
66 window->Show(); | 66 window->Show(); |
67 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 67 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
68 } | 68 } |
69 | 69 |
70 TEST_F(WindowAnimationsTest, LayerTargetVisibility_AnimateShow) { | 70 TEST_F(WindowAnimationsTest, LayerTargetVisibility_AnimateShow) { |
71 // Tests if opacity and transform are reset when only show animation is | 71 // Tests if opacity and transform are reset when only show animation is |
72 // enabled. See also LayerTargetVisibility_AnimateHide. | 72 // enabled. See also LayerTargetVisibility_AnimateHide. |
73 // Since the window is not visible after Hide() is called, opacity and | 73 // Since the window is not visible after Hide() is called, opacity and |
74 // transform shouldn't matter in case of ANIMATE_SHOW, but we reset them | 74 // transform shouldn't matter in case of ANIMATE_SHOW, but we reset them |
75 // to keep consistency. | 75 // to keep consistency. |
76 | 76 |
77 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL)); | 77 std::unique_ptr<aura::Window> window( |
| 78 aura::test::CreateTestWindowWithId(0, NULL)); |
78 SetWindowVisibilityAnimationTransition(window.get(), ANIMATE_SHOW); | 79 SetWindowVisibilityAnimationTransition(window.get(), ANIMATE_SHOW); |
79 | 80 |
80 // Layer target visibility and opacity change according to Show/Hide. | 81 // Layer target visibility and opacity change according to Show/Hide. |
81 window->Show(); | 82 window->Show(); |
82 AnimateOnChildWindowVisibilityChanged(window.get(), true); | 83 AnimateOnChildWindowVisibilityChanged(window.get(), true); |
83 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 84 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
84 EXPECT_EQ(1, window->layer()->opacity()); | 85 EXPECT_EQ(1, window->layer()->opacity()); |
85 | 86 |
86 window->Hide(); | 87 window->Hide(); |
87 AnimateOnChildWindowVisibilityChanged(window.get(), false); | 88 AnimateOnChildWindowVisibilityChanged(window.get(), false); |
88 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 89 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
89 EXPECT_EQ(0, window->layer()->opacity()); | 90 EXPECT_EQ(0, window->layer()->opacity()); |
90 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); | 91 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); |
91 | 92 |
92 window->Show(); | 93 window->Show(); |
93 AnimateOnChildWindowVisibilityChanged(window.get(), true); | 94 AnimateOnChildWindowVisibilityChanged(window.get(), true); |
94 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 95 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
95 EXPECT_EQ(1, window->layer()->opacity()); | 96 EXPECT_EQ(1, window->layer()->opacity()); |
96 } | 97 } |
97 | 98 |
98 TEST_F(WindowAnimationsTest, LayerTargetVisibility_AnimateHide) { | 99 TEST_F(WindowAnimationsTest, LayerTargetVisibility_AnimateHide) { |
99 // Tests if opacity and transform are reset when only hide animation is | 100 // Tests if opacity and transform are reset when only hide animation is |
100 // enabled. Hide animation changes opacity and transform in addition to | 101 // enabled. Hide animation changes opacity and transform in addition to |
101 // visibility, so we need to reset not only visibility but also opacity | 102 // visibility, so we need to reset not only visibility but also opacity |
102 // and transform to show the window. | 103 // and transform to show the window. |
103 | 104 |
104 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL)); | 105 std::unique_ptr<aura::Window> window( |
| 106 aura::test::CreateTestWindowWithId(0, NULL)); |
105 SetWindowVisibilityAnimationTransition(window.get(), ANIMATE_HIDE); | 107 SetWindowVisibilityAnimationTransition(window.get(), ANIMATE_HIDE); |
106 | 108 |
107 // Layer target visibility and opacity change according to Show/Hide. | 109 // Layer target visibility and opacity change according to Show/Hide. |
108 window->Show(); | 110 window->Show(); |
109 AnimateOnChildWindowVisibilityChanged(window.get(), true); | 111 AnimateOnChildWindowVisibilityChanged(window.get(), true); |
110 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 112 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
111 EXPECT_EQ(1, window->layer()->opacity()); | 113 EXPECT_EQ(1, window->layer()->opacity()); |
112 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); | 114 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); |
113 | 115 |
114 window->Hide(); | 116 window->Hide(); |
115 AnimateOnChildWindowVisibilityChanged(window.get(), false); | 117 AnimateOnChildWindowVisibilityChanged(window.get(), false); |
116 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 118 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
117 EXPECT_EQ(0, window->layer()->opacity()); | 119 EXPECT_EQ(0, window->layer()->opacity()); |
118 | 120 |
119 window->Show(); | 121 window->Show(); |
120 AnimateOnChildWindowVisibilityChanged(window.get(), true); | 122 AnimateOnChildWindowVisibilityChanged(window.get(), true); |
121 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 123 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
122 EXPECT_EQ(1, window->layer()->opacity()); | 124 EXPECT_EQ(1, window->layer()->opacity()); |
123 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); | 125 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); |
124 } | 126 } |
125 | 127 |
126 TEST_F(WindowAnimationsTest, HideAnimationDetachLayers) { | 128 TEST_F(WindowAnimationsTest, HideAnimationDetachLayers) { |
127 scoped_ptr<aura::Window> parent(aura::test::CreateTestWindowWithId(0, NULL)); | 129 std::unique_ptr<aura::Window> parent( |
| 130 aura::test::CreateTestWindowWithId(0, NULL)); |
128 | 131 |
129 scoped_ptr<aura::Window> other( | 132 std::unique_ptr<aura::Window> other( |
130 aura::test::CreateTestWindowWithId(1, parent.get())); | 133 aura::test::CreateTestWindowWithId(1, parent.get())); |
131 | 134 |
132 scoped_ptr<aura::Window> animating_window( | 135 std::unique_ptr<aura::Window> animating_window( |
133 aura::test::CreateTestWindowWithId(2, parent.get())); | 136 aura::test::CreateTestWindowWithId(2, parent.get())); |
134 SetWindowVisibilityAnimationTransition(animating_window.get(), ANIMATE_HIDE); | 137 SetWindowVisibilityAnimationTransition(animating_window.get(), ANIMATE_HIDE); |
135 | 138 |
136 EXPECT_EQ(0, GetWindowZPosition(other.get())); | 139 EXPECT_EQ(0, GetWindowZPosition(other.get())); |
137 EXPECT_EQ(1, GetWindowZPosition(animating_window.get())); | 140 EXPECT_EQ(1, GetWindowZPosition(animating_window.get())); |
138 EXPECT_EQ(0, GetLayerZPosition(other->layer())); | 141 EXPECT_EQ(0, GetLayerZPosition(other->layer())); |
139 EXPECT_EQ(1, GetLayerZPosition(animating_window->layer())); | 142 EXPECT_EQ(1, GetLayerZPosition(animating_window->layer())); |
140 | 143 |
141 { | 144 { |
142 ui::ScopedAnimationDurationScaleMode scale_mode( | 145 ui::ScopedAnimationDurationScaleMode scale_mode( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 std::find(parent->layer()->children().begin(), | 187 std::find(parent->layer()->children().begin(), |
185 parent->layer()->children().end(), | 188 parent->layer()->children().end(), |
186 animating_layer) == | 189 animating_layer) == |
187 parent->layer()->children().end()); | 190 parent->layer()->children().end()); |
188 } | 191 } |
189 } | 192 } |
190 | 193 |
191 TEST_F(WindowAnimationsTest, HideAnimationDetachLayersWithTransientChildren) { | 194 TEST_F(WindowAnimationsTest, HideAnimationDetachLayersWithTransientChildren) { |
192 TransientWindowStackingClient transient_stacking_client; | 195 TransientWindowStackingClient transient_stacking_client; |
193 | 196 |
194 scoped_ptr<aura::Window> parent(aura::test::CreateTestWindowWithId(0, NULL)); | 197 std::unique_ptr<aura::Window> parent( |
| 198 aura::test::CreateTestWindowWithId(0, NULL)); |
195 | 199 |
196 scoped_ptr<aura::Window> other( | 200 std::unique_ptr<aura::Window> other( |
197 aura::test::CreateTestWindowWithId(1, parent.get())); | 201 aura::test::CreateTestWindowWithId(1, parent.get())); |
198 | 202 |
199 scoped_ptr<aura::Window> animating_window( | 203 std::unique_ptr<aura::Window> animating_window( |
200 aura::test::CreateTestWindowWithId(2, parent.get())); | 204 aura::test::CreateTestWindowWithId(2, parent.get())); |
201 SetWindowVisibilityAnimationTransition(animating_window.get(), ANIMATE_HIDE); | 205 SetWindowVisibilityAnimationTransition(animating_window.get(), ANIMATE_HIDE); |
202 | 206 |
203 scoped_ptr<aura::Window> transient1( | 207 std::unique_ptr<aura::Window> transient1( |
204 aura::test::CreateTestWindowWithId(3, parent.get())); | 208 aura::test::CreateTestWindowWithId(3, parent.get())); |
205 scoped_ptr<aura::Window> transient2( | 209 std::unique_ptr<aura::Window> transient2( |
206 aura::test::CreateTestWindowWithId(4, parent.get())); | 210 aura::test::CreateTestWindowWithId(4, parent.get())); |
207 | 211 |
208 TransientWindowManager::Get(animating_window.get()); | 212 TransientWindowManager::Get(animating_window.get()); |
209 AddTransientChild(animating_window.get(), transient1.get()); | 213 AddTransientChild(animating_window.get(), transient1.get()); |
210 AddTransientChild(animating_window.get(), transient2.get()); | 214 AddTransientChild(animating_window.get(), transient2.get()); |
211 | 215 |
212 EXPECT_EQ(0, GetWindowZPosition(other.get())); | 216 EXPECT_EQ(0, GetWindowZPosition(other.get())); |
213 EXPECT_EQ(1, GetWindowZPosition(animating_window.get())); | 217 EXPECT_EQ(1, GetWindowZPosition(animating_window.get())); |
214 EXPECT_EQ(2, GetWindowZPosition(transient1.get())); | 218 EXPECT_EQ(2, GetWindowZPosition(transient1.get())); |
215 EXPECT_EQ(3, GetWindowZPosition(transient2.get())); | 219 EXPECT_EQ(3, GetWindowZPosition(transient2.get())); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 bool hide_completed() const { return hide_completed_; } | 269 bool hide_completed() const { return hide_completed_; } |
266 | 270 |
267 private: | 271 private: |
268 bool hide_completed_; | 272 bool hide_completed_; |
269 | 273 |
270 DISALLOW_COPY_AND_ASSIGN(NotifyHideCompletedAnimationHost); | 274 DISALLOW_COPY_AND_ASSIGN(NotifyHideCompletedAnimationHost); |
271 }; | 275 }; |
272 | 276 |
273 TEST_F(WindowAnimationsTest, NotifyHideCompleted) { | 277 TEST_F(WindowAnimationsTest, NotifyHideCompleted) { |
274 NotifyHideCompletedAnimationHost animation_host; | 278 NotifyHideCompletedAnimationHost animation_host; |
275 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL)); | 279 std::unique_ptr<aura::Window> window( |
| 280 aura::test::CreateTestWindowWithId(0, NULL)); |
276 aura::client::SetAnimationHost(window.get(), &animation_host); | 281 aura::client::SetAnimationHost(window.get(), &animation_host); |
277 wm::SetWindowVisibilityAnimationType( | 282 wm::SetWindowVisibilityAnimationType( |
278 window.get(), WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 283 window.get(), WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
279 AnimateOnChildWindowVisibilityChanged(window.get(), true); | 284 AnimateOnChildWindowVisibilityChanged(window.get(), true); |
280 EXPECT_TRUE(window->layer()->visible()); | 285 EXPECT_TRUE(window->layer()->visible()); |
281 | 286 |
282 EXPECT_FALSE(animation_host.hide_completed()); | 287 EXPECT_FALSE(animation_host.hide_completed()); |
283 AnimateOnChildWindowVisibilityChanged(window.get(), false); | 288 AnimateOnChildWindowVisibilityChanged(window.get(), false); |
284 EXPECT_TRUE(animation_host.hide_completed()); | 289 EXPECT_TRUE(animation_host.hide_completed()); |
285 } | 290 } |
286 | 291 |
287 // The rotation animation for hiding a window should not leak the animation | 292 // The rotation animation for hiding a window should not leak the animation |
288 // observer. | 293 // observer. |
289 TEST_F(WindowAnimationsTest, RotateHideNoLeak) { | 294 TEST_F(WindowAnimationsTest, RotateHideNoLeak) { |
290 ui::ScopedAnimationDurationScaleMode scale_mode( | 295 ui::ScopedAnimationDurationScaleMode scale_mode( |
291 ui::ScopedAnimationDurationScaleMode::FAST_DURATION); | 296 ui::ScopedAnimationDurationScaleMode::FAST_DURATION); |
292 | 297 |
293 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL)); | 298 std::unique_ptr<aura::Window> window( |
| 299 aura::test::CreateTestWindowWithId(0, NULL)); |
294 ui::Layer* animating_layer = window->layer(); | 300 ui::Layer* animating_layer = window->layer(); |
295 wm::SetWindowVisibilityAnimationType(window.get(), | 301 wm::SetWindowVisibilityAnimationType(window.get(), |
296 WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); | 302 WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); |
297 | 303 |
298 AnimateOnChildWindowVisibilityChanged(window.get(), true); | 304 AnimateOnChildWindowVisibilityChanged(window.get(), true); |
299 AnimateOnChildWindowVisibilityChanged(window.get(), false); | 305 AnimateOnChildWindowVisibilityChanged(window.get(), false); |
300 | 306 |
301 animating_layer->GetAnimator()->StopAnimating(); | 307 animating_layer->GetAnimator()->StopAnimating(); |
302 } | 308 } |
303 | 309 |
304 // The rotation animation for hiding a window should not crash when terminated | 310 // The rotation animation for hiding a window should not crash when terminated |
305 // by LayerAnimator::StopAnimating(). | 311 // by LayerAnimator::StopAnimating(). |
306 TEST_F(WindowAnimationsTest, RotateHideNoCrash) { | 312 TEST_F(WindowAnimationsTest, RotateHideNoCrash) { |
307 ui::ScopedAnimationDurationScaleMode scale_mode( | 313 ui::ScopedAnimationDurationScaleMode scale_mode( |
308 ui::ScopedAnimationDurationScaleMode::FAST_DURATION); | 314 ui::ScopedAnimationDurationScaleMode::FAST_DURATION); |
309 | 315 |
310 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL)); | 316 std::unique_ptr<aura::Window> window( |
| 317 aura::test::CreateTestWindowWithId(0, NULL)); |
311 ui::Layer* animating_layer = window->layer(); | 318 ui::Layer* animating_layer = window->layer(); |
312 wm::SetWindowVisibilityAnimationType(window.get(), | 319 wm::SetWindowVisibilityAnimationType(window.get(), |
313 WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); | 320 WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); |
314 AnimateOnChildWindowVisibilityChanged(window.get(), true); | 321 AnimateOnChildWindowVisibilityChanged(window.get(), true); |
315 window->layer()->GetAnimator()->Step(base::TimeTicks::Now() + | 322 window->layer()->GetAnimator()->Step(base::TimeTicks::Now() + |
316 base::TimeDelta::FromSeconds(5)); | 323 base::TimeDelta::FromSeconds(5)); |
317 AnimateOnChildWindowVisibilityChanged(window.get(), false); | 324 AnimateOnChildWindowVisibilityChanged(window.get(), false); |
318 animating_layer->GetAnimator()->StopAnimating(); | 325 animating_layer->GetAnimator()->StopAnimating(); |
319 } | 326 } |
320 | 327 |
321 } // namespace wm | 328 } // namespace wm |
OLD | NEW |