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

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

Issue 1924703002: Rename gfx::Display/Screen to display::Display/Screen in ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/display/screen_orientation_controller_chromeos.h" 5 #include "ash/display/screen_orientation_controller_chromeos.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/content/shell_content_state.h" 11 #include "ash/content/shell_content_state.h"
12 #include "ash/display/display_info.h" 12 #include "ash/display/display_info.h"
13 #include "ash/display/display_manager.h" 13 #include "ash/display/display_manager.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/ash_test_helper.h" 16 #include "ash/test/ash_test_helper.h"
17 #include "ash/test/content/test_shell_content_state.h" 17 #include "ash/test/content/test_shell_content_state.h"
18 #include "ash/test/display_manager_test_api.h" 18 #include "ash/test/display_manager_test_api.h"
19 #include "ash/test/test_shell_delegate.h" 19 #include "ash/test/test_shell_delegate.h"
20 #include "ash/test/test_system_tray_delegate.h" 20 #include "ash/test/test_system_tray_delegate.h"
21 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 21 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
22 #include "base/command_line.h" 22 #include "base/command_line.h"
23 #include "chromeos/accelerometer/accelerometer_reader.h" 23 #include "chromeos/accelerometer/accelerometer_reader.h"
24 #include "chromeos/accelerometer/accelerometer_types.h" 24 #include "chromeos/accelerometer/accelerometer_types.h"
25 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/test/test_browser_context.h" 27 #include "content/public/test/test_browser_context.h"
28 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 28 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
29 #include "ui/aura/window.h" 29 #include "ui/aura/window.h"
30 #include "ui/gfx/display.h" 30 #include "ui/display/display.h"
31 #include "ui/message_center/message_center.h" 31 #include "ui/message_center/message_center.h"
32 #include "ui/views/test/webview_test_helper.h" 32 #include "ui/views/test/webview_test_helper.h"
33 #include "ui/views/view.h" 33 #include "ui/views/view.h"
34 #include "ui/views/views_delegate.h" 34 #include "ui/views/views_delegate.h"
35 #include "ui/wm/public/activation_client.h" 35 #include "ui/wm/public/activation_client.h"
36 36
37 namespace ash { 37 namespace ash {
38 38
39 namespace { 39 namespace {
40 40
(...skipping 12 matching lines...) Expand all
53 ->EnableMaximizeModeWindowManager(enable); 53 ->EnableMaximizeModeWindowManager(enable);
54 } 54 }
55 55
56 bool RotationLocked() { 56 bool RotationLocked() {
57 return Shell::GetInstance() 57 return Shell::GetInstance()
58 ->screen_orientation_controller() 58 ->screen_orientation_controller()
59 ->rotation_locked(); 59 ->rotation_locked();
60 } 60 }
61 61
62 void SetDisplayRotationById(int64_t display_id, 62 void SetDisplayRotationById(int64_t display_id,
63 gfx::Display::Rotation rotation) { 63 display::Display::Rotation rotation) {
64 Shell::GetInstance()->display_manager()->SetDisplayRotation( 64 Shell::GetInstance()->display_manager()->SetDisplayRotation(
65 display_id, rotation, gfx::Display::ROTATION_SOURCE_USER); 65 display_id, rotation, display::Display::ROTATION_SOURCE_USER);
66 } 66 }
67 67
68 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) { 68 void SetInternalDisplayRotation(display::Display::Rotation rotation) {
69 SetDisplayRotationById(gfx::Display::InternalDisplayId(), rotation); 69 SetDisplayRotationById(display::Display::InternalDisplayId(), rotation);
70 } 70 }
71 71
72 void SetRotationLocked(bool rotation_locked) { 72 void SetRotationLocked(bool rotation_locked) {
73 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( 73 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked(
74 rotation_locked); 74 rotation_locked);
75 } 75 }
76 76
77 void TriggerLidUpdate(const gfx::Vector3dF& lid) { 77 void TriggerLidUpdate(const gfx::Vector3dF& lid) {
78 scoped_refptr<chromeos::AccelerometerUpdate> update( 78 scoped_refptr<chromeos::AccelerometerUpdate> update(
79 new chromeos::AccelerometerUpdate()); 79 new chromeos::AccelerometerUpdate());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 base::CommandLine::ForCurrentProcess()->AppendSwitch( 159 base::CommandLine::ForCurrentProcess()->AppendSwitch(
160 switches::kAshEnableTouchViewTesting); 160 switches::kAshEnableTouchViewTesting);
161 test::AshTestBase::SetUp(); 161 test::AshTestBase::SetUp();
162 } 162 }
163 163
164 // Tests that a content::WebContents can lock rotation. 164 // Tests that a content::WebContents can lock rotation.
165 TEST_F(ScreenOrientationControllerTest, LockOrientation) { 165 TEST_F(ScreenOrientationControllerTest, LockOrientation) {
166 std::unique_ptr<content::WebContents> content(CreateWebContents()); 166 std::unique_ptr<content::WebContents> content(CreateWebContents());
167 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 167 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
168 ASSERT_NE(nullptr, content->GetNativeView()); 168 ASSERT_NE(nullptr, content->GetNativeView());
169 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 169 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
170 ASSERT_FALSE(RotationLocked()); 170 ASSERT_FALSE(RotationLocked());
171 171
172 AttachAndActivateWebContents(content.get(), focus_window.get()); 172 AttachAndActivateWebContents(content.get(), focus_window.get());
173 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 173 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
174 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 174 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
175 EXPECT_TRUE(RotationLocked()); 175 EXPECT_TRUE(RotationLocked());
176 } 176 }
177 177
178 // Tests that a content::WebContents can unlock rotation. 178 // Tests that a content::WebContents can unlock rotation.
179 TEST_F(ScreenOrientationControllerTest, Unlock) { 179 TEST_F(ScreenOrientationControllerTest, Unlock) {
180 std::unique_ptr<content::WebContents> content(CreateWebContents()); 180 std::unique_ptr<content::WebContents> content(CreateWebContents());
181 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 181 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
182 ASSERT_NE(nullptr, content->GetNativeView()); 182 ASSERT_NE(nullptr, content->GetNativeView());
183 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 183 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
184 ASSERT_FALSE(RotationLocked()); 184 ASSERT_FALSE(RotationLocked());
185 185
186 AttachAndActivateWebContents(content.get(), focus_window.get()); 186 AttachAndActivateWebContents(content.get(), focus_window.get());
187 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 187 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
188 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 188 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
189 EXPECT_TRUE(RotationLocked()); 189 EXPECT_TRUE(RotationLocked());
190 190
191 delegate()->Unlock(content.get()); 191 delegate()->Unlock(content.get());
192 EXPECT_FALSE(RotationLocked()); 192 EXPECT_FALSE(RotationLocked());
193 } 193 }
194 194
195 // Tests that a content::WebContents is able to change the orientation of the 195 // Tests that a content::WebContents is able to change the orientation of the
196 // display after having locked rotation. 196 // display after having locked rotation.
197 TEST_F(ScreenOrientationControllerTest, OrientationChanges) { 197 TEST_F(ScreenOrientationControllerTest, OrientationChanges) {
198 std::unique_ptr<content::WebContents> content(CreateWebContents()); 198 std::unique_ptr<content::WebContents> content(CreateWebContents());
199 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 199 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
200 ASSERT_NE(nullptr, content->GetNativeView()); 200 ASSERT_NE(nullptr, content->GetNativeView());
201 ASSERT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 201 ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
202 ASSERT_FALSE(RotationLocked()); 202 ASSERT_FALSE(RotationLocked());
203 203
204 AttachAndActivateWebContents(content.get(), focus_window.get()); 204 AttachAndActivateWebContents(content.get(), focus_window.get());
205 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); 205 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait);
206 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 206 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
207 EXPECT_TRUE(RotationLocked()); 207 EXPECT_TRUE(RotationLocked());
208 208
209 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 209 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
210 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 210 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
211 } 211 }
212 212
213 // Tests that orientation can only be set by the first content::WebContents that 213 // Tests that orientation can only be set by the first content::WebContents that
214 // has set a rotation lock. 214 // has set a rotation lock.
215 TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) { 215 TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) {
216 std::unique_ptr<content::WebContents> content1(CreateWebContents()); 216 std::unique_ptr<content::WebContents> content1(CreateWebContents());
217 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); 217 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents());
218 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); 218 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0));
219 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); 219 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1));
220 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); 220 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
221 221
222 AttachAndActivateWebContents(content1.get(), focus_window1.get()); 222 AttachAndActivateWebContents(content1.get(), focus_window1.get());
223 AttachWebContents(content2.get(), focus_window2.get()); 223 AttachWebContents(content2.get(), focus_window2.get());
224 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); 224 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
225 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); 225 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
226 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 226 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
227 } 227 }
228 228
229 // Tests that only the content::WebContents that set a rotation lock can perform 229 // Tests that only the content::WebContents that set a rotation lock can perform
230 // an unlock. 230 // an unlock.
231 TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) { 231 TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) {
232 std::unique_ptr<content::WebContents> content1(CreateWebContents()); 232 std::unique_ptr<content::WebContents> content1(CreateWebContents());
233 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); 233 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents());
234 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); 234 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0));
235 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); 235 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1));
236 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); 236 ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
(...skipping 30 matching lines...) Expand all
267 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { 267 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) {
268 std::unique_ptr<content::WebContents> content1(CreateWebContents()); 268 std::unique_ptr<content::WebContents> content1(CreateWebContents());
269 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); 269 std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents());
270 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); 270 std::unique_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0));
271 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); 271 std::unique_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1));
272 AttachAndActivateWebContents(content1.get(), focus_window1.get()); 272 AttachAndActivateWebContents(content1.get(), focus_window1.get());
273 AttachWebContents(content2.get(), focus_window2.get()); 273 AttachWebContents(content2.get(), focus_window2.get());
274 274
275 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); 275 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
276 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); 276 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
277 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 277 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
278 278
279 aura::client::ActivationClient* activation_client = 279 aura::client::ActivationClient* activation_client =
280 Shell::GetInstance()->activation_client(); 280 Shell::GetInstance()->activation_client();
281 activation_client->ActivateWindow(focus_window2.get()); 281 activation_client->ActivateWindow(focus_window2.get());
282 EXPECT_TRUE(RotationLocked()); 282 EXPECT_TRUE(RotationLocked());
283 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 283 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
284 284
285 activation_client->ActivateWindow(focus_window1.get()); 285 activation_client->ActivateWindow(focus_window1.get());
286 EXPECT_TRUE(RotationLocked()); 286 EXPECT_TRUE(RotationLocked());
287 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 287 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
288 } 288 }
289 289
290 // Tests that a rotation lock is removed when the setting window is hidden, and 290 // Tests that a rotation lock is removed when the setting window is hidden, and
291 // that it is reapplied when the window becomes visible. 291 // that it is reapplied when the window becomes visible.
292 TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { 292 TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) {
293 std::unique_ptr<content::WebContents> content(CreateWebContents()); 293 std::unique_ptr<content::WebContents> content(CreateWebContents());
294 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 294 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
295 AttachAndActivateWebContents(content.get(), focus_window.get()); 295 AttachAndActivateWebContents(content.get(), focus_window.get());
296 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 296 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
297 EXPECT_TRUE(RotationLocked()); 297 EXPECT_TRUE(RotationLocked());
(...skipping 29 matching lines...) Expand all
327 activation_client->ActivateWindow(focus_window1.get()); 327 activation_client->ActivateWindow(focus_window1.get());
328 EXPECT_FALSE(RotationLocked()); 328 EXPECT_FALSE(RotationLocked());
329 } 329 }
330 330
331 // Tests that accelerometer readings in each of the screen angles will trigger a 331 // Tests that accelerometer readings in each of the screen angles will trigger a
332 // rotation of the internal display. 332 // rotation of the internal display.
333 TEST_F(ScreenOrientationControllerTest, DisplayRotation) { 333 TEST_F(ScreenOrientationControllerTest, DisplayRotation) {
334 EnableMaximizeMode(true); 334 EnableMaximizeMode(true);
335 // Now test rotating in all directions. 335 // Now test rotating in all directions.
336 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 336 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
337 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 337 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
338 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 338 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
339 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 339 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
340 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 340 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
341 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 341 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
342 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 342 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
343 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 343 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
344 } 344 }
345 345
346 // Tests that low angles are ignored by the accelerometer (i.e. when the device 346 // Tests that low angles are ignored by the accelerometer (i.e. when the device
347 // is almost laying flat). 347 // is almost laying flat).
348 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) { 348 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) {
349 EnableMaximizeMode(true); 349 EnableMaximizeMode(true);
350 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); 350 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity));
351 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 351 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
352 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); 352 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity));
353 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 353 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
354 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); 354 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity));
355 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 355 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
356 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); 356 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity));
357 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 357 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
358 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); 358 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity));
359 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 359 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
360 } 360 }
361 361
362 // Tests that the display will stick to the current orientation beyond the 362 // Tests that the display will stick to the current orientation beyond the
363 // halfway point, preventing frequent updates back and forth. 363 // halfway point, preventing frequent updates back and forth.
364 TEST_F(ScreenOrientationControllerTest, RotationSticky) { 364 TEST_F(ScreenOrientationControllerTest, RotationSticky) {
365 EnableMaximizeMode(true); 365 EnableMaximizeMode(true);
366 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); 366 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f);
367 TriggerLidUpdate(gravity); 367 TriggerLidUpdate(gravity);
368 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 368 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
369 369
370 // Turn past half-way point to next direction and rotation should remain 370 // Turn past half-way point to next direction and rotation should remain
371 // the same. 371 // the same.
372 float degrees = 50.0; 372 float degrees = 50.0;
373 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); 373 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
374 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); 374 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
375 TriggerLidUpdate(gravity); 375 TriggerLidUpdate(gravity);
376 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 376 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
377 377
378 // Turn more and the screen should rotate. 378 // Turn more and the screen should rotate.
379 degrees = 70.0; 379 degrees = 70.0;
380 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); 380 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
381 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); 381 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
382 TriggerLidUpdate(gravity); 382 TriggerLidUpdate(gravity);
383 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 383 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
384 384
385 // Turn back just beyond the half-way point and the new rotation should 385 // Turn back just beyond the half-way point and the new rotation should
386 // still be in effect. 386 // still be in effect.
387 degrees = 40.0; 387 degrees = 40.0;
388 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); 388 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
389 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); 389 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
390 TriggerLidUpdate(gravity); 390 TriggerLidUpdate(gravity);
391 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 391 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
392 } 392 }
393 393
394 // Tests that the display will stick to its current orientation when the 394 // Tests that the display will stick to its current orientation when the
395 // rotation lock has been set. 395 // rotation lock has been set.
396 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { 396 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) {
397 EnableMaximizeMode(true); 397 EnableMaximizeMode(true);
398 SetRotationLocked(true); 398 SetRotationLocked(true);
399 399
400 // Turn past the threshold for rotation. 400 // Turn past the threshold for rotation.
401 float degrees = 90.0; 401 float degrees = 90.0;
402 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity, 402 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity,
403 -cos(degrees * kDegreesToRadians) * kMeanGravity, 403 -cos(degrees * kDegreesToRadians) * kMeanGravity,
404 0.0f); 404 0.0f);
405 TriggerLidUpdate(gravity); 405 TriggerLidUpdate(gravity);
406 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 406 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
407 407
408 SetRotationLocked(false); 408 SetRotationLocked(false);
409 TriggerLidUpdate(gravity); 409 TriggerLidUpdate(gravity);
410 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 410 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
411 } 411 }
412 412
413 // The TrayDisplay class that is responsible for adding/updating MessageCenter 413 // The TrayDisplay class that is responsible for adding/updating MessageCenter
414 // notifications is only added to the SystemTray on ChromeOS. 414 // notifications is only added to the SystemTray on ChromeOS.
415 // Tests that the screen rotation notifications are suppressed when 415 // Tests that the screen rotation notifications are suppressed when
416 // triggered by the accelerometer. 416 // triggered by the accelerometer.
417 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { 417 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) {
418 EnableMaximizeMode(true); 418 EnableMaximizeMode(true);
419 test::TestSystemTrayDelegate* tray_delegate = 419 test::TestSystemTrayDelegate* tray_delegate =
420 static_cast<test::TestSystemTrayDelegate*>( 420 static_cast<test::TestSystemTrayDelegate*>(
421 Shell::GetInstance()->system_tray_delegate()); 421 Shell::GetInstance()->system_tray_delegate());
422 tray_delegate->set_should_show_display_notification(true); 422 tray_delegate->set_should_show_display_notification(true);
423 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay(); 423 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
424 424
425 message_center::MessageCenter* message_center = 425 message_center::MessageCenter* message_center =
426 message_center::MessageCenter::Get(); 426 message_center::MessageCenter::Get();
427 427
428 EXPECT_EQ(0u, message_center->NotificationCount()); 428 EXPECT_EQ(0u, message_center->NotificationCount());
429 EXPECT_FALSE(message_center->HasPopupNotifications()); 429 EXPECT_FALSE(message_center->HasPopupNotifications());
430 430
431 // Make sure notifications are still displayed when 431 // Make sure notifications are still displayed when
432 // adjusting the screen rotation directly when in maximize mode 432 // adjusting the screen rotation directly when in maximize mode
433 ASSERT_NE(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 433 ASSERT_NE(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
434 SetInternalDisplayRotation(gfx::Display::ROTATE_270); 434 SetInternalDisplayRotation(display::Display::ROTATE_270);
435 SetRotationLocked(false); 435 SetRotationLocked(false);
436 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 436 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
437 EXPECT_EQ(1u, message_center->NotificationCount()); 437 EXPECT_EQ(1u, message_center->NotificationCount());
438 EXPECT_TRUE(message_center->HasPopupNotifications()); 438 EXPECT_TRUE(message_center->HasPopupNotifications());
439 439
440 // Clear all notifications 440 // Clear all notifications
441 message_center->RemoveAllNotifications( 441 message_center->RemoveAllNotifications(
442 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); 442 false /* by_user */, message_center::MessageCenter::RemoveType::ALL);
443 EXPECT_EQ(0u, message_center->NotificationCount()); 443 EXPECT_EQ(0u, message_center->NotificationCount());
444 EXPECT_FALSE(message_center->HasPopupNotifications()); 444 EXPECT_FALSE(message_center->HasPopupNotifications());
445 445
446 // Make sure notifications are blocked when adjusting the screen rotation 446 // Make sure notifications are blocked when adjusting the screen rotation
447 // via the accelerometer while in maximize mode 447 // via the accelerometer while in maximize mode
448 // Rotate the screen 90 degrees 448 // Rotate the screen 90 degrees
449 ASSERT_NE(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 449 ASSERT_NE(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
450 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 450 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
451 ASSERT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 451 ASSERT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
452 EXPECT_EQ(0u, message_center->NotificationCount()); 452 EXPECT_EQ(0u, message_center->NotificationCount());
453 EXPECT_FALSE(message_center->HasPopupNotifications()); 453 EXPECT_FALSE(message_center->HasPopupNotifications());
454 454
455 // Make sure notifications are still displayed when 455 // Make sure notifications are still displayed when
456 // adjusting the screen rotation directly when not in maximize mode 456 // adjusting the screen rotation directly when not in maximize mode
457 EnableMaximizeMode(false); 457 EnableMaximizeMode(false);
458 // Reset the screen rotation. 458 // Reset the screen rotation.
459 SetInternalDisplayRotation(gfx::Display::ROTATE_0); 459 SetInternalDisplayRotation(display::Display::ROTATE_0);
460 // Clear all notifications 460 // Clear all notifications
461 message_center->RemoveAllNotifications( 461 message_center->RemoveAllNotifications(
462 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); 462 false /* by_user */, message_center::MessageCenter::RemoveType::ALL);
463 ASSERT_NE(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 463 ASSERT_NE(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
464 ASSERT_EQ(0u, message_center->NotificationCount()); 464 ASSERT_EQ(0u, message_center->NotificationCount());
465 ASSERT_FALSE(message_center->HasPopupNotifications()); 465 ASSERT_FALSE(message_center->HasPopupNotifications());
466 SetInternalDisplayRotation(gfx::Display::ROTATE_180); 466 SetInternalDisplayRotation(display::Display::ROTATE_180);
467 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 467 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
468 EXPECT_EQ(1u, message_center->NotificationCount()); 468 EXPECT_EQ(1u, message_center->NotificationCount());
469 EXPECT_TRUE(message_center->HasPopupNotifications()); 469 EXPECT_TRUE(message_center->HasPopupNotifications());
470 } 470 }
471 471
472 // Tests that if a user has set a display rotation that it is restored upon 472 // Tests that if a user has set a display rotation that it is restored upon
473 // exiting maximize mode. 473 // exiting maximize mode.
474 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) { 474 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) {
475 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay(); 475 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
476 476
477 SetInternalDisplayRotation(gfx::Display::ROTATE_90); 477 SetInternalDisplayRotation(display::Display::ROTATE_90);
478 EnableMaximizeMode(true); 478 EnableMaximizeMode(true);
479 479
480 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 480 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
481 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 481 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
482 482
483 EnableMaximizeMode(false); 483 EnableMaximizeMode(false);
484 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 484 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
485 } 485 }
486 486
487 // Tests that if a user sets a display rotation that accelerometer rotation 487 // Tests that if a user sets a display rotation that accelerometer rotation
488 // becomes locked. 488 // becomes locked.
489 TEST_F(ScreenOrientationControllerTest, 489 TEST_F(ScreenOrientationControllerTest,
490 NonAccelerometerRotationChangesLockRotation) { 490 NonAccelerometerRotationChangesLockRotation) {
491 EnableMaximizeMode(true); 491 EnableMaximizeMode(true);
492 ASSERT_FALSE(RotationLocked()); 492 ASSERT_FALSE(RotationLocked());
493 SetInternalDisplayRotation(gfx::Display::ROTATE_270); 493 SetInternalDisplayRotation(display::Display::ROTATE_270);
494 EXPECT_TRUE(RotationLocked()); 494 EXPECT_TRUE(RotationLocked());
495 } 495 }
496 496
497 // Tests that if a user changes the display rotation, while rotation is locked, 497 // Tests that if a user changes the display rotation, while rotation is locked,
498 // that the updates are recorded. Upon exiting maximize mode the latest user 498 // that the updates are recorded. Upon exiting maximize mode the latest user
499 // rotation should be applied. 499 // rotation should be applied.
500 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { 500 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) {
501 EnableMaximizeMode(true); 501 EnableMaximizeMode(true);
502 SetInternalDisplayRotation(gfx::Display::ROTATE_270); 502 SetInternalDisplayRotation(display::Display::ROTATE_270);
503 // User sets rotation to the same rotation that the display was at when 503 // User sets rotation to the same rotation that the display was at when
504 // maximize mode was activated. 504 // maximize mode was activated.
505 SetInternalDisplayRotation(gfx::Display::ROTATE_0); 505 SetInternalDisplayRotation(display::Display::ROTATE_0);
506 EnableMaximizeMode(false); 506 EnableMaximizeMode(false);
507 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 507 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
508 } 508 }
509 509
510 // Tests that when the orientation lock is set to Landscape, that rotation can 510 // Tests that when the orientation lock is set to Landscape, that rotation can
511 // be done between the two angles of the orientation. 511 // be done between the two angles of the orientation.
512 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { 512 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) {
513 std::unique_ptr<content::WebContents> content(CreateWebContents()); 513 std::unique_ptr<content::WebContents> content(CreateWebContents());
514 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 514 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
515 EnableMaximizeMode(true); 515 EnableMaximizeMode(true);
516 516
517 AttachAndActivateWebContents(content.get(), focus_window.get()); 517 AttachAndActivateWebContents(content.get(), focus_window.get());
518 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 518 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
519 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 519 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
520 EXPECT_TRUE(RotationLocked()); 520 EXPECT_TRUE(RotationLocked());
521 521
522 // Inverse of orientation is allowed 522 // Inverse of orientation is allowed
523 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 523 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
524 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 524 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
525 525
526 // Display rotations between are not allowed 526 // Display rotations between are not allowed
527 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 527 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
528 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 528 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
529 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 529 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
530 EXPECT_EQ(gfx::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 530 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
531 } 531 }
532 532
533 // Tests that when the orientation lock is set to Portrait, that rotaiton can be 533 // Tests that when the orientation lock is set to Portrait, that rotaiton can be
534 // done between the two angles of the orientation. 534 // done between the two angles of the orientation.
535 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { 535 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) {
536 std::unique_ptr<content::WebContents> content(CreateWebContents()); 536 std::unique_ptr<content::WebContents> content(CreateWebContents());
537 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 537 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
538 EnableMaximizeMode(true); 538 EnableMaximizeMode(true);
539 539
540 AttachAndActivateWebContents(content.get(), focus_window.get()); 540 AttachAndActivateWebContents(content.get(), focus_window.get());
541 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); 541 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait);
542 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 542 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
543 EXPECT_TRUE(RotationLocked()); 543 EXPECT_TRUE(RotationLocked());
544 544
545 // Inverse of orientation is allowed 545 // Inverse of orientation is allowed
546 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 546 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
547 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 547 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
548 548
549 // Display rotations between are not allowed 549 // Display rotations between are not allowed
550 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 550 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
551 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 551 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
552 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 552 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
553 EXPECT_EQ(gfx::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 553 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
554 } 554 }
555 555
556 // Tests that for an orientation lock which does not allow rotation, that the 556 // Tests that for an orientation lock which does not allow rotation, that the
557 // display rotation remains constant. 557 // display rotation remains constant.
558 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { 558 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) {
559 std::unique_ptr<content::WebContents> content(CreateWebContents()); 559 std::unique_ptr<content::WebContents> content(CreateWebContents());
560 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 560 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
561 EnableMaximizeMode(true); 561 EnableMaximizeMode(true);
562 562
563 AttachAndActivateWebContents(content.get(), focus_window.get()); 563 AttachAndActivateWebContents(content.get(), focus_window.get());
564 delegate()->Lock(content.get(), 564 delegate()->Lock(content.get(),
565 blink::WebScreenOrientationLockPortraitPrimary); 565 blink::WebScreenOrientationLockPortraitPrimary);
566 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 566 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
567 EXPECT_TRUE(RotationLocked()); 567 EXPECT_TRUE(RotationLocked());
568 568
569 // Rotation does not change. 569 // Rotation does not change.
570 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 570 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
571 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 571 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
572 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 572 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
573 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 573 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
574 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 574 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
575 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 575 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
576 } 576 }
577 577
578 // Tests that after a content::WebContents has applied an orientation lock which 578 // Tests that after a content::WebContents has applied an orientation lock which
579 // supports rotation, that a user rotation lock does not allow rotation. 579 // supports rotation, that a user rotation lock does not allow rotation.
580 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { 580 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) {
581 std::unique_ptr<content::WebContents> content(CreateWebContents()); 581 std::unique_ptr<content::WebContents> content(CreateWebContents());
582 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 582 std::unique_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
583 EnableMaximizeMode(true); 583 EnableMaximizeMode(true);
584 584
585 AttachAndActivateWebContents(content.get(), focus_window.get()); 585 AttachAndActivateWebContents(content.get(), focus_window.get());
586 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 586 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
587 delegate()->Unlock(content.get()); 587 delegate()->Unlock(content.get());
588 588
589 SetRotationLocked(true); 589 SetRotationLocked(true);
590 EXPECT_TRUE(RotationLocked()); 590 EXPECT_TRUE(RotationLocked());
591 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 591 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
592 592
593 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 593 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
594 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 594 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
595 } 595 }
596 596
597 // Tests that when MaximizeMode is triggered before the internal display is 597 // Tests that when MaximizeMode is triggered before the internal display is
598 // ready, that ScreenOrientationController still begins listening to events, 598 // ready, that ScreenOrientationController still begins listening to events,
599 // which require an internal display to be acted upon. 599 // which require an internal display to be acted upon.
600 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { 600 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) {
601 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay(); 601 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
602 602
603 int64_t internal_display_id = gfx::Display::InternalDisplayId(); 603 int64_t internal_display_id = display::Display::InternalDisplayId();
604 gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID); 604 display::Display::SetInternalDisplayId(display::Display::kInvalidDisplayID);
605 605
606 EnableMaximizeMode(true); 606 EnableMaximizeMode(true);
607 607
608 // Should not crash, even though there is no internal display. 608 // Should not crash, even though there is no internal display.
609 SetDisplayRotationById(internal_display_id, gfx::Display::ROTATE_180); 609 SetDisplayRotationById(internal_display_id, display::Display::ROTATE_180);
610 EXPECT_FALSE(RotationLocked()); 610 EXPECT_FALSE(RotationLocked());
611 611
612 // Should not crash, even though the invalid display id is requested. 612 // Should not crash, even though the invalid display id is requested.
613 SetDisplayRotationById(gfx::Display::kInvalidDisplayID, 613 SetDisplayRotationById(display::Display::kInvalidDisplayID,
614 gfx::Display::ROTATE_180); 614 display::Display::ROTATE_180);
615 EXPECT_FALSE(RotationLocked()); 615 EXPECT_FALSE(RotationLocked());
616 616
617 // With an internal display now available, functionality should resume. 617 // With an internal display now available, functionality should resume.
618 gfx::Display::SetInternalDisplayId(internal_display_id); 618 display::Display::SetInternalDisplayId(internal_display_id);
619 SetInternalDisplayRotation(gfx::Display::ROTATE_90); 619 SetInternalDisplayRotation(display::Display::ROTATE_90);
620 EXPECT_TRUE(RotationLocked()); 620 EXPECT_TRUE(RotationLocked());
621 } 621 }
622 622
623 // Verifies rotating an inactive Display is successful. 623 // Verifies rotating an inactive Display is successful.
624 TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) { 624 TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) {
625 const int64_t kInternalDisplayId = 9; 625 const int64_t kInternalDisplayId = 9;
626 const int64_t kExternalDisplayId = 10; 626 const int64_t kExternalDisplayId = 10;
627 const gfx::Display::Rotation kNewRotation = gfx::Display::ROTATE_180; 627 const display::Display::Rotation kNewRotation = display::Display::ROTATE_180;
628 628
629 const DisplayInfo internal_display_info = 629 const DisplayInfo internal_display_info =
630 CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 500, 500)); 630 CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 500, 500));
631 const DisplayInfo external_display_info = 631 const DisplayInfo external_display_info =
632 CreateDisplayInfo(kExternalDisplayId, gfx::Rect(1, 1, 500, 500)); 632 CreateDisplayInfo(kExternalDisplayId, gfx::Rect(1, 1, 500, 500));
633 633
634 std::vector<DisplayInfo> display_info_list_two_active; 634 std::vector<DisplayInfo> display_info_list_two_active;
635 display_info_list_two_active.push_back(internal_display_info); 635 display_info_list_two_active.push_back(internal_display_info);
636 display_info_list_two_active.push_back(external_display_info); 636 display_info_list_two_active.push_back(external_display_info);
637 637
638 std::vector<DisplayInfo> display_info_list_one_active; 638 std::vector<DisplayInfo> display_info_list_one_active;
639 display_info_list_one_active.push_back(external_display_info); 639 display_info_list_one_active.push_back(external_display_info);
640 640
641 // The DisplayInfo list with two active displays needs to be added first so 641 // The DisplayInfo list with two active displays needs to be added first so
642 // that the DisplayManager can track the |internal_display_info| as inactive 642 // that the DisplayManager can track the |internal_display_info| as inactive
643 // instead of non-existent. 643 // instead of non-existent.
644 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 644 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
645 display_manager->UpdateDisplaysWith(display_info_list_two_active); 645 display_manager->UpdateDisplaysWith(display_info_list_two_active);
646 display_manager->UpdateDisplaysWith(display_info_list_one_active); 646 display_manager->UpdateDisplaysWith(display_info_list_one_active);
647 647
648 test::ScopedSetInternalDisplayId set_internal(kInternalDisplayId); 648 test::ScopedSetInternalDisplayId set_internal(kInternalDisplayId);
649 649
650 ASSERT_NE(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId) 650 ASSERT_NE(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId)
651 .GetActiveRotation()); 651 .GetActiveRotation());
652 652
653 Shell::GetInstance()->screen_orientation_controller()->SetDisplayRotation( 653 Shell::GetInstance()->screen_orientation_controller()->SetDisplayRotation(
654 kNewRotation, gfx::Display::ROTATION_SOURCE_ACTIVE); 654 kNewRotation, display::Display::ROTATION_SOURCE_ACTIVE);
655 655
656 EXPECT_EQ(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId) 656 EXPECT_EQ(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId)
657 .GetActiveRotation()); 657 .GetActiveRotation());
658 } 658 }
659 659
660 } // namespace ash 660 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller_unittest.cc ('k') | ash/content/keyboard_overlay/keyboard_overlay_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698