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