| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 10 #include "ash/display/screen_orientation_controller_chromeos.h" | 10 #include "ash/display/screen_orientation_controller_chromeos.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ui/display/test/display_manager_test_api.h" | 24 #include "ui/display/test/display_manager_test_api.h" |
| 25 #include "ui/display/types/display_constants.h" | 25 #include "ui/display/types/display_constants.h" |
| 26 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 27 | 27 |
| 28 namespace extensions { | 28 namespace extensions { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 using DisplayUnitInfoList = DisplayInfoProvider::DisplayUnitInfoList; | 31 using DisplayUnitInfoList = DisplayInfoProvider::DisplayUnitInfoList; |
| 32 using DisplayLayoutList = DisplayInfoProvider::DisplayLayoutList; | 32 using DisplayLayoutList = DisplayInfoProvider::DisplayLayoutList; |
| 33 | 33 |
| 34 void EnableMaximizeMode(bool enable) { |
| 35 ash::Shell::GetInstance() |
| 36 ->maximize_mode_controller() |
| 37 ->EnableMaximizeModeWindowManager(enable); |
| 38 } |
| 39 |
| 40 bool UserRotationLocked() { |
| 41 return ash::Shell::GetInstance() |
| 42 ->screen_orientation_controller() |
| 43 ->user_rotation_locked(); |
| 44 } |
| 45 |
| 46 void SetUserRotationLocked(bool rotation_locked) { |
| 47 if (ash::Shell::GetInstance() |
| 48 ->screen_orientation_controller() |
| 49 ->user_rotation_locked() != rotation_locked) { |
| 50 ash::Shell::GetInstance() |
| 51 ->screen_orientation_controller() |
| 52 ->ToggleUserRotationLock(); |
| 53 } |
| 54 } |
| 55 |
| 34 class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase { | 56 class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase { |
| 35 public: | 57 public: |
| 36 DisplayInfoProviderChromeosTest() {} | 58 DisplayInfoProviderChromeosTest() {} |
| 37 | 59 |
| 38 ~DisplayInfoProviderChromeosTest() override {} | 60 ~DisplayInfoProviderChromeosTest() override {} |
| 39 | 61 |
| 40 void SetUp() override { | 62 void SetUp() override { |
| 41 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 63 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 42 switches::kUseFirstDisplayAsInternal); | 64 switches::kUseFirstDisplayAsInternal); |
| 43 ash::test::AshTestBase::SetUp(); | 65 ash::test::AshTestBase::SetUp(); |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 std::string error; | 936 std::string error; |
| 915 CallSetDisplayUnitInfo( | 937 CallSetDisplayUnitInfo( |
| 916 base::Int64ToString(display::Display::InternalDisplayId()), info, | 938 base::Int64ToString(display::Display::InternalDisplayId()), info, |
| 917 &success, &error); | 939 &success, &error); |
| 918 | 940 |
| 919 ASSERT_TRUE(success); | 941 ASSERT_TRUE(success); |
| 920 EXPECT_TRUE(error.empty()); | 942 EXPECT_TRUE(error.empty()); |
| 921 EXPECT_FALSE(screen_orientation_controller->rotation_locked()); | 943 EXPECT_FALSE(screen_orientation_controller->rotation_locked()); |
| 922 | 944 |
| 923 // Entering maximize mode enables accelerometer screen rotations. | 945 // Entering maximize mode enables accelerometer screen rotations. |
| 924 ash::Shell::Get() | 946 EnableMaximizeMode(true); |
| 925 ->maximize_mode_controller() | |
| 926 ->EnableMaximizeModeWindowManager(true); | |
| 927 // Rotation lock should not activate because DisplayInfoProvider::SetInfo() | 947 // Rotation lock should not activate because DisplayInfoProvider::SetInfo() |
| 928 // was called when not in maximize mode. | 948 // was called when not in maximize mode. |
| 929 EXPECT_FALSE(screen_orientation_controller->rotation_locked()); | 949 EXPECT_FALSE(screen_orientation_controller->rotation_locked()); |
| 930 | 950 |
| 931 // ScreenOrientationController rotations override display info. | 951 // ScreenOrientationController rotations override display info. |
| 932 ash::test::ScreenOrientationControllerTestApi test_api( | 952 ash::test::ScreenOrientationControllerTestApi test_api( |
| 933 screen_orientation_controller); | 953 screen_orientation_controller); |
| 934 test_api.SetDisplayRotation(display::Display::ROTATE_0, | 954 test_api.SetDisplayRotation(display::Display::ROTATE_0, |
| 935 display::Display::ROTATION_SOURCE_ACTIVE); | 955 display::Display::ROTATION_SOURCE_ACTIVE); |
| 936 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); | 956 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 937 | 957 |
| 938 // Exiting maximize mode should restore the initial rotation | 958 // Exiting maximize mode should restore the initial rotation |
| 939 ash::Shell::Get() | 959 EnableMaximizeMode(false); |
| 940 ->maximize_mode_controller() | |
| 941 ->EnableMaximizeModeWindowManager(false); | |
| 942 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 960 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 943 } | 961 } |
| 944 | 962 |
| 945 // Tests that rotation changes made during maximize mode lock the display | 963 // Tests that rotation changes made during maximize mode lock the display |
| 946 // against accelerometer rotations. | 964 // against accelerometer rotations. |
| 947 TEST_F(DisplayInfoProviderChromeosTest, SetRotationDuringMaximizeMode) { | 965 TEST_F(DisplayInfoProviderChromeosTest, SetRotationDuringMaximizeMode) { |
| 948 // Entering maximize mode enables accelerometer screen rotations. | 966 // Entering maximize mode enables accelerometer screen rotations. |
| 949 ash::Shell::Get() | 967 EnableMaximizeMode(true); |
| 950 ->maximize_mode_controller() | |
| 951 ->EnableMaximizeModeWindowManager(true); | |
| 952 | 968 |
| 953 ASSERT_FALSE(ash::Shell::GetInstance() | 969 ASSERT_FALSE(ash::Shell::GetInstance() |
| 954 ->screen_orientation_controller() | 970 ->screen_orientation_controller() |
| 955 ->rotation_locked()); | 971 ->rotation_locked()); |
| 956 | 972 |
| 957 api::system_display::DisplayProperties info; | 973 api::system_display::DisplayProperties info; |
| 958 info.rotation.reset(new int(90)); | 974 info.rotation.reset(new int(90)); |
| 959 | 975 |
| 960 bool success = false; | 976 bool success = false; |
| 961 std::string error; | 977 std::string error; |
| 962 CallSetDisplayUnitInfo( | 978 CallSetDisplayUnitInfo( |
| 963 base::Int64ToString(display::Display::InternalDisplayId()), info, | 979 base::Int64ToString(display::Display::InternalDisplayId()), info, |
| 964 &success, &error); | 980 &success, &error); |
| 965 | 981 |
| 966 ASSERT_TRUE(success); | 982 ASSERT_TRUE(success); |
| 967 EXPECT_TRUE(error.empty()); | 983 EXPECT_TRUE(error.empty()); |
| 968 EXPECT_TRUE(ash::Shell::GetInstance() | 984 EXPECT_TRUE(ash::Shell::GetInstance() |
| 969 ->screen_orientation_controller() | 985 ->screen_orientation_controller() |
| 970 ->rotation_locked()); | 986 ->rotation_locked()); |
| 971 } | 987 } |
| 972 | 988 |
| 989 // Tests that setting display rotation is ignored on maximize mode with user |
| 990 // rotation locked. |
| 991 TEST_F(DisplayInfoProviderChromeosTest, |
| 992 SetRotationOnMaximizeModeWithUserRotationLocked) { |
| 993 EnableMaximizeMode(true); |
| 994 SetUserRotationLocked(true); |
| 995 EXPECT_TRUE(UserRotationLocked()); |
| 996 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 997 api::system_display::DisplayProperties info; |
| 998 info.rotation.reset(new int(90)); |
| 999 bool success = false; |
| 1000 std::string error; |
| 1001 CallSetDisplayUnitInfo( |
| 1002 base::Int64ToString(display::Display::InternalDisplayId()), info, |
| 1003 &success, &error); |
| 1004 ASSERT_TRUE(success); |
| 1005 EXPECT_TRUE(error.empty()); |
| 1006 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 1007 |
| 1008 SetUserRotationLocked(false); |
| 1009 EXPECT_FALSE(UserRotationLocked()); |
| 1010 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); |
| 1011 success = false; |
| 1012 CallSetDisplayUnitInfo( |
| 1013 base::Int64ToString(display::Display::InternalDisplayId()), info, |
| 1014 &success, &error); |
| 1015 ASSERT_TRUE(success); |
| 1016 EXPECT_TRUE(error.empty()); |
| 1017 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 1018 } |
| 1019 |
| 973 TEST_F(DisplayInfoProviderChromeosTest, SetInvalidRotation) { | 1020 TEST_F(DisplayInfoProviderChromeosTest, SetInvalidRotation) { |
| 974 UpdateDisplay("1200x600,600x1000*2"); | 1021 UpdateDisplay("1200x600,600x1000*2"); |
| 975 | 1022 |
| 976 const display::Display& secondary = display_manager()->GetSecondaryDisplay(); | 1023 const display::Display& secondary = display_manager()->GetSecondaryDisplay(); |
| 977 api::system_display::DisplayProperties info; | 1024 api::system_display::DisplayProperties info; |
| 978 info.rotation.reset(new int(91)); | 1025 info.rotation.reset(new int(91)); |
| 979 | 1026 |
| 980 bool success = false; | 1027 bool success = false; |
| 981 std::string error; | 1028 std::string error; |
| 982 CallSetDisplayUnitInfo( | 1029 CallSetDisplayUnitInfo( |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 EXPECT_EQ(pairs.pair1.touch_point.y, data.point_pairs[0].second.y()); | 1490 EXPECT_EQ(pairs.pair1.touch_point.y, data.point_pairs[0].second.y()); |
| 1444 EXPECT_EQ(pairs.pair2.touch_point.y, data.point_pairs[1].second.y()); | 1491 EXPECT_EQ(pairs.pair2.touch_point.y, data.point_pairs[1].second.y()); |
| 1445 EXPECT_EQ(pairs.pair3.touch_point.y, data.point_pairs[2].second.y()); | 1492 EXPECT_EQ(pairs.pair3.touch_point.y, data.point_pairs[2].second.y()); |
| 1446 EXPECT_EQ(pairs.pair4.touch_point.y, data.point_pairs[3].second.y()); | 1493 EXPECT_EQ(pairs.pair4.touch_point.y, data.point_pairs[3].second.y()); |
| 1447 | 1494 |
| 1448 EXPECT_EQ(bounds.width, data.bounds.width()); | 1495 EXPECT_EQ(bounds.width, data.bounds.width()); |
| 1449 EXPECT_EQ(bounds.height, data.bounds.height()); | 1496 EXPECT_EQ(bounds.height, data.bounds.height()); |
| 1450 } | 1497 } |
| 1451 } // namespace | 1498 } // namespace |
| 1452 } // namespace extensions | 1499 } // namespace extensions |
| OLD | NEW |