| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/display/display_preferences.h" | 5 #include "chrome/browser/chromeos/display/display_preferences.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 |
| 8 #include <string> | 9 #include <string> |
| 9 #include <utility> | 10 #include <utility> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "ash/display/display_layout_builder.h" | 13 #include "ash/display/display_layout_builder.h" |
| 13 #include "ash/display/display_layout_store.h" | 14 #include "ash/display/display_layout_store.h" |
| 14 #include "ash/display/display_manager.h" | 15 #include "ash/display/display_manager.h" |
| 15 #include "ash/display/display_util.h" | 16 #include "ash/display/display_util.h" |
| 16 #include "ash/display/json_converter.h" | 17 #include "ash/display/json_converter.h" |
| 17 #include "ash/display/resolution_notification_controller.h" | 18 #include "ash/display/resolution_notification_controller.h" |
| 18 #include "ash/display/screen_orientation_controller_chromeos.h" | 19 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 19 #include "ash/display/window_tree_host_manager.h" | 20 #include "ash/display/window_tree_host_manager.h" |
| 20 #include "ash/screen_util.h" | 21 #include "ash/screen_util.h" |
| 21 #include "ash/shell.h" | 22 #include "ash/shell.h" |
| 22 #include "ash/test/ash_test_base.h" | 23 #include "ash/test/ash_test_base.h" |
| 23 #include "ash/test/display_manager_test_api.h" | 24 #include "ash/test/display_manager_test_api.h" |
| 24 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 25 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 25 #include "base/macros.h" | 26 #include "base/macros.h" |
| 27 #include "base/memory/ptr_util.h" |
| 26 #include "base/memory/ref_counted.h" | 28 #include "base/memory/ref_counted.h" |
| 27 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/values.h" | 30 #include "base/values.h" |
| 29 #include "chrome/browser/chromeos/display/display_configuration_observer.h" | 31 #include "chrome/browser/chromeos/display/display_configuration_observer.h" |
| 30 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 32 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 33 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 32 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/test/base/testing_browser_process.h" | 35 #include "chrome/test/base/testing_browser_process.h" |
| 34 #include "components/prefs/scoped_user_pref_update.h" | 36 #include "components/prefs/scoped_user_pref_update.h" |
| 35 #include "components/prefs/testing_pref_service.h" | 37 #include "components/prefs/testing_pref_service.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 int64_t primary_id) { | 109 int64_t primary_id) { |
| 108 std::string name = ash::DisplayIdListToString(list); | 110 std::string name = ash::DisplayIdListToString(list); |
| 109 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); | 111 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); |
| 110 ash::DisplayLayout display_layout; | 112 ash::DisplayLayout display_layout; |
| 111 display_layout.placement_list.emplace_back(position, offset); | 113 display_layout.placement_list.emplace_back(position, offset); |
| 112 display_layout.primary_id = primary_id; | 114 display_layout.primary_id = primary_id; |
| 113 | 115 |
| 114 DCHECK(!name.empty()); | 116 DCHECK(!name.empty()); |
| 115 | 117 |
| 116 base::DictionaryValue* pref_data = update.Get(); | 118 base::DictionaryValue* pref_data = update.Get(); |
| 117 scoped_ptr<base::Value>layout_value(new base::DictionaryValue()); | 119 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); |
| 118 if (pref_data->HasKey(name)) { | 120 if (pref_data->HasKey(name)) { |
| 119 base::Value* value = nullptr; | 121 base::Value* value = nullptr; |
| 120 if (pref_data->Get(name, &value) && value != nullptr) | 122 if (pref_data->Get(name, &value) && value != nullptr) |
| 121 layout_value.reset(value->DeepCopy()); | 123 layout_value.reset(value->DeepCopy()); |
| 122 } | 124 } |
| 123 if (ash::DisplayLayoutToJson(display_layout, layout_value.get())) | 125 if (ash::DisplayLayoutToJson(display_layout, layout_value.get())) |
| 124 pref_data->Set(name, layout_value.release()); | 126 pref_data->Set(name, layout_value.release()); |
| 125 } | 127 } |
| 126 | 128 |
| 127 void StoreDisplayPropertyForList(const ash::DisplayIdList& list, | 129 void StoreDisplayPropertyForList(const ash::DisplayIdList& list, |
| 128 std::string key, | 130 std::string key, |
| 129 scoped_ptr<base::Value> value) { | 131 std::unique_ptr<base::Value> value) { |
| 130 std::string name = ash::DisplayIdListToString(list); | 132 std::string name = ash::DisplayIdListToString(list); |
| 131 | 133 |
| 132 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); | 134 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); |
| 133 base::DictionaryValue* pref_data = update.Get(); | 135 base::DictionaryValue* pref_data = update.Get(); |
| 134 | 136 |
| 135 if (pref_data->HasKey(name)) { | 137 if (pref_data->HasKey(name)) { |
| 136 base::Value* layout_value = nullptr; | 138 base::Value* layout_value = nullptr; |
| 137 pref_data->Get(name, &layout_value); | 139 pref_data->Get(name, &layout_value); |
| 138 if (layout_value) | 140 if (layout_value) |
| 139 static_cast<base::DictionaryValue*>(layout_value) | 141 static_cast<base::DictionaryValue*>(layout_value) |
| 140 ->Set(key, std::move(value)); | 142 ->Set(key, std::move(value)); |
| 141 } else { | 143 } else { |
| 142 scoped_ptr<base::DictionaryValue> layout_value( | 144 std::unique_ptr<base::DictionaryValue> layout_value( |
| 143 new base::DictionaryValue()); | 145 new base::DictionaryValue()); |
| 144 layout_value->SetBoolean(key, value != nullptr); | 146 layout_value->SetBoolean(key, value != nullptr); |
| 145 pref_data->Set(name, layout_value.release()); | 147 pref_data->Set(name, layout_value.release()); |
| 146 } | 148 } |
| 147 } | 149 } |
| 148 | 150 |
| 149 void StoreDisplayBoolPropertyForList(const ash::DisplayIdList& list, | 151 void StoreDisplayBoolPropertyForList(const ash::DisplayIdList& list, |
| 150 const std::string& key, | 152 const std::string& key, |
| 151 bool value) { | 153 bool value) { |
| 152 StoreDisplayPropertyForList( | 154 StoreDisplayPropertyForList( |
| 153 list, key, make_scoped_ptr(new base::FundamentalValue(value))); | 155 list, key, base::WrapUnique(new base::FundamentalValue(value))); |
| 154 } | 156 } |
| 155 | 157 |
| 156 void StoreDisplayLayoutPrefForList(const ash::DisplayIdList& list, | 158 void StoreDisplayLayoutPrefForList(const ash::DisplayIdList& list, |
| 157 ash::DisplayPlacement::Position layout, | 159 ash::DisplayPlacement::Position layout, |
| 158 int offset) { | 160 int offset) { |
| 159 StoreDisplayLayoutPrefForList(list, layout, offset, list[0]); | 161 StoreDisplayLayoutPrefForList(list, layout, offset, list[0]); |
| 160 } | 162 } |
| 161 | 163 |
| 162 void StoreDisplayOverscan(int64_t id, const gfx::Insets& insets) { | 164 void StoreDisplayOverscan(int64_t id, const gfx::Insets& insets) { |
| 163 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties); | 165 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 .placement_list[0] | 200 .placement_list[0] |
| 199 .ToString(); | 201 .ToString(); |
| 200 } | 202 } |
| 201 | 203 |
| 202 PrefService* local_state() { return &local_state_; } | 204 PrefService* local_state() { return &local_state_; } |
| 203 | 205 |
| 204 private: | 206 private: |
| 205 MockUserManager* mock_user_manager_; // Not owned. | 207 MockUserManager* mock_user_manager_; // Not owned. |
| 206 ScopedUserManagerEnabler user_manager_enabler_; | 208 ScopedUserManagerEnabler user_manager_enabler_; |
| 207 TestingPrefServiceSimple local_state_; | 209 TestingPrefServiceSimple local_state_; |
| 208 scoped_ptr<DisplayConfigurationObserver> observer_; | 210 std::unique_ptr<DisplayConfigurationObserver> observer_; |
| 209 | 211 |
| 210 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); | 212 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); |
| 211 }; | 213 }; |
| 212 | 214 |
| 213 } // namespace | 215 } // namespace |
| 214 | 216 |
| 215 TEST_F(DisplayPreferencesTest, ListedLayoutOverrides) { | 217 TEST_F(DisplayPreferencesTest, ListedLayoutOverrides) { |
| 216 UpdateDisplay("100x100,200x200"); | 218 UpdateDisplay("100x100,200x200"); |
| 217 ash::DisplayManager* display_manager = | 219 ash::DisplayManager* display_manager = |
| 218 ash::Shell::GetInstance()->display_manager(); | 220 ash::Shell::GetInstance()->display_manager(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 278 |
| 277 display_manager->SetLayoutForCurrentDisplays( | 279 display_manager->SetLayoutForCurrentDisplays( |
| 278 ash::test::CreateDisplayLayout(ash::DisplayPlacement::TOP, 10)); | 280 ash::test::CreateDisplayLayout(ash::DisplayPlacement::TOP, 10)); |
| 279 const ash::DisplayLayout& layout = display_manager->GetCurrentDisplayLayout(); | 281 const ash::DisplayLayout& layout = display_manager->GetCurrentDisplayLayout(); |
| 280 EXPECT_EQ(ash::DisplayPlacement::TOP, layout.placement_list[0].position); | 282 EXPECT_EQ(ash::DisplayPlacement::TOP, layout.placement_list[0].position); |
| 281 EXPECT_EQ(10, layout.placement_list[0].offset); | 283 EXPECT_EQ(10, layout.placement_list[0].offset); |
| 282 | 284 |
| 283 ash::DisplayLayoutBuilder dummy_layout_builder(id1); | 285 ash::DisplayLayoutBuilder dummy_layout_builder(id1); |
| 284 dummy_layout_builder.SetSecondaryPlacement(dummy_id, | 286 dummy_layout_builder.SetSecondaryPlacement(dummy_id, |
| 285 ash::DisplayPlacement::LEFT, 20); | 287 ash::DisplayPlacement::LEFT, 20); |
| 286 scoped_ptr<ash::DisplayLayout> dummy_layout(dummy_layout_builder.Build()); | 288 std::unique_ptr<ash::DisplayLayout> dummy_layout( |
| 289 dummy_layout_builder.Build()); |
| 287 ash::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, dummy_id); | 290 ash::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, dummy_id); |
| 288 StoreDisplayLayoutPrefForTest(list, *dummy_layout); | 291 StoreDisplayLayoutPrefForTest(list, *dummy_layout); |
| 289 | 292 |
| 290 // Can't switch to a display that does not exist. | 293 // Can't switch to a display that does not exist. |
| 291 window_tree_host_manager->SetPrimaryDisplayId(dummy_id); | 294 window_tree_host_manager->SetPrimaryDisplayId(dummy_id); |
| 292 EXPECT_NE(dummy_id, gfx::Screen::GetScreen()->GetPrimaryDisplay().id()); | 295 EXPECT_NE(dummy_id, gfx::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 293 | 296 |
| 294 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); | 297 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); |
| 295 display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90, | 298 display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90, |
| 296 gfx::Display::ROTATION_SOURCE_USER); | 299 gfx::Display::ROTATION_SOURCE_USER); |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 EXPECT_FALSE(stored_layout.default_unified); | 1014 EXPECT_FALSE(stored_layout.default_unified); |
| 1012 EXPECT_FALSE(stored_layout.mirrored); | 1015 EXPECT_FALSE(stored_layout.mirrored); |
| 1013 } | 1016 } |
| 1014 | 1017 |
| 1015 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { | 1018 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { |
| 1016 int64_t id1 = gfx::Screen::GetScreen()->GetPrimaryDisplay().id(); | 1019 int64_t id1 = gfx::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 1017 ash::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1); | 1020 ash::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1); |
| 1018 StoreDisplayBoolPropertyForList(list, "default_unified", true); | 1021 StoreDisplayBoolPropertyForList(list, "default_unified", true); |
| 1019 StoreDisplayPropertyForList( | 1022 StoreDisplayPropertyForList( |
| 1020 list, "primary-id", | 1023 list, "primary-id", |
| 1021 make_scoped_ptr(new base::StringValue(base::Int64ToString(id1)))); | 1024 base::WrapUnique(new base::StringValue(base::Int64ToString(id1)))); |
| 1022 LoadDisplayPreferences(false); | 1025 LoadDisplayPreferences(false); |
| 1023 | 1026 |
| 1024 // Should not restore to unified unless unified desktop is enabled. | 1027 // Should not restore to unified unless unified desktop is enabled. |
| 1025 UpdateDisplay("100x100,200x200"); | 1028 UpdateDisplay("100x100,200x200"); |
| 1026 ash::DisplayManager* display_manager = | 1029 ash::DisplayManager* display_manager = |
| 1027 ash::Shell::GetInstance()->display_manager(); | 1030 ash::Shell::GetInstance()->display_manager(); |
| 1028 EXPECT_FALSE(display_manager->IsInUnifiedMode()); | 1031 EXPECT_FALSE(display_manager->IsInUnifiedMode()); |
| 1029 | 1032 |
| 1030 // Restored to unified. | 1033 // Restored to unified. |
| 1031 display_manager->SetUnifiedDesktopEnabled(true); | 1034 display_manager->SetUnifiedDesktopEnabled(true); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 | 1103 |
| 1101 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), | 1104 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 1102 display_manager->GetDisplayForId(list[0]).bounds()); | 1105 display_manager->GetDisplayForId(list[0]).bounds()); |
| 1103 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), | 1106 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), |
| 1104 display_manager->GetDisplayForId(list[1]).bounds()); | 1107 display_manager->GetDisplayForId(list[1]).bounds()); |
| 1105 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), | 1108 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), |
| 1106 display_manager->GetDisplayForId(list[2]).bounds()); | 1109 display_manager->GetDisplayForId(list[2]).bounds()); |
| 1107 } | 1110 } |
| 1108 | 1111 |
| 1109 } // namespace chromeos | 1112 } // namespace chromeos |
| OLD | NEW |