| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 26 matching lines...) Expand all Loading... |
| 212 DeviceCloudPolicyInvalidatorTest::GetInvalidationService() const { | 223 DeviceCloudPolicyInvalidatorTest::GetInvalidationService() const { |
| 213 return invalidator_->invalidation_service_; | 224 return invalidator_->invalidation_service_; |
| 214 } | 225 } |
| 215 | 226 |
| 216 CloudPolicyInvalidator* | 227 CloudPolicyInvalidator* |
| 217 DeviceCloudPolicyInvalidatorTest::GetCloudPolicyInvalidator() const { | 228 DeviceCloudPolicyInvalidatorTest::GetCloudPolicyInvalidator() const { |
| 218 return invalidator_->invalidator_.get(); | 229 return invalidator_->invalidator_.get(); |
| 219 } | 230 } |
| 220 | 231 |
| 221 void DeviceCloudPolicyInvalidatorTest::ConnectDeviceInvalidationService() { | 232 void DeviceCloudPolicyInvalidatorTest::ConnectDeviceInvalidationService() { |
| 233 const int per_profile_invalidation_service_observer_count = |
| 234 GetProfileInvalidationServiceObserverCount(); |
| 235 |
| 222 // Verify that a device-global invalidation service has been created. | 236 // Verify that a device-global invalidation service has been created. |
| 223 ASSERT_TRUE(GetDeviceInvalidationService()); | 237 ASSERT_TRUE(GetDeviceInvalidationService()); |
| 224 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); | 238 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 225 | 239 |
| 226 // Verify that no per-profile invalidation service observers have been | 240 // Verify that no new per-profile invalidation service observers have been |
| 227 // created. | 241 // created. |
| 228 EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); | 242 EXPECT_EQ(per_profile_invalidation_service_observer_count, |
| 243 GetProfileInvalidationServiceObserverCount()); |
| 229 | 244 |
| 230 // Verify that no invalidator exists yet | 245 // Verify that no invalidator exists yet |
| 231 EXPECT_FALSE(GetCloudPolicyInvalidator()); | 246 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 232 EXPECT_FALSE(GetInvalidationService()); | 247 EXPECT_FALSE(GetInvalidationService()); |
| 233 | 248 |
| 234 // Indicate that the device-global invalidation service has connected. | 249 // Indicate that the device-global invalidation service has connected. |
| 235 GetDeviceInvalidationService()->OnInvalidatorStateChange( | 250 GetDeviceInvalidationService()->OnInvalidatorStateChange( |
| 236 syncer::INVALIDATIONS_ENABLED); | 251 syncer::INVALIDATIONS_ENABLED); |
| 237 base::RunLoop().RunUntilIdle(); | 252 base::RunLoop().RunUntilIdle(); |
| 238 | 253 |
| 239 // Verify that the device-global invalidation service still exists. | 254 // Verify that the device-global invalidation service still exists. |
| 240 EXPECT_TRUE(GetDeviceInvalidationService()); | 255 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 241 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); | 256 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 242 | 257 |
| 243 // Verify that an invalidator backed by the device-global invalidation service | 258 // Verify that an invalidator backed by the device-global invalidation service |
| 244 // has been created. | 259 // has been created. |
| 245 EXPECT_TRUE(GetCloudPolicyInvalidator()); | 260 EXPECT_TRUE(GetCloudPolicyInvalidator()); |
| 246 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); | 261 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| 247 } | 262 } |
| 248 | 263 |
| 249 // Verifies that a DeviceCloudPolicyInvalidator backed by a device-global | 264 // Verifies that a DeviceCloudPolicyInvalidator backed by a device-global |
| 250 // invalidation service is created/destroyed as the service | 265 // invalidation service is created/destroyed as the service |
| 251 // connects/disconnects. | 266 // connects/disconnects. |
| 252 TEST_F(DeviceCloudPolicyInvalidatorTest, UseDeviceInvalidationService) { | 267 TEST_F(DeviceCloudPolicyInvalidatorTest, UseDeviceInvalidationService) { |
| 253 // Verify that an invalidator backed by the device-global invalidation service | 268 // Verify that an invalidator backed by the device-global invalidation service |
| 254 // is created when the service connects. | 269 // is created when the service connects. |
| 255 ConnectDeviceInvalidationService(); | 270 ConnectDeviceInvalidationService(); |
| 256 ASSERT_TRUE(GetDeviceInvalidationService()); | 271 ASSERT_TRUE(GetDeviceInvalidationService()); |
| 272 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| 257 | 273 |
| 258 // Indicate that the device-global invalidation service has disconnected. | 274 // Indicate that the device-global invalidation service has disconnected. |
| 259 GetDeviceInvalidationService()->OnInvalidatorStateChange( | 275 GetDeviceInvalidationService()->OnInvalidatorStateChange( |
| 260 syncer::INVALIDATION_CREDENTIALS_REJECTED); | 276 syncer::INVALIDATION_CREDENTIALS_REJECTED); |
| 261 base::RunLoop().RunUntilIdle(); | 277 base::RunLoop().RunUntilIdle(); |
| 262 | 278 |
| 263 // Verify that the device-global invalidation service still exists. | 279 // Verify that the device-global invalidation service still exists. |
| 264 EXPECT_TRUE(GetDeviceInvalidationService()); | 280 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 265 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); | 281 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 266 | 282 |
| 267 // Verify that the invalidator has been destroyed. | 283 // Verify that the invalidator has been destroyed. |
| 268 EXPECT_FALSE(GetCloudPolicyInvalidator()); | 284 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 269 EXPECT_FALSE(GetInvalidationService()); | 285 EXPECT_FALSE(GetInvalidationService()); |
| 270 } | 286 } |
| 271 | 287 |
| 272 // Verifies that a DeviceCloudPolicyInvalidator backed by a per-profile | 288 // Verifies that when the per-profile invalidation service for an affiliated |
| 273 // invalidation service is created/destroyed as the service | 289 // user connect/disconnects, a DeviceCloudPolicyInvalidator backed by it is |
| 274 // connects/disconnects. | 290 // created/destroyed. |
| 275 TEST_F(DeviceCloudPolicyInvalidatorTest, UseProfileInvalidationService) { | 291 TEST_F(DeviceCloudPolicyInvalidatorTest, |
| 276 // Create a user profile. | 292 UseAffiliatedProfileInvalidationService) { |
| 277 Profile* profile = CreateProfile("test"); | 293 // Log in as an affiliated user. |
| 294 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); |
| 278 ASSERT_TRUE(profile); | 295 ASSERT_TRUE(profile); |
| 279 | 296 |
| 280 // Verify that a device-global invalidation service has been created. | 297 // Verify that a device-global invalidation service has been created. |
| 281 EXPECT_TRUE(GetDeviceInvalidationService()); | 298 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 282 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); | 299 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 283 | 300 |
| 284 // Verify that a per-profile invalidation service has been created. | 301 // Verify that a per-profile invalidation service has been created. |
| 285 invalidation::FakeInvalidationService* profile_invalidation_service = | 302 invalidation::FakeInvalidationService* profile_invalidation_service = |
| 286 GetProfileInvalidationService(profile); | 303 GetProfileInvalidationService(profile); |
| 287 ASSERT_TRUE(profile_invalidation_service); | 304 ASSERT_TRUE(profile_invalidation_service); |
| 288 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); | 305 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 289 | 306 |
| 290 // Verify that no invalidator exists yet | 307 // Verify that no invalidator exists yet. |
| 291 EXPECT_FALSE(GetCloudPolicyInvalidator()); | 308 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 292 EXPECT_FALSE(GetInvalidationService()); | 309 EXPECT_FALSE(GetInvalidationService()); |
| 293 | 310 |
| 294 // Indicate that the per-profile invalidation service has connected. | 311 // Indicate that the per-profile invalidation service has connected. |
| 295 profile_invalidation_service->SetInvalidatorState( | 312 profile_invalidation_service->SetInvalidatorState( |
| 296 syncer::INVALIDATIONS_ENABLED); | 313 syncer::INVALIDATIONS_ENABLED); |
| 297 | 314 |
| 298 // Verify that the device-global invalidator has been destroyed. | 315 // Verify that the device-global invalidator has been destroyed. |
| 299 EXPECT_FALSE(GetDeviceInvalidationService()); | 316 EXPECT_FALSE(GetDeviceInvalidationService()); |
| 300 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); | 317 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 320 // Verify that a per-profile invalidation service still exists. | 337 // Verify that a per-profile invalidation service still exists. |
| 321 profile_invalidation_service = GetProfileInvalidationService(profile); | 338 profile_invalidation_service = GetProfileInvalidationService(profile); |
| 322 EXPECT_TRUE(profile_invalidation_service); | 339 EXPECT_TRUE(profile_invalidation_service); |
| 323 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); | 340 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 324 | 341 |
| 325 // Verify that the invalidator has been destroyed. | 342 // Verify that the invalidator has been destroyed. |
| 326 EXPECT_FALSE(GetCloudPolicyInvalidator()); | 343 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 327 EXPECT_FALSE(GetInvalidationService()); | 344 EXPECT_FALSE(GetInvalidationService()); |
| 328 } | 345 } |
| 329 | 346 |
| 330 // Verifies that a DeviceCloudPolicyInvalidator exists whenever a connected | 347 // Verifies that even if the per-profile invalidation service for an |
| 331 // invalidation service is available, automatically switching between | 348 // unaffiliated user connects, no DeviceCloudPolicyInvalidator backed by it is |
| 332 // device-global and per-profile invalidation services as they | 349 // created. |
| 333 // connect/disconnect, giving priority to per-profile invalidation services. | 350 TEST_F(DeviceCloudPolicyInvalidatorTest, |
| 334 // Also verifies that the highest handled invalidation version is preserved when | 351 DoNotUseUnaffiliatedProfileInvalidationService) { |
| 335 // switching invalidation services. | 352 // Log in as an unaffiliated user. |
| 336 TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchInvalidationServices) { | 353 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); |
| 354 ASSERT_TRUE(profile); |
| 355 |
| 356 // Verify that a device-global invalidation service has been created. |
| 357 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 358 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 359 |
| 360 // Verify that a per-profile invalidation service has been created. |
| 361 invalidation::FakeInvalidationService* profile_invalidation_service = |
| 362 GetProfileInvalidationService(profile); |
| 363 ASSERT_TRUE(profile_invalidation_service); |
| 364 EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| 365 |
| 366 // Verify that no invalidator exists yet. |
| 367 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 368 EXPECT_FALSE(GetInvalidationService()); |
| 369 |
| 370 // Indicate that the per-profile invalidation service has connected. |
| 371 profile_invalidation_service->SetInvalidatorState( |
| 372 syncer::INVALIDATIONS_ENABLED); |
| 373 |
| 374 // Verify that the device-global invalidator still exists. |
| 375 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 376 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 377 |
| 378 // Verify that a per-profile invalidation service still exists. |
| 379 profile_invalidation_service = GetProfileInvalidationService(profile); |
| 380 EXPECT_TRUE(profile_invalidation_service); |
| 381 EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| 382 |
| 383 // Verify that no invalidator has been created. |
| 384 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 385 EXPECT_FALSE(GetInvalidationService()); |
| 386 } |
| 387 |
| 388 // Verifies that when the per-profile invalidation service for an affiliated |
| 389 // user connects, a DeviceCloudPolicyInvalidator backed by it replaces the |
| 390 // current DeviceCloudPolicyInvalidator backed by a device-global invalidation |
| 391 // service. Also verifies that the device-global invalidation service is |
| 392 // destroyed at this point and the highest handled invalidation version is |
| 393 // preserved when switching invalidation services. |
| 394 TEST_F(DeviceCloudPolicyInvalidatorTest, |
| 395 SwitchToAffiliatedProfileInvalidationService) { |
| 337 CloudPolicyStore* store = static_cast<CloudPolicyStore*>( | 396 CloudPolicyStore* store = static_cast<CloudPolicyStore*>( |
| 338 TestingBrowserProcess::GetGlobal()->platform_part()-> | 397 TestingBrowserProcess::GetGlobal()->platform_part()-> |
| 339 browser_policy_connector_chromeos()->GetDeviceCloudPolicyManager()-> | 398 browser_policy_connector_chromeos()->GetDeviceCloudPolicyManager()-> |
| 340 device_store()); | 399 device_store()); |
| 341 ASSERT_TRUE(store); | 400 ASSERT_TRUE(store); |
| 342 | 401 |
| 343 // Verify that an invalidator backed by the device-global invalidation service | 402 // Verify that an invalidator backed by the device-global invalidation service |
| 344 // is created when the service connects. | 403 // is created when the service connects. |
| 345 ConnectDeviceInvalidationService(); | 404 ConnectDeviceInvalidationService(); |
| 346 CloudPolicyInvalidator* invalidator = GetCloudPolicyInvalidator(); | 405 CloudPolicyInvalidator* invalidator = GetCloudPolicyInvalidator(); |
| 347 ASSERT_TRUE(invalidator); | 406 ASSERT_TRUE(invalidator); |
| 348 ASSERT_TRUE(GetDeviceInvalidationService()); | 407 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| 349 | 408 |
| 350 // Verify that the invalidator's highest handled invalidation version starts | 409 // Verify that the invalidator's highest handled invalidation version starts |
| 351 // out as zero. | 410 // out as zero. |
| 352 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version()); | 411 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version()); |
| 353 | 412 |
| 354 // Create a first user profile. | 413 // Handle an invalidation with version 1. Verify that the invalidator's |
| 355 Profile* profile_1 = CreateProfile("test_1"); | 414 // highest handled invalidation version is updated accordingly. |
| 415 store->Store(device_policy_.policy(), 1); |
| 416 invalidator->OnStoreLoaded(store); |
| 417 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); |
| 418 |
| 419 // Log in as an affiliated user. |
| 420 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); |
| 421 ASSERT_TRUE(profile); |
| 422 |
| 423 // Verify that the device-global invalidation service still exists. |
| 424 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 425 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 426 |
| 427 // Verify that a per-profile invalidation service has been created. |
| 428 invalidation::FakeInvalidationService* profile_invalidation_service = |
| 429 GetProfileInvalidationService(profile); |
| 430 ASSERT_TRUE(profile_invalidation_service); |
| 431 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 432 |
| 433 // Verify that an invalidator backed by the device-global invalidation service |
| 434 // still exists. |
| 435 EXPECT_TRUE(GetCloudPolicyInvalidator()); |
| 436 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| 437 |
| 438 // Indicate that the per-profile invalidation service has connected. |
| 439 profile_invalidation_service->SetInvalidatorState( |
| 440 syncer::INVALIDATIONS_ENABLED); |
| 441 |
| 442 // Verify that the device-global invalidator has been destroyed. |
| 443 EXPECT_FALSE(GetDeviceInvalidationService()); |
| 444 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| 445 |
| 446 // Verify that a per-profile invalidation service still exists. |
| 447 profile_invalidation_service = GetProfileInvalidationService(profile); |
| 448 EXPECT_TRUE(profile_invalidation_service); |
| 449 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 450 |
| 451 // Verify that an invalidator backed by the per-profile invalidation service |
| 452 // has been created. |
| 453 invalidator = GetCloudPolicyInvalidator(); |
| 454 ASSERT_TRUE(invalidator); |
| 455 EXPECT_EQ(profile_invalidation_service, GetInvalidationService()); |
| 456 |
| 457 // Verify that the invalidator's highest handled invalidation version starts |
| 458 // out as one. |
| 459 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); |
| 460 } |
| 461 |
| 462 // Verifies that when the per-profile invalidation service for an unaffiliated |
| 463 // user connects, the current DeviceCloudPolicyInvalidator backed by a |
| 464 // device-global invalidation service is not destroyed and replaced. |
| 465 TEST_F(DeviceCloudPolicyInvalidatorTest, |
| 466 DoNotSwitchToUnaffiliatedProfileInvalidationService) { |
| 467 // Verify that an invalidator backed by the device-global invalidation service |
| 468 // is created when the service connects. |
| 469 ConnectDeviceInvalidationService(); |
| 470 CloudPolicyInvalidator* invalidator = GetCloudPolicyInvalidator(); |
| 471 ASSERT_TRUE(invalidator); |
| 472 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| 473 |
| 474 // Verify that the invalidator's highest handled invalidation version starts |
| 475 // out as zero. |
| 476 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version()); |
| 477 |
| 478 // Log in as an unaffiliated user. |
| 479 Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); |
| 480 ASSERT_TRUE(profile); |
| 481 |
| 482 // Verify that the device-global invalidation service still exists. |
| 483 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 484 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 485 |
| 486 // Verify that a per-profile invalidation service has been created. |
| 487 invalidation::FakeInvalidationService* profile_invalidation_service = |
| 488 GetProfileInvalidationService(profile); |
| 489 ASSERT_TRUE(profile_invalidation_service); |
| 490 EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| 491 |
| 492 // Verify that an invalidator backed by the device-global invalidation service |
| 493 // still exists. |
| 494 EXPECT_TRUE(GetCloudPolicyInvalidator()); |
| 495 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| 496 |
| 497 // Indicate that the per-profile invalidation service has connected. |
| 498 profile_invalidation_service->SetInvalidatorState( |
| 499 syncer::INVALIDATIONS_ENABLED); |
| 500 |
| 501 // Verify that the device-global invalidator still exists. |
| 502 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 503 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 504 |
| 505 // Verify that a per-profile invalidation service still exists. |
| 506 profile_invalidation_service = GetProfileInvalidationService(profile); |
| 507 EXPECT_TRUE(profile_invalidation_service); |
| 508 EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| 509 |
| 510 // Verify that an invalidator backed by the device-global invalidation service |
| 511 // still exists. |
| 512 EXPECT_TRUE(GetCloudPolicyInvalidator()); |
| 513 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| 514 } |
| 515 |
| 516 // Verifies that when the per-profile invalidation service backing the current |
| 517 // DeviceCloudPolicyInvalidator disconnects and no other connected invalidation |
| 518 // service is available for use, a device-global invalidation service is |
| 519 // created. Also verifies that when this service connects, a |
| 520 // DeviceCloudPolicyInvalidator backed by it is created and the highest handled |
| 521 // invalidation version is preserved when switching invalidation services. |
| 522 TEST_F(DeviceCloudPolicyInvalidatorTest, SwitchToDeviceInvalidationService) { |
| 523 CloudPolicyStore* store = static_cast<CloudPolicyStore*>( |
| 524 TestingBrowserProcess::GetGlobal()->platform_part()-> |
| 525 browser_policy_connector_chromeos()->GetDeviceCloudPolicyManager()-> |
| 526 device_store()); |
| 527 ASSERT_TRUE(store); |
| 528 |
| 529 // Log in as an affiliated user. |
| 530 Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); |
| 531 ASSERT_TRUE(profile); |
| 532 |
| 533 // Verify that a device-global invalidation service has been created. |
| 534 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 535 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 536 |
| 537 // Verify that a per-profile invalidation service has been created. |
| 538 invalidation::FakeInvalidationService* profile_invalidation_service = |
| 539 GetProfileInvalidationService(profile); |
| 540 ASSERT_TRUE(profile_invalidation_service); |
| 541 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 542 |
| 543 // Verify that no invalidator exists yet. |
| 544 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 545 EXPECT_FALSE(GetInvalidationService()); |
| 546 |
| 547 // Indicate that the per-profile invalidation service has connected. |
| 548 profile_invalidation_service->SetInvalidatorState( |
| 549 syncer::INVALIDATIONS_ENABLED); |
| 550 |
| 551 // Verify that the device-global invalidator has been destroyed. |
| 552 EXPECT_FALSE(GetDeviceInvalidationService()); |
| 553 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| 554 |
| 555 // Verify that a per-profile invalidation service still exists. |
| 556 profile_invalidation_service = GetProfileInvalidationService(profile); |
| 557 ASSERT_TRUE(profile_invalidation_service); |
| 558 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 559 |
| 560 // Verify that an invalidator backed by the per-profile invalidation service |
| 561 // has been created. |
| 562 CloudPolicyInvalidator* invalidator = GetCloudPolicyInvalidator(); |
| 563 ASSERT_TRUE(invalidator); |
| 564 EXPECT_EQ(profile_invalidation_service, GetInvalidationService()); |
| 565 |
| 566 // Verify that the invalidator's highest handled invalidation version starts |
| 567 // out as zero. |
| 568 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version()); |
| 569 |
| 570 // Handle an invalidation with version 1. Verify that the invalidator's |
| 571 // highest handled invalidation version is updated accordingly. |
| 572 store->Store(device_policy_.policy(), 1); |
| 573 invalidator->OnStoreLoaded(store); |
| 574 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); |
| 575 |
| 576 // Indicate that the per-profile invalidation service has disconnected. |
| 577 profile_invalidation_service->SetInvalidatorState( |
| 578 syncer::INVALIDATION_CREDENTIALS_REJECTED); |
| 579 |
| 580 // Verify that a device-global invalidation service has been created. |
| 581 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 582 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 583 |
| 584 // Verify that a per-profile invalidation service still exists. |
| 585 profile_invalidation_service = GetProfileInvalidationService(profile); |
| 586 EXPECT_TRUE(profile_invalidation_service); |
| 587 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 588 |
| 589 // Verify that the invalidator has been destroyed. |
| 590 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 591 EXPECT_FALSE(GetInvalidationService()); |
| 592 |
| 593 // Verify that an invalidator backed by the device-global invalidation service |
| 594 // is created when the service connects. |
| 595 ConnectDeviceInvalidationService(); |
| 596 invalidator = GetCloudPolicyInvalidator(); |
| 597 ASSERT_TRUE(invalidator); |
| 598 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| 599 |
| 600 // Verify that the invalidator's highest handled invalidation version starts |
| 601 // out as one. |
| 602 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); |
| 603 } |
| 604 |
| 605 // Verifies that when the per-profile invalidation service backing the current |
| 606 // DeviceCloudPolicyInvalidator disconnects and another connected per-profile |
| 607 // invalidation service is available for use, a DeviceCloudPolicyInvalidator |
| 608 // backed by that service is created. Also verifies that the highest handled |
| 609 // invalidation version is preserved when switching invalidation services. |
| 610 TEST_F(DeviceCloudPolicyInvalidatorTest, |
| 611 SwitchBetweenAffiliatedProfileInvalidationServices) { |
| 612 CloudPolicyStore* store = static_cast<CloudPolicyStore*>( |
| 613 TestingBrowserProcess::GetGlobal()->platform_part()-> |
| 614 browser_policy_connector_chromeos()->GetDeviceCloudPolicyManager()-> |
| 615 device_store()); |
| 616 ASSERT_TRUE(store); |
| 617 |
| 618 // Verify that a device-global invalidation service has been created. |
| 619 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 620 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 621 |
| 622 // Verify that no invalidator exists yet. |
| 623 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 624 EXPECT_FALSE(GetInvalidationService()); |
| 625 |
| 626 // Log in as a first affiliated user. |
| 627 Profile* profile_1 = LogInAndReturnProfile(kAffiliatedUserID1); |
| 356 ASSERT_TRUE(profile_1); | 628 ASSERT_TRUE(profile_1); |
| 357 | 629 |
| 358 // Verify that the device-global invalidation service still exists. | 630 // Verify that the device-global invalidation service still exists. |
| 359 EXPECT_TRUE(GetDeviceInvalidationService()); | 631 EXPECT_TRUE(GetDeviceInvalidationService()); |
| 360 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); | 632 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| 361 | 633 |
| 362 // Verify that a per-profile invalidation service has been created for the | 634 // Verify that a per-profile invalidation service has been created for the |
| 363 // first user profile. | 635 // first user. |
| 364 invalidation::FakeInvalidationService* profile_1_invalidation_service = | 636 invalidation::FakeInvalidationService* profile_1_invalidation_service = |
| 365 GetProfileInvalidationService(profile_1); | 637 GetProfileInvalidationService(profile_1); |
| 366 ASSERT_TRUE(profile_1_invalidation_service); | 638 ASSERT_TRUE(profile_1_invalidation_service); |
| 367 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); | 639 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 368 | 640 |
| 369 // Verify that an invalidator backed by the device-global invalidation service | 641 // Verify that no invalidator has been created. |
| 370 // still exists. | 642 EXPECT_FALSE(GetCloudPolicyInvalidator()); |
| 371 EXPECT_TRUE(GetCloudPolicyInvalidator()); | 643 EXPECT_FALSE(GetInvalidationService()); |
| 372 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); | |
| 373 | 644 |
| 374 // Indicate that the first user profile's per-profile invalidation service has | 645 // Indicate that the first user's per-profile invalidation service has |
| 375 // connected. | 646 // connected. |
| 376 profile_1_invalidation_service->SetInvalidatorState( | 647 profile_1_invalidation_service->SetInvalidatorState( |
| 377 syncer::INVALIDATIONS_ENABLED); | 648 syncer::INVALIDATIONS_ENABLED); |
| 378 | 649 |
| 379 // Verify that the device-global invalidator has been destroyed. | 650 // Verify that the device-global invalidator has been destroyed. |
| 380 EXPECT_FALSE(GetDeviceInvalidationService()); | 651 EXPECT_FALSE(GetDeviceInvalidationService()); |
| 381 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); | 652 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| 382 | 653 |
| 383 // Verify that a per-profile invalidation service still exists for the first | 654 // Verify that a per-profile invalidation service still exists for the first |
| 384 // user profile. | 655 // user. |
| 385 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); | 656 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); |
| 386 EXPECT_TRUE(profile_1_invalidation_service); | 657 EXPECT_TRUE(profile_1_invalidation_service); |
| 387 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); | 658 EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| 388 | 659 |
| 389 // Verify that an invalidator backed by the per-profile invalidation service | 660 // Verify that an invalidator backed by the first user's per-profile |
| 390 // for the first user profile has been created. | 661 // invalidation service has been created. |
| 391 invalidator = GetCloudPolicyInvalidator(); | 662 CloudPolicyInvalidator* invalidator = GetCloudPolicyInvalidator(); |
| 392 ASSERT_TRUE(invalidator); | 663 ASSERT_TRUE(invalidator); |
| 393 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); | 664 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); |
| 394 | 665 |
| 395 // Verify that the invalidator's highest handled invalidation version starts | 666 // Verify that the invalidator's highest handled invalidation version starts |
| 396 // out as zero. | 667 // out as zero. |
| 397 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version()); | 668 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version()); |
| 398 | 669 |
| 399 // Handle an invalidation with version 1. Verify that the invalidator's | 670 // Handle an invalidation with version 1. Verify that the invalidator's |
| 400 // highest handled invalidation version is updated accordingly. | 671 // highest handled invalidation version is updated accordingly. |
| 401 store->Store(device_policy_.policy(), 1); | 672 store->Store(device_policy_.policy(), 1); |
| 402 invalidator->OnStoreLoaded(store); | 673 invalidator->OnStoreLoaded(store); |
| 403 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); | 674 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); |
| 404 | 675 |
| 405 // Create a second user profile. | 676 // Log in as a second affiliated user. |
| 406 Profile* profile_2 = CreateProfile("test_2"); | 677 Profile* profile_2 = LogInAndReturnProfile(kAffiliatedUserID2); |
| 407 ASSERT_TRUE(profile_2); | 678 ASSERT_TRUE(profile_2); |
| 408 | 679 |
| 409 // Verify that the device-global invalidator still does not exist. | 680 // Verify that the device-global invalidator still does not exist. |
| 410 EXPECT_FALSE(GetDeviceInvalidationService()); | 681 EXPECT_FALSE(GetDeviceInvalidationService()); |
| 411 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); | 682 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| 412 | 683 |
| 413 // Verify that a per-profile invalidation service still exists for the first | 684 // 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. | 685 // user and one has been created for the second user. |
| 415 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); | 686 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); |
| 416 EXPECT_TRUE(profile_1_invalidation_service); | 687 EXPECT_TRUE(profile_1_invalidation_service); |
| 417 invalidation::FakeInvalidationService* profile_2_invalidation_service = | 688 invalidation::FakeInvalidationService* profile_2_invalidation_service = |
| 418 GetProfileInvalidationService(profile_2); | 689 GetProfileInvalidationService(profile_2); |
| 419 ASSERT_TRUE(profile_2_invalidation_service); | 690 ASSERT_TRUE(profile_2_invalidation_service); |
| 420 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); | 691 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); |
| 421 | 692 |
| 422 // Verify that an invalidator backed by the per-profile invalidation service | 693 // Verify that an invalidator backed by the first user's per-profile |
| 423 // for the first user profile still exists. | 694 // invalidation service still exists. |
| 424 EXPECT_TRUE(GetCloudPolicyInvalidator()); | 695 EXPECT_TRUE(GetCloudPolicyInvalidator()); |
| 425 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); | 696 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); |
| 426 | 697 |
| 427 // Indicate that the second user profile's per-profile invalidation service | 698 // Indicate that the second user's per-profile invalidation service has |
| 428 // has connected. | 699 // connected. |
| 429 profile_2_invalidation_service->SetInvalidatorState( | 700 profile_2_invalidation_service->SetInvalidatorState( |
| 430 syncer::INVALIDATIONS_ENABLED); | 701 syncer::INVALIDATIONS_ENABLED); |
| 431 | 702 |
| 432 // Verify that the device-global invalidator still does not exist. | 703 // Verify that the device-global invalidator still does not exist. |
| 433 EXPECT_FALSE(GetDeviceInvalidationService()); | 704 EXPECT_FALSE(GetDeviceInvalidationService()); |
| 434 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); | 705 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| 435 | 706 |
| 436 // Verify that per-profile invalidation services still exist for both user | 707 // Verify that per-profile invalidation services still exist for both users. |
| 437 // profiles. | |
| 438 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); | 708 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); |
| 439 ASSERT_TRUE(profile_1_invalidation_service); | 709 ASSERT_TRUE(profile_1_invalidation_service); |
| 440 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); | 710 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); |
| 441 EXPECT_TRUE(profile_2_invalidation_service); | 711 EXPECT_TRUE(profile_2_invalidation_service); |
| 442 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); | 712 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); |
| 443 | 713 |
| 444 // Verify that an invalidator backed by the per-profile invalidation service | 714 // Verify that an invalidator backed by the first user's per-profile |
| 445 // for the first user profile still exists. | 715 // invalidation service still exists. |
| 446 EXPECT_TRUE(GetCloudPolicyInvalidator()); | 716 EXPECT_TRUE(GetCloudPolicyInvalidator()); |
| 447 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); | 717 EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); |
| 448 | 718 |
| 449 // Indicate that the per-profile invalidation service for the first user | 719 // Indicate that the first user's per-profile invalidation service has |
| 450 // profile has disconnected. | 720 // disconnected. |
| 451 profile_1_invalidation_service->SetInvalidatorState( | 721 profile_1_invalidation_service->SetInvalidatorState( |
| 452 syncer::INVALIDATION_CREDENTIALS_REJECTED); | 722 syncer::INVALIDATION_CREDENTIALS_REJECTED); |
| 453 | 723 |
| 454 // Verify that the device-global invalidator still does not exist. | 724 // Verify that the device-global invalidator still does not exist. |
| 455 EXPECT_FALSE(GetDeviceInvalidationService()); | 725 EXPECT_FALSE(GetDeviceInvalidationService()); |
| 456 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); | 726 EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| 457 | 727 |
| 458 // Verify that per-profile invalidation services still exist for both user | 728 // Verify that per-profile invalidation services still exist for both users. |
| 459 // profiles. | |
| 460 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); | 729 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); |
| 461 EXPECT_TRUE(profile_1_invalidation_service); | 730 EXPECT_TRUE(profile_1_invalidation_service); |
| 462 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); | 731 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); |
| 463 ASSERT_TRUE(profile_2_invalidation_service); | 732 ASSERT_TRUE(profile_2_invalidation_service); |
| 464 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); | 733 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); |
| 465 | 734 |
| 466 // Verify that an invalidator backed by the per-profile invalidation service | 735 // Verify that an invalidator backed by the second user's per-profile |
| 467 // for the second user profile has been created. | 736 // invalidation service has been created. |
| 468 invalidator = GetCloudPolicyInvalidator(); | 737 invalidator = GetCloudPolicyInvalidator(); |
| 469 ASSERT_TRUE(invalidator); | 738 ASSERT_TRUE(invalidator); |
| 470 EXPECT_EQ(profile_2_invalidation_service, GetInvalidationService()); | 739 EXPECT_EQ(profile_2_invalidation_service, GetInvalidationService()); |
| 471 | 740 |
| 472 // Verify that the invalidator's highest handled invalidation version starts | 741 // Verify that the invalidator's highest handled invalidation version starts |
| 473 // out as 1. | 742 // out as one. |
| 474 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); | 743 EXPECT_EQ(1, invalidator->highest_handled_invalidation_version()); |
| 475 | |
| 476 // Handle an invalidation with version 2. Verify that the invalidator's | |
| 477 // highest handled invalidation version is updated accordingly. | |
| 478 store->Store(device_policy_.policy(), 2); | |
| 479 invalidator->OnStoreLoaded(store); | |
| 480 EXPECT_EQ(2, invalidator->highest_handled_invalidation_version()); | |
| 481 | |
| 482 // Indicate that the per-profile invalidation service for the second user | |
| 483 // profile has disconnected. | |
| 484 profile_2_invalidation_service->SetInvalidatorState( | |
| 485 syncer::INVALIDATION_CREDENTIALS_REJECTED); | |
| 486 | |
| 487 // Verify that a device-global invalidation service has been created. | |
| 488 ASSERT_TRUE(GetDeviceInvalidationService()); | |
| 489 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); | |
| 490 | |
| 491 // Verify that per-profile invalidation services still exist for both user | |
| 492 // profiles. | |
| 493 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); | |
| 494 EXPECT_TRUE(profile_1_invalidation_service); | |
| 495 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); | |
| 496 EXPECT_TRUE(profile_2_invalidation_service); | |
| 497 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); | |
| 498 | |
| 499 // Verify that the invalidator has been destroyed. | |
| 500 EXPECT_FALSE(GetCloudPolicyInvalidator()); | |
| 501 EXPECT_FALSE(GetInvalidationService()); | |
| 502 | |
| 503 // Indicate that the device-global invalidation service has connected. | |
| 504 GetDeviceInvalidationService()->OnInvalidatorStateChange( | |
| 505 syncer::INVALIDATIONS_ENABLED); | |
| 506 base::RunLoop().RunUntilIdle(); | |
| 507 | |
| 508 // Verify that the device-global invalidation service still exists. | |
| 509 EXPECT_TRUE(GetDeviceInvalidationService()); | |
| 510 EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); | |
| 511 | |
| 512 // Verify that per-profile invalidation services still exist for both user | |
| 513 // profiles. | |
| 514 profile_1_invalidation_service = GetProfileInvalidationService(profile_1); | |
| 515 EXPECT_TRUE(profile_1_invalidation_service); | |
| 516 profile_2_invalidation_service = GetProfileInvalidationService(profile_2); | |
| 517 EXPECT_TRUE(profile_2_invalidation_service); | |
| 518 EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); | |
| 519 | |
| 520 // Verify that an invalidator backed by the device-global invalidation service | |
| 521 // has been created. | |
| 522 invalidator = GetCloudPolicyInvalidator(); | |
| 523 ASSERT_TRUE(invalidator); | |
| 524 EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); | |
| 525 | |
| 526 // Verify that the invalidator's highest handled invalidation version starts | |
| 527 // out as 2. | |
| 528 EXPECT_EQ(2, invalidator->highest_handled_invalidation_version()); | |
| 529 } | 744 } |
| 530 | 745 |
| 531 } // namespace policy | 746 } // namespace policy |
| OLD | NEW |