| 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chromeos/chromeos_switches.h" | 26 #include "chromeos/chromeos_switches.h" |
| 27 #include "chromeos/dbus/cryptohome_client.h" | 27 #include "chromeos/dbus/cryptohome_client.h" |
| 28 #include "chromeos/dbus/dbus_thread_manager.h" | 28 #include "chromeos/dbus/dbus_thread_manager.h" |
| 29 #include "chromeos/dbus/fake_cryptohome_client.h" | 29 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 30 #include "chromeos/dbus/fake_session_manager_client.h" | 30 #include "chromeos/dbus/fake_session_manager_client.h" |
| 31 #include "chromeos/dbus/session_manager_client.h" | 31 #include "chromeos/dbus/session_manager_client.h" |
| 32 #include "chromeos/settings/cros_settings_names.h" | 32 #include "chromeos/settings/cros_settings_names.h" |
| 33 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "ui/display/display.h" |
| 35 #include "ui/display/manager/display_layout.h" | 36 #include "ui/display/manager/display_layout.h" |
| 36 #include "ui/gfx/display.h" | |
| 37 | 37 |
| 38 namespace em = enterprise_management; | 38 namespace em = enterprise_management; |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 ash::DisplayManager* GetDisplayManager() { | 42 ash::DisplayManager* GetDisplayManager() { |
| 43 return ash::Shell::GetInstance()->display_manager(); | 43 return ash::Shell::GetInstance()->display_manager(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 gfx::Display::Rotation GetRotationOfFirstDisplay() { | 46 display::Display::Rotation GetRotationOfFirstDisplay() { |
| 47 const ash::DisplayManager* const display_manager = GetDisplayManager(); | 47 const ash::DisplayManager* const display_manager = GetDisplayManager(); |
| 48 const int64_t first_display_id = display_manager->first_display_id(); | 48 const int64_t first_display_id = display_manager->first_display_id(); |
| 49 const gfx::Display& first_display = | 49 const display::Display& first_display = |
| 50 display_manager->GetDisplayForId(first_display_id); | 50 display_manager->GetDisplayForId(first_display_id); |
| 51 return first_display.rotation(); | 51 return first_display.rotation(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Fails the test and returns ROTATE_0 if there is no second display. | 54 // Fails the test and returns ROTATE_0 if there is no second display. |
| 55 gfx::Display::Rotation GetRotationOfSecondDisplay() { | 55 display::Display::Rotation GetRotationOfSecondDisplay() { |
| 56 const ash::DisplayManager* const display_manager = GetDisplayManager(); | 56 const ash::DisplayManager* const display_manager = GetDisplayManager(); |
| 57 if (display_manager->GetNumDisplays() < 2) { | 57 if (display_manager->GetNumDisplays() < 2) { |
| 58 ADD_FAILURE() | 58 ADD_FAILURE() |
| 59 << "Requested rotation of second display while there was only one."; | 59 << "Requested rotation of second display while there was only one."; |
| 60 return gfx::Display::ROTATE_0; | 60 return display::Display::ROTATE_0; |
| 61 } | 61 } |
| 62 const display::DisplayIdList display_id_pair = | 62 const display::DisplayIdList display_id_pair = |
| 63 display_manager->GetCurrentDisplayIdList(); | 63 display_manager->GetCurrentDisplayIdList(); |
| 64 const gfx::Display& second_display = | 64 const display::Display& second_display = |
| 65 display_manager->GetDisplayForId(display_id_pair[1]); | 65 display_manager->GetDisplayForId(display_id_pair[1]); |
| 66 return second_display.rotation(); | 66 return second_display.rotation(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // anonymous namespace | 69 } // anonymous namespace |
| 70 | 70 |
| 71 namespace policy { | 71 namespace policy { |
| 72 | 72 |
| 73 class DisplayRotationDefaultTest | 73 class DisplayRotationDefaultTest |
| 74 : public policy::DevicePolicyCrosBrowserTest, | 74 : public policy::DevicePolicyCrosBrowserTest, |
| 75 public testing::WithParamInterface<gfx::Display::Rotation> { | 75 public testing::WithParamInterface<display::Display::Rotation> { |
| 76 public: | 76 public: |
| 77 DisplayRotationDefaultTest() {} | 77 DisplayRotationDefaultTest() {} |
| 78 | 78 |
| 79 void SetUpCommandLine(base::CommandLine* command_line) override { | 79 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 80 command_line->AppendSwitch(chromeos::switches::kLoginManager); | 80 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
| 81 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | 81 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void SetUpInProcessBrowserTestFixture() override { | 84 void SetUpInProcessBrowserTestFixture() override { |
| 85 InstallOwnerKey(); | 85 InstallOwnerKey(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 chromeos::CrosSettings::Get()->AddSettingsObserver( | 137 chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 138 chromeos::kSystemUse24HourClock, run_loop.QuitClosure()); | 138 chromeos::kSystemUse24HourClock, run_loop.QuitClosure()); |
| 139 RefreshDevicePolicy(); | 139 RefreshDevicePolicy(); |
| 140 run_loop.Run(); | 140 run_loop.Run(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 DISALLOW_COPY_AND_ASSIGN(DisplayRotationDefaultTest); | 144 DISALLOW_COPY_AND_ASSIGN(DisplayRotationDefaultTest); |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 // If gfx::Display::Rotation is ever modified and this test fails, there are | 147 // If display::Display::Rotation is ever modified and this test fails, there are |
| 148 // hardcoded enum-values in the following files that might need adjustment: | 148 // hardcoded enum-values in the following files that might need adjustment: |
| 149 // * this file: range check in this function, initializations, expected values, | 149 // * this file: range check in this function, initializations, expected values, |
| 150 // the list of parameters at the bottom of the file | 150 // the list of parameters at the bottom of the file |
| 151 // * display_rotation_default_handler.cc: Range check in UpdateFromCrosSettings, | 151 // * display_rotation_default_handler.cc: Range check in UpdateFromCrosSettings, |
| 152 // initialization to ROTATE_0 | 152 // initialization to ROTATE_0 |
| 153 // * display_rotation_default_handler.h: initialization to ROTATE_0 | 153 // * display_rotation_default_handler.h: initialization to ROTATE_0 |
| 154 // * chrome/browser/chromeos/policy/proto/chrome_device_policy.proto: | 154 // * chrome/browser/chromeos/policy/proto/chrome_device_policy.proto: |
| 155 // DisplayRotationDefaultProto::Rotation should match one to one | 155 // DisplayRotationDefaultProto::Rotation should match one to one |
| 156 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, EnumsInSync) { | 156 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, EnumsInSync) { |
| 157 const gfx::Display::Rotation rotation = GetParam(); | 157 const display::Display::Rotation rotation = GetParam(); |
| 158 EXPECT_EQ(em::DisplayRotationDefaultProto::Rotation_ARRAYSIZE, | 158 EXPECT_EQ(em::DisplayRotationDefaultProto::Rotation_ARRAYSIZE, |
| 159 gfx::Display::ROTATE_270 + 1) | 159 display::Display::ROTATE_270 + 1) |
| 160 << "Enums gfx::Display::Rotation and " | 160 << "Enums display::Display::Rotation and " |
| 161 << "em::DisplayRotationDefaultProto::Rotation are not in sync."; | 161 << "em::DisplayRotationDefaultProto::Rotation are not in sync."; |
| 162 EXPECT_TRUE(em::DisplayRotationDefaultProto::Rotation_IsValid(rotation)) | 162 EXPECT_TRUE(em::DisplayRotationDefaultProto::Rotation_IsValid(rotation)) |
| 163 << rotation << " is invalid as rotation. All valid values lie in " | 163 << rotation << " is invalid as rotation. All valid values lie in " |
| 164 << "the range from " << em::DisplayRotationDefaultProto::Rotation_MIN | 164 << "the range from " << em::DisplayRotationDefaultProto::Rotation_MIN |
| 165 << " to " << em::DisplayRotationDefaultProto::Rotation_MAX << "."; | 165 << " to " << em::DisplayRotationDefaultProto::Rotation_MAX << "."; |
| 166 } | 166 } |
| 167 | 167 |
| 168 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, FirstDisplay) { | 168 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, FirstDisplay) { |
| 169 const gfx::Display::Rotation policy_rotation = GetParam(); | 169 const display::Display::Rotation policy_rotation = GetParam(); |
| 170 EXPECT_EQ(gfx::Display::ROTATE_0, GetRotationOfFirstDisplay()) | 170 EXPECT_EQ(display::Display::ROTATE_0, GetRotationOfFirstDisplay()) |
| 171 << "Initial primary rotation before policy"; | 171 << "Initial primary rotation before policy"; |
| 172 | 172 |
| 173 SetPolicy(policy_rotation); | 173 SetPolicy(policy_rotation); |
| 174 int settings_rotation; | 174 int settings_rotation; |
| 175 EXPECT_TRUE(chromeos::CrosSettings::Get()->GetInteger( | 175 EXPECT_TRUE(chromeos::CrosSettings::Get()->GetInteger( |
| 176 chromeos::kDisplayRotationDefault, &settings_rotation)); | 176 chromeos::kDisplayRotationDefault, &settings_rotation)); |
| 177 EXPECT_EQ(policy_rotation, settings_rotation) | 177 EXPECT_EQ(policy_rotation, settings_rotation) |
| 178 << "Value of CrosSettings after policy value changed"; | 178 << "Value of CrosSettings after policy value changed"; |
| 179 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()) | 179 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()) |
| 180 << "Rotation of primary display after policy"; | 180 << "Rotation of primary display after policy"; |
| 181 } | 181 } |
| 182 | 182 |
| 183 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, RefreshSecondDisplay) { | 183 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, RefreshSecondDisplay) { |
| 184 const gfx::Display::Rotation policy_rotation = GetParam(); | 184 const display::Display::Rotation policy_rotation = GetParam(); |
| 185 ToggleSecondDisplay(); | 185 ToggleSecondDisplay(); |
| 186 EXPECT_EQ(gfx::Display::ROTATE_0, GetRotationOfSecondDisplay()) | 186 EXPECT_EQ(display::Display::ROTATE_0, GetRotationOfSecondDisplay()) |
| 187 << "Rotation of secondary display before policy"; | 187 << "Rotation of secondary display before policy"; |
| 188 SetPolicy(policy_rotation); | 188 SetPolicy(policy_rotation); |
| 189 EXPECT_EQ(policy_rotation, GetRotationOfSecondDisplay()) | 189 EXPECT_EQ(policy_rotation, GetRotationOfSecondDisplay()) |
| 190 << "Rotation of already connected secondary display after policy"; | 190 << "Rotation of already connected secondary display after policy"; |
| 191 } | 191 } |
| 192 | 192 |
| 193 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, ConnectSecondDisplay) { | 193 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, ConnectSecondDisplay) { |
| 194 const gfx::Display::Rotation policy_rotation = GetParam(); | 194 const display::Display::Rotation policy_rotation = GetParam(); |
| 195 SetPolicy(policy_rotation); | 195 SetPolicy(policy_rotation); |
| 196 ToggleSecondDisplay(); | 196 ToggleSecondDisplay(); |
| 197 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()) | 197 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()) |
| 198 << "Rotation of primary display after policy"; | 198 << "Rotation of primary display after policy"; |
| 199 EXPECT_EQ(policy_rotation, GetRotationOfSecondDisplay()) | 199 EXPECT_EQ(policy_rotation, GetRotationOfSecondDisplay()) |
| 200 << "Rotation of newly connected secondary display after policy"; | 200 << "Rotation of newly connected secondary display after policy"; |
| 201 } | 201 } |
| 202 | 202 |
| 203 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, UserInteraction) { | 203 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, UserInteraction) { |
| 204 const gfx::Display::Rotation policy_rotation = GetParam(); | 204 const display::Display::Rotation policy_rotation = GetParam(); |
| 205 const gfx::Display::Rotation user_rotation = gfx::Display::ROTATE_90; | 205 const display::Display::Rotation user_rotation = display::Display::ROTATE_90; |
| 206 GetDisplayManager()->SetDisplayRotation( | 206 GetDisplayManager()->SetDisplayRotation( |
| 207 GetDisplayManager()->first_display_id(), user_rotation, | 207 GetDisplayManager()->first_display_id(), user_rotation, |
| 208 gfx::Display::ROTATION_SOURCE_USER); | 208 display::Display::ROTATION_SOURCE_USER); |
| 209 EXPECT_EQ(user_rotation, GetRotationOfFirstDisplay()) | 209 EXPECT_EQ(user_rotation, GetRotationOfFirstDisplay()) |
| 210 << "Rotation of primary display after user change"; | 210 << "Rotation of primary display after user change"; |
| 211 SetPolicy(policy_rotation); | 211 SetPolicy(policy_rotation); |
| 212 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()) | 212 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()) |
| 213 << "Rotation of primary display after policy overrode user change"; | 213 << "Rotation of primary display after policy overrode user change"; |
| 214 GetDisplayManager()->SetDisplayRotation( | 214 GetDisplayManager()->SetDisplayRotation( |
| 215 GetDisplayManager()->first_display_id(), user_rotation, | 215 GetDisplayManager()->first_display_id(), user_rotation, |
| 216 gfx::Display::ROTATION_SOURCE_USER); | 216 display::Display::ROTATION_SOURCE_USER); |
| 217 EXPECT_EQ(user_rotation, GetRotationOfFirstDisplay()) | 217 EXPECT_EQ(user_rotation, GetRotationOfFirstDisplay()) |
| 218 << "Rotation of primary display after user overrode policy change"; | 218 << "Rotation of primary display after user overrode policy change"; |
| 219 SetADifferentPolicy(); | 219 SetADifferentPolicy(); |
| 220 EXPECT_EQ(user_rotation, GetRotationOfFirstDisplay()) | 220 EXPECT_EQ(user_rotation, GetRotationOfFirstDisplay()) |
| 221 << "Rotation of primary display after policy reloaded without change"; | 221 << "Rotation of primary display after policy reloaded without change"; |
| 222 } | 222 } |
| 223 | 223 |
| 224 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, SetAndUnsetPolicy) { | 224 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, SetAndUnsetPolicy) { |
| 225 const gfx::Display::Rotation policy_rotation = GetParam(); | 225 const display::Display::Rotation policy_rotation = GetParam(); |
| 226 SetPolicy(policy_rotation); | 226 SetPolicy(policy_rotation); |
| 227 UnsetPolicy(); | 227 UnsetPolicy(); |
| 228 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()) | 228 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()) |
| 229 << "Rotation of primary display after policy was set and removed."; | 229 << "Rotation of primary display after policy was set and removed."; |
| 230 } | 230 } |
| 231 | 231 |
| 232 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, | 232 IN_PROC_BROWSER_TEST_P(DisplayRotationDefaultTest, |
| 233 SetAndUnsetPolicyWithUserInteraction) { | 233 SetAndUnsetPolicyWithUserInteraction) { |
| 234 const gfx::Display::Rotation policy_rotation = GetParam(); | 234 const display::Display::Rotation policy_rotation = GetParam(); |
| 235 const gfx::Display::Rotation user_rotation = gfx::Display::ROTATE_90; | 235 const display::Display::Rotation user_rotation = display::Display::ROTATE_90; |
| 236 SetPolicy(policy_rotation); | 236 SetPolicy(policy_rotation); |
| 237 GetDisplayManager()->SetDisplayRotation( | 237 GetDisplayManager()->SetDisplayRotation( |
| 238 GetDisplayManager()->first_display_id(), user_rotation, | 238 GetDisplayManager()->first_display_id(), user_rotation, |
| 239 gfx::Display::ROTATION_SOURCE_USER); | 239 display::Display::ROTATION_SOURCE_USER); |
| 240 UnsetPolicy(); | 240 UnsetPolicy(); |
| 241 EXPECT_EQ(user_rotation, GetRotationOfFirstDisplay()) | 241 EXPECT_EQ(user_rotation, GetRotationOfFirstDisplay()) |
| 242 << "Rotation of primary display after policy was set to " | 242 << "Rotation of primary display after policy was set to " |
| 243 << policy_rotation << ", user changed the rotation to " << user_rotation | 243 << policy_rotation << ", user changed the rotation to " << user_rotation |
| 244 << ", and policy was removed."; | 244 << ", and policy was removed."; |
| 245 } | 245 } |
| 246 | 246 |
| 247 INSTANTIATE_TEST_CASE_P(PolicyDisplayRotationDefault, | 247 INSTANTIATE_TEST_CASE_P(PolicyDisplayRotationDefault, |
| 248 DisplayRotationDefaultTest, | 248 DisplayRotationDefaultTest, |
| 249 testing::Values(gfx::Display::ROTATE_0, | 249 testing::Values(display::Display::ROTATE_0, |
| 250 gfx::Display::ROTATE_90, | 250 display::Display::ROTATE_90, |
| 251 gfx::Display::ROTATE_180, | 251 display::Display::ROTATE_180, |
| 252 gfx::Display::ROTATE_270)); | 252 display::Display::ROTATE_270)); |
| 253 | 253 |
| 254 // This class tests that the policy is reapplied after a reboot. To persist from | 254 // This class tests that the policy is reapplied after a reboot. To persist from |
| 255 // PRE_Reboot to Reboot, the policy is inserted into a FakeSessionManagerClient. | 255 // PRE_Reboot to Reboot, the policy is inserted into a FakeSessionManagerClient. |
| 256 // From there, it travels to DeviceSettingsProvider, whose UpdateFromService() | 256 // From there, it travels to DeviceSettingsProvider, whose UpdateFromService() |
| 257 // method caches the policy (using device_settings_cache::Store()). | 257 // method caches the policy (using device_settings_cache::Store()). |
| 258 // In the main test, the FakeSessionManagerClient is not fully initialized. | 258 // In the main test, the FakeSessionManagerClient is not fully initialized. |
| 259 // Thus, DeviceSettingsProvider falls back on the cached values (using | 259 // Thus, DeviceSettingsProvider falls back on the cached values (using |
| 260 // device_settings_cache::Retrieve()). | 260 // device_settings_cache::Retrieve()). |
| 261 class DisplayRotationBootTest | 261 class DisplayRotationBootTest |
| 262 : public InProcessBrowserTest, | 262 : public InProcessBrowserTest, |
| 263 public testing::WithParamInterface<gfx::Display::Rotation> { | 263 public testing::WithParamInterface<display::Display::Rotation> { |
| 264 protected: | 264 protected: |
| 265 DisplayRotationBootTest() | 265 DisplayRotationBootTest() |
| 266 : fake_session_manager_client_(new chromeos::FakeSessionManagerClient) {} | 266 : fake_session_manager_client_(new chromeos::FakeSessionManagerClient) {} |
| 267 ~DisplayRotationBootTest() override {} | 267 ~DisplayRotationBootTest() override {} |
| 268 | 268 |
| 269 void SetUpInProcessBrowserTestFixture() override { | 269 void SetUpInProcessBrowserTestFixture() override { |
| 270 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 270 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 271 std::unique_ptr<chromeos::SessionManagerClient>( | 271 std::unique_ptr<chromeos::SessionManagerClient>( |
| 272 fake_session_manager_client_)); | 272 fake_session_manager_client_)); |
| 273 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( | 273 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( |
| 274 std::unique_ptr<chromeos::CryptohomeClient>( | 274 std::unique_ptr<chromeos::CryptohomeClient>( |
| 275 new chromeos::FakeCryptohomeClient)); | 275 new chromeos::FakeCryptohomeClient)); |
| 276 | 276 |
| 277 test_helper_.InstallOwnerKey(); | 277 test_helper_.InstallOwnerKey(); |
| 278 test_helper_.MarkAsEnterpriseOwned(); | 278 test_helper_.MarkAsEnterpriseOwned(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 chromeos::FakeSessionManagerClient* fake_session_manager_client_; | 281 chromeos::FakeSessionManagerClient* fake_session_manager_client_; |
| 282 policy::DevicePolicyCrosTestHelper test_helper_; | 282 policy::DevicePolicyCrosTestHelper test_helper_; |
| 283 }; | 283 }; |
| 284 | 284 |
| 285 IN_PROC_BROWSER_TEST_P(DisplayRotationBootTest, PRE_Reboot) { | 285 IN_PROC_BROWSER_TEST_P(DisplayRotationBootTest, PRE_Reboot) { |
| 286 const gfx::Display::Rotation policy_rotation = GetParam(); | 286 const display::Display::Rotation policy_rotation = GetParam(); |
| 287 const gfx::Display::Rotation user_rotation = gfx::Display::ROTATE_180; | 287 const display::Display::Rotation user_rotation = display::Display::ROTATE_180; |
| 288 | 288 |
| 289 // Set policy. | 289 // Set policy. |
| 290 policy::DevicePolicyBuilder* const device_policy( | 290 policy::DevicePolicyBuilder* const device_policy( |
| 291 test_helper_.device_policy()); | 291 test_helper_.device_policy()); |
| 292 em::ChromeDeviceSettingsProto& proto(device_policy->payload()); | 292 em::ChromeDeviceSettingsProto& proto(device_policy->payload()); |
| 293 proto.mutable_display_rotation_default()->set_display_rotation_default( | 293 proto.mutable_display_rotation_default()->set_display_rotation_default( |
| 294 static_cast<em::DisplayRotationDefaultProto::Rotation>(policy_rotation)); | 294 static_cast<em::DisplayRotationDefaultProto::Rotation>(policy_rotation)); |
| 295 base::RunLoop run_loop; | 295 base::RunLoop run_loop; |
| 296 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> observer = | 296 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> observer = |
| 297 chromeos::CrosSettings::Get()->AddSettingsObserver( | 297 chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 298 chromeos::kDisplayRotationDefault, run_loop.QuitClosure()); | 298 chromeos::kDisplayRotationDefault, run_loop.QuitClosure()); |
| 299 device_policy->SetDefaultSigningKey(); | 299 device_policy->SetDefaultSigningKey(); |
| 300 device_policy->Build(); | 300 device_policy->Build(); |
| 301 fake_session_manager_client_->set_device_policy(device_policy->GetBlob()); | 301 fake_session_manager_client_->set_device_policy(device_policy->GetBlob()); |
| 302 fake_session_manager_client_->OnPropertyChangeComplete(true); | 302 fake_session_manager_client_->OnPropertyChangeComplete(true); |
| 303 run_loop.Run(); | 303 run_loop.Run(); |
| 304 | 304 |
| 305 // Check the display's rotation. | 305 // Check the display's rotation. |
| 306 ash::DisplayManager* const display_manager = GetDisplayManager(); | 306 ash::DisplayManager* const display_manager = GetDisplayManager(); |
| 307 const int64_t first_display_id = display_manager->first_display_id(); | 307 const int64_t first_display_id = display_manager->first_display_id(); |
| 308 const gfx::Display& first_display = | 308 const display::Display& first_display = |
| 309 display_manager->GetDisplayForId(first_display_id); | 309 display_manager->GetDisplayForId(first_display_id); |
| 310 EXPECT_EQ(policy_rotation, first_display.rotation()); | 310 EXPECT_EQ(policy_rotation, first_display.rotation()); |
| 311 | 311 |
| 312 // Let the user rotate the display to a different orientation, to check that | 312 // Let the user rotate the display to a different orientation, to check that |
| 313 // the policy value is restored after reboot. | 313 // the policy value is restored after reboot. |
| 314 display_manager->SetDisplayRotation(first_display_id, user_rotation, | 314 display_manager->SetDisplayRotation(first_display_id, user_rotation, |
| 315 gfx::Display::ROTATION_SOURCE_USER); | 315 display::Display::ROTATION_SOURCE_USER); |
| 316 EXPECT_EQ(user_rotation, first_display.rotation()); | 316 EXPECT_EQ(user_rotation, first_display.rotation()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 IN_PROC_BROWSER_TEST_P(DisplayRotationBootTest, Reboot) { | 319 IN_PROC_BROWSER_TEST_P(DisplayRotationBootTest, Reboot) { |
| 320 const gfx::Display::Rotation policy_rotation = GetParam(); | 320 const display::Display::Rotation policy_rotation = GetParam(); |
| 321 | 321 |
| 322 // Check that the policy rotation is restored. | 322 // Check that the policy rotation is restored. |
| 323 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()); | 323 EXPECT_EQ(policy_rotation, GetRotationOfFirstDisplay()); |
| 324 } | 324 } |
| 325 | 325 |
| 326 INSTANTIATE_TEST_CASE_P(PolicyDisplayRotationDefault, | 326 INSTANTIATE_TEST_CASE_P(PolicyDisplayRotationDefault, |
| 327 DisplayRotationBootTest, | 327 DisplayRotationBootTest, |
| 328 testing::Values(gfx::Display::ROTATE_0, | 328 testing::Values(display::Display::ROTATE_0, |
| 329 gfx::Display::ROTATE_90, | 329 display::Display::ROTATE_90, |
| 330 gfx::Display::ROTATE_180, | 330 display::Display::ROTATE_180, |
| 331 gfx::Display::ROTATE_270)); | 331 display::Display::ROTATE_270)); |
| 332 | 332 |
| 333 } // namespace policy | 333 } // namespace policy |
| OLD | NEW |