| Index: ash/rotator/screen_rotation_animator_unittest.cc
|
| diff --git a/ash/rotator/screen_rotation_animator_unittest.cc b/ash/rotator/screen_rotation_animator_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a42387c3bd0695de08dbf4c6e6ad598941ebb5c7
|
| --- /dev/null
|
| +++ b/ash/rotator/screen_rotation_animator_unittest.cc
|
| @@ -0,0 +1,126 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ash/rotator/screen_rotation_animator.h"
|
| +
|
| +#include "ash/common/wm_shell.h"
|
| +#include "ash/test/ash_test_base.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "ui/compositor/scoped_animation_duration_scale_mode.h"
|
| +#include "ui/display/display.h"
|
| +#include "ui/display/screen.h"
|
| +
|
| +namespace ash {
|
| +namespace test {
|
| +
|
| +class AnimationObserver
|
| + : public ScreenRotationAnimator::ScreenRotationAnimatorObserver {
|
| + public:
|
| + std::unique_ptr<ScreenRotationAnimator> animator_;
|
| +
|
| + void OnEndedOrAbortedAnimation(ScreenRotationAnimator* animator) override;
|
| +};
|
| +
|
| +void AnimationObserver::OnEndedOrAbortedAnimation(
|
| + ScreenRotationAnimator* animator) {
|
| + animator_.reset();
|
| +}
|
| +
|
| +class ScreenRotationAnimatorTest : public AshTestBase {
|
| + public:
|
| + ScreenRotationAnimatorTest() {}
|
| + ~ScreenRotationAnimatorTest() override {}
|
| +
|
| + // AshTestBase:
|
| + void SetUp() override;
|
| +
|
| + protected:
|
| + std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest);
|
| +};
|
| +
|
| +void ScreenRotationAnimatorTest::SetUp() {
|
| + AshTestBase::SetUp();
|
| + non_zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
|
| + ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
|
| +}
|
| +
|
| +TEST_F(ScreenRotationAnimatorTest, DeletesAnimator) {
|
| + // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480.
|
| + if (WmShell::Get()->IsRunningInMash())
|
| + return;
|
| +
|
| + non_zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
|
| + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
|
| +
|
| + display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
|
| + AnimationObserver observer;
|
| + observer.animator_.reset(new ScreenRotationAnimator(display.id()));
|
| + observer.animator_->SetObserver(&observer);
|
| +
|
| + display.set_rotation(display::Display::ROTATE_0);
|
| + observer.animator_->Rotate(
|
| + display::Display::ROTATE_90,
|
| + display::Display::RotationSource::ROTATION_SOURCE_USER);
|
| + EXPECT_FALSE(observer.animator_);
|
| +}
|
| +
|
| +TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) {
|
| + // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480.
|
| + if (WmShell::Get()->IsRunningInMash())
|
| + return;
|
| +
|
| + display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
|
| + std::unique_ptr<ScreenRotationAnimator> animator =
|
| + base::MakeUnique<ScreenRotationAnimator>(display.id());
|
| +
|
| + display.set_rotation(display::Display::ROTATE_0);
|
| + animator->Rotate(display::Display::ROTATE_90,
|
| + display::Display::RotationSource::ROTATION_SOURCE_USER);
|
| + EXPECT_TRUE(animator->is_rotating());
|
| +}
|
| +
|
| +TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) {
|
| + // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480.
|
| + if (WmShell::Get()->IsRunningInMash())
|
| + return;
|
| +
|
| + display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
|
| + std::unique_ptr<ScreenRotationAnimator> animator =
|
| + base::MakeUnique<ScreenRotationAnimator>(display.id());
|
| +
|
| + display.set_rotation(display::Display::ROTATE_0);
|
| + animator->Rotate(display::Display::ROTATE_0,
|
| + display::Display::RotationSource::ROTATION_SOURCE_USER);
|
| + EXPECT_FALSE(animator->is_rotating());
|
| +}
|
| +
|
| +// Simulates the situation that if there is a new rotation request during
|
| +// animation, it should stop the animation immediately and add the new rotation
|
| +// request to the |last_pending_request_|.
|
| +TEST_F(ScreenRotationAnimatorTest, AddsToPendingRequest) {
|
| + // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480.
|
| + if (WmShell::Get()->IsRunningInMash())
|
| + return;
|
| +
|
| + display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
|
| + std::unique_ptr<ScreenRotationAnimator> animator =
|
| + base::MakeUnique<ScreenRotationAnimator>(display.id());
|
| +
|
| + EXPECT_FALSE(animator->last_pending_request());
|
| +
|
| + display.set_rotation(display::Display::ROTATE_0);
|
| + animator->Rotate(display::Display::ROTATE_90,
|
| + display::Display::RotationSource::ROTATION_SOURCE_USER);
|
| + animator->Rotate(display::Display::ROTATE_180,
|
| + display::Display::RotationSource::ROTATION_SOURCE_USER);
|
| + EXPECT_TRUE(animator->last_pending_request());
|
| + EXPECT_EQ(display::Display::ROTATE_180,
|
| + animator->last_pending_request()->new_rotation);
|
| +}
|
| +
|
| +} // namespace test
|
| +} // namespace ash
|
|
|