| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/policy/display_rotation_default_handler.h" | 5 #include "chrome/browser/chromeos/policy/display_rotation_default_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "ash/display/display_manager.h" | |
| 12 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 13 #include "base/bind.h" | 12 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 15 #include "base/location.h" | 14 #include "base/location.h" |
| 16 #include "base/macros.h" | 15 #include "base/macros.h" |
| 17 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 19 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 21 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 20 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |
| 22 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 21 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| 23 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 22 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 24 #include "chrome/browser/chromeos/settings/cros_settings.h" | 23 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 25 #include "chrome/browser/lifetime/application_lifetime.h" | 24 #include "chrome/browser/lifetime/application_lifetime.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chromeos/chromeos_switches.h" | 26 #include "chromeos/chromeos_switches.h" |
| 28 #include "chromeos/dbus/cryptohome_client.h" | 27 #include "chromeos/dbus/cryptohome_client.h" |
| 29 #include "chromeos/dbus/dbus_thread_manager.h" | 28 #include "chromeos/dbus/dbus_thread_manager.h" |
| 30 #include "chromeos/dbus/fake_cryptohome_client.h" | 29 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 31 #include "chromeos/dbus/fake_session_manager_client.h" | 30 #include "chromeos/dbus/fake_session_manager_client.h" |
| 32 #include "chromeos/dbus/session_manager_client.h" | 31 #include "chromeos/dbus/session_manager_client.h" |
| 33 #include "chromeos/settings/cros_settings_names.h" | 32 #include "chromeos/settings/cros_settings_names.h" |
| 34 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "ui/display/display.h" | 35 #include "ui/display/display.h" |
| 37 #include "ui/display/manager/display_layout.h" | 36 #include "ui/display/manager/display_layout.h" |
| 37 #include "ui/display/manager/display_manager.h" |
| 38 | 38 |
| 39 namespace em = enterprise_management; | 39 namespace em = enterprise_management; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 ash::DisplayManager* GetDisplayManager() { | 43 display::DisplayManager* GetDisplayManager() { |
| 44 return ash::Shell::GetInstance()->display_manager(); | 44 return ash::Shell::GetInstance()->display_manager(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 display::Display::Rotation GetRotationOfFirstDisplay() { | 47 display::Display::Rotation GetRotationOfFirstDisplay() { |
| 48 const ash::DisplayManager* const display_manager = GetDisplayManager(); | 48 const display::DisplayManager* const display_manager = GetDisplayManager(); |
| 49 const int64_t first_display_id = display_manager->first_display_id(); | 49 const int64_t first_display_id = display_manager->first_display_id(); |
| 50 const display::Display& first_display = | 50 const display::Display& first_display = |
| 51 display_manager->GetDisplayForId(first_display_id); | 51 display_manager->GetDisplayForId(first_display_id); |
| 52 return first_display.rotation(); | 52 return first_display.rotation(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Fails the test and returns ROTATE_0 if there is no second display. | 55 // Fails the test and returns ROTATE_0 if there is no second display. |
| 56 display::Display::Rotation GetRotationOfSecondDisplay() { | 56 display::Display::Rotation GetRotationOfSecondDisplay() { |
| 57 const ash::DisplayManager* const display_manager = GetDisplayManager(); | 57 const display::DisplayManager* const display_manager = GetDisplayManager(); |
| 58 if (display_manager->GetNumDisplays() < 2) { | 58 if (display_manager->GetNumDisplays() < 2) { |
| 59 ADD_FAILURE() | 59 ADD_FAILURE() |
| 60 << "Requested rotation of second display while there was only one."; | 60 << "Requested rotation of second display while there was only one."; |
| 61 return display::Display::ROTATE_0; | 61 return display::Display::ROTATE_0; |
| 62 } | 62 } |
| 63 const display::DisplayIdList display_id_pair = | 63 const display::DisplayIdList display_id_pair = |
| 64 display_manager->GetCurrentDisplayIdList(); | 64 display_manager->GetCurrentDisplayIdList(); |
| 65 const display::Display& second_display = | 65 const display::Display& second_display = |
| 66 display_manager->GetDisplayForId(display_id_pair[1]); | 66 display_manager->GetDisplayForId(display_id_pair[1]); |
| 67 return second_display.rotation(); | 67 return second_display.rotation(); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> observer = | 297 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> observer = |
| 298 chromeos::CrosSettings::Get()->AddSettingsObserver( | 298 chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 299 chromeos::kDisplayRotationDefault, run_loop.QuitClosure()); | 299 chromeos::kDisplayRotationDefault, run_loop.QuitClosure()); |
| 300 device_policy->SetDefaultSigningKey(); | 300 device_policy->SetDefaultSigningKey(); |
| 301 device_policy->Build(); | 301 device_policy->Build(); |
| 302 fake_session_manager_client_->set_device_policy(device_policy->GetBlob()); | 302 fake_session_manager_client_->set_device_policy(device_policy->GetBlob()); |
| 303 fake_session_manager_client_->OnPropertyChangeComplete(true); | 303 fake_session_manager_client_->OnPropertyChangeComplete(true); |
| 304 run_loop.Run(); | 304 run_loop.Run(); |
| 305 | 305 |
| 306 // Check the display's rotation. | 306 // Check the display's rotation. |
| 307 ash::DisplayManager* const display_manager = GetDisplayManager(); | 307 display::DisplayManager* const display_manager = GetDisplayManager(); |
| 308 const int64_t first_display_id = display_manager->first_display_id(); | 308 const int64_t first_display_id = display_manager->first_display_id(); |
| 309 const display::Display& first_display = | 309 const display::Display& first_display = |
| 310 display_manager->GetDisplayForId(first_display_id); | 310 display_manager->GetDisplayForId(first_display_id); |
| 311 EXPECT_EQ(policy_rotation, first_display.rotation()); | 311 EXPECT_EQ(policy_rotation, first_display.rotation()); |
| 312 | 312 |
| 313 // Let the user rotate the display to a different orientation, to check that | 313 // Let the user rotate the display to a different orientation, to check that |
| 314 // the policy value is restored after reboot. | 314 // the policy value is restored after reboot. |
| 315 display_manager->SetDisplayRotation(first_display_id, user_rotation, | 315 display_manager->SetDisplayRotation(first_display_id, user_rotation, |
| 316 display::Display::ROTATION_SOURCE_USER); | 316 display::Display::ROTATION_SOURCE_USER); |
| 317 EXPECT_EQ(user_rotation, first_display.rotation()); | 317 EXPECT_EQ(user_rotation, first_display.rotation()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 IN_PROC_BROWSER_TEST_P(DisplayRotationBootTest, Reboot) { | 320 IN_PROC_BROWSER_TEST_P(DisplayRotationBootTest, Reboot) { |
| 321 const display::Display::Rotation policy_rotation = GetParam(); | 321 const display::Display::Rotation policy_rotation = GetParam(); |
| 322 | 322 |
| 323 // Check that the policy rotation is restored. | 323 // Check that the policy rotation is restored. |
| 324 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()); | 324 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()); |
| 325 } | 325 } |
| 326 | 326 |
| 327 INSTANTIATE_TEST_CASE_P(PolicyDisplayRotationDefault, | 327 INSTANTIATE_TEST_CASE_P(PolicyDisplayRotationDefault, |
| 328 DisplayRotationBootTest, | 328 DisplayRotationBootTest, |
| 329 testing::Values(display::Display::ROTATE_0, | 329 testing::Values(display::Display::ROTATE_0, |
| 330 display::Display::ROTATE_90, | 330 display::Display::ROTATE_90, |
| 331 display::Display::ROTATE_180, | 331 display::Display::ROTATE_180, |
| 332 display::Display::ROTATE_270)); | 332 display::Display::ROTATE_270)); |
| 333 | 333 |
| 334 } // namespace policy | 334 } // namespace policy |
| OLD | NEW |