Chromium Code Reviews| 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 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 13 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 14 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
| 15 #include "ash/display/display_manager.h" | 15 #include "ash/display/display_manager.h" |
| 16 #include "ash/display/display_util.h" | 16 #include "ash/display/display_util.h" |
| 17 #include "ash/display/json_converter.h" | 17 #include "ash/display/json_converter.h" |
| 18 #include "ash/display/resolution_notification_controller.h" | 18 #include "ash/display/resolution_notification_controller.h" |
| 19 #include "ash/display/screen_orientation_controller_chromeos.h" | 19 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 20 #include "ash/display/window_tree_host_manager.h" | 20 #include "ash/display/window_tree_host_manager.h" |
| 21 #include "ash/screen_util.h" | 21 //#include "ash/screen_util.h" |
|
oshima
2016/10/04 00:47:16
remove this
rjkroege
2016/10/05 00:21:46
Done.
| |
| 22 #include "ash/shell.h" | |
| 22 #include "ash/shell.h" | 23 #include "ash/shell.h" |
| 23 #include "ash/test/ash_test_base.h" | 24 #include "ash/test/ash_test_base.h" |
| 24 #include "ash/test/display_manager_test_api.h" | 25 #include "ash/test/display_manager_test_api.h" |
| 25 #include "base/macros.h" | 26 #include "base/macros.h" |
| 26 #include "base/memory/ptr_util.h" | 27 #include "base/memory/ptr_util.h" |
| 27 #include "base/memory/ref_counted.h" | 28 #include "base/memory/ref_counted.h" |
| 28 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
| 29 #include "base/values.h" | 30 #include "base/values.h" |
| 30 #include "chrome/browser/chromeos/display/display_configuration_observer.h" | 31 #include "chrome/browser/chromeos/display/display_configuration_observer.h" |
| 31 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 32 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 TestingPrefServiceSimple local_state_; | 214 TestingPrefServiceSimple local_state_; |
| 214 std::unique_ptr<DisplayConfigurationObserver> observer_; | 215 std::unique_ptr<DisplayConfigurationObserver> observer_; |
| 215 | 216 |
| 216 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); | 217 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); |
| 217 }; | 218 }; |
| 218 | 219 |
| 219 } // namespace | 220 } // namespace |
| 220 | 221 |
| 221 TEST_F(DisplayPreferencesTest, ListedLayoutOverrides) { | 222 TEST_F(DisplayPreferencesTest, ListedLayoutOverrides) { |
| 222 UpdateDisplay("100x100,200x200"); | 223 UpdateDisplay("100x100,200x200"); |
| 223 ash::DisplayManager* display_manager = | |
| 224 ash::Shell::GetInstance()->display_manager(); | 224 ash::Shell::GetInstance()->display_manager(); |
|
oshima
2016/10/04 00:47:16
indent (you can just run git cl format)
rjkroege
2016/10/05 00:21:46
Done.
| |
| 225 | 225 |
| 226 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); | 226 display::DisplayIdList list = |
| 227 display::DisplayIdList dummy_list = | 227 display_manager()->GetCurrentDisplayIdList(); |
| 228 ash::test::CreateDisplayIdList2(list[0], list[1] + 1); | 228 display::DisplayIdList dummy_list = |
| 229 ASSERT_NE(list[0], dummy_list[1]); | 229 ash::test::CreateDisplayIdList2(list[0], list[1] + 1); |
| 230 ASSERT_NE(list[0], dummy_list[1]); | |
| 230 | 231 |
| 231 StoreDisplayLayoutPrefForList(list, display::DisplayPlacement::TOP, 20); | 232 StoreDisplayLayoutPrefForList(list, display::DisplayPlacement::TOP, 20); |
| 232 StoreDisplayLayoutPrefForList(dummy_list, display::DisplayPlacement::LEFT, | 233 StoreDisplayLayoutPrefForList(dummy_list, display::DisplayPlacement::LEFT, |
| 233 30); | 234 30); |
| 234 StoreDisplayPowerStateForTest( | 235 StoreDisplayPowerStateForTest( |
| 235 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); | 236 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
| 236 | 237 |
| 237 ash::Shell* shell = ash::Shell::GetInstance(); | 238 ash::Shell* shell = ash::Shell::GetInstance(); |
| 238 | 239 |
| 239 LoadDisplayPreferences(true); | 240 LoadDisplayPreferences(true); |
| 240 // DisplayPowerState should be ignored at boot. | 241 // DisplayPowerState should be ignored at boot. |
| 241 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, | 242 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, |
| 242 shell->display_configurator()->requested_power_state()); | 243 shell->display_configurator()->requested_power_state()); |
| 243 | 244 |
| 244 shell->display_manager()->UpdateDisplays(); | 245 shell->display_manager()->UpdateDisplays(); |
| 245 // Check if the layout settings are notified to the system properly. | 246 // Check if the layout settings are notified to the system properly. |
| 246 // The new layout overrides old layout. | 247 // The new layout overrides old layout. |
| 247 // Inverted one of for specified pair (id1, id2). Not used for the list | 248 // Inverted one of for specified pair (id1, id2). Not used for the list |
| 248 // (id1, dummy_id) since dummy_id is not connected right now. | 249 // (id1, dummy_id) since dummy_id is not connected right now. |
| 249 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", | 250 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", |
| 250 shell->display_manager() | 251 shell->display_manager() |
| 251 ->GetCurrentDisplayLayout() | 252 ->GetCurrentDisplayLayout() |
| 252 .placement_list[0] | 253 .placement_list[0] |
| 253 .ToString()); | 254 .ToString()); |
| 254 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", | 255 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", |
| 255 GetRegisteredDisplayPlacementStr(list)); | 256 GetRegisteredDisplayPlacementStr(list)); |
| 256 EXPECT_EQ("id=2200000002, parent=2200000000, left, 30", | 257 EXPECT_EQ("id=2200000002, parent=2200000000, left, 30", |
| 257 GetRegisteredDisplayPlacementStr(dummy_list)); | 258 GetRegisteredDisplayPlacementStr(dummy_list)); |
| 258 } | 259 } |
| 259 | 260 |
| 260 TEST_F(DisplayPreferencesTest, BasicStores) { | 261 TEST_F(DisplayPreferencesTest, BasicStores) { |
| 261 ash::WindowTreeHostManager* window_tree_host_manager = | 262 ash::WindowTreeHostManager* window_tree_host_manager = |
| 262 ash::Shell::GetInstance()->window_tree_host_manager(); | 263 ash::Shell::GetInstance()->window_tree_host_manager(); |
| 263 ash::DisplayManager* display_manager = | |
| 264 ash::Shell::GetInstance()->display_manager(); | |
| 265 | 264 |
| 266 UpdateDisplay("200x200*2, 400x300#400x400|300x200*1.25"); | 265 UpdateDisplay("200x200*2, 400x300#400x400|300x200*1.25"); |
| 267 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 266 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 268 ash::test::ScopedSetInternalDisplayId set_internal(id1); | 267 ash::test::ScopedSetInternalDisplayId set_internal(display_manager(), id1); |
| 269 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 268 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 270 int64_t dummy_id = id2 + 1; | 269 int64_t dummy_id = id2 + 1; |
| 271 ASSERT_NE(id1, dummy_id); | 270 ASSERT_NE(id1, dummy_id); |
| 272 std::vector<ui::ColorCalibrationProfile> profiles; | 271 std::vector<ui::ColorCalibrationProfile> profiles; |
| 273 profiles.push_back(ui::COLOR_PROFILE_STANDARD); | 272 profiles.push_back(ui::COLOR_PROFILE_STANDARD); |
| 274 profiles.push_back(ui::COLOR_PROFILE_DYNAMIC); | 273 profiles.push_back(ui::COLOR_PROFILE_DYNAMIC); |
| 275 profiles.push_back(ui::COLOR_PROFILE_MOVIE); | 274 profiles.push_back(ui::COLOR_PROFILE_MOVIE); |
| 276 profiles.push_back(ui::COLOR_PROFILE_READING); | 275 profiles.push_back(ui::COLOR_PROFILE_READING); |
| 277 // Allows only |id1|. | 276 // Allows only |id1|. |
| 278 ash::test::DisplayManagerTestApi().SetAvailableColorProfiles(id1, profiles); | 277 ash::test::DisplayManagerTestApi(display_manager()) |
| 279 display_manager->SetColorCalibrationProfile(id1, ui::COLOR_PROFILE_DYNAMIC); | 278 .SetAvailableColorProfiles(id1, profiles); |
| 280 display_manager->SetColorCalibrationProfile(id2, ui::COLOR_PROFILE_DYNAMIC); | 279 display_manager()->SetColorCalibrationProfile(id1, ui::COLOR_PROFILE_DYNAMIC); |
| 280 display_manager()->SetColorCalibrationProfile(id2, ui::COLOR_PROFILE_DYNAMIC); | |
| 281 | 281 |
| 282 LoggedInAsUser(); | 282 LoggedInAsUser(); |
| 283 | 283 |
| 284 display_manager->SetLayoutForCurrentDisplays( | 284 display_manager()->SetLayoutForCurrentDisplays(ash::test::CreateDisplayLayout( |
| 285 ash::test::CreateDisplayLayout(display::DisplayPlacement::TOP, 10)); | 285 display_manager(), display::DisplayPlacement::TOP, 10)); |
| 286 const display::DisplayLayout& layout = | 286 const display::DisplayLayout& layout = |
| 287 display_manager->GetCurrentDisplayLayout(); | 287 display_manager()->GetCurrentDisplayLayout(); |
| 288 EXPECT_EQ(display::DisplayPlacement::TOP, layout.placement_list[0].position); | 288 EXPECT_EQ(display::DisplayPlacement::TOP, layout.placement_list[0].position); |
| 289 EXPECT_EQ(10, layout.placement_list[0].offset); | 289 EXPECT_EQ(10, layout.placement_list[0].offset); |
| 290 | 290 |
| 291 display::DisplayLayoutBuilder dummy_layout_builder(id1); | 291 display::DisplayLayoutBuilder dummy_layout_builder(id1); |
| 292 dummy_layout_builder.SetSecondaryPlacement( | 292 dummy_layout_builder.SetSecondaryPlacement( |
| 293 dummy_id, display::DisplayPlacement::LEFT, 20); | 293 dummy_id, display::DisplayPlacement::LEFT, 20); |
| 294 std::unique_ptr<display::DisplayLayout> dummy_layout( | 294 std::unique_ptr<display::DisplayLayout> dummy_layout( |
| 295 dummy_layout_builder.Build()); | 295 dummy_layout_builder.Build()); |
| 296 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, dummy_id); | 296 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, dummy_id); |
| 297 StoreDisplayLayoutPrefForTest(list, *dummy_layout); | 297 StoreDisplayLayoutPrefForTest(list, *dummy_layout); |
| 298 | 298 |
| 299 // Can't switch to a display that does not exist. | 299 // Can't switch to a display that does not exist. |
| 300 window_tree_host_manager->SetPrimaryDisplayId(dummy_id); | 300 window_tree_host_manager->SetPrimaryDisplayId(dummy_id); |
| 301 EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 301 EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 302 | 302 |
| 303 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); | 303 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); |
| 304 display_manager->SetDisplayRotation(id1, display::Display::ROTATE_90, | 304 display_manager()->SetDisplayRotation(id1, display::Display::ROTATE_90, |
| 305 display::Display::ROTATION_SOURCE_USER); | 305 display::Display::ROTATION_SOURCE_USER); |
| 306 EXPECT_TRUE(display_manager->SetDisplayUIScale(id1, 1.25f)); | 306 EXPECT_TRUE(display_manager()->SetDisplayUIScale(id1, 1.25f)); |
| 307 EXPECT_FALSE(display_manager->SetDisplayUIScale(id2, 1.25f)); | 307 EXPECT_FALSE(display_manager()->SetDisplayUIScale(id2, 1.25f)); |
| 308 | 308 |
| 309 const base::DictionaryValue* displays = | 309 const base::DictionaryValue* displays = |
| 310 local_state()->GetDictionary(prefs::kSecondaryDisplays); | 310 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 311 const base::DictionaryValue* layout_value = nullptr; | 311 const base::DictionaryValue* layout_value = nullptr; |
| 312 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 312 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 313 std::string dummy_key = | 313 std::string dummy_key = |
| 314 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); | 314 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); |
| 315 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); | 315 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); |
| 316 | 316 |
| 317 display::DisplayLayout stored_layout; | 317 display::DisplayLayout stored_layout; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 // by DisplayManager::SetDisplayMode | 376 // by DisplayManager::SetDisplayMode |
| 377 width = 0; | 377 width = 0; |
| 378 height = 0; | 378 height = 0; |
| 379 EXPECT_FALSE(property->GetInteger("width", &width)); | 379 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 380 EXPECT_FALSE(property->GetInteger("height", &height)); | 380 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 381 | 381 |
| 382 scoped_refptr<display::ManagedDisplayMode> mode( | 382 scoped_refptr<display::ManagedDisplayMode> mode( |
| 383 new display::ManagedDisplayMode(gfx::Size(300, 200), 60.0f, false, true, | 383 new display::ManagedDisplayMode(gfx::Size(300, 200), 60.0f, false, true, |
| 384 1.0 /* ui_scale */, | 384 1.0 /* ui_scale */, |
| 385 1.25f /* device_scale_factor */)); | 385 1.25f /* device_scale_factor */)); |
| 386 display_manager->SetDisplayMode(id2, mode); | 386 display_manager()->SetDisplayMode(id2, mode); |
| 387 | 387 |
| 388 window_tree_host_manager->SetPrimaryDisplayId(id2); | 388 window_tree_host_manager->SetPrimaryDisplayId(id2); |
| 389 | 389 |
| 390 EXPECT_EQ(id2, display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 390 EXPECT_EQ(id2, display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 391 | 391 |
| 392 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 392 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 393 width = 0; | 393 width = 0; |
| 394 height = 0; | 394 height = 0; |
| 395 // Internal display shouldn't store its resolution. | 395 // Internal display shouldn't store its resolution. |
| 396 EXPECT_FALSE(property->GetInteger("width", &width)); | 396 EXPECT_FALSE(property->GetInteger("width", &width)); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 424 if (true) | 424 if (true) |
| 425 return; | 425 return; |
| 426 | 426 |
| 427 mirrored = true; | 427 mirrored = true; |
| 428 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 428 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 429 EXPECT_FALSE(mirrored); | 429 EXPECT_FALSE(mirrored); |
| 430 std::string primary_id_str; | 430 std::string primary_id_str; |
| 431 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 431 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 432 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); | 432 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); |
| 433 | 433 |
| 434 display_manager->SetLayoutForCurrentDisplays( | 434 display_manager()->SetLayoutForCurrentDisplays(ash::test::CreateDisplayLayout( |
| 435 ash::test::CreateDisplayLayout(display::DisplayPlacement::BOTTOM, 20)); | 435 ash::Shell::GetInstance()->display_manager(), |
| 436 display::DisplayPlacement::BOTTOM, 20)); | |
| 436 | 437 |
| 437 UpdateDisplay("1+0-200x200*2,1+0-200x200"); | 438 UpdateDisplay("1+0-200x200*2,1+0-200x200"); |
| 438 // Mirrored. | 439 // Mirrored. |
| 439 int offset = 0; | 440 int offset = 0; |
| 440 std::string position; | 441 std::string position; |
| 441 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 442 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 442 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 443 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 443 EXPECT_EQ("bottom", position); | 444 EXPECT_EQ("bottom", position); |
| 444 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 445 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 445 EXPECT_EQ(20, offset); | 446 EXPECT_EQ(20, offset); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 461 | 462 |
| 462 // External display's selected resolution must not change | 463 // External display's selected resolution must not change |
| 463 // by mirroring. | 464 // by mirroring. |
| 464 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 465 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 465 EXPECT_TRUE(property->GetInteger("width", &width)); | 466 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 466 EXPECT_TRUE(property->GetInteger("height", &height)); | 467 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 467 EXPECT_EQ(300, width); | 468 EXPECT_EQ(300, width); |
| 468 EXPECT_EQ(200, height); | 469 EXPECT_EQ(200, height); |
| 469 | 470 |
| 470 // Set new display's selected resolution. | 471 // Set new display's selected resolution. |
| 471 display_manager->RegisterDisplayProperty(id2 + 1, display::Display::ROTATE_0, | 472 display_manager()->RegisterDisplayProperty( |
| 472 1.0f, nullptr, gfx::Size(500, 400), | 473 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), |
| 473 1.0f, ui::COLOR_PROFILE_STANDARD); | 474 1.0f, ui::COLOR_PROFILE_STANDARD); |
| 474 | 475 |
| 475 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); | 476 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); |
| 476 | 477 |
| 477 // Update key as the 2nd display gets new id. | 478 // Update key as the 2nd display gets new id. |
| 478 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 479 id2 = display_manager()->GetSecondaryDisplay().id(); |
| 479 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 480 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 480 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 481 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 481 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 482 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 482 EXPECT_EQ("right", position); | 483 EXPECT_EQ("right", position); |
| 483 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 484 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 484 EXPECT_EQ(0, offset); | 485 EXPECT_EQ(0, offset); |
| 485 mirrored = true; | 486 mirrored = true; |
| 486 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 487 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 487 EXPECT_FALSE(mirrored); | 488 EXPECT_FALSE(mirrored); |
| 488 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 489 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 489 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 490 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
| 490 | 491 |
| 491 // Best resolution should not be saved. | 492 // Best resolution should not be saved. |
| 492 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 493 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 493 EXPECT_FALSE(property->GetInteger("width", &width)); | 494 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 494 EXPECT_FALSE(property->GetInteger("height", &height)); | 495 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 495 | 496 |
| 496 // Set yet another new display's selected resolution. | 497 // Set yet another new display's selected resolution. |
| 497 display_manager->RegisterDisplayProperty(id2 + 1, display::Display::ROTATE_0, | 498 display_manager()->RegisterDisplayProperty( |
| 498 1.0f, nullptr, gfx::Size(500, 400), | 499 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), |
| 499 1.0f, ui::COLOR_PROFILE_STANDARD); | 500 1.0f, ui::COLOR_PROFILE_STANDARD); |
| 500 // Disconnect 2nd display first to generate new id for external display. | 501 // Disconnect 2nd display first to generate new id for external display. |
| 501 UpdateDisplay("200x200*2"); | 502 UpdateDisplay("200x200*2"); |
| 502 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); | 503 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); |
| 503 // Update key as the 2nd display gets new id. | 504 // Update key as the 2nd display gets new id. |
| 504 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 505 id2 = display_manager()->GetSecondaryDisplay().id(); |
| 505 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 506 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 506 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 507 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 507 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 508 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 508 EXPECT_EQ("right", position); | 509 EXPECT_EQ("right", position); |
| 509 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 510 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 510 EXPECT_EQ(0, offset); | 511 EXPECT_EQ(0, offset); |
| 511 mirrored = true; | 512 mirrored = true; |
| 512 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 513 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 513 EXPECT_FALSE(mirrored); | 514 EXPECT_FALSE(mirrored); |
| 514 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 515 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); | 569 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); |
| 569 EXPECT_TRUE(property->GetInteger("width", &width)); | 570 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 570 EXPECT_TRUE(property->GetInteger("height", &height)); | 571 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 571 EXPECT_EQ(300, width); | 572 EXPECT_EQ(300, width); |
| 572 EXPECT_EQ(200, height); | 573 EXPECT_EQ(200, height); |
| 573 } | 574 } |
| 574 | 575 |
| 575 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { | 576 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { |
| 576 UpdateDisplay("100x100,200x200"); | 577 UpdateDisplay("100x100,200x200"); |
| 577 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 578 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 578 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 579 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 579 | 580 |
| 580 LoggedInAsUser(); | 581 LoggedInAsUser(); |
| 581 | 582 |
| 582 ash::test::SwapPrimaryDisplay(); | 583 SwapPrimaryDisplay(); |
| 583 ASSERT_EQ(id1, ash::ScreenUtil::GetSecondaryDisplay().id()); | 584 ASSERT_EQ(id1, display_manager()->GetSecondaryDisplay().id()); |
| 584 | 585 |
| 585 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 586 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 586 const base::DictionaryValue* displays = | 587 const base::DictionaryValue* displays = |
| 587 local_state()->GetDictionary(prefs::kSecondaryDisplays); | 588 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 588 // Initial saved value is swapped. | 589 // Initial saved value is swapped. |
| 589 { | 590 { |
| 590 const base::DictionaryValue* new_value = nullptr; | 591 const base::DictionaryValue* new_value = nullptr; |
| 591 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); | 592 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
| 592 display::DisplayLayout stored_layout; | 593 display::DisplayLayout stored_layout; |
| 593 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); | 594 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); |
| 594 ASSERT_EQ(1u, stored_layout.placement_list.size()); | 595 ASSERT_EQ(1u, stored_layout.placement_list.size()); |
| 595 const display::DisplayPlacement& stored_placement = | 596 const display::DisplayPlacement& stored_placement = |
| 596 stored_layout.placement_list[0]; | 597 stored_layout.placement_list[0]; |
| 597 EXPECT_EQ(display::DisplayPlacement::LEFT, stored_placement.position); | 598 EXPECT_EQ(display::DisplayPlacement::LEFT, stored_placement.position); |
| 598 EXPECT_EQ(0, stored_placement.offset); | 599 EXPECT_EQ(0, stored_placement.offset); |
| 599 EXPECT_EQ(id1, stored_placement.display_id); | 600 EXPECT_EQ(id1, stored_placement.display_id); |
| 600 EXPECT_EQ(id2, stored_placement.parent_display_id); | 601 EXPECT_EQ(id2, stored_placement.parent_display_id); |
| 601 EXPECT_EQ(id2, stored_layout.primary_id); | 602 EXPECT_EQ(id2, stored_layout.primary_id); |
| 602 } | 603 } |
| 603 | 604 |
| 604 // Updating layout with primary swapped should save the correct value. | 605 // Updating layout with primary swapped should save the correct value. |
| 605 { | 606 { |
| 606 ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( | 607 display_manager()->SetLayoutForCurrentDisplays( |
| 607 ash::test::CreateDisplayLayout(display::DisplayPlacement::TOP, 10)); | 608 ash::test::CreateDisplayLayout(display_manager(), |
| 609 display::DisplayPlacement::TOP, 10)); | |
| 608 const base::DictionaryValue* new_value = nullptr; | 610 const base::DictionaryValue* new_value = nullptr; |
| 609 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); | 611 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
| 610 display::DisplayLayout stored_layout; | 612 display::DisplayLayout stored_layout; |
| 611 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); | 613 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); |
| 612 ASSERT_EQ(1u, stored_layout.placement_list.size()); | 614 ASSERT_EQ(1u, stored_layout.placement_list.size()); |
| 613 const display::DisplayPlacement& stored_placement = | 615 const display::DisplayPlacement& stored_placement = |
| 614 stored_layout.placement_list[0]; | 616 stored_layout.placement_list[0]; |
| 615 EXPECT_EQ(display::DisplayPlacement::TOP, stored_placement.position); | 617 EXPECT_EQ(display::DisplayPlacement::TOP, stored_placement.position); |
| 616 EXPECT_EQ(10, stored_placement.offset); | 618 EXPECT_EQ(10, stored_placement.offset); |
| 617 EXPECT_EQ(id1, stored_placement.display_id); | 619 EXPECT_EQ(id1, stored_placement.display_id); |
| 618 EXPECT_EQ(id2, stored_placement.parent_display_id); | 620 EXPECT_EQ(id2, stored_placement.parent_display_id); |
| 619 EXPECT_EQ(id2, stored_layout.primary_id); | 621 EXPECT_EQ(id2, stored_layout.primary_id); |
| 620 } | 622 } |
| 621 | 623 |
| 622 // Swapping primary will save the swapped value. | 624 // Swapping primary will save the swapped value. |
| 623 { | 625 { |
| 624 ash::test::SwapPrimaryDisplay(); | 626 SwapPrimaryDisplay(); |
| 625 const base::DictionaryValue* new_value = nullptr; | 627 const base::DictionaryValue* new_value = nullptr; |
| 626 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); | 628 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
| 627 display::DisplayLayout stored_layout; | 629 display::DisplayLayout stored_layout; |
| 628 | 630 |
| 629 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); | 631 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
| 630 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); | 632 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); |
| 631 ASSERT_EQ(1u, stored_layout.placement_list.size()); | 633 ASSERT_EQ(1u, stored_layout.placement_list.size()); |
| 632 const display::DisplayPlacement& stored_placement = | 634 const display::DisplayPlacement& stored_placement = |
| 633 stored_layout.placement_list[0]; | 635 stored_layout.placement_list[0]; |
| 634 EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position); | 636 EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position); |
| 635 EXPECT_EQ(-10, stored_placement.offset); | 637 EXPECT_EQ(-10, stored_placement.offset); |
| 636 EXPECT_EQ(id2, stored_placement.display_id); | 638 EXPECT_EQ(id2, stored_placement.display_id); |
| 637 EXPECT_EQ(id1, stored_placement.parent_display_id); | 639 EXPECT_EQ(id1, stored_placement.parent_display_id); |
| 638 EXPECT_EQ(id1, stored_layout.primary_id); | 640 EXPECT_EQ(id1, stored_layout.primary_id); |
| 639 } | 641 } |
| 640 } | 642 } |
| 641 | 643 |
| 642 TEST_F(DisplayPreferencesTest, RestoreColorProfiles) { | 644 TEST_F(DisplayPreferencesTest, RestoreColorProfiles) { |
| 643 ash::DisplayManager* display_manager = | |
| 644 ash::Shell::GetInstance()->display_manager(); | |
| 645 | |
| 646 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 645 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 647 | 646 |
| 648 StoreColorProfile(id1, "dynamic"); | 647 StoreColorProfile(id1, "dynamic"); |
| 649 | 648 |
| 650 LoggedInAsUser(); | 649 LoggedInAsUser(); |
| 651 LoadDisplayPreferences(false); | 650 LoadDisplayPreferences(false); |
| 652 | 651 |
| 653 // id1's available color profiles list is empty, means somehow the color | 652 // id1's available color profiles list is empty, means somehow the color |
| 654 // profile suport is temporary in trouble. | 653 // profile suport is temporary in trouble. |
| 655 EXPECT_NE(ui::COLOR_PROFILE_DYNAMIC, | 654 EXPECT_NE(ui::COLOR_PROFILE_DYNAMIC, |
| 656 display_manager->GetDisplayInfo(id1).color_profile()); | 655 display_manager()->GetDisplayInfo(id1).color_profile()); |
| 657 | 656 |
| 658 // Once the profile is supported, the color profile should be restored. | 657 // Once the profile is supported, the color profile should be restored. |
| 659 std::vector<ui::ColorCalibrationProfile> profiles; | 658 std::vector<ui::ColorCalibrationProfile> profiles; |
| 660 profiles.push_back(ui::COLOR_PROFILE_STANDARD); | 659 profiles.push_back(ui::COLOR_PROFILE_STANDARD); |
| 661 profiles.push_back(ui::COLOR_PROFILE_DYNAMIC); | 660 profiles.push_back(ui::COLOR_PROFILE_DYNAMIC); |
| 662 profiles.push_back(ui::COLOR_PROFILE_MOVIE); | 661 profiles.push_back(ui::COLOR_PROFILE_MOVIE); |
| 663 profiles.push_back(ui::COLOR_PROFILE_READING); | 662 profiles.push_back(ui::COLOR_PROFILE_READING); |
| 664 ash::test::DisplayManagerTestApi().SetAvailableColorProfiles(id1, profiles); | 663 ash::test::DisplayManagerTestApi(ash::Shell::GetInstance()->display_manager()) |
| 664 .SetAvailableColorProfiles(id1, profiles); | |
| 665 | 665 |
| 666 LoadDisplayPreferences(false); | 666 LoadDisplayPreferences(false); |
| 667 EXPECT_EQ(ui::COLOR_PROFILE_DYNAMIC, | 667 EXPECT_EQ(ui::COLOR_PROFILE_DYNAMIC, |
| 668 display_manager->GetDisplayInfo(id1).color_profile()); | 668 display_manager()->GetDisplayInfo(id1).color_profile()); |
| 669 } | 669 } |
| 670 | 670 |
| 671 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { | 671 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { |
| 672 ash::WindowTreeHostManager* window_tree_host_manager = | 672 ash::WindowTreeHostManager* window_tree_host_manager = |
| 673 ash::Shell::GetInstance()->window_tree_host_manager(); | 673 ash::Shell::GetInstance()->window_tree_host_manager(); |
| 674 | 674 |
| 675 UpdateDisplay("200x200*2,200x200"); | 675 UpdateDisplay("200x200*2,200x200"); |
| 676 | 676 |
| 677 LoggedInAsGuest(); | 677 LoggedInAsGuest(); |
| 678 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 678 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 679 ash::test::ScopedSetInternalDisplayId set_internal(id1); | 679 ash::test::ScopedSetInternalDisplayId set_internal( |
| 680 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 680 ash::Shell::GetInstance()->display_manager(), id1); |
| 681 ash::DisplayManager* display_manager = | 681 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 682 ash::Shell::GetInstance()->display_manager(); | 682 display_manager()->SetLayoutForCurrentDisplays(ash::test::CreateDisplayLayout( |
| 683 display_manager->SetLayoutForCurrentDisplays( | 683 display_manager(), display::DisplayPlacement::TOP, 10)); |
| 684 ash::test::CreateDisplayLayout(display::DisplayPlacement::TOP, 10)); | 684 display_manager()->SetDisplayUIScale(id1, 1.25f); |
| 685 display_manager->SetDisplayUIScale(id1, 1.25f); | |
| 686 window_tree_host_manager->SetPrimaryDisplayId(id2); | 685 window_tree_host_manager->SetPrimaryDisplayId(id2); |
| 687 int64_t new_primary = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 686 int64_t new_primary = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 688 window_tree_host_manager->SetOverscanInsets(new_primary, | 687 window_tree_host_manager->SetOverscanInsets(new_primary, |
| 689 gfx::Insets(10, 11, 12, 13)); | 688 gfx::Insets(10, 11, 12, 13)); |
| 690 display_manager->SetDisplayRotation(new_primary, display::Display::ROTATE_90, | 689 display_manager()->SetDisplayRotation(new_primary, |
| 691 display::Display::ROTATION_SOURCE_USER); | 690 display::Display::ROTATE_90, |
| 691 display::Display::ROTATION_SOURCE_USER); | |
| 692 | 692 |
| 693 // Does not store the preferences locally. | 693 // Does not store the preferences locally. |
| 694 EXPECT_FALSE(local_state()->FindPreference( | 694 EXPECT_FALSE(local_state()->FindPreference( |
| 695 prefs::kSecondaryDisplays)->HasUserSetting()); | 695 prefs::kSecondaryDisplays)->HasUserSetting()); |
| 696 EXPECT_FALSE(local_state()->FindPreference( | 696 EXPECT_FALSE(local_state()->FindPreference( |
| 697 prefs::kDisplayProperties)->HasUserSetting()); | 697 prefs::kDisplayProperties)->HasUserSetting()); |
| 698 | 698 |
| 699 // Settings are still notified to the system. | 699 // Settings are still notified to the system. |
| 700 display::Screen* screen = display::Screen::GetScreen(); | 700 display::Screen* screen = display::Screen::GetScreen(); |
| 701 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); | 701 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); |
| 702 const display::DisplayPlacement& placement = | 702 const display::DisplayPlacement& placement = |
| 703 display_manager->GetCurrentDisplayLayout().placement_list[0]; | 703 display_manager()->GetCurrentDisplayLayout().placement_list[0]; |
| 704 EXPECT_EQ(display::DisplayPlacement::BOTTOM, placement.position); | 704 EXPECT_EQ(display::DisplayPlacement::BOTTOM, placement.position); |
| 705 EXPECT_EQ(-10, placement.offset); | 705 EXPECT_EQ(-10, placement.offset); |
| 706 const display::Display& primary_display = screen->GetPrimaryDisplay(); | 706 const display::Display& primary_display = screen->GetPrimaryDisplay(); |
| 707 EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); | 707 EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); |
| 708 EXPECT_EQ(display::Display::ROTATE_90, primary_display.rotation()); | 708 EXPECT_EQ(display::Display::ROTATE_90, primary_display.rotation()); |
| 709 | 709 |
| 710 const display::ManagedDisplayInfo& info1 = | 710 const display::ManagedDisplayInfo& info1 = |
| 711 display_manager->GetDisplayInfo(id1); | 711 display_manager()->GetDisplayInfo(id1); |
| 712 EXPECT_EQ(1.25f, info1.configured_ui_scale()); | 712 EXPECT_EQ(1.25f, info1.configured_ui_scale()); |
| 713 | 713 |
| 714 const display::ManagedDisplayInfo& info_primary = | 714 const display::ManagedDisplayInfo& info_primary = |
| 715 display_manager->GetDisplayInfo(new_primary); | 715 display_manager()->GetDisplayInfo(new_primary); |
| 716 EXPECT_EQ(display::Display::ROTATE_90, info_primary.GetActiveRotation()); | 716 EXPECT_EQ(display::Display::ROTATE_90, info_primary.GetActiveRotation()); |
| 717 EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); | 717 EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); |
| 718 } | 718 } |
| 719 | 719 |
| 720 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { | 720 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { |
| 721 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); | 721 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| 722 | 722 |
| 723 // Stores display prefs without login, which still stores the power state. | 723 // Stores display prefs without login, which still stores the power state. |
| 724 StoreDisplayPrefs(); | 724 StoreDisplayPrefs(); |
| 725 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); | 725 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 772 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 773 shell->display_configurator()->requested_power_state()); | 773 shell->display_configurator()->requested_power_state()); |
| 774 } | 774 } |
| 775 | 775 |
| 776 // Tests that display configuration changes caused by MaximizeModeController | 776 // Tests that display configuration changes caused by MaximizeModeController |
| 777 // are not saved. | 777 // are not saved. |
| 778 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { | 778 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { |
| 779 ash::Shell* shell = ash::Shell::GetInstance(); | 779 ash::Shell* shell = ash::Shell::GetInstance(); |
| 780 display::Display::SetInternalDisplayId( | 780 display::Display::SetInternalDisplayId( |
| 781 display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 781 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 782 ash::DisplayManager* display_manager = shell->display_manager(); | |
| 783 LoggedInAsUser(); | 782 LoggedInAsUser(); |
| 784 // Populate the properties. | 783 // Populate the properties. |
| 785 display_manager->SetDisplayRotation(display::Display::InternalDisplayId(), | 784 display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(), |
| 786 display::Display::ROTATE_180, | 785 display::Display::ROTATE_180, |
| 787 display::Display::ROTATION_SOURCE_USER); | 786 display::Display::ROTATION_SOURCE_USER); |
| 788 // Reset property to avoid rotation lock | 787 // Reset property to avoid rotation lock |
| 789 display_manager->SetDisplayRotation(display::Display::InternalDisplayId(), | 788 display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(), |
| 790 display::Display::ROTATE_0, | 789 display::Display::ROTATE_0, |
| 791 display::Display::ROTATION_SOURCE_USER); | 790 display::Display::ROTATION_SOURCE_USER); |
| 792 | 791 |
| 793 // Open up 270 degrees to trigger maximize mode | 792 // Open up 270 degrees to trigger maximize mode |
| 794 scoped_refptr<chromeos::AccelerometerUpdate> update( | 793 scoped_refptr<chromeos::AccelerometerUpdate> update( |
| 795 new chromeos::AccelerometerUpdate()); | 794 new chromeos::AccelerometerUpdate()); |
| 796 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, | 795 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, |
| 797 kMeanGravity); | 796 kMeanGravity); |
| 798 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); | 797 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); |
| 799 ash::MaximizeModeController* controller = | 798 ash::MaximizeModeController* controller = |
| 800 ash::WmShell::Get()->maximize_mode_controller(); | 799 ash::WmShell::Get()->maximize_mode_controller(); |
| 801 controller->OnAccelerometerUpdated(update); | 800 controller->OnAccelerometerUpdated(update); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 EXPECT_EQ(current_rotation, orientation); | 900 EXPECT_EQ(current_rotation, orientation); |
| 902 } | 901 } |
| 903 | 902 |
| 904 // Tests that rotation state is loaded without a user being logged in, and that | 903 // Tests that rotation state is loaded without a user being logged in, and that |
| 905 // entering maximize mode applies the state. | 904 // entering maximize mode applies the state. |
| 906 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { | 905 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { |
| 907 display::Display::SetInternalDisplayId( | 906 display::Display::SetInternalDisplayId( |
| 908 display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 907 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 909 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 908 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 910 | 909 |
| 911 ash::Shell* shell = ash::Shell::GetInstance(); | |
| 912 bool initial_rotation_lock = IsRotationLocked(); | 910 bool initial_rotation_lock = IsRotationLocked(); |
| 913 ASSERT_FALSE(initial_rotation_lock); | 911 ASSERT_FALSE(initial_rotation_lock); |
| 914 ash::DisplayManager* display_manager = shell->display_manager(); | |
| 915 display::Display::Rotation initial_rotation = | 912 display::Display::Rotation initial_rotation = |
| 916 GetCurrentInternalDisplayRotation(); | 913 GetCurrentInternalDisplayRotation(); |
| 917 ASSERT_EQ(display::Display::ROTATE_0, initial_rotation); | 914 ASSERT_EQ(display::Display::ROTATE_0, initial_rotation); |
| 918 | 915 |
| 919 StoreDisplayRotationPrefs(initial_rotation_lock); | 916 StoreDisplayRotationPrefs(initial_rotation_lock); |
| 920 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 917 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 921 | 918 |
| 922 StoreDisplayRotationPrefsForTest(true, display::Display::ROTATE_90); | 919 StoreDisplayRotationPrefsForTest(true, display::Display::ROTATE_90); |
| 923 LoadDisplayPreferences(false); | 920 LoadDisplayPreferences(false); |
| 924 | 921 |
| 925 bool display_rotation_lock = | 922 bool display_rotation_lock = |
| 926 display_manager->registered_internal_display_rotation_lock(); | 923 display_manager()->registered_internal_display_rotation_lock(); |
| 927 bool display_rotation = | 924 bool display_rotation = |
| 928 display_manager->registered_internal_display_rotation(); | 925 display_manager()->registered_internal_display_rotation(); |
| 929 EXPECT_TRUE(display_rotation_lock); | 926 EXPECT_TRUE(display_rotation_lock); |
| 930 EXPECT_EQ(display::Display::ROTATE_90, display_rotation); | 927 EXPECT_EQ(display::Display::ROTATE_90, display_rotation); |
| 931 | 928 |
| 932 bool rotation_lock = IsRotationLocked(); | 929 bool rotation_lock = IsRotationLocked(); |
| 933 display::Display::Rotation before_maximize_mode_rotation = | 930 display::Display::Rotation before_maximize_mode_rotation = |
| 934 GetCurrentInternalDisplayRotation(); | 931 GetCurrentInternalDisplayRotation(); |
| 935 | 932 |
| 936 // Settings should not be applied until maximize mode activates | 933 // Settings should not be applied until maximize mode activates |
| 937 EXPECT_FALSE(rotation_lock); | 934 EXPECT_FALSE(rotation_lock); |
| 938 EXPECT_EQ(display::Display::ROTATE_0, before_maximize_mode_rotation); | 935 EXPECT_EQ(display::Display::ROTATE_0, before_maximize_mode_rotation); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 965 | 962 |
| 966 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 963 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 967 | 964 |
| 968 const base::DictionaryValue* properties = | 965 const base::DictionaryValue* properties = |
| 969 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 966 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
| 970 bool rotation_lock; | 967 bool rotation_lock; |
| 971 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 968 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
| 972 } | 969 } |
| 973 | 970 |
| 974 TEST_F(DisplayPreferencesTest, SaveUnifiedMode) { | 971 TEST_F(DisplayPreferencesTest, SaveUnifiedMode) { |
| 975 | |
| 976 LoggedInAsUser(); | 972 LoggedInAsUser(); |
| 977 ash::DisplayManager* display_manager = | 973 display_manager()->SetUnifiedDesktopEnabled(true); |
| 978 ash::Shell::GetInstance()->display_manager(); | |
| 979 display_manager->SetUnifiedDesktopEnabled(true); | |
| 980 | 974 |
| 981 UpdateDisplay("200x200,100x100"); | 975 UpdateDisplay("200x200,100x100"); |
| 982 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); | 976 display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList(); |
| 983 EXPECT_EQ( | 977 EXPECT_EQ( |
| 984 "400x200", | 978 "400x200", |
| 985 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); | 979 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); |
| 986 | 980 |
| 987 const base::DictionaryValue* secondary_displays = | 981 const base::DictionaryValue* secondary_displays = |
| 988 local_state()->GetDictionary(prefs::kSecondaryDisplays); | 982 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 989 const base::DictionaryValue* new_value = nullptr; | 983 const base::DictionaryValue* new_value = nullptr; |
| 990 EXPECT_TRUE(secondary_displays->GetDictionary( | 984 EXPECT_TRUE(secondary_displays->GetDictionary( |
| 991 display::DisplayIdListToString(list), &new_value)); | 985 display::DisplayIdListToString(list), &new_value)); |
| 992 | 986 |
| 993 display::DisplayLayout stored_layout; | 987 display::DisplayLayout stored_layout; |
| 994 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); | 988 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); |
| 995 EXPECT_TRUE(stored_layout.default_unified); | 989 EXPECT_TRUE(stored_layout.default_unified); |
| 996 EXPECT_FALSE(stored_layout.mirrored); | 990 EXPECT_FALSE(stored_layout.mirrored); |
| 997 | 991 |
| 998 const base::DictionaryValue* displays = | 992 const base::DictionaryValue* displays = |
| 999 local_state()->GetDictionary(prefs::kDisplayProperties); | 993 local_state()->GetDictionary(prefs::kDisplayProperties); |
| 1000 int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 994 int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 1001 EXPECT_FALSE( | 995 EXPECT_FALSE( |
| 1002 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); | 996 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); |
| 1003 | 997 |
| 1004 ash::test::SetDisplayResolution(unified_id, gfx::Size(200, 100)); | 998 ash::test::SetDisplayResolution(display_manager(), unified_id, |
| 999 gfx::Size(200, 100)); | |
| 1005 EXPECT_EQ( | 1000 EXPECT_EQ( |
| 1006 "200x100", | 1001 "200x100", |
| 1007 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); | 1002 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); |
| 1008 EXPECT_FALSE( | 1003 EXPECT_FALSE( |
| 1009 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); | 1004 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); |
| 1010 | 1005 |
| 1011 // Mirror mode should remember if the default mode was unified. | 1006 // Mirror mode should remember if the default mode was unified. |
| 1012 display_manager->SetMirrorMode(true); | 1007 display_manager()->SetMirrorMode(true); |
| 1013 ASSERT_TRUE(secondary_displays->GetDictionary( | 1008 ASSERT_TRUE(secondary_displays->GetDictionary( |
| 1014 display::DisplayIdListToString(list), &new_value)); | 1009 display::DisplayIdListToString(list), &new_value)); |
| 1015 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); | 1010 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); |
| 1016 EXPECT_TRUE(stored_layout.default_unified); | 1011 EXPECT_TRUE(stored_layout.default_unified); |
| 1017 EXPECT_TRUE(stored_layout.mirrored); | 1012 EXPECT_TRUE(stored_layout.mirrored); |
| 1018 | 1013 |
| 1019 display_manager->SetMirrorMode(false); | 1014 display_manager()->SetMirrorMode(false); |
| 1020 ASSERT_TRUE(secondary_displays->GetDictionary( | 1015 ASSERT_TRUE(secondary_displays->GetDictionary( |
| 1021 display::DisplayIdListToString(list), &new_value)); | 1016 display::DisplayIdListToString(list), &new_value)); |
| 1022 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); | 1017 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); |
| 1023 EXPECT_TRUE(stored_layout.default_unified); | 1018 EXPECT_TRUE(stored_layout.default_unified); |
| 1024 EXPECT_FALSE(stored_layout.mirrored); | 1019 EXPECT_FALSE(stored_layout.mirrored); |
| 1025 | 1020 |
| 1026 // Exit unified mode. | 1021 // Exit unified mode. |
| 1027 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays( | 1022 display_manager()->SetDefaultMultiDisplayModeForCurrentDisplays( |
| 1028 ash::DisplayManager::EXTENDED); | 1023 ash::DisplayManager::EXTENDED); |
| 1029 ASSERT_TRUE(secondary_displays->GetDictionary( | 1024 ASSERT_TRUE(secondary_displays->GetDictionary( |
| 1030 display::DisplayIdListToString(list), &new_value)); | 1025 display::DisplayIdListToString(list), &new_value)); |
| 1031 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); | 1026 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); |
| 1032 EXPECT_FALSE(stored_layout.default_unified); | 1027 EXPECT_FALSE(stored_layout.default_unified); |
| 1033 EXPECT_FALSE(stored_layout.mirrored); | 1028 EXPECT_FALSE(stored_layout.mirrored); |
| 1034 } | 1029 } |
| 1035 | 1030 |
| 1036 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { | 1031 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { |
| 1037 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 1032 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 1038 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1); | 1033 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1); |
| 1039 StoreDisplayBoolPropertyForList(list, "default_unified", true); | 1034 StoreDisplayBoolPropertyForList(list, "default_unified", true); |
| 1040 StoreDisplayPropertyForList( | 1035 StoreDisplayPropertyForList( |
| 1041 list, "primary-id", | 1036 list, "primary-id", |
| 1042 base::MakeUnique<base::StringValue>(base::Int64ToString(id1))); | 1037 base::MakeUnique<base::StringValue>(base::Int64ToString(id1))); |
| 1043 LoadDisplayPreferences(false); | 1038 LoadDisplayPreferences(false); |
| 1044 | 1039 |
| 1045 // Should not restore to unified unless unified desktop is enabled. | 1040 // Should not restore to unified unless unified desktop is enabled. |
| 1046 UpdateDisplay("100x100,200x200"); | 1041 UpdateDisplay("100x100,200x200"); |
| 1047 ash::DisplayManager* display_manager = | 1042 EXPECT_FALSE(display_manager()->IsInUnifiedMode()); |
| 1048 ash::Shell::GetInstance()->display_manager(); | |
| 1049 EXPECT_FALSE(display_manager->IsInUnifiedMode()); | |
| 1050 | 1043 |
| 1051 // Restored to unified. | 1044 // Restored to unified. |
| 1052 display_manager->SetUnifiedDesktopEnabled(true); | 1045 display_manager()->SetUnifiedDesktopEnabled(true); |
| 1053 StoreDisplayBoolPropertyForList(list, "default_unified", true); | 1046 StoreDisplayBoolPropertyForList(list, "default_unified", true); |
| 1054 LoadDisplayPreferences(false); | 1047 LoadDisplayPreferences(false); |
| 1055 UpdateDisplay("100x100,200x200"); | 1048 UpdateDisplay("100x100,200x200"); |
| 1056 EXPECT_TRUE(display_manager->IsInUnifiedMode()); | 1049 EXPECT_TRUE(display_manager()->IsInUnifiedMode()); |
| 1057 | 1050 |
| 1058 // Restored to mirror, then unified. | 1051 // Restored to mirror, then unified. |
| 1059 StoreDisplayBoolPropertyForList(list, "mirrored", true); | 1052 StoreDisplayBoolPropertyForList(list, "mirrored", true); |
| 1060 StoreDisplayBoolPropertyForList(list, "default_unified", true); | 1053 StoreDisplayBoolPropertyForList(list, "default_unified", true); |
| 1061 LoadDisplayPreferences(false); | 1054 LoadDisplayPreferences(false); |
| 1062 UpdateDisplay("100x100,200x200"); | 1055 UpdateDisplay("100x100,200x200"); |
| 1063 EXPECT_TRUE(display_manager->IsInMirrorMode()); | 1056 EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
| 1064 | 1057 |
| 1065 display_manager->SetMirrorMode(false); | 1058 display_manager()->SetMirrorMode(false); |
| 1066 EXPECT_TRUE(display_manager->IsInUnifiedMode()); | 1059 EXPECT_TRUE(display_manager()->IsInUnifiedMode()); |
| 1067 | 1060 |
| 1068 // Sanity check. Restore to extended. | 1061 // Sanity check. Restore to extended. |
| 1069 StoreDisplayBoolPropertyForList(list, "default_unified", false); | 1062 StoreDisplayBoolPropertyForList(list, "default_unified", false); |
| 1070 StoreDisplayBoolPropertyForList(list, "mirrored", false); | 1063 StoreDisplayBoolPropertyForList(list, "mirrored", false); |
| 1071 LoadDisplayPreferences(false); | 1064 LoadDisplayPreferences(false); |
| 1072 UpdateDisplay("100x100,200x200"); | 1065 UpdateDisplay("100x100,200x200"); |
| 1073 EXPECT_FALSE(display_manager->IsInMirrorMode()); | 1066 EXPECT_FALSE(display_manager()->IsInMirrorMode()); |
| 1074 EXPECT_FALSE(display_manager->IsInUnifiedMode()); | 1067 EXPECT_FALSE(display_manager()->IsInUnifiedMode()); |
| 1075 } | 1068 } |
| 1076 | 1069 |
| 1077 TEST_F(DisplayPreferencesTest, SaveThreeDisplays) { | 1070 TEST_F(DisplayPreferencesTest, SaveThreeDisplays) { |
| 1078 LoggedInAsUser(); | 1071 LoggedInAsUser(); |
| 1079 ash::DisplayManager* display_manager = | |
| 1080 ash::Shell::GetInstance()->display_manager(); | |
| 1081 UpdateDisplay("200x200,200x200,300x300"); | 1072 UpdateDisplay("200x200,200x200,300x300"); |
| 1082 | 1073 |
| 1083 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); | 1074 display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList(); |
| 1084 ASSERT_EQ(3u, list.size()); | 1075 ASSERT_EQ(3u, list.size()); |
| 1085 | 1076 |
| 1086 display::DisplayLayoutBuilder builder(list[0]); | 1077 display::DisplayLayoutBuilder builder(list[0]); |
| 1087 builder.AddDisplayPlacement(list[1], list[0], | 1078 builder.AddDisplayPlacement(list[1], list[0], |
| 1088 display::DisplayPlacement::RIGHT, 0); | 1079 display::DisplayPlacement::RIGHT, 0); |
| 1089 builder.AddDisplayPlacement(list[2], list[0], | 1080 builder.AddDisplayPlacement(list[2], list[0], |
| 1090 display::DisplayPlacement::BOTTOM, 100); | 1081 display::DisplayPlacement::BOTTOM, 100); |
| 1091 display_manager->SetLayoutForCurrentDisplays(builder.Build()); | 1082 display_manager()->SetLayoutForCurrentDisplays(builder.Build()); |
| 1092 | 1083 |
| 1093 const base::DictionaryValue* secondary_displays = | 1084 const base::DictionaryValue* secondary_displays = |
| 1094 local_state()->GetDictionary(prefs::kSecondaryDisplays); | 1085 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 1095 const base::DictionaryValue* new_value = nullptr; | 1086 const base::DictionaryValue* new_value = nullptr; |
| 1096 EXPECT_TRUE(secondary_displays->GetDictionary( | 1087 EXPECT_TRUE(secondary_displays->GetDictionary( |
| 1097 display::DisplayIdListToString(list), &new_value)); | 1088 display::DisplayIdListToString(list), &new_value)); |
| 1098 } | 1089 } |
| 1099 | 1090 |
| 1100 TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) { | 1091 TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) { |
| 1101 LoggedInAsUser(); | 1092 LoggedInAsUser(); |
| 1102 ash::DisplayManager* display_manager = | |
| 1103 ash::Shell::GetInstance()->display_manager(); | |
| 1104 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 1093 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 1105 display::DisplayIdList list = | 1094 display::DisplayIdList list = |
| 1106 ash::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2); | 1095 ash::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2); |
| 1107 | 1096 |
| 1108 display::DisplayLayoutBuilder builder(list[0]); | 1097 display::DisplayLayoutBuilder builder(list[0]); |
| 1109 builder.AddDisplayPlacement(list[1], list[0], display::DisplayPlacement::LEFT, | 1098 builder.AddDisplayPlacement(list[1], list[0], display::DisplayPlacement::LEFT, |
| 1110 0); | 1099 0); |
| 1111 builder.AddDisplayPlacement(list[2], list[1], | 1100 builder.AddDisplayPlacement(list[2], list[1], |
| 1112 display::DisplayPlacement::BOTTOM, 100); | 1101 display::DisplayPlacement::BOTTOM, 100); |
| 1113 StoreDisplayLayoutPrefForTest(list, *builder.Build()); | 1102 StoreDisplayLayoutPrefForTest(list, *builder.Build()); |
| 1114 LoadDisplayPreferences(false); | 1103 LoadDisplayPreferences(false); |
| 1115 | 1104 |
| 1116 UpdateDisplay("200x200,200x200,300x300"); | 1105 UpdateDisplay("200x200,200x200,300x300"); |
| 1117 display::DisplayIdList new_list = display_manager->GetCurrentDisplayIdList(); | 1106 display::DisplayIdList new_list = |
| 1107 display_manager()->GetCurrentDisplayIdList(); | |
| 1118 ASSERT_EQ(3u, list.size()); | 1108 ASSERT_EQ(3u, list.size()); |
| 1119 ASSERT_EQ(list[0], new_list[0]); | 1109 ASSERT_EQ(list[0], new_list[0]); |
| 1120 ASSERT_EQ(list[1], new_list[1]); | 1110 ASSERT_EQ(list[1], new_list[1]); |
| 1121 ASSERT_EQ(list[2], new_list[2]); | 1111 ASSERT_EQ(list[2], new_list[2]); |
| 1122 | 1112 |
| 1123 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), | 1113 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 1124 display_manager->GetDisplayForId(list[0]).bounds()); | 1114 display_manager()->GetDisplayForId(list[0]).bounds()); |
| 1125 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), | 1115 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), |
| 1126 display_manager->GetDisplayForId(list[1]).bounds()); | 1116 display_manager()->GetDisplayForId(list[1]).bounds()); |
| 1127 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), | 1117 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), |
| 1128 display_manager->GetDisplayForId(list[2]).bounds()); | 1118 display_manager()->GetDisplayForId(list[2]).bounds()); |
| 1129 } | 1119 } |
| 1130 | 1120 |
| 1131 } // namespace chromeos | 1121 } // namespace chromeos |
| OLD | NEW |