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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Ownership is not passed. The Profile is owned by the global ProfileManager. |
91 Profile* LogInAndReturnProfile(const std::string& user_id); | 91 Profile* LogInAndReturnProfile(const std::string& user_id, |
92 bool is_affiliated); | |
92 | 93 |
93 // Logs in as an affiliated user and indicates that the per-profile | 94 // Logs in as an affiliated user and indicates that the per-profile |
94 // invalidation service for this user connected. Verifies that this | 95 // invalidation service for this user connected. Verifies that this |
95 // invalidation service is made available to the |consumer_| and the | 96 // invalidation service is made available to the |consumer_| and the |
96 // device-global invalidation service is destroyed. | 97 // device-global invalidation service is destroyed. |
97 void LogInAsAffiliatedUserAndConnectInvalidationService(); | 98 void LogInAsAffiliatedUserAndConnectInvalidationService(); |
98 | 99 |
99 // Logs in as an unaffiliated user and indicates that the per-profile | 100 // Logs in as an unaffiliated user and indicates that the per-profile |
100 // invalidation service for this user connected. Verifies that this | 101 // invalidation service for this user connected. Verifies that this |
101 // invalidation service is ignored and the device-global invalidation service | 102 // 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(); | 215 provider_.reset(); |
215 | 216 |
216 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> | 217 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
217 RegisterTestingFactory(nullptr); | 218 RegisterTestingFactory(nullptr); |
218 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); | 219 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); |
219 chromeos::DBusThreadManager::Shutdown(); | 220 chromeos::DBusThreadManager::Shutdown(); |
220 chromeos::SystemSaltGetter::Shutdown(); | 221 chromeos::SystemSaltGetter::Shutdown(); |
221 } | 222 } |
222 | 223 |
223 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile( | 224 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile( |
224 const std::string& user_id) { | 225 const std::string& user_id, |
225 fake_user_manager_->AddUser(user_id); | 226 bool is_affiliated) { |
227 fake_user_manager_->AddUserWithAffiliation(user_id, is_affiliated); | |
226 Profile* profile = profile_manager_.CreateTestingProfile(user_id); | 228 Profile* profile = profile_manager_.CreateTestingProfile(user_id); |
227 content::NotificationService::current()->Notify( | 229 content::NotificationService::current()->Notify( |
228 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 230 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
229 content::NotificationService::AllSources(), | 231 content::NotificationService::AllSources(), |
230 content::Details<Profile>(profile)); | 232 content::Details<Profile>(profile)); |
231 return profile; | 233 return profile; |
232 } | 234 } |
233 | 235 |
234 void AffiliatedInvalidationServiceProviderImplTest:: | 236 void AffiliatedInvalidationServiceProviderImplTest:: |
235 LogInAsAffiliatedUserAndConnectInvalidationService() { | 237 LogInAsAffiliatedUserAndConnectInvalidationService() { |
236 // Log in as an affiliated user. | 238 // Log in as an affiliated user. |
237 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); | 239 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1, true); |
Andrew T Wilson (Slow)
2015/10/09 12:35:46
this is fine, but consider defining a constant:
c
peletskyi
2015/10/29 15:27:36
Done.
| |
238 EXPECT_TRUE(profile); | 240 EXPECT_TRUE(profile); |
239 | 241 |
240 // Verify that a per-profile invalidation service has been created. | 242 // Verify that a per-profile invalidation service has been created. |
241 profile_invalidation_service_ = | 243 profile_invalidation_service_ = |
242 GetProfileInvalidationService(profile, false /* create */); | 244 GetProfileInvalidationService(profile, false /* create */); |
243 ASSERT_TRUE(profile_invalidation_service_); | 245 ASSERT_TRUE(profile_invalidation_service_); |
244 | 246 |
245 // Verify that the device-global invalidation service still exists. | 247 // Verify that the device-global invalidation service still exists. |
246 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 248 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
247 | 249 |
248 // Indicate that the per-profile invalidation service has connected. Verify | 250 // Indicate that the per-profile invalidation service has connected. Verify |
249 // that the consumer is informed about this. | 251 // that the consumer is informed about this. |
250 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 252 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
251 profile_invalidation_service_->SetInvalidatorState( | 253 profile_invalidation_service_->SetInvalidatorState( |
252 syncer::INVALIDATIONS_ENABLED); | 254 syncer::INVALIDATIONS_ENABLED); |
253 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 255 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
254 EXPECT_EQ(profile_invalidation_service_, consumer_->GetInvalidationService()); | 256 EXPECT_EQ(profile_invalidation_service_, consumer_->GetInvalidationService()); |
255 | 257 |
256 // Verify that the device-global invalidation service has been destroyed. | 258 // Verify that the device-global invalidation service has been destroyed. |
257 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 259 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
258 } | 260 } |
259 | 261 |
260 void AffiliatedInvalidationServiceProviderImplTest:: | 262 void AffiliatedInvalidationServiceProviderImplTest:: |
261 LogInAsUnaffiliatedUserAndConnectInvalidationService() { | 263 LogInAsUnaffiliatedUserAndConnectInvalidationService() { |
262 // Log in as an unaffiliated user. | 264 // Log in as an unaffiliated user. |
263 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); | 265 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID, false); |
264 EXPECT_TRUE(profile); | 266 EXPECT_TRUE(profile); |
265 | 267 |
266 // Verify that a per-profile invalidation service has been created. | 268 // Verify that a per-profile invalidation service has been created. |
267 profile_invalidation_service_ = | 269 profile_invalidation_service_ = |
268 GetProfileInvalidationService(profile, false /* create */); | 270 GetProfileInvalidationService(profile, false /* create */); |
269 ASSERT_TRUE(profile_invalidation_service_); | 271 ASSERT_TRUE(profile_invalidation_service_); |
270 | 272 |
271 // Verify that the device-global invalidation service still exists. | 273 // Verify that the device-global invalidation service still exists. |
272 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 274 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
273 | 275 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 | 330 |
329 // No consumers are registered with the | 331 // No consumers are registered with the |
330 // AffiliatedInvalidationServiceProviderImpl. Verifies that no device-global | 332 // AffiliatedInvalidationServiceProviderImpl. Verifies that no device-global |
331 // invalidation service is created, whether an affiliated user is logged in or | 333 // invalidation service is created, whether an affiliated user is logged in or |
332 // not. | 334 // not. |
333 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoConsumers) { | 335 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoConsumers) { |
334 // Verify that no device-global invalidation service has been created. | 336 // Verify that no device-global invalidation service has been created. |
335 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 337 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
336 | 338 |
337 // Log in as an affiliated user. | 339 // Log in as an affiliated user. |
338 EXPECT_TRUE(LogInAndReturnProfile(kAffiliatedUserID1)); | 340 EXPECT_TRUE(LogInAndReturnProfile(kAffiliatedUserID1, true)); |
339 | 341 |
340 // Verify that no device-global invalidation service has been created. | 342 // Verify that no device-global invalidation service has been created. |
341 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 343 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
342 } | 344 } |
343 | 345 |
344 // Verifies that when no connected invalidation service is available for use, | 346 // Verifies that when no connected invalidation service is available for use, |
345 // none is made available to consumers. | 347 // none is made available to consumers. |
346 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 348 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
347 NoInvalidationServiceAvailable) { | 349 NoInvalidationServiceAvailable) { |
348 // Register a consumer. Verify that the consumer is not called back | 350 // 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. | 501 // Verify that a device-global invalidation service has been created. |
500 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 502 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
501 | 503 |
502 // Log in as a first affiliated user and indicate that the per-profile | 504 // Log in as a first affiliated user and indicate that the per-profile |
503 // invalidation service for this user connected. Verify that this invalidation | 505 // invalidation service for this user connected. Verify that this invalidation |
504 // service is made available to the |consumer_| and the device-global | 506 // service is made available to the |consumer_| and the device-global |
505 // invalidation service is destroyed. | 507 // invalidation service is destroyed. |
506 LogInAsAffiliatedUserAndConnectInvalidationService(); | 508 LogInAsAffiliatedUserAndConnectInvalidationService(); |
507 | 509 |
508 // Log in as a second affiliated user. | 510 // Log in as a second affiliated user. |
509 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); | 511 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2, true); |
510 EXPECT_TRUE(second_profile); | 512 EXPECT_TRUE(second_profile); |
511 | 513 |
512 // Verify that the device-global invalidation service still does not exist. | 514 // Verify that the device-global invalidation service still does not exist. |
513 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 515 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
514 | 516 |
515 // Verify that a per-profile invalidation service for the second user has been | 517 // Verify that a per-profile invalidation service for the second user has been |
516 // created. | 518 // created. |
517 invalidation::FakeInvalidationService* second_profile_invalidation_service = | 519 invalidation::FakeInvalidationService* second_profile_invalidation_service = |
518 GetProfileInvalidationService(second_profile, false /* create */); | 520 GetProfileInvalidationService(second_profile, false /* create */); |
519 ASSERT_TRUE(second_profile_invalidation_service); | 521 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. | 600 // invalidation service is available for use anymore. |
599 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 601 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
600 provider_->Shutdown(); | 602 provider_->Shutdown(); |
601 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 603 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
602 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | 604 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); |
603 | 605 |
604 // Verify that the device-global invalidation service still does not exist. | 606 // Verify that the device-global invalidation service still does not exist. |
605 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 607 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
606 | 608 |
607 // Log in as a second affiliated user. | 609 // Log in as a second affiliated user. |
608 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); | 610 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2, true); |
609 EXPECT_TRUE(second_profile); | 611 EXPECT_TRUE(second_profile); |
610 | 612 |
611 // Verify that the device-global invalidation service still does not exist. | 613 // Verify that the device-global invalidation service still does not exist. |
612 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 614 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
613 | 615 |
614 // Create a per-profile invalidation service for the second user. | 616 // Create a per-profile invalidation service for the second user. |
615 invalidation::FakeInvalidationService* second_profile_invalidation_service = | 617 invalidation::FakeInvalidationService* second_profile_invalidation_service = |
616 GetProfileInvalidationService(second_profile, true /* create */); | 618 GetProfileInvalidationService(second_profile, true /* create */); |
617 ASSERT_TRUE(second_profile_invalidation_service); | 619 ASSERT_TRUE(second_profile_invalidation_service); |
618 | 620 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 654 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
653 provider_->Shutdown(); | 655 provider_->Shutdown(); |
654 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 656 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
655 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | 657 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); |
656 | 658 |
657 // Verify that the device-global invalidation service has been destroyed. | 659 // Verify that the device-global invalidation service has been destroyed. |
658 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 660 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
659 } | 661 } |
660 | 662 |
661 } // namespace policy | 663 } // namespace policy |
OLD | NEW |