| OLD | NEW |
| 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/screen_orientation_controller_chromeos.h" | 12 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 13 #include "ash/shared/app_types.h" | 13 #include "ash/shared/app_types.h" |
| 14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/system/screen_layout_observer.h" | 15 #include "ash/system/screen_layout_observer.h" |
| 16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/test/ash_test_environment_content.h" | 17 #include "ash/test/ash_test_environment_content.h" |
| 18 #include "ash/test/ash_test_helper.h" | 18 #include "ash/test/ash_test_helper.h" |
| 19 #include "ash/test/content/test_shell_content_state.h" | 19 #include "ash/test/content/test_shell_content_state.h" |
| 20 #include "ash/test/screen_orientation_controller_test_api.h" | 20 #include "ash/test/screen_orientation_controller_test_api.h" |
| 21 #include "ash/test/test_shell_delegate.h" | 21 #include "ash/test/test_shell_delegate.h" |
| 22 #include "ash/test/test_system_tray_delegate.h" | 22 #include "ash/test/test_system_tray_delegate.h" |
| 23 #include "ash/wm/tablet_mode/tablet_mode_controller.h" | 23 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 24 #include "ash/wm/window_state.h" | 24 #include "ash/wm/window_state.h" |
| 25 #include "ash/wm_window.h" | 25 #include "ash/wm_window.h" |
| 26 #include "base/command_line.h" | 26 #include "base/command_line.h" |
| 27 #include "chromeos/accelerometer/accelerometer_reader.h" | 27 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 28 #include "chromeos/accelerometer/accelerometer_types.h" | 28 #include "chromeos/accelerometer/accelerometer_types.h" |
| 29 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/test/test_browser_context.h" | 31 #include "content/public/test/test_browser_context.h" |
| 32 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | 32 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
| 33 #include "ui/aura/window.h" | 33 #include "ui/aura/window.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 49 const float kDegreesToRadians = 3.1415926f / 180.0f; | 49 const float kDegreesToRadians = 3.1415926f / 180.0f; |
| 50 const float kMeanGravity = -9.8066f; | 50 const float kMeanGravity = -9.8066f; |
| 51 | 51 |
| 52 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id, | 52 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id, |
| 53 const gfx::Rect& bounds) { | 53 const gfx::Rect& bounds) { |
| 54 display::ManagedDisplayInfo info(id, "dummy", false); | 54 display::ManagedDisplayInfo info(id, "dummy", false); |
| 55 info.SetBounds(bounds); | 55 info.SetBounds(bounds); |
| 56 return info; | 56 return info; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void EnableTabletMode(bool enable) { | 59 void EnableMaximizeMode(bool enable) { |
| 60 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(enable); | 60 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 61 enable); |
| 61 } | 62 } |
| 62 | 63 |
| 63 bool RotationLocked() { | 64 bool RotationLocked() { |
| 64 return Shell::Get()->screen_orientation_controller()->rotation_locked(); | 65 return Shell::Get()->screen_orientation_controller()->rotation_locked(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 bool UserRotationLocked() { | 68 bool UserRotationLocked() { |
| 68 return Shell::Get()->screen_orientation_controller()->user_rotation_locked(); | 69 return Shell::Get()->screen_orientation_controller()->user_rotation_locked(); |
| 69 } | 70 } |
| 70 | 71 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 activation_client->ActivateWindow(focus_window2.get()); | 353 activation_client->ActivateWindow(focus_window2.get()); |
| 353 EXPECT_FALSE(RotationLocked()); | 354 EXPECT_FALSE(RotationLocked()); |
| 354 | 355 |
| 355 activation_client->ActivateWindow(focus_window1.get()); | 356 activation_client->ActivateWindow(focus_window1.get()); |
| 356 EXPECT_FALSE(RotationLocked()); | 357 EXPECT_FALSE(RotationLocked()); |
| 357 } | 358 } |
| 358 | 359 |
| 359 // Tests that accelerometer readings in each of the screen angles will trigger a | 360 // Tests that accelerometer readings in each of the screen angles will trigger a |
| 360 // rotation of the internal display. | 361 // rotation of the internal display. |
| 361 TEST_F(ScreenOrientationControllerTest, DisplayRotation) { | 362 TEST_F(ScreenOrientationControllerTest, DisplayRotation) { |
| 362 EnableTabletMode(true); | 363 EnableMaximizeMode(true); |
| 363 // Now test rotating in all directions. | 364 // Now test rotating in all directions. |
| 364 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 365 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
| 365 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 366 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 366 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 367 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 367 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 368 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 368 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 369 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
| 369 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 370 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 370 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 371 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
| 371 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 372 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 372 } | 373 } |
| 373 | 374 |
| 374 // Tests that low angles are ignored by the accelerometer (i.e. when the device | 375 // Tests that low angles are ignored by the accelerometer (i.e. when the device |
| 375 // is almost laying flat). | 376 // is almost laying flat). |
| 376 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) { | 377 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) { |
| 377 EnableTabletMode(true); | 378 EnableMaximizeMode(true); |
| 378 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); | 379 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); |
| 379 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 380 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 380 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); | 381 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); |
| 381 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 382 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 382 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); | 383 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); |
| 383 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 384 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 384 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); | 385 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); |
| 385 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 386 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 386 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); | 387 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); |
| 387 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 388 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 388 } | 389 } |
| 389 | 390 |
| 390 // Tests that the display will stick to the current orientation beyond the | 391 // Tests that the display will stick to the current orientation beyond the |
| 391 // halfway point, preventing frequent updates back and forth. | 392 // halfway point, preventing frequent updates back and forth. |
| 392 TEST_F(ScreenOrientationControllerTest, RotationSticky) { | 393 TEST_F(ScreenOrientationControllerTest, RotationSticky) { |
| 393 EnableTabletMode(true); | 394 EnableMaximizeMode(true); |
| 394 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); | 395 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); |
| 395 TriggerLidUpdate(gravity); | 396 TriggerLidUpdate(gravity); |
| 396 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 397 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 397 | 398 |
| 398 // Turn past half-way point to next direction and rotation should remain | 399 // Turn past half-way point to next direction and rotation should remain |
| 399 // the same. | 400 // the same. |
| 400 float degrees = 50.0; | 401 float degrees = 50.0; |
| 401 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); | 402 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); |
| 402 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); | 403 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); |
| 403 TriggerLidUpdate(gravity); | 404 TriggerLidUpdate(gravity); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 415 degrees = 40.0; | 416 degrees = 40.0; |
| 416 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); | 417 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); |
| 417 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); | 418 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); |
| 418 TriggerLidUpdate(gravity); | 419 TriggerLidUpdate(gravity); |
| 419 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 420 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 420 } | 421 } |
| 421 | 422 |
| 422 // Tests that the display will stick to its current orientation when the | 423 // Tests that the display will stick to its current orientation when the |
| 423 // rotation lock has been set. | 424 // rotation lock has been set. |
| 424 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { | 425 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { |
| 425 EnableTabletMode(true); | 426 EnableMaximizeMode(true); |
| 426 SetUserRotationLocked(true); | 427 SetUserRotationLocked(true); |
| 427 | 428 |
| 428 // Turn past the threshold for rotation. | 429 // Turn past the threshold for rotation. |
| 429 float degrees = 90.0; | 430 float degrees = 90.0; |
| 430 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity, | 431 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity, |
| 431 -cos(degrees * kDegreesToRadians) * kMeanGravity, | 432 -cos(degrees * kDegreesToRadians) * kMeanGravity, |
| 432 0.0f); | 433 0.0f); |
| 433 TriggerLidUpdate(gravity); | 434 TriggerLidUpdate(gravity); |
| 434 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 435 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 435 | 436 |
| 436 SetUserRotationLocked(false); | 437 SetUserRotationLocked(false); |
| 437 TriggerLidUpdate(gravity); | 438 TriggerLidUpdate(gravity); |
| 438 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 439 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 439 } | 440 } |
| 440 | 441 |
| 441 // The ScreenLayoutObserver class that is responsible for adding/updating | 442 // The ScreenLayoutObserver class that is responsible for adding/updating |
| 442 // MessageCenter notifications is only added to the SystemTray on ChromeOS. | 443 // MessageCenter notifications is only added to the SystemTray on ChromeOS. |
| 443 // Tests that the screen rotation notifications are suppressed when | 444 // Tests that the screen rotation notifications are suppressed when |
| 444 // triggered by the accelerometer. | 445 // triggered by the accelerometer. |
| 445 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { | 446 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { |
| 446 EnableTabletMode(true); | 447 EnableMaximizeMode(true); |
| 447 Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing( | 448 Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing( |
| 448 true); | 449 true); |
| 449 display::test::DisplayManagerTestApi(display_manager()) | 450 display::test::DisplayManagerTestApi(display_manager()) |
| 450 .SetFirstDisplayAsInternalDisplay(); | 451 .SetFirstDisplayAsInternalDisplay(); |
| 451 | 452 |
| 452 message_center::MessageCenter* message_center = | 453 message_center::MessageCenter* message_center = |
| 453 message_center::MessageCenter::Get(); | 454 message_center::MessageCenter::Get(); |
| 454 | 455 |
| 455 EXPECT_EQ(0u, message_center->NotificationCount()); | 456 EXPECT_EQ(0u, message_center->NotificationCount()); |
| 456 EXPECT_FALSE(message_center->HasPopupNotifications()); | 457 EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 457 | 458 |
| 458 // Make sure notifications are still displayed when | 459 // Make sure notifications are still displayed when |
| 459 // adjusting the screen rotation directly when in tablet mode | 460 // adjusting the screen rotation directly when in maximize mode |
| 460 ASSERT_NE(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 461 ASSERT_NE(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 461 SetInternalDisplayRotation(display::Display::ROTATE_270); | 462 SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 462 SetSystemRotationLocked(false); | 463 SetSystemRotationLocked(false); |
| 463 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 464 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 464 EXPECT_EQ(1u, message_center->NotificationCount()); | 465 EXPECT_EQ(1u, message_center->NotificationCount()); |
| 465 EXPECT_TRUE(message_center->HasPopupNotifications()); | 466 EXPECT_TRUE(message_center->HasPopupNotifications()); |
| 466 | 467 |
| 467 // Clear all notifications | 468 // Clear all notifications |
| 468 message_center->RemoveAllNotifications( | 469 message_center->RemoveAllNotifications( |
| 469 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); | 470 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); |
| 470 EXPECT_EQ(0u, message_center->NotificationCount()); | 471 EXPECT_EQ(0u, message_center->NotificationCount()); |
| 471 EXPECT_FALSE(message_center->HasPopupNotifications()); | 472 EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 472 | 473 |
| 473 // Make sure notifications are blocked when adjusting the screen rotation | 474 // Make sure notifications are blocked when adjusting the screen rotation |
| 474 // via the accelerometer while in tablet mode | 475 // via the accelerometer while in maximize mode |
| 475 // Rotate the screen 90 degrees | 476 // Rotate the screen 90 degrees |
| 476 ASSERT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 477 ASSERT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 477 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 478 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
| 478 ASSERT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 479 ASSERT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 479 EXPECT_EQ(0u, message_center->NotificationCount()); | 480 EXPECT_EQ(0u, message_center->NotificationCount()); |
| 480 EXPECT_FALSE(message_center->HasPopupNotifications()); | 481 EXPECT_FALSE(message_center->HasPopupNotifications()); |
| 481 | 482 |
| 482 // Make sure notifications are still displayed when | 483 // Make sure notifications are still displayed when |
| 483 // adjusting the screen rotation directly when not in tablet mode | 484 // adjusting the screen rotation directly when not in maximize mode |
| 484 EnableTabletMode(false); | 485 EnableMaximizeMode(false); |
| 485 // Reset the screen rotation. | 486 // Reset the screen rotation. |
| 486 SetInternalDisplayRotation(display::Display::ROTATE_0); | 487 SetInternalDisplayRotation(display::Display::ROTATE_0); |
| 487 // Clear all notifications | 488 // Clear all notifications |
| 488 message_center->RemoveAllNotifications( | 489 message_center->RemoveAllNotifications( |
| 489 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); | 490 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); |
| 490 ASSERT_NE(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 491 ASSERT_NE(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 491 ASSERT_EQ(0u, message_center->NotificationCount()); | 492 ASSERT_EQ(0u, message_center->NotificationCount()); |
| 492 ASSERT_FALSE(message_center->HasPopupNotifications()); | 493 ASSERT_FALSE(message_center->HasPopupNotifications()); |
| 493 SetInternalDisplayRotation(display::Display::ROTATE_180); | 494 SetInternalDisplayRotation(display::Display::ROTATE_180); |
| 494 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 495 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 495 EXPECT_EQ(1u, message_center->NotificationCount()); | 496 EXPECT_EQ(1u, message_center->NotificationCount()); |
| 496 EXPECT_TRUE(message_center->HasPopupNotifications()); | 497 EXPECT_TRUE(message_center->HasPopupNotifications()); |
| 497 } | 498 } |
| 498 | 499 |
| 499 // Tests that if a user has set a display rotation that it is restored upon | 500 // Tests that if a user has set a display rotation that it is restored upon |
| 500 // exiting tablet mode. | 501 // exiting maximize mode. |
| 501 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) { | 502 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) { |
| 502 display::test::DisplayManagerTestApi(display_manager()) | 503 display::test::DisplayManagerTestApi(display_manager()) |
| 503 .SetFirstDisplayAsInternalDisplay(); | 504 .SetFirstDisplayAsInternalDisplay(); |
| 504 | 505 |
| 505 SetInternalDisplayRotation(display::Display::ROTATE_90); | 506 SetInternalDisplayRotation(display::Display::ROTATE_90); |
| 506 EnableTabletMode(true); | 507 EnableMaximizeMode(true); |
| 507 | 508 |
| 508 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 509 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 509 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 510 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 510 | 511 |
| 511 EnableTabletMode(false); | 512 EnableMaximizeMode(false); |
| 512 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 513 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 513 } | 514 } |
| 514 | 515 |
| 515 // Tests that if a user sets a display rotation that accelerometer rotation | 516 // Tests that if a user sets a display rotation that accelerometer rotation |
| 516 // becomes locked. | 517 // becomes locked. |
| 517 TEST_F(ScreenOrientationControllerTest, | 518 TEST_F(ScreenOrientationControllerTest, |
| 518 NonAccelerometerRotationChangesLockRotation) { | 519 NonAccelerometerRotationChangesLockRotation) { |
| 519 EnableTabletMode(true); | 520 EnableMaximizeMode(true); |
| 520 ASSERT_FALSE(RotationLocked()); | 521 ASSERT_FALSE(RotationLocked()); |
| 521 SetInternalDisplayRotation(display::Display::ROTATE_270); | 522 SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 522 EXPECT_TRUE(RotationLocked()); | 523 EXPECT_TRUE(RotationLocked()); |
| 523 } | 524 } |
| 524 | 525 |
| 525 // Tests that if a user changes the display rotation, while rotation is locked, | 526 // Tests that if a user changes the display rotation, while rotation is locked, |
| 526 // that the updates are recorded. Upon exiting tablet mode the latest user | 527 // that the updates are recorded. Upon exiting maximize mode the latest user |
| 527 // rotation should be applied. | 528 // rotation should be applied. |
| 528 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { | 529 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { |
| 529 EnableTabletMode(true); | 530 EnableMaximizeMode(true); |
| 530 SetInternalDisplayRotation(display::Display::ROTATE_270); | 531 SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 531 // User sets rotation to the same rotation that the display was at when | 532 // User sets rotation to the same rotation that the display was at when |
| 532 // tablet mode was activated. | 533 // maximize mode was activated. |
| 533 SetInternalDisplayRotation(display::Display::ROTATE_0); | 534 SetInternalDisplayRotation(display::Display::ROTATE_0); |
| 534 EnableTabletMode(false); | 535 EnableMaximizeMode(false); |
| 535 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 536 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 536 } | 537 } |
| 537 | 538 |
| 538 // Tests that when the orientation lock is set to Landscape, that rotation can | 539 // Tests that when the orientation lock is set to Landscape, that rotation can |
| 539 // be done between the two angles of the orientation. | 540 // be done between the two angles of the orientation. |
| 540 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { | 541 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { |
| 541 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 542 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 542 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); | 543 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
| 543 EnableTabletMode(true); | 544 EnableMaximizeMode(true); |
| 544 | 545 |
| 545 AttachAndActivateWebContents(content.get(), focus_window.get()); | 546 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 546 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); | 547 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); |
| 547 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 548 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 548 EXPECT_TRUE(RotationLocked()); | 549 EXPECT_TRUE(RotationLocked()); |
| 549 | 550 |
| 550 // Inverse of orientation is allowed | 551 // Inverse of orientation is allowed |
| 551 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 552 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 552 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 553 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 553 | 554 |
| 554 // Display rotations between are not allowed | 555 // Display rotations between are not allowed |
| 555 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 556 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
| 556 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 557 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 557 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); | 558 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); |
| 558 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 559 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 559 } | 560 } |
| 560 | 561 |
| 561 // Tests that when the orientation lock is set to Portrait, that rotaiton can be | 562 // Tests that when the orientation lock is set to Portrait, that rotaiton can be |
| 562 // done between the two angles of the orientation. | 563 // done between the two angles of the orientation. |
| 563 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { | 564 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { |
| 564 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 565 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 565 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); | 566 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
| 566 EnableTabletMode(true); | 567 EnableMaximizeMode(true); |
| 567 | 568 |
| 568 AttachAndActivateWebContents(content.get(), focus_window.get()); | 569 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 569 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockPortrait); | 570 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockPortrait); |
| 570 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 571 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 571 EXPECT_TRUE(RotationLocked()); | 572 EXPECT_TRUE(RotationLocked()); |
| 572 | 573 |
| 573 // Inverse of orientation is allowed | 574 // Inverse of orientation is allowed |
| 574 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 575 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
| 575 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 576 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 576 | 577 |
| 577 // Display rotations between are not allowed | 578 // Display rotations between are not allowed |
| 578 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 579 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 579 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 580 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 580 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 581 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
| 581 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); | 582 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); |
| 582 } | 583 } |
| 583 | 584 |
| 584 // Tests that for an orientation lock which does not allow rotation, that the | 585 // Tests that for an orientation lock which does not allow rotation, that the |
| 585 // display rotation remains constant. | 586 // display rotation remains constant. |
| 586 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { | 587 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { |
| 587 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 588 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 588 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); | 589 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
| 589 EnableTabletMode(true); | 590 EnableMaximizeMode(true); |
| 590 | 591 |
| 591 AttachAndActivateWebContents(content.get(), focus_window.get()); | 592 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 592 delegate()->Lock(content.get(), | 593 delegate()->Lock(content.get(), |
| 593 blink::kWebScreenOrientationLockPortraitPrimary); | 594 blink::kWebScreenOrientationLockPortraitPrimary); |
| 594 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 595 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 595 EXPECT_TRUE(RotationLocked()); | 596 EXPECT_TRUE(RotationLocked()); |
| 596 | 597 |
| 597 // Rotation does not change. | 598 // Rotation does not change. |
| 598 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); | 599 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); |
| 599 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 600 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 600 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 601 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 601 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 602 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 602 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); | 603 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); |
| 603 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 604 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 604 } | 605 } |
| 605 | 606 |
| 606 // Tests that after a content::WebContents has applied an orientation lock which | 607 // Tests that after a content::WebContents has applied an orientation lock which |
| 607 // supports rotation, that a user rotation lock does not allow rotation. | 608 // supports rotation, that a user rotation lock does not allow rotation. |
| 608 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { | 609 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { |
| 609 std::unique_ptr<content::WebContents> content(CreateWebContents()); | 610 std::unique_ptr<content::WebContents> content(CreateWebContents()); |
| 610 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); | 611 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); |
| 611 EnableTabletMode(true); | 612 EnableMaximizeMode(true); |
| 612 | 613 |
| 613 AttachAndActivateWebContents(content.get(), focus_window.get()); | 614 AttachAndActivateWebContents(content.get(), focus_window.get()); |
| 614 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); | 615 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); |
| 615 delegate()->Unlock(content.get()); | 616 delegate()->Unlock(content.get()); |
| 616 | 617 |
| 617 SetUserRotationLocked(true); | 618 SetUserRotationLocked(true); |
| 618 EXPECT_TRUE(RotationLocked()); | 619 EXPECT_TRUE(RotationLocked()); |
| 619 EXPECT_TRUE(UserRotationLocked()); | 620 EXPECT_TRUE(UserRotationLocked()); |
| 620 | 621 |
| 621 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 622 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 622 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 623 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 623 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 624 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 624 } | 625 } |
| 625 | 626 |
| 626 // Tests that when TabletMode is triggered before the internal display is | 627 // Tests that when MaximizeMode is triggered before the internal display is |
| 627 // ready, that ScreenOrientationController still begins listening to events, | 628 // ready, that ScreenOrientationController still begins listening to events, |
| 628 // which require an internal display to be acted upon. | 629 // which require an internal display to be acted upon. |
| 629 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { | 630 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { |
| 630 display::test::DisplayManagerTestApi(display_manager()) | 631 display::test::DisplayManagerTestApi(display_manager()) |
| 631 .SetFirstDisplayAsInternalDisplay(); | 632 .SetFirstDisplayAsInternalDisplay(); |
| 632 | 633 |
| 633 int64_t internal_display_id = display::Display::InternalDisplayId(); | 634 int64_t internal_display_id = display::Display::InternalDisplayId(); |
| 634 display::Display::SetInternalDisplayId(display::kInvalidDisplayId); | 635 display::Display::SetInternalDisplayId(display::kInvalidDisplayId); |
| 635 | 636 |
| 636 EnableTabletMode(true); | 637 EnableMaximizeMode(true); |
| 637 | 638 |
| 638 // Should not crash, even though there is no internal display. | 639 // Should not crash, even though there is no internal display. |
| 639 SetDisplayRotationById(internal_display_id, display::Display::ROTATE_180); | 640 SetDisplayRotationById(internal_display_id, display::Display::ROTATE_180); |
| 640 EXPECT_FALSE(RotationLocked()); | 641 EXPECT_FALSE(RotationLocked()); |
| 641 | 642 |
| 642 // Should not crash, even though the invalid display id is requested. | 643 // Should not crash, even though the invalid display id is requested. |
| 643 SetDisplayRotationById(display::kInvalidDisplayId, | 644 SetDisplayRotationById(display::kInvalidDisplayId, |
| 644 display::Display::ROTATE_180); | 645 display::Display::ROTATE_180); |
| 645 EXPECT_FALSE(RotationLocked()); | 646 EXPECT_FALSE(RotationLocked()); |
| 646 | 647 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockLandscape); | 792 delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockLandscape); |
| 792 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 793 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 793 | 794 |
| 794 delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockAny); | 795 delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockAny); |
| 795 activation_client->ActivateWindow(focus_window1.get()); | 796 activation_client->ActivateWindow(focus_window1.get()); |
| 796 // Switching back to any will rotate to user rotation. | 797 // Switching back to any will rotate to user rotation. |
| 797 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 798 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 798 } | 799 } |
| 799 | 800 |
| 800 } // namespace ash | 801 } // namespace ash |
| OLD | NEW |