1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/display/display_configuration_controller.h"
7 #include "ash/display/display_configuration_controller_test_api.h"
8 #include "ash/rotator/screen_rotation_animator.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/wallpaper/wallpaper_controller_impl.h"
12 #include "base/command_line.h"
13 #include "ui/display/manager/display_manager.h"
18 display::Display::Rotation GetDisplayRotation(int64_t display_id) {
21 ->GetDisplayInfo(display_id)
25 class DisplayConfigurationControllerSmoothRotationTest : public AshTestBase {
27 DisplayConfigurationControllerSmoothRotationTest() = default;
29 DisplayConfigurationControllerSmoothRotationTest(
30 const DisplayConfigurationControllerSmoothRotationTest&) = delete;
31 DisplayConfigurationControllerSmoothRotationTest& operator=(
32 const DisplayConfigurationControllerSmoothRotationTest&) = delete;
34 ~DisplayConfigurationControllerSmoothRotationTest() override = default;
36 void SetUp() override {
38 // ScreenRotionAnimator skips animation if the wallpaper isn't ready.
39 Shell::Get()->wallpaper_controller()->set_bypass_decode_for_testing();
40 Shell::Get()->wallpaper_controller()->ShowDefaultWallpaperForTesting();
46 using DisplayConfigurationControllerTest = AshTestBase;
48 TEST_F(DisplayConfigurationControllerTest, OnlyHasOneAnimator) {
49 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
50 DisplayConfigurationControllerTestApi testapi(
51 Shell::Get()->display_configuration_controller());
52 ScreenRotationAnimator* old_screen_rotation_animator =
53 testapi.GetScreenRotationAnimatorForDisplay(display.id());
55 Shell::Get()->display_manager()->SetDisplayRotation(
56 display.id(), display::Display::ROTATE_0,
57 display::Display::RotationSource::USER);
58 old_screen_rotation_animator->Rotate(
59 display::Display::ROTATE_90, display::Display::RotationSource::USER,
60 DisplayConfigurationController::ANIMATION_SYNC);
62 ScreenRotationAnimator* new_screen_rotation_animator =
63 testapi.GetScreenRotationAnimatorForDisplay(display.id());
64 new_screen_rotation_animator->Rotate(
65 display::Display::ROTATE_180, display::Display::RotationSource::USER,
66 DisplayConfigurationController::ANIMATION_SYNC);
67 EXPECT_EQ(old_screen_rotation_animator, new_screen_rotation_animator);
70 TEST_F(DisplayConfigurationControllerTest, GetTargetRotationWithAnimation) {
71 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
72 DisplayConfigurationController* controller =
73 Shell::Get()->display_configuration_controller();
74 DisplayConfigurationControllerTestApi(controller).SetDisplayAnimator(true);
75 controller->SetDisplayRotation(
76 display.id(), display::Display::ROTATE_180,
77 display::Display::RotationSource::USER,
78 DisplayConfigurationController::ANIMATION_SYNC);
79 EXPECT_EQ(display::Display::ROTATE_180,
80 controller->GetTargetRotation(display.id()));
81 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display.id()));
84 TEST_F(DisplayConfigurationControllerSmoothRotationTest,
85 GetTargetRotationWithAnimation) {
86 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
87 DisplayConfigurationController* controller =
88 Shell::Get()->display_configuration_controller();
89 DisplayConfigurationControllerTestApi(controller).SetDisplayAnimator(true);
90 controller->SetDisplayRotation(
91 display.id(), display::Display::ROTATE_180,
92 display::Display::RotationSource::USER,
93 DisplayConfigurationController::ANIMATION_ASYNC);
94 EXPECT_EQ(display::Display::ROTATE_180,
95 controller->GetTargetRotation(display.id()));
96 EXPECT_EQ(display::Display::ROTATE_0, GetDisplayRotation(display.id()));