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

Side by Side Diff: ash/content/display/screen_orientation_controller_chromeos_unittest.cc

Issue 759063002: Move Screen Rotation from MaximizeModeController to ScreenOrientationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Helper code Created 5 years, 11 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/ash_switches.h" 5 #include "ash/ash_switches.h"
6 #include "ash/content/display/screen_orientation_delegate_chromeos.h" 6 #include "ash/content/display/screen_orientation_controller_chromeos.h"
7 #include "ash/display/display_info.h" 7 #include "ash/display/display_info.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/ash_test_helper.h" 11 #include "ash/test/ash_test_helper.h"
12 #include "ash/test/test_shell_delegate.h" 12 #include "ash/test/test_shell_delegate.h"
13 #include "ash/test/test_system_tray_delegate.h"
13 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 14 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "chromeos/accelerometer/accelerometer_reader.h"
16 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/test_browser_context.h" 20 #include "content/public/test/test_browser_context.h"
19 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" 21 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
20 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
23 #include "ui/message_center/message_center.h"
21 #include "ui/views/test/webview_test_helper.h" 24 #include "ui/views/test/webview_test_helper.h"
22 #include "ui/views/view.h" 25 #include "ui/views/view.h"
23 #include "ui/views/views_delegate.h" 26 #include "ui/views/views_delegate.h"
24 27
25 namespace ash { 28 namespace ash {
26 29
27 namespace { 30 namespace {
28 31
32 const float kDegreesToRadians = 3.1415926f / 180.0f;
33 const float kMeanGravity = 9.8066f;
34
35 void EnableMaximizeMode(bool enable) {
36 Shell::GetInstance()
37 ->maximize_mode_controller()
38 ->EnableMaximizeModeWindowManager(enable);
39 }
40
41 gfx::Display::Rotation GetInternalDisplayRotation() {
42 return Shell::GetInstance()
43 ->display_manager()
44 ->GetDisplayInfo(gfx::Display::InternalDisplayId())
45 .rotation();
46 }
47
29 gfx::Display::Rotation Rotation() { 48 gfx::Display::Rotation Rotation() {
30 return Shell::GetInstance() 49 return Shell::GetInstance()
31 ->display_manager() 50 ->display_manager()
32 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) 51 ->GetDisplayInfo(gfx::Display::InternalDisplayId())
33 .rotation(); 52 .rotation();
34 } 53 }
35 54
36 bool RotationLocked() { 55 bool RotationLocked() {
37 return Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); 56 return Shell::GetInstance()
57 ->screen_orientation_controller()
58 ->rotation_locked();
59 }
60
61 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) {
62 Shell::GetInstance()->display_manager()->SetDisplayRotation(
63 gfx::Display::InternalDisplayId(), rotation);
64 }
65
66 void SetRotationLocked(bool rotation_locked) {
67 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked(
68 rotation_locked);
69 }
70
71 void TriggerLidUpdate(const gfx::Vector3dF& lid) {
72 ui::AccelerometerUpdate update;
73 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z());
74 Shell::GetInstance()->screen_orientation_controller()->OnAccelerometerUpdated(
75 update);
38 } 76 }
39 77
40 } // namespace 78 } // namespace
41 79
42 class ScreenOrientationDelegateTest : public test::AshTestBase { 80 class ScreenOrientationControllerTest : public test::AshTestBase {
43 public: 81 public:
44 ScreenOrientationDelegateTest(); 82 ScreenOrientationControllerTest();
45 virtual ~ScreenOrientationDelegateTest(); 83 virtual ~ScreenOrientationControllerTest();
oshima 2015/01/09 21:23:55 nit: override
jonross 2015/01/12 14:46:49 Done.
46 84
47 ScreenOrientationDelegate* delegate() { return screen_orientation_delegate_; } 85 ScreenOrientationController* delegate() {
86 return screen_orientation_controller_;
87 }
48 88
49 // Creates and initializes and empty content::WebContents that is backed by a 89 // Creates and initializes and empty content::WebContents that is backed by a
50 // content::BrowserContext and that has an aura::Window. 90 // content::BrowserContext and that has an aura::Window.
51 content::WebContents* CreateWebContents(); 91 content::WebContents* CreateWebContents();
52 92
53 // Creates a secondary content::WebContents, with a separate 93 // Creates a secondary content::WebContents, with a separate
54 // content::BrowserContext. 94 // content::BrowserContext.
55 content::WebContents* CreateSecondaryWebContents(); 95 content::WebContents* CreateSecondaryWebContents();
56 96
57 // test::AshTestBase: 97 // test::AshTestBase:
58 void SetUp() override; 98 void SetUp() override;
59 99
60 private: 100 private:
61 ScreenOrientationDelegate* screen_orientation_delegate_; 101 ScreenOrientationController* screen_orientation_controller_;
62 102
63 // Optional content::BrowserContext used for two window tests. 103 // Optional content::BrowserContext used for two window tests.
64 scoped_ptr<content::BrowserContext> secondary_browser_context_; 104 scoped_ptr<content::BrowserContext> secondary_browser_context_;
65 105
66 // Setups underlying content layer so that content::WebContents can be 106 // Setups underlying content layer so that content::WebContents can be
67 // generated. 107 // generated.
68 scoped_ptr<views::WebViewTestHelper> webview_test_helper_; 108 scoped_ptr<views::WebViewTestHelper> webview_test_helper_;
69 109
70 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDelegateTest); 110 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationControllerTest);
71 }; 111 };
72 112
73 ScreenOrientationDelegateTest::ScreenOrientationDelegateTest() { 113 ScreenOrientationControllerTest::ScreenOrientationControllerTest() {
74 webview_test_helper_.reset(new views::WebViewTestHelper()); 114 webview_test_helper_.reset(new views::WebViewTestHelper());
75 } 115 }
76 116
77 ScreenOrientationDelegateTest::~ScreenOrientationDelegateTest() { 117 ScreenOrientationControllerTest::~ScreenOrientationControllerTest() {
78 } 118 }
79 119
80 content::WebContents* ScreenOrientationDelegateTest::CreateWebContents() { 120 content::WebContents* ScreenOrientationControllerTest::CreateWebContents() {
81 return views::ViewsDelegate::views_delegate->CreateWebContents( 121 return views::ViewsDelegate::views_delegate->CreateWebContents(
82 ash_test_helper()->test_shell_delegate()->GetActiveBrowserContext(), 122 ash_test_helper()->test_shell_delegate()->GetActiveBrowserContext(),
83 nullptr); 123 nullptr);
84 } 124 }
85 125
86 content::WebContents* 126 content::WebContents*
87 ScreenOrientationDelegateTest::CreateSecondaryWebContents() { 127 ScreenOrientationControllerTest::CreateSecondaryWebContents() {
88 secondary_browser_context_.reset(new content::TestBrowserContext()); 128 secondary_browser_context_.reset(new content::TestBrowserContext());
89 return views::ViewsDelegate::views_delegate->CreateWebContents( 129 return views::ViewsDelegate::views_delegate->CreateWebContents(
90 secondary_browser_context_.get(), nullptr); 130 secondary_browser_context_.get(), nullptr);
91 } 131 }
92 132
93 void ScreenOrientationDelegateTest::SetUp() { 133 void ScreenOrientationControllerTest::SetUp() {
94 base::CommandLine::ForCurrentProcess()->AppendSwitch( 134 base::CommandLine::ForCurrentProcess()->AppendSwitch(
95 switches::kAshUseFirstDisplayAsInternal); 135 switches::kAshUseFirstDisplayAsInternal);
96 base::CommandLine::ForCurrentProcess()->AppendSwitch( 136 base::CommandLine::ForCurrentProcess()->AppendSwitch(
97 switches::kAshEnableTouchViewTesting); 137 switches::kAshEnableTouchViewTesting);
98 test::AshTestBase::SetUp(); 138 test::AshTestBase::SetUp();
99 screen_orientation_delegate_ = 139 screen_orientation_controller_ =
100 Shell::GetInstance()->screen_orientation_delegate(); 140 Shell::GetInstance()->screen_orientation_controller();
101 } 141 }
102 142
103 // Tests that a content::WebContents can lock rotation. 143 // Tests that a content::WebContents can lock rotation.
104 TEST_F(ScreenOrientationDelegateTest, LockOrientation) { 144 TEST_F(ScreenOrientationControllerTest, LockOrientation) {
105 scoped_ptr<content::WebContents> content(CreateWebContents()); 145 scoped_ptr<content::WebContents> content(CreateWebContents());
106 ASSERT_NE(nullptr, content->GetNativeView()); 146 ASSERT_NE(nullptr, content->GetNativeView());
107 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation()); 147 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
108 ASSERT_FALSE(RotationLocked()); 148 ASSERT_FALSE(RotationLocked());
109 149
110 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 150 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
111 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); 151 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
112 EXPECT_TRUE(RotationLocked()); 152 EXPECT_TRUE(RotationLocked());
113 } 153 }
114 154
115 // Tests that a content::WebContents can unlock rotation. 155 // Tests that a content::WebContents can unlock rotation.
116 TEST_F(ScreenOrientationDelegateTest, Unlock) { 156 TEST_F(ScreenOrientationControllerTest, Unlock) {
117 scoped_ptr<content::WebContents> content(CreateWebContents()); 157 scoped_ptr<content::WebContents> content(CreateWebContents());
118 ASSERT_NE(nullptr, content->GetNativeView()); 158 ASSERT_NE(nullptr, content->GetNativeView());
119 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation()); 159 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
120 ASSERT_FALSE(RotationLocked()); 160 ASSERT_FALSE(RotationLocked());
121 161
122 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 162 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
123 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); 163 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
124 EXPECT_TRUE(RotationLocked()); 164 EXPECT_TRUE(RotationLocked());
125 165
126 delegate()->Unlock(content.get()); 166 delegate()->Unlock(content.get());
127 EXPECT_FALSE(RotationLocked()); 167 EXPECT_FALSE(RotationLocked());
128 } 168 }
129 169
130 // Tests that a content::WebContents is able to change the orientation of the 170 // Tests that a content::WebContents is able to change the orientation of the
131 // display after having locked rotation. 171 // display after having locked rotation.
132 TEST_F(ScreenOrientationDelegateTest, OrientationChanges) { 172 TEST_F(ScreenOrientationControllerTest, OrientationChanges) {
133 scoped_ptr<content::WebContents> content(CreateWebContents()); 173 scoped_ptr<content::WebContents> content(CreateWebContents());
134 ASSERT_NE(nullptr, content->GetNativeView()); 174 ASSERT_NE(nullptr, content->GetNativeView());
135 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation()); 175 ASSERT_EQ(gfx::Display::ROTATE_0, Rotation());
136 ASSERT_FALSE(RotationLocked()); 176 ASSERT_FALSE(RotationLocked());
137 177
138 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); 178 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait);
139 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation()); 179 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
140 EXPECT_TRUE(RotationLocked()); 180 EXPECT_TRUE(RotationLocked());
141 181
142 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 182 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
143 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); 183 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
144 } 184 }
145 185
146 // Tests that a user initiated rotation lock cannot be unlocked by a 186 // Tests that a user initiated rotation lock cannot be unlocked by a
147 // content::WebContents. 187 // content::WebContents.
148 TEST_F(ScreenOrientationDelegateTest, UserLockRejectsUnlock) { 188 TEST_F(ScreenOrientationControllerTest, UserLockRejectsUnlock) {
149 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(true); 189 delegate()->SetRotationLocked(true);
150 190
151 scoped_ptr<content::WebContents> content(CreateWebContents()); 191 scoped_ptr<content::WebContents> content(CreateWebContents());
152 delegate()->Unlock(content.get()); 192 delegate()->Unlock(content.get());
153 EXPECT_TRUE(RotationLocked()); 193 EXPECT_TRUE(RotationLocked());
154 } 194 }
155 195
156 // Tests that orientation can only be set by the first content::WebContents that 196 // Tests that orientation can only be set by the first content::WebContents that
157 // has set a rotation lock. 197 // has set a rotation lock.
158 TEST_F(ScreenOrientationDelegateTest, SecondContentCannotChangeOrientation) { 198 TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) {
159 scoped_ptr<content::WebContents> content1(CreateWebContents()); 199 scoped_ptr<content::WebContents> content1(CreateWebContents());
160 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents()); 200 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
161 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); 201 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
162 202
163 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); 203 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
164 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); 204 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
165 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); 205 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
166 } 206 }
167 207
168 // Tests that only the content::WebContents that set a rotation lock can perform 208 // Tests that only the content::WebContents that set a rotation lock can perform
169 // an unlock. 209 // an unlock.
170 TEST_F(ScreenOrientationDelegateTest, SecondContentCannotUnlock) { 210 TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) {
171 scoped_ptr<content::WebContents> content1(CreateWebContents()); 211 scoped_ptr<content::WebContents> content1(CreateWebContents());
172 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents()); 212 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
173 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); 213 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
174 214
175 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); 215 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
176 delegate()->Unlock(content2.get()); 216 delegate()->Unlock(content2.get());
177 EXPECT_TRUE(RotationLocked()); 217 EXPECT_TRUE(RotationLocked());
178 } 218 }
179 219
180 // Tests that alternate content::WebContents can set a rotation lock after a 220 // Tests that alternate content::WebContents can set a rotation lock after a
181 // preexisting lock has been released. 221 // preexisting lock has been released.
182 TEST_F(ScreenOrientationDelegateTest, AfterUnlockSecondContentCanLock) { 222 TEST_F(ScreenOrientationControllerTest, AfterUnlockSecondContentCanLock) {
183 scoped_ptr<content::WebContents> content1(CreateWebContents()); 223 scoped_ptr<content::WebContents> content1(CreateWebContents());
184 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents()); 224 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
185 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); 225 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
186 226
187 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); 227 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
188 delegate()->Unlock(content1.get()); 228 delegate()->Unlock(content1.get());
189 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); 229 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
190 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation()); 230 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
191 EXPECT_TRUE(RotationLocked()); 231 EXPECT_TRUE(RotationLocked());
192 } 232 }
193 233
234 // Tests that accelerometer readings in each of the screen angles will trigger a
235 // rotation of the internal display.
236 TEST_F(ScreenOrientationControllerTest, DisplayRotation) {
237 EnableMaximizeMode(true);
238 // Now test rotating in all directions.
239 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
240 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
241 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
242 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
243 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
244 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
245 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
246 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
247 }
248
249 // Tests that low angles are ignored by the accelerometer (i.e. when the device
250 // is almost laying flat).
251 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) {
252 EnableMaximizeMode(true);
253 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity));
254 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
255 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity));
256 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
257 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity));
258 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
259 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity));
260 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
261 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity));
262 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
263 }
264
265 // Tests that the display will stick to the current orientation beyond the
266 // halfway point, preventing frequent updates back and forth.
267 TEST_F(ScreenOrientationControllerTest, RotationSticky) {
268 EnableMaximizeMode(true);
269 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f);
270 TriggerLidUpdate(gravity);
271 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
272
273 // Turn past half-way point to next direction and rotation should remain
274 // the same.
275 float degrees = 50.0;
276 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
277 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
278 TriggerLidUpdate(gravity);
279 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
280
281 // Turn more and the screen should rotate.
282 degrees = 70.0;
283 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
284 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
285 TriggerLidUpdate(gravity);
286 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
287
288 // Turn back just beyond the half-way point and the new rotation should
289 // still be in effect.
290 degrees = 40.0;
291 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
292 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
293 TriggerLidUpdate(gravity);
294 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
295 }
296
297 // Tests that the display will stick to its current orientation when the
298 // rotation lock has been set.
299 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) {
300 EnableMaximizeMode(true);
301 SetRotationLocked(true);
302
303 // Turn past the threshold for rotation.
304 float degrees = 90.0;
305 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity,
306 -cos(degrees * kDegreesToRadians) * kMeanGravity,
307 0.0f);
308 TriggerLidUpdate(gravity);
309 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
310
311 SetRotationLocked(false);
312 TriggerLidUpdate(gravity);
313 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
314 }
315
316 // The TrayDisplay class that is responsible for adding/updating MessageCenter
317 // notifications is only added to the SystemTray on ChromeOS.
318 // Tests that the screen rotation notifications are suppressed when
319 // triggered by the accelerometer.
320 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) {
321 EnableMaximizeMode(true);
322 test::TestSystemTrayDelegate* tray_delegate =
323 static_cast<test::TestSystemTrayDelegate*>(
324 Shell::GetInstance()->system_tray_delegate());
325 tray_delegate->set_should_show_display_notification(true);
326
327 message_center::MessageCenter* message_center =
328 message_center::MessageCenter::Get();
329
330 EXPECT_EQ(0u, message_center->NotificationCount());
331 EXPECT_FALSE(message_center->HasPopupNotifications());
332
333 // Make sure notifications are still displayed when
334 // adjusting the screen rotation directly when in maximize mode
335 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
336 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
337 SetRotationLocked(false);
338 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
339 EXPECT_EQ(1u, message_center->NotificationCount());
340 EXPECT_TRUE(message_center->HasPopupNotifications());
341
342 // Clear all notifications
343 message_center->RemoveAllNotifications(false);
344 EXPECT_EQ(0u, message_center->NotificationCount());
345 EXPECT_FALSE(message_center->HasPopupNotifications());
346
347 // Make sure notifications are blocked when adjusting the screen rotation
348 // via the accelerometer while in maximize mode
349 // Rotate the screen 90 degrees
350 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
351 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
352 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
353 EXPECT_EQ(0u, message_center->NotificationCount());
354 EXPECT_FALSE(message_center->HasPopupNotifications());
355
356 // Make sure notifications are still displayed when
357 // adjusting the screen rotation directly when not in maximize mode
358 EnableMaximizeMode(false);
359 // Reset the screen rotation.
360 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
361 // Clear all notifications
362 message_center->RemoveAllNotifications(false);
363 ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
364 ASSERT_EQ(0u, message_center->NotificationCount());
365 ASSERT_FALSE(message_center->HasPopupNotifications());
366 SetInternalDisplayRotation(gfx::Display::ROTATE_180);
367 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
368 EXPECT_EQ(1u, message_center->NotificationCount());
369 EXPECT_TRUE(message_center->HasPopupNotifications());
370 }
371
372 // Tests that if a user has set a display rotation that it is restored upon
373 // exiting maximize mode.
374 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) {
375 SetInternalDisplayRotation(gfx::Display::ROTATE_90);
376 EnableMaximizeMode(true);
377
378 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
379 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
380
381 EnableMaximizeMode(false);
382 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
383 }
384
385 // Tests that if a user sets a display rotation that accelerometer rotation
386 // becomes locked.
387 TEST_F(ScreenOrientationControllerTest,
388 NonAccelerometerRotationChangesLockRotation) {
389 EnableMaximizeMode(true);
390 ASSERT_FALSE(RotationLocked());
391 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
392 EXPECT_TRUE(RotationLocked());
393 }
394
395 // Tests that if a user changes the display rotation, while rotation is locked,
396 // that the updates are recorded. Upon exiting maximize mode the latest user
397 // rotation should be applied.
398 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) {
399 EnableMaximizeMode(true);
400 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
401 // User sets rotation to the same rotation that the display was at when
402 // maximize mode was activated.
403 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
404 EnableMaximizeMode(false);
405 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
406 }
407
194 } // namespace ash 408 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698