Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/ash/session_controller_client.h" | 5 #include "chrome/browser/ui/ash/session_controller_client.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 13 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 14 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 14 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
| 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 16 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | 16 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 17 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | 17 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
| 18 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" | 18 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" |
| 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_service.h" | 20 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 21 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 21 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
| 24 #include "chrome/test/base/testing_profile_manager.h" | 24 #include "chrome/test/base/testing_profile_manager.h" |
| 25 #include "components/prefs/pref_service.h" | |
| 25 #include "components/session_manager/core/session_manager.h" | 26 #include "components/session_manager/core/session_manager.h" |
| 26 #include "components/signin/core/account_id/account_id.h" | 27 #include "components/signin/core/account_id/account_id.h" |
| 27 #include "components/user_manager/user_manager.h" | 28 #include "components/user_manager/user_manager.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "net/cert/x509_certificate.h" | 30 #include "net/cert/x509_certificate.h" |
| 30 #include "net/test/cert_test_util.h" | 31 #include "net/test/cert_test_util.h" |
| 31 #include "net/test/test_data_directory.h" | 32 #include "net/test/test_data_directory.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 34 |
| 34 using chromeos::FakeChromeUserManager; | 35 using chromeos::FakeChromeUserManager; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 59 // user_manager::UserManager: | 60 // user_manager::UserManager: |
| 60 void UserLoggedIn(const AccountId& account_id, | 61 void UserLoggedIn(const AccountId& account_id, |
| 61 const std::string& user_id_hash, | 62 const std::string& user_id_hash, |
| 62 bool browser_restart) override { | 63 bool browser_restart) override { |
| 63 FakeChromeUserManager::UserLoggedIn(account_id, user_id_hash, | 64 FakeChromeUserManager::UserLoggedIn(account_id, user_id_hash, |
| 64 browser_restart); | 65 browser_restart); |
| 65 active_user_ = const_cast<user_manager::User*>(FindUser(account_id)); | 66 active_user_ = const_cast<user_manager::User*>(FindUser(account_id)); |
| 66 NotifyOnLogin(); | 67 NotifyOnLogin(); |
| 67 } | 68 } |
| 68 | 69 |
| 70 user_manager::UserList GetUnlockUsers() const override { | |
| 71 // Test case UserPrefsChange expects that the list of the unlock users | |
| 72 // depends on prefs::kAllowScreenLock. | |
| 73 user_manager::UserList unlock_users; | |
| 74 for (user_manager::User* user : users_) { | |
| 75 Profile* user_profile = | |
| 76 chromeos::ProfileHelper::Get()->GetProfileByUser(user); | |
| 77 // Skip if user has a profile and kAllowScreenLock is set to false. | |
| 78 if (user_profile && | |
| 79 !user_profile->GetPrefs()->GetBoolean(prefs::kAllowScreenLock)) { | |
| 80 continue; | |
| 81 } | |
| 82 | |
| 83 unlock_users.push_back(user); | |
| 84 } | |
| 85 | |
| 86 return unlock_users; | |
| 87 } | |
| 88 | |
| 69 private: | 89 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(TestChromeUserManager); | 90 DISALLOW_COPY_AND_ASSIGN(TestChromeUserManager); |
| 71 }; | 91 }; |
| 72 | 92 |
| 73 // A session controller interface implementation that tracks sessions and users. | 93 // A session controller interface implementation that tracks sessions and users. |
| 74 class TestSessionController : public ash::mojom::SessionController { | 94 class TestSessionController : public ash::mojom::SessionController { |
| 75 public: | 95 public: |
| 76 TestSessionController() : binding_(this) {} | 96 TestSessionController() : binding_(this) {} |
| 77 ~TestSessionController() override {} | 97 ~TestSessionController() override {} |
| 78 | 98 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 const std::string& GetActiveUserEmail() { | 185 const std::string& GetActiveUserEmail() { |
| 166 return user_manager::UserManager::Get() | 186 return user_manager::UserManager::Get() |
| 167 ->GetActiveUser() | 187 ->GetActiveUser() |
| 168 ->GetAccountId() | 188 ->GetAccountId() |
| 169 .GetUserEmail(); | 189 .GetUserEmail(); |
| 170 } | 190 } |
| 171 | 191 |
| 172 TestChromeUserManager* user_manager() { return user_manager_; } | 192 TestChromeUserManager* user_manager() { return user_manager_; } |
| 173 | 193 |
| 174 // Adds a regular user with a profile. | 194 // Adds a regular user with a profile. |
| 175 void InitForMultiProfile() { | 195 TestingProfile* InitForMultiProfile() { |
| 176 const AccountId account_id(AccountId::FromUserEmail(kUser)); | 196 const AccountId account_id(AccountId::FromUserEmail(kUser)); |
| 177 const user_manager::User* user = user_manager()->AddUser(account_id); | 197 const user_manager::User* user = user_manager()->AddUser(account_id); |
| 178 | 198 |
| 179 // Note that user profiles are created after user login in reality. | 199 // Note that user profiles are created after user login in reality. |
| 180 CreateTestingProfile(user); | 200 return CreateTestingProfile(user); |
| 181 } | 201 } |
| 182 | 202 |
| 183 // Calls private methods to create a testing profile. | 203 // Calls private methods to create a testing profile. |
|
James Cook
2017/05/08 21:50:00
nit: Maybe note that the profile is owned by the P
xiyuan
2017/05/08 22:27:39
Done.
It is sort of owned by ProfileManager. Pro
| |
| 184 void CreateTestingProfile(const user_manager::User* user) { | 204 TestingProfile* CreateTestingProfile(const user_manager::User* user) { |
| 185 const AccountId& account_id = user->GetAccountId(); | 205 const AccountId& account_id = user->GetAccountId(); |
| 186 user_profile_ = | 206 TestingProfile* profile = |
| 187 profile_manager_->CreateTestingProfile(account_id.GetUserEmail()); | 207 profile_manager_->CreateTestingProfile(account_id.GetUserEmail()); |
| 188 user_profile_->set_profile_name(account_id.GetUserEmail()); | 208 profile->set_profile_name(account_id.GetUserEmail()); |
| 189 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( | 209 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, |
| 190 user, user_profile_); | 210 profile); |
| 211 return profile; | |
| 191 } | 212 } |
| 192 | 213 |
| 193 content::TestBrowserThreadBundle threads_; | 214 content::TestBrowserThreadBundle threads_; |
| 194 std::unique_ptr<policy::PolicyCertVerifier> cert_verifier_; | 215 std::unique_ptr<policy::PolicyCertVerifier> cert_verifier_; |
| 195 std::unique_ptr<TestingProfileManager> profile_manager_; | 216 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 196 TestingProfile* user_profile_; | |
| 197 session_manager::SessionManager session_manager_; | 217 session_manager::SessionManager session_manager_; |
| 198 | 218 |
| 199 private: | 219 private: |
| 200 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 220 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 201 | 221 |
| 202 // Owned by |user_manager_enabler_|. | 222 // Owned by |user_manager_enabler_|. |
| 203 TestChromeUserManager* user_manager_ = nullptr; | 223 TestChromeUserManager* user_manager_ = nullptr; |
| 204 | 224 |
| 205 DISALLOW_COPY_AND_ASSIGN(SessionControllerClientTest); | 225 DISALLOW_COPY_AND_ASSIGN(SessionControllerClientTest); |
| 206 }; | 226 }; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 SessionControllerClient::DoCycleActiveUser(backward); | 259 SessionControllerClient::DoCycleActiveUser(backward); |
| 240 EXPECT_EQ("thirduser@test.com", GetActiveUserEmail()); | 260 EXPECT_EQ("thirduser@test.com", GetActiveUserEmail()); |
| 241 SessionControllerClient::DoCycleActiveUser(backward); | 261 SessionControllerClient::DoCycleActiveUser(backward); |
| 242 EXPECT_EQ("seconduser@test.com", GetActiveUserEmail()); | 262 EXPECT_EQ("seconduser@test.com", GetActiveUserEmail()); |
| 243 SessionControllerClient::DoCycleActiveUser(backward); | 263 SessionControllerClient::DoCycleActiveUser(backward); |
| 244 EXPECT_EQ("firstuser@test.com", GetActiveUserEmail()); | 264 EXPECT_EQ("firstuser@test.com", GetActiveUserEmail()); |
| 245 } | 265 } |
| 246 | 266 |
| 247 // Make sure MultiProfile disabled by primary user policy. | 267 // Make sure MultiProfile disabled by primary user policy. |
| 248 TEST_F(SessionControllerClientTest, MultiProfileDisallowedByUserPolicy) { | 268 TEST_F(SessionControllerClientTest, MultiProfileDisallowedByUserPolicy) { |
| 249 InitForMultiProfile(); | 269 TestingProfile* user_profile = InitForMultiProfile(); |
| 250 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, | 270 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, |
| 251 SessionControllerClient::GetAddUserSessionPolicy()); | 271 SessionControllerClient::GetAddUserSessionPolicy()); |
| 252 const AccountId account_id(AccountId::FromUserEmail(kUser)); | 272 const AccountId account_id(AccountId::FromUserEmail(kUser)); |
| 253 user_manager()->LoginUser(account_id); | 273 user_manager()->LoginUser(account_id); |
| 254 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS, | 274 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS, |
| 255 SessionControllerClient::GetAddUserSessionPolicy()); | 275 SessionControllerClient::GetAddUserSessionPolicy()); |
| 256 | 276 |
| 257 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); | 277 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); |
| 258 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, | 278 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, |
| 259 SessionControllerClient::GetAddUserSessionPolicy()); | 279 SessionControllerClient::GetAddUserSessionPolicy()); |
| 260 | 280 |
| 261 user_profile_->GetPrefs()->SetString( | 281 user_profile->GetPrefs()->SetString( |
| 262 prefs::kMultiProfileUserBehavior, | 282 prefs::kMultiProfileUserBehavior, |
| 263 chromeos::MultiProfileUserController::kBehaviorNotAllowed); | 283 chromeos::MultiProfileUserController::kBehaviorNotAllowed); |
| 264 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, | 284 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, |
| 265 SessionControllerClient::GetAddUserSessionPolicy()); | 285 SessionControllerClient::GetAddUserSessionPolicy()); |
| 266 } | 286 } |
| 267 | 287 |
| 268 // Make sure MultiProfile disabled by primary user policy certificates. | 288 // Make sure MultiProfile disabled by primary user policy certificates. |
| 269 TEST_F(SessionControllerClientTest, | 289 TEST_F(SessionControllerClientTest, |
| 270 MultiProfileDisallowedByPolicyCertificates) { | 290 MultiProfileDisallowedByPolicyCertificates) { |
| 271 InitForMultiProfile(); | 291 InitForMultiProfile(); |
| 272 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); | 292 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); |
| 273 | 293 |
| 274 const AccountId account_id(AccountId::FromUserEmail(kUser)); | 294 const AccountId account_id(AccountId::FromUserEmail(kUser)); |
| 275 user_manager()->LoginUser(account_id); | 295 user_manager()->LoginUser(account_id); |
| 276 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, | 296 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, |
| 277 SessionControllerClient::GetAddUserSessionPolicy()); | 297 SessionControllerClient::GetAddUserSessionPolicy()); |
| 278 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates( | 298 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates( |
| 279 account_id.GetUserEmail()); | 299 account_id.GetUserEmail()); |
| 280 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, | 300 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, |
| 281 SessionControllerClient::GetAddUserSessionPolicy()); | 301 SessionControllerClient::GetAddUserSessionPolicy()); |
| 282 | 302 |
| 283 // Flush tasks posted to IO. | 303 // Flush tasks posted to IO. |
| 284 base::RunLoop().RunUntilIdle(); | 304 base::RunLoop().RunUntilIdle(); |
| 285 } | 305 } |
| 286 | 306 |
| 287 // Make sure MultiProfile disabled by primary user certificates in memory. | 307 // Make sure MultiProfile disabled by primary user certificates in memory. |
| 288 TEST_F(SessionControllerClientTest, | 308 TEST_F(SessionControllerClientTest, |
| 289 MultiProfileDisallowedByPrimaryUserCertificatesInMemory) { | 309 MultiProfileDisallowedByPrimaryUserCertificatesInMemory) { |
| 290 InitForMultiProfile(); | 310 TestingProfile* user_profile = InitForMultiProfile(); |
| 291 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); | 311 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); |
| 292 | 312 |
| 293 const AccountId account_id(AccountId::FromUserEmail(kUser)); | 313 const AccountId account_id(AccountId::FromUserEmail(kUser)); |
| 294 user_manager()->LoginUser(account_id); | 314 user_manager()->LoginUser(account_id); |
| 295 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, | 315 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, |
| 296 SessionControllerClient::GetAddUserSessionPolicy()); | 316 SessionControllerClient::GetAddUserSessionPolicy()); |
| 297 cert_verifier_.reset(new policy::PolicyCertVerifier(base::Closure())); | 317 cert_verifier_.reset(new policy::PolicyCertVerifier(base::Closure())); |
| 298 g_policy_cert_verifier_for_factory = cert_verifier_.get(); | 318 g_policy_cert_verifier_for_factory = cert_verifier_.get(); |
| 299 ASSERT_TRUE( | 319 ASSERT_TRUE( |
| 300 policy::PolicyCertServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 320 policy::PolicyCertServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 301 user_profile_, CreateTestPolicyCertService)); | 321 user_profile, CreateTestPolicyCertService)); |
| 302 policy::PolicyCertService* service = | 322 policy::PolicyCertService* service = |
| 303 policy::PolicyCertServiceFactory::GetForProfile(user_profile_); | 323 policy::PolicyCertServiceFactory::GetForProfile(user_profile); |
| 304 ASSERT_TRUE(service); | 324 ASSERT_TRUE(service); |
| 305 | 325 |
| 306 EXPECT_FALSE(service->has_policy_certificates()); | 326 EXPECT_FALSE(service->has_policy_certificates()); |
| 307 net::CertificateList certificates; | 327 net::CertificateList certificates; |
| 308 certificates.push_back( | 328 certificates.push_back( |
| 309 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem")); | 329 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem")); |
| 310 service->OnTrustAnchorsChanged(certificates); | 330 service->OnTrustAnchorsChanged(certificates); |
| 311 EXPECT_TRUE(service->has_policy_certificates()); | 331 EXPECT_TRUE(service->has_policy_certificates()); |
| 312 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, | 332 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, |
| 313 SessionControllerClient::GetAddUserSessionPolicy()); | 333 SessionControllerClient::GetAddUserSessionPolicy()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 const AccountId account_id(AccountId::FromUserEmail(kUser)); | 365 const AccountId account_id(AccountId::FromUserEmail(kUser)); |
| 346 user_manager()->LoginUser(account_id); | 366 user_manager()->LoginUser(account_id); |
| 347 UserAddedToSession("bb@b.b"); | 367 UserAddedToSession("bb@b.b"); |
| 348 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS, | 368 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS, |
| 349 SessionControllerClient::GetAddUserSessionPolicy()); | 369 SessionControllerClient::GetAddUserSessionPolicy()); |
| 350 } | 370 } |
| 351 | 371 |
| 352 // Make sure adding users to multiprofiles disabled by primary user policy. | 372 // Make sure adding users to multiprofiles disabled by primary user policy. |
| 353 TEST_F(SessionControllerClientTest, | 373 TEST_F(SessionControllerClientTest, |
| 354 AddUserToMultiprofileDisallowedByPrimaryUserPolicy) { | 374 AddUserToMultiprofileDisallowedByPrimaryUserPolicy) { |
| 355 InitForMultiProfile(); | 375 TestingProfile* user_profile = InitForMultiProfile(); |
| 356 | 376 |
| 357 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, | 377 EXPECT_EQ(ash::AddUserSessionPolicy::ALLOWED, |
| 358 SessionControllerClient::GetAddUserSessionPolicy()); | 378 SessionControllerClient::GetAddUserSessionPolicy()); |
| 359 const AccountId account_id(AccountId::FromUserEmail(kUser)); | 379 const AccountId account_id(AccountId::FromUserEmail(kUser)); |
| 360 user_manager()->LoginUser(account_id); | 380 user_manager()->LoginUser(account_id); |
| 361 user_profile_->GetPrefs()->SetString( | 381 user_profile->GetPrefs()->SetString( |
| 362 prefs::kMultiProfileUserBehavior, | 382 prefs::kMultiProfileUserBehavior, |
| 363 chromeos::MultiProfileUserController::kBehaviorNotAllowed); | 383 chromeos::MultiProfileUserController::kBehaviorNotAllowed); |
| 364 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); | 384 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); |
| 365 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, | 385 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, |
| 366 SessionControllerClient::GetAddUserSessionPolicy()); | 386 SessionControllerClient::GetAddUserSessionPolicy()); |
| 367 } | 387 } |
| 368 | 388 |
| 369 TEST_F(SessionControllerClientTest, SendUserSession) { | 389 TEST_F(SessionControllerClientTest, SendUserSession) { |
| 370 // Create an object to test and connect it to our test interface. | 390 // Create an object to test and connect it to our test interface. |
| 371 SessionControllerClient client; | 391 SessionControllerClient client; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 "child@test.com")); | 442 "child@test.com")); |
| 423 session_manager_.SetSessionState(SessionState::ACTIVE); | 443 session_manager_.SetSessionState(SessionState::ACTIVE); |
| 424 SessionControllerClient::FlushForTesting(); | 444 SessionControllerClient::FlushForTesting(); |
| 425 | 445 |
| 426 // The session controller received session info and user session. | 446 // The session controller received session info and user session. |
| 427 EXPECT_LT(0u, session_controller.last_user_session()->session_id); | 447 EXPECT_LT(0u, session_controller.last_user_session()->session_id); |
| 428 EXPECT_EQ(user_manager::USER_TYPE_SUPERVISED, | 448 EXPECT_EQ(user_manager::USER_TYPE_SUPERVISED, |
| 429 session_controller.last_user_session()->type); | 449 session_controller.last_user_session()->type); |
| 430 | 450 |
| 431 // Simulate profile creation after login. | 451 // Simulate profile creation after login. |
| 432 CreateTestingProfile(user); | 452 TestingProfile* user_profile = CreateTestingProfile(user); |
| 433 user_profile_->SetSupervisedUserId("child-id"); | 453 user_profile->SetSupervisedUserId("child-id"); |
| 434 | 454 |
| 435 // Simulate supervised user custodians. | 455 // Simulate supervised user custodians. |
| 436 PrefService* prefs = user_profile_->GetPrefs(); | 456 PrefService* prefs = user_profile->GetPrefs(); |
| 437 prefs->SetString(prefs::kSupervisedUserCustodianEmail, "parent1@test.com"); | 457 prefs->SetString(prefs::kSupervisedUserCustodianEmail, "parent1@test.com"); |
| 438 prefs->SetString(prefs::kSupervisedUserSecondCustodianEmail, | 458 prefs->SetString(prefs::kSupervisedUserSecondCustodianEmail, |
| 439 "parent2@test.com"); | 459 "parent2@test.com"); |
| 440 | 460 |
| 441 // Simulate the notification that the profile is ready. | 461 // Simulate the notification that the profile is ready. |
| 442 client.OnLoginUserProfilePrepared(user_profile_); | 462 client.OnLoginUserProfilePrepared(user_profile); |
| 443 base::RunLoop().RunUntilIdle(); // For PostTask and mojo interface. | 463 base::RunLoop().RunUntilIdle(); // For PostTask and mojo interface. |
| 444 | 464 |
| 445 // The custodians were sent over the mojo interface. | 465 // The custodians were sent over the mojo interface. |
| 446 EXPECT_EQ("parent1@test.com", | 466 EXPECT_EQ("parent1@test.com", |
| 447 session_controller.last_user_session()->custodian_email); | 467 session_controller.last_user_session()->custodian_email); |
| 448 EXPECT_EQ("parent2@test.com", | 468 EXPECT_EQ("parent2@test.com", |
| 449 session_controller.last_user_session()->second_custodian_email); | 469 session_controller.last_user_session()->second_custodian_email); |
| 450 | 470 |
| 451 // Simulate an update to the custodian information. | 471 // Simulate an update to the custodian information. |
| 452 prefs->SetString(prefs::kSupervisedUserCustodianEmail, "parent3@test.com"); | 472 prefs->SetString(prefs::kSupervisedUserCustodianEmail, "parent3@test.com"); |
| 453 client.OnCustodianInfoChanged(); | 473 client.OnCustodianInfoChanged(); |
| 454 SessionControllerClient::FlushForTesting(); | 474 SessionControllerClient::FlushForTesting(); |
| 455 | 475 |
| 456 // The updated custodian was sent over the mojo interface. | 476 // The updated custodian was sent over the mojo interface. |
| 457 EXPECT_EQ("parent3@test.com", | 477 EXPECT_EQ("parent3@test.com", |
| 458 session_controller.last_user_session()->custodian_email); | 478 session_controller.last_user_session()->custodian_email); |
| 459 } | 479 } |
| 480 | |
| 481 TEST_F(SessionControllerClientTest, UserPrefsChange) { | |
| 482 // Create an object to test and connect it to our test interface. | |
| 483 SessionControllerClient client; | |
| 484 TestSessionController session_controller; | |
| 485 client.session_controller_ = session_controller.CreateInterfacePtrAndBind(); | |
| 486 client.Init(); | |
| 487 SessionControllerClient::FlushForTesting(); | |
| 488 | |
| 489 // Simulate login. | |
| 490 const AccountId account_id(AccountId::FromUserEmail("user@test.com")); | |
| 491 const user_manager::User* user = user_manager()->AddUser(account_id); | |
| 492 session_manager_.CreateSession( | |
| 493 account_id, chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting( | |
| 494 "user@test.com")); | |
| 495 session_manager_.SetSessionState(SessionState::ACTIVE); | |
| 496 SessionControllerClient::FlushForTesting(); | |
| 497 | |
| 498 // Simulate the notification that the profile is ready. | |
| 499 TestingProfile* const user_profile = CreateTestingProfile(user); | |
| 500 client.OnLoginUserProfilePrepared(user_profile); | |
| 501 | |
| 502 // Manipulate user prefs and verify SessionController is updated. | |
| 503 PrefService* const user_prefs = user_profile->GetPrefs(); | |
| 504 | |
| 505 user_prefs->SetBoolean(prefs::kAllowScreenLock, true); | |
| 506 SessionControllerClient::FlushForTesting(); | |
| 507 EXPECT_TRUE(session_controller.last_session_info()->can_lock_screen); | |
| 508 user_prefs->SetBoolean(prefs::kAllowScreenLock, false); | |
| 509 SessionControllerClient::FlushForTesting(); | |
| 510 EXPECT_FALSE(session_controller.last_session_info()->can_lock_screen); | |
| 511 | |
| 512 user_prefs->SetBoolean(prefs::kEnableAutoScreenLock, true); | |
| 513 SessionControllerClient::FlushForTesting(); | |
| 514 EXPECT_TRUE( | |
| 515 session_controller.last_session_info()->should_lock_screen_automatically); | |
| 516 user_prefs->SetBoolean(prefs::kEnableAutoScreenLock, false); | |
| 517 SessionControllerClient::FlushForTesting(); | |
| 518 EXPECT_FALSE( | |
| 519 session_controller.last_session_info()->should_lock_screen_automatically); | |
| 520 } | |
| OLD | NEW |