Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 #include "content/public/test/test_browser_thread_bundle.h" | 34 #include "content/public/test/test_browser_thread_bundle.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 36 |
| 37 namespace policy { | 37 namespace policy { |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 const char kAffiliatedUserID1[] = "test_1@example.com"; | 41 const char kAffiliatedUserID1[] = "test_1@example.com"; |
| 42 const char kAffiliatedUserID2[] = "test_2@example.com"; | 42 const char kAffiliatedUserID2[] = "test_2@example.com"; |
| 43 const char kUnaffiliatedUserID[] = "test@other_domain.test"; | 43 const char kUnaffiliatedUserID[] = "test@other_domain.test"; |
| 44 const bool NOT_AFFILIATED = false; | |
| 45 const bool AFFILIATED = true; | |
|
oshima
2015/11/13 19:53:04
optional suggestion. Please ignore if you prefer t
peletskyi
2015/11/16 14:33:15
Done.
| |
| 44 | 46 |
| 45 scoped_ptr<KeyedService> BuildProfileInvalidationProvider( | 47 scoped_ptr<KeyedService> BuildProfileInvalidationProvider( |
| 46 content::BrowserContext* context) { | 48 content::BrowserContext* context) { |
| 47 scoped_ptr<invalidation::FakeInvalidationService> invalidation_service( | 49 scoped_ptr<invalidation::FakeInvalidationService> invalidation_service( |
| 48 new invalidation::FakeInvalidationService); | 50 new invalidation::FakeInvalidationService); |
| 49 invalidation_service->SetInvalidatorState( | 51 invalidation_service->SetInvalidatorState( |
| 50 syncer::TRANSIENT_INVALIDATION_ERROR); | 52 syncer::TRANSIENT_INVALIDATION_ERROR); |
| 51 return make_scoped_ptr(new invalidation::ProfileInvalidationProvider( | 53 return make_scoped_ptr(new invalidation::ProfileInvalidationProvider( |
| 52 invalidation_service.Pass())); | 54 invalidation_service.Pass())); |
| 53 } | 55 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 81 | 83 |
| 82 class AffiliatedInvalidationServiceProviderImplTest : public testing::Test { | 84 class AffiliatedInvalidationServiceProviderImplTest : public testing::Test { |
| 83 public: | 85 public: |
| 84 AffiliatedInvalidationServiceProviderImplTest(); | 86 AffiliatedInvalidationServiceProviderImplTest(); |
| 85 | 87 |
| 86 // testing::Test: | 88 // testing::Test: |
| 87 void SetUp() override; | 89 void SetUp() override; |
| 88 void TearDown() override; | 90 void TearDown() override; |
| 89 | 91 |
| 90 // Ownership is not passed. The Profile is owned by the global ProfileManager. | 92 // Ownership is not passed. The Profile is owned by the global ProfileManager. |
| 91 Profile* LogInAndReturnProfile(const std::string& user_id); | 93 Profile* LogInAndReturnProfile(const std::string& user_id, |
| 94 bool is_affiliated); | |
| 92 | 95 |
| 93 // Logs in as an affiliated user and indicates that the per-profile | 96 // Logs in as an affiliated user and indicates that the per-profile |
| 94 // invalidation service for this user connected. Verifies that this | 97 // invalidation service for this user connected. Verifies that this |
| 95 // invalidation service is made available to the |consumer_| and the | 98 // invalidation service is made available to the |consumer_| and the |
| 96 // device-global invalidation service is destroyed. | 99 // device-global invalidation service is destroyed. |
| 97 void LogInAsAffiliatedUserAndConnectInvalidationService(); | 100 void LogInAsAffiliatedUserAndConnectInvalidationService(); |
| 98 | 101 |
| 99 // Logs in as an unaffiliated user and indicates that the per-profile | 102 // Logs in as an unaffiliated user and indicates that the per-profile |
| 100 // invalidation service for this user connected. Verifies that this | 103 // invalidation service for this user connected. Verifies that this |
| 101 // invalidation service is ignored and the device-global invalidation service | 104 // invalidation service is ignored and the device-global invalidation service |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 provider_.reset(); | 217 provider_.reset(); |
| 215 | 218 |
| 216 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> | 219 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
| 217 RegisterTestingFactory(nullptr); | 220 RegisterTestingFactory(nullptr); |
| 218 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); | 221 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); |
| 219 chromeos::DBusThreadManager::Shutdown(); | 222 chromeos::DBusThreadManager::Shutdown(); |
| 220 chromeos::SystemSaltGetter::Shutdown(); | 223 chromeos::SystemSaltGetter::Shutdown(); |
| 221 } | 224 } |
| 222 | 225 |
| 223 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile( | 226 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile( |
| 224 const std::string& user_id) { | 227 const std::string& user_id, |
| 225 fake_user_manager_->AddUser(AccountId::FromUserEmail(user_id)); | 228 bool is_affiliated) { |
| 229 fake_user_manager_->AddUserWithAffiliation(AccountId::FromUserEmail(user_id), | |
| 230 is_affiliated); | |
| 226 Profile* profile = profile_manager_.CreateTestingProfile(user_id); | 231 Profile* profile = profile_manager_.CreateTestingProfile(user_id); |
| 227 content::NotificationService::current()->Notify( | 232 content::NotificationService::current()->Notify( |
| 228 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 233 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 229 content::NotificationService::AllSources(), | 234 content::NotificationService::AllSources(), |
| 230 content::Details<Profile>(profile)); | 235 content::Details<Profile>(profile)); |
| 231 return profile; | 236 return profile; |
| 232 } | 237 } |
| 233 | 238 |
| 234 void AffiliatedInvalidationServiceProviderImplTest:: | 239 void AffiliatedInvalidationServiceProviderImplTest:: |
| 235 LogInAsAffiliatedUserAndConnectInvalidationService() { | 240 LogInAsAffiliatedUserAndConnectInvalidationService() { |
| 236 // Log in as an affiliated user. | 241 // Log in as an affiliated user. |
| 237 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); | 242 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1, AFFILIATED); |
| 238 EXPECT_TRUE(profile); | 243 EXPECT_TRUE(profile); |
| 239 | 244 |
| 240 // Verify that a per-profile invalidation service has been created. | 245 // Verify that a per-profile invalidation service has been created. |
| 241 profile_invalidation_service_ = | 246 profile_invalidation_service_ = |
| 242 GetProfileInvalidationService(profile, false /* create */); | 247 GetProfileInvalidationService(profile, false /* create */); |
| 243 ASSERT_TRUE(profile_invalidation_service_); | 248 ASSERT_TRUE(profile_invalidation_service_); |
| 244 | 249 |
| 245 // Verify that the device-global invalidation service still exists. | 250 // Verify that the device-global invalidation service still exists. |
| 246 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 251 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
| 247 | 252 |
| 248 // Indicate that the per-profile invalidation service has connected. Verify | 253 // Indicate that the per-profile invalidation service has connected. Verify |
| 249 // that the consumer is informed about this. | 254 // that the consumer is informed about this. |
| 250 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 255 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 251 profile_invalidation_service_->SetInvalidatorState( | 256 profile_invalidation_service_->SetInvalidatorState( |
| 252 syncer::INVALIDATIONS_ENABLED); | 257 syncer::INVALIDATIONS_ENABLED); |
| 253 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 258 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 254 EXPECT_EQ(profile_invalidation_service_, consumer_->GetInvalidationService()); | 259 EXPECT_EQ(profile_invalidation_service_, consumer_->GetInvalidationService()); |
| 255 | 260 |
| 256 // Verify that the device-global invalidation service has been destroyed. | 261 // Verify that the device-global invalidation service has been destroyed. |
| 257 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 262 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 258 } | 263 } |
| 259 | 264 |
| 260 void AffiliatedInvalidationServiceProviderImplTest:: | 265 void AffiliatedInvalidationServiceProviderImplTest:: |
| 261 LogInAsUnaffiliatedUserAndConnectInvalidationService() { | 266 LogInAsUnaffiliatedUserAndConnectInvalidationService() { |
| 262 // Log in as an unaffiliated user. | 267 // Log in as an unaffiliated user. |
| 263 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); | 268 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID, NOT_AFFILIATED); |
| 264 EXPECT_TRUE(profile); | 269 EXPECT_TRUE(profile); |
| 265 | 270 |
| 266 // Verify that a per-profile invalidation service has been created. | 271 // Verify that a per-profile invalidation service has been created. |
| 267 profile_invalidation_service_ = | 272 profile_invalidation_service_ = |
| 268 GetProfileInvalidationService(profile, false /* create */); | 273 GetProfileInvalidationService(profile, false /* create */); |
| 269 ASSERT_TRUE(profile_invalidation_service_); | 274 ASSERT_TRUE(profile_invalidation_service_); |
| 270 | 275 |
| 271 // Verify that the device-global invalidation service still exists. | 276 // Verify that the device-global invalidation service still exists. |
| 272 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 277 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
| 273 | 278 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 | 333 |
| 329 // No consumers are registered with the | 334 // No consumers are registered with the |
| 330 // AffiliatedInvalidationServiceProviderImpl. Verifies that no device-global | 335 // AffiliatedInvalidationServiceProviderImpl. Verifies that no device-global |
| 331 // invalidation service is created, whether an affiliated user is logged in or | 336 // invalidation service is created, whether an affiliated user is logged in or |
| 332 // not. | 337 // not. |
| 333 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoConsumers) { | 338 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoConsumers) { |
| 334 // Verify that no device-global invalidation service has been created. | 339 // Verify that no device-global invalidation service has been created. |
| 335 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 340 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 336 | 341 |
| 337 // Log in as an affiliated user. | 342 // Log in as an affiliated user. |
| 338 EXPECT_TRUE(LogInAndReturnProfile(kAffiliatedUserID1)); | 343 EXPECT_TRUE(LogInAndReturnProfile(kAffiliatedUserID1, AFFILIATED)); |
| 339 | 344 |
| 340 // Verify that no device-global invalidation service has been created. | 345 // Verify that no device-global invalidation service has been created. |
| 341 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 346 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 342 } | 347 } |
| 343 | 348 |
| 344 // Verifies that when no connected invalidation service is available for use, | 349 // Verifies that when no connected invalidation service is available for use, |
| 345 // none is made available to consumers. | 350 // none is made available to consumers. |
| 346 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 351 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
| 347 NoInvalidationServiceAvailable) { | 352 NoInvalidationServiceAvailable) { |
| 348 // Register a consumer. Verify that the consumer is not called back | 353 // 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. | 504 // Verify that a device-global invalidation service has been created. |
| 500 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 505 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
| 501 | 506 |
| 502 // Log in as a first affiliated user and indicate that the per-profile | 507 // Log in as a first affiliated user and indicate that the per-profile |
| 503 // invalidation service for this user connected. Verify that this invalidation | 508 // invalidation service for this user connected. Verify that this invalidation |
| 504 // service is made available to the |consumer_| and the device-global | 509 // service is made available to the |consumer_| and the device-global |
| 505 // invalidation service is destroyed. | 510 // invalidation service is destroyed. |
| 506 LogInAsAffiliatedUserAndConnectInvalidationService(); | 511 LogInAsAffiliatedUserAndConnectInvalidationService(); |
| 507 | 512 |
| 508 // Log in as a second affiliated user. | 513 // Log in as a second affiliated user. |
| 509 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); | 514 Profile* second_profile = |
| 515 LogInAndReturnProfile(kAffiliatedUserID2, AFFILIATED); | |
| 510 EXPECT_TRUE(second_profile); | 516 EXPECT_TRUE(second_profile); |
| 511 | 517 |
| 512 // Verify that the device-global invalidation service still does not exist. | 518 // Verify that the device-global invalidation service still does not exist. |
| 513 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 519 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 514 | 520 |
| 515 // Verify that a per-profile invalidation service for the second user has been | 521 // Verify that a per-profile invalidation service for the second user has been |
| 516 // created. | 522 // created. |
| 517 invalidation::FakeInvalidationService* second_profile_invalidation_service = | 523 invalidation::FakeInvalidationService* second_profile_invalidation_service = |
| 518 GetProfileInvalidationService(second_profile, false /* create */); | 524 GetProfileInvalidationService(second_profile, false /* create */); |
| 519 ASSERT_TRUE(second_profile_invalidation_service); | 525 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. | 604 // invalidation service is available for use anymore. |
| 599 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 605 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 600 provider_->Shutdown(); | 606 provider_->Shutdown(); |
| 601 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 607 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 602 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | 608 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); |
| 603 | 609 |
| 604 // Verify that the device-global invalidation service still does not exist. | 610 // Verify that the device-global invalidation service still does not exist. |
| 605 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 611 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 606 | 612 |
| 607 // Log in as a second affiliated user. | 613 // Log in as a second affiliated user. |
| 608 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); | 614 Profile* second_profile = |
| 615 LogInAndReturnProfile(kAffiliatedUserID2, AFFILIATED); | |
| 609 EXPECT_TRUE(second_profile); | 616 EXPECT_TRUE(second_profile); |
| 610 | 617 |
| 611 // Verify that the device-global invalidation service still does not exist. | 618 // Verify that the device-global invalidation service still does not exist. |
| 612 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 619 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 613 | 620 |
| 614 // Create a per-profile invalidation service for the second user. | 621 // Create a per-profile invalidation service for the second user. |
| 615 invalidation::FakeInvalidationService* second_profile_invalidation_service = | 622 invalidation::FakeInvalidationService* second_profile_invalidation_service = |
| 616 GetProfileInvalidationService(second_profile, true /* create */); | 623 GetProfileInvalidationService(second_profile, true /* create */); |
| 617 ASSERT_TRUE(second_profile_invalidation_service); | 624 ASSERT_TRUE(second_profile_invalidation_service); |
| 618 | 625 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 659 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 653 provider_->Shutdown(); | 660 provider_->Shutdown(); |
| 654 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 661 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 655 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | 662 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); |
| 656 | 663 |
| 657 // Verify that the device-global invalidation service has been destroyed. | 664 // Verify that the device-global invalidation service has been destroyed. |
| 658 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 665 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 659 } | 666 } |
| 660 | 667 |
| 661 } // namespace policy | 668 } // namespace policy |
| OLD | NEW |