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 "extensions/browser/api/system_display/display_info_provider.h" | 5 #include "extensions/browser/api/system_display/display_info_provider.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | |
8 #include "ash/content/display/screen_orientation_controller_chromeos.h" | |
7 #include "ash/display/display_controller.h" | 9 #include "ash/display/display_controller.h" |
8 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
9 #include "ash/screen_util.h" | 11 #include "ash/screen_util.h" |
10 #include "ash/shell.h" | 12 #include "ash/shell.h" |
11 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
12 #include "ash/test/display_manager_test_api.h" | 14 #include "ash/test/display_manager_test_api.h" |
15 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
16 #include "base/command_line.h" | |
13 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
15 #include "extensions/common/api/system_display.h" | 19 #include "extensions/common/api/system_display.h" |
16 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
17 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
18 | 22 |
19 namespace extensions { | 23 namespace extensions { |
20 namespace { | 24 namespace { |
21 | 25 |
22 class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase { | 26 class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase { |
23 public: | 27 public: |
24 DisplayInfoProviderChromeosTest() {} | 28 DisplayInfoProviderChromeosTest() {} |
25 | 29 |
26 ~DisplayInfoProviderChromeosTest() override {} | 30 ~DisplayInfoProviderChromeosTest() override {} |
27 | 31 |
32 void SetUp() override { | |
not at google - send to devlin
2015/04/28 22:04:56
isn't there a SetUpCommandLine override or somethi
jonross
2015/04/28 22:09:03
That is in PPAPI and some browser tests. No one ev
| |
33 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
34 ash::switches::kAshUseFirstDisplayAsInternal); | |
35 ash::test::AshTestBase::SetUp(); | |
36 } | |
37 | |
28 protected: | 38 protected: |
29 void CallSetDisplayUnitInfo( | 39 void CallSetDisplayUnitInfo( |
30 const std::string& display_id, | 40 const std::string& display_id, |
31 const core_api::system_display::DisplayProperties& info, | 41 const core_api::system_display::DisplayProperties& info, |
32 bool* success, | 42 bool* success, |
33 std::string* error) { | 43 std::string* error) { |
34 // Reset error messsage. | 44 // Reset error messsage. |
35 (*error).clear(); | 45 (*error).clear(); |
36 *success = DisplayInfoProvider::Get()->SetInfo(display_id, info, error); | 46 *success = DisplayInfoProvider::Get()->SetInfo(display_id, info, error); |
37 } | 47 } |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 base::Int64ToString(secondary.id()), info, &success, &error); | 719 base::Int64ToString(secondary.id()), info, &success, &error); |
710 | 720 |
711 ASSERT_TRUE(success); | 721 ASSERT_TRUE(success); |
712 EXPECT_TRUE(error.empty()); | 722 EXPECT_TRUE(error.empty()); |
713 | 723 |
714 EXPECT_EQ("0,0 300x500", secondary.bounds().ToString()); | 724 EXPECT_EQ("0,0 300x500", secondary.bounds().ToString()); |
715 EXPECT_EQ(gfx::Display::ROTATE_0, secondary.rotation()); | 725 EXPECT_EQ(gfx::Display::ROTATE_0, secondary.rotation()); |
716 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().id(), secondary.id()); | 726 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().id(), secondary.id()); |
717 } | 727 } |
718 | 728 |
729 // Tests that rotation changes made before entering maximize mode are restored | |
730 // upon exiting maximize mode, and that a rotation lock is not set. | |
731 TEST_F(DisplayInfoProviderChromeosTest, SetRotationBeforeMaximizeMode) { | |
732 ash::ScreenOrientationController* screen_orientation_controller = | |
733 ash::Shell::GetInstance()->screen_orientation_controller(); | |
734 core_api::system_display::DisplayProperties info; | |
735 info.rotation.reset(new int(90)); | |
736 | |
737 bool success = false; | |
738 std::string error; | |
739 CallSetDisplayUnitInfo(base::Int64ToString(gfx::Display::InternalDisplayId()), | |
740 info, &success, &error); | |
741 | |
742 ASSERT_TRUE(success); | |
743 EXPECT_TRUE(error.empty()); | |
744 EXPECT_FALSE(screen_orientation_controller->rotation_locked()); | |
745 | |
746 // Entering maximize mode enables accelerometer screen rotations. | |
747 ash::Shell::GetInstance() | |
748 ->maximize_mode_controller() | |
749 ->EnableMaximizeModeWindowManager(true); | |
750 // Rotation lock should not activate because DisplayInfoProvider::SetInfo() | |
751 // was called when not in maximize mode. | |
752 EXPECT_FALSE(screen_orientation_controller->rotation_locked()); | |
753 | |
754 // ScreenOrientationController rotations override display info. | |
755 screen_orientation_controller->SetDisplayRotation( | |
756 gfx::Display::ROTATE_0, gfx::Display::ROTATION_SOURCE_ACTIVE); | |
757 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | |
758 | |
759 // Exiting maximize mode should restore the initial rotation | |
760 ash::Shell::GetInstance() | |
761 ->maximize_mode_controller() | |
762 ->EnableMaximizeModeWindowManager(false); | |
763 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | |
764 } | |
765 | |
766 // Tests that rotation changes made during maximize mode lock the display | |
767 // against accelerometer rotations. | |
768 TEST_F(DisplayInfoProviderChromeosTest, SetRotationDuringMaximizeMode) { | |
769 // Entering maximize mode enables accelerometer screen rotations. | |
770 ash::Shell::GetInstance() | |
771 ->maximize_mode_controller() | |
772 ->EnableMaximizeModeWindowManager(true); | |
773 | |
774 ASSERT_FALSE(ash::Shell::GetInstance() | |
775 ->screen_orientation_controller() | |
776 ->rotation_locked()); | |
777 | |
778 core_api::system_display::DisplayProperties info; | |
779 info.rotation.reset(new int(90)); | |
780 | |
781 bool success = false; | |
782 std::string error; | |
783 CallSetDisplayUnitInfo(base::Int64ToString(gfx::Display::InternalDisplayId()), | |
784 info, &success, &error); | |
785 | |
786 ASSERT_TRUE(success); | |
787 EXPECT_TRUE(error.empty()); | |
788 EXPECT_TRUE(ash::Shell::GetInstance() | |
789 ->screen_orientation_controller() | |
790 ->rotation_locked()); | |
791 } | |
792 | |
719 TEST_F(DisplayInfoProviderChromeosTest, SetInvalidRotation) { | 793 TEST_F(DisplayInfoProviderChromeosTest, SetInvalidRotation) { |
720 UpdateDisplay("1200x600,600x1000*2"); | 794 UpdateDisplay("1200x600,600x1000*2"); |
721 | 795 |
722 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay(); | 796 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay(); |
723 core_api::system_display::DisplayProperties info; | 797 core_api::system_display::DisplayProperties info; |
724 info.rotation.reset(new int(91)); | 798 info.rotation.reset(new int(91)); |
725 | 799 |
726 bool success = false; | 800 bool success = false; |
727 std::string error; | 801 std::string error; |
728 CallSetDisplayUnitInfo( | 802 CallSetDisplayUnitInfo( |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
885 std::string error; | 959 std::string error; |
886 CallSetDisplayUnitInfo( | 960 CallSetDisplayUnitInfo( |
887 base::Int64ToString(internal_display_id), info, &success, &error); | 961 base::Int64ToString(internal_display_id), info, &success, &error); |
888 | 962 |
889 ASSERT_FALSE(success); | 963 ASSERT_FALSE(success); |
890 EXPECT_EQ("Overscan changes not allowed for the internal monitor.", error); | 964 EXPECT_EQ("Overscan changes not allowed for the internal monitor.", error); |
891 } | 965 } |
892 | 966 |
893 } // namespace | 967 } // namespace |
894 } // namespace extensions | 968 } // namespace extensions |
OLD | NEW |