| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/rotator/screen_rotation_animator.h" |
| 6 |
| 7 #include "ash/common/wm_shell.h" |
| 8 #include "ash/test/ash_test_base.h" |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 11 #include "ui/display/display.h" |
| 12 #include "ui/display/screen.h" |
| 13 |
| 14 namespace ash { |
| 15 namespace test { |
| 16 |
| 17 class AnimationObserver |
| 18 : public ScreenRotationAnimator::ScreenRotationAnimatorObserver { |
| 19 public: |
| 20 std::unique_ptr<ScreenRotationAnimator> animator_; |
| 21 |
| 22 void OnEndedOrAbortedAnimation(ScreenRotationAnimator* animator) override; |
| 23 }; |
| 24 |
| 25 void AnimationObserver::OnEndedOrAbortedAnimation( |
| 26 ScreenRotationAnimator* animator) { |
| 27 animator_.reset(); |
| 28 } |
| 29 |
| 30 class ScreenRotationAnimatorTest : public AshTestBase { |
| 31 public: |
| 32 ScreenRotationAnimatorTest() {} |
| 33 ~ScreenRotationAnimatorTest() override {} |
| 34 |
| 35 // AshTestBase: |
| 36 void SetUp() override; |
| 37 |
| 38 protected: |
| 39 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; |
| 40 |
| 41 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest); |
| 43 }; |
| 44 |
| 45 void ScreenRotationAnimatorTest::SetUp() { |
| 46 AshTestBase::SetUp(); |
| 47 non_zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| 48 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); |
| 49 } |
| 50 |
| 51 TEST_F(ScreenRotationAnimatorTest, DeletesAnimator) { |
| 52 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480. |
| 53 if (WmShell::Get()->IsRunningInMash()) |
| 54 return; |
| 55 |
| 56 non_zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| 57 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
| 58 |
| 59 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 60 AnimationObserver observer; |
| 61 observer.animator_.reset(new ScreenRotationAnimator(display.id())); |
| 62 observer.animator_->SetObserver(&observer); |
| 63 |
| 64 display.set_rotation(display::Display::ROTATE_0); |
| 65 observer.animator_->Rotate( |
| 66 display::Display::ROTATE_90, |
| 67 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 68 EXPECT_FALSE(observer.animator_); |
| 69 } |
| 70 |
| 71 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) { |
| 72 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480. |
| 73 if (WmShell::Get()->IsRunningInMash()) |
| 74 return; |
| 75 |
| 76 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 77 std::unique_ptr<ScreenRotationAnimator> animator = |
| 78 base::MakeUnique<ScreenRotationAnimator>(display.id()); |
| 79 |
| 80 display.set_rotation(display::Display::ROTATE_0); |
| 81 animator->Rotate(display::Display::ROTATE_90, |
| 82 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 83 EXPECT_TRUE(animator->is_rotating()); |
| 84 } |
| 85 |
| 86 TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) { |
| 87 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480. |
| 88 if (WmShell::Get()->IsRunningInMash()) |
| 89 return; |
| 90 |
| 91 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 92 std::unique_ptr<ScreenRotationAnimator> animator = |
| 93 base::MakeUnique<ScreenRotationAnimator>(display.id()); |
| 94 |
| 95 display.set_rotation(display::Display::ROTATE_0); |
| 96 animator->Rotate(display::Display::ROTATE_0, |
| 97 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 98 EXPECT_FALSE(animator->is_rotating()); |
| 99 } |
| 100 |
| 101 // Simulates the situation that if there is a new rotation request during |
| 102 // animation, it should stop the animation immediately and add the new rotation |
| 103 // request to the |last_pending_request_|. |
| 104 TEST_F(ScreenRotationAnimatorTest, AddsToPendingRequest) { |
| 105 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480. |
| 106 if (WmShell::Get()->IsRunningInMash()) |
| 107 return; |
| 108 |
| 109 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 110 std::unique_ptr<ScreenRotationAnimator> animator = |
| 111 base::MakeUnique<ScreenRotationAnimator>(display.id()); |
| 112 |
| 113 EXPECT_FALSE(animator->last_pending_request()); |
| 114 |
| 115 display.set_rotation(display::Display::ROTATE_0); |
| 116 animator->Rotate(display::Display::ROTATE_90, |
| 117 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 118 animator->Rotate(display::Display::ROTATE_180, |
| 119 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 120 EXPECT_TRUE(animator->last_pending_request()); |
| 121 EXPECT_EQ(display::Display::ROTATE_180, |
| 122 animator->last_pending_request()->new_rotation); |
| 123 } |
| 124 |
| 125 } // namespace test |
| 126 } // namespace ash |
| OLD | NEW |