OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/display/display_preferences.h" | 5 #include "chrome/browser/chromeos/display/display_preferences.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/content/display/screen_orientation_controller_chromeos.h" | 10 #include "ash/content/display/screen_orientation_controller_chromeos.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 LoggedInAsUser(); | 238 LoggedInAsUser(); |
239 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); | 239 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); |
240 SetCurrentDisplayLayout(layout); | 240 SetCurrentDisplayLayout(layout); |
241 StoreDisplayLayoutPrefForTest( | 241 StoreDisplayLayoutPrefForTest( |
242 id1, dummy_id, ash::DisplayLayout(ash::DisplayLayout::LEFT, 20)); | 242 id1, dummy_id, ash::DisplayLayout(ash::DisplayLayout::LEFT, 20)); |
243 // Can't switch to a display that does not exist. | 243 // Can't switch to a display that does not exist. |
244 display_controller->SetPrimaryDisplayId(dummy_id); | 244 display_controller->SetPrimaryDisplayId(dummy_id); |
245 EXPECT_NE(dummy_id, ash::Shell::GetScreen()->GetPrimaryDisplay().id()); | 245 EXPECT_NE(dummy_id, ash::Shell::GetScreen()->GetPrimaryDisplay().id()); |
246 | 246 |
247 display_controller->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); | 247 display_controller->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); |
248 display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90); | 248 display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90, |
249 gfx::Display::ROTATION_SOURCE_USER); | |
249 EXPECT_TRUE(display_manager->SetDisplayUIScale(id1, 1.25f)); | 250 EXPECT_TRUE(display_manager->SetDisplayUIScale(id1, 1.25f)); |
250 EXPECT_FALSE(display_manager->SetDisplayUIScale(id2, 1.25f)); | 251 EXPECT_FALSE(display_manager->SetDisplayUIScale(id2, 1.25f)); |
251 | 252 |
252 const base::DictionaryValue* displays = | 253 const base::DictionaryValue* displays = |
253 local_state()->GetDictionary(prefs::kSecondaryDisplays); | 254 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
254 const base::DictionaryValue* layout_value = NULL; | 255 const base::DictionaryValue* layout_value = NULL; |
255 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 256 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
256 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 257 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
257 | 258 |
258 ash::DisplayLayout stored_layout; | 259 ash::DisplayLayout stored_layout; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 .SetInternalDisplayId(id1); | 570 .SetInternalDisplayId(id1); |
570 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 571 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
571 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); | 572 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); |
572 SetCurrentDisplayLayout(layout); | 573 SetCurrentDisplayLayout(layout); |
573 display_manager->SetDisplayUIScale(id1, 1.25f); | 574 display_manager->SetDisplayUIScale(id1, 1.25f); |
574 display_controller->SetPrimaryDisplayId(id2); | 575 display_controller->SetPrimaryDisplayId(id2); |
575 int64 new_primary = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 576 int64 new_primary = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
576 display_controller->SetOverscanInsets( | 577 display_controller->SetOverscanInsets( |
577 new_primary, | 578 new_primary, |
578 gfx::Insets(10, 11, 12, 13)); | 579 gfx::Insets(10, 11, 12, 13)); |
579 display_manager->SetDisplayRotation(new_primary, gfx::Display::ROTATE_90); | 580 display_manager->SetDisplayRotation(new_primary, gfx::Display::ROTATE_90, |
581 gfx::Display::ROTATION_SOURCE_USER); | |
580 | 582 |
581 // Does not store the preferences locally. | 583 // Does not store the preferences locally. |
582 EXPECT_FALSE(local_state()->FindPreference( | 584 EXPECT_FALSE(local_state()->FindPreference( |
583 prefs::kSecondaryDisplays)->HasUserSetting()); | 585 prefs::kSecondaryDisplays)->HasUserSetting()); |
584 EXPECT_FALSE(local_state()->FindPreference( | 586 EXPECT_FALSE(local_state()->FindPreference( |
585 prefs::kDisplayProperties)->HasUserSetting()); | 587 prefs::kDisplayProperties)->HasUserSetting()); |
586 | 588 |
587 // Settings are still notified to the system. | 589 // Settings are still notified to the system. |
588 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 590 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
589 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); | 591 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); |
590 EXPECT_EQ(ash::DisplayLayout::BOTTOM, | 592 EXPECT_EQ(ash::DisplayLayout::BOTTOM, |
591 display_manager->GetCurrentDisplayLayout().position); | 593 display_manager->GetCurrentDisplayLayout().position); |
592 EXPECT_EQ(-10, display_manager->GetCurrentDisplayLayout().offset); | 594 EXPECT_EQ(-10, display_manager->GetCurrentDisplayLayout().offset); |
593 const gfx::Display& primary_display = screen->GetPrimaryDisplay(); | 595 const gfx::Display& primary_display = screen->GetPrimaryDisplay(); |
594 EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); | 596 EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); |
595 EXPECT_EQ(gfx::Display::ROTATE_90, primary_display.rotation()); | 597 EXPECT_EQ(gfx::Display::ROTATE_90, primary_display.rotation()); |
596 | 598 |
597 const ash::DisplayInfo& info1 = display_manager->GetDisplayInfo(id1); | 599 const ash::DisplayInfo& info1 = display_manager->GetDisplayInfo(id1); |
598 EXPECT_EQ(1.25f, info1.configured_ui_scale()); | 600 EXPECT_EQ(1.25f, info1.configured_ui_scale()); |
599 | 601 |
600 const ash::DisplayInfo& info_primary = | 602 const ash::DisplayInfo& info_primary = |
601 display_manager->GetDisplayInfo(new_primary); | 603 display_manager->GetDisplayInfo(new_primary); |
602 EXPECT_EQ(gfx::Display::ROTATE_90, info_primary.rotation()); | 604 EXPECT_EQ(gfx::Display::ROTATE_90, |
605 info_primary.Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE)); | |
603 EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); | 606 EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); |
604 } | 607 } |
605 | 608 |
606 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { | 609 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { |
607 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); | 610 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
608 | 611 |
609 // Stores display prefs without login, which still stores the power state. | 612 // Stores display prefs without login, which still stores the power state. |
610 StoreDisplayPrefs(); | 613 StoreDisplayPrefs(); |
611 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); | 614 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
612 } | 615 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 // Tests that display configuration changes caused by MaximizeModeController | 665 // Tests that display configuration changes caused by MaximizeModeController |
663 // are not saved. | 666 // are not saved. |
664 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { | 667 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { |
665 ash::Shell* shell = ash::Shell::GetInstance(); | 668 ash::Shell* shell = ash::Shell::GetInstance(); |
666 gfx::Display::SetInternalDisplayId( | 669 gfx::Display::SetInternalDisplayId( |
667 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 670 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
668 ash::DisplayManager* display_manager = shell->display_manager(); | 671 ash::DisplayManager* display_manager = shell->display_manager(); |
669 LoggedInAsUser(); | 672 LoggedInAsUser(); |
670 // Populate the properties. | 673 // Populate the properties. |
671 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 674 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
672 gfx::Display::ROTATE_180); | 675 gfx::Display::ROTATE_180, |
676 gfx::Display::ROTATION_SOURCE_USER); | |
673 // Reset property to avoid rotation lock | 677 // Reset property to avoid rotation lock |
674 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 678 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
675 gfx::Display::ROTATE_0); | 679 gfx::Display::ROTATE_0, |
680 gfx::Display::ROTATION_SOURCE_USER); | |
676 | 681 |
677 // Open up 270 degrees to trigger maximize mode | 682 // Open up 270 degrees to trigger maximize mode |
678 scoped_refptr<chromeos::AccelerometerUpdate> update( | 683 scoped_refptr<chromeos::AccelerometerUpdate> update( |
679 new chromeos::AccelerometerUpdate()); | 684 new chromeos::AccelerometerUpdate()); |
680 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, | 685 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, |
681 kMeanGravity); | 686 kMeanGravity); |
682 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); | 687 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); |
683 ash::MaximizeModeController* controller = shell->maximize_mode_controller(); | 688 ash::MaximizeModeController* controller = shell->maximize_mode_controller(); |
684 controller->OnAccelerometerUpdated(update); | 689 controller->OnAccelerometerUpdated(update); |
685 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); | 690 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); |
686 | 691 |
687 // Trigger 90 degree rotation | 692 // Trigger 90 degree rotation |
688 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, -kMeanGravity, | 693 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, -kMeanGravity, |
689 0.0f, 0.0f); | 694 0.0f, 0.0f); |
690 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.0f, 0.0f); | 695 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.0f, 0.0f); |
691 controller->OnAccelerometerUpdated(update); | 696 controller->OnAccelerometerUpdated(update); |
692 shell->screen_orientation_controller()->OnAccelerometerUpdated(update); | 697 shell->screen_orientation_controller()->OnAccelerometerUpdated(update); |
693 EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> | 698 EXPECT_EQ(gfx::Display::ROTATE_90, |
694 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); | 699 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
700 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE)); | |
695 | 701 |
696 const base::DictionaryValue* properties = | 702 const base::DictionaryValue* properties = |
697 local_state()->GetDictionary(prefs::kDisplayProperties); | 703 local_state()->GetDictionary(prefs::kDisplayProperties); |
698 const base::DictionaryValue* property = NULL; | 704 const base::DictionaryValue* property = NULL; |
699 EXPECT_TRUE(properties->GetDictionary( | 705 EXPECT_TRUE(properties->GetDictionary( |
700 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); | 706 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); |
701 int rotation = -1; | 707 int rotation = -1; |
702 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | 708 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
703 EXPECT_EQ(gfx::Display::ROTATE_0, rotation); | 709 EXPECT_EQ(gfx::Display::ROTATE_0, rotation); |
710 | |
711 // Trigger a save, the acceleration rotation should not be saved as the user | |
712 // rotation. | |
jonross
2015/04/10 17:54:43
Test for incorrect orientation being saved.
| |
713 StoreDisplayPrefs(); | |
714 properties = local_state()->GetDictionary(prefs::kDisplayProperties); | |
715 property = NULL; | |
716 EXPECT_TRUE(properties->GetDictionary( | |
717 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); | |
718 rotation = -1; | |
719 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | |
720 EXPECT_EQ(gfx::Display::ROTATE_0, rotation); | |
704 } | 721 } |
705 | 722 |
706 // Tests that the rotation state is saved without a user being logged in. | 723 // Tests that the rotation state is saved without a user being logged in. |
707 TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { | 724 TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { |
708 gfx::Display::SetInternalDisplayId( | 725 gfx::Display::SetInternalDisplayId( |
709 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 726 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
710 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 727 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
711 | 728 |
712 bool current_rotation_lock = IsRotationLocked(); | 729 bool current_rotation_lock = IsRotationLocked(); |
713 StoreDisplayRotationPrefs(current_rotation_lock); | 730 StoreDisplayRotationPrefs(current_rotation_lock); |
714 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 731 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
715 | 732 |
716 const base::DictionaryValue* properties = | 733 const base::DictionaryValue* properties = |
717 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 734 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
718 bool rotation_lock; | 735 bool rotation_lock; |
719 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 736 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
720 EXPECT_EQ(current_rotation_lock, rotation_lock); | 737 EXPECT_EQ(current_rotation_lock, rotation_lock); |
721 | 738 |
722 int orientation; | 739 int orientation; |
723 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 740 gfx::Display::Rotation current_rotation = |
724 display_manager()-> | 741 ash::Shell::GetInstance() |
725 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 742 ->display_manager() |
743 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) | |
744 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE); | |
726 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 745 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
727 EXPECT_EQ(current_rotation, orientation); | 746 EXPECT_EQ(current_rotation, orientation); |
728 } | 747 } |
729 | 748 |
730 // Tests that the rotation state is saved when a guest is logged in. | 749 // Tests that the rotation state is saved when a guest is logged in. |
731 TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { | 750 TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { |
732 gfx::Display::SetInternalDisplayId( | 751 gfx::Display::SetInternalDisplayId( |
733 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 752 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
734 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 753 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
735 LoggedInAsGuest(); | 754 LoggedInAsGuest(); |
736 | 755 |
737 bool current_rotation_lock = IsRotationLocked(); | 756 bool current_rotation_lock = IsRotationLocked(); |
738 StoreDisplayRotationPrefs(current_rotation_lock); | 757 StoreDisplayRotationPrefs(current_rotation_lock); |
739 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 758 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
740 | 759 |
741 const base::DictionaryValue* properties = | 760 const base::DictionaryValue* properties = |
742 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 761 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
743 bool rotation_lock; | 762 bool rotation_lock; |
744 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 763 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
745 EXPECT_EQ(current_rotation_lock, rotation_lock); | 764 EXPECT_EQ(current_rotation_lock, rotation_lock); |
746 | 765 |
747 int orientation; | 766 int orientation; |
748 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 767 gfx::Display::Rotation current_rotation = |
749 display_manager()-> | 768 ash::Shell::GetInstance() |
750 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 769 ->display_manager() |
770 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) | |
771 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE); | |
751 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 772 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
752 EXPECT_EQ(current_rotation, orientation); | 773 EXPECT_EQ(current_rotation, orientation); |
753 } | 774 } |
754 | 775 |
755 // Tests that the rotation state is saved when a normal user is logged in. | 776 // Tests that the rotation state is saved when a normal user is logged in. |
756 TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { | 777 TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { |
757 gfx::Display::SetInternalDisplayId( | 778 gfx::Display::SetInternalDisplayId( |
758 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 779 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
759 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 780 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
760 LoggedInAsGuest(); | 781 LoggedInAsGuest(); |
761 | 782 |
762 bool current_rotation_lock = IsRotationLocked(); | 783 bool current_rotation_lock = IsRotationLocked(); |
763 StoreDisplayRotationPrefs(current_rotation_lock); | 784 StoreDisplayRotationPrefs(current_rotation_lock); |
764 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 785 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
765 | 786 |
766 const base::DictionaryValue* properties = | 787 const base::DictionaryValue* properties = |
767 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 788 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
768 bool rotation_lock; | 789 bool rotation_lock; |
769 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 790 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
770 EXPECT_EQ(current_rotation_lock, rotation_lock); | 791 EXPECT_EQ(current_rotation_lock, rotation_lock); |
771 | 792 |
772 int orientation; | 793 int orientation; |
773 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 794 gfx::Display::Rotation current_rotation = |
774 display_manager()-> | 795 ash::Shell::GetInstance() |
775 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 796 ->display_manager() |
797 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) | |
798 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE); | |
776 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 799 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
777 EXPECT_EQ(current_rotation, orientation); | 800 EXPECT_EQ(current_rotation, orientation); |
778 } | 801 } |
779 | 802 |
780 // Tests that rotation state is loaded without a user being logged in, and that | 803 // Tests that rotation state is loaded without a user being logged in, and that |
781 // entering maximize mode applies the state. | 804 // entering maximize mode applies the state. |
782 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { | 805 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { |
783 gfx::Display::SetInternalDisplayId( | 806 gfx::Display::SetInternalDisplayId( |
784 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 807 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
785 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 808 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
786 | 809 |
787 ash::Shell* shell = ash::Shell::GetInstance(); | 810 ash::Shell* shell = ash::Shell::GetInstance(); |
788 bool initial_rotation_lock = IsRotationLocked(); | 811 bool initial_rotation_lock = IsRotationLocked(); |
789 ASSERT_FALSE(initial_rotation_lock); | 812 ASSERT_FALSE(initial_rotation_lock); |
790 ash::DisplayManager* display_manager = shell->display_manager(); | 813 ash::DisplayManager* display_manager = shell->display_manager(); |
791 gfx::Display::Rotation initial_rotation = display_manager-> | 814 gfx::Display::Rotation initial_rotation = |
792 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 815 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
816 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE); | |
793 ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); | 817 ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); |
794 | 818 |
795 StoreDisplayRotationPrefs(initial_rotation_lock); | 819 StoreDisplayRotationPrefs(initial_rotation_lock); |
796 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 820 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
797 | 821 |
798 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); | 822 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); |
799 LoadDisplayPreferences(false); | 823 LoadDisplayPreferences(false); |
800 | 824 |
801 bool display_rotation_lock = | 825 bool display_rotation_lock = |
802 display_manager->registered_internal_display_rotation_lock(); | 826 display_manager->registered_internal_display_rotation_lock(); |
803 bool display_rotation = | 827 bool display_rotation = |
804 display_manager->registered_internal_display_rotation(); | 828 display_manager->registered_internal_display_rotation(); |
805 EXPECT_TRUE(display_rotation_lock); | 829 EXPECT_TRUE(display_rotation_lock); |
806 EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); | 830 EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); |
807 | 831 |
808 bool rotation_lock = IsRotationLocked(); | 832 bool rotation_lock = IsRotationLocked(); |
809 gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> | 833 gfx::Display::Rotation before_maximize_mode_rotation = |
810 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 834 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
835 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE); | |
811 | 836 |
812 // Settings should not be applied until maximize mode activates | 837 // Settings should not be applied until maximize mode activates |
813 EXPECT_FALSE(rotation_lock); | 838 EXPECT_FALSE(rotation_lock); |
814 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); | 839 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); |
815 | 840 |
816 // Open up 270 degrees to trigger maximize mode | 841 // Open up 270 degrees to trigger maximize mode |
817 scoped_refptr<chromeos::AccelerometerUpdate> update( | 842 scoped_refptr<chromeos::AccelerometerUpdate> update( |
818 new chromeos::AccelerometerUpdate()); | 843 new chromeos::AccelerometerUpdate()); |
819 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, | 844 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, |
820 kMeanGravity); | 845 kMeanGravity); |
821 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); | 846 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); |
822 ash::MaximizeModeController* maximize_mode_controller = | 847 ash::MaximizeModeController* maximize_mode_controller = |
823 shell->maximize_mode_controller(); | 848 shell->maximize_mode_controller(); |
824 maximize_mode_controller->OnAccelerometerUpdated(update); | 849 maximize_mode_controller->OnAccelerometerUpdated(update); |
825 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 850 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); |
826 bool screen_orientation_rotation_lock = IsRotationLocked(); | 851 bool screen_orientation_rotation_lock = IsRotationLocked(); |
827 gfx::Display::Rotation maximize_mode_rotation = display_manager-> | 852 gfx::Display::Rotation maximize_mode_rotation = |
828 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 853 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
854 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE); | |
829 EXPECT_TRUE(screen_orientation_rotation_lock); | 855 EXPECT_TRUE(screen_orientation_rotation_lock); |
830 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); | 856 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); |
831 } | 857 } |
832 | 858 |
833 // Tests that rotation lock being set causes the rotation state to be saved. | 859 // Tests that rotation lock being set causes the rotation state to be saved. |
834 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { | 860 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { |
835 gfx::Display::SetInternalDisplayId( | 861 gfx::Display::SetInternalDisplayId( |
836 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 862 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
837 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 863 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
838 | 864 |
839 ash::Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | 865 ash::Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( |
840 true); | 866 true); |
841 | 867 |
842 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 868 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
843 | 869 |
844 const base::DictionaryValue* properties = | 870 const base::DictionaryValue* properties = |
845 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 871 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
846 bool rotation_lock; | 872 bool rotation_lock; |
847 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 873 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
848 } | 874 } |
849 | 875 |
850 } // namespace chromeos | 876 } // namespace chromeos |
OLD | NEW |