| 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" |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 SetInternalDisplayRotation(display::Display::ROTATE_90); | 503 SetInternalDisplayRotation(display::Display::ROTATE_90); |
| 504 EnableMaximizeMode(true); | 504 EnableMaximizeMode(true); |
| 505 | 505 |
| 506 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 506 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 507 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); | 507 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); |
| 508 | 508 |
| 509 EnableMaximizeMode(false); | 509 EnableMaximizeMode(false); |
| 510 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 510 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 511 } | 511 } |
| 512 | 512 |
| 513 // Tests that if a user sets a display rotation that accelerometer rotation | |
| 514 // becomes locked. | |
| 515 TEST_F(ScreenOrientationControllerTest, | |
| 516 NonAccelerometerRotationChangesLockRotation) { | |
| 517 EnableMaximizeMode(true); | |
| 518 ASSERT_FALSE(RotationLocked()); | |
| 519 SetInternalDisplayRotation(display::Display::ROTATE_270); | |
| 520 EXPECT_TRUE(RotationLocked()); | |
| 521 } | |
| 522 | |
| 523 // Tests that if a user changes the display rotation, while rotation is locked, | 513 // Tests that if a user changes the display rotation, while rotation is locked, |
| 524 // that the updates are recorded. Upon exiting maximize mode the latest user | 514 // that the updates are recorded. Upon exiting maximize mode the latest user |
| 525 // rotation should be applied. | 515 // rotation should be applied. |
| 526 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { | 516 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { |
| 527 EnableMaximizeMode(true); | 517 EnableMaximizeMode(true); |
| 528 SetInternalDisplayRotation(display::Display::ROTATE_270); | 518 SetInternalDisplayRotation(display::Display::ROTATE_270); |
| 529 // User sets rotation to the same rotation that the display was at when | 519 // User sets rotation to the same rotation that the display was at when |
| 530 // maximize mode was activated. | 520 // maximize mode was activated. |
| 531 SetInternalDisplayRotation(display::Display::ROTATE_0); | 521 SetInternalDisplayRotation(display::Display::ROTATE_0); |
| 532 EnableMaximizeMode(false); | 522 EnableMaximizeMode(false); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 604 |
| 615 SetUserRotationLocked(true); | 605 SetUserRotationLocked(true); |
| 616 EXPECT_TRUE(RotationLocked()); | 606 EXPECT_TRUE(RotationLocked()); |
| 617 EXPECT_TRUE(UserRotationLocked()); | 607 EXPECT_TRUE(UserRotationLocked()); |
| 618 | 608 |
| 619 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 609 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 620 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); | 610 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); |
| 621 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 611 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 622 } | 612 } |
| 623 | 613 |
| 624 // Tests that when MaximizeMode is triggered before the internal display is | |
| 625 // ready, that ScreenOrientationController still begins listening to events, | |
| 626 // which require an internal display to be acted upon. | |
| 627 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { | |
| 628 display::test::DisplayManagerTestApi(display_manager()) | |
| 629 .SetFirstDisplayAsInternalDisplay(); | |
| 630 | |
| 631 int64_t internal_display_id = display::Display::InternalDisplayId(); | |
| 632 display::Display::SetInternalDisplayId(display::kInvalidDisplayId); | |
| 633 | |
| 634 EnableMaximizeMode(true); | |
| 635 | |
| 636 // Should not crash, even though there is no internal display. | |
| 637 SetDisplayRotationById(internal_display_id, display::Display::ROTATE_180); | |
| 638 EXPECT_FALSE(RotationLocked()); | |
| 639 | |
| 640 // Should not crash, even though the invalid display id is requested. | |
| 641 SetDisplayRotationById(display::kInvalidDisplayId, | |
| 642 display::Display::ROTATE_180); | |
| 643 EXPECT_FALSE(RotationLocked()); | |
| 644 | |
| 645 // With an internal display now available, functionality should resume. | |
| 646 display::Display::SetInternalDisplayId(internal_display_id); | |
| 647 SetInternalDisplayRotation(display::Display::ROTATE_90); | |
| 648 EXPECT_TRUE(RotationLocked()); | |
| 649 } | |
| 650 | |
| 651 // Verifies rotating an inactive Display is successful. | 614 // Verifies rotating an inactive Display is successful. |
| 652 TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) { | 615 TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) { |
| 653 const int64_t kInternalDisplayId = 9; | 616 const int64_t kInternalDisplayId = 9; |
| 654 const int64_t kExternalDisplayId = 10; | 617 const int64_t kExternalDisplayId = 10; |
| 655 const display::Display::Rotation kNewRotation = display::Display::ROTATE_180; | 618 const display::Display::Rotation kNewRotation = display::Display::ROTATE_180; |
| 656 | 619 |
| 657 const display::ManagedDisplayInfo internal_display_info = | 620 const display::ManagedDisplayInfo internal_display_info = |
| 658 CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 500, 500)); | 621 CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 500, 500)); |
| 659 const display::ManagedDisplayInfo external_display_info = | 622 const display::ManagedDisplayInfo external_display_info = |
| 660 CreateDisplayInfo(kExternalDisplayId, gfx::Rect(1, 1, 500, 500)); | 623 CreateDisplayInfo(kExternalDisplayId, gfx::Rect(1, 1, 500, 500)); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockLandscape); | 751 delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockLandscape); |
| 789 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 752 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 790 | 753 |
| 791 delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockAny); | 754 delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockAny); |
| 792 activation_client->ActivateWindow(focus_window1.get()); | 755 activation_client->ActivateWindow(focus_window1.get()); |
| 793 // Switching back to any will rotate to user rotation. | 756 // Switching back to any will rotate to user rotation. |
| 794 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 757 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 795 } | 758 } |
| 796 | 759 |
| 797 } // namespace ash | 760 } // namespace ash |
| OLD | NEW |