OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/overview/cleanup_animation_observer.h" | 5 #include "ash/wm/overview/cleanup_animation_observer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/wm/overview/window_selector_delegate.h" | 10 #include "ash/wm/overview/window_selector_delegate.h" |
11 #include "ash/wm_window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/compositor/layer_animation_observer.h" | 12 #include "ui/compositor/layer_animation_observer.h" |
13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
14 #include "ui/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/compositor/scoped_layer_animation_settings.h" |
15 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
17 #include "ui/views/widget/widget_observer.h" | 17 #include "ui/views/widget/widget_observer.h" |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 namespace { | 20 namespace { |
21 | 21 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 delegate.AddDelayedAnimationObserver(std::move(observer)); | 117 delegate.AddDelayedAnimationObserver(std::move(observer)); |
118 } | 118 } |
119 | 119 |
120 // Tests that completing animation deletes the animation observer and the | 120 // Tests that completing animation deletes the animation observer and the |
121 // test widget and that deleting the WindowSelectorDelegate instance which | 121 // test widget and that deleting the WindowSelectorDelegate instance which |
122 // owns the observer does not crash. | 122 // owns the observer does not crash. |
123 TEST_F(CleanupAnimationObserverTest, CreateAnimateComplete) { | 123 TEST_F(CleanupAnimationObserverTest, CreateAnimateComplete) { |
124 TestWindowSelectorDelegate delegate; | 124 TestWindowSelectorDelegate delegate; |
125 std::unique_ptr<views::Widget> widget( | 125 std::unique_ptr<views::Widget> widget( |
126 CreateWindowWidget(gfx::Rect(0, 0, 40, 40))); | 126 CreateWindowWidget(gfx::Rect(0, 0, 40, 40))); |
127 WmWindow* widget_window = WmWindow::Get(widget->GetNativeWindow()); | 127 aura::Window* widget_window = widget->GetNativeWindow(); |
128 { | 128 { |
129 ui::ScopedLayerAnimationSettings animation_settings( | 129 ui::ScopedLayerAnimationSettings animation_settings( |
130 widget_window->GetLayer()->GetAnimator()); | 130 widget_window->layer()->GetAnimator()); |
131 animation_settings.SetTransitionDuration( | 131 animation_settings.SetTransitionDuration( |
132 base::TimeDelta::FromMilliseconds(1000)); | 132 base::TimeDelta::FromMilliseconds(1000)); |
133 animation_settings.SetPreemptionStrategy( | 133 animation_settings.SetPreemptionStrategy( |
134 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 134 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
135 | 135 |
136 std::unique_ptr<CleanupAnimationObserver> observer( | 136 std::unique_ptr<CleanupAnimationObserver> observer( |
137 new CleanupAnimationObserver(std::move(widget))); | 137 new CleanupAnimationObserver(std::move(widget))); |
138 animation_settings.AddObserver(observer.get()); | 138 animation_settings.AddObserver(observer.get()); |
139 delegate.AddDelayedAnimationObserver(std::move(observer)); | 139 delegate.AddDelayedAnimationObserver(std::move(observer)); |
140 | 140 |
141 widget_window->SetBounds(gfx::Rect(50, 50, 60, 60)); | 141 widget_window->SetBounds(gfx::Rect(50, 50, 60, 60)); |
142 } | 142 } |
143 // The widget should be destroyed when |animation_settings| gets out of scope | 143 // The widget should be destroyed when |animation_settings| gets out of scope |
144 // which in absence of NON_ZERO_DURATION animation duration mode completes | 144 // which in absence of NON_ZERO_DURATION animation duration mode completes |
145 // the animation and calls OnImplicitAnimationsCompleted() on the cleanup | 145 // the animation and calls OnImplicitAnimationsCompleted() on the cleanup |
146 // observer and auto-deletes the owned widget. | 146 // observer and auto-deletes the owned widget. |
147 EXPECT_TRUE(widget_destroyed()); | 147 EXPECT_TRUE(widget_destroyed()); |
148 // TestWindowSelectorDelegate going out of scope should not crash. | 148 // TestWindowSelectorDelegate going out of scope should not crash. |
149 } | 149 } |
150 | 150 |
151 // Tests that starting an animation and exiting doesn't crash. If not for | 151 // Tests that starting an animation and exiting doesn't crash. If not for |
152 // TestWindowSelectorDelegate calling Shutdown() on a CleanupAnimationObserver | 152 // TestWindowSelectorDelegate calling Shutdown() on a CleanupAnimationObserver |
153 // instance in destructor, this test would have crashed. | 153 // instance in destructor, this test would have crashed. |
154 TEST_F(CleanupAnimationObserverTest, CreateAnimateShutdown) { | 154 TEST_F(CleanupAnimationObserverTest, CreateAnimateShutdown) { |
155 TestWindowSelectorDelegate delegate; | 155 TestWindowSelectorDelegate delegate; |
156 std::unique_ptr<views::Widget> widget( | 156 std::unique_ptr<views::Widget> widget( |
157 CreateWindowWidget(gfx::Rect(0, 0, 40, 40))); | 157 CreateWindowWidget(gfx::Rect(0, 0, 40, 40))); |
158 WmWindow* widget_window = WmWindow::Get(widget->GetNativeWindow()); | 158 aura::Window* widget_window = widget->GetNativeWindow(); |
159 { | 159 { |
160 // Normal animations for tests have ZERO_DURATION, make sure we are actually | 160 // Normal animations for tests have ZERO_DURATION, make sure we are actually |
161 // animating the movement. | 161 // animating the movement. |
162 ui::ScopedAnimationDurationScaleMode animation_scale_mode( | 162 ui::ScopedAnimationDurationScaleMode animation_scale_mode( |
163 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 163 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
164 ui::ScopedLayerAnimationSettings animation_settings( | 164 ui::ScopedLayerAnimationSettings animation_settings( |
165 widget_window->GetLayer()->GetAnimator()); | 165 widget_window->layer()->GetAnimator()); |
166 animation_settings.SetTransitionDuration( | 166 animation_settings.SetTransitionDuration( |
167 base::TimeDelta::FromMilliseconds(1000)); | 167 base::TimeDelta::FromMilliseconds(1000)); |
168 animation_settings.SetPreemptionStrategy( | 168 animation_settings.SetPreemptionStrategy( |
169 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 169 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
170 | 170 |
171 std::unique_ptr<CleanupAnimationObserver> observer( | 171 std::unique_ptr<CleanupAnimationObserver> observer( |
172 new CleanupAnimationObserver(std::move(widget))); | 172 new CleanupAnimationObserver(std::move(widget))); |
173 animation_settings.AddObserver(observer.get()); | 173 animation_settings.AddObserver(observer.get()); |
174 delegate.AddDelayedAnimationObserver(std::move(observer)); | 174 delegate.AddDelayedAnimationObserver(std::move(observer)); |
175 | 175 |
176 widget_window->SetBounds(gfx::Rect(50, 50, 60, 60)); | 176 widget_window->SetBounds(gfx::Rect(50, 50, 60, 60)); |
177 } | 177 } |
178 // The widget still exists. | 178 // The widget still exists. |
179 EXPECT_FALSE(widget_destroyed()); | 179 EXPECT_FALSE(widget_destroyed()); |
180 // The test widget is auto-deleted when |delegate| that owns it goes out of | 180 // The test widget is auto-deleted when |delegate| that owns it goes out of |
181 // scope. The animation is still active when this happens which should not | 181 // scope. The animation is still active when this happens which should not |
182 // crash. | 182 // crash. |
183 } | 183 } |
184 | 184 |
185 } // namespace ash | 185 } // namespace ash |
OLD | NEW |