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

Side by Side Diff: chrome/browser/chromeos/display/display_preferences_unittest.cc

Issue 1071353003: Prevent DisplayPreferences from saving incorrect rotations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 (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
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
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, info_primary.GetActiveRotation());
603 EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); 605 EXPECT_EQ(1.0f, info_primary.configured_ui_scale());
604 } 606 }
605 607
606 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { 608 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) {
607 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); 609 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
608 610
609 // Stores display prefs without login, which still stores the power state. 611 // Stores display prefs without login, which still stores the power state.
610 StoreDisplayPrefs(); 612 StoreDisplayPrefs();
611 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); 613 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
612 } 614 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 // Tests that display configuration changes caused by MaximizeModeController 664 // Tests that display configuration changes caused by MaximizeModeController
663 // are not saved. 665 // are not saved.
664 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { 666 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) {
665 ash::Shell* shell = ash::Shell::GetInstance(); 667 ash::Shell* shell = ash::Shell::GetInstance();
666 gfx::Display::SetInternalDisplayId( 668 gfx::Display::SetInternalDisplayId(
667 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); 669 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
668 ash::DisplayManager* display_manager = shell->display_manager(); 670 ash::DisplayManager* display_manager = shell->display_manager();
669 LoggedInAsUser(); 671 LoggedInAsUser();
670 // Populate the properties. 672 // Populate the properties.
671 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 673 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
672 gfx::Display::ROTATE_180); 674 gfx::Display::ROTATE_180,
675 gfx::Display::ROTATION_SOURCE_USER);
673 // Reset property to avoid rotation lock 676 // Reset property to avoid rotation lock
674 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 677 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
675 gfx::Display::ROTATE_0); 678 gfx::Display::ROTATE_0,
679 gfx::Display::ROTATION_SOURCE_USER);
676 680
677 // Open up 270 degrees to trigger maximize mode 681 // Open up 270 degrees to trigger maximize mode
678 scoped_refptr<chromeos::AccelerometerUpdate> update( 682 scoped_refptr<chromeos::AccelerometerUpdate> update(
679 new chromeos::AccelerometerUpdate()); 683 new chromeos::AccelerometerUpdate());
680 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, 684 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f,
681 kMeanGravity); 685 kMeanGravity);
682 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); 686 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f);
683 ash::MaximizeModeController* controller = shell->maximize_mode_controller(); 687 ash::MaximizeModeController* controller = shell->maximize_mode_controller();
684 controller->OnAccelerometerUpdated(update); 688 controller->OnAccelerometerUpdated(update);
685 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); 689 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled());
686 690
687 // Trigger 90 degree rotation 691 // Trigger 90 degree rotation
688 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, -kMeanGravity, 692 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, -kMeanGravity,
689 0.0f, 0.0f); 693 0.0f, 0.0f);
690 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.0f, 0.0f); 694 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.0f, 0.0f);
691 controller->OnAccelerometerUpdated(update); 695 controller->OnAccelerometerUpdated(update);
692 shell->screen_orientation_controller()->OnAccelerometerUpdated(update); 696 shell->screen_orientation_controller()->OnAccelerometerUpdated(update);
693 EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> 697 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
694 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation());
695 698
696 const base::DictionaryValue* properties = 699 const base::DictionaryValue* properties =
697 local_state()->GetDictionary(prefs::kDisplayProperties); 700 local_state()->GetDictionary(prefs::kDisplayProperties);
698 const base::DictionaryValue* property = NULL; 701 const base::DictionaryValue* property = NULL;
699 EXPECT_TRUE(properties->GetDictionary( 702 EXPECT_TRUE(properties->GetDictionary(
700 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); 703 base::Int64ToString(gfx::Display::InternalDisplayId()), &property));
701 int rotation = -1; 704 int rotation = -1;
702 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); 705 EXPECT_TRUE(property->GetInteger("rotation", &rotation));
703 EXPECT_EQ(gfx::Display::ROTATE_0, rotation); 706 EXPECT_EQ(gfx::Display::ROTATE_0, rotation);
707
708 // Trigger a save, the acceleration rotation should not be saved as the user
709 // rotation.
710 StoreDisplayPrefs();
711 properties = local_state()->GetDictionary(prefs::kDisplayProperties);
712 property = NULL;
713 EXPECT_TRUE(properties->GetDictionary(
714 base::Int64ToString(gfx::Display::InternalDisplayId()), &property));
715 rotation = -1;
716 EXPECT_TRUE(property->GetInteger("rotation", &rotation));
717 EXPECT_EQ(gfx::Display::ROTATE_0, rotation);
704 } 718 }
705 719
706 // Tests that the rotation state is saved without a user being logged in. 720 // Tests that the rotation state is saved without a user being logged in.
707 TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { 721 TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) {
708 gfx::Display::SetInternalDisplayId( 722 gfx::Display::SetInternalDisplayId(
709 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); 723 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
710 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 724 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
711 725
712 bool current_rotation_lock = IsRotationLocked(); 726 bool current_rotation_lock = IsRotationLocked();
713 StoreDisplayRotationPrefs(current_rotation_lock); 727 StoreDisplayRotationPrefs(current_rotation_lock);
714 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 728 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
715 729
716 const base::DictionaryValue* properties = 730 const base::DictionaryValue* properties =
717 local_state()->GetDictionary(prefs::kDisplayRotationLock); 731 local_state()->GetDictionary(prefs::kDisplayRotationLock);
718 bool rotation_lock; 732 bool rotation_lock;
719 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); 733 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
720 EXPECT_EQ(current_rotation_lock, rotation_lock); 734 EXPECT_EQ(current_rotation_lock, rotation_lock);
721 735
722 int orientation; 736 int orientation;
723 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> 737 gfx::Display::Rotation current_rotation = GetCurrentInternalDisplayRotation();
724 display_manager()->
725 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
726 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); 738 EXPECT_TRUE(properties->GetInteger("orientation", &orientation));
727 EXPECT_EQ(current_rotation, orientation); 739 EXPECT_EQ(current_rotation, orientation);
728 } 740 }
729 741
730 // Tests that the rotation state is saved when a guest is logged in. 742 // Tests that the rotation state is saved when a guest is logged in.
731 TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { 743 TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) {
732 gfx::Display::SetInternalDisplayId( 744 gfx::Display::SetInternalDisplayId(
733 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); 745 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
734 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 746 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
735 LoggedInAsGuest(); 747 LoggedInAsGuest();
736 748
737 bool current_rotation_lock = IsRotationLocked(); 749 bool current_rotation_lock = IsRotationLocked();
738 StoreDisplayRotationPrefs(current_rotation_lock); 750 StoreDisplayRotationPrefs(current_rotation_lock);
739 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 751 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
740 752
741 const base::DictionaryValue* properties = 753 const base::DictionaryValue* properties =
742 local_state()->GetDictionary(prefs::kDisplayRotationLock); 754 local_state()->GetDictionary(prefs::kDisplayRotationLock);
743 bool rotation_lock; 755 bool rotation_lock;
744 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); 756 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
745 EXPECT_EQ(current_rotation_lock, rotation_lock); 757 EXPECT_EQ(current_rotation_lock, rotation_lock);
746 758
747 int orientation; 759 int orientation;
748 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> 760 gfx::Display::Rotation current_rotation = GetCurrentInternalDisplayRotation();
749 display_manager()->
750 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
751 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); 761 EXPECT_TRUE(properties->GetInteger("orientation", &orientation));
752 EXPECT_EQ(current_rotation, orientation); 762 EXPECT_EQ(current_rotation, orientation);
753 } 763 }
754 764
755 // Tests that the rotation state is saved when a normal user is logged in. 765 // Tests that the rotation state is saved when a normal user is logged in.
756 TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { 766 TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) {
757 gfx::Display::SetInternalDisplayId( 767 gfx::Display::SetInternalDisplayId(
758 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); 768 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
759 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 769 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
760 LoggedInAsGuest(); 770 LoggedInAsGuest();
761 771
762 bool current_rotation_lock = IsRotationLocked(); 772 bool current_rotation_lock = IsRotationLocked();
763 StoreDisplayRotationPrefs(current_rotation_lock); 773 StoreDisplayRotationPrefs(current_rotation_lock);
764 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 774 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
765 775
766 const base::DictionaryValue* properties = 776 const base::DictionaryValue* properties =
767 local_state()->GetDictionary(prefs::kDisplayRotationLock); 777 local_state()->GetDictionary(prefs::kDisplayRotationLock);
768 bool rotation_lock; 778 bool rotation_lock;
769 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); 779 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
770 EXPECT_EQ(current_rotation_lock, rotation_lock); 780 EXPECT_EQ(current_rotation_lock, rotation_lock);
771 781
772 int orientation; 782 int orientation;
773 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> 783 gfx::Display::Rotation current_rotation = GetCurrentInternalDisplayRotation();
774 display_manager()->
775 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
776 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); 784 EXPECT_TRUE(properties->GetInteger("orientation", &orientation));
777 EXPECT_EQ(current_rotation, orientation); 785 EXPECT_EQ(current_rotation, orientation);
778 } 786 }
779 787
780 // Tests that rotation state is loaded without a user being logged in, and that 788 // Tests that rotation state is loaded without a user being logged in, and that
781 // entering maximize mode applies the state. 789 // entering maximize mode applies the state.
782 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { 790 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) {
783 gfx::Display::SetInternalDisplayId( 791 gfx::Display::SetInternalDisplayId(
784 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); 792 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
785 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 793 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
786 794
787 ash::Shell* shell = ash::Shell::GetInstance(); 795 ash::Shell* shell = ash::Shell::GetInstance();
788 bool initial_rotation_lock = IsRotationLocked(); 796 bool initial_rotation_lock = IsRotationLocked();
789 ASSERT_FALSE(initial_rotation_lock); 797 ASSERT_FALSE(initial_rotation_lock);
790 ash::DisplayManager* display_manager = shell->display_manager(); 798 ash::DisplayManager* display_manager = shell->display_manager();
791 gfx::Display::Rotation initial_rotation = display_manager-> 799 gfx::Display::Rotation initial_rotation = GetCurrentInternalDisplayRotation();
792 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
793 ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); 800 ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation);
794 801
795 StoreDisplayRotationPrefs(initial_rotation_lock); 802 StoreDisplayRotationPrefs(initial_rotation_lock);
796 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 803 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
797 804
798 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); 805 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90);
799 LoadDisplayPreferences(false); 806 LoadDisplayPreferences(false);
800 807
801 bool display_rotation_lock = 808 bool display_rotation_lock =
802 display_manager->registered_internal_display_rotation_lock(); 809 display_manager->registered_internal_display_rotation_lock();
803 bool display_rotation = 810 bool display_rotation =
804 display_manager->registered_internal_display_rotation(); 811 display_manager->registered_internal_display_rotation();
805 EXPECT_TRUE(display_rotation_lock); 812 EXPECT_TRUE(display_rotation_lock);
806 EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); 813 EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation);
807 814
808 bool rotation_lock = IsRotationLocked(); 815 bool rotation_lock = IsRotationLocked();
809 gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> 816 gfx::Display::Rotation before_maximize_mode_rotation =
810 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); 817 GetCurrentInternalDisplayRotation();
811 818
812 // Settings should not be applied until maximize mode activates 819 // Settings should not be applied until maximize mode activates
813 EXPECT_FALSE(rotation_lock); 820 EXPECT_FALSE(rotation_lock);
814 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); 821 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation);
815 822
816 // Open up 270 degrees to trigger maximize mode 823 // Open up 270 degrees to trigger maximize mode
817 scoped_refptr<chromeos::AccelerometerUpdate> update( 824 scoped_refptr<chromeos::AccelerometerUpdate> update(
818 new chromeos::AccelerometerUpdate()); 825 new chromeos::AccelerometerUpdate());
819 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, 826 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f,
820 kMeanGravity); 827 kMeanGravity);
821 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); 828 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f);
822 ash::MaximizeModeController* maximize_mode_controller = 829 ash::MaximizeModeController* maximize_mode_controller =
823 shell->maximize_mode_controller(); 830 shell->maximize_mode_controller();
824 maximize_mode_controller->OnAccelerometerUpdated(update); 831 maximize_mode_controller->OnAccelerometerUpdated(update);
825 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); 832 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled());
826 bool screen_orientation_rotation_lock = IsRotationLocked(); 833 bool screen_orientation_rotation_lock = IsRotationLocked();
827 gfx::Display::Rotation maximize_mode_rotation = display_manager-> 834 gfx::Display::Rotation maximize_mode_rotation =
828 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); 835 GetCurrentInternalDisplayRotation();
829 EXPECT_TRUE(screen_orientation_rotation_lock); 836 EXPECT_TRUE(screen_orientation_rotation_lock);
830 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); 837 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation);
831 } 838 }
832 839
833 // Tests that rotation lock being set causes the rotation state to be saved. 840 // Tests that rotation lock being set causes the rotation state to be saved.
834 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { 841 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) {
835 gfx::Display::SetInternalDisplayId( 842 gfx::Display::SetInternalDisplayId(
836 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); 843 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
837 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 844 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
838 845
839 ash::Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( 846 ash::Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked(
840 true); 847 true);
841 848
842 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 849 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
843 850
844 const base::DictionaryValue* properties = 851 const base::DictionaryValue* properties =
845 local_state()->GetDictionary(prefs::kDisplayRotationLock); 852 local_state()->GetDictionary(prefs::kDisplayRotationLock);
846 bool rotation_lock; 853 bool rotation_lock;
847 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); 854 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
848 } 855 }
849 856
850 } // namespace chromeos 857 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/display/display_preferences.cc ('k') | chrome/browser/extensions/display_info_provider_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698