OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/rotator/screen_rotation_animation.h" | 5 #include "ash/rotator/screen_rotation_animation.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 void ScreenRotationAnimationTest::SetUp() { | 39 void ScreenRotationAnimationTest::SetUp() { |
40 AshTestBase::SetUp(); | 40 AshTestBase::SetUp(); |
41 non_zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 41 non_zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
42 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION)); | 42 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION)); |
43 } | 43 } |
44 | 44 |
45 TEST_F(ScreenRotationAnimationTest, LayerTransformGetsSetToTargetWhenAborted) { | 45 TEST_F(ScreenRotationAnimationTest, LayerTransformGetsSetToTargetWhenAborted) { |
46 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(9)); | 46 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(9)); |
47 ui::Layer* layer = window->layer(); | 47 ui::Layer* layer = window->layer(); |
48 | 48 |
49 std::unique_ptr<ScreenRotationAnimation> screen_rotation( | 49 std::unique_ptr<ScreenRotationAnimation> screen_rotation = |
50 new ScreenRotationAnimation( | 50 base::MakeUnique<ScreenRotationAnimation>( |
51 layer, 45 /* start_degrees */, 0 /* end_degrees */, | 51 layer, 45 /* start_degrees */, 0 /* end_degrees */, |
52 0.5f /* initial_opacity */, 1.0f /* target_opacity */, | 52 0.5f /* initial_opacity */, 1.0f /* target_opacity */, |
53 gfx::Point(10, 10) /* pivot */, | 53 gfx::Point(10, 10) /* pivot */, |
54 base::TimeDelta::FromSeconds(10) /* duration */, gfx::Tween::LINEAR)); | 54 base::TimeDelta::FromSeconds(10) /* duration */, gfx::Tween::LINEAR); |
55 | 55 |
56 ui::LayerAnimator* animator = layer->GetAnimator(); | 56 ui::LayerAnimator* animator = layer->GetAnimator(); |
57 animator->set_preemption_strategy( | 57 animator->set_preemption_strategy( |
58 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 58 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
59 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence( | 59 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
60 new ui::LayerAnimationSequence(screen_rotation.release())); | 60 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); |
61 animator->StartAnimation(animation_sequence.release()); | 61 animator->StartAnimation(animation_sequence.release()); |
62 | 62 |
63 const gfx::Transform identity_transform; | 63 const gfx::Transform identity_transform; |
64 | 64 |
65 ASSERT_EQ(identity_transform, layer->GetTargetTransform()); | 65 ASSERT_EQ(identity_transform, layer->GetTargetTransform()); |
66 ASSERT_NE(identity_transform, layer->transform()); | 66 ASSERT_NE(identity_transform, layer->transform()); |
67 | 67 |
68 layer->GetAnimator()->AbortAllAnimations(); | 68 layer->GetAnimator()->AbortAllAnimations(); |
69 | 69 |
70 EXPECT_EQ(identity_transform, layer->transform()); | 70 EXPECT_EQ(identity_transform, layer->transform()); |
71 } | 71 } |
72 | 72 |
73 // Tests that ScreenRotationAnimation::OnAbort() doesn't segfault when passed a | 73 // Tests that ScreenRotationAnimation::OnAbort() doesn't segfault when passed a |
74 // null delegate in response to its ui::Layer being destroyed: | 74 // null delegate in response to its ui::Layer being destroyed: |
75 // http://crbug.com/661313 | 75 // http://crbug.com/661313 |
76 TEST_F(ScreenRotationAnimationTest, DestroyLayerDuringAnimation) { | 76 TEST_F(ScreenRotationAnimationTest, DestroyLayerDuringAnimation) { |
77 // Create a ui::Layer directly rather than an aura::Window, as the latter | 77 // Create a ui::Layer directly rather than an aura::Window, as the latter |
78 // finishes all of its animation before destroying its layer. | 78 // finishes all of its animation before destroying its layer. |
79 std::unique_ptr<ui::Layer> layer = base::MakeUnique<ui::Layer>(); | 79 std::unique_ptr<ui::Layer> layer = base::MakeUnique<ui::Layer>(); |
80 | 80 |
81 ui::Layer* root_layer = CurrentContext()->layer(); | 81 ui::Layer* root_layer = CurrentContext()->layer(); |
82 layer->SetBounds(gfx::Rect(root_layer->bounds().size())); | 82 layer->SetBounds(gfx::Rect(root_layer->bounds().size())); |
83 root_layer->Add(layer.get()); | 83 root_layer->Add(layer.get()); |
84 | 84 |
85 std::unique_ptr<ScreenRotationAnimation> screen_rotation( | 85 std::unique_ptr<ScreenRotationAnimation> screen_rotation = |
86 new ScreenRotationAnimation(layer.get(), 45, 0, 1.0f, 1.0f, gfx::Point(), | 86 base::MakeUnique<ScreenRotationAnimation>( |
87 base::TimeDelta::FromSeconds(1), | 87 layer.get(), 45, 0, 1.0f, 1.0f, gfx::Point(), |
88 gfx::Tween::LINEAR)); | 88 base::TimeDelta::FromSeconds(1), gfx::Tween::LINEAR); |
89 ui::LayerAnimator* animator = layer->GetAnimator(); | 89 ui::LayerAnimator* animator = layer->GetAnimator(); |
90 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence( | 90 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = |
91 new ui::LayerAnimationSequence(screen_rotation.release())); | 91 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); |
92 animator->StartAnimation(animation_sequence.release()); | 92 animator->StartAnimation(animation_sequence.release()); |
93 | 93 |
94 // Explicitly destroy the layer to verify that the animation doesn't crash. | 94 // Explicitly destroy the layer to verify that the animation doesn't crash. |
95 layer.reset(); | 95 layer.reset(); |
96 } | 96 } |
97 | 97 |
98 } // namespace test | 98 } // namespace test |
99 } // namespace ash | 99 } // namespace ash |
OLD | NEW |