Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: ash/rotator/screen_rotation_animator_unittest.cc

Issue 2728803002: Handles users rotating screen too early (Closed)
Patch Set: Make ScreenRotationAnimator handle its own internal states. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "base/memory/ptr_util.h"
11 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
12 #include "ui/display/display.h"
13 #include "ui/display/manager/display_manager.h"
14 #include "ui/display/screen.h"
15
16 namespace ash {
17
18 namespace {
19
20 display::Display::Rotation GetDisplayRotation(int64_t display_id) {
21 return Shell::GetInstance()
22 ->display_manager()
23 ->GetDisplayInfo(display_id)
24 .GetActiveRotation();
25 }
26
27 void SetDisplayRotation(int64_t display_id,
28 display::Display::Rotation rotation) {
29 Shell::GetInstance()->display_manager()->SetDisplayRotation(
30 display_id, rotation,
31 display::Display::RotationSource::ROTATION_SOURCE_USER);
32 }
33
34 } // namespace
35
36 namespace test {
37
38 class AnimationObserver
39 : public ScreenRotationAnimator::ScreenRotationAnimatorObserver {
40 public:
41 std::unique_ptr<ScreenRotationAnimator> animator_;
42
43 void OnEndedOrAbortedScreenRotationAnimation(
44 ScreenRotationAnimator* animator) override;
45 };
46
47 void AnimationObserver::OnEndedOrAbortedScreenRotationAnimation(
48 ScreenRotationAnimator* animator) {
49 animator_.reset();
50 }
51
52 class ScreenRotationAnimatorTest : public AshTestBase {
bruthig 2017/03/10 22:34:08 Thanks again for adding this missing test fixture!
wutao 2017/03/14 16:46:38 Acknowledged.
53 public:
54 ScreenRotationAnimatorTest() {}
55 ~ScreenRotationAnimatorTest() override {}
56
57 // AshTestBase:
58 void SetUp() override;
59
60 int64_t display_id();
61
62 protected:
63 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_;
64
65 private:
66 display::Display display_;
67
68 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest);
69 };
70
71 void ScreenRotationAnimatorTest::SetUp() {
72 AshTestBase::SetUp();
73 non_zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
74 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
75
76 display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
77 SetDisplayRotation(display_.id(), display::Display::ROTATE_0);
78 }
79
80 int64_t ScreenRotationAnimatorTest::display_id() {
81 return display_.id();
82 }
83
84 TEST_F(ScreenRotationAnimatorTest, DeletesAnimator) {
bruthig 2017/03/10 22:34:08 Isn't this more verifying that the observer is cal
wutao 2017/03/14 16:46:38 You are right. Deleting animator is tested in the
85 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480.
86 if (WmShell::Get()->IsRunningInMash())
87 return;
88
89 non_zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
90 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
91
92 AnimationObserver observer;
93 observer.animator_.reset(new ScreenRotationAnimator(display_id()));
94 observer.animator_->SetScreenRotationAnimatorObserver(&observer);
95 observer.animator_->Rotate(
96 display::Display::ROTATE_90,
97 display::Display::RotationSource::ROTATION_SOURCE_USER);
98 EXPECT_FALSE(observer.animator_);
99 }
100
101 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) {
102 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480.
103 if (WmShell::Get()->IsRunningInMash())
104 return;
105
106 ScreenRotationAnimator animator(display_id());
107 animator.Rotate(display::Display::ROTATE_90,
108 display::Display::RotationSource::ROTATION_SOURCE_USER);
109 EXPECT_TRUE(animator.is_rotating_for_test());
110 }
111
112 TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) {
113 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480.
114 if (WmShell::Get()->IsRunningInMash())
115 return;
116
117 ScreenRotationAnimator animator(display_id());
118 animator.Rotate(display::Display::ROTATE_0,
119 display::Display::RotationSource::ROTATION_SOURCE_USER);
120 EXPECT_FALSE(animator.is_rotating_for_test());
121 }
122
123 // Simulates the situation that if there is a new rotation request during
124 // animation, it should stop the animation immediately and add the new rotation
125 // request to the |last_pending_request_|.
126 TEST_F(ScreenRotationAnimatorTest, AddsToPendingRequest) {
127 // TODO(wutao): needs displayManager::GetDisplayInfo http://crbug.com/622480.
128 if (WmShell::Get()->IsRunningInMash())
129 return;
130
131 ScreenRotationAnimator animator(display_id());
132 animator.Rotate(display::Display::ROTATE_90,
133 display::Display::RotationSource::ROTATION_SOURCE_USER);
134 animator.Rotate(display::Display::ROTATE_180,
135 display::Display::RotationSource::ROTATION_SOURCE_USER);
136 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id()));
137 }
138
bruthig 2017/03/10 22:34:08 I think it would be VERY valuable to have a test t
wutao 2017/03/14 16:46:38 I will add a new test with a ScreenRotationAnimato
139 } // namespace test
140 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698