Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/chromeos/policy/affiliated_invalidation_service_provider_impl_unittest.cc

Issue 822523003: Implement device-local account policy pushing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_2_442800_switch_device_cloud_policy_invalidator
Patch Set: Rebased. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 MockConsumer(); 61 MockConsumer();
62 ~MockConsumer() override; 62 ~MockConsumer() override;
63 63
64 MOCK_METHOD1(OnInvalidationServiceSet, 64 MOCK_METHOD1(OnInvalidationServiceSet,
65 void(invalidation::InvalidationService*)); 65 void(invalidation::InvalidationService*));
66 66
67 private: 67 private:
68 DISALLOW_COPY_AND_ASSIGN(MockConsumer); 68 DISALLOW_COPY_AND_ASSIGN(MockConsumer);
69 }; 69 };
70 70
71 class AffiliatedInvalidationServiceProviderTest : public testing::Test { 71 class AffiliatedInvalidationServiceProviderImplTest : public testing::Test {
72 public: 72 public:
73 AffiliatedInvalidationServiceProviderTest(); 73 AffiliatedInvalidationServiceProviderImplTest();
74 74
75 // testing::Test: 75 // testing::Test:
76 virtual void SetUp() override; 76 virtual void SetUp() override;
77 virtual void TearDown() override; 77 virtual void TearDown() override;
78 78
79 // Ownership is not passed. The Profile is owned by the global ProfileManager. 79 // Ownership is not passed. The Profile is owned by the global ProfileManager.
80 Profile* LogInAndReturnProfile(const std::string& user_id); 80 Profile* LogInAndReturnProfile(const std::string& user_id);
81 81
82 // Logs in as an affiliated user and indicates that the per-profile 82 // Logs in as an affiliated user and indicates that the per-profile
83 // invalidation service for this user connected. Verifies that this 83 // invalidation service for this user connected. Verifies that this
(...skipping 14 matching lines...) Expand all
98 // Indicates that the logged-in user's per-profile invalidation service 98 // Indicates that the logged-in user's per-profile invalidation service
99 // disconnected. Verifies that the |consumer_| is informed about this and a 99 // disconnected. Verifies that the |consumer_| is informed about this and a
100 // device-global invalidation service is created. 100 // device-global invalidation service is created.
101 void DisconnectPerProfileInvalidationService(); 101 void DisconnectPerProfileInvalidationService();
102 102
103 invalidation::FakeInvalidationService* GetProfileInvalidationService( 103 invalidation::FakeInvalidationService* GetProfileInvalidationService(
104 Profile* profile, 104 Profile* profile,
105 bool create); 105 bool create);
106 106
107 protected: 107 protected:
108 scoped_ptr<AffiliatedInvalidationServiceProvider> provider_; 108 scoped_ptr<AffiliatedInvalidationServiceProviderImpl> provider_;
109 StrictMock<MockConsumer> consumer_; 109 StrictMock<MockConsumer> consumer_;
110 invalidation::TiclInvalidationService* device_invalidation_service_; 110 invalidation::TiclInvalidationService* device_invalidation_service_;
111 invalidation::FakeInvalidationService* profile_invalidation_service_; 111 invalidation::FakeInvalidationService* profile_invalidation_service_;
112 112
113 private: 113 private:
114 content::TestBrowserThreadBundle thread_bundle_; 114 content::TestBrowserThreadBundle thread_bundle_;
115 chromeos::FakeChromeUserManager* fake_user_manager_; 115 chromeos::FakeChromeUserManager* fake_user_manager_;
116 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 116 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
117 ScopedStubEnterpriseInstallAttributes install_attributes_; 117 ScopedStubEnterpriseInstallAttributes install_attributes_;
118 scoped_ptr<chromeos::ScopedTestDeviceSettingsService> 118 scoped_ptr<chromeos::ScopedTestDeviceSettingsService>
119 test_device_settings_service_; 119 test_device_settings_service_;
120 scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_; 120 scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_;
121 TestingProfileManager profile_manager_; 121 TestingProfileManager profile_manager_;
122 }; 122 };
123 123
124 MockConsumer::MockConsumer() { 124 MockConsumer::MockConsumer() {
125 } 125 }
126 126
127 MockConsumer::~MockConsumer() { 127 MockConsumer::~MockConsumer() {
128 } 128 }
129 129
130 AffiliatedInvalidationServiceProviderTest:: 130 AffiliatedInvalidationServiceProviderImplTest::
131 AffiliatedInvalidationServiceProviderTest() 131 AffiliatedInvalidationServiceProviderImplTest()
132 : device_invalidation_service_(nullptr), 132 : device_invalidation_service_(nullptr),
133 profile_invalidation_service_(nullptr), 133 profile_invalidation_service_(nullptr),
134 fake_user_manager_(new chromeos::FakeChromeUserManager), 134 fake_user_manager_(new chromeos::FakeChromeUserManager),
135 user_manager_enabler_(fake_user_manager_), 135 user_manager_enabler_(fake_user_manager_),
136 install_attributes_("example.com", 136 install_attributes_("example.com",
137 "user@example.com", 137 "user@example.com",
138 "device_id", 138 "device_id",
139 DEVICE_MODE_ENTERPRISE), 139 DEVICE_MODE_ENTERPRISE),
140 profile_manager_(TestingBrowserProcess::GetGlobal()) { 140 profile_manager_(TestingBrowserProcess::GetGlobal()) {
141 } 141 }
142 142
143 void AffiliatedInvalidationServiceProviderTest::SetUp() { 143 void AffiliatedInvalidationServiceProviderImplTest::SetUp() {
144 chromeos::SystemSaltGetter::Initialize(); 144 chromeos::SystemSaltGetter::Initialize();
145 chromeos::DBusThreadManager::Initialize(); 145 chromeos::DBusThreadManager::Initialize();
146 ASSERT_TRUE(profile_manager_.SetUp()); 146 ASSERT_TRUE(profile_manager_.SetUp());
147 147
148 test_device_settings_service_.reset(new 148 test_device_settings_service_.reset(new
149 chromeos::ScopedTestDeviceSettingsService); 149 chromeos::ScopedTestDeviceSettingsService);
150 test_cros_settings_.reset(new chromeos::ScopedTestCrosSettings); 150 test_cros_settings_.reset(new chromeos::ScopedTestCrosSettings);
151 chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); 151 chromeos::DeviceOAuth2TokenServiceFactory::Initialize();
152 152
153 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> 153 invalidation::ProfileInvalidationProviderFactory::GetInstance()->
154 RegisterTestingFactory(BuildProfileInvalidationProvider); 154 RegisterTestingFactory(BuildProfileInvalidationProvider);
155 155
156 provider_.reset(new AffiliatedInvalidationServiceProvider); 156 provider_.reset(new AffiliatedInvalidationServiceProviderImpl);
157 } 157 }
158 158
159 void AffiliatedInvalidationServiceProviderTest::TearDown() { 159 void AffiliatedInvalidationServiceProviderImplTest::TearDown() {
160 provider_->Shutdown(); 160 provider_->Shutdown();
161 provider_.reset(); 161 provider_.reset();
162 162
163 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> 163 invalidation::ProfileInvalidationProviderFactory::GetInstance()->
164 RegisterTestingFactory(nullptr); 164 RegisterTestingFactory(nullptr);
165 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); 165 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown();
166 chromeos::DBusThreadManager::Shutdown(); 166 chromeos::DBusThreadManager::Shutdown();
167 chromeos::SystemSaltGetter::Shutdown(); 167 chromeos::SystemSaltGetter::Shutdown();
168 } 168 }
169 169
170 Profile* AffiliatedInvalidationServiceProviderTest::LogInAndReturnProfile( 170 Profile* AffiliatedInvalidationServiceProviderImplTest::LogInAndReturnProfile(
171 const std::string& user_id) { 171 const std::string& user_id) {
172 fake_user_manager_->AddUser(user_id); 172 fake_user_manager_->AddUser(user_id);
173 Profile* profile = profile_manager_.CreateTestingProfile(user_id); 173 Profile* profile = profile_manager_.CreateTestingProfile(user_id);
174 content::NotificationService::current()->Notify( 174 content::NotificationService::current()->Notify(
175 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 175 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
176 content::NotificationService::AllSources(), 176 content::NotificationService::AllSources(),
177 content::Details<Profile>(profile)); 177 content::Details<Profile>(profile));
178 return profile; 178 return profile;
179 } 179 }
180 180
181 void AffiliatedInvalidationServiceProviderTest:: 181 void AffiliatedInvalidationServiceProviderImplTest::
182 LogInAsAffiliatedUserAndConnectInvalidationService() { 182 LogInAsAffiliatedUserAndConnectInvalidationService() {
183 Mock::VerifyAndClearExpectations(&consumer_); 183 Mock::VerifyAndClearExpectations(&consumer_);
184 184
185 // Log in as an affiliated user. 185 // Log in as an affiliated user.
186 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); 186 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1);
187 EXPECT_TRUE(profile); 187 EXPECT_TRUE(profile);
188 Mock::VerifyAndClearExpectations(&consumer_); 188 Mock::VerifyAndClearExpectations(&consumer_);
189 189
190 // Verify that a per-profile invalidation service has been created. 190 // Verify that a per-profile invalidation service has been created.
191 profile_invalidation_service_ = 191 profile_invalidation_service_ =
(...skipping 10 matching lines...) Expand all
202 profile_invalidation_service_->SetInvalidatorState( 202 profile_invalidation_service_->SetInvalidatorState(
203 syncer::INVALIDATIONS_ENABLED); 203 syncer::INVALIDATIONS_ENABLED);
204 Mock::VerifyAndClearExpectations(&consumer_); 204 Mock::VerifyAndClearExpectations(&consumer_);
205 205
206 // Verify that the device-global invalidation service has been destroyed. 206 // Verify that the device-global invalidation service has been destroyed.
207 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); 207 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest());
208 208
209 Mock::VerifyAndClearExpectations(&consumer_); 209 Mock::VerifyAndClearExpectations(&consumer_);
210 } 210 }
211 211
212 void AffiliatedInvalidationServiceProviderTest:: 212 void AffiliatedInvalidationServiceProviderImplTest::
213 LogInAsUnaffiliatedUserAndConnectInvalidationService() { 213 LogInAsUnaffiliatedUserAndConnectInvalidationService() {
214 Mock::VerifyAndClearExpectations(&consumer_); 214 Mock::VerifyAndClearExpectations(&consumer_);
215 215
216 // Log in as an unaffiliated user. 216 // Log in as an unaffiliated user.
217 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); 217 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID);
218 EXPECT_TRUE(profile); 218 EXPECT_TRUE(profile);
219 219
220 // Verify that a per-profile invalidation service has been created. 220 // Verify that a per-profile invalidation service has been created.
221 profile_invalidation_service_ = 221 profile_invalidation_service_ =
222 GetProfileInvalidationService(profile, false /* create */); 222 GetProfileInvalidationService(profile, false /* create */);
223 ASSERT_TRUE(profile_invalidation_service_); 223 ASSERT_TRUE(profile_invalidation_service_);
224 224
225 // Verify that the device-global invalidation service still exists. 225 // Verify that the device-global invalidation service still exists.
226 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 226 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
227 227
228 // Indicate that the per-profile invalidation service has connected. Verify 228 // Indicate that the per-profile invalidation service has connected. Verify
229 // that the consumer is not called back. 229 // that the consumer is not called back.
230 profile_invalidation_service_->SetInvalidatorState( 230 profile_invalidation_service_->SetInvalidatorState(
231 syncer::INVALIDATIONS_ENABLED); 231 syncer::INVALIDATIONS_ENABLED);
232 232
233 // Verify that the device-global invalidation service still exists. 233 // Verify that the device-global invalidation service still exists.
234 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 234 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
235 235
236 Mock::VerifyAndClearExpectations(&consumer_); 236 Mock::VerifyAndClearExpectations(&consumer_);
237 } 237 }
238 238
239 void AffiliatedInvalidationServiceProviderTest:: 239 void AffiliatedInvalidationServiceProviderImplTest::
240 ConnectDeviceGlobalInvalidationService() { 240 ConnectDeviceGlobalInvalidationService() {
241 Mock::VerifyAndClearExpectations(&consumer_); 241 Mock::VerifyAndClearExpectations(&consumer_);
242 242
243 // Verify that a device-global invalidation service has been created. 243 // Verify that a device-global invalidation service has been created.
244 device_invalidation_service_ = 244 device_invalidation_service_ =
245 provider_->GetDeviceInvalidationServiceForTest(); 245 provider_->GetDeviceInvalidationServiceForTest();
246 ASSERT_TRUE(device_invalidation_service_); 246 ASSERT_TRUE(device_invalidation_service_);
247 247
248 // Indicate that the device-global invalidation service has connected. Verify 248 // Indicate that the device-global invalidation service has connected. Verify
249 // that the consumer is informed about this. 249 // that the consumer is informed about this.
250 EXPECT_CALL(consumer_, OnInvalidationServiceSet(device_invalidation_service_)) 250 EXPECT_CALL(consumer_, OnInvalidationServiceSet(device_invalidation_service_))
251 .Times(1); 251 .Times(1);
252 device_invalidation_service_->OnInvalidatorStateChange( 252 device_invalidation_service_->OnInvalidatorStateChange(
253 syncer::INVALIDATIONS_ENABLED); 253 syncer::INVALIDATIONS_ENABLED);
254 254
255 Mock::VerifyAndClearExpectations(&consumer_); 255 Mock::VerifyAndClearExpectations(&consumer_);
256 } 256 }
257 257
258 void AffiliatedInvalidationServiceProviderTest:: 258 void AffiliatedInvalidationServiceProviderImplTest::
259 DisconnectPerProfileInvalidationService() { 259 DisconnectPerProfileInvalidationService() {
260 Mock::VerifyAndClearExpectations(&consumer_); 260 Mock::VerifyAndClearExpectations(&consumer_);
261 261
262 ASSERT_TRUE(profile_invalidation_service_); 262 ASSERT_TRUE(profile_invalidation_service_);
263 263
264 // Indicate that the per-profile invalidation service has disconnected. Verify 264 // Indicate that the per-profile invalidation service has disconnected. Verify
265 // that the consumer is informed about this. 265 // that the consumer is informed about this.
266 EXPECT_CALL(consumer_, OnInvalidationServiceSet(nullptr)).Times(1); 266 EXPECT_CALL(consumer_, OnInvalidationServiceSet(nullptr)).Times(1);
267 profile_invalidation_service_->SetInvalidatorState( 267 profile_invalidation_service_->SetInvalidatorState(
268 syncer::INVALIDATION_CREDENTIALS_REJECTED); 268 syncer::INVALIDATION_CREDENTIALS_REJECTED);
269 269
270 // Verify that a device-global invalidation service has been created. 270 // Verify that a device-global invalidation service has been created.
271 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 271 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
272 272
273 Mock::VerifyAndClearExpectations(&consumer_); 273 Mock::VerifyAndClearExpectations(&consumer_);
274 } 274 }
275 275
276 invalidation::FakeInvalidationService* 276 invalidation::FakeInvalidationService*
277 AffiliatedInvalidationServiceProviderTest::GetProfileInvalidationService( 277 AffiliatedInvalidationServiceProviderImplTest::GetProfileInvalidationService(
278 Profile* profile, bool create) { 278 Profile* profile, bool create) {
279 invalidation::ProfileInvalidationProvider* invalidation_provider = 279 invalidation::ProfileInvalidationProvider* invalidation_provider =
280 static_cast<invalidation::ProfileInvalidationProvider*>( 280 static_cast<invalidation::ProfileInvalidationProvider*>(
281 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> 281 invalidation::ProfileInvalidationProviderFactory::GetInstance()->
282 GetServiceForBrowserContext(profile, create)); 282 GetServiceForBrowserContext(profile, create));
283 if (!invalidation_provider) 283 if (!invalidation_provider)
284 return nullptr; 284 return nullptr;
285 return static_cast<invalidation::FakeInvalidationService*>( 285 return static_cast<invalidation::FakeInvalidationService*>(
286 invalidation_provider->GetInvalidationService()); 286 invalidation_provider->GetInvalidationService());
287 } 287 }
288 288
289 // No consumers are registered with the AffiliatedInvalidationServiceProvider. 289 // No consumers are registered with the
290 // Verifies that no device-global invalidation service is created, whether an 290 // AffiliatedInvalidationServiceProviderImpl. Verifies that no device-global
291 // affiliated user is logged in or not. 291 // invalidation service is created, whether an affiliated user is logged in or
292 TEST_F(AffiliatedInvalidationServiceProviderTest, NoConsumers) { 292 // not.
293 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoConsumers) {
293 // Verify that no device-global invalidation service has been created. 294 // Verify that no device-global invalidation service has been created.
294 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); 295 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest());
295 296
296 // Log in as an affiliated user. 297 // Log in as an affiliated user.
297 EXPECT_TRUE(LogInAndReturnProfile(kAffiliatedUserID1)); 298 EXPECT_TRUE(LogInAndReturnProfile(kAffiliatedUserID1));
298 299
299 // Verify that no device-global invalidation service has been created. 300 // Verify that no device-global invalidation service has been created.
300 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); 301 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest());
301 } 302 }
302 303
303 // A consumer is registered with the AffiliatedInvalidationServiceProvider. 304 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
304 // Verifies that when no per-profile invalidation service belonging to an 305 // Verifies that when no per-profile invalidation service belonging to an
305 // affiliated user is available, a device-global invalidation service is 306 // affiliated user is available, a device-global invalidation service is
306 // created. Further verifies that when the device-global invalidation service 307 // created. Further verifies that when the device-global invalidation service
307 // connects, it is made available to the consumer. 308 // connects, it is made available to the consumer.
308 TEST_F(AffiliatedInvalidationServiceProviderTest, 309 TEST_F(AffiliatedInvalidationServiceProviderImplTest,
309 UseDeviceInvalidationService) { 310 UseDeviceInvalidationService) {
310 // Register a consumer. Verify that the consumer is not called back 311 // Register a consumer. Verify that the consumer is not called back
311 // immediately as no connected invalidation service exists yet. 312 // immediately as no connected invalidation service exists yet.
312 provider_->RegisterConsumer(&consumer_); 313 provider_->RegisterConsumer(&consumer_);
313 314
314 // Indicate that the device-global invalidation service connected. Verify that 315 // Indicate that the device-global invalidation service connected. Verify that
315 // that the consumer is informed about this. 316 // that the consumer is informed about this.
316 ConnectDeviceGlobalInvalidationService(); 317 ConnectDeviceGlobalInvalidationService();
317 318
318 // Indicate that the device-global invalidation service has disconnected. 319 // Indicate that the device-global invalidation service has disconnected.
319 // Verify that the consumer is informed about this. 320 // Verify that the consumer is informed about this.
320 EXPECT_CALL(consumer_, OnInvalidationServiceSet(nullptr)).Times(1); 321 EXPECT_CALL(consumer_, OnInvalidationServiceSet(nullptr)).Times(1);
321 device_invalidation_service_->OnInvalidatorStateChange( 322 device_invalidation_service_->OnInvalidatorStateChange(
322 syncer::INVALIDATION_CREDENTIALS_REJECTED); 323 syncer::INVALIDATION_CREDENTIALS_REJECTED);
323 Mock::VerifyAndClearExpectations(&consumer_); 324 Mock::VerifyAndClearExpectations(&consumer_);
324 325
325 // Verify that the device-global invalidation service still exists. 326 // Verify that the device-global invalidation service still exists.
326 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 327 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
327 328
328 // Unregister the consumer. 329 // Unregister the consumer.
329 provider_->UnregisterConsumer(&consumer_); 330 provider_->UnregisterConsumer(&consumer_);
330 Mock::VerifyAndClearExpectations(&consumer_); 331 Mock::VerifyAndClearExpectations(&consumer_);
331 } 332 }
332 333
333 // A consumer is registered with the AffiliatedInvalidationServiceProvider. 334 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
334 // Verifies that when a per-profile invalidation service belonging to an 335 // Verifies that when a per-profile invalidation service belonging to an
335 // affiliated user connects, it is made available to the consumer. 336 // affiliated user connects, it is made available to the consumer.
336 TEST_F(AffiliatedInvalidationServiceProviderTest, 337 TEST_F(AffiliatedInvalidationServiceProviderImplTest,
337 UseAffiliatedProfileInvalidationService) { 338 UseAffiliatedProfileInvalidationService) {
338 // Register a consumer. Verify that the consumer is not called back 339 // Register a consumer. Verify that the consumer is not called back
339 // immediately as no connected invalidation service exists yet. 340 // immediately as no connected invalidation service exists yet.
340 provider_->RegisterConsumer(&consumer_); 341 provider_->RegisterConsumer(&consumer_);
341 342
342 // Verify that a device-global invalidation service has been created. 343 // Verify that a device-global invalidation service has been created.
343 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 344 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
344 345
345 // Log in as an affiliated user and indicate that the per-profile invalidation 346 // Log in as an affiliated user and indicate that the per-profile invalidation
346 // service for this user connected. Verify that this invalidation service is 347 // service for this user connected. Verify that this invalidation service is
347 // made available to the |consumer_| and the device-global invalidation 348 // made available to the |consumer_| and the device-global invalidation
348 // service is destroyed. 349 // service is destroyed.
349 LogInAsAffiliatedUserAndConnectInvalidationService(); 350 LogInAsAffiliatedUserAndConnectInvalidationService();
350 351
351 // Indicate that the logged-in user's per-profile invalidation service 352 // Indicate that the logged-in user's per-profile invalidation service
352 // disconnected. Verify that the consumer is informed about this and a 353 // disconnected. Verify that the consumer is informed about this and a
353 // device-global invalidation service is created. 354 // device-global invalidation service is created.
354 DisconnectPerProfileInvalidationService(); 355 DisconnectPerProfileInvalidationService();
355 356
356 // Unregister the consumer. 357 // Unregister the consumer.
357 provider_->UnregisterConsumer(&consumer_); 358 provider_->UnregisterConsumer(&consumer_);
358 Mock::VerifyAndClearExpectations(&consumer_); 359 Mock::VerifyAndClearExpectations(&consumer_);
359 } 360 }
360 361
361 // A consumer is registered with the AffiliatedInvalidationServiceProvider. 362 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
362 // Verifies that when a per-profile invalidation service belonging to an 363 // Verifies that when a per-profile invalidation service belonging to an
363 // unaffiliated user connects, it is ignored. 364 // unaffiliated user connects, it is ignored.
364 TEST_F(AffiliatedInvalidationServiceProviderTest, 365 TEST_F(AffiliatedInvalidationServiceProviderImplTest,
365 DoNotUseUnaffiliatedProfileInvalidationService) { 366 DoNotUseUnaffiliatedProfileInvalidationService) {
366 // Register a consumer. Verify that the consumer is not called back 367 // Register a consumer. Verify that the consumer is not called back
367 // immediately as no connected invalidation service exists yet. 368 // immediately as no connected invalidation service exists yet.
368 provider_->RegisterConsumer(&consumer_); 369 provider_->RegisterConsumer(&consumer_);
369 370
370 // Verify that a device-global invalidation service has been created. 371 // Verify that a device-global invalidation service has been created.
371 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 372 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
372 373
373 // Log in as an unaffiliated user and indicate that the per-profile 374 // Log in as an unaffiliated user and indicate that the per-profile
374 // invalidation service for this user connected. Verify that this invalidation 375 // invalidation service for this user connected. Verify that this invalidation
375 // service is ignored and the device-global invalidation service is not 376 // service is ignored and the device-global invalidation service is not
376 // destroyed. 377 // destroyed.
377 LogInAsUnaffiliatedUserAndConnectInvalidationService(); 378 LogInAsUnaffiliatedUserAndConnectInvalidationService();
378 379
379 // Unregister the consumer. 380 // Unregister the consumer.
380 provider_->UnregisterConsumer(&consumer_); 381 provider_->UnregisterConsumer(&consumer_);
381 Mock::VerifyAndClearExpectations(&consumer_); 382 Mock::VerifyAndClearExpectations(&consumer_);
382 } 383 }
383 384
384 // A consumer is registered with the AffiliatedInvalidationServiceProvider. A 385 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
385 // device-global invalidation service exists, is connected and is made available 386 // A device-global invalidation service exists, is connected and is made
386 // to the consumer. Verifies that when a per-profile invalidation service 387 // available to the consumer. Verifies that when a per-profile invalidation
387 // belonging to an affiliated user connects, it is made available to the 388 // service belonging to an affiliated user connects, it is made available to the
388 // consumer instead and the device-global invalidation service is destroyed. 389 // consumer instead and the device-global invalidation service is destroyed.
389 TEST_F(AffiliatedInvalidationServiceProviderTest, 390 TEST_F(AffiliatedInvalidationServiceProviderImplTest,
390 SwitchToAffiliatedProfileInvalidationService) { 391 SwitchToAffiliatedProfileInvalidationService) {
391 // Register a consumer. Verify that the consumer is not called back 392 // Register a consumer. Verify that the consumer is not called back
392 // immediately as no connected invalidation service exists yet. 393 // immediately as no connected invalidation service exists yet.
393 provider_->RegisterConsumer(&consumer_); 394 provider_->RegisterConsumer(&consumer_);
394 395
395 // Indicate that the device-global invalidation service connected. Verify that 396 // Indicate that the device-global invalidation service connected. Verify that
396 // that the consumer is informed about this. 397 // that the consumer is informed about this.
397 ConnectDeviceGlobalInvalidationService(); 398 ConnectDeviceGlobalInvalidationService();
398 399
399 // Log in as an affiliated user and indicate that the per-profile invalidation 400 // Log in as an affiliated user and indicate that the per-profile invalidation
400 // service for this user connected. Verify that this invalidation service is 401 // service for this user connected. Verify that this invalidation service is
401 // made available to the |consumer_| and the device-global invalidation 402 // made available to the |consumer_| and the device-global invalidation
402 // service is destroyed. 403 // service is destroyed.
403 LogInAsAffiliatedUserAndConnectInvalidationService(); 404 LogInAsAffiliatedUserAndConnectInvalidationService();
404 405
405 // Unregister the consumer. 406 // Unregister the consumer.
406 provider_->UnregisterConsumer(&consumer_); 407 provider_->UnregisterConsumer(&consumer_);
407 Mock::VerifyAndClearExpectations(&consumer_); 408 Mock::VerifyAndClearExpectations(&consumer_);
408 } 409 }
409 410
410 // A consumer is registered with the AffiliatedInvalidationServiceProvider. A 411 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
411 // device-global invalidation service exists, is connected and is made available 412 // A device-global invalidation service exists, is connected and is made
412 // to the consumer. Verifies that when a per-profile invalidation service 413 // available to the consumer. Verifies that when a per-profile invalidation
413 // belonging to an unaffiliated user connects, it is ignored and the 414 // service belonging to an unaffiliated user connects, it is ignored and the
414 // device-global invalidation service continues to be made available to the 415 // device-global invalidation service continues to be made available to the
415 // consumer. 416 // consumer.
416 TEST_F(AffiliatedInvalidationServiceProviderTest, 417 TEST_F(AffiliatedInvalidationServiceProviderImplTest,
417 DoNotSwitchToUnaffiliatedProfileInvalidationService) { 418 DoNotSwitchToUnaffiliatedProfileInvalidationService) {
418 // Register a consumer. Verify that the consumer is not called back 419 // Register a consumer. Verify that the consumer is not called back
419 // immediately as no connected invalidation service exists yet. 420 // immediately as no connected invalidation service exists yet.
420 provider_->RegisterConsumer(&consumer_); 421 provider_->RegisterConsumer(&consumer_);
421 422
422 // Indicate that the device-global invalidation service connected. Verify that 423 // Indicate that the device-global invalidation service connected. Verify that
423 // that the consumer is informed about this. 424 // that the consumer is informed about this.
424 ConnectDeviceGlobalInvalidationService(); 425 ConnectDeviceGlobalInvalidationService();
425 426
426 // Log in as an unaffiliated user and indicate that the per-profile 427 // Log in as an unaffiliated user and indicate that the per-profile
427 // invalidation service for this user connected. Verify that this invalidation 428 // invalidation service for this user connected. Verify that this invalidation
428 // service is ignored and the device-global invalidation service is not 429 // service is ignored and the device-global invalidation service is not
429 // destroyed. 430 // destroyed.
430 LogInAsUnaffiliatedUserAndConnectInvalidationService(); 431 LogInAsUnaffiliatedUserAndConnectInvalidationService();
431 432
432 // Unregister the consumer. 433 // Unregister the consumer.
433 provider_->UnregisterConsumer(&consumer_); 434 provider_->UnregisterConsumer(&consumer_);
434 Mock::VerifyAndClearExpectations(&consumer_); 435 Mock::VerifyAndClearExpectations(&consumer_);
435 } 436 }
436 437
437 // A consumer is registered with the AffiliatedInvalidationServiceProvider. A 438 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
438 // per-profile invalidation service belonging to an affiliated user exists, is 439 // A per-profile invalidation service belonging to an affiliated user exists, is
439 // connected and is made available to the consumer. Verifies that when the 440 // connected and is made available to the consumer. Verifies that when the
440 // per-profile invalidation service disconnects, a device-global invalidation 441 // per-profile invalidation service disconnects, a device-global invalidation
441 // service is created. Further verifies that when the device-global invalidation 442 // service is created. Further verifies that when the device-global invalidation
442 // service connects, it is made available to the consumer. 443 // service connects, it is made available to the consumer.
443 TEST_F(AffiliatedInvalidationServiceProviderTest, 444 TEST_F(AffiliatedInvalidationServiceProviderImplTest,
444 SwitchToDeviceInvalidationService) { 445 SwitchToDeviceInvalidationService) {
445 // Register a consumer. Verify that the consumer is not called back 446 // Register a consumer. Verify that the consumer is not called back
446 // immediately as no connected invalidation service exists yet. 447 // immediately as no connected invalidation service exists yet.
447 provider_->RegisterConsumer(&consumer_); 448 provider_->RegisterConsumer(&consumer_);
448 449
449 // Verify that a device-global invalidation service has been created. 450 // Verify that a device-global invalidation service has been created.
450 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 451 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
451 452
452 // Log in as an affiliated user and indicate that the per-profile invalidation 453 // Log in as an affiliated user and indicate that the per-profile invalidation
453 // service for this user connected. Verify that this invalidation service is 454 // service for this user connected. Verify that this invalidation service is
454 // made available to the |consumer_| and the device-global invalidation 455 // made available to the |consumer_| and the device-global invalidation
455 // service is destroyed. 456 // service is destroyed.
456 LogInAsAffiliatedUserAndConnectInvalidationService(); 457 LogInAsAffiliatedUserAndConnectInvalidationService();
457 458
458 // Indicate that the logged-in user's per-profile invalidation service 459 // Indicate that the logged-in user's per-profile invalidation service
459 // disconnected. Verify that the consumer is informed about this and a 460 // disconnected. Verify that the consumer is informed about this and a
460 // device-global invalidation service is created. 461 // device-global invalidation service is created.
461 DisconnectPerProfileInvalidationService(); 462 DisconnectPerProfileInvalidationService();
462 463
463 // Indicate that the device-global invalidation service connected. Verify that 464 // Indicate that the device-global invalidation service connected. Verify that
464 // that the consumer is informed about this. 465 // that the consumer is informed about this.
465 ConnectDeviceGlobalInvalidationService(); 466 ConnectDeviceGlobalInvalidationService();
466 467
467 // Unregister the consumer. 468 // Unregister the consumer.
468 provider_->UnregisterConsumer(&consumer_); 469 provider_->UnregisterConsumer(&consumer_);
469 Mock::VerifyAndClearExpectations(&consumer_); 470 Mock::VerifyAndClearExpectations(&consumer_);
470 } 471 }
471 472
472 // A consumer is registered with the AffiliatedInvalidationServiceProvider. A 473 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
473 // per-profile invalidation service belonging to a first affiliated user exists, 474 // A per-profile invalidation service belonging to a first affiliated user
474 // is connected and is made available to the consumer. A per-profile 475 // exists, is connected and is made available to the consumer. A per-profile
475 // invalidation service belonging to a second affiliated user also exists and is 476 // invalidation service belonging to a second affiliated user also exists and is
476 // connected. Verifies that when the per-profile invalidation service belonging 477 // connected. Verifies that when the per-profile invalidation service belonging
477 // to the first user disconnects, the per-profile invalidation service belonging 478 // to the first user disconnects, the per-profile invalidation service belonging
478 // to the second user is made available to the consumer instead. 479 // to the second user is made available to the consumer instead.
479 TEST_F(AffiliatedInvalidationServiceProviderTest, 480 TEST_F(AffiliatedInvalidationServiceProviderImplTest,
480 SwitchBetweenAffiliatedProfileInvalidationServices) { 481 SwitchBetweenAffiliatedProfileInvalidationServices) {
481 // Register a consumer. Verify that the consumer is not called back 482 // Register a consumer. Verify that the consumer is not called back
482 // immediately as no connected invalidation service exists yet. 483 // immediately as no connected invalidation service exists yet.
483 provider_->RegisterConsumer(&consumer_); 484 provider_->RegisterConsumer(&consumer_);
484 485
485 // Verify that a device-global invalidation service has been created. 486 // Verify that a device-global invalidation service has been created.
486 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 487 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
487 488
488 // Log in as a first affiliated user and indicate that the per-profile 489 // Log in as a first affiliated user and indicate that the per-profile
489 // invalidation service for this user connected. Verify that this invalidation 490 // invalidation service for this user connected. Verify that this invalidation
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 Mock::VerifyAndClearExpectations(&consumer_); 523 Mock::VerifyAndClearExpectations(&consumer_);
523 524
524 // Verify that the device-global invalidation service still does not exist. 525 // Verify that the device-global invalidation service still does not exist.
525 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); 526 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest());
526 527
527 // Unregister the consumer. 528 // Unregister the consumer.
528 provider_->UnregisterConsumer(&consumer_); 529 provider_->UnregisterConsumer(&consumer_);
529 Mock::VerifyAndClearExpectations(&consumer_); 530 Mock::VerifyAndClearExpectations(&consumer_);
530 } 531 }
531 532
532 // A consumer is registered with the AffiliatedInvalidationServiceProvider. A 533 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
533 // device-global invalidation service exists, is connected and is made available 534 // A device-global invalidation service exists, is connected and is made
534 // to the consumer. Verifies that when a second consumer registers, the 535 // available to the consumer. Verifies that when a second consumer registers,
535 // device-global invalidation service is made available to it as well. Further 536 // the device-global invalidation service is made available to it as well.
536 // verifies that when the first consumer unregisters, the device-global 537 // Further verifies that when the first consumer unregisters, the device-global
537 // invalidation service is not destroyed and remains available to the second 538 // invalidation service is not destroyed and remains available to the second
538 // consumer. Further verifies that when the second consumer also unregisters, 539 // consumer. Further verifies that when the second consumer also unregisters,
539 // the device-global invalidation service is destroyed. 540 // the device-global invalidation service is destroyed.
540 TEST_F(AffiliatedInvalidationServiceProviderTest, MultipleConsumers) { 541 TEST_F(AffiliatedInvalidationServiceProviderImplTest, MultipleConsumers) {
541 // Register a first consumer. Verify that the consumer is not called back 542 // Register a first consumer. Verify that the consumer is not called back
542 // immediately as no connected invalidation service exists yet. 543 // immediately as no connected invalidation service exists yet.
543 provider_->RegisterConsumer(&consumer_); 544 provider_->RegisterConsumer(&consumer_);
544 545
545 // Indicate that the device-global invalidation service connected. Verify that 546 // Indicate that the device-global invalidation service connected. Verify that
546 // that the consumer is informed about this. 547 // that the consumer is informed about this.
547 ConnectDeviceGlobalInvalidationService(); 548 ConnectDeviceGlobalInvalidationService();
548 549
549 // Register a second consumer. Verify that the consumer is called back 550 // Register a second consumer. Verify that the consumer is called back
550 // immediately as a connected invalidation service is available. 551 // immediately as a connected invalidation service is available.
(...skipping 11 matching lines...) Expand all
562 563
563 // Unregister the second consumer. 564 // Unregister the second consumer.
564 provider_->UnregisterConsumer(&second_consumer); 565 provider_->UnregisterConsumer(&second_consumer);
565 566
566 // Verify that the device-global invalidation service has been destroyed. 567 // Verify that the device-global invalidation service has been destroyed.
567 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); 568 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest());
568 Mock::VerifyAndClearExpectations(&consumer_); 569 Mock::VerifyAndClearExpectations(&consumer_);
569 Mock::VerifyAndClearExpectations(&second_consumer); 570 Mock::VerifyAndClearExpectations(&second_consumer);
570 } 571 }
571 572
572 // A consumer is registered with the AffiliatedInvalidationServiceProvider. A 573 // A consumer is registered with the AffiliatedInvalidationServiceProviderImpl.
573 // per-profile invalidation service belonging to a first affiliated user exists, 574 // A per-profile invalidation service belonging to a first affiliated user
574 // is connected and is made available to the consumer. Verifies that when the 575 // exists, is connected and is made available to the consumer. Verifies that
575 // provider is shut down, the consumer is informed that no invalidation service 576 // when the provider is shut down, the consumer is informed that no
576 // is available for use anymore. Also verifies that no device-global 577 // invalidation service is available for use anymore. Also verifies that no
577 // invalidation service is created and a per-profile invalidation service 578 // device-global invalidation service is created and a per-profile invalidation
578 // belonging to a second affiliated user that subsequently connects is ignored. 579 // service belonging to a second affiliated user that subsequently connects is
579 TEST_F(AffiliatedInvalidationServiceProviderTest, NoServiceAfterShutdown) { 580 // ignored.
581 TEST_F(AffiliatedInvalidationServiceProviderImplTest, NoServiceAfterShutdown) {
580 // Register a consumer. Verify that the consumer is not called back 582 // Register a consumer. Verify that the consumer is not called back
581 // immediately as no connected invalidation service exists yet. 583 // immediately as no connected invalidation service exists yet.
582 provider_->RegisterConsumer(&consumer_); 584 provider_->RegisterConsumer(&consumer_);
583 585
584 // Verify that a device-global invalidation service has been created. 586 // Verify that a device-global invalidation service has been created.
585 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest()); 587 EXPECT_TRUE(provider_->GetDeviceInvalidationServiceForTest());
586 588
587 // Log in as a first affiliated user and indicate that the per-profile 589 // Log in as a first affiliated user and indicate that the per-profile
588 // invalidation service for this user connected. Verify that this invalidation 590 // invalidation service for this user connected. Verify that this invalidation
589 // service is made available to the |consumer_| and the device-global 591 // service is made available to the |consumer_| and the device-global
(...skipping 28 matching lines...) Expand all
618 620
619 // Verify that the device-global invalidation service still does not exist. 621 // Verify that the device-global invalidation service still does not exist.
620 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest()); 622 EXPECT_FALSE(provider_->GetDeviceInvalidationServiceForTest());
621 623
622 // Unregister the consumer. 624 // Unregister the consumer.
623 provider_->UnregisterConsumer(&consumer_); 625 provider_->UnregisterConsumer(&consumer_);
624 Mock::VerifyAndClearExpectations(&consumer_); 626 Mock::VerifyAndClearExpectations(&consumer_);
625 } 627 }
626 628
627 } // namespace policy 629 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698