| 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 <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 14 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 15 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" | 16 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
| 18 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 19 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 19 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 20 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 39 |
| 39 namespace policy { | 40 namespace policy { |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 const char kAffiliatedUserID1[] = "test_1@example.com"; | 44 const char kAffiliatedUserID1[] = "test_1@example.com"; |
| 44 const char kAffiliatedUserID2[] = "test_2@example.com"; | 45 const char kAffiliatedUserID2[] = "test_2@example.com"; |
| 45 const char kUnaffiliatedUserID[] = "test@other_domain.test"; | 46 const char kUnaffiliatedUserID[] = "test@other_domain.test"; |
| 46 | 47 |
| 47 scoped_ptr<KeyedService> BuildProfileInvalidationProvider( | 48 std::unique_ptr<KeyedService> BuildProfileInvalidationProvider( |
| 48 content::BrowserContext* context) { | 49 content::BrowserContext* context) { |
| 49 scoped_ptr<invalidation::FakeInvalidationService> invalidation_service( | 50 std::unique_ptr<invalidation::FakeInvalidationService> invalidation_service( |
| 50 new invalidation::FakeInvalidationService); | 51 new invalidation::FakeInvalidationService); |
| 51 invalidation_service->SetInvalidatorState( | 52 invalidation_service->SetInvalidatorState( |
| 52 syncer::TRANSIENT_INVALIDATION_ERROR); | 53 syncer::TRANSIENT_INVALIDATION_ERROR); |
| 53 return make_scoped_ptr(new invalidation::ProfileInvalidationProvider( | 54 return base::WrapUnique(new invalidation::ProfileInvalidationProvider( |
| 54 std::move(invalidation_service))); | 55 std::move(invalidation_service))); |
| 55 } | 56 } |
| 56 | 57 |
| 57 } // namespace | 58 } // namespace |
| 58 | 59 |
| 59 // A simple AffiliatedInvalidationServiceProvider::Consumer that registers a | 60 // A simple AffiliatedInvalidationServiceProvider::Consumer that registers a |
| 60 // syncer::FakeInvalidationHandler with the invalidation::InvalidationService | 61 // syncer::FakeInvalidationHandler with the invalidation::InvalidationService |
| 61 // that is currently being made available. | 62 // that is currently being made available. |
| 62 class FakeConsumer : public AffiliatedInvalidationServiceProvider::Consumer { | 63 class FakeConsumer : public AffiliatedInvalidationServiceProvider::Consumer { |
| 63 public: | 64 public: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 void DisconnectPerProfileInvalidationService(); | 117 void DisconnectPerProfileInvalidationService(); |
| 117 | 118 |
| 118 invalidation::FakeInvalidationService* GetProfileInvalidationService( | 119 invalidation::FakeInvalidationService* GetProfileInvalidationService( |
| 119 Profile* profile, | 120 Profile* profile, |
| 120 bool create); | 121 bool create); |
| 121 | 122 |
| 122 protected: | 123 protected: |
| 123 // Ownership is not passed. The Profile is owned by the global ProfileManager. | 124 // Ownership is not passed. The Profile is owned by the global ProfileManager. |
| 124 Profile* LogInAndReturnProfile(const std::string& user_id, | 125 Profile* LogInAndReturnProfile(const std::string& user_id, |
| 125 bool is_affiliated); | 126 bool is_affiliated); |
| 126 scoped_ptr<AffiliatedInvalidationServiceProviderImpl> provider_; | 127 std::unique_ptr<AffiliatedInvalidationServiceProviderImpl> provider_; |
| 127 scoped_ptr<FakeConsumer> consumer_; | 128 std::unique_ptr<FakeConsumer> consumer_; |
| 128 invalidation::TiclInvalidationService* device_invalidation_service_; | 129 invalidation::TiclInvalidationService* device_invalidation_service_; |
| 129 invalidation::FakeInvalidationService* profile_invalidation_service_; | 130 invalidation::FakeInvalidationService* profile_invalidation_service_; |
| 130 | 131 |
| 131 private: | 132 private: |
| 132 content::TestBrowserThreadBundle thread_bundle_; | 133 content::TestBrowserThreadBundle thread_bundle_; |
| 133 chromeos::FakeChromeUserManager* fake_user_manager_; | 134 chromeos::FakeChromeUserManager* fake_user_manager_; |
| 134 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 135 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 135 ScopedStubEnterpriseInstallAttributes install_attributes_; | 136 ScopedStubEnterpriseInstallAttributes install_attributes_; |
| 136 scoped_ptr<chromeos::ScopedTestDeviceSettingsService> | 137 std::unique_ptr<chromeos::ScopedTestDeviceSettingsService> |
| 137 test_device_settings_service_; | 138 test_device_settings_service_; |
| 138 scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_; | 139 std::unique_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_; |
| 139 TestingProfileManager profile_manager_; | 140 TestingProfileManager profile_manager_; |
| 140 }; | 141 }; |
| 141 | 142 |
| 142 FakeConsumer::FakeConsumer(AffiliatedInvalidationServiceProviderImpl* provider) | 143 FakeConsumer::FakeConsumer(AffiliatedInvalidationServiceProviderImpl* provider) |
| 143 : provider_(provider) { | 144 : provider_(provider) { |
| 144 provider_->RegisterConsumer(this); | 145 provider_->RegisterConsumer(this); |
| 145 } | 146 } |
| 146 | 147 |
| 147 FakeConsumer::~FakeConsumer() { | 148 FakeConsumer::~FakeConsumer() { |
| 148 if (invalidation_service_) { | 149 if (invalidation_service_) { |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 // the device-global invalidation service is destroyed. | 570 // the device-global invalidation service is destroyed. |
| 570 TEST_F(AffiliatedInvalidationServiceProviderImplTest, MultipleConsumers) { | 571 TEST_F(AffiliatedInvalidationServiceProviderImplTest, MultipleConsumers) { |
| 571 consumer_.reset(new FakeConsumer(provider_.get())); | 572 consumer_.reset(new FakeConsumer(provider_.get())); |
| 572 | 573 |
| 573 // Indicate that the device-global invalidation service connected. Verify that | 574 // Indicate that the device-global invalidation service connected. Verify that |
| 574 // that the consumer is informed about this. | 575 // that the consumer is informed about this. |
| 575 ConnectDeviceGlobalInvalidationService(); | 576 ConnectDeviceGlobalInvalidationService(); |
| 576 | 577 |
| 577 // Register a second consumer. Verify that the consumer is called back | 578 // Register a second consumer. Verify that the consumer is called back |
| 578 // immediately as a connected invalidation service is available. | 579 // immediately as a connected invalidation service is available. |
| 579 scoped_ptr<FakeConsumer> second_consumer(new FakeConsumer(provider_.get())); | 580 std::unique_ptr<FakeConsumer> second_consumer( |
| 581 new FakeConsumer(provider_.get())); |
| 580 EXPECT_EQ(1, second_consumer->GetAndClearInvalidationServiceSetCount()); | 582 EXPECT_EQ(1, second_consumer->GetAndClearInvalidationServiceSetCount()); |
| 581 EXPECT_EQ(device_invalidation_service_, | 583 EXPECT_EQ(device_invalidation_service_, |
| 582 second_consumer->GetInvalidationService()); | 584 second_consumer->GetInvalidationService()); |
| 583 | 585 |
| 584 // Unregister the first consumer. | 586 // Unregister the first consumer. |
| 585 consumer_.reset(); | 587 consumer_.reset(); |
| 586 | 588 |
| 587 // Verify that the device-global invalidation service still exists. | 589 // Verify that the device-global invalidation service still exists. |
| 588 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 590 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
| 589 | 591 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | 674 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 673 provider_->Shutdown(); | 675 provider_->Shutdown(); |
| 674 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | 676 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
| 675 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | 677 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); |
| 676 | 678 |
| 677 // Verify that the device-global invalidation service has been destroyed. | 679 // Verify that the device-global invalidation service has been destroyed. |
| 678 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 680 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
| 679 } | 681 } |
| 680 | 682 |
| 681 } // namespace policy | 683 } // namespace policy |
| OLD | NEW |