Chromium Code Reviews| 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/display/display.h" | |
| 11 #include "ui/display/screen.h" | |
| 12 | |
| 13 namespace ash { | |
| 14 namespace test { | |
| 15 | |
| 16 class ScreenRotationAnimatorTest : public AshTestBase { | |
| 17 public: | |
| 18 ScreenRotationAnimatorTest() {} | |
| 19 ~ScreenRotationAnimatorTest() override {} | |
| 20 | |
| 21 private: | |
| 22 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest); | |
| 23 }; | |
| 24 | |
| 25 class AnimationObserver | |
| 26 : public ScreenRotationAnimator::ScreenRotationAnimatorObserver { | |
| 27 public: | |
| 28 std::unique_ptr<ScreenRotationAnimator> animator_; | |
| 29 | |
| 30 void OnEndedOrAbortedAnimation( | |
| 31 base::WeakPtr<ScreenRotationAnimator> animator) override; | |
| 32 }; | |
| 33 | |
| 34 void AnimationObserver::OnEndedOrAbortedAnimation( | |
| 35 base::WeakPtr<ScreenRotationAnimator> animator) { | |
| 36 animator_.reset(); | |
| 37 } | |
| 38 | |
| 39 TEST_F(ScreenRotationAnimatorTest, DeletesAnimator) { | |
| 40 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480. | |
| 41 if (WmShell::Get()->IsRunningInMash()) | |
| 42 return; | |
| 43 | |
| 44 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); | |
| 45 std::unique_ptr<AnimationObserver> observer = | |
| 46 base::MakeUnique<AnimationObserver>(); | |
| 47 observer->animator_.reset(new ScreenRotationAnimator(display.id())); | |
| 48 observer->animator_->SetObserver(observer.get()); | |
| 49 | |
| 50 display.set_rotation(display::Display::ROTATE_0); | |
| 51 observer->animator_->Rotate( | |
| 52 display::Display::ROTATE_90, | |
| 53 display::Display::RotationSource::ROTATION_SOURCE_USER); | |
| 54 EXPECT_FALSE(observer->animator_); | |
| 55 } | |
| 56 | |
| 57 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) { | |
| 58 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480. | |
| 59 if (WmShell::Get()->IsRunningInMash()) | |
| 60 return; | |
| 61 | |
| 62 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); | |
| 63 std::unique_ptr<ScreenRotationAnimator> animator = | |
| 64 base::MakeUnique<ScreenRotationAnimator>(display.id()); | |
| 65 | |
| 66 display.set_rotation(display::Display::ROTATE_0); | |
| 67 animator->Rotate(display::Display::ROTATE_90, | |
| 68 display::Display::RotationSource::ROTATION_SOURCE_USER); | |
| 69 EXPECT_TRUE(animator->is_animating()); | |
| 70 } | |
| 71 | |
| 72 TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) { | |
| 73 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480. | |
| 74 if (WmShell::Get()->IsRunningInMash()) | |
| 75 return; | |
| 76 | |
| 77 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); | |
| 78 std::unique_ptr<ScreenRotationAnimator> animator = | |
| 79 base::MakeUnique<ScreenRotationAnimator>(display.id()); | |
| 80 | |
| 81 display.set_rotation(display::Display::ROTATE_0); | |
| 82 animator->Rotate(display::Display::ROTATE_0, | |
| 83 display::Display::RotationSource::ROTATION_SOURCE_USER); | |
| 84 EXPECT_FALSE(animator->is_animating()); | |
| 85 } | |
| 86 | |
| 87 // Simulates the situation that if there is a new rotation request during | |
| 88 // animation, it should stop the animation immediately and add the new rotation | |
| 89 // request to the |last_pending_request_|. | |
| 90 TEST_F(ScreenRotationAnimatorTest, AddsToPendingRequest) { | |
| 91 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480. | |
| 92 if (WmShell::Get()->IsRunningInMash()) | |
| 93 return; | |
| 94 | |
| 95 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); | |
| 96 std::unique_ptr<ScreenRotationAnimator> animator = | |
| 97 base::MakeUnique<ScreenRotationAnimator>(display.id()); | |
| 98 | |
| 99 EXPECT_FALSE(animator->last_pending_request()); | |
| 100 display.set_rotation(display::Display::ROTATE_0); | |
| 101 animator->Rotate(display::Display::ROTATE_90, | |
|
bruthig
2017/03/02 18:25:45
FYI AshTestBase via AshTestHelper::SetUp() uses th
wutao
2017/03/03 02:45:52
Done.
You are right. The trick here is that in the
| |
| 102 display::Display::RotationSource::ROTATION_SOURCE_USER); | |
| 103 animator->Rotate(display::Display::ROTATE_180, | |
| 104 display::Display::RotationSource::ROTATION_SOURCE_USER); | |
| 105 | |
| 106 EXPECT_TRUE(animator->last_pending_request()); | |
| 107 EXPECT_EQ(display::Display::ROTATE_180, | |
| 108 animator->last_pending_request()->new_rotation); | |
| 109 } | |
| 110 | |
| 111 } // namespace test | |
| 112 } // namespace ash | |
| OLD | NEW |