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

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

Issue 567393006: Do not use unaffiliated users' connections for device policy pushing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « chrome/browser/chromeos/policy/device_cloud_policy_invalidator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/device_cloud_policy_invalidator.h" 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_invalidator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "chrome/browser/browser_process_platform_part.h" 12 #include "chrome/browser/browser_process_platform_part.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
14 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
15 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" 17 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
16 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 18 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
17 #include "chrome/browser/chromeos/policy/device_policy_builder.h" 19 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
18 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" 20 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 21 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 22 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
21 #include "chrome/browser/chromeos/settings/device_settings_service.h" 23 #include "chrome/browser/chromeos/settings/device_settings_service.h"
22 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 24 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
23 #include "chrome/browser/invalidation/fake_invalidation_service.h" 25 #include "chrome/browser/invalidation/fake_invalidation_service.h"
(...skipping 21 matching lines...) Expand all
45 #include "net/url_request/url_request_context_getter.h" 47 #include "net/url_request/url_request_context_getter.h"
46 #include "net/url_request/url_request_test_util.h" 48 #include "net/url_request/url_request_test_util.h"
47 #include "policy/proto/device_management_backend.pb.h" 49 #include "policy/proto/device_management_backend.pb.h"
48 #include "testing/gmock/include/gmock/gmock.h" 50 #include "testing/gmock/include/gmock/gmock.h"
49 #include "testing/gtest/include/gtest/gtest.h" 51 #include "testing/gtest/include/gtest/gtest.h"
50 52
51 namespace policy { 53 namespace policy {
52 54
53 namespace { 55 namespace {
54 56
57 const char kAffiliatedUserID1[] = "test_1@example.com";
58 const char kAffiliatedUserID2[] = "test_2@example.com";
59 const char kUnaffiliatedUserID[] = "test_2@other_domain.test";
60
55 KeyedService* BuildProfileInvalidationProvider( 61 KeyedService* BuildProfileInvalidationProvider(
56 content::BrowserContext* context) { 62 content::BrowserContext* context) {
57 scoped_ptr<invalidation::FakeInvalidationService> invalidation_service( 63 scoped_ptr<invalidation::FakeInvalidationService> invalidation_service(
58 new invalidation::FakeInvalidationService); 64 new invalidation::FakeInvalidationService);
59 invalidation_service->SetInvalidatorState( 65 invalidation_service->SetInvalidatorState(
60 syncer::TRANSIENT_INVALIDATION_ERROR); 66 syncer::TRANSIENT_INVALIDATION_ERROR);
61 return new invalidation::ProfileInvalidationProvider( 67 return new invalidation::ProfileInvalidationProvider(
62 invalidation_service.PassAs<invalidation::InvalidationService>()); 68 invalidation_service.PassAs<invalidation::InvalidationService>());
63 } 69 }
64 70
65 } // namespace 71 } // namespace
66 72
67 class DeviceCloudPolicyInvalidatorTest : public testing::Test { 73 class DeviceCloudPolicyInvalidatorTest : public testing::Test {
68 public: 74 public:
69 DeviceCloudPolicyInvalidatorTest(); 75 DeviceCloudPolicyInvalidatorTest();
70 virtual ~DeviceCloudPolicyInvalidatorTest(); 76 virtual ~DeviceCloudPolicyInvalidatorTest();
71 77
72 // testing::Test: 78 // testing::Test:
73 virtual void SetUp() OVERRIDE; 79 virtual void SetUp() OVERRIDE;
74 virtual void TearDown() OVERRIDE; 80 virtual void TearDown() OVERRIDE;
75 81
76 // Ownership is not passed. The Profile is owned by the global ProfileManager. 82 // Ownership is not passed. The Profile is owned by the global ProfileManager.
77 Profile *CreateProfile(const std::string& profile_name); 83 Profile *LogInAndReturnProfile(const std::string& user_id);
78 84
79 invalidation::TiclInvalidationService* GetDeviceInvalidationService(); 85 invalidation::TiclInvalidationService* GetDeviceInvalidationService();
80 bool HasDeviceInvalidationServiceObserver() const; 86 bool HasDeviceInvalidationServiceObserver() const;
81 87
82 invalidation::FakeInvalidationService* GetProfileInvalidationService( 88 invalidation::FakeInvalidationService* GetProfileInvalidationService(
83 Profile* profile); 89 Profile* profile);
84 int GetProfileInvalidationServiceObserverCount() const; 90 int GetProfileInvalidationServiceObserverCount() const;
85 91
86 const invalidation::InvalidationService* GetInvalidationService() const; 92 const invalidation::InvalidationService* GetInvalidationService() const;
87 CloudPolicyInvalidator* GetCloudPolicyInvalidator() const; 93 CloudPolicyInvalidator* GetCloudPolicyInvalidator() const;
88 94
89 void ConnectDeviceInvalidationService(); 95 void ConnectDeviceInvalidationService();
90 96
91 protected: 97 protected:
92 DevicePolicyBuilder device_policy_; 98 DevicePolicyBuilder device_policy_;
93 99
94 private: 100 private:
95 content::TestBrowserThreadBundle thread_bundle_; 101 content::TestBrowserThreadBundle thread_bundle_;
96 scoped_refptr<net::URLRequestContextGetter> system_request_context_; 102 scoped_refptr<net::URLRequestContextGetter> system_request_context_;
97 TestingProfileManager profile_manager_; 103 TestingProfileManager profile_manager_;
104 chromeos::FakeUserManager* fake_user_manager_;
105 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
98 ScopedStubEnterpriseInstallAttributes install_attributes_; 106 ScopedStubEnterpriseInstallAttributes install_attributes_;
99 scoped_ptr<chromeos::ScopedTestDeviceSettingsService> 107 scoped_ptr<chromeos::ScopedTestDeviceSettingsService>
100 test_device_settings_service_; 108 test_device_settings_service_;
101 scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_; 109 scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_;
102 chromeos::DeviceSettingsTestHelper device_settings_test_helper_; 110 chromeos::DeviceSettingsTestHelper device_settings_test_helper_;
103 111
104 scoped_ptr<DeviceCloudPolicyInvalidator> invalidator_; 112 scoped_ptr<DeviceCloudPolicyInvalidator> invalidator_;
105 }; 113 };
106 114
107 DeviceCloudPolicyInvalidatorTest::DeviceCloudPolicyInvalidatorTest() 115 DeviceCloudPolicyInvalidatorTest::DeviceCloudPolicyInvalidatorTest()
108 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 116 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
109 system_request_context_(new net::TestURLRequestContextGetter( 117 system_request_context_(new net::TestURLRequestContextGetter(
110 base::MessageLoopProxy::current())), 118 base::MessageLoopProxy::current())),
111 profile_manager_(TestingBrowserProcess::GetGlobal()), 119 profile_manager_(TestingBrowserProcess::GetGlobal()),
120 fake_user_manager_(new chromeos::FakeUserManager),
121 user_manager_enabler_(fake_user_manager_),
112 install_attributes_("example.com", 122 install_attributes_("example.com",
113 "user@example.com", 123 "user@example.com",
114 "device_id", 124 "device_id",
115 DEVICE_MODE_ENTERPRISE) { 125 DEVICE_MODE_ENTERPRISE) {
116 } 126 }
117 127
118 DeviceCloudPolicyInvalidatorTest::~DeviceCloudPolicyInvalidatorTest() { 128 DeviceCloudPolicyInvalidatorTest::~DeviceCloudPolicyInvalidatorTest() {
119 } 129 }
120 130
121 void DeviceCloudPolicyInvalidatorTest::SetUp() { 131 void DeviceCloudPolicyInvalidatorTest::SetUp() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 173
164 invalidation::ProfileInvalidationProviderFactory::GetInstance()-> 174 invalidation::ProfileInvalidationProviderFactory::GetInstance()->
165 RegisterTestingFactory(NULL); 175 RegisterTestingFactory(NULL);
166 chromeos::DeviceSettingsService::Get()->UnsetSessionManager(); 176 chromeos::DeviceSettingsService::Get()->UnsetSessionManager();
167 TestingBrowserProcess::GetGlobal()->SetBrowserPolicyConnector(NULL); 177 TestingBrowserProcess::GetGlobal()->SetBrowserPolicyConnector(NULL);
168 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); 178 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown();
169 chromeos::DBusThreadManager::Shutdown(); 179 chromeos::DBusThreadManager::Shutdown();
170 chromeos::SystemSaltGetter::Shutdown(); 180 chromeos::SystemSaltGetter::Shutdown();
171 } 181 }
172 182
173 Profile *DeviceCloudPolicyInvalidatorTest::CreateProfile( 183 Profile *DeviceCloudPolicyInvalidatorTest::LogInAndReturnProfile(
174 const std::string& profile_name) { 184 const std::string& user_id) {
175 Profile* profile = profile_manager_.CreateTestingProfile(profile_name); 185 fake_user_manager_->AddUser(user_id);
186 Profile* profile = profile_manager_.CreateTestingProfile(user_id);
176 content::NotificationService::current()->Notify( 187 content::NotificationService::current()->Notify(
177 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 188 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
178 content::NotificationService::AllSources(), 189 content::NotificationService::AllSources(),
179 content::Details<Profile>(profile)); 190 content::Details<Profile>(profile));
180 return profile; 191 return profile;
181 } 192 }
182 193
183 invalidation::TiclInvalidationService* 194 invalidation::TiclInvalidationService*
184 DeviceCloudPolicyInvalidatorTest::GetDeviceInvalidationService() { 195 DeviceCloudPolicyInvalidatorTest::GetDeviceInvalidationService() {
185 return invalidator_->device_invalidation_service_.get(); 196 return invalidator_->device_invalidation_service_.get();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 273
263 // Verify that the device-global invalidation service still exists. 274 // Verify that the device-global invalidation service still exists.
264 EXPECT_TRUE(GetDeviceInvalidationService()); 275 EXPECT_TRUE(GetDeviceInvalidationService());
265 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); 276 EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
266 277
267 // Verify that the invalidator has been destroyed. 278 // Verify that the invalidator has been destroyed.
268 EXPECT_FALSE(GetCloudPolicyInvalidator()); 279 EXPECT_FALSE(GetCloudPolicyInvalidator());
269 EXPECT_FALSE(GetInvalidationService()); 280 EXPECT_FALSE(GetInvalidationService());
270 } 281 }
271 282
272 // Verifies that a DeviceCloudPolicyInvalidator backed by a per-profile 283 // Verifies that when the per-profile invalidation service for an affiliated
273 // invalidation service is created/destroyed as the service 284 // user connect/disconnects, a DeviceCloudPolicyInvalidator backed by it is
274 // connects/disconnects. 285 // created/destroyed.
275 TEST_F(DeviceCloudPolicyInvalidatorTest, UseProfileInvalidationService) { 286 TEST_F(DeviceCloudPolicyInvalidatorTest,
276 // Create a user profile. 287 UseAffiliatedProfileInvalidationService) {
277 Profile* profile = CreateProfile("test"); 288 // Log in as an affiliated user.
289 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1);
278 ASSERT_TRUE(profile); 290 ASSERT_TRUE(profile);
279 291
280 // Verify that a device-global invalidation service has been created. 292 // Verify that a device-global invalidation service has been created.
281 EXPECT_TRUE(GetDeviceInvalidationService()); 293 EXPECT_TRUE(GetDeviceInvalidationService());
282 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); 294 EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
283 295
284 // Verify that a per-profile invalidation service has been created. 296 // Verify that a per-profile invalidation service has been created.
285 invalidation::FakeInvalidationService* profile_invalidation_service = 297 invalidation::FakeInvalidationService* profile_invalidation_service =
286 GetProfileInvalidationService(profile); 298 GetProfileInvalidationService(profile);
287 ASSERT_TRUE(profile_invalidation_service); 299 ASSERT_TRUE(profile_invalidation_service);
288 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); 300 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount());
289 301
290 // Verify that no invalidator exists yet 302 // Verify that no invalidator exists yet.
291 EXPECT_FALSE(GetCloudPolicyInvalidator()); 303 EXPECT_FALSE(GetCloudPolicyInvalidator());
292 EXPECT_FALSE(GetInvalidationService()); 304 EXPECT_FALSE(GetInvalidationService());
293 305
294 // Indicate that the per-profile invalidation service has connected. 306 // Indicate that the per-profile invalidation service has connected.
295 profile_invalidation_service->SetInvalidatorState( 307 profile_invalidation_service->SetInvalidatorState(
296 syncer::INVALIDATIONS_ENABLED); 308 syncer::INVALIDATIONS_ENABLED);
297 309
298 // Verify that the device-global invalidator has been destroyed. 310 // Verify that the device-global invalidator has been destroyed.
299 EXPECT_FALSE(GetDeviceInvalidationService()); 311 EXPECT_FALSE(GetDeviceInvalidationService());
300 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); 312 EXPECT_FALSE(HasDeviceInvalidationServiceObserver());
(...skipping 19 matching lines...) Expand all
320 // Verify that a per-profile invalidation service still exists. 332 // Verify that a per-profile invalidation service still exists.
321 profile_invalidation_service = GetProfileInvalidationService(profile); 333 profile_invalidation_service = GetProfileInvalidationService(profile);
322 EXPECT_TRUE(profile_invalidation_service); 334 EXPECT_TRUE(profile_invalidation_service);
323 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); 335 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount());
324 336
325 // Verify that the invalidator has been destroyed. 337 // Verify that the invalidator has been destroyed.
326 EXPECT_FALSE(GetCloudPolicyInvalidator()); 338 EXPECT_FALSE(GetCloudPolicyInvalidator());
327 EXPECT_FALSE(GetInvalidationService()); 339 EXPECT_FALSE(GetInvalidationService());
328 } 340 }
329 341
342 // Verifies that even if the per-profile invalidation service for an
343 // unaffiliated user connects, no DeviceCloudPolicyInvalidator backed by it is
344 // created.
345 TEST_F(DeviceCloudPolicyInvalidatorTest,
346 DoNotUseUnaffiliatedProfileInvalidationService) {
347 // Log in as an unaffiliated user.
348 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID);
349 ASSERT_TRUE(profile);
350
351 // Verify that a device-global invalidation service has been created.
352 EXPECT_TRUE(GetDeviceInvalidationService());
353 EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
354
355 // Verify that a per-profile invalidation service has been created.
356 invalidation::FakeInvalidationService* profile_invalidation_service =
357 GetProfileInvalidationService(profile);
358 ASSERT_TRUE(profile_invalidation_service);
359 EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount());
360
361 // Verify that no invalidator exists yet.
362 EXPECT_FALSE(GetCloudPolicyInvalidator());
363 EXPECT_FALSE(GetInvalidationService());
364
365 // Indicate that the per-profile invalidation service has connected.
366 profile_invalidation_service->SetInvalidatorState(
367 syncer::INVALIDATIONS_ENABLED);
368
369 // Verify that the device-global invalidator still exists.
370 EXPECT_TRUE(GetDeviceInvalidationService());
371 EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
372
373 // Verify that a per-profile invalidation service still exists.
374 profile_invalidation_service = GetProfileInvalidationService(profile);
375 EXPECT_TRUE(profile_invalidation_service);
376 EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount());
377
378 // Verify that no invalidator has been created.
379 EXPECT_FALSE(GetCloudPolicyInvalidator());
380 EXPECT_FALSE(GetInvalidationService());
381 }
382
330 // Verifies that a DeviceCloudPolicyInvalidator exists whenever a connected 383 // Verifies that a DeviceCloudPolicyInvalidator exists whenever a connected
331 // invalidation service is available, automatically switching between 384 // invalidation service is available, automatically switching between
332 // device-global and per-profile invalidation services as they 385 // device-global and per-profile invalidation services as they
333 // connect/disconnect, giving priority to per-profile invalidation services. 386 // connect/disconnect, giving priority to per-profile invalidation services.
334 // Also verifies that the highest handled invalidation version is preserved when 387 // Also verifies that the highest handled invalidation version is preserved when
335 // switching invalidation services. 388 // switching invalidation services.
336 TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) { 389 TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) {
pastarmovj 2014/09/17 16:04:57 nit: This is a GIANT test. Is there any chance you
337 CloudPolicyStore* store = static_cast<CloudPolicyStore*>( 390 CloudPolicyStore* store = static_cast<CloudPolicyStore*>(
338 TestingBrowserProcess::GetGlobal()->platform_part()-> 391 TestingBrowserProcess::GetGlobal()->platform_part()->
339 browser_policy_connector_chromeos()->GetDeviceCloudPolicyManager()-> 392 browser_policy_connector_chromeos()->GetDeviceCloudPolicyManager()->
340 device_store()); 393 device_store());
341 ASSERT_TRUE(store); 394 ASSERT_TRUE(store);
342 395
343 // Verify that an invalidator backed by the device-global invalidation service 396 // Verify that an invalidator backed by the device-global invalidation service
344 // is created when the service connects. 397 // is created when the service connects.
345 ConnectDeviceInvalidationService(); 398 ConnectDeviceInvalidationService();
346 CloudPolicyInvalidator* invalidator = GetCloudPolicyInvalidator(); 399 CloudPolicyInvalidator* invalidator = GetCloudPolicyInvalidator();
347 ASSERT_TRUE(invalidator); 400 ASSERT_TRUE(invalidator);
348 ASSERT_TRUE(GetDeviceInvalidationService()); 401 ASSERT_TRUE(GetDeviceInvalidationService());
349 402
350 // Verify that the invalidator's highest handled invalidation version starts 403 // Verify that the invalidator's highest handled invalidation version starts
351 // out as zero. 404 // out as zero.
352 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version()); 405 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version());
353 406
354 // Create a first user profile. 407 // Log in as a first affiliated user.
355 Profile* profile_1 = CreateProfile("test_1"); 408 Profile* profile_1 = LogInAndReturnProfile(kAffiliatedUserID1);
356 ASSERT_TRUE(profile_1); 409 ASSERT_TRUE(profile_1);
357 410
358 // Verify that the device-global invalidation service still exists. 411 // Verify that the device-global invalidation service still exists.
359 EXPECT_TRUE(GetDeviceInvalidationService()); 412 EXPECT_TRUE(GetDeviceInvalidationService());
360 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); 413 EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
361 414
362 // Verify that a per-profile invalidation service has been created for the 415 // Verify that a per-profile invalidation service has been created for the
363 // first user profile. 416 // first user.
364 invalidation::FakeInvalidationService* profile_1_invalidation_service = 417 invalidation::FakeInvalidationService* profile_1_invalidation_service =
365 GetProfileInvalidationService(profile_1); 418 GetProfileInvalidationService(profile_1);
366 ASSERT_TRUE(profile_1_invalidation_service); 419 ASSERT_TRUE(profile_1_invalidation_service);
367 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); 420 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount());
368 421
369 // Verify that an invalidator backed by the device-global invalidation service 422 // Verify that an invalidator backed by the device-global invalidation service
370 // still exists. 423 // still exists.
371 EXPECT_TRUE(GetCloudPolicyInvalidator()); 424 EXPECT_TRUE(GetCloudPolicyInvalidator());
372 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); 425 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService());
373 426
374 // Indicate that the first user profile's per-profile invalidation service has 427 // Indicate that the first user's per-profile invalidation service has
375 // connected. 428 // connected.
376 profile_1_invalidation_service->SetInvalidatorState( 429 profile_1_invalidation_service->SetInvalidatorState(
377 syncer::INVALIDATIONS_ENABLED); 430 syncer::INVALIDATIONS_ENABLED);
378 431
379 // Verify that the device-global invalidator has been destroyed. 432 // Verify that the device-global invalidator has been destroyed.
380 EXPECT_FALSE(GetDeviceInvalidationService()); 433 EXPECT_FALSE(GetDeviceInvalidationService());
381 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); 434 EXPECT_FALSE(HasDeviceInvalidationServiceObserver());
382 435
383 // Verify that a per-profile invalidation service still exists for the first 436 // Verify that a per-profile invalidation service still exists for the first
384 // user profile. 437 // user.
385 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); 438 profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
386 EXPECT_TRUE(profile_1_invalidation_service); 439 EXPECT_TRUE(profile_1_invalidation_service);
387 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); 440 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount());
388 441
389 // Verify that an invalidator backed by the per-profile invalidation service 442 // Verify that an invalidator backed by the per-profile invalidation service
390 // for the first user profile has been created. 443 // for the first user has been created.
391 invalidator = GetCloudPolicyInvalidator(); 444 invalidator = GetCloudPolicyInvalidator();
392 ASSERT_TRUE(invalidator); 445 ASSERT_TRUE(invalidator);
393 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); 446 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService());
394 447
395 // Verify that the invalidator's highest handled invalidation version starts 448 // Verify that the invalidator's highest handled invalidation version starts
396 // out as zero. 449 // out as zero.
397 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version()); 450 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version());
398 451
399 // Handle an invalidation with version 1. Verify that the invalidator's 452 // Handle an invalidation with version 1. Verify that the invalidator's
400 // highest handled invalidation version is updated accordingly. 453 // highest handled invalidation version is updated accordingly.
401 store->Store(device_policy_.policy(), 1); 454 store->Store(device_policy_.policy(), 1);
402 invalidator->OnStoreLoaded(store); 455 invalidator->OnStoreLoaded(store);
403 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); 456 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version());
404 457
405 // Create a second user profile. 458 // Log in as a second affiliated user.
406 Profile* profile_2 = CreateProfile("test_2"); 459 Profile* profile_2 = LogInAndReturnProfile(kAffiliatedUserID2);
407 ASSERT_TRUE(profile_2); 460 ASSERT_TRUE(profile_2);
408 461
409 // Verify that the device-global invalidator still does not exist. 462 // Verify that the device-global invalidator still does not exist.
410 EXPECT_FALSE(GetDeviceInvalidationService()); 463 EXPECT_FALSE(GetDeviceInvalidationService());
411 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); 464 EXPECT_FALSE(HasDeviceInvalidationServiceObserver());
412 465
413 // Verify that a per-profile invalidation service still exists for the first 466 // Verify that a per-profile invalidation service still exists for the first
414 // user profile and one has been created for the second user profile. 467 // user and one has been created for the second user.
415 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); 468 profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
416 EXPECT_TRUE(profile_1_invalidation_service); 469 EXPECT_TRUE(profile_1_invalidation_service);
417 invalidation::FakeInvalidationService* profile_2_invalidation_service = 470 invalidation::FakeInvalidationService* profile_2_invalidation_service =
418 GetProfileInvalidationService(profile_2); 471 GetProfileInvalidationService(profile_2);
419 ASSERT_TRUE(profile_2_invalidation_service); 472 ASSERT_TRUE(profile_2_invalidation_service);
420 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); 473 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
421 474
422 // Verify that an invalidator backed by the per-profile invalidation service 475 // Verify that an invalidator backed by the per-profile invalidation service
423 // for the first user profile still exists. 476 // for the first user still exists.
424 EXPECT_TRUE(GetCloudPolicyInvalidator()); 477 EXPECT_TRUE(GetCloudPolicyInvalidator());
425 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); 478 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService());
426 479
427 // Indicate that the second user profile's per-profile invalidation service 480 // Indicate that the second user's per-profile invalidation service has
428 // has connected. 481 // connected.
429 profile_2_invalidation_service->SetInvalidatorState( 482 profile_2_invalidation_service->SetInvalidatorState(
430 syncer::INVALIDATIONS_ENABLED); 483 syncer::INVALIDATIONS_ENABLED);
431 484
432 // Verify that the device-global invalidator still does not exist. 485 // Verify that the device-global invalidator still does not exist.
433 EXPECT_FALSE(GetDeviceInvalidationService()); 486 EXPECT_FALSE(GetDeviceInvalidationService());
434 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); 487 EXPECT_FALSE(HasDeviceInvalidationServiceObserver());
435 488
436 // Verify that per-profile invalidation services still exist for both user 489 // Verify that per-profile invalidation services still exist for both users.
437 // profiles.
438 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); 490 profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
439 ASSERT_TRUE(profile_1_invalidation_service); 491 ASSERT_TRUE(profile_1_invalidation_service);
440 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); 492 profile_2_invalidation_service = GetProfileInvalidationService(profile_2);
441 EXPECT_TRUE(profile_2_invalidation_service); 493 EXPECT_TRUE(profile_2_invalidation_service);
442 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); 494 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
443 495
444 // Verify that an invalidator backed by the per-profile invalidation service 496 // Verify that an invalidator backed by the per-profile invalidation service
445 // for the first user profile still exists. 497 // for the first user still exists.
446 EXPECT_TRUE(GetCloudPolicyInvalidator()); 498 EXPECT_TRUE(GetCloudPolicyInvalidator());
447 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); 499 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService());
448 500
449 // Indicate that the per-profile invalidation service for the first user 501 // Indicate that the per-profile invalidation service for the first user has
450 // profile has disconnected. 502 // disconnected.
451 profile_1_invalidation_service->SetInvalidatorState( 503 profile_1_invalidation_service->SetInvalidatorState(
452 syncer::INVALIDATION_CREDENTIALS_REJECTED); 504 syncer::INVALIDATION_CREDENTIALS_REJECTED);
453 505
454 // Verify that the device-global invalidator still does not exist. 506 // Verify that the device-global invalidator still does not exist.
455 EXPECT_FALSE(GetDeviceInvalidationService()); 507 EXPECT_FALSE(GetDeviceInvalidationService());
456 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); 508 EXPECT_FALSE(HasDeviceInvalidationServiceObserver());
457 509
458 // Verify that per-profile invalidation services still exist for both user 510 // Verify that per-profile invalidation services still exist for both users.
459 // profiles.
460 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); 511 profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
461 EXPECT_TRUE(profile_1_invalidation_service); 512 EXPECT_TRUE(profile_1_invalidation_service);
462 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); 513 profile_2_invalidation_service = GetProfileInvalidationService(profile_2);
463 ASSERT_TRUE(profile_2_invalidation_service); 514 ASSERT_TRUE(profile_2_invalidation_service);
464 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); 515 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
465 516
466 // Verify that an invalidator backed by the per-profile invalidation service 517 // Verify that an invalidator backed by the per-profile invalidation service
467 // for the second user profile has been created. 518 // for the second user has been created.
468 invalidator = GetCloudPolicyInvalidator(); 519 invalidator = GetCloudPolicyInvalidator();
469 ASSERT_TRUE(invalidator); 520 ASSERT_TRUE(invalidator);
470 EXPECT_EQ(profile_2_invalidation_service, GetInvalidationService()); 521 EXPECT_EQ(profile_2_invalidation_service, GetInvalidationService());
471 522
472 // Verify that the invalidator's highest handled invalidation version starts 523 // Verify that the invalidator's highest handled invalidation version starts
473 // out as 1. 524 // out as 1.
474 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); 525 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version());
475 526
476 // Handle an invalidation with version 2. Verify that the invalidator's 527 // Handle an invalidation with version 2. Verify that the invalidator's
477 // highest handled invalidation version is updated accordingly. 528 // highest handled invalidation version is updated accordingly.
478 store->Store(device_policy_.policy(), 2); 529 store->Store(device_policy_.policy(), 2);
479 invalidator->OnStoreLoaded(store); 530 invalidator->OnStoreLoaded(store);
480 EXPECT_EQ(2, invalidator->highest_handled_invalidation_version()); 531 EXPECT_EQ(2, invalidator->highest_handled_invalidation_version());
481 532
533 // Log in as an unaffiliated user.
534 Profile* profile_3 = LogInAndReturnProfile(kUnaffiliatedUserID);
535 ASSERT_TRUE(profile_3);
536
537 // Verify that the device-global invalidator still does not exist.
538 EXPECT_FALSE(GetDeviceInvalidationService());
539 EXPECT_FALSE(HasDeviceInvalidationServiceObserver());
540
541 // Verify that a per-profile invalidation service still exists for the two
542 // affiliated user sand one has been created for the unaffiliated user.
543 profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
544 EXPECT_TRUE(profile_1_invalidation_service);
545 profile_2_invalidation_service = GetProfileInvalidationService(profile_2);
546 ASSERT_TRUE(profile_2_invalidation_service);
547 invalidation::FakeInvalidationService* profile_3_invalidation_service =
548 GetProfileInvalidationService(profile_3);
549 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
550
551 // Verify that an invalidator backed by the per-profile invalidation service
552 // for the second affiliated user still exists.
553 EXPECT_TRUE(GetCloudPolicyInvalidator());
554 EXPECT_EQ(profile_2_invalidation_service, GetInvalidationService());
555
556 // Indicate that the unaffiliated user's per-profile invalidation service has
557 // connected.
558 profile_3_invalidation_service->SetInvalidatorState(
559 syncer::INVALIDATIONS_ENABLED);
560
561 // Verify that the device-global invalidator still does not exist.
562 EXPECT_FALSE(GetDeviceInvalidationService());
563 EXPECT_FALSE(HasDeviceInvalidationServiceObserver());
564
565 // Verify that per-profile invalidation services still exist for all three
566 // users.
567 profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
568 ASSERT_TRUE(profile_1_invalidation_service);
569 profile_2_invalidation_service = GetProfileInvalidationService(profile_2);
570 EXPECT_TRUE(profile_2_invalidation_service);
571 profile_3_invalidation_service = GetProfileInvalidationService(profile_3);
572 EXPECT_TRUE(profile_3_invalidation_service);
573 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
574
575 // Verify that an invalidator backed by the per-profile invalidation service
576 // for the second affiliated user still exists.
577 EXPECT_TRUE(GetCloudPolicyInvalidator());
578
482 // Indicate that the per-profile invalidation service for the second user 579 // Indicate that the per-profile invalidation service for the second user
483 // profile has disconnected. 580 // profile has disconnected.
484 profile_2_invalidation_service->SetInvalidatorState( 581 profile_2_invalidation_service->SetInvalidatorState(
485 syncer::INVALIDATION_CREDENTIALS_REJECTED); 582 syncer::INVALIDATION_CREDENTIALS_REJECTED);
486 583
487 // Verify that a device-global invalidation service has been created. 584 // Verify that a device-global invalidation service has been created.
488 ASSERT_TRUE(GetDeviceInvalidationService()); 585 ASSERT_TRUE(GetDeviceInvalidationService());
489 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); 586 EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
490 587
491 // Verify that per-profile invalidation services still exist for both user 588 // Verify that per-profile invalidation services still exist for all three
492 // profiles. 589 // users.
493 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); 590 profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
494 EXPECT_TRUE(profile_1_invalidation_service); 591 ASSERT_TRUE(profile_1_invalidation_service);
495 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); 592 profile_2_invalidation_service = GetProfileInvalidationService(profile_2);
496 EXPECT_TRUE(profile_2_invalidation_service); 593 EXPECT_TRUE(profile_2_invalidation_service);
594 profile_3_invalidation_service = GetProfileInvalidationService(profile_3);
595 EXPECT_TRUE(profile_3_invalidation_service);
497 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); 596 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
498 597
499 // Verify that the invalidator has been destroyed. 598 // Verify that the invalidator has been destroyed.
500 EXPECT_FALSE(GetCloudPolicyInvalidator()); 599 EXPECT_FALSE(GetCloudPolicyInvalidator());
501 EXPECT_FALSE(GetInvalidationService()); 600 EXPECT_FALSE(GetInvalidationService());
502 601
503 // Indicate that the device-global invalidation service has connected. 602 // Indicate that the device-global invalidation service has connected.
504 GetDeviceInvalidationService()->OnInvalidatorStateChange( 603 GetDeviceInvalidationService()->OnInvalidatorStateChange(
505 syncer::INVALIDATIONS_ENABLED); 604 syncer::INVALIDATIONS_ENABLED);
506 base::RunLoop().RunUntilIdle(); 605 base::RunLoop().RunUntilIdle();
507 606
508 // Verify that the device-global invalidation service still exists. 607 // Verify that the device-global invalidation service still exists.
509 EXPECT_TRUE(GetDeviceInvalidationService()); 608 EXPECT_TRUE(GetDeviceInvalidationService());
510 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); 609 EXPECT_TRUE(HasDeviceInvalidationServiceObserver());
511 610
512 // Verify that per-profile invalidation services still exist for both user 611 // Verify that per-profile invalidation services still exist for all three
513 // profiles. 612 // users.
514 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); 613 profile_1_invalidation_service = GetProfileInvalidationService(profile_1);
515 EXPECT_TRUE(profile_1_invalidation_service); 614 ASSERT_TRUE(profile_1_invalidation_service);
516 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); 615 profile_2_invalidation_service = GetProfileInvalidationService(profile_2);
517 EXPECT_TRUE(profile_2_invalidation_service); 616 EXPECT_TRUE(profile_2_invalidation_service);
617 profile_3_invalidation_service = GetProfileInvalidationService(profile_3);
618 EXPECT_TRUE(profile_3_invalidation_service);
518 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); 619 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount());
519 620
520 // Verify that an invalidator backed by the device-global invalidation service 621 // Verify that an invalidator backed by the device-global invalidation service
521 // has been created. 622 // has been created.
522 invalidator = GetCloudPolicyInvalidator(); 623 invalidator = GetCloudPolicyInvalidator();
523 ASSERT_TRUE(invalidator); 624 ASSERT_TRUE(invalidator);
524 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); 625 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService());
525 626
526 // Verify that the invalidator's highest handled invalidation version starts 627 // Verify that the invalidator's highest handled invalidation version starts
527 // out as 2. 628 // out as 2.
528 EXPECT_EQ(2, invalidator->highest_handled_invalidation_version()); 629 EXPECT_EQ(2, invalidator->highest_handled_invalidation_version());
529 } 630 }
530 631
531 } // namespace policy 632 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_cloud_policy_invalidator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698