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

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

Issue 1071353003: Prevent DisplayPreferences from saving incorrect rotations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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_controller_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"
(...skipping 23 matching lines...) Expand all
34 34
35 const float kDegreesToRadians = 3.1415926f / 180.0f; 35 const float kDegreesToRadians = 3.1415926f / 180.0f;
36 const float kMeanGravity = 9.8066f; 36 const float kMeanGravity = 9.8066f;
37 37
38 void EnableMaximizeMode(bool enable) { 38 void EnableMaximizeMode(bool enable) {
39 Shell::GetInstance() 39 Shell::GetInstance()
40 ->maximize_mode_controller() 40 ->maximize_mode_controller()
41 ->EnableMaximizeModeWindowManager(enable); 41 ->EnableMaximizeModeWindowManager(enable);
42 } 42 }
43 43
44 gfx::Display::Rotation GetInternalDisplayRotation() {
jonross 2015/04/10 17:54:43 This method is duplicated on 51, was missed in a p
45 return Shell::GetInstance()
46 ->display_manager()
47 ->GetDisplayInfo(gfx::Display::InternalDisplayId())
48 .rotation();
49 }
50
51 gfx::Display::Rotation Rotation() { 44 gfx::Display::Rotation Rotation() {
52 return Shell::GetInstance() 45 return Shell::GetInstance()
53 ->display_manager() 46 ->display_manager()
54 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) 47 ->GetDisplayInfo(gfx::Display::InternalDisplayId())
55 .rotation(); 48 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE);
56 } 49 }
57 50
58 bool RotationLocked() { 51 bool RotationLocked() {
59 return Shell::GetInstance() 52 return Shell::GetInstance()
60 ->screen_orientation_controller() 53 ->screen_orientation_controller()
61 ->rotation_locked(); 54 ->rotation_locked();
62 } 55 }
63 56
64 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) { 57 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) {
65 Shell::GetInstance()->display_manager()->SetDisplayRotation( 58 Shell::GetInstance()->display_manager()->SetDisplayRotation(
66 gfx::Display::InternalDisplayId(), rotation); 59 gfx::Display::InternalDisplayId(), rotation,
60 gfx::Display::ROTATION_SOURCE_USER);
67 } 61 }
68 62
69 void SetRotationLocked(bool rotation_locked) { 63 void SetRotationLocked(bool rotation_locked) {
70 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( 64 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked(
71 rotation_locked); 65 rotation_locked);
72 } 66 }
73 67
74 void TriggerLidUpdate(const gfx::Vector3dF& lid) { 68 void TriggerLidUpdate(const gfx::Vector3dF& lid) {
75 scoped_refptr<chromeos::AccelerometerUpdate> update( 69 scoped_refptr<chromeos::AccelerometerUpdate> update(
76 new chromeos::AccelerometerUpdate()); 70 new chromeos::AccelerometerUpdate());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { 261 TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) {
268 scoped_ptr<content::WebContents> content1(CreateWebContents()); 262 scoped_ptr<content::WebContents> content1(CreateWebContents());
269 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents()); 263 scoped_ptr<content::WebContents> content2(CreateSecondaryWebContents());
270 scoped_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0)); 264 scoped_ptr<aura::Window> focus_window1(CreateTestWindowInShellWithId(0));
271 scoped_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1)); 265 scoped_ptr<aura::Window> focus_window2(CreateTestWindowInShellWithId(1));
272 AttachAndActivateWebContents(content1.get(), focus_window1.get()); 266 AttachAndActivateWebContents(content1.get(), focus_window1.get());
273 AttachWebContents(content2.get(), focus_window2.get()); 267 AttachWebContents(content2.get(), focus_window2.get());
274 268
275 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape); 269 delegate()->Lock(content1.get(), blink::WebScreenOrientationLockLandscape);
276 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait); 270 delegate()->Lock(content2.get(), blink::WebScreenOrientationLockPortrait);
277 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 271 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
278 272
279 aura::client::ActivationClient* activation_client = 273 aura::client::ActivationClient* activation_client =
280 Shell::GetInstance()->activation_client(); 274 Shell::GetInstance()->activation_client();
281 activation_client->ActivateWindow(focus_window2.get()); 275 activation_client->ActivateWindow(focus_window2.get());
282 EXPECT_TRUE(RotationLocked()); 276 EXPECT_TRUE(RotationLocked());
283 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 277 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
284 278
285 activation_client->ActivateWindow(focus_window1.get()); 279 activation_client->ActivateWindow(focus_window1.get());
286 EXPECT_TRUE(RotationLocked()); 280 EXPECT_TRUE(RotationLocked());
287 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 281 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
288 } 282 }
289 283
290 // Tests that a rotation lock is removed when the setting window is hidden, and 284 // Tests that a rotation lock is removed when the setting window is hidden, and
291 // that it is reapplied when the window becomes visible. 285 // that it is reapplied when the window becomes visible.
292 TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { 286 TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) {
293 scoped_ptr<content::WebContents> content(CreateWebContents()); 287 scoped_ptr<content::WebContents> content(CreateWebContents());
294 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 288 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
295 AttachAndActivateWebContents(content.get(), focus_window.get()); 289 AttachAndActivateWebContents(content.get(), focus_window.get());
296 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 290 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
297 EXPECT_TRUE(RotationLocked()); 291 EXPECT_TRUE(RotationLocked());
(...skipping 29 matching lines...) Expand all
327 activation_client->ActivateWindow(focus_window1.get()); 321 activation_client->ActivateWindow(focus_window1.get());
328 EXPECT_FALSE(RotationLocked()); 322 EXPECT_FALSE(RotationLocked());
329 } 323 }
330 324
331 // Tests that accelerometer readings in each of the screen angles will trigger a 325 // Tests that accelerometer readings in each of the screen angles will trigger a
332 // rotation of the internal display. 326 // rotation of the internal display.
333 TEST_F(ScreenOrientationControllerTest, DisplayRotation) { 327 TEST_F(ScreenOrientationControllerTest, DisplayRotation) {
334 EnableMaximizeMode(true); 328 EnableMaximizeMode(true);
335 // Now test rotating in all directions. 329 // Now test rotating in all directions.
336 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 330 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
337 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 331 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
338 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 332 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
339 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 333 EXPECT_EQ(gfx::Display::ROTATE_180, Rotation());
340 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 334 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
341 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); 335 EXPECT_EQ(gfx::Display::ROTATE_270, Rotation());
342 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 336 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
343 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 337 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
344 } 338 }
345 339
346 // Tests that low angles are ignored by the accelerometer (i.e. when the device 340 // Tests that low angles are ignored by the accelerometer (i.e. when the device
347 // is almost laying flat). 341 // is almost laying flat).
348 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) { 342 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) {
349 EnableMaximizeMode(true); 343 EnableMaximizeMode(true);
350 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); 344 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity));
351 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 345 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
352 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); 346 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity));
353 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 347 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
354 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); 348 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity));
355 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 349 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
356 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); 350 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity));
357 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 351 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
358 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); 352 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity));
359 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 353 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
360 } 354 }
361 355
362 // Tests that the display will stick to the current orientation beyond the 356 // Tests that the display will stick to the current orientation beyond the
363 // halfway point, preventing frequent updates back and forth. 357 // halfway point, preventing frequent updates back and forth.
364 TEST_F(ScreenOrientationControllerTest, RotationSticky) { 358 TEST_F(ScreenOrientationControllerTest, RotationSticky) {
365 EnableMaximizeMode(true); 359 EnableMaximizeMode(true);
366 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); 360 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f);
367 TriggerLidUpdate(gravity); 361 TriggerLidUpdate(gravity);
368 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 362 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
369 363
370 // Turn past half-way point to next direction and rotation should remain 364 // Turn past half-way point to next direction and rotation should remain
371 // the same. 365 // the same.
372 float degrees = 50.0; 366 float degrees = 50.0;
373 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); 367 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
374 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); 368 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
375 TriggerLidUpdate(gravity); 369 TriggerLidUpdate(gravity);
376 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 370 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
377 371
378 // Turn more and the screen should rotate. 372 // Turn more and the screen should rotate.
379 degrees = 70.0; 373 degrees = 70.0;
380 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); 374 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
381 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); 375 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
382 TriggerLidUpdate(gravity); 376 TriggerLidUpdate(gravity);
383 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 377 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
384 378
385 // Turn back just beyond the half-way point and the new rotation should 379 // Turn back just beyond the half-way point and the new rotation should
386 // still be in effect. 380 // still be in effect.
387 degrees = 40.0; 381 degrees = 40.0;
388 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); 382 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
389 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); 383 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
390 TriggerLidUpdate(gravity); 384 TriggerLidUpdate(gravity);
391 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 385 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
392 } 386 }
393 387
394 // Tests that the display will stick to its current orientation when the 388 // Tests that the display will stick to its current orientation when the
395 // rotation lock has been set. 389 // rotation lock has been set.
396 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { 390 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) {
397 EnableMaximizeMode(true); 391 EnableMaximizeMode(true);
398 SetRotationLocked(true); 392 SetRotationLocked(true);
399 393
400 // Turn past the threshold for rotation. 394 // Turn past the threshold for rotation.
401 float degrees = 90.0; 395 float degrees = 90.0;
402 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity, 396 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity,
403 -cos(degrees * kDegreesToRadians) * kMeanGravity, 397 -cos(degrees * kDegreesToRadians) * kMeanGravity,
404 0.0f); 398 0.0f);
405 TriggerLidUpdate(gravity); 399 TriggerLidUpdate(gravity);
406 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 400 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
407 401
408 SetRotationLocked(false); 402 SetRotationLocked(false);
409 TriggerLidUpdate(gravity); 403 TriggerLidUpdate(gravity);
410 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 404 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
411 } 405 }
412 406
413 // The TrayDisplay class that is responsible for adding/updating MessageCenter 407 // The TrayDisplay class that is responsible for adding/updating MessageCenter
414 // notifications is only added to the SystemTray on ChromeOS. 408 // notifications is only added to the SystemTray on ChromeOS.
415 // Tests that the screen rotation notifications are suppressed when 409 // Tests that the screen rotation notifications are suppressed when
416 // triggered by the accelerometer. 410 // triggered by the accelerometer.
417 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { 411 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) {
418 EnableMaximizeMode(true); 412 EnableMaximizeMode(true);
419 test::TestSystemTrayDelegate* tray_delegate = 413 test::TestSystemTrayDelegate* tray_delegate =
420 static_cast<test::TestSystemTrayDelegate*>( 414 static_cast<test::TestSystemTrayDelegate*>(
421 Shell::GetInstance()->system_tray_delegate()); 415 Shell::GetInstance()->system_tray_delegate());
422 tray_delegate->set_should_show_display_notification(true); 416 tray_delegate->set_should_show_display_notification(true);
423 417
424 message_center::MessageCenter* message_center = 418 message_center::MessageCenter* message_center =
425 message_center::MessageCenter::Get(); 419 message_center::MessageCenter::Get();
426 420
427 EXPECT_EQ(0u, message_center->NotificationCount()); 421 EXPECT_EQ(0u, message_center->NotificationCount());
428 EXPECT_FALSE(message_center->HasPopupNotifications()); 422 EXPECT_FALSE(message_center->HasPopupNotifications());
429 423
430 // Make sure notifications are still displayed when 424 // Make sure notifications are still displayed when
431 // adjusting the screen rotation directly when in maximize mode 425 // adjusting the screen rotation directly when in maximize mode
432 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); 426 ASSERT_NE(gfx::Display::ROTATE_270, Rotation());
433 SetInternalDisplayRotation(gfx::Display::ROTATE_270); 427 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
434 SetRotationLocked(false); 428 SetRotationLocked(false);
435 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); 429 EXPECT_EQ(gfx::Display::ROTATE_270, Rotation());
436 EXPECT_EQ(1u, message_center->NotificationCount()); 430 EXPECT_EQ(1u, message_center->NotificationCount());
437 EXPECT_TRUE(message_center->HasPopupNotifications()); 431 EXPECT_TRUE(message_center->HasPopupNotifications());
438 432
439 // Clear all notifications 433 // Clear all notifications
440 message_center->RemoveAllNotifications(false); 434 message_center->RemoveAllNotifications(false);
441 EXPECT_EQ(0u, message_center->NotificationCount()); 435 EXPECT_EQ(0u, message_center->NotificationCount());
442 EXPECT_FALSE(message_center->HasPopupNotifications()); 436 EXPECT_FALSE(message_center->HasPopupNotifications());
443 437
444 // Make sure notifications are blocked when adjusting the screen rotation 438 // Make sure notifications are blocked when adjusting the screen rotation
445 // via the accelerometer while in maximize mode 439 // via the accelerometer while in maximize mode
446 // Rotate the screen 90 degrees 440 // Rotate the screen 90 degrees
447 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 441 ASSERT_NE(gfx::Display::ROTATE_90, Rotation());
448 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 442 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
449 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 443 ASSERT_EQ(gfx::Display::ROTATE_90, Rotation());
450 EXPECT_EQ(0u, message_center->NotificationCount()); 444 EXPECT_EQ(0u, message_center->NotificationCount());
451 EXPECT_FALSE(message_center->HasPopupNotifications()); 445 EXPECT_FALSE(message_center->HasPopupNotifications());
452 446
453 // Make sure notifications are still displayed when 447 // Make sure notifications are still displayed when
454 // adjusting the screen rotation directly when not in maximize mode 448 // adjusting the screen rotation directly when not in maximize mode
455 EnableMaximizeMode(false); 449 EnableMaximizeMode(false);
456 // Reset the screen rotation. 450 // Reset the screen rotation.
457 SetInternalDisplayRotation(gfx::Display::ROTATE_0); 451 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
458 // Clear all notifications 452 // Clear all notifications
459 message_center->RemoveAllNotifications(false); 453 message_center->RemoveAllNotifications(false);
460 ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 454 ASSERT_NE(gfx::Display::ROTATE_180, Rotation());
461 ASSERT_EQ(0u, message_center->NotificationCount()); 455 ASSERT_EQ(0u, message_center->NotificationCount());
462 ASSERT_FALSE(message_center->HasPopupNotifications()); 456 ASSERT_FALSE(message_center->HasPopupNotifications());
463 SetInternalDisplayRotation(gfx::Display::ROTATE_180); 457 SetInternalDisplayRotation(gfx::Display::ROTATE_180);
464 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 458 EXPECT_EQ(gfx::Display::ROTATE_180, Rotation());
465 EXPECT_EQ(1u, message_center->NotificationCount()); 459 EXPECT_EQ(1u, message_center->NotificationCount());
466 EXPECT_TRUE(message_center->HasPopupNotifications()); 460 EXPECT_TRUE(message_center->HasPopupNotifications());
467 } 461 }
468 462
469 // Tests that if a user has set a display rotation that it is restored upon 463 // Tests that if a user has set a display rotation that it is restored upon
470 // exiting maximize mode. 464 // exiting maximize mode.
471 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) { 465 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) {
472 SetInternalDisplayRotation(gfx::Display::ROTATE_90); 466 SetInternalDisplayRotation(gfx::Display::ROTATE_90);
473 EnableMaximizeMode(true); 467 EnableMaximizeMode(true);
474 468
475 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 469 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
476 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 470 EXPECT_EQ(gfx::Display::ROTATE_180, Rotation());
477 471
478 EnableMaximizeMode(false); 472 EnableMaximizeMode(false);
479 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 473 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
480 } 474 }
481 475
482 // Tests that if a user sets a display rotation that accelerometer rotation 476 // Tests that if a user sets a display rotation that accelerometer rotation
483 // becomes locked. 477 // becomes locked.
484 TEST_F(ScreenOrientationControllerTest, 478 TEST_F(ScreenOrientationControllerTest,
485 NonAccelerometerRotationChangesLockRotation) { 479 NonAccelerometerRotationChangesLockRotation) {
486 EnableMaximizeMode(true); 480 EnableMaximizeMode(true);
487 ASSERT_FALSE(RotationLocked()); 481 ASSERT_FALSE(RotationLocked());
488 SetInternalDisplayRotation(gfx::Display::ROTATE_270); 482 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
489 EXPECT_TRUE(RotationLocked()); 483 EXPECT_TRUE(RotationLocked());
490 } 484 }
491 485
492 // Tests that if a user changes the display rotation, while rotation is locked, 486 // Tests that if a user changes the display rotation, while rotation is locked,
493 // that the updates are recorded. Upon exiting maximize mode the latest user 487 // that the updates are recorded. Upon exiting maximize mode the latest user
494 // rotation should be applied. 488 // rotation should be applied.
495 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { 489 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) {
496 EnableMaximizeMode(true); 490 EnableMaximizeMode(true);
497 SetInternalDisplayRotation(gfx::Display::ROTATE_270); 491 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
498 // User sets rotation to the same rotation that the display was at when 492 // User sets rotation to the same rotation that the display was at when
499 // maximize mode was activated. 493 // maximize mode was activated.
500 SetInternalDisplayRotation(gfx::Display::ROTATE_0); 494 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
501 EnableMaximizeMode(false); 495 EnableMaximizeMode(false);
502 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 496 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
503 } 497 }
504 498
505 // Tests that when the orientation lock is set to Landscape, that rotation can 499 // Tests that when the orientation lock is set to Landscape, that rotation can
506 // be done between the two angles of the orientation. 500 // be done between the two angles of the orientation.
507 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { 501 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) {
508 scoped_ptr<content::WebContents> content(CreateWebContents()); 502 scoped_ptr<content::WebContents> content(CreateWebContents());
509 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 503 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
510 EnableMaximizeMode(true); 504 EnableMaximizeMode(true);
511 505
512 AttachAndActivateWebContents(content.get(), focus_window.get()); 506 AttachAndActivateWebContents(content.get(), focus_window.get());
513 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 507 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
514 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); 508 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
515 EXPECT_TRUE(RotationLocked()); 509 EXPECT_TRUE(RotationLocked());
516 510
517 // Inverse of orientation is allowed 511 // Inverse of orientation is allowed
518 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 512 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
519 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 513 EXPECT_EQ(gfx::Display::ROTATE_180, Rotation());
520 514
521 // Display rotations between are not allowed 515 // Display rotations between are not allowed
522 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 516 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
523 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 517 EXPECT_EQ(gfx::Display::ROTATE_180, Rotation());
524 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 518 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
525 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 519 EXPECT_EQ(gfx::Display::ROTATE_180, Rotation());
526 } 520 }
527 521
528 // Tests that when the orientation lock is set to Portrait, that rotaiton can be 522 // Tests that when the orientation lock is set to Portrait, that rotaiton can be
529 // done between the two angles of the orientation. 523 // done between the two angles of the orientation.
530 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { 524 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) {
531 scoped_ptr<content::WebContents> content(CreateWebContents()); 525 scoped_ptr<content::WebContents> content(CreateWebContents());
532 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 526 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
533 EnableMaximizeMode(true); 527 EnableMaximizeMode(true);
534 528
535 AttachAndActivateWebContents(content.get(), focus_window.get()); 529 AttachAndActivateWebContents(content.get(), focus_window.get());
536 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait); 530 delegate()->Lock(content.get(), blink::WebScreenOrientationLockPortrait);
537 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation()); 531 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
538 EXPECT_TRUE(RotationLocked()); 532 EXPECT_TRUE(RotationLocked());
539 533
540 // Inverse of orientation is allowed 534 // Inverse of orientation is allowed
541 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 535 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
542 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); 536 EXPECT_EQ(gfx::Display::ROTATE_270, Rotation());
543 537
544 // Display rotations between are not allowed 538 // Display rotations between are not allowed
545 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 539 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
546 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); 540 EXPECT_EQ(gfx::Display::ROTATE_270, Rotation());
547 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 541 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
548 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); 542 EXPECT_EQ(gfx::Display::ROTATE_270, Rotation());
549 } 543 }
550 544
551 // Tests that for an orientation lock which does not allow rotation, that the 545 // Tests that for an orientation lock which does not allow rotation, that the
552 // display rotation remains constant. 546 // display rotation remains constant.
553 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { 547 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) {
554 scoped_ptr<content::WebContents> content(CreateWebContents()); 548 scoped_ptr<content::WebContents> content(CreateWebContents());
555 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 549 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
556 EnableMaximizeMode(true); 550 EnableMaximizeMode(true);
557 551
558 AttachAndActivateWebContents(content.get(), focus_window.get()); 552 AttachAndActivateWebContents(content.get(), focus_window.get());
559 delegate()->Lock(content.get(), 553 delegate()->Lock(content.get(),
560 blink::WebScreenOrientationLockPortraitPrimary); 554 blink::WebScreenOrientationLockPortraitPrimary);
561 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation()); 555 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
562 EXPECT_TRUE(RotationLocked()); 556 EXPECT_TRUE(RotationLocked());
563 557
564 // Rotation does not change. 558 // Rotation does not change.
565 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 559 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
566 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 560 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
567 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 561 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
568 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 562 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
569 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 563 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
570 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 564 EXPECT_EQ(gfx::Display::ROTATE_90, Rotation());
571 } 565 }
572 566
573 // Tests that after a content::WebContents has applied an orientation lock which 567 // Tests that after a content::WebContents has applied an orientation lock which
574 // supports rotation, that a user rotation lock does not allow rotation. 568 // supports rotation, that a user rotation lock does not allow rotation.
575 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { 569 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) {
576 scoped_ptr<content::WebContents> content(CreateWebContents()); 570 scoped_ptr<content::WebContents> content(CreateWebContents());
577 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0)); 571 scoped_ptr<aura::Window> focus_window(CreateTestWindowInShellWithId(0));
578 EnableMaximizeMode(true); 572 EnableMaximizeMode(true);
579 573
580 AttachAndActivateWebContents(content.get(), focus_window.get()); 574 AttachAndActivateWebContents(content.get(), focus_window.get());
581 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape); 575 delegate()->Lock(content.get(), blink::WebScreenOrientationLockLandscape);
582 delegate()->Unlock(content.get()); 576 delegate()->Unlock(content.get());
583 577
584 SetRotationLocked(true); 578 SetRotationLocked(true);
585 EXPECT_TRUE(RotationLocked()); 579 EXPECT_TRUE(RotationLocked());
586 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation()); 580 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
587 581
588 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 582 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
589 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 583 EXPECT_EQ(gfx::Display::ROTATE_0, Rotation());
590 } 584 }
591 585
592 } // namespace ash 586 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698