| 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/affiliated_invalidation_service_provide
r_impl.h" | 5 #include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provide
r_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 class AffiliatedInvalidationServiceProviderImplTest : public testing::Test { | 82 class AffiliatedInvalidationServiceProviderImplTest : public testing::Test { |
| 83 public: | 83 public: |
| 84 AffiliatedInvalidationServiceProviderImplTest(); | 84 AffiliatedInvalidationServiceProviderImplTest(); |
| 85 | 85 |
| 86 // testing::Test: | 86 // testing::Test: |
| 87 void SetUp() override; | 87 void SetUp() override; |
| 88 void TearDown() override; | 88 void TearDown() override; |
| 89 | 89 |
| 90 // Ownership is not passed. The Profile is owned by the global ProfileManager. | 90 // Both functions don't pass ownership of the profile. The Profile is owned |
| 91 Profile* LogInAndReturnProfile(const std::string& user_id); | 91 // by the global ProfileManager. |
| 92 Profile* LogInAndReturnAffiliatedProfile(const std::string& user_id); |
| 93 Profile* LogInAndReturnNonAffiliatedProfile(const std::string& user_id); |
| 92 | 94 |
| 93 // Logs in as an affiliated user and indicates that the per-profile | 95 // Logs in as an affiliated user and indicates that the per-profile |
| 94 // invalidation service for this user connected. Verifies that this | 96 // invalidation service for this user connected. Verifies that this |
| 95 // invalidation service is made available to the |consumer_| and the | 97 // invalidation service is made available to the |consumer_| and the |
| 96 // device-global invalidation service is destroyed. | 98 // device-global invalidation service is destroyed. |
| 97 void LogInAsAffiliatedUserAndConnectInvalidationService(); | 99 void LogInAsAffiliatedUserAndConnectInvalidationService(); |
| 98 | 100 |
| 99 // Logs in as an unaffiliated user and indicates that the per-profile | 101 // Logs in as an unaffiliated user and indicates that the per-profile |
| 100 // invalidation service for this user connected. Verifies that this | 102 // invalidation service for this user connected. Verifies that this |
| 101 // invalidation service is ignored and the device-global invalidation service | 103 // invalidation service is ignored and the device-global invalidation service |
| 102 // is not destroyed. | 104 // is not destroyed. |
| 103 void LogInAsUnaffiliatedUserAndConnectInvalidationService(); | 105 void LogInAsUnaffiliatedUserAndConnectInvalidationService(); |
| 104 | 106 |
| 105 // Indicates that the device-global invalidation service connected. Verifies | 107 // Indicates that the device-global invalidation service connected. Verifies |
| 106 // that the |consumer_| is informed about this. | 108 // that the |consumer_| is informed about this. |
| 107 void ConnectDeviceGlobalInvalidationService(); | 109 void ConnectDeviceGlobalInvalidationService(); |
| 108 | 110 |
| 109 // Indicates that the logged-in user's per-profile invalidation service | 111 // Indicates that the logged-in user's per-profile invalidation service |
| 110 // disconnected. Verifies that the |consumer_| is informed about this and a | 112 // disconnected. Verifies that the |consumer_| is informed about this and a |
| 111 // device-global invalidation service is created. | 113 // device-global invalidation service is created. |
| 112 void DisconnectPerProfileInvalidationService(); | 114 void DisconnectPerProfileInvalidationService(); |
| 113 | 115 |
| 114 invalidation::FakeInvalidationService* GetProfileInvalidationService( | 116 invalidation::FakeInvalidationService* GetProfileInvalidationService( |
| 115 Profile* profile, | 117 Profile* profile, |
| 116 bool create); | 118 bool create); |
| 117 | 119 |
| 118 protected: | 120 protected: |
| 121 // Ownership is not passed. The Profile is owned by the global ProfileManager. |
| 122 Profile* LogInAndReturnProfile(const std::string& user_id, |
| 123 bool is_affiliated); |
| 119 scoped_ptr<AffiliatedInvalidationServiceProviderImpl> provider_; | 124 scoped_ptr<AffiliatedInvalidationServiceProviderImpl> provider_; |
| 120 scoped_ptr<FakeConsumer> consumer_; | 125 scoped_ptr<FakeConsumer> consumer_; |
| 121 invalidation::TiclInvalidationService* device_invalidation_service_; | 126 invalidation::TiclInvalidationService* device_invalidation_service_; |
| 122 invalidation::FakeInvalidationService* profile_invalidation_service_; | 127 invalidation::FakeInvalidationService* profile_invalidation_service_; |
| 123 | 128 |
| 124 private: | 129 private: |
| 125 content::TestBrowserThreadBundle thread_bundle_; | 130 content::TestBrowserThreadBundle thread_bundle_; |
| 126 chromeos::FakeChromeUserManager* fake_user_manager_; | 131 chromeos::FakeChromeUserManager* fake_user_manager_; |
| 127 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 132 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 128 ScopedStubEnterpriseInstallAttributes install_attributes_; | 133 ScopedStubEnterpriseInstallAttributes install_attributes_; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 provider_->Shutdown(); | 218 provider_->Shutdown(); |
| 214 provider_.reset(); | 219 provider_.reset(); |
| 215 | 220 |
| 216 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> | 221 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
| 217 RegisterTestingFactory(nullptr); | 222 RegisterTestingFactory(nullptr); |
| 218 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); | 223 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); |
| 219 chromeos::DBusThreadManager::Shutdown(); | 224 chromeos::DBusThreadManager::Shutdown(); |
| 220 chromeos::SystemSaltGetter::Shutdown(); | 225 chromeos::SystemSaltGetter::Shutdown(); |
| 221 } | 226 } |
| 222 | 227 |
| 228 Profile* |
| 229 AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnAffiliatedProfile( |
| 230 const std::string& user_id) { |
| 231 return LogInAndReturnProfile(user_id, true); |
| 232 } |
| 233 |
| 234 Profile* AffiliatedInvalidationServiceProviderImplTest:: |
| 235 LogInAndReturnNonAffiliatedProfile(const std::string& user_id) { |
| 236 return LogInAndReturnProfile(user_id, false); |
| 237 } |
| 238 |
| 223 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile( | 239 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile( |
| 224 const std::string& user_id) { | 240 const std::string& user_id, |
| 225 fake_user_manager_->AddUser(AccountId::FromUserEmail(user_id)); | 241 bool is_affiliated) { |
| 242 fake_user_manager_->AddUserWithAffiliation(AccountId::FromUserEmail(user_id), |
| 243 is_affiliated); |
| 226 Profile* profile = profile_manager_.CreateTestingProfile(user_id); | 244 Profile* profile = profile_manager_.CreateTestingProfile(user_id); |
| 227 content::NotificationService::current()->Notify( | 245 content::NotificationService::current()->Notify( |
| 228 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 246 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 229 content::NotificationService::AllSources(), | 247 content::NotificationService::AllSources(), |
| 230 content::Details<Profile>(profile)); | 248 content::Details<Profile>(profile)); |
| 231 return profile; | 249 return profile; |
| 232 } | 250 } |
| 233 | 251 |
| 234 void AffiliatedInvalidationServiceProviderImplTest:: | 252 void AffiliatedInvalidationServiceProviderImplTest:: |
| 235 LogInAsAffiliatedUserAndConnectInvalidationService() { | 253 LogInAsAffiliatedUserAndConnectInvalidationService() { |
| 236 // Log in as an affiliated user. | 254 // Log in as an affiliated user. |
| 237 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); | 255 Profile* profile = LogInAndReturnAffiliatedProfile(kAffiliatedUserID1); |
| 238 EXPECT_TRUE(profile); | 256 EXPECT_TRUE(profile); |
| 239 | 257 |
| 240 // Verify that a per-profile invalidation service has been created. | 258 // Verify that a per-profile invalidation service has been created. |
| 241 profile_invalidation_service_ = | 259 profile_invalidation_service_ = |
| 242 GetProfileInvalidationService(profile, false /* create */); | 260 GetProfileInvalidationService(profile, false /* create */); |
| 243 ASSERT_TRUE(profile_invalidation_service_); | 261 ASSERT_TRUE(profile_invalidation_service_); |
| 244 | 262 |
| 245 // Verify that the device-global invalidation service still exists. | 263 // Verify that the device-global invalidation service still exists. |
| 246 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 264 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
| 247 | 265 |
| 248 // Indicate that the per-profile invalidation service has connected. Verify | 266 // Indicate that the per-profile invalidation service has connected. Verify |
| 249 // that the consumer is informed about this. | 267 // that the consumer is informed about this. |
| 250 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 268 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 251 profile_invalidation_service_->SetInvalidatorState( | 269 profile_invalidation_service_->SetInvalidatorState( |
| 252 syncer::INVALIDATIONS_ENABLED); | 270 syncer::INVALIDATIONS_ENABLED); |
| 253 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 271 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 254 EXPECT_EQ(profile_invalidation_service_, consumer_->GetInvalidationService()); | 272 EXPECT_EQ(profile_invalidation_service_, consumer_->GetInvalidationService()); |
| 255 | 273 |
| 256 // Verify that the device-global invalidation service has been destroyed. | 274 // Verify that the device-global invalidation service has been destroyed. |
| 257 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 275 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 258 } | 276 } |
| 259 | 277 |
| 260 void AffiliatedInvalidationServiceProviderImplTest:: | 278 void AffiliatedInvalidationServiceProviderImplTest:: |
| 261 LogInAsUnaffiliatedUserAndConnectInvalidationService() { | 279 LogInAsUnaffiliatedUserAndConnectInvalidationService() { |
| 262 // Log in as an unaffiliated user. | 280 // Log in as an unaffiliated user. |
| 263 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); | 281 Profile* profile = LogInAndReturnNonAffiliatedProfile(kUnaffiliatedUserID); |
| 264 EXPECT_TRUE(profile); | 282 EXPECT_TRUE(profile); |
| 265 | 283 |
| 266 // Verify that a per-profile invalidation service has been created. | 284 // Verify that a per-profile invalidation service has been created. |
| 267 profile_invalidation_service_ = | 285 profile_invalidation_service_ = |
| 268 GetProfileInvalidationService(profile, false /* create */); | 286 GetProfileInvalidationService(profile, false /* create */); |
| 269 ASSERT_TRUE(profile_invalidation_service_); | 287 ASSERT_TRUE(profile_invalidation_service_); |
| 270 | 288 |
| 271 // Verify that the device-global invalidation service still exists. | 289 // Verify that the device-global invalidation service still exists. |
| 272 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 290 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
| 273 | 291 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 346 |
| 329 // No consumers are registered with the | 347 // No consumers are registered with the |
| 330 // AffiliatedInvalidationServiceProviderImpl. Verifies that no device-global | 348 // AffiliatedInvalidationServiceProviderImpl. Verifies that no device-global |
| 331 // invalidation service is created, whether an affiliated user is logged in or | 349 // invalidation service is created, whether an affiliated user is logged in or |
| 332 // not. | 350 // not. |
| 333 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoConsumers) { | 351 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoConsumers) { |
| 334 // Verify that no device-global invalidation service has been created. | 352 // Verify that no device-global invalidation service has been created. |
| 335 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 353 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 336 | 354 |
| 337 // Log in as an affiliated user. | 355 // Log in as an affiliated user. |
| 338 EXPECT_TRUE(LogInAndReturnProfile(kAffiliatedUserID1)); | 356 EXPECT_TRUE(LogInAndReturnAffiliatedProfile(kAffiliatedUserID1)); |
| 339 | 357 |
| 340 // Verify that no device-global invalidation service has been created. | 358 // Verify that no device-global invalidation service has been created. |
| 341 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 359 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 342 } | 360 } |
| 343 | 361 |
| 344 // Verifies that when no connected invalidation service is available for use, | 362 // Verifies that when no connected invalidation service is available for use, |
| 345 // none is made available to consumers. | 363 // none is made available to consumers. |
| 346 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 364 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
| 347 NoInvalidationServiceAvailable) { | 365 NoInvalidationServiceAvailable) { |
| 348 // Register a consumer. Verify that the consumer is not called back | 366 // Register a consumer. Verify that the consumer is not called back |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 // Verify that a device-global invalidation service has been created. | 517 // Verify that a device-global invalidation service has been created. |
| 500 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 518 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
| 501 | 519 |
| 502 // Log in as a first affiliated user and indicate that the per-profile | 520 // Log in as a first affiliated user and indicate that the per-profile |
| 503 // invalidation service for this user connected. Verify that this invalidation | 521 // invalidation service for this user connected. Verify that this invalidation |
| 504 // service is made available to the |consumer_| and the device-global | 522 // service is made available to the |consumer_| and the device-global |
| 505 // invalidation service is destroyed. | 523 // invalidation service is destroyed. |
| 506 LogInAsAffiliatedUserAndConnectInvalidationService(); | 524 LogInAsAffiliatedUserAndConnectInvalidationService(); |
| 507 | 525 |
| 508 // Log in as a second affiliated user. | 526 // Log in as a second affiliated user. |
| 509 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); | 527 Profile* second_profile = LogInAndReturnAffiliatedProfile(kAffiliatedUserID2); |
| 510 EXPECT_TRUE(second_profile); | 528 EXPECT_TRUE(second_profile); |
| 511 | 529 |
| 512 // Verify that the device-global invalidation service still does not exist. | 530 // Verify that the device-global invalidation service still does not exist. |
| 513 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 531 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 514 | 532 |
| 515 // Verify that a per-profile invalidation service for the second user has been | 533 // Verify that a per-profile invalidation service for the second user has been |
| 516 // created. | 534 // created. |
| 517 invalidation::FakeInvalidationService* second_profile_invalidation_service = | 535 invalidation::FakeInvalidationService* second_profile_invalidation_service = |
| 518 GetProfileInvalidationService(second_profile, false /* create */); | 536 GetProfileInvalidationService(second_profile, false /* create */); |
| 519 ASSERT_TRUE(second_profile_invalidation_service); | 537 ASSERT_TRUE(second_profile_invalidation_service); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 // invalidation service is available for use anymore. | 616 // invalidation service is available for use anymore. |
| 599 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 617 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 600 provider_->Shutdown(); | 618 provider_->Shutdown(); |
| 601 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 619 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 602 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | 620 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); |
| 603 | 621 |
| 604 // Verify that the device-global invalidation service still does not exist. | 622 // Verify that the device-global invalidation service still does not exist. |
| 605 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 623 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 606 | 624 |
| 607 // Log in as a second affiliated user. | 625 // Log in as a second affiliated user. |
| 608 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); | 626 Profile* second_profile = LogInAndReturnAffiliatedProfile(kAffiliatedUserID2); |
| 609 EXPECT_TRUE(second_profile); | 627 EXPECT_TRUE(second_profile); |
| 610 | 628 |
| 611 // Verify that the device-global invalidation service still does not exist. | 629 // Verify that the device-global invalidation service still does not exist. |
| 612 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 630 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 613 | 631 |
| 614 // Create a per-profile invalidation service for the second user. | 632 // Create a per-profile invalidation service for the second user. |
| 615 invalidation::FakeInvalidationService* second_profile_invalidation_service = | 633 invalidation::FakeInvalidationService* second_profile_invalidation_service = |
| 616 GetProfileInvalidationService(second_profile, true /* create */); | 634 GetProfileInvalidationService(second_profile, true /* create */); |
| 617 ASSERT_TRUE(second_profile_invalidation_service); | 635 ASSERT_TRUE(second_profile_invalidation_service); |
| 618 | 636 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 670 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 653 provider_->Shutdown(); | 671 provider_->Shutdown(); |
| 654 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 672 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 655 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | 673 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); |
| 656 | 674 |
| 657 // Verify that the device-global invalidation service has been destroyed. | 675 // Verify that the device-global invalidation service has been destroyed. |
| 658 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 676 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 659 } | 677 } |
| 660 | 678 |
| 661 } // namespace policy | 679 } // namespace policy |
| OLD | NEW |