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 "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
12 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" | 12 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" |
13 #include "chrome/browser/chromeos/settings/cros_settings.h" | 13 #include "chrome/browser/chromeos/settings/cros_settings.h" |
14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " | 14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " |
15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
16 #include "chrome/browser/invalidation/fake_invalidation_service.h" | 16 #include "chrome/browser/invalidation/fake_invalidation_service.h" |
17 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 17 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
20 #include "chrome/test/base/testing_profile_manager.h" | 20 #include "chrome/test/base/testing_profile_manager.h" |
21 #include "chromeos/cryptohome/system_salt_getter.h" | 21 #include "chromeos/cryptohome/system_salt_getter.h" |
22 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
23 #include "components/invalidation/fake_invalidation_handler.h" | |
23 #include "components/invalidation/invalidation_service.h" | 24 #include "components/invalidation/invalidation_service.h" |
24 #include "components/invalidation/invalidator_state.h" | 25 #include "components/invalidation/invalidator_state.h" |
25 #include "components/invalidation/profile_invalidation_provider.h" | 26 #include "components/invalidation/profile_invalidation_provider.h" |
26 #include "components/invalidation/ticl_invalidation_service.h" | 27 #include "components/invalidation/ticl_invalidation_service.h" |
27 #include "components/keyed_service/core/keyed_service.h" | 28 #include "components/keyed_service/core/keyed_service.h" |
28 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 29 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
29 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
30 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
31 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
32 #include "content/public/test/test_browser_thread_bundle.h" | 33 #include "content/public/test/test_browser_thread_bundle.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 | 35 |
36 using testing::Mock; | |
37 using testing::StrictMock; | |
38 | |
39 namespace policy { | 36 namespace policy { |
40 | 37 |
41 namespace { | 38 namespace { |
42 | 39 |
43 const char kAffiliatedUserID1[] = "test_1@example.com"; | 40 const char kAffiliatedUserID1[] = "test_1@example.com"; |
44 const char kAffiliatedUserID2[] = "test_2@example.com"; | 41 const char kAffiliatedUserID2[] = "test_2@example.com"; |
45 const char kUnaffiliatedUserID[] = "test@other_domain.test"; | 42 const char kUnaffiliatedUserID[] = "test@other_domain.test"; |
46 | 43 |
47 KeyedService* BuildProfileInvalidationProvider( | 44 KeyedService* BuildProfileInvalidationProvider( |
48 content::BrowserContext* context) { | 45 content::BrowserContext* context) { |
49 scoped_ptr<invalidation::FakeInvalidationService> invalidation_service( | 46 scoped_ptr<invalidation::FakeInvalidationService> invalidation_service( |
50 new invalidation::FakeInvalidationService); | 47 new invalidation::FakeInvalidationService); |
51 invalidation_service->SetInvalidatorState( | 48 invalidation_service->SetInvalidatorState( |
52 syncer::TRANSIENT_INVALIDATION_ERROR); | 49 syncer::TRANSIENT_INVALIDATION_ERROR); |
53 return new invalidation::ProfileInvalidationProvider( | 50 return new invalidation::ProfileInvalidationProvider( |
54 invalidation_service.Pass()); | 51 invalidation_service.Pass()); |
55 } | 52 } |
56 | 53 |
57 } // namespace | 54 } // namespace |
58 | 55 |
59 class MockConsumer : public AffiliatedInvalidationServiceProvider::Consumer { | 56 // A simple AffiliatedInvalidationServiceProvider::Consumer that registers a |
57 // syncer::FakeInvalidationHandler with the invalidation::InvalidationService | |
58 // that is currently being made available. | |
59 class FakeConsumer : public AffiliatedInvalidationServiceProvider::Consumer { | |
60 public: | 60 public: |
61 MockConsumer(); | 61 explicit FakeConsumer(AffiliatedInvalidationServiceProviderImpl* provider); |
62 ~MockConsumer() override; | 62 ~FakeConsumer() override; |
63 | 63 |
64 MOCK_METHOD1(OnInvalidationServiceSet, | 64 // AffiliatedInvalidationServiceProvider::Consumer: |
65 void(invalidation::InvalidationService*)); | 65 void OnInvalidationServiceSet( |
66 invalidation::InvalidationService* invalidation_service) override; | |
67 | |
68 int GetAndClearInvalidationServiceSetCount(); | |
69 const invalidation::InvalidationService* GetInvalidationService() const; | |
66 | 70 |
67 private: | 71 private: |
68 DISALLOW_COPY_AND_ASSIGN(MockConsumer); | 72 AffiliatedInvalidationServiceProviderImpl* provider_; |
73 syncer::FakeInvalidationHandler invalidation_handler_; | |
74 | |
75 int invalidation_service_set_count_; | |
pneubeck (no reviews)
2015/02/05 12:39:05
you can use static initializers here:
int invalid
bartfab (slow)
2015/02/05 15:15:53
Phew, fancy C++11 :).
Done.
By the way - this wo
| |
76 invalidation::InvalidationService* invalidation_service_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(FakeConsumer); | |
69 }; | 79 }; |
70 | 80 |
71 class AffiliatedInvalidationServiceProviderImplTest : public testing::Test { | 81 class AffiliatedInvalidationServiceProviderImplTest : public testing::Test { |
72 public: | 82 public: |
73 AffiliatedInvalidationServiceProviderImplTest(); | 83 AffiliatedInvalidationServiceProviderImplTest(); |
74 | 84 |
75 // testing::Test: | 85 // testing::Test: |
76 virtual void SetUp() override; | 86 virtual void SetUp() override; |
77 virtual void TearDown() override; | 87 virtual void TearDown() override; |
78 | 88 |
(...skipping 20 matching lines...) Expand all Loading... | |
99 // disconnected. Verifies that the |consumer_| is informed about this and a | 109 // disconnected. Verifies that the |consumer_| is informed about this and a |
100 // device-global invalidation service is created. | 110 // device-global invalidation service is created. |
101 void DisconnectPerProfileInvalidationService(); | 111 void DisconnectPerProfileInvalidationService(); |
102 | 112 |
103 invalidation::FakeInvalidationService* GetProfileInvalidationService( | 113 invalidation::FakeInvalidationService* GetProfileInvalidationService( |
104 Profile* profile, | 114 Profile* profile, |
105 bool create); | 115 bool create); |
106 | 116 |
107 protected: | 117 protected: |
108 scoped_ptr<AffiliatedInvalidationServiceProviderImpl> provider_; | 118 scoped_ptr<AffiliatedInvalidationServiceProviderImpl> provider_; |
109 StrictMock<MockConsumer> consumer_; | 119 scoped_ptr<FakeConsumer> consumer_; |
110 invalidation::TiclInvalidationService* device_invalidation_service_; | 120 invalidation::TiclInvalidationService* device_invalidation_service_; |
111 invalidation::FakeInvalidationService* profile_invalidation_service_; | 121 invalidation::FakeInvalidationService* profile_invalidation_service_; |
112 | 122 |
113 private: | 123 private: |
114 content::TestBrowserThreadBundle thread_bundle_; | 124 content::TestBrowserThreadBundle thread_bundle_; |
115 chromeos::FakeChromeUserManager* fake_user_manager_; | 125 chromeos::FakeChromeUserManager* fake_user_manager_; |
116 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 126 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
117 ScopedStubEnterpriseInstallAttributes install_attributes_; | 127 ScopedStubEnterpriseInstallAttributes install_attributes_; |
118 scoped_ptr<chromeos::ScopedTestDeviceSettingsService> | 128 scoped_ptr<chromeos::ScopedTestDeviceSettingsService> |
119 test_device_settings_service_; | 129 test_device_settings_service_; |
120 scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_; | 130 scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_; |
121 TestingProfileManager profile_manager_; | 131 TestingProfileManager profile_manager_; |
122 }; | 132 }; |
123 | 133 |
124 MockConsumer::MockConsumer() { | 134 FakeConsumer::FakeConsumer(AffiliatedInvalidationServiceProviderImpl* provider) |
135 : provider_(provider), | |
136 invalidation_service_set_count_(0), | |
137 invalidation_service_(nullptr) { | |
138 provider_->RegisterConsumer(this); | |
125 } | 139 } |
126 | 140 |
127 MockConsumer::~MockConsumer() { | 141 FakeConsumer::~FakeConsumer() { |
142 if (invalidation_service_) { | |
143 invalidation_service_->UnregisterInvalidationHandler( | |
144 &invalidation_handler_); | |
145 } | |
146 provider_->UnregisterConsumer(this); | |
147 | |
148 EXPECT_EQ(0, invalidation_service_set_count_); | |
149 } | |
150 | |
151 void FakeConsumer::OnInvalidationServiceSet( | |
152 invalidation::InvalidationService* invalidation_service) { | |
153 ++invalidation_service_set_count_; | |
154 | |
155 if (invalidation_service_) { | |
156 invalidation_service_->UnregisterInvalidationHandler( | |
157 &invalidation_handler_); | |
158 } | |
159 | |
160 invalidation_service_ = invalidation_service; | |
161 | |
162 if (invalidation_service_) | |
163 invalidation_service_->RegisterInvalidationHandler(&invalidation_handler_); | |
164 } | |
165 | |
166 int FakeConsumer::GetAndClearInvalidationServiceSetCount() { | |
167 const int invalidation_service_set_count = invalidation_service_set_count_; | |
168 invalidation_service_set_count_ = 0; | |
169 return invalidation_service_set_count; | |
170 } | |
171 | |
172 const invalidation::InvalidationService* | |
173 FakeConsumer::GetInvalidationService() const { | |
174 return invalidation_service_; | |
128 } | 175 } |
129 | 176 |
130 AffiliatedInvalidationServiceProviderImplTest:: | 177 AffiliatedInvalidationServiceProviderImplTest:: |
131 AffiliatedInvalidationServiceProviderImplTest() | 178 AffiliatedInvalidationServiceProviderImplTest() |
132 : device_invalidation_service_(nullptr), | 179 : device_invalidation_service_(nullptr), |
133 profile_invalidation_service_(nullptr), | 180 profile_invalidation_service_(nullptr), |
134 fake_user_manager_(new chromeos::FakeChromeUserManager), | 181 fake_user_manager_(new chromeos::FakeChromeUserManager), |
135 user_manager_enabler_(fake_user_manager_), | 182 user_manager_enabler_(fake_user_manager_), |
136 install_attributes_("example.com", | 183 install_attributes_("example.com", |
137 "user@example.com", | 184 "user@example.com", |
(...skipping 12 matching lines...) Expand all Loading... | |
150 test_cros_settings_.reset(new chromeos::ScopedTestCrosSettings); | 197 test_cros_settings_.reset(new chromeos::ScopedTestCrosSettings); |
151 chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); | 198 chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); |
152 | 199 |
153 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> | 200 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
154 RegisterTestingFactory(BuildProfileInvalidationProvider); | 201 RegisterTestingFactory(BuildProfileInvalidationProvider); |
155 | 202 |
156 provider_.reset(new AffiliatedInvalidationServiceProviderImpl); | 203 provider_.reset(new AffiliatedInvalidationServiceProviderImpl); |
157 } | 204 } |
158 | 205 |
159 void AffiliatedInvalidationServiceProviderImplTest::TearDown() { | 206 void AffiliatedInvalidationServiceProviderImplTest::TearDown() { |
207 consumer_.reset(); | |
160 provider_->Shutdown(); | 208 provider_->Shutdown(); |
161 provider_.reset(); | 209 provider_.reset(); |
162 | 210 |
163 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> | 211 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
164 RegisterTestingFactory(nullptr); | 212 RegisterTestingFactory(nullptr); |
165 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); | 213 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); |
166 chromeos::DBusThreadManager::Shutdown(); | 214 chromeos::DBusThreadManager::Shutdown(); |
167 chromeos::SystemSaltGetter::Shutdown(); | 215 chromeos::SystemSaltGetter::Shutdown(); |
168 } | 216 } |
169 | 217 |
170 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile( | 218 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile( |
171 const std::string& user_id) { | 219 const std::string& user_id) { |
172 fake_user_manager_->AddUser(user_id); | 220 fake_user_manager_->AddUser(user_id); |
173 Profile* profile = profile_manager_.CreateTestingProfile(user_id); | 221 Profile* profile = profile_manager_.CreateTestingProfile(user_id); |
174 content::NotificationService::current()->Notify( | 222 content::NotificationService::current()->Notify( |
175 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 223 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
176 content::NotificationService::AllSources(), | 224 content::NotificationService::AllSources(), |
177 content::Details<Profile>(profile)); | 225 content::Details<Profile>(profile)); |
178 return profile; | 226 return profile; |
179 } | 227 } |
180 | 228 |
181 void AffiliatedInvalidationServiceProviderImplTest:: | 229 void AffiliatedInvalidationServiceProviderImplTest:: |
182 LogInAsAffiliatedUserAndConnectInvalidationService() { | 230 LogInAsAffiliatedUserAndConnectInvalidationService() { |
183 Mock::VerifyAndClearExpectations(&consumer_); | |
184 | |
185 // Log in as an affiliated user. | 231 // Log in as an affiliated user. |
186 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); | 232 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); |
187 EXPECT_TRUE(profile); | 233 EXPECT_TRUE(profile); |
188 Mock::VerifyAndClearExpectations(&consumer_); | |
189 | 234 |
190 // Verify that a per-profile invalidation service has been created. | 235 // Verify that a per-profile invalidation service has been created. |
191 profile_invalidation_service_ = | 236 profile_invalidation_service_ = |
192 GetProfileInvalidationService(profile, false /* create */); | 237 GetProfileInvalidationService(profile, false /* create */); |
193 ASSERT_TRUE(profile_invalidation_service_); | 238 ASSERT_TRUE(profile_invalidation_service_); |
194 | 239 |
195 // Verify that the device-global invalidation service still exists. | 240 // Verify that the device-global invalidation service still exists. |
196 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 241 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
197 | 242 |
198 // Indicate that the per-profile invalidation service has connected. Verify | 243 // Indicate that the per-profile invalidation service has connected. Verify |
199 // that the consumer is informed about this. | 244 // that the consumer is informed about this. |
200 EXPECT_CALL(consumer_, | 245 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
201 OnInvalidationServiceSet(profile_invalidation_service_)).Times(1); | |
202 profile_invalidation_service_->SetInvalidatorState( | 246 profile_invalidation_service_->SetInvalidatorState( |
203 syncer::INVALIDATIONS_ENABLED); | 247 syncer::INVALIDATIONS_ENABLED); |
204 Mock::VerifyAndClearExpectations(&consumer_); | 248 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
249 EXPECT_EQ(profile_invalidation_service_, consumer_->GetInvalidationService()); | |
205 | 250 |
206 // Verify that the device-global invalidation service has been destroyed. | 251 // Verify that the device-global invalidation service has been destroyed. |
207 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 252 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
208 | |
209 Mock::VerifyAndClearExpectations(&consumer_); | |
210 } | 253 } |
211 | 254 |
212 void AffiliatedInvalidationServiceProviderImplTest:: | 255 void AffiliatedInvalidationServiceProviderImplTest:: |
213 LogInAsUnaffiliatedUserAndConnectInvalidationService() { | 256 LogInAsUnaffiliatedUserAndConnectInvalidationService() { |
214 Mock::VerifyAndClearExpectations(&consumer_); | |
215 | |
216 // Log in as an unaffiliated user. | 257 // Log in as an unaffiliated user. |
217 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); | 258 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); |
218 EXPECT_TRUE(profile); | 259 EXPECT_TRUE(profile); |
219 | 260 |
220 // Verify that a per-profile invalidation service has been created. | 261 // Verify that a per-profile invalidation service has been created. |
221 profile_invalidation_service_ = | 262 profile_invalidation_service_ = |
222 GetProfileInvalidationService(profile, false /* create */); | 263 GetProfileInvalidationService(profile, false /* create */); |
223 ASSERT_TRUE(profile_invalidation_service_); | 264 ASSERT_TRUE(profile_invalidation_service_); |
224 | 265 |
225 // Verify that the device-global invalidation service still exists. | 266 // Verify that the device-global invalidation service still exists. |
226 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 267 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
227 | 268 |
228 // Indicate that the per-profile invalidation service has connected. Verify | 269 // Indicate that the per-profile invalidation service has connected. Verify |
229 // that the consumer is not called back. | 270 // that the consumer is not called back. |
230 profile_invalidation_service_->SetInvalidatorState( | 271 profile_invalidation_service_->SetInvalidatorState( |
231 syncer::INVALIDATIONS_ENABLED); | 272 syncer::INVALIDATIONS_ENABLED); |
273 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
232 | 274 |
233 // Verify that the device-global invalidation service still exists. | 275 // Verify that the device-global invalidation service still exists. |
234 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 276 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
235 | |
236 Mock::VerifyAndClearExpectations(&consumer_); | |
237 } | 277 } |
238 | 278 |
239 void AffiliatedInvalidationServiceProviderImplTest:: | 279 void AffiliatedInvalidationServiceProviderImplTest:: |
240 ConnectDeviceGlobalInvalidationService() { | 280 ConnectDeviceGlobalInvalidationService() { |
241 Mock::VerifyAndClearExpectations(&consumer_); | |
242 | |
243 // Verify that a device-global invalidation service has been created. | 281 // Verify that a device-global invalidation service has been created. |
244 device_invalidation_service_ = | 282 device_invalidation_service_ = |
245 provider_->GetDeviceInvalidationServiceForTest(); | 283 provider_->GetDeviceInvalidationServiceForTest(); |
246 ASSERT_TRUE(device_invalidation_service_); | 284 ASSERT_TRUE(device_invalidation_service_); |
247 | 285 |
248 // Indicate that the device-global invalidation service has connected. Verify | 286 // Indicate that the device-global invalidation service has connected. Verify |
249 // that the consumer is informed about this. | 287 // that the consumer is informed about this. |
250 EXPECT_CALL(consumer_, OnInvalidationServiceSet(device_invalidation_service_)) | 288 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
251 .Times(1); | |
252 device_invalidation_service_->OnInvalidatorStateChange( | 289 device_invalidation_service_->OnInvalidatorStateChange( |
253 syncer::INVALIDATIONS_ENABLED); | 290 syncer::INVALIDATIONS_ENABLED); |
254 | 291 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
255 Mock::VerifyAndClearExpectations(&consumer_); | 292 EXPECT_EQ(device_invalidation_service_, consumer_->GetInvalidationService()); |
256 } | 293 } |
257 | 294 |
258 void AffiliatedInvalidationServiceProviderImplTest:: | 295 void AffiliatedInvalidationServiceProviderImplTest:: |
259 DisconnectPerProfileInvalidationService() { | 296 DisconnectPerProfileInvalidationService() { |
260 Mock::VerifyAndClearExpectations(&consumer_); | |
261 | |
262 ASSERT_TRUE(profile_invalidation_service_); | 297 ASSERT_TRUE(profile_invalidation_service_); |
263 | 298 |
264 // Indicate that the per-profile invalidation service has disconnected. Verify | 299 // Indicate that the per-profile invalidation service has disconnected. Verify |
265 // that the consumer is informed about this. | 300 // that the consumer is informed about this. |
266 EXPECT_CALL(consumer_, OnInvalidationServiceSet(nullptr)).Times(1); | 301 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
267 profile_invalidation_service_->SetInvalidatorState( | 302 profile_invalidation_service_->SetInvalidatorState( |
268 syncer::INVALIDATION_CREDENTIALS_REJECTED); | 303 syncer::INVALIDATION_CREDENTIALS_REJECTED); |
304 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); | |
305 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | |
269 | 306 |
270 // Verify that a device-global invalidation service has been created. | 307 // Verify that a device-global invalidation service has been created. |
271 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 308 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
272 | |
273 Mock::VerifyAndClearExpectations(&consumer_); | |
274 } | 309 } |
275 | 310 |
276 invalidation::FakeInvalidationService* | 311 invalidation::FakeInvalidationService* |
277 AffiliatedInvalidationServiceProviderImplTest::GetProfileInvalidationService( | 312 AffiliatedInvalidationServiceProviderImplTest::GetProfileInvalidationService( |
278 Profile* profile, bool create) { | 313 Profile* profile, bool create) { |
279 invalidation::ProfileInvalidationProvider* invalidation_provider = | 314 invalidation::ProfileInvalidationProvider* invalidation_provider = |
280 static_cast<invalidation::ProfileInvalidationProvider*>( | 315 static_cast<invalidation::ProfileInvalidationProvider*>( |
281 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> | 316 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
282 GetServiceForBrowserContext(profile, create)); | 317 GetServiceForBrowserContext(profile, create)); |
283 if (!invalidation_provider) | 318 if (!invalidation_provider) |
(...skipping 19 matching lines...) Expand all Loading... | |
303 | 338 |
304 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 339 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
305 // Verifies that when no per-profile invalidation service belonging to an | 340 // Verifies that when no per-profile invalidation service belonging to an |
306 // affiliated user is available, a device-global invalidation service is | 341 // affiliated user is available, a device-global invalidation service is |
307 // created. Further verifies that when the device-global invalidation service | 342 // created. Further verifies that when the device-global invalidation service |
308 // connects, it is made available to the consumer. | 343 // connects, it is made available to the consumer. |
309 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 344 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
310 UseDeviceInvalidationService) { | 345 UseDeviceInvalidationService) { |
311 // Register a consumer. Verify that the consumer is not called back | 346 // Register a consumer. Verify that the consumer is not called back |
312 // immediately as no connected invalidation service exists yet. | 347 // immediately as no connected invalidation service exists yet. |
313 provider_->RegisterConsumer(&consumer_); | 348 consumer_.reset(new FakeConsumer(provider_.get())); |
349 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
314 | 350 |
315 // Indicate that the device-global invalidation service connected. Verify that | 351 // Indicate that the device-global invalidation service connected. Verify that |
316 // that the consumer is informed about this. | 352 // that the consumer is informed about this. |
317 ConnectDeviceGlobalInvalidationService(); | 353 ConnectDeviceGlobalInvalidationService(); |
318 | 354 |
319 // Indicate that the device-global invalidation service has disconnected. | 355 // Indicate that the device-global invalidation service has disconnected. |
320 // Verify that the consumer is informed about this. | 356 // Verify that the consumer is informed about this. |
321 EXPECT_CALL(consumer_, OnInvalidationServiceSet(nullptr)).Times(1); | 357 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
322 device_invalidation_service_->OnInvalidatorStateChange( | 358 device_invalidation_service_->OnInvalidatorStateChange( |
323 syncer::INVALIDATION_CREDENTIALS_REJECTED); | 359 syncer::INVALIDATION_CREDENTIALS_REJECTED); |
324 Mock::VerifyAndClearExpectations(&consumer_); | 360 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
361 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | |
325 | 362 |
326 // Verify that the device-global invalidation service still exists. | 363 // Verify that the device-global invalidation service still exists. |
327 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 364 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
328 | |
329 // Unregister the consumer. | |
330 provider_->UnregisterConsumer(&consumer_); | |
331 Mock::VerifyAndClearExpectations(&consumer_); | |
332 } | 365 } |
333 | 366 |
334 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 367 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
335 // Verifies that when a per-profile invalidation service belonging to an | 368 // Verifies that when a per-profile invalidation service belonging to an |
336 // affiliated user connects, it is made available to the consumer. | 369 // affiliated user connects, it is made available to the consumer. |
337 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 370 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
338 UseAffiliatedProfileInvalidationService) { | 371 UseAffiliatedProfileInvalidationService) { |
339 // Register a consumer. Verify that the consumer is not called back | 372 // Register a consumer. Verify that the consumer is not called back |
pneubeck (no reviews)
2015/02/05 12:39:05
I know you didn't add it in this CL, but instead o
bartfab (slow)
2015/02/05 15:15:53
Done.
| |
340 // immediately as no connected invalidation service exists yet. | 373 // immediately as no connected invalidation service exists yet. |
341 provider_->RegisterConsumer(&consumer_); | 374 consumer_.reset(new FakeConsumer(provider_.get())); |
375 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
342 | 376 |
343 // Verify that a device-global invalidation service has been created. | 377 // Verify that a device-global invalidation service has been created. |
344 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 378 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
345 | 379 |
346 // Log in as an affiliated user and indicate that the per-profile invalidation | 380 // Log in as an affiliated user and indicate that the per-profile invalidation |
347 // service for this user connected. Verify that this invalidation service is | 381 // service for this user connected. Verify that this invalidation service is |
348 // made available to the |consumer_| and the device-global invalidation | 382 // made available to the |consumer_| and the device-global invalidation |
349 // service is destroyed. | 383 // service is destroyed. |
350 LogInAsAffiliatedUserAndConnectInvalidationService(); | 384 LogInAsAffiliatedUserAndConnectInvalidationService(); |
351 | 385 |
352 // Indicate that the logged-in user's per-profile invalidation service | 386 // Indicate that the logged-in user's per-profile invalidation service |
353 // disconnected. Verify that the consumer is informed about this and a | 387 // disconnected. Verify that the consumer is informed about this and a |
354 // device-global invalidation service is created. | 388 // device-global invalidation service is created. |
355 DisconnectPerProfileInvalidationService(); | 389 DisconnectPerProfileInvalidationService(); |
356 | |
357 // Unregister the consumer. | |
358 provider_->UnregisterConsumer(&consumer_); | |
359 Mock::VerifyAndClearExpectations(&consumer_); | |
360 } | 390 } |
361 | 391 |
362 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 392 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
363 // Verifies that when a per-profile invalidation service belonging to an | 393 // Verifies that when a per-profile invalidation service belonging to an |
364 // unaffiliated user connects, it is ignored. | 394 // unaffiliated user connects, it is ignored. |
365 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 395 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
366 DoNotUseUnaffiliatedProfileInvalidationService) { | 396 DoNotUseUnaffiliatedProfileInvalidationService) { |
367 // Register a consumer. Verify that the consumer is not called back | 397 // Register a consumer. Verify that the consumer is not called back |
368 // immediately as no connected invalidation service exists yet. | 398 // immediately as no connected invalidation service exists yet. |
369 provider_->RegisterConsumer(&consumer_); | 399 consumer_.reset(new FakeConsumer(provider_.get())); |
400 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
370 | 401 |
371 // Verify that a device-global invalidation service has been created. | 402 // Verify that a device-global invalidation service has been created. |
372 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 403 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
373 | 404 |
374 // Log in as an unaffiliated user and indicate that the per-profile | 405 // Log in as an unaffiliated user and indicate that the per-profile |
375 // invalidation service for this user connected. Verify that this invalidation | 406 // invalidation service for this user connected. Verify that this invalidation |
376 // service is ignored and the device-global invalidation service is not | 407 // service is ignored and the device-global invalidation service is not |
377 // destroyed. | 408 // destroyed. |
378 LogInAsUnaffiliatedUserAndConnectInvalidationService(); | 409 LogInAsUnaffiliatedUserAndConnectInvalidationService(); |
379 | |
380 // Unregister the consumer. | |
381 provider_->UnregisterConsumer(&consumer_); | |
382 Mock::VerifyAndClearExpectations(&consumer_); | |
383 } | 410 } |
384 | 411 |
385 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 412 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
386 // A device-global invalidation service exists, is connected and is made | 413 // A device-global invalidation service exists, is connected and is made |
387 // available to the consumer. Verifies that when a per-profile invalidation | 414 // available to the consumer. Verifies that when a per-profile invalidation |
388 // service belonging to an affiliated user connects, it is made available to the | 415 // service belonging to an affiliated user connects, it is made available to the |
389 // consumer instead and the device-global invalidation service is destroyed. | 416 // consumer instead and the device-global invalidation service is destroyed. |
390 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 417 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
391 SwitchToAffiliatedProfileInvalidationService) { | 418 SwitchToAffiliatedProfileInvalidationService) { |
392 // Register a consumer. Verify that the consumer is not called back | 419 // Register a consumer. Verify that the consumer is not called back |
393 // immediately as no connected invalidation service exists yet. | 420 // immediately as no connected invalidation service exists yet. |
394 provider_->RegisterConsumer(&consumer_); | 421 consumer_.reset(new FakeConsumer(provider_.get())); |
422 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
395 | 423 |
396 // Indicate that the device-global invalidation service connected. Verify that | 424 // Indicate that the device-global invalidation service connected. Verify that |
397 // that the consumer is informed about this. | 425 // that the consumer is informed about this. |
398 ConnectDeviceGlobalInvalidationService(); | 426 ConnectDeviceGlobalInvalidationService(); |
399 | 427 |
400 // Log in as an affiliated user and indicate that the per-profile invalidation | 428 // Log in as an affiliated user and indicate that the per-profile invalidation |
401 // service for this user connected. Verify that this invalidation service is | 429 // service for this user connected. Verify that this invalidation service is |
402 // made available to the |consumer_| and the device-global invalidation | 430 // made available to the |consumer_| and the device-global invalidation |
403 // service is destroyed. | 431 // service is destroyed. |
404 LogInAsAffiliatedUserAndConnectInvalidationService(); | 432 LogInAsAffiliatedUserAndConnectInvalidationService(); |
405 | |
406 // Unregister the consumer. | |
407 provider_->UnregisterConsumer(&consumer_); | |
408 Mock::VerifyAndClearExpectations(&consumer_); | |
409 } | 433 } |
410 | 434 |
411 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 435 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
412 // A device-global invalidation service exists, is connected and is made | 436 // A device-global invalidation service exists, is connected and is made |
413 // available to the consumer. Verifies that when a per-profile invalidation | 437 // available to the consumer. Verifies that when a per-profile invalidation |
414 // service belonging to an unaffiliated user connects, it is ignored and the | 438 // service belonging to an unaffiliated user connects, it is ignored and the |
415 // device-global invalidation service continues to be made available to the | 439 // device-global invalidation service continues to be made available to the |
416 // consumer. | 440 // consumer. |
417 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 441 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
418 DoNotSwitchToUnaffiliatedProfileInvalidationService) { | 442 DoNotSwitchToUnaffiliatedProfileInvalidationService) { |
419 // Register a consumer. Verify that the consumer is not called back | 443 // Register a consumer. Verify that the consumer is not called back |
420 // immediately as no connected invalidation service exists yet. | 444 // immediately as no connected invalidation service exists yet. |
421 provider_->RegisterConsumer(&consumer_); | 445 consumer_.reset(new FakeConsumer(provider_.get())); |
446 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
422 | 447 |
423 // Indicate that the device-global invalidation service connected. Verify that | 448 // Indicate that the device-global invalidation service connected. Verify that |
424 // that the consumer is informed about this. | 449 // that the consumer is informed about this. |
425 ConnectDeviceGlobalInvalidationService(); | 450 ConnectDeviceGlobalInvalidationService(); |
426 | 451 |
427 // Log in as an unaffiliated user and indicate that the per-profile | 452 // Log in as an unaffiliated user and indicate that the per-profile |
428 // invalidation service for this user connected. Verify that this invalidation | 453 // invalidation service for this user connected. Verify that this invalidation |
429 // service is ignored and the device-global invalidation service is not | 454 // service is ignored and the device-global invalidation service is not |
430 // destroyed. | 455 // destroyed. |
431 LogInAsUnaffiliatedUserAndConnectInvalidationService(); | 456 LogInAsUnaffiliatedUserAndConnectInvalidationService(); |
432 | |
433 // Unregister the consumer. | |
434 provider_->UnregisterConsumer(&consumer_); | |
435 Mock::VerifyAndClearExpectations(&consumer_); | |
436 } | 457 } |
437 | 458 |
438 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 459 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
439 // A per-profile invalidation service belonging to an affiliated user exists, is | 460 // A per-profile invalidation service belonging to an affiliated user exists, is |
440 // connected and is made available to the consumer. Verifies that when the | 461 // connected and is made available to the consumer. Verifies that when the |
441 // per-profile invalidation service disconnects, a device-global invalidation | 462 // per-profile invalidation service disconnects, a device-global invalidation |
442 // service is created. Further verifies that when the device-global invalidation | 463 // service is created. Further verifies that when the device-global invalidation |
443 // service connects, it is made available to the consumer. | 464 // service connects, it is made available to the consumer. |
444 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 465 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
445 SwitchToDeviceInvalidationService) { | 466 SwitchToDeviceInvalidationService) { |
446 // Register a consumer. Verify that the consumer is not called back | 467 // Register a consumer. Verify that the consumer is not called back |
447 // immediately as no connected invalidation service exists yet. | 468 // immediately as no connected invalidation service exists yet. |
448 provider_->RegisterConsumer(&consumer_); | 469 consumer_.reset(new FakeConsumer(provider_.get())); |
470 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
449 | 471 |
450 // Verify that a device-global invalidation service has been created. | 472 // Verify that a device-global invalidation service has been created. |
451 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 473 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
452 | 474 |
453 // Log in as an affiliated user and indicate that the per-profile invalidation | 475 // Log in as an affiliated user and indicate that the per-profile invalidation |
454 // service for this user connected. Verify that this invalidation service is | 476 // service for this user connected. Verify that this invalidation service is |
455 // made available to the |consumer_| and the device-global invalidation | 477 // made available to the |consumer_| and the device-global invalidation |
456 // service is destroyed. | 478 // service is destroyed. |
457 LogInAsAffiliatedUserAndConnectInvalidationService(); | 479 LogInAsAffiliatedUserAndConnectInvalidationService(); |
458 | 480 |
459 // Indicate that the logged-in user's per-profile invalidation service | 481 // Indicate that the logged-in user's per-profile invalidation service |
460 // disconnected. Verify that the consumer is informed about this and a | 482 // disconnected. Verify that the consumer is informed about this and a |
461 // device-global invalidation service is created. | 483 // device-global invalidation service is created. |
462 DisconnectPerProfileInvalidationService(); | 484 DisconnectPerProfileInvalidationService(); |
463 | 485 |
464 // Indicate that the device-global invalidation service connected. Verify that | 486 // Indicate that the device-global invalidation service connected. Verify that |
465 // that the consumer is informed about this. | 487 // that the consumer is informed about this. |
466 ConnectDeviceGlobalInvalidationService(); | 488 ConnectDeviceGlobalInvalidationService(); |
467 | |
468 // Unregister the consumer. | |
469 provider_->UnregisterConsumer(&consumer_); | |
470 Mock::VerifyAndClearExpectations(&consumer_); | |
471 } | 489 } |
472 | 490 |
473 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 491 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
474 // A per-profile invalidation service belonging to a first affiliated user | 492 // A per-profile invalidation service belonging to a first affiliated user |
475 // exists, is connected and is made available to the consumer. A per-profile | 493 // exists, is connected and is made available to the consumer. A per-profile |
476 // invalidation service belonging to a second affiliated user also exists and is | 494 // invalidation service belonging to a second affiliated user also exists and is |
477 // connected. Verifies that when the per-profile invalidation service belonging | 495 // connected. Verifies that when the per-profile invalidation service belonging |
478 // to the first user disconnects, the per-profile invalidation service belonging | 496 // to the first user disconnects, the per-profile invalidation service belonging |
479 // to the second user is made available to the consumer instead. | 497 // to the second user is made available to the consumer instead. |
480 TEST_F(AffiliatedInvalidationServiceProviderImplTest, | 498 TEST_F(AffiliatedInvalidationServiceProviderImplTest, |
481 SwitchBetweenAffiliatedProfileInvalidationServices) { | 499 SwitchBetweenAffiliatedProfileInvalidationServices) { |
482 // Register a consumer. Verify that the consumer is not called back | 500 // Register a consumer. Verify that the consumer is not called back |
483 // immediately as no connected invalidation service exists yet. | 501 // immediately as no connected invalidation service exists yet. |
484 provider_->RegisterConsumer(&consumer_); | 502 consumer_.reset(new FakeConsumer(provider_.get())); |
503 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
485 | 504 |
486 // Verify that a device-global invalidation service has been created. | 505 // Verify that a device-global invalidation service has been created. |
487 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 506 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
488 | 507 |
489 // Log in as a first affiliated user and indicate that the per-profile | 508 // Log in as a first affiliated user and indicate that the per-profile |
490 // invalidation service for this user connected. Verify that this invalidation | 509 // invalidation service for this user connected. Verify that this invalidation |
491 // service is made available to the |consumer_| and the device-global | 510 // service is made available to the |consumer_| and the device-global |
492 // invalidation service is destroyed. | 511 // invalidation service is destroyed. |
493 LogInAsAffiliatedUserAndConnectInvalidationService(); | 512 LogInAsAffiliatedUserAndConnectInvalidationService(); |
494 | 513 |
495 // Log in as a second affiliated user. | 514 // Log in as a second affiliated user. |
496 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); | 515 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); |
497 EXPECT_TRUE(second_profile); | 516 EXPECT_TRUE(second_profile); |
498 | 517 |
499 // Verify that the device-global invalidation service still does not exist. | 518 // Verify that the device-global invalidation service still does not exist. |
500 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 519 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
501 | 520 |
502 // 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 |
503 // created. | 522 // created. |
504 invalidation::FakeInvalidationService* second_profile_invalidation_service = | 523 invalidation::FakeInvalidationService* second_profile_invalidation_service = |
505 GetProfileInvalidationService(second_profile, false /* create */); | 524 GetProfileInvalidationService(second_profile, false /* create */); |
506 ASSERT_TRUE(second_profile_invalidation_service); | 525 ASSERT_TRUE(second_profile_invalidation_service); |
507 | 526 |
508 // Indicate that the second user's per-profile invalidation service has | 527 // Indicate that the second user's per-profile invalidation service has |
509 // connected. Verify that the consumer is not called back. | 528 // connected. Verify that the consumer is not called back. |
510 second_profile_invalidation_service->SetInvalidatorState( | 529 second_profile_invalidation_service->SetInvalidatorState( |
511 syncer::INVALIDATIONS_ENABLED); | 530 syncer::INVALIDATIONS_ENABLED); |
512 Mock::VerifyAndClearExpectations(&consumer_); | 531 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
513 | 532 |
514 // Indicate that the first user's per-profile invalidation service has | 533 // Indicate that the first user's per-profile invalidation service has |
515 // disconnected. Verify that the consumer is informed that the second user's | 534 // disconnected. Verify that the consumer is informed that the second user's |
516 // per-profile invalidation service should be used instead of the first | 535 // per-profile invalidation service should be used instead of the first |
517 // user's. | 536 // user's. |
518 EXPECT_CALL(consumer_, | 537 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
519 OnInvalidationServiceSet(second_profile_invalidation_service)) | |
520 .Times(1); | |
521 profile_invalidation_service_->SetInvalidatorState( | 538 profile_invalidation_service_->SetInvalidatorState( |
522 syncer::INVALIDATION_CREDENTIALS_REJECTED); | 539 syncer::INVALIDATION_CREDENTIALS_REJECTED); |
523 Mock::VerifyAndClearExpectations(&consumer_); | 540 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
541 EXPECT_EQ(second_profile_invalidation_service, | |
542 consumer_->GetInvalidationService()); | |
524 | 543 |
525 // Verify that the device-global invalidation service still does not exist. | 544 // Verify that the device-global invalidation service still does not exist. |
526 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 545 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
527 | |
528 // Unregister the consumer. | |
529 provider_->UnregisterConsumer(&consumer_); | |
530 Mock::VerifyAndClearExpectations(&consumer_); | |
531 } | 546 } |
532 | 547 |
533 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 548 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
534 // A device-global invalidation service exists, is connected and is made | 549 // A device-global invalidation service exists, is connected and is made |
535 // available to the consumer. Verifies that when a second consumer registers, | 550 // available to the consumer. Verifies that when a second consumer registers, |
536 // the device-global invalidation service is made available to it as well. | 551 // the device-global invalidation service is made available to it as well. |
537 // Further verifies that when the first consumer unregisters, the device-global | 552 // Further verifies that when the first consumer unregisters, the device-global |
538 // invalidation service is not destroyed and remains available to the second | 553 // invalidation service is not destroyed and remains available to the second |
539 // consumer. Further verifies that when the second consumer also unregisters, | 554 // consumer. Further verifies that when the second consumer also unregisters, |
540 // the device-global invalidation service is destroyed. | 555 // the device-global invalidation service is destroyed. |
541 TEST_F(AffiliatedInvalidationServiceProviderImplTest, MultipleConsumers) { | 556 TEST_F(AffiliatedInvalidationServiceProviderImplTest, MultipleConsumers) { |
542 // Register a first consumer. Verify that the consumer is not called back | 557 // Register a first consumer. Verify that the consumer is not called back |
543 // immediately as no connected invalidation service exists yet. | 558 // immediately as no connected invalidation service exists yet. |
544 provider_->RegisterConsumer(&consumer_); | 559 consumer_.reset(new FakeConsumer(provider_.get())); |
560 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
545 | 561 |
546 // Indicate that the device-global invalidation service connected. Verify that | 562 // Indicate that the device-global invalidation service connected. Verify that |
547 // that the consumer is informed about this. | 563 // that the consumer is informed about this. |
548 ConnectDeviceGlobalInvalidationService(); | 564 ConnectDeviceGlobalInvalidationService(); |
549 | 565 |
550 // Register a second consumer. Verify that the consumer is called back | 566 // Register a second consumer. Verify that the consumer is called back |
551 // immediately as a connected invalidation service is available. | 567 // immediately as a connected invalidation service is available. |
552 StrictMock<MockConsumer> second_consumer; | 568 scoped_ptr<FakeConsumer> second_consumer(new FakeConsumer(provider_.get())); |
553 EXPECT_CALL(second_consumer, | 569 EXPECT_EQ(1, second_consumer->GetAndClearInvalidationServiceSetCount()); |
554 OnInvalidationServiceSet(device_invalidation_service_)).Times(1); | 570 EXPECT_EQ(device_invalidation_service_, |
555 provider_->RegisterConsumer(&second_consumer); | 571 second_consumer->GetInvalidationService()); |
556 Mock::VerifyAndClearExpectations(&second_consumer); | |
557 | 572 |
558 // Unregister the first consumer. | 573 // Unregister the first consumer. |
559 provider_->UnregisterConsumer(&consumer_); | 574 consumer_.reset(); |
560 | 575 |
561 // Verify that the device-global invalidation service still exists. | 576 // Verify that the device-global invalidation service still exists. |
562 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 577 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
563 | 578 |
564 // Unregister the second consumer. | 579 // Unregister the second consumer. |
565 provider_->UnregisterConsumer(&second_consumer); | 580 second_consumer.reset(); |
566 | 581 |
567 // Verify that the device-global invalidation service has been destroyed. | 582 // Verify that the device-global invalidation service has been destroyed. |
568 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 583 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
569 Mock::VerifyAndClearExpectations(&consumer_); | |
570 Mock::VerifyAndClearExpectations(&second_consumer); | |
571 } | 584 } |
572 | 585 |
573 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. | 586 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl. |
574 // A per-profile invalidation service belonging to a first affiliated user | 587 // A per-profile invalidation service belonging to a first affiliated user |
575 // exists, is connected and is made available to the consumer. Verifies that | 588 // exists, is connected and is made available to the consumer. Verifies that |
576 // when the provider is shut down, the consumer is informed that no | 589 // when the provider is shut down, the consumer is informed that no |
577 // invalidation service is available for use anymore. Also verifies that no | 590 // invalidation service is available for use anymore. Also verifies that no |
578 // device-global invalidation service is created and a per-profile invalidation | 591 // device-global invalidation service is created and a per-profile invalidation |
579 // service belonging to a second affiliated user that subsequently connects is | 592 // service belonging to a second affiliated user that subsequently connects is |
580 // ignored. | 593 // ignored. |
581 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoServiceAfterShutdown) { | 594 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoServiceAfterShutdown) { |
582 // Register a consumer. Verify that the consumer is not called back | 595 // Register a consumer. Verify that the consumer is not called back |
583 // immediately as no connected invalidation service exists yet. | 596 // immediately as no connected invalidation service exists yet. |
584 provider_->RegisterConsumer(&consumer_); | 597 consumer_.reset(new FakeConsumer(provider_.get())); |
598 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
585 | 599 |
586 // Verify that a device-global invalidation service has been created. | 600 // Verify that a device-global invalidation service has been created. |
587 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); | 601 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); |
588 | 602 |
589 // Log in as a first affiliated user and indicate that the per-profile | 603 // Log in as a first affiliated user and indicate that the per-profile |
590 // invalidation service for this user connected. Verify that this invalidation | 604 // invalidation service for this user connected. Verify that this invalidation |
591 // service is made available to the |consumer_| and the device-global | 605 // service is made available to the |consumer_| and the device-global |
592 // invalidation service is destroyed. | 606 // invalidation service is destroyed. |
593 LogInAsAffiliatedUserAndConnectInvalidationService(); | 607 LogInAsAffiliatedUserAndConnectInvalidationService(); |
594 | 608 |
595 // Shut down the |provider_|. Verify that the |consumer_| is informed that no | 609 // Shut down the |provider_|. Verify that the |consumer_| is informed that no |
596 // invalidation service is available for use anymore. | 610 // invalidation service is available for use anymore. |
597 EXPECT_CALL(consumer_, OnInvalidationServiceSet(nullptr)).Times(1); | 611 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); |
598 provider_->Shutdown(); | 612 provider_->Shutdown(); |
599 Mock::VerifyAndClearExpectations(&consumer_); | 613 EXPECT_EQ(1, consumer_->GetAndClearInvalidationServiceSetCount()); |
614 EXPECT_EQ(nullptr, consumer_->GetInvalidationService()); | |
600 | 615 |
601 // Verify that the device-global invalidation service still does not exist. | 616 // Verify that the device-global invalidation service still does not exist. |
602 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 617 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
603 | 618 |
604 // Log in as a second affiliated user. | 619 // Log in as a second affiliated user. |
605 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); | 620 Profile* second_profile = LogInAndReturnProfile(kAffiliatedUserID2); |
606 EXPECT_TRUE(second_profile); | 621 EXPECT_TRUE(second_profile); |
607 | 622 |
608 // Verify that the device-global invalidation service still does not exist. | 623 // Verify that the device-global invalidation service still does not exist. |
609 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 624 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
610 | 625 |
611 // Create a per-profile invalidation service for the second user. | 626 // Create a per-profile invalidation service for the second user. |
612 invalidation::FakeInvalidationService* second_profile_invalidation_service = | 627 invalidation::FakeInvalidationService* second_profile_invalidation_service = |
613 GetProfileInvalidationService(second_profile, true /* create */); | 628 GetProfileInvalidationService(second_profile, true /* create */); |
614 ASSERT_TRUE(second_profile_invalidation_service); | 629 ASSERT_TRUE(second_profile_invalidation_service); |
615 | 630 |
616 // Indicate that the second user's per-profile invalidation service has | 631 // Indicate that the second user's per-profile invalidation service has |
617 // connected. Verify that the consumer is not called back. | 632 // connected. Verify that the consumer is not called back. |
618 second_profile_invalidation_service->SetInvalidatorState( | 633 second_profile_invalidation_service->SetInvalidatorState( |
619 syncer::INVALIDATIONS_ENABLED); | 634 syncer::INVALIDATIONS_ENABLED); |
635 EXPECT_EQ(0, consumer_->GetAndClearInvalidationServiceSetCount()); | |
620 | 636 |
621 // Verify that the device-global invalidation service still does not exist. | 637 // Verify that the device-global invalidation service still does not exist. |
622 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); | 638 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); |
623 | |
624 // Unregister the consumer. | |
625 provider_->UnregisterConsumer(&consumer_); | |
626 Mock::VerifyAndClearExpectations(&consumer_); | |
627 } | 639 } |
628 | 640 |
629 } // namespace policy | 641 } // namespace policy |
OLD | NEW |