| 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/common/wm/overview/cleanup_animation_observer.h" | 5 #include "ash/common/wm/overview/cleanup_animation_observer.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/common/wm/overview/window_selector_delegate.h" | 9 #include "ash/common/wm/overview/window_selector_delegate.h" |
| 10 #include "ash/common/wm_lookup.h" | |
| 11 #include "ash/common/wm_window.h" | 10 #include "ash/common/wm_window.h" |
| 12 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 13 #include "ui/compositor/layer_animation_observer.h" | 12 #include "ui/compositor/layer_animation_observer.h" |
| 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 15 #include "ui/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 18 #include "ui/views/widget/widget_observer.h" | 17 #include "ui/views/widget/widget_observer.h" |
| 19 | 18 |
| 20 namespace ash { | 19 namespace ash { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 delegate.AddDelayedAnimationObserver(std::move(observer)); | 117 delegate.AddDelayedAnimationObserver(std::move(observer)); |
| 119 } | 118 } |
| 120 | 119 |
| 121 // Tests that completing animation deletes the animation observer and the | 120 // Tests that completing animation deletes the animation observer and the |
| 122 // test widget and that deleting the WindowSelectorDelegate instance which | 121 // test widget and that deleting the WindowSelectorDelegate instance which |
| 123 // owns the observer does not crash. | 122 // owns the observer does not crash. |
| 124 TEST_F(CleanupAnimationObserverTest, CreateAnimateComplete) { | 123 TEST_F(CleanupAnimationObserverTest, CreateAnimateComplete) { |
| 125 TestWindowSelectorDelegate delegate; | 124 TestWindowSelectorDelegate delegate; |
| 126 std::unique_ptr<views::Widget> widget( | 125 std::unique_ptr<views::Widget> widget( |
| 127 CreateWindowWidget(gfx::Rect(0, 0, 40, 40))); | 126 CreateWindowWidget(gfx::Rect(0, 0, 40, 40))); |
| 128 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get()); | 127 WmWindow* widget_window = WmWindow::Get(widget->GetNativeWindow()); |
| 129 { | 128 { |
| 130 ui::ScopedLayerAnimationSettings animation_settings( | 129 ui::ScopedLayerAnimationSettings animation_settings( |
| 131 widget_window->GetLayer()->GetAnimator()); | 130 widget_window->GetLayer()->GetAnimator()); |
| 132 animation_settings.SetTransitionDuration( | 131 animation_settings.SetTransitionDuration( |
| 133 base::TimeDelta::FromMilliseconds(1000)); | 132 base::TimeDelta::FromMilliseconds(1000)); |
| 134 animation_settings.SetPreemptionStrategy( | 133 animation_settings.SetPreemptionStrategy( |
| 135 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 134 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 136 | 135 |
| 137 std::unique_ptr<CleanupAnimationObserver> observer( | 136 std::unique_ptr<CleanupAnimationObserver> observer( |
| 138 new CleanupAnimationObserver(std::move(widget))); | 137 new CleanupAnimationObserver(std::move(widget))); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 149 // TestWindowSelectorDelegate going out of scope should not crash. | 148 // TestWindowSelectorDelegate going out of scope should not crash. |
| 150 } | 149 } |
| 151 | 150 |
| 152 // 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 |
| 153 // TestWindowSelectorDelegate calling Shutdown() on a CleanupAnimationObserver | 152 // TestWindowSelectorDelegate calling Shutdown() on a CleanupAnimationObserver |
| 154 // instance in destructor, this test would have crashed. | 153 // instance in destructor, this test would have crashed. |
| 155 TEST_F(CleanupAnimationObserverTest, CreateAnimateShutdown) { | 154 TEST_F(CleanupAnimationObserverTest, CreateAnimateShutdown) { |
| 156 TestWindowSelectorDelegate delegate; | 155 TestWindowSelectorDelegate delegate; |
| 157 std::unique_ptr<views::Widget> widget( | 156 std::unique_ptr<views::Widget> widget( |
| 158 CreateWindowWidget(gfx::Rect(0, 0, 40, 40))); | 157 CreateWindowWidget(gfx::Rect(0, 0, 40, 40))); |
| 159 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get()); | 158 WmWindow* widget_window = WmWindow::Get(widget->GetNativeWindow()); |
| 160 { | 159 { |
| 161 // 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 |
| 162 // animating the movement. | 161 // animating the movement. |
| 163 ui::ScopedAnimationDurationScaleMode animation_scale_mode( | 162 ui::ScopedAnimationDurationScaleMode animation_scale_mode( |
| 164 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 163 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 165 ui::ScopedLayerAnimationSettings animation_settings( | 164 ui::ScopedLayerAnimationSettings animation_settings( |
| 166 widget_window->GetLayer()->GetAnimator()); | 165 widget_window->GetLayer()->GetAnimator()); |
| 167 animation_settings.SetTransitionDuration( | 166 animation_settings.SetTransitionDuration( |
| 168 base::TimeDelta::FromMilliseconds(1000)); | 167 base::TimeDelta::FromMilliseconds(1000)); |
| 169 animation_settings.SetPreemptionStrategy( | 168 animation_settings.SetPreemptionStrategy( |
| 170 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 169 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 171 | 170 |
| 172 std::unique_ptr<CleanupAnimationObserver> observer( | 171 std::unique_ptr<CleanupAnimationObserver> observer( |
| 173 new CleanupAnimationObserver(std::move(widget))); | 172 new CleanupAnimationObserver(std::move(widget))); |
| 174 animation_settings.AddObserver(observer.get()); | 173 animation_settings.AddObserver(observer.get()); |
| 175 delegate.AddDelayedAnimationObserver(std::move(observer)); | 174 delegate.AddDelayedAnimationObserver(std::move(observer)); |
| 176 | 175 |
| 177 widget_window->SetBounds(gfx::Rect(50, 50, 60, 60)); | 176 widget_window->SetBounds(gfx::Rect(50, 50, 60, 60)); |
| 178 } | 177 } |
| 179 // The widget still exists. | 178 // The widget still exists. |
| 180 EXPECT_FALSE(widget_destroyed()); | 179 EXPECT_FALSE(widget_destroyed()); |
| 181 // 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 |
| 182 // 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 |
| 183 // crash. | 182 // crash. |
| 184 } | 183 } |
| 185 | 184 |
| 186 } // namespace ash | 185 } // namespace ash |
| OLD | NEW |