[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/chromeos/display/display_preferences.h" |
| 6 | |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 7 | #include <stdint.h> |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 8 | |
[email protected] | 2a57beb5 | 2014-06-09 20:02:26 | [diff] [blame] | 9 | #include <string> |
dcheng | 7c802f0 | 2015-12-31 16:09:55 | [diff] [blame] | 10 | #include <utility> |
[email protected] | 2a57beb5 | 2014-06-09 20:02:26 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
oshima | 81d3328 | 2015-07-27 21:16:01 | [diff] [blame] | 13 | #include "ash/display/display_util.h" |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 14 | #include "ash/display/resolution_notification_controller.h" |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 15 | #include "ash/display/screen_orientation_controller_chromeos.h" |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 16 | #include "ash/display/window_tree_host_manager.h" |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 17 | #include "ash/shell.h" |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 18 | #include "ash/test/ash_test_base.h" |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 19 | #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 20 | #include "base/macros.h" |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 21 | #include "base/memory/ptr_util.h" |
jonross | d6b7705 | 2015-03-11 22:04:35 | [diff] [blame] | 22 | #include "base/memory/ref_counted.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 23 | #include "base/strings/string_number_conversions.h" |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 24 | #include "base/values.h" |
[email protected] | 945ece96 | 2013-03-21 06:42:39 | [diff] [blame] | 25 | #include "chrome/browser/chromeos/display/display_configuration_observer.h" |
[email protected] | 83d82d4 | 2014-05-16 02:04:42 | [diff] [blame] | 26 | #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 27 | #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 28 | #include "chrome/common/pref_names.h" |
| 29 | #include "chrome/test/base/testing_browser_process.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 30 | #include "components/prefs/scoped_user_pref_update.h" |
| 31 | #include "components/prefs/testing_pref_service.h" |
kylechar | 731f85f9 | 2016-12-01 20:50:46 | [diff] [blame] | 32 | #include "ui/display/display_layout_builder.h" |
| 33 | #include "ui/display/manager/chromeos/display_configurator.h" |
F#m | 4791c3d7 | 2017-11-03 21:39:58 | [diff] [blame] | 34 | #include "ui/display/manager/chromeos/test/touch_device_manager_test_api.h" |
kylechar | 7eaccca | 2016-08-19 15:16:07 | [diff] [blame] | 35 | #include "ui/display/manager/display_layout_store.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 36 | #include "ui/display/manager/display_manager.h" |
rjkroege | 0458f01 | 2016-08-31 00:31:36 | [diff] [blame] | 37 | #include "ui/display/manager/display_manager_utilities.h" |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 38 | #include "ui/display/manager/json_converter.h" |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 39 | #include "ui/display/screen.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 40 | #include "ui/display/test/display_manager_test_api.h" |
tfarina | a2a039f | 2014-10-23 03:40:02 | [diff] [blame] | 41 | #include "ui/gfx/geometry/vector3d_f.h" |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 42 | #include "ui/message_center/message_center.h" |
| 43 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 44 | using ash::ResolutionNotificationController; |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 45 | |
| 46 | namespace chromeos { |
| 47 | namespace { |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 48 | const char kPrimaryIdKey[] = "primary-id"; |
| 49 | const char kMirroredKey[] = "mirrored"; |
| 50 | const char kPositionKey[] = "position"; |
| 51 | const char kOffsetKey[] = "offset"; |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 52 | const char kPlacementDisplayIdKey[] = "placement.display_id"; |
| 53 | const char kPlacementParentDisplayIdKey[] = "placement.parent_display_id"; |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 54 | |
flackr | 45f31ae7 | 2014-09-02 18:50:25 | [diff] [blame] | 55 | // The mean acceleration due to gravity on Earth in m/s^2. |
jonross | 01d453e | 2015-08-28 15:06:30 | [diff] [blame] | 56 | const float kMeanGravity = -9.80665f; |
flackr | 45f31ae7 | 2014-09-02 18:50:25 | [diff] [blame] | 57 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 58 | bool IsRotationLocked() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 59 | return ash::Shell::Get()->screen_orientation_controller()->rotation_locked(); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 60 | } |
| 61 | |
F#m | 4791c3d7 | 2017-11-03 21:39:58 | [diff] [blame] | 62 | bool CompareTouchAssociations( |
| 63 | const display::TouchDeviceManager::TouchAssociationMap& map_1, |
| 64 | const display::TouchDeviceManager::TouchAssociationMap& map_2) { |
| 65 | if (map_1.size() != map_2.size()) |
| 66 | return false; |
| 67 | // Each iterator instance |entry| is a pair of type |
| 68 | // std::pair<display::TouchDeviceIdentifier, |
| 69 | // display::TouchDeviceManager::AssociationInfoMap> |
| 70 | for (const auto& entry : map_1) { |
| 71 | if (!map_2.count(entry.first)) |
| 72 | return false; |
| 73 | |
| 74 | const auto& association_info_map_1 = entry.second; |
| 75 | const auto& association_info_map_2 = map_2.at(entry.first); |
| 76 | if (association_info_map_1.size() != association_info_map_2.size()) |
| 77 | return false; |
| 78 | |
| 79 | // Each iterator instance is a pair of type: |
| 80 | // std::pair<int64_t, display::TouchDeviceManager::TouchAssociationInfo> |
| 81 | for (const auto& info_1 : association_info_map_1) { |
| 82 | if (!association_info_map_2.count(info_1.first)) |
| 83 | return false; |
| 84 | |
| 85 | const auto& info_2 = association_info_map_2.at(info_1.first); |
| 86 | if (!(info_1.second.timestamp == info_2.timestamp && |
| 87 | info_1.second.calibration_data == info_2.calibration_data)) { |
| 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | return true; |
| 93 | } |
| 94 | |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 95 | class DisplayPreferencesTest : public ash::AshTestBase { |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 96 | protected: |
[email protected] | 5e4891b | 2014-01-08 19:24:35 | [diff] [blame] | 97 | DisplayPreferencesTest() |
| 98 | : mock_user_manager_(new MockUserManager), |
| 99 | user_manager_enabler_(mock_user_manager_) { |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 100 | } |
| 101 | |
dcheng | c97a028 | 2015-01-15 23:04:24 | [diff] [blame] | 102 | ~DisplayPreferencesTest() override {} |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 103 | |
dcheng | c97a028 | 2015-01-15 23:04:24 | [diff] [blame] | 104 | void SetUp() override { |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 105 | EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 106 | .WillRepeatedly(testing::Return(false)); |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 107 | EXPECT_CALL(*mock_user_manager_, Shutdown()); |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 108 | ash::AshTestBase::SetUp(); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 109 | RegisterDisplayLocalStatePrefs(local_state_.registry()); |
[email protected] | c494d08 | 2013-01-04 20:41:22 | [diff] [blame] | 110 | TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
Mitsuru Oshima | 3695b8be | 2017-10-09 14:18:36 | [diff] [blame] | 111 | observer_ = std::make_unique<DisplayConfigurationObserver>(); |
| 112 | observer_->OnDisplaysInitialized(); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 113 | } |
| 114 | |
dcheng | c97a028 | 2015-01-15 23:04:24 | [diff] [blame] | 115 | void TearDown() override { |
[email protected] | 945ece96 | 2013-03-21 06:42:39 | [diff] [blame] | 116 | observer_.reset(); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 117 | TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 118 | ash::AshTestBase::TearDown(); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void LoggedInAsUser() { |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 122 | EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 123 | .WillRepeatedly(testing::Return(true)); |
merkulova | c3ae44d | 2014-11-17 09:35:07 | [diff] [blame] | 124 | EXPECT_CALL(*mock_user_manager_, IsLoggedInAsUserWithGaiaAccount()) |
[email protected] | 1ccbac1 | 2013-09-13 06:55:54 | [diff] [blame] | 125 | .WillRepeatedly(testing::Return(true)); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void LoggedInAsGuest() { |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 129 | EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 130 | .WillRepeatedly(testing::Return(true)); |
merkulova | c3ae44d | 2014-11-17 09:35:07 | [diff] [blame] | 131 | EXPECT_CALL(*mock_user_manager_, IsLoggedInAsUserWithGaiaAccount()) |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 132 | .WillRepeatedly(testing::Return(false)); |
[email protected] | 933cc2e2 | 2014-07-18 13:26:57 | [diff] [blame] | 133 | EXPECT_CALL(*mock_user_manager_, IsLoggedInAsSupervisedUser()) |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 134 | .WillRepeatedly(testing::Return(false)); |
| 135 | } |
| 136 | |
| 137 | // Do not use the implementation of display_preferences.cc directly to avoid |
| 138 | // notifying the update to the system. |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 139 | void StoreDisplayLayoutPrefForList( |
| 140 | const display::DisplayIdList& list, |
| 141 | display::DisplayPlacement::Position position, |
| 142 | int offset, |
| 143 | int64_t primary_id) { |
rjkroege | 0458f01 | 2016-08-31 00:31:36 | [diff] [blame] | 144 | std::string name = display::DisplayIdListToString(list); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 145 | DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 146 | display::DisplayLayout display_layout; |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 147 | display_layout.placement_list.emplace_back(position, offset); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 148 | display_layout.primary_id = primary_id; |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 149 | |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 150 | DCHECK(!name.empty()); |
| 151 | |
| 152 | base::DictionaryValue* pref_data = update.Get(); |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 153 | std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); |
Mitsuru Oshima | 3695b8be | 2017-10-09 14:18:36 | [diff] [blame] | 154 | base::Value* value = nullptr; |
| 155 | if (pref_data->Get(name, &value) && value != nullptr) |
| 156 | layout_value.reset(value->DeepCopy()); |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 157 | if (display::DisplayLayoutToJson(display_layout, layout_value.get())) |
vabr | 6e421c60 | 2017-03-23 23:27:55 | [diff] [blame] | 158 | pref_data->Set(name, std::move(layout_value)); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 159 | } |
| 160 | |
Mitsuru Oshima | 3695b8be | 2017-10-09 14:18:36 | [diff] [blame] | 161 | bool GetDisplayPropertyFromList(const display::DisplayIdList& list, |
| 162 | const std::string& key, |
| 163 | base::Value** out_value) { |
| 164 | std::string name = display::DisplayIdListToString(list); |
| 165 | |
| 166 | DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); |
| 167 | base::DictionaryValue* pref_data = update.Get(); |
| 168 | |
jdoerrie | 8deeec2 | 2017-10-27 13:39:48 | [diff] [blame] | 169 | base::Value* layout_value = pref_data->FindKey(name); |
Mitsuru Oshima | 3695b8be | 2017-10-09 14:18:36 | [diff] [blame] | 170 | if (layout_value) { |
| 171 | return static_cast<base::DictionaryValue*>(layout_value) |
| 172 | ->Get(key, out_value); |
| 173 | } |
| 174 | return false; |
| 175 | } |
| 176 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 177 | void StoreDisplayPropertyForList(const display::DisplayIdList& list, |
Mitsuru Oshima | 3695b8be | 2017-10-09 14:18:36 | [diff] [blame] | 178 | const std::string& key, |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 179 | std::unique_ptr<base::Value> value) { |
rjkroege | 0458f01 | 2016-08-31 00:31:36 | [diff] [blame] | 180 | std::string name = display::DisplayIdListToString(list); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 181 | |
| 182 | DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); |
| 183 | base::DictionaryValue* pref_data = update.Get(); |
| 184 | |
jdoerrie | 8deeec2 | 2017-10-27 13:39:48 | [diff] [blame] | 185 | base::Value* layout_value = pref_data->FindKey(name); |
Mitsuru Oshima | 3695b8be | 2017-10-09 14:18:36 | [diff] [blame] | 186 | if (layout_value) { |
| 187 | static_cast<base::DictionaryValue*>(layout_value) |
| 188 | ->Set(key, std::move(value)); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 189 | } else { |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 190 | std::unique_ptr<base::DictionaryValue> layout_value( |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 191 | new base::DictionaryValue()); |
dcheng | 6e5c22f9 | 2016-03-03 22:09:15 | [diff] [blame] | 192 | layout_value->SetBoolean(key, value != nullptr); |
vabr | 6e421c60 | 2017-03-23 23:27:55 | [diff] [blame] | 193 | pref_data->Set(name, std::move(layout_value)); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 194 | } |
battre | de0c9e02 | 2015-05-22 09:48:00 | [diff] [blame] | 195 | } |
| 196 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 197 | void StoreDisplayBoolPropertyForList(const display::DisplayIdList& list, |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 198 | const std::string& key, |
| 199 | bool value) { |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 200 | StoreDisplayPropertyForList(list, key, |
| 201 | base::MakeUnique<base::Value>(value)); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 202 | } |
| 203 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 204 | void StoreDisplayLayoutPrefForList(const display::DisplayIdList& list, |
| 205 | display::DisplayPlacement::Position layout, |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 206 | int offset) { |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 207 | StoreDisplayLayoutPrefForList(list, layout, offset, list[0]); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 208 | } |
| 209 | |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 210 | void StoreDisplayOverscan(int64_t id, const gfx::Insets& insets) { |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 211 | DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 212 | const std::string name = base::Int64ToString(id); |
| 213 | |
| 214 | base::DictionaryValue* pref_data = update.Get(); |
vabr | 6e421c60 | 2017-03-23 23:27:55 | [diff] [blame] | 215 | auto insets_value = base::MakeUnique<base::DictionaryValue>(); |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 216 | insets_value->SetInteger("insets_top", insets.top()); |
| 217 | insets_value->SetInteger("insets_left", insets.left()); |
| 218 | insets_value->SetInteger("insets_bottom", insets.bottom()); |
| 219 | insets_value->SetInteger("insets_right", insets.right()); |
vabr | 6e421c60 | 2017-03-23 23:27:55 | [diff] [blame] | 220 | pref_data->Set(name, std::move(insets_value)); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 223 | void StoreDisplayRotationPrefsForTest(bool rotation_lock, |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 224 | display::Display::Rotation rotation) { |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 225 | DictionaryPrefUpdate update(local_state(), prefs::kDisplayRotationLock); |
| 226 | base::DictionaryValue* pref_data = update.Get(); |
| 227 | pref_data->SetBoolean("lock", rotation_lock); |
| 228 | pref_data->SetInteger("orientation", static_cast<int>(rotation)); |
| 229 | } |
| 230 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 231 | std::string GetRegisteredDisplayPlacementStr( |
| 232 | const display::DisplayIdList& list) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 233 | return ash::Shell::Get() |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 234 | ->display_manager() |
| 235 | ->layout_store() |
| 236 | ->GetRegisteredDisplayLayout(list) |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 237 | .placement_list[0] |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 238 | .ToString(); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | b732a6d | 2013-11-13 05:52:12 | [diff] [blame] | 241 | PrefService* local_state() { return &local_state_; } |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 242 | |
| 243 | private: |
[email protected] | 9a68d3a | 2013-04-22 16:26:54 | [diff] [blame] | 244 | MockUserManager* mock_user_manager_; // Not owned. |
| 245 | ScopedUserManagerEnabler user_manager_enabler_; |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 246 | TestingPrefServiceSimple local_state_; |
Mitsuru Oshima | 3695b8be | 2017-10-09 14:18:36 | [diff] [blame] | 247 | std::unique_ptr<ash::WindowTreeHostManager::Observer> observer_; |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 248 | |
| 249 | DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); |
| 250 | }; |
| 251 | |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 252 | } // namespace |
| 253 | |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 254 | TEST_F(DisplayPreferencesTest, ListedLayoutOverrides) { |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 255 | UpdateDisplay("100x100,200x200"); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 256 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 257 | display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList(); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 258 | display::DisplayIdList dummy_list = |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 259 | display::test::CreateDisplayIdList2(list[0], list[1] + 1); |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 260 | ASSERT_NE(list[0], dummy_list[1]); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 261 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 262 | StoreDisplayLayoutPrefForList(list, display::DisplayPlacement::TOP, 20); |
| 263 | StoreDisplayLayoutPrefForList(dummy_list, display::DisplayPlacement::LEFT, |
| 264 | 30); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 265 | StoreDisplayPowerStateForTest( |
| 266 | chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 267 | |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 268 | ash::Shell* shell = ash::Shell::Get(); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 269 | |
| 270 | LoadDisplayPreferences(true); |
| 271 | // DisplayPowerState should be ignored at boot. |
| 272 | EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, |
derat | 4a06278 | 2014-09-25 21:46:13 | [diff] [blame] | 273 | shell->display_configurator()->requested_power_state()); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 274 | |
| 275 | shell->display_manager()->UpdateDisplays(); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 276 | // Check if the layout settings are notified to the system properly. |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 277 | // The new layout overrides old layout. |
| 278 | // Inverted one of for specified pair (id1, id2). Not used for the list |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 279 | // (id1, dummy_id) since dummy_id is not connected right now. |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 280 | EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", |
| 281 | shell->display_manager() |
| 282 | ->GetCurrentDisplayLayout() |
| 283 | .placement_list[0] |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 284 | .ToString()); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 285 | EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", |
| 286 | GetRegisteredDisplayPlacementStr(list)); |
| 287 | EXPECT_EQ("id=2200000002, parent=2200000000, left, 30", |
| 288 | GetRegisteredDisplayPlacementStr(dummy_list)); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | TEST_F(DisplayPreferencesTest, BasicStores) { |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 292 | ash::WindowTreeHostManager* window_tree_host_manager = |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 293 | ash::Shell::Get()->window_tree_host_manager(); |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 294 | |
[email protected] | 2f6bc70 | 2014-08-08 19:23:23 | [diff] [blame] | 295 | UpdateDisplay("200x200*2, 400x300#400x400|300x200*1.25"); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 296 | int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 297 | display::test::ScopedSetInternalDisplayId set_internal(display_manager(), |
| 298 | id1); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 299 | int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 300 | int64_t dummy_id = id2 + 1; |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 301 | ASSERT_NE(id1, dummy_id); |
| 302 | |
| 303 | LoggedInAsUser(); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 304 | |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 305 | display_manager()->SetLayoutForCurrentDisplays( |
| 306 | display::test::CreateDisplayLayout(display_manager(), |
| 307 | display::DisplayPlacement::TOP, 10)); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 308 | const display::DisplayLayout& layout = |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 309 | display_manager()->GetCurrentDisplayLayout(); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 310 | EXPECT_EQ(display::DisplayPlacement::TOP, layout.placement_list[0].position); |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 311 | EXPECT_EQ(10, layout.placement_list[0].offset); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 312 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 313 | display::DisplayLayoutBuilder dummy_layout_builder(id1); |
| 314 | dummy_layout_builder.SetSecondaryPlacement( |
| 315 | dummy_id, display::DisplayPlacement::LEFT, 20); |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 316 | std::unique_ptr<display::DisplayLayout> dummy_layout( |
| 317 | dummy_layout_builder.Build()); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 318 | display::DisplayIdList list = |
| 319 | display::test::CreateDisplayIdList2(id1, dummy_id); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 320 | StoreDisplayLayoutPrefForTest(list, *dummy_layout); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 321 | |
[email protected] | 945ece96 | 2013-03-21 06:42:39 | [diff] [blame] | 322 | // Can't switch to a display that does not exist. |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 323 | window_tree_host_manager->SetPrimaryDisplayId(dummy_id); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 324 | EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
[email protected] | 945ece96 | 2013-03-21 06:42:39 | [diff] [blame] | 325 | |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 326 | window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 327 | display_manager()->SetDisplayRotation(id1, display::Display::ROTATE_90, |
| 328 | display::Display::ROTATION_SOURCE_USER); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 329 | EXPECT_TRUE(display::test::DisplayManagerTestApi(display_manager()) |
afakhry | 8571a9c | 2016-10-26 22:03:41 | [diff] [blame] | 330 | .SetDisplayUIScale(id1, 1.25f)); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 331 | EXPECT_FALSE(display::test::DisplayManagerTestApi(display_manager()) |
afakhry | 8571a9c | 2016-10-26 22:03:41 | [diff] [blame] | 332 | .SetDisplayUIScale(id2, 1.25f)); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 333 | |
malaykeshav | 4d3a49e | 2016-12-06 00:03:11 | [diff] [blame] | 334 | // Set touch calibration data for display |id2|. |
F#m | 6662d83 | 2017-10-27 16:55:01 | [diff] [blame] | 335 | uint32_t id_1 = 1234; |
| 336 | const display::TouchDeviceIdentifier touch_device_identifier_1(id_1); |
F#m | 0249012 | 2017-09-28 22:47:24 | [diff] [blame] | 337 | display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad_1 = { |
malaykeshav | 4d3a49e | 2016-12-06 00:03:11 | [diff] [blame] | 338 | {std::make_pair(gfx::Point(10, 10), gfx::Point(11, 12)), |
| 339 | std::make_pair(gfx::Point(190, 10), gfx::Point(195, 8)), |
| 340 | std::make_pair(gfx::Point(10, 90), gfx::Point(12, 94)), |
| 341 | std::make_pair(gfx::Point(190, 90), gfx::Point(189, 88))}}; |
F#m | 0249012 | 2017-09-28 22:47:24 | [diff] [blame] | 342 | gfx::Size touch_size_1(200, 150); |
| 343 | |
F#m | 6662d83 | 2017-10-27 16:55:01 | [diff] [blame] | 344 | uint32_t id_2 = 2345; |
| 345 | const display::TouchDeviceIdentifier touch_device_identifier_2(id_2); |
F#m | 0249012 | 2017-09-28 22:47:24 | [diff] [blame] | 346 | display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad_2 = { |
| 347 | {std::make_pair(gfx::Point(10, 10), gfx::Point(11, 12)), |
| 348 | std::make_pair(gfx::Point(190, 10), gfx::Point(195, 8)), |
| 349 | std::make_pair(gfx::Point(10, 90), gfx::Point(12, 94)), |
| 350 | std::make_pair(gfx::Point(190, 90), gfx::Point(189, 88))}}; |
| 351 | gfx::Size touch_size_2(150, 150); |
| 352 | |
| 353 | display_manager()->SetTouchCalibrationData( |
| 354 | id2, point_pair_quad_1, touch_size_1, touch_device_identifier_1); |
| 355 | display_manager()->SetTouchCalibrationData( |
| 356 | id2, point_pair_quad_2, touch_size_2, touch_device_identifier_2); |
malaykeshav | 4d3a49e | 2016-12-06 00:03:11 | [diff] [blame] | 357 | |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 358 | const base::DictionaryValue* displays = |
| 359 | local_state()->GetDictionary(prefs::kSecondaryDisplays); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 360 | const base::DictionaryValue* layout_value = nullptr; |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 361 | std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 362 | std::string dummy_key = |
| 363 | base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); |
| 364 | EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 365 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 366 | display::DisplayLayout stored_layout; |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 367 | EXPECT_TRUE(display::JsonToDisplayLayout(*layout_value, &stored_layout)); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 368 | ASSERT_EQ(1u, stored_layout.placement_list.size()); |
| 369 | |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 370 | EXPECT_EQ(dummy_layout->placement_list[0].position, |
| 371 | stored_layout.placement_list[0].position); |
| 372 | EXPECT_EQ(dummy_layout->placement_list[0].offset, |
| 373 | stored_layout.placement_list[0].offset); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 374 | |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 375 | bool mirrored = true; |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 376 | EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 377 | EXPECT_FALSE(mirrored); |
| 378 | |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 379 | const base::DictionaryValue* properties = |
| 380 | local_state()->GetDictionary(prefs::kDisplayProperties); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 381 | const base::DictionaryValue* property = nullptr; |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 382 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 383 | int ui_scale = 0; |
| 384 | int rotation = 0; |
| 385 | EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
| 386 | EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); |
| 387 | EXPECT_EQ(1, rotation); |
| 388 | EXPECT_EQ(1250, ui_scale); |
| 389 | |
[email protected] | 2bd1fcf0 | 2014-02-12 22:35:53 | [diff] [blame] | 390 | // Internal display never registered the resolution. |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 391 | int width = 0, height = 0; |
| 392 | EXPECT_FALSE(property->GetInteger("width", &width)); |
| 393 | EXPECT_FALSE(property->GetInteger("height", &height)); |
| 394 | |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 395 | int top = 0, left = 0, bottom = 0, right = 0; |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 396 | EXPECT_TRUE(property->GetInteger("insets_top", &top)); |
| 397 | EXPECT_TRUE(property->GetInteger("insets_left", &left)); |
| 398 | EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); |
| 399 | EXPECT_TRUE(property->GetInteger("insets_right", &right)); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 400 | EXPECT_EQ(10, top); |
| 401 | EXPECT_EQ(11, left); |
| 402 | EXPECT_EQ(12, bottom); |
| 403 | EXPECT_EQ(13, right); |
[email protected] | 945ece96 | 2013-03-21 06:42:39 | [diff] [blame] | 404 | |
F#m | 4791c3d7 | 2017-11-03 21:39:58 | [diff] [blame] | 405 | display::TouchDeviceManager* tdm = display_manager()->touch_device_manager(); |
| 406 | display::test::TouchDeviceManagerTestApi tdm_test_api(tdm); |
| 407 | display::TouchDeviceManager::TouchAssociationMap |
| 408 | expected_touch_associations_map = tdm->touch_associations(); |
| 409 | tdm_test_api.ResetTouchDeviceManager(); |
| 410 | |
| 411 | EXPECT_FALSE(CompareTouchAssociations(expected_touch_associations_map, |
| 412 | tdm->touch_associations())); |
| 413 | |
| 414 | LoadTouchAssociationPreferenceForTest(); |
| 415 | |
| 416 | display::TouchDeviceManager::TouchAssociationMap |
| 417 | actual_touch_associations_map = tdm->touch_associations(); |
| 418 | |
| 419 | EXPECT_TRUE(CompareTouchAssociations(actual_touch_associations_map, |
| 420 | expected_touch_associations_map)); |
| 421 | |
malaykeshav | 4d3a49e | 2016-12-06 00:03:11 | [diff] [blame] | 422 | std::string touch_str; |
malaykeshav | 4d3a49e | 2016-12-06 00:03:11 | [diff] [blame] | 423 | |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 424 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 425 | EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
| 426 | EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); |
| 427 | EXPECT_EQ(0, rotation); |
| 428 | // ui_scale works only on 2x scale factor/1st display. |
| 429 | EXPECT_EQ(1000, ui_scale); |
| 430 | EXPECT_FALSE(property->GetInteger("insets_top", &top)); |
| 431 | EXPECT_FALSE(property->GetInteger("insets_left", &left)); |
| 432 | EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom)); |
| 433 | EXPECT_FALSE(property->GetInteger("insets_right", &right)); |
| 434 | |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 435 | // Resolution is saved only when the resolution is set |
[email protected] | 2f6bc70 | 2014-08-08 19:23:23 | [diff] [blame] | 436 | // by DisplayManager::SetDisplayMode |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 437 | width = 0; |
| 438 | height = 0; |
| 439 | EXPECT_FALSE(property->GetInteger("width", &width)); |
| 440 | EXPECT_FALSE(property->GetInteger("height", &height)); |
| 441 | |
Miguel Casas-Sanchez | be6c6663 | 2017-10-19 16:40:23 | [diff] [blame] | 442 | display::ManagedDisplayMode mode(gfx::Size(300, 200), 60.0f, false, true, |
| 443 | 1.0 /* ui_scale */, |
| 444 | 1.25f /* device_scale_factor */); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 445 | display_manager()->SetDisplayMode(id2, mode); |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 446 | |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 447 | window_tree_host_manager->SetPrimaryDisplayId(id2); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 448 | |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 449 | EXPECT_EQ(id2, display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 450 | |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 451 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 452 | width = 0; |
| 453 | height = 0; |
[email protected] | 2bd1fcf0 | 2014-02-12 22:35:53 | [diff] [blame] | 454 | // Internal display shouldn't store its resolution. |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 455 | EXPECT_FALSE(property->GetInteger("width", &width)); |
| 456 | EXPECT_FALSE(property->GetInteger("height", &height)); |
| 457 | |
[email protected] | 2bd1fcf0 | 2014-02-12 22:35:53 | [diff] [blame] | 458 | // External display's resolution must be stored this time because |
[email protected] | 885f2672 | 2013-08-13 06:37:47 | [diff] [blame] | 459 | // it's not best. |
[email protected] | 2f6bc70 | 2014-08-08 19:23:23 | [diff] [blame] | 460 | int device_scale_factor = 0; |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 461 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 462 | EXPECT_TRUE(property->GetInteger("width", &width)); |
| 463 | EXPECT_TRUE(property->GetInteger("height", &height)); |
[email protected] | 2f6bc70 | 2014-08-08 19:23:23 | [diff] [blame] | 464 | EXPECT_TRUE(property->GetInteger( |
| 465 | "device-scale-factor", &device_scale_factor)); |
[email protected] | 885f2672 | 2013-08-13 06:37:47 | [diff] [blame] | 466 | EXPECT_EQ(300, width); |
| 467 | EXPECT_EQ(200, height); |
[email protected] | 2f6bc70 | 2014-08-08 19:23:23 | [diff] [blame] | 468 | EXPECT_EQ(1250, device_scale_factor); |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 469 | |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 470 | // The layout is swapped. |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 471 | EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 472 | |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 473 | EXPECT_TRUE(display::JsonToDisplayLayout(*layout_value, &stored_layout)); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 474 | ASSERT_EQ(1u, stored_layout.placement_list.size()); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 475 | const display::DisplayPlacement& stored_placement = |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 476 | stored_layout.placement_list[0]; |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 477 | EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 478 | EXPECT_EQ(-10, stored_placement.offset); |
| 479 | EXPECT_EQ(id1, stored_placement.display_id); |
| 480 | EXPECT_EQ(id2, stored_placement.parent_display_id); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 481 | EXPECT_EQ(id2, stored_layout.primary_id); |
| 482 | |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 483 | if (true) |
| 484 | return; |
| 485 | |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 486 | mirrored = true; |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 487 | EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 488 | EXPECT_FALSE(mirrored); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 489 | std::string primary_id_str; |
| 490 | EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 491 | EXPECT_EQ(base::Int64ToString(id2), primary_id_str); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 492 | |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 493 | display_manager()->SetLayoutForCurrentDisplays( |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 494 | display::test::CreateDisplayLayout(ash::Shell::Get()->display_manager(), |
| 495 | display::DisplayPlacement::BOTTOM, |
| 496 | 20)); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 497 | |
[email protected] | d41e889 | 2013-07-11 08:03:49 | [diff] [blame] | 498 | UpdateDisplay("1+0-200x200*2,1+0-200x200"); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 499 | // Mirrored. |
| 500 | int offset = 0; |
| 501 | std::string position; |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 502 | EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 503 | EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 504 | EXPECT_EQ("bottom", position); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 505 | EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 506 | EXPECT_EQ(20, offset); |
| 507 | std::string id; |
| 508 | EXPECT_TRUE(layout_value->GetString(kPlacementDisplayIdKey, &id)); |
| 509 | EXPECT_EQ(base::Int64ToString(id1), id); |
| 510 | EXPECT_TRUE(layout_value->GetString(kPlacementParentDisplayIdKey, &id)); |
| 511 | EXPECT_EQ(base::Int64ToString(id2), id); |
| 512 | |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 513 | mirrored = false; |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 514 | EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 515 | EXPECT_TRUE(mirrored); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 516 | EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 517 | EXPECT_EQ(base::Int64ToString(id2), primary_id_str); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 518 | |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 519 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 520 | EXPECT_FALSE(property->GetInteger("width", &width)); |
| 521 | EXPECT_FALSE(property->GetInteger("height", &height)); |
| 522 | |
[email protected] | 2bd1fcf0 | 2014-02-12 22:35:53 | [diff] [blame] | 523 | // External display's selected resolution must not change |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 524 | // by mirroring. |
| 525 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 526 | EXPECT_TRUE(property->GetInteger("width", &width)); |
| 527 | EXPECT_TRUE(property->GetInteger("height", &height)); |
[email protected] | 885f2672 | 2013-08-13 06:37:47 | [diff] [blame] | 528 | EXPECT_EQ(300, width); |
| 529 | EXPECT_EQ(200, height); |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 530 | |
| 531 | // Set new display's selected resolution. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 532 | display_manager()->RegisterDisplayProperty( |
| 533 | id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), |
F#m | 4791c3d7 | 2017-11-03 21:39:58 | [diff] [blame] | 534 | 1.0f); |
[email protected] | 885f2672 | 2013-08-13 06:37:47 | [diff] [blame] | 535 | |
| 536 | UpdateDisplay("200x200*2, 600x500#600x500|500x400"); |
| 537 | |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 538 | // Update key as the 2nd display gets new id. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 539 | id2 = display_manager()->GetSecondaryDisplay().id(); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 540 | key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 541 | EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 542 | EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 543 | EXPECT_EQ("right", position); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 544 | EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 545 | EXPECT_EQ(0, offset); |
| 546 | mirrored = true; |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 547 | EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 548 | EXPECT_FALSE(mirrored); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 549 | EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 550 | EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 551 | |
[email protected] | 5e4891b | 2014-01-08 19:24:35 | [diff] [blame] | 552 | // Best resolution should not be saved. |
| 553 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 554 | EXPECT_FALSE(property->GetInteger("width", &width)); |
| 555 | EXPECT_FALSE(property->GetInteger("height", &height)); |
| 556 | |
| 557 | // Set yet another new display's selected resolution. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 558 | display_manager()->RegisterDisplayProperty( |
| 559 | id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), |
F#m | 4791c3d7 | 2017-11-03 21:39:58 | [diff] [blame] | 560 | 1.0f); |
[email protected] | 5e4891b | 2014-01-08 19:24:35 | [diff] [blame] | 561 | // Disconnect 2nd display first to generate new id for external display. |
| 562 | UpdateDisplay("200x200*2"); |
[email protected] | 2bd1fcf0 | 2014-02-12 22:35:53 | [diff] [blame] | 563 | UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); |
[email protected] | 5e4891b | 2014-01-08 19:24:35 | [diff] [blame] | 564 | // Update key as the 2nd display gets new id. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 565 | id2 = display_manager()->GetSecondaryDisplay().id(); |
[email protected] | 5e4891b | 2014-01-08 19:24:35 | [diff] [blame] | 566 | key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 567 | EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 568 | EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 569 | EXPECT_EQ("right", position); |
| 570 | EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 571 | EXPECT_EQ(0, offset); |
| 572 | mirrored = true; |
| 573 | EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 574 | EXPECT_FALSE(mirrored); |
| 575 | EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 576 | EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
| 577 | |
[email protected] | 2bd1fcf0 | 2014-02-12 22:35:53 | [diff] [blame] | 578 | // External display's selected resolution must be updated. |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 579 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 580 | EXPECT_TRUE(property->GetInteger("width", &width)); |
| 581 | EXPECT_TRUE(property->GetInteger("height", &height)); |
| 582 | EXPECT_EQ(500, width); |
| 583 | EXPECT_EQ(400, height); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 584 | } |
| 585 | |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 586 | TEST_F(DisplayPreferencesTest, PreventStore) { |
| 587 | ResolutionNotificationController::SuppressTimerForTest(); |
| 588 | LoggedInAsUser(); |
[email protected] | 885f2672 | 2013-08-13 06:37:47 | [diff] [blame] | 589 | UpdateDisplay("400x300#500x400|400x300|300x200"); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 590 | int64_t id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 591 | // Set display's resolution in single display. It creates the notification and |
| 592 | // display preferences should not stored meanwhile. |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 593 | ash::Shell* shell = ash::Shell::Get(); |
rjkroege | 8503c15 | 2016-08-05 21:19:42 | [diff] [blame] | 594 | |
Miguel Casas-Sanchez | be6c6663 | 2017-10-19 16:40:23 | [diff] [blame] | 595 | display::ManagedDisplayMode old_mode(gfx::Size(400, 300)); |
| 596 | display::ManagedDisplayMode new_mode(gfx::Size(500, 400)); |
afakhry | d5fd8d94 | 2017-04-13 23:34:10 | [diff] [blame] | 597 | EXPECT_TRUE(shell->resolution_notification_controller() |
| 598 | ->PrepareNotificationAndSetDisplayMode(id, old_mode, new_mode, |
| 599 | base::Closure())); |
[email protected] | 885f2672 | 2013-08-13 06:37:47 | [diff] [blame] | 600 | UpdateDisplay("500x400#500x400|400x300|300x200"); |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 601 | |
| 602 | const base::DictionaryValue* properties = |
| 603 | local_state()->GetDictionary(prefs::kDisplayProperties); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 604 | const base::DictionaryValue* property = nullptr; |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 605 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); |
| 606 | int width = 0, height = 0; |
| 607 | EXPECT_FALSE(property->GetInteger("width", &width)); |
| 608 | EXPECT_FALSE(property->GetInteger("height", &height)); |
| 609 | |
| 610 | // Revert the change. When timeout, 2nd button is revert. |
| 611 | message_center::MessageCenter::Get()->ClickOnNotificationButton( |
| 612 | ResolutionNotificationController::kNotificationId, 1); |
| 613 | RunAllPendingInMessageLoop(); |
[email protected] | 91ff44d8 | 2014-06-12 18:37:37 | [diff] [blame] | 614 | EXPECT_FALSE( |
| 615 | message_center::MessageCenter::Get()->FindVisibleNotificationById( |
| 616 | ResolutionNotificationController::kNotificationId)); |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 617 | |
| 618 | // Once the notification is removed, the specified resolution will be stored |
[email protected] | 2f6bc70 | 2014-08-08 19:23:23 | [diff] [blame] | 619 | // by SetDisplayMode. |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 620 | ash::Shell::Get()->display_manager()->SetDisplayMode( |
Miguel Casas-Sanchez | be6c6663 | 2017-10-19 16:40:23 | [diff] [blame] | 621 | id, display::ManagedDisplayMode(gfx::Size(300, 200), 60.0f, false, true)); |
[email protected] | 885f2672 | 2013-08-13 06:37:47 | [diff] [blame] | 622 | UpdateDisplay("300x200#500x400|400x300|300x200"); |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 623 | |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 624 | property = nullptr; |
[email protected] | 6ef71d7 | 2013-08-10 18:13:44 | [diff] [blame] | 625 | EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); |
| 626 | EXPECT_TRUE(property->GetInteger("width", &width)); |
| 627 | EXPECT_TRUE(property->GetInteger("height", &height)); |
| 628 | EXPECT_EQ(300, width); |
| 629 | EXPECT_EQ(200, height); |
| 630 | } |
| 631 | |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 632 | TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { |
| 633 | UpdateDisplay("100x100,200x200"); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 634 | int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 635 | int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 636 | |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 637 | LoggedInAsUser(); |
| 638 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 639 | SwapPrimaryDisplay(); |
| 640 | ASSERT_EQ(id1, display_manager()->GetSecondaryDisplay().id()); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 641 | |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 642 | std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 643 | const base::DictionaryValue* displays = |
| 644 | local_state()->GetDictionary(prefs::kSecondaryDisplays); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 645 | // Initial saved value is swapped. |
| 646 | { |
| 647 | const base::DictionaryValue* new_value = nullptr; |
| 648 | EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 649 | display::DisplayLayout stored_layout; |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 650 | EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout)); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 651 | ASSERT_EQ(1u, stored_layout.placement_list.size()); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 652 | const display::DisplayPlacement& stored_placement = |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 653 | stored_layout.placement_list[0]; |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 654 | EXPECT_EQ(display::DisplayPlacement::LEFT, stored_placement.position); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 655 | EXPECT_EQ(0, stored_placement.offset); |
| 656 | EXPECT_EQ(id1, stored_placement.display_id); |
| 657 | EXPECT_EQ(id2, stored_placement.parent_display_id); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 658 | EXPECT_EQ(id2, stored_layout.primary_id); |
| 659 | } |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 660 | |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 661 | // Updating layout with primary swapped should save the correct value. |
| 662 | { |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 663 | display_manager()->SetLayoutForCurrentDisplays( |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 664 | display::test::CreateDisplayLayout(display_manager(), |
| 665 | display::DisplayPlacement::TOP, 10)); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 666 | const base::DictionaryValue* new_value = nullptr; |
| 667 | EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 668 | display::DisplayLayout stored_layout; |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 669 | EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout)); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 670 | ASSERT_EQ(1u, stored_layout.placement_list.size()); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 671 | const display::DisplayPlacement& stored_placement = |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 672 | stored_layout.placement_list[0]; |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 673 | EXPECT_EQ(display::DisplayPlacement::TOP, stored_placement.position); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 674 | EXPECT_EQ(10, stored_placement.offset); |
| 675 | EXPECT_EQ(id1, stored_placement.display_id); |
| 676 | EXPECT_EQ(id2, stored_placement.parent_display_id); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 677 | EXPECT_EQ(id2, stored_layout.primary_id); |
| 678 | } |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 679 | |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 680 | // Swapping primary will save the swapped value. |
| 681 | { |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 682 | SwapPrimaryDisplay(); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 683 | const base::DictionaryValue* new_value = nullptr; |
| 684 | EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 685 | display::DisplayLayout stored_layout; |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 686 | |
| 687 | EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 688 | EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout)); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 689 | ASSERT_EQ(1u, stored_layout.placement_list.size()); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 690 | const display::DisplayPlacement& stored_placement = |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 691 | stored_layout.placement_list[0]; |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 692 | EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 693 | EXPECT_EQ(-10, stored_placement.offset); |
| 694 | EXPECT_EQ(id2, stored_placement.display_id); |
| 695 | EXPECT_EQ(id1, stored_placement.parent_display_id); |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 696 | EXPECT_EQ(id1, stored_layout.primary_id); |
| 697 | } |
[email protected] | 0622b36 | 2013-03-02 17:43:16 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 701 | ash::WindowTreeHostManager* window_tree_host_manager = |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 702 | ash::Shell::Get()->window_tree_host_manager(); |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 703 | |
| 704 | UpdateDisplay("200x200*2,200x200"); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 705 | |
| 706 | LoggedInAsGuest(); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 707 | int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 708 | display::test::ScopedSetInternalDisplayId set_internal( |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 709 | ash::Shell::Get()->display_manager(), id1); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 710 | int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 711 | display_manager()->SetLayoutForCurrentDisplays( |
| 712 | display::test::CreateDisplayLayout(display_manager(), |
| 713 | display::DisplayPlacement::TOP, 10)); |
| 714 | display::test::DisplayManagerTestApi(display_manager()) |
afakhry | 8571a9c | 2016-10-26 22:03:41 | [diff] [blame] | 715 | .SetDisplayUIScale(id1, 1.25f); |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 716 | window_tree_host_manager->SetPrimaryDisplayId(id2); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 717 | int64_t new_primary = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
oshima | e281892 | 2015-07-28 01:18:52 | [diff] [blame] | 718 | window_tree_host_manager->SetOverscanInsets(new_primary, |
| 719 | gfx::Insets(10, 11, 12, 13)); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 720 | display_manager()->SetDisplayRotation(new_primary, |
| 721 | display::Display::ROTATE_90, |
| 722 | display::Display::ROTATION_SOURCE_USER); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 723 | |
| 724 | // Does not store the preferences locally. |
| 725 | EXPECT_FALSE(local_state()->FindPreference( |
| 726 | prefs::kSecondaryDisplays)->HasUserSetting()); |
| 727 | EXPECT_FALSE(local_state()->FindPreference( |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 728 | prefs::kDisplayProperties)->HasUserSetting()); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 729 | |
| 730 | // Settings are still notified to the system. |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 731 | display::Screen* screen = display::Screen::GetScreen(); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 732 | EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 733 | const display::DisplayPlacement& placement = |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 734 | display_manager()->GetCurrentDisplayLayout().placement_list[0]; |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 735 | EXPECT_EQ(display::DisplayPlacement::BOTTOM, placement.position); |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 736 | EXPECT_EQ(-10, placement.offset); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 737 | const display::Display& primary_display = screen->GetPrimaryDisplay(); |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 738 | EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 739 | EXPECT_EQ(display::Display::ROTATE_90, primary_display.rotation()); |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 740 | |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 741 | const display::ManagedDisplayInfo& info1 = |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 742 | display_manager()->GetDisplayInfo(id1); |
[email protected] | ccb962d | 2013-11-20 02:54:01 | [diff] [blame] | 743 | EXPECT_EQ(1.25f, info1.configured_ui_scale()); |
[email protected] | 8b2447e | 2013-03-22 21:13:31 | [diff] [blame] | 744 | |
rjkroege | 259c0188 | 2016-08-30 19:29:50 | [diff] [blame] | 745 | const display::ManagedDisplayInfo& info_primary = |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 746 | display_manager()->GetDisplayInfo(new_primary); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 747 | EXPECT_EQ(display::Display::ROTATE_90, info_primary.GetActiveRotation()); |
[email protected] | ccb962d | 2013-11-20 02:54:01 | [diff] [blame] | 748 | EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 749 | } |
| 750 | |
[email protected] | 1ccbac1 | 2013-09-13 06:55:54 | [diff] [blame] | 751 | TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { |
| 752 | EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| 753 | |
| 754 | // Stores display prefs without login, which still stores the power state. |
| 755 | StoreDisplayPrefs(); |
| 756 | EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| 757 | } |
| 758 | |
| 759 | TEST_F(DisplayPreferencesTest, StorePowerStateGuest) { |
| 760 | EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| 761 | |
| 762 | LoggedInAsGuest(); |
| 763 | StoreDisplayPrefs(); |
| 764 | EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| 765 | } |
| 766 | |
| 767 | TEST_F(DisplayPreferencesTest, StorePowerStateNormalUser) { |
| 768 | EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| 769 | |
| 770 | LoggedInAsUser(); |
| 771 | StoreDisplayPrefs(); |
| 772 | EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| 773 | } |
| 774 | |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 775 | TEST_F(DisplayPreferencesTest, DisplayPowerStateAfterRestart) { |
| 776 | StoreDisplayPowerStateForTest( |
| 777 | chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
| 778 | LoadDisplayPreferences(false); |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 779 | EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 780 | ash::Shell::Get()->display_configurator()->requested_power_state()); |
[email protected] | 29190fd | 2013-03-30 16:09:50 | [diff] [blame] | 781 | } |
| 782 | |
[email protected] | b732a6d | 2013-11-13 05:52:12 | [diff] [blame] | 783 | TEST_F(DisplayPreferencesTest, DontSaveAndRestoreAllOff) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 784 | ash::Shell* shell = ash::Shell::Get(); |
[email protected] | b732a6d | 2013-11-13 05:52:12 | [diff] [blame] | 785 | StoreDisplayPowerStateForTest( |
| 786 | chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
| 787 | LoadDisplayPreferences(false); |
| 788 | // DisplayPowerState should be ignored at boot. |
| 789 | EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
derat | 4a06278 | 2014-09-25 21:46:13 | [diff] [blame] | 790 | shell->display_configurator()->requested_power_state()); |
[email protected] | b732a6d | 2013-11-13 05:52:12 | [diff] [blame] | 791 | |
| 792 | StoreDisplayPowerStateForTest( |
| 793 | chromeos::DISPLAY_POWER_ALL_OFF); |
| 794 | EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
derat | 4a06278 | 2014-09-25 21:46:13 | [diff] [blame] | 795 | shell->display_configurator()->requested_power_state()); |
[email protected] | b732a6d | 2013-11-13 05:52:12 | [diff] [blame] | 796 | EXPECT_EQ("internal_off_external_on", |
| 797 | local_state()->GetString(prefs::kDisplayPowerState)); |
| 798 | |
| 799 | // Don't try to load |
| 800 | local_state()->SetString(prefs::kDisplayPowerState, "all_off"); |
| 801 | LoadDisplayPreferences(false); |
| 802 | EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
derat | 4a06278 | 2014-09-25 21:46:13 | [diff] [blame] | 803 | shell->display_configurator()->requested_power_state()); |
[email protected] | b732a6d | 2013-11-13 05:52:12 | [diff] [blame] | 804 | } |
| 805 | |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 806 | // Tests that display configuration changes caused by TabletModeController |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 807 | // are not saved. |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 808 | TEST_F(DisplayPreferencesTest, DontSaveTabletModeControllerRotations) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 809 | ash::Shell* shell = ash::Shell::Get(); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 810 | display::Display::SetInternalDisplayId( |
| 811 | display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 812 | LoggedInAsUser(); |
| 813 | // Populate the properties. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 814 | display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(), |
| 815 | display::Display::ROTATE_180, |
| 816 | display::Display::ROTATION_SOURCE_USER); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 817 | // Reset property to avoid rotation lock |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 818 | display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(), |
| 819 | display::Display::ROTATE_0, |
| 820 | display::Display::ROTATION_SOURCE_USER); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 821 | |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 822 | // Open up 270 degrees to trigger tablet mode |
jonross | d6b7705 | 2015-03-11 22:04:35 | [diff] [blame] | 823 | scoped_refptr<chromeos::AccelerometerUpdate> update( |
| 824 | new chromeos::AccelerometerUpdate()); |
| 825 | update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, |
jonross | c47d12e2 | 2015-02-04 00:44:21 | [diff] [blame] | 826 | kMeanGravity); |
jonross | d6b7705 | 2015-03-11 22:04:35 | [diff] [blame] | 827 | update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 828 | ash::TabletModeController* controller = |
| 829 | ash::Shell::Get()->tablet_mode_controller(); |
flackr | 45f31ae7 | 2014-09-02 18:50:25 | [diff] [blame] | 830 | controller->OnAccelerometerUpdated(update); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 831 | EXPECT_TRUE(controller->IsTabletModeWindowManagerEnabled()); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 832 | |
| 833 | // Trigger 90 degree rotation |
jonross | d6b7705 | 2015-03-11 22:04:35 | [diff] [blame] | 834 | update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, -kMeanGravity, |
jonross | c47d12e2 | 2015-02-04 00:44:21 | [diff] [blame] | 835 | 0.0f, 0.0f); |
jonross | d6b7705 | 2015-03-11 22:04:35 | [diff] [blame] | 836 | update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.0f, 0.0f); |
flackr | 45f31ae7 | 2014-09-02 18:50:25 | [diff] [blame] | 837 | controller->OnAccelerometerUpdated(update); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 838 | shell->screen_orientation_controller()->OnAccelerometerUpdated(update); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 839 | EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 840 | |
| 841 | const base::DictionaryValue* properties = |
| 842 | local_state()->GetDictionary(prefs::kDisplayProperties); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 843 | const base::DictionaryValue* property = nullptr; |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 844 | EXPECT_TRUE(properties->GetDictionary( |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 845 | base::Int64ToString(display::Display::InternalDisplayId()), &property)); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 846 | int rotation = -1; |
| 847 | EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 848 | EXPECT_EQ(display::Display::ROTATE_0, rotation); |
jonross | d01de7f | 2015-04-23 19:52:00 | [diff] [blame] | 849 | |
| 850 | // Trigger a save, the acceleration rotation should not be saved as the user |
| 851 | // rotation. |
| 852 | StoreDisplayPrefs(); |
| 853 | properties = local_state()->GetDictionary(prefs::kDisplayProperties); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 854 | property = nullptr; |
jonross | d01de7f | 2015-04-23 19:52:00 | [diff] [blame] | 855 | EXPECT_TRUE(properties->GetDictionary( |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 856 | base::Int64ToString(display::Display::InternalDisplayId()), &property)); |
jonross | d01de7f | 2015-04-23 19:52:00 | [diff] [blame] | 857 | rotation = -1; |
| 858 | EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 859 | EXPECT_EQ(display::Display::ROTATE_0, rotation); |
[email protected] | da28585 | 2014-05-27 19:53:43 | [diff] [blame] | 860 | } |
| 861 | |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 862 | // Tests that the rotation state is saved without a user being logged in. |
| 863 | TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 864 | display::Display::SetInternalDisplayId( |
| 865 | display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 866 | EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 867 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 868 | bool current_rotation_lock = IsRotationLocked(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 869 | StoreDisplayRotationPrefs(current_rotation_lock); |
| 870 | EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 871 | |
| 872 | const base::DictionaryValue* properties = |
| 873 | local_state()->GetDictionary(prefs::kDisplayRotationLock); |
| 874 | bool rotation_lock; |
| 875 | EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
| 876 | EXPECT_EQ(current_rotation_lock, rotation_lock); |
| 877 | |
| 878 | int orientation; |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 879 | display::Display::Rotation current_rotation = |
| 880 | GetCurrentInternalDisplayRotation(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 881 | EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
| 882 | EXPECT_EQ(current_rotation, orientation); |
| 883 | } |
| 884 | |
| 885 | // Tests that the rotation state is saved when a guest is logged in. |
| 886 | TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 887 | display::Display::SetInternalDisplayId( |
| 888 | display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 889 | EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 890 | LoggedInAsGuest(); |
| 891 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 892 | bool current_rotation_lock = IsRotationLocked(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 893 | StoreDisplayRotationPrefs(current_rotation_lock); |
| 894 | EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 895 | |
| 896 | const base::DictionaryValue* properties = |
| 897 | local_state()->GetDictionary(prefs::kDisplayRotationLock); |
| 898 | bool rotation_lock; |
| 899 | EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
| 900 | EXPECT_EQ(current_rotation_lock, rotation_lock); |
| 901 | |
| 902 | int orientation; |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 903 | display::Display::Rotation current_rotation = |
| 904 | GetCurrentInternalDisplayRotation(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 905 | EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
| 906 | EXPECT_EQ(current_rotation, orientation); |
| 907 | } |
| 908 | |
| 909 | // Tests that the rotation state is saved when a normal user is logged in. |
| 910 | TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 911 | display::Display::SetInternalDisplayId( |
| 912 | display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 913 | EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 914 | LoggedInAsGuest(); |
| 915 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 916 | bool current_rotation_lock = IsRotationLocked(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 917 | StoreDisplayRotationPrefs(current_rotation_lock); |
| 918 | EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 919 | |
| 920 | const base::DictionaryValue* properties = |
| 921 | local_state()->GetDictionary(prefs::kDisplayRotationLock); |
| 922 | bool rotation_lock; |
| 923 | EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
| 924 | EXPECT_EQ(current_rotation_lock, rotation_lock); |
| 925 | |
| 926 | int orientation; |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 927 | display::Display::Rotation current_rotation = |
| 928 | GetCurrentInternalDisplayRotation(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 929 | EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
| 930 | EXPECT_EQ(current_rotation, orientation); |
| 931 | } |
| 932 | |
| 933 | // Tests that rotation state is loaded without a user being logged in, and that |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 934 | // entering tablet mode applies the state. |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 935 | TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 936 | display::Display::SetInternalDisplayId( |
| 937 | display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 938 | ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 939 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 940 | bool initial_rotation_lock = IsRotationLocked(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 941 | ASSERT_FALSE(initial_rotation_lock); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 942 | display::Display::Rotation initial_rotation = |
| 943 | GetCurrentInternalDisplayRotation(); |
| 944 | ASSERT_EQ(display::Display::ROTATE_0, initial_rotation); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 945 | |
| 946 | StoreDisplayRotationPrefs(initial_rotation_lock); |
| 947 | ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 948 | |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 949 | StoreDisplayRotationPrefsForTest(true, display::Display::ROTATE_90); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 950 | LoadDisplayPreferences(false); |
| 951 | |
| 952 | bool display_rotation_lock = |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 953 | display_manager()->registered_internal_display_rotation_lock(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 954 | bool display_rotation = |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 955 | display_manager()->registered_internal_display_rotation(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 956 | EXPECT_TRUE(display_rotation_lock); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 957 | EXPECT_EQ(display::Display::ROTATE_90, display_rotation); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 958 | |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 959 | bool rotation_lock = IsRotationLocked(); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 960 | display::Display::Rotation before_tablet_mode_rotation = |
jonross | d01de7f | 2015-04-23 19:52:00 | [diff] [blame] | 961 | GetCurrentInternalDisplayRotation(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 962 | |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 963 | // Settings should not be applied until tablet mode activates |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 964 | EXPECT_FALSE(rotation_lock); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 965 | EXPECT_EQ(display::Display::ROTATE_0, before_tablet_mode_rotation); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 966 | |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 967 | // Open up 270 degrees to trigger tablet mode |
jonross | d6b7705 | 2015-03-11 22:04:35 | [diff] [blame] | 968 | scoped_refptr<chromeos::AccelerometerUpdate> update( |
| 969 | new chromeos::AccelerometerUpdate()); |
| 970 | update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, |
jonross | c47d12e2 | 2015-02-04 00:44:21 | [diff] [blame] | 971 | kMeanGravity); |
jonross | d6b7705 | 2015-03-11 22:04:35 | [diff] [blame] | 972 | update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 973 | ash::TabletModeController* tablet_mode_controller = |
| 974 | ash::Shell::Get()->tablet_mode_controller(); |
| 975 | tablet_mode_controller->OnAccelerometerUpdated(update); |
| 976 | EXPECT_TRUE(tablet_mode_controller->IsTabletModeWindowManagerEnabled()); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 977 | bool screen_orientation_rotation_lock = IsRotationLocked(); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 978 | display::Display::Rotation tablet_mode_rotation = |
jonross | d01de7f | 2015-04-23 19:52:00 | [diff] [blame] | 979 | GetCurrentInternalDisplayRotation(); |
jonross | 0af4521 | 2015-01-13 18:55:46 | [diff] [blame] | 980 | EXPECT_TRUE(screen_orientation_rotation_lock); |
Mitsuru Oshima | 0e9b7a6 | 2017-07-19 18:23:03 | [diff] [blame] | 981 | EXPECT_EQ(display::Display::ROTATE_90, tablet_mode_rotation); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 982 | } |
| 983 | |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 984 | // Tests that rotation lock being set causes the rotation state to be saved. |
| 985 | TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 986 | display::Display::SetInternalDisplayId( |
| 987 | display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 988 | ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 989 | |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 990 | ash::Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); |
[email protected] | 62e90d4 | 2014-08-20 15:23:32 | [diff] [blame] | 991 | |
| 992 | EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 993 | |
| 994 | const base::DictionaryValue* properties = |
| 995 | local_state()->GetDictionary(prefs::kDisplayRotationLock); |
| 996 | bool rotation_lock; |
| 997 | EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
| 998 | } |
| 999 | |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1000 | TEST_F(DisplayPreferencesTest, SaveUnifiedMode) { |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1001 | LoggedInAsUser(); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1002 | display_manager()->SetUnifiedDesktopEnabled(true); |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 1003 | |
oshima | af6e857 | 2015-07-30 19:41:57 | [diff] [blame] | 1004 | UpdateDisplay("200x200,100x100"); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1005 | display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList(); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 1006 | EXPECT_EQ( |
| 1007 | "400x200", |
| 1008 | display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1009 | |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 1010 | const base::DictionaryValue* secondary_displays = |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1011 | local_state()->GetDictionary(prefs::kSecondaryDisplays); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 1012 | const base::DictionaryValue* new_value = nullptr; |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 1013 | EXPECT_TRUE(secondary_displays->GetDictionary( |
rjkroege | 0458f01 | 2016-08-31 00:31:36 | [diff] [blame] | 1014 | display::DisplayIdListToString(list), &new_value)); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1015 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 1016 | display::DisplayLayout stored_layout; |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 1017 | EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout)); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1018 | EXPECT_TRUE(stored_layout.default_unified); |
| 1019 | EXPECT_FALSE(stored_layout.mirrored); |
| 1020 | |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 1021 | const base::DictionaryValue* displays = |
| 1022 | local_state()->GetDictionary(prefs::kDisplayProperties); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 1023 | int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
oshima | 2190eb61 | 2015-07-28 22:44:43 | [diff] [blame] | 1024 | EXPECT_FALSE( |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 1025 | displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 1026 | |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 1027 | display::test::SetDisplayResolution(display_manager(), unified_id, |
| 1028 | gfx::Size(200, 100)); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 1029 | EXPECT_EQ( |
| 1030 | "200x100", |
| 1031 | display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); |
oshima | 2190eb61 | 2015-07-28 22:44:43 | [diff] [blame] | 1032 | EXPECT_FALSE( |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 1033 | displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 1034 | |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1035 | // Mirror mode should remember if the default mode was unified. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1036 | display_manager()->SetMirrorMode(true); |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 1037 | ASSERT_TRUE(secondary_displays->GetDictionary( |
rjkroege | 0458f01 | 2016-08-31 00:31:36 | [diff] [blame] | 1038 | display::DisplayIdListToString(list), &new_value)); |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 1039 | EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout)); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1040 | EXPECT_TRUE(stored_layout.default_unified); |
| 1041 | EXPECT_TRUE(stored_layout.mirrored); |
| 1042 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1043 | display_manager()->SetMirrorMode(false); |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 1044 | ASSERT_TRUE(secondary_displays->GetDictionary( |
rjkroege | 0458f01 | 2016-08-31 00:31:36 | [diff] [blame] | 1045 | display::DisplayIdListToString(list), &new_value)); |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 1046 | EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout)); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1047 | EXPECT_TRUE(stored_layout.default_unified); |
| 1048 | EXPECT_FALSE(stored_layout.mirrored); |
| 1049 | |
| 1050 | // Exit unified mode. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1051 | display_manager()->SetDefaultMultiDisplayModeForCurrentDisplays( |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 1052 | display::DisplayManager::EXTENDED); |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 1053 | ASSERT_TRUE(secondary_displays->GetDictionary( |
rjkroege | 0458f01 | 2016-08-31 00:31:36 | [diff] [blame] | 1054 | display::DisplayIdListToString(list), &new_value)); |
thanhph | 9a5d265 | 2017-03-18 18:57:11 | [diff] [blame] | 1055 | EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout)); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1056 | EXPECT_FALSE(stored_layout.default_unified); |
| 1057 | EXPECT_FALSE(stored_layout.mirrored); |
| 1058 | } |
| 1059 | |
| 1060 | TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 1061 | int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 1062 | display::DisplayIdList list = |
| 1063 | display::test::CreateDisplayIdList2(id1, id1 + 1); |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 1064 | StoreDisplayBoolPropertyForList(list, "default_unified", true); |
| 1065 | StoreDisplayPropertyForList( |
| 1066 | list, "primary-id", |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 1067 | base::MakeUnique<base::Value>(base::Int64ToString(id1))); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1068 | LoadDisplayPreferences(false); |
| 1069 | |
| 1070 | // Should not restore to unified unless unified desktop is enabled. |
| 1071 | UpdateDisplay("100x100,200x200"); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1072 | EXPECT_FALSE(display_manager()->IsInUnifiedMode()); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1073 | |
| 1074 | // Restored to unified. |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1075 | display_manager()->SetUnifiedDesktopEnabled(true); |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 1076 | StoreDisplayBoolPropertyForList(list, "default_unified", true); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1077 | LoadDisplayPreferences(false); |
| 1078 | UpdateDisplay("100x100,200x200"); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1079 | EXPECT_TRUE(display_manager()->IsInUnifiedMode()); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1080 | |
| 1081 | // Restored to mirror, then unified. |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 1082 | StoreDisplayBoolPropertyForList(list, "mirrored", true); |
| 1083 | StoreDisplayBoolPropertyForList(list, "default_unified", true); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1084 | LoadDisplayPreferences(false); |
| 1085 | UpdateDisplay("100x100,200x200"); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1086 | EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1087 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1088 | display_manager()->SetMirrorMode(false); |
| 1089 | EXPECT_TRUE(display_manager()->IsInUnifiedMode()); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1090 | |
| 1091 | // Sanity check. Restore to extended. |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 1092 | StoreDisplayBoolPropertyForList(list, "default_unified", false); |
| 1093 | StoreDisplayBoolPropertyForList(list, "mirrored", false); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1094 | LoadDisplayPreferences(false); |
| 1095 | UpdateDisplay("100x100,200x200"); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1096 | EXPECT_FALSE(display_manager()->IsInMirrorMode()); |
| 1097 | EXPECT_FALSE(display_manager()->IsInUnifiedMode()); |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 1098 | } |
| 1099 | |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1100 | TEST_F(DisplayPreferencesTest, SaveThreeDisplays) { |
| 1101 | LoggedInAsUser(); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1102 | UpdateDisplay("200x200,200x200,300x300"); |
| 1103 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1104 | display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList(); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1105 | ASSERT_EQ(3u, list.size()); |
| 1106 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 1107 | display::DisplayLayoutBuilder builder(list[0]); |
| 1108 | builder.AddDisplayPlacement(list[1], list[0], |
| 1109 | display::DisplayPlacement::RIGHT, 0); |
| 1110 | builder.AddDisplayPlacement(list[2], list[0], |
| 1111 | display::DisplayPlacement::BOTTOM, 100); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1112 | display_manager()->SetLayoutForCurrentDisplays(builder.Build()); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1113 | |
| 1114 | const base::DictionaryValue* secondary_displays = |
| 1115 | local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 1116 | const base::DictionaryValue* new_value = nullptr; |
| 1117 | EXPECT_TRUE(secondary_displays->GetDictionary( |
rjkroege | 0458f01 | 2016-08-31 00:31:36 | [diff] [blame] | 1118 | display::DisplayIdListToString(list), &new_value)); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) { |
| 1122 | LoggedInAsUser(); |
oshima | d5c972e | 2016-04-28 23:17:14 | [diff] [blame] | 1123 | int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 1124 | display::DisplayIdList list = |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 1125 | display::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1126 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 1127 | display::DisplayLayoutBuilder builder(list[0]); |
| 1128 | builder.AddDisplayPlacement(list[1], list[0], display::DisplayPlacement::LEFT, |
| 1129 | 0); |
| 1130 | builder.AddDisplayPlacement(list[2], list[1], |
| 1131 | display::DisplayPlacement::BOTTOM, 100); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1132 | StoreDisplayLayoutPrefForTest(list, *builder.Build()); |
| 1133 | LoadDisplayPreferences(false); |
| 1134 | |
| 1135 | UpdateDisplay("200x200,200x200,300x300"); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1136 | display::DisplayIdList new_list = |
| 1137 | display_manager()->GetCurrentDisplayIdList(); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1138 | ASSERT_EQ(3u, list.size()); |
| 1139 | ASSERT_EQ(list[0], new_list[0]); |
| 1140 | ASSERT_EQ(list[1], new_list[1]); |
| 1141 | ASSERT_EQ(list[2], new_list[2]); |
| 1142 | |
| 1143 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1144 | display_manager()->GetDisplayForId(list[0]).bounds()); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1145 | EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1146 | display_manager()->GetDisplayForId(list[1]).bounds()); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1147 | EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 1148 | display_manager()->GetDisplayForId(list[2]).bounds()); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 1149 | } |
| 1150 | |
Mitsuru Oshima | 3695b8be | 2017-10-09 14:18:36 | [diff] [blame] | 1151 | TEST_F(DisplayPreferencesTest, MirrorWhenEnterTableMode) { |
| 1152 | display::Display::SetInternalDisplayId( |
| 1153 | display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 1154 | LoggedInAsUser(); |
| 1155 | UpdateDisplay("800x600,1200x800"); |
| 1156 | EXPECT_FALSE(display_manager()->IsInMirrorMode()); |
| 1157 | ash::TabletModeController* controller = |
| 1158 | ash::Shell::Get()->tablet_mode_controller(); |
| 1159 | controller->EnableTabletModeWindowManager(true); |
| 1160 | ASSERT_TRUE(controller->IsTabletModeWindowManagerEnabled()); |
| 1161 | EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
| 1162 | |
| 1163 | // Make sure the mirror mode is not saved in the preference. |
| 1164 | display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList(); |
| 1165 | ASSERT_EQ(2u, list.size()); |
| 1166 | base::Value* value; |
| 1167 | EXPECT_TRUE(GetDisplayPropertyFromList(list, "mirrored", &value)); |
| 1168 | bool mirrored; |
| 1169 | EXPECT_TRUE(value->GetAsBoolean(&mirrored)); |
| 1170 | EXPECT_FALSE(mirrored); |
| 1171 | |
| 1172 | // Exiting the tablet mode should exit mirror mode. |
| 1173 | controller->EnableTabletModeWindowManager(false); |
| 1174 | ASSERT_FALSE(controller->IsTabletModeWindowManagerEnabled()); |
| 1175 | EXPECT_FALSE(display_manager()->IsInMirrorMode()); |
| 1176 | } |
| 1177 | |
| 1178 | TEST_F(DisplayPreferencesTest, AlreadyMirrorWhenEnterTableMode) { |
| 1179 | display::Display::SetInternalDisplayId( |
| 1180 | display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 1181 | LoggedInAsUser(); |
| 1182 | UpdateDisplay("800x600,1200x800"); |
| 1183 | display_manager()->SetMirrorMode(true); |
| 1184 | EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
| 1185 | ash::TabletModeController* controller = |
| 1186 | ash::Shell::Get()->tablet_mode_controller(); |
| 1187 | controller->EnableTabletModeWindowManager(true); |
| 1188 | ASSERT_TRUE(controller->IsTabletModeWindowManagerEnabled()); |
| 1189 | EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
| 1190 | |
| 1191 | // Exiting the tablet mode should stay in mirror mode. |
| 1192 | controller->EnableTabletModeWindowManager(false); |
| 1193 | ASSERT_FALSE(controller->IsTabletModeWindowManagerEnabled()); |
| 1194 | EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
| 1195 | } |
| 1196 | |
F#m | 4791c3d7 | 2017-11-03 21:39:58 | [diff] [blame] | 1197 | TEST_F(DisplayPreferencesTest, LegacyTouchCalibrationDataSupport) { |
| 1198 | UpdateDisplay("800x600,1200x800"); |
| 1199 | LoggedInAsUser(); |
| 1200 | int64_t id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 1201 | display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad = { |
| 1202 | {std::make_pair(gfx::Point(10, 10), gfx::Point(11, 12)), |
| 1203 | std::make_pair(gfx::Point(190, 10), gfx::Point(195, 8)), |
| 1204 | std::make_pair(gfx::Point(10, 90), gfx::Point(12, 94)), |
| 1205 | std::make_pair(gfx::Point(190, 90), gfx::Point(189, 88))}}; |
| 1206 | gfx::Size touch_size(200, 150); |
| 1207 | display::TouchCalibrationData data(point_pair_quad, touch_size); |
| 1208 | |
| 1209 | StoreLegacyTouchDataForTest(id, data); |
| 1210 | |
| 1211 | display::TouchDeviceManager* tdm = display_manager()->touch_device_manager(); |
| 1212 | display::test::TouchDeviceManagerTestApi tdm_test_api(tdm); |
| 1213 | tdm_test_api.ResetTouchDeviceManager(); |
| 1214 | |
| 1215 | LoadTouchAssociationPreferenceForTest(); |
| 1216 | |
| 1217 | const display::TouchDeviceManager::TouchAssociationMap& association_map = |
| 1218 | tdm->touch_associations(); |
| 1219 | |
| 1220 | const display::TouchDeviceIdentifier& fallback_identifier = |
| 1221 | display::TouchDeviceIdentifier::GetFallbackTouchDeviceIdentifier(); |
| 1222 | |
| 1223 | EXPECT_TRUE(association_map.count(fallback_identifier)); |
| 1224 | EXPECT_TRUE(association_map.at(fallback_identifier).count(id)); |
| 1225 | EXPECT_EQ(association_map.at(fallback_identifier).at(id).calibration_data, |
| 1226 | data); |
| 1227 | |
| 1228 | int64_t id_2 = display_manager()->GetSecondaryDisplay().id(); |
| 1229 | gfx::Size touch_size_2(300, 300); |
| 1230 | display::TouchCalibrationData data_2(point_pair_quad, touch_size_2); |
| 1231 | |
| 1232 | display::TouchDeviceIdentifier identifier(12345); |
| 1233 | display_manager()->SetTouchCalibrationData(id_2, point_pair_quad, |
| 1234 | touch_size_2, identifier); |
| 1235 | |
| 1236 | EXPECT_TRUE(tdm->touch_associations().count(identifier)); |
| 1237 | EXPECT_TRUE(tdm->touch_associations().at(identifier).count(id_2)); |
| 1238 | EXPECT_EQ(tdm->touch_associations().at(identifier).at(id_2).calibration_data, |
| 1239 | data_2); |
| 1240 | |
| 1241 | tdm_test_api.ResetTouchDeviceManager(); |
| 1242 | EXPECT_TRUE(tdm->touch_associations().empty()); |
| 1243 | |
| 1244 | LoadTouchAssociationPreferenceForTest(); |
| 1245 | |
| 1246 | EXPECT_TRUE(tdm->touch_associations().count(fallback_identifier)); |
| 1247 | EXPECT_TRUE(tdm->touch_associations().at(fallback_identifier).count(id)); |
| 1248 | EXPECT_EQ( |
| 1249 | tdm->touch_associations().at(fallback_identifier).at(id).calibration_data, |
| 1250 | data); |
| 1251 | EXPECT_TRUE(tdm->touch_associations().count(identifier)); |
| 1252 | EXPECT_TRUE(tdm->touch_associations().at(identifier).count(id_2)); |
| 1253 | EXPECT_EQ(tdm->touch_associations().at(identifier).at(id_2).calibration_data, |
| 1254 | data_2); |
| 1255 | } |
| 1256 | |
[email protected] | 78e23704 | 2013-01-02 22:35:09 | [diff] [blame] | 1257 | } // namespace chromeos |