Chromium Code Reviews| Index: chrome/browser/chromeos/policy/affiliated_invalidation_service_provider_unittest.cc |
| diff --git a/chrome/browser/chromeos/policy/affiliated_invalidation_service_provider_unittest.cc b/chrome/browser/chromeos/policy/affiliated_invalidation_service_provider_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fd1d7b0165f1591f81ea88672f6ecf27bcc7f7be |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/policy/affiliated_invalidation_service_provider_unittest.cc |
| @@ -0,0 +1,954 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provider.h" |
| + |
| +#include <string> |
| + |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
| +#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| +#include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" |
| +#include "chrome/browser/chromeos/settings/cros_settings.h" |
| +#include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h" |
| +#include "chrome/browser/chromeos/settings/device_settings_service.h" |
| +#include "chrome/browser/invalidation/fake_invalidation_service.h" |
| +#include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/test/base/testing_browser_process.h" |
| +#include "chrome/test/base/testing_profile_manager.h" |
| +#include "chromeos/cryptohome/system_salt_getter.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "components/invalidation/invalidation_service.h" |
| +#include "components/invalidation/invalidator_state.h" |
| +#include "components/invalidation/profile_invalidation_provider.h" |
| +#include "components/invalidation/ticl_invalidation_service.h" |
| +#include "components/keyed_service/core/keyed_service.h" |
| +#include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/notification_details.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using testing::_; |
| +using testing::Mock; |
| +using testing::Sequence; |
| + |
| +namespace policy { |
| + |
| +namespace { |
| + |
| +const char kAffiliatedUserID1[] = "test_1@example.com"; |
| +const char kAffiliatedUserID2[] = "test_2@example.com"; |
| +const char kUnaffiliatedUserID[] = "test@other_domain.test"; |
| + |
| +KeyedService* BuildProfileInvalidationProvider( |
| + content::BrowserContext* context) { |
| + scoped_ptr<invalidation::FakeInvalidationService> invalidation_service( |
| + new invalidation::FakeInvalidationService); |
| + invalidation_service->SetInvalidatorState( |
| + syncer::TRANSIENT_INVALIDATION_ERROR); |
| + return new invalidation::ProfileInvalidationProvider( |
| + invalidation_service.Pass()); |
| +} |
| + |
| +} // namespace |
| + |
| +class MockConsumer : public AffiliatedInvalidationServiceProvider::Consumer { |
| + public: |
| + MockConsumer(); |
| + ~MockConsumer() override; |
| + |
| + MOCK_METHOD1(OnInvalidationServiceSet, |
| + void(invalidation::InvalidationService*)); |
| + MOCK_METHOD0(OnInvalidationServiceReset, void()); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MockConsumer); |
| +}; |
| + |
| +class AffiliatedInvalidationServiceProviderTest : public testing::Test { |
| + public: |
| + AffiliatedInvalidationServiceProviderTest(); |
| + |
| + // testing::Test: |
| + virtual void SetUp() override; |
| + virtual void TearDown() override; |
| + |
| + // Ownership is not passed. The Profile is owned by the global ProfileManager. |
| + Profile* LogInAndReturnProfile(const std::string& user_id); |
| + |
| + AffiliatedInvalidationServiceProvider* GetProvider(); |
| + |
| + invalidation::TiclInvalidationService* GetDeviceInvalidationService(); |
| + bool HasDeviceInvalidationServiceObserver() const; |
| + |
| + invalidation::FakeInvalidationService* GetProfileInvalidationService( |
| + Profile* profile); |
| + int GetProfileInvalidationServiceObserverCount() const; |
| + |
| + const invalidation::InvalidationService* GetInvalidationService() const; |
| + |
| + private: |
| + content::TestBrowserThreadBundle thread_bundle_; |
| + chromeos::FakeUserManager* fake_user_manager_; |
| + chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| + ScopedStubEnterpriseInstallAttributes install_attributes_; |
| + scoped_ptr<chromeos::ScopedTestDeviceSettingsService> |
| + test_device_settings_service_; |
| + scoped_ptr<chromeos::ScopedTestCrosSettings> test_cros_settings_; |
| + TestingProfileManager profile_manager_; |
| + |
| + scoped_ptr<AffiliatedInvalidationServiceProvider> provider_; |
| +}; |
| + |
| +MockConsumer::MockConsumer() { |
| +} |
| + |
| +MockConsumer::~MockConsumer() { |
| +} |
| + |
| +AffiliatedInvalidationServiceProviderTest:: |
| +AffiliatedInvalidationServiceProviderTest() |
| + : fake_user_manager_(new chromeos::FakeUserManager), |
| + user_manager_enabler_(fake_user_manager_), |
| + install_attributes_("example.com", |
| + "user@example.com", |
| + "device_id", |
| + DEVICE_MODE_ENTERPRISE), |
| + profile_manager_(TestingBrowserProcess::GetGlobal()) { |
| +} |
| + |
| +void AffiliatedInvalidationServiceProviderTest::SetUp() { |
| + chromeos::SystemSaltGetter::Initialize(); |
| + chromeos::DBusThreadManager::Initialize(); |
| + chromeos::DeviceOAuth2TokenServiceFactory::Initialize(); |
| + ASSERT_TRUE(profile_manager_.SetUp()); |
| + |
| + test_device_settings_service_.reset(new |
| + chromeos::ScopedTestDeviceSettingsService); |
| + test_cros_settings_.reset(new chromeos::ScopedTestCrosSettings); |
| + |
| + invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
| + RegisterTestingFactory(BuildProfileInvalidationProvider); |
| + |
| + provider_.reset(new AffiliatedInvalidationServiceProvider); |
| +} |
| + |
| +void AffiliatedInvalidationServiceProviderTest::TearDown() { |
| + provider_.reset(); |
| + |
| + invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
| + RegisterTestingFactory(nullptr); |
| + chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); |
| + chromeos::DBusThreadManager::Shutdown(); |
| + chromeos::SystemSaltGetter::Shutdown(); |
| +} |
| + |
| +Profile* AffiliatedInvalidationServiceProviderTest::LogInAndReturnProfile( |
| + const std::string& user_id) { |
| + fake_user_manager_->AddUser(user_id); |
| + Profile* profile = profile_manager_.CreateTestingProfile(user_id); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| + content::NotificationService::AllSources(), |
| + content::Details<Profile>(profile)); |
| + return profile; |
| +} |
| + |
| +AffiliatedInvalidationServiceProvider* |
| +AffiliatedInvalidationServiceProviderTest::GetProvider() { |
| + return provider_.get(); |
|
Mattias Nissler (ping if slow)
2015/01/13 09:50:16
Is there a good reason to have everything go throu
bartfab (slow)
2015/01/13 17:45:23
Just practicing good OOD encapsulation. I can make
|
| +} |
| + |
| +invalidation::TiclInvalidationService* |
| +AffiliatedInvalidationServiceProviderTest::GetDeviceInvalidationService() { |
| + return provider_->GetDeviceInvalidationServiceForTest(); |
| +} |
| + |
| +bool |
| +AffiliatedInvalidationServiceProviderTest:: |
| +HasDeviceInvalidationServiceObserver() const { |
| + return provider_->HasDeviceInvalidationServiceObserverForTest(); |
| +} |
| + |
| +invalidation::FakeInvalidationService* |
| +AffiliatedInvalidationServiceProviderTest::GetProfileInvalidationService( |
| + Profile* profile) { |
| + invalidation::ProfileInvalidationProvider* invalidation_provider = |
| + static_cast<invalidation::ProfileInvalidationProvider*>( |
| + invalidation::ProfileInvalidationProviderFactory::GetInstance()-> |
| + GetServiceForBrowserContext(profile, false)); |
| + if (!invalidation_provider) |
| + return nullptr; |
| + return static_cast<invalidation::FakeInvalidationService*>( |
| + invalidation_provider->GetInvalidationService()); |
| +} |
| + |
| +int AffiliatedInvalidationServiceProviderTest:: |
| + GetProfileInvalidationServiceObserverCount() const { |
| + return provider_->GetProfileInvalidationServiceObserverCountForTest(); |
| +} |
| + |
| +const invalidation::InvalidationService* |
| +AffiliatedInvalidationServiceProviderTest::GetInvalidationService() const { |
| + return provider_->GetInvalidationServiceForTest(); |
| +} |
| + |
| +// No consumers are registered with the AffiliatedInvalidationServiceProvider. |
| +// Verifies that no device-global invalidation service is created. Further |
| +// verifies that when an affiliated user's per-profile invalidation service |
| +// connects, that invalidation service is ignored. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, NoConsumers) { |
| + // Verify that no device-global invalidation service and no per-profile |
| + // invalidation service observers have been created. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
|
Mattias Nissler (ping if slow)
2015/01/13 09:50:15
These tests are very strongly tied to the implemen
bartfab (slow)
2015/01/13 17:45:23
Ensuring that consumers see the right thing is one
|
| + |
| + // Log in as an affiliated user. |
| + Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); |
| + EXPECT_TRUE(profile); |
| + |
| + // Verify that a per-profile invalidation service and an observer for it have |
| + // been created. |
| + invalidation::FakeInvalidationService* profile_invalidation_service = |
| + GetProfileInvalidationService(profile); |
| + EXPECT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that no device-global invalidation service has been created. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that no invalidation service is being made available to consumers. |
| + EXPECT_FALSE(GetInvalidationService()); |
| +} |
| + |
| +// A consumer is registered with the AffiliatedInvalidationServiceProvider. |
| +// Verifies that when no per-profile invalidation service belonging to an |
| +// affiliated user is available, a device-global invalidation service is |
| +// created. Further verifies that when the device-global invalidation service |
| +// connects, it is made available to the consumer. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, |
| + UseDeviceInvalidationService) { |
| + // Register a consumer. Verify that the consumer is not called back |
| + // immediately as no connected invalidation service exists yet. |
| + MockConsumer consumer; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer); |
| + |
| + // Verify that a device-global invalidation service has been created but is |
| + // not being made available to consumers. |
|
Mattias Nissler (ping if slow)
2015/01/13 09:50:15
does it matter to assert this?
bartfab (slow)
2015/01/13 17:45:23
Yes, because the call in line 260 will try to call
|
| + ASSERT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the device-global invalidation service has connected. Verify |
| + // that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, |
| + OnInvalidationServiceSet(GetDeviceInvalidationService())) |
| + .Times(1); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetDeviceInvalidationService()->OnInvalidatorStateChange( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that the device-global invalidation service still exists and is |
| + // being made available to consumers. |
|
Mattias Nissler (ping if slow)
2015/01/13 09:50:15
Didn't you test this per the consumer callback exp
bartfab (slow)
2015/01/13 17:45:23
I tested that the service is *not* made available
|
| + ASSERT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Indicate that the device-global invalidation service has disconnected. |
| + // Verify that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(1); |
| + GetDeviceInvalidationService()->OnInvalidatorStateChange( |
| + syncer::INVALIDATION_CREDENTIALS_REJECTED); |
| + |
| + // Verify that a device-global invalidation service still exists but is not |
| + // being made available to consumers. |
|
Mattias Nissler (ping if slow)
2015/01/13 09:50:15
ditto here
bartfab (slow)
2015/01/13 17:45:23
As above, in reverse - we switched back from *is*
|
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Unregister the consumer. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->UnregisterConsumer(&consumer); |
| +} |
| + |
| +// A consumer is registered with the AffiliatedInvalidationServiceProvider. |
| +// Verifies that when a per-profile invalidation service belonging to an |
| +// affiliated user connects, it is made available to the consumer. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, |
| + UseAffiliatedProfileInvalidationService) { |
| + // Register a consumer. Verify that the consumer is not called back |
| + // immediately as no connected invalidation service exists yet. |
| + MockConsumer consumer; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer); |
| + |
| + // Verify that a device-global invalidation service has been created but is |
| + // not being made available to consumers. |
|
Mattias Nissler (ping if slow)
2015/01/13 09:50:16
ditto
bartfab (slow)
2015/01/13 17:45:23
This is a new test, so we check the starting state
|
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Log in as an affiliated user. |
| + Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); |
| + EXPECT_TRUE(profile); |
| + |
| + // Verify that a per-profile invalidation service and an observer for it have |
| + // been created. |
|
Mattias Nissler (ping if slow)
2015/01/13 09:50:15
ditto - do we care in the test? The consumer shoul
bartfab (slow)
2015/01/13 17:45:23
We can discuss this offline if you want. The thing
|
| + invalidation::FakeInvalidationService* profile_invalidation_service = |
| + GetProfileInvalidationService(profile); |
| + ASSERT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that a device-global invalidation service still exists. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that no invalidation service is being made available to consumers. |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the per-profile invalidation service has connected. Verify |
| + // that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(profile_invalidation_service)) |
| + .Times(1); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + profile_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that the device-global invalidation service has been destroyed. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the per-profile invalidation service is being made available to |
| + // consumers and an observer for it still exists. |
| + profile_invalidation_service = GetProfileInvalidationService(profile); |
| + ASSERT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(profile_invalidation_service, GetInvalidationService()); |
| + |
| + // Indicate that the per-profile invalidation service has disconnected. Verify |
| + // that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(1); |
| + profile_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATION_CREDENTIALS_REJECTED); |
| + |
| + // Verify that a device-global invalidation service has been created. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the per-profile invalidation service still exists but is no |
| + // longer being made available to consumers. |
| + profile_invalidation_service = GetProfileInvalidationService(profile); |
| + EXPECT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Unregister the consumer. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->UnregisterConsumer(&consumer); |
| +} |
| + |
| +// A consumer is registered with the AffiliatedInvalidationServiceProvider. |
| +// Verifies that when a per-profile invalidation service belonging to an |
| +// unaffiliated user connects, it is ignored. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, |
| + DoNotUseUnaffiliatedProfileInvalidationService) { |
| + // Register a consumer. Verify that the consumer is not called back |
| + // immediately as no connected invalidation service exists yet. |
| + MockConsumer consumer; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer); |
| + |
| + // Verify that a device-global invalidation service has been created but is |
| + // not being made available to consumers. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Log in as an unaffiliated user. |
| + Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); |
| + EXPECT_TRUE(profile); |
| + |
| + // Verify that a per-profile invalidation service but no observer for it has |
| + // been created. |
| + invalidation::FakeInvalidationService* profile_invalidation_service = |
| + GetProfileInvalidationService(profile); |
| + ASSERT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that a device-global invalidation service still exists. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that no invalidation service is being made available to consumers. |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the per-profile invalidation service has connected. Verify |
| + // that the consumer is not called back. |
| + profile_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that a device-global invalidation service still exists. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the per-profile invalidation service still exists but is not |
| + // being made available to consumers. |
| + profile_invalidation_service = GetProfileInvalidationService(profile); |
| + EXPECT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Unregister the consumer. |
| + GetProvider()->UnregisterConsumer(&consumer); |
| +} |
| + |
| +// A consumer is registered with the AffiliatedInvalidationServiceProvider. A |
| +// device-global invalidation service exists, is connected and is made available |
| +// to the consumer. Verifies that when a per-profile invalidation service |
| +// belonging to an affiliated user connects, it is made available to the |
| +// consumer instead and the device-global invalidation service is destroyed. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, |
| + SwitchToAffiliatedProfileInvalidationService) { |
| + // Register a consumer. Verify that the consumer is not called back |
| + // immediately as no connected invalidation service exists yet. |
| + MockConsumer consumer; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer); |
| + |
| + // Verify that a device-global invalidation service has been created but is |
| + // not being made available to consumers. |
| + ASSERT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the device-global invalidation service has connected. Verify |
| + // that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, |
| + OnInvalidationServiceSet(GetDeviceInvalidationService())) |
| + .Times(1); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetDeviceInvalidationService()->OnInvalidatorStateChange( |
| + syncer::INVALIDATIONS_ENABLED); |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + |
| + // Verify that the device-global invalidation service still exists and is |
| + // being made available to consumers. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Log in as an affiliated user. |
| + Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); |
| + EXPECT_TRUE(profile); |
| + |
| + // Verify that a per-profile invalidation service and an observer for it have |
| + // been created. |
| + invalidation::FakeInvalidationService* profile_invalidation_service = |
| + GetProfileInvalidationService(profile); |
| + ASSERT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that a device-global invalidation service still exists. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the device-global invalidation service is still being made |
| + // available to consumers. |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Indicate that the per-profile invalidation service has connected. Verify |
| + // that the consumer is informed that the device-global invalidation service |
| + // is no longer to be used and the per-profile invalidation service is to be |
| + // used instead. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + Sequence sequence; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()) |
| + .Times(1) |
| + .InSequence(sequence); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(profile_invalidation_service)) |
| + .Times(1) |
| + .InSequence(sequence); |
| + profile_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that the device-global invalidation service has been destroyed. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the per-profile invalidation service is being made available to |
| + // consumers and an observer for it still exists. |
| + profile_invalidation_service = GetProfileInvalidationService(profile); |
| + ASSERT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(profile_invalidation_service, GetInvalidationService()); |
| + |
| + // Unregister the consumer. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(1); |
| + GetProvider()->UnregisterConsumer(&consumer); |
| +} |
| + |
| +// A consumer is registered with the AffiliatedInvalidationServiceProvider. A |
| +// device-global invalidation service exists, is connected and is made available |
| +// to the consumer. Verifies that when a per-profile invalidation service |
| +// belonging to an unaffiliated user connects, it is ignored and the |
| +// device-global invalidation service continues to be made available to the |
| +// consumer. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, |
| + DoNotSwitchToUnaffiliatedProfileInvalidationService) { |
| + // Register a consumer. Verify that the consumer is not called back |
| + // immediately as no connected invalidation service exists yet. |
| + MockConsumer consumer; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer); |
| + |
| + // Verify that a device-global invalidation service has been created but is |
| + // not being made available to consumers. |
| + ASSERT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the device-global invalidation service has connected. Verify |
| + // that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, |
| + OnInvalidationServiceSet(GetDeviceInvalidationService())) |
| + .Times(1); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetDeviceInvalidationService()->OnInvalidatorStateChange( |
| + syncer::INVALIDATIONS_ENABLED); |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + |
| + // Verify that the device-global invalidation service still exists and is |
| + // being made available to consumers. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Log in as an unaffiliated user. |
| + Profile* profile = LogInAndReturnProfile(kUnaffiliatedUserID); |
| + EXPECT_TRUE(profile); |
| + |
| + // Verify that a per-profile invalidation service but no observer for it has |
| + // been created. |
| + invalidation::FakeInvalidationService* profile_invalidation_service = |
| + GetProfileInvalidationService(profile); |
| + ASSERT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that a device-global invalidation service still exists. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the device-global invalidation service is still being made |
| + // available to consumers. |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Indicate that the per-profile invalidation service has connected. Verify |
| + // that the consumer is not called back. |
| + profile_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that the device-global invalidation service still exists and is |
| + // being made available to consumers. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Verify that the per-profile invalidation service still exists. |
| + profile_invalidation_service = GetProfileInvalidationService(profile); |
| + EXPECT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Unregister the consumer. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(1); |
| + GetProvider()->UnregisterConsumer(&consumer); |
| +} |
| + |
| +// A consumer is registered with the AffiliatedInvalidationServiceProvider. A |
| +// per-profile invalidation service belonging to an affiliated user exists, is |
| +// connected and is made available to the consumer. Verifies that when the |
| +// per-profile invalidation service disconnects, a device-global invalidation |
| +// service is created. Further verifies that when the device-global invalidation |
| +// service connects, it is made available to the consumer. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, |
| + SwitchToDeviceInvalidationService) { |
| + // Register a consumer. Verify that the consumer is not called back |
| + // immediately as no connected invalidation service exists yet. |
| + MockConsumer consumer; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer); |
| + |
| + // Verify that a device-global invalidation service has been created but is |
| + // not being made available to consumers. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Log in as an affiliated user. |
| + Profile* profile = LogInAndReturnProfile(kAffiliatedUserID1); |
| + EXPECT_TRUE(profile); |
| + |
| + // Verify that a per-profile invalidation service and an observer for it have |
| + // been created. |
| + invalidation::FakeInvalidationService* profile_invalidation_service = |
| + GetProfileInvalidationService(profile); |
| + ASSERT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that a device-global invalidation service still exists. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that no invalidation service is being made available to consumers. |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the per-profile invalidation service has connected. Verify |
| + // that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(profile_invalidation_service)) |
| + .Times(1); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + profile_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that the device-global invalidation service has been destroyed. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the per-profile invalidation service is being made available to |
| + // consumers and an observer for it still exists. |
| + profile_invalidation_service = GetProfileInvalidationService(profile); |
| + ASSERT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(profile_invalidation_service, GetInvalidationService()); |
| + |
| + // Indicate that the per-profile invalidation service has disconnected. Verify |
| + // that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(1); |
| + profile_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATION_CREDENTIALS_REJECTED); |
| + |
| + // Verify that a device-global invalidation service has been created. |
| + ASSERT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the per-profile invalidation service still exists but is no |
| + // longer being made available to consumers. |
| + profile_invalidation_service = GetProfileInvalidationService(profile); |
| + EXPECT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the device-global invalidation service has connected. Verify |
| + // that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, |
| + OnInvalidationServiceSet(GetDeviceInvalidationService())) |
| + .Times(1); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetDeviceInvalidationService()->OnInvalidatorStateChange( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that the device-global invalidation service still exists and is |
| + // being made available to consumers. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Verify that the per-profile invalidation service still exists. |
| + profile_invalidation_service = GetProfileInvalidationService(profile); |
| + EXPECT_TRUE(profile_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Unregister the consumer. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(1); |
| + GetProvider()->UnregisterConsumer(&consumer); |
| +} |
| + |
| +// A consumer is registered with the AffiliatedInvalidationServiceProvider. A |
| +// per-profile invalidation service belonging to a first affiliated user exists, |
| +// is connected and is made available to the consumer. A per-profile |
| +// invalidation service belonging to a second affiliated user also exists and is |
| +// connected. Verifies that when the per-profile invalidation service belonging |
| +// to the first user disconnects, the per-profile invalidation service belonging |
| +// to the second user is made available to the consumer instead. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, |
| + SwitchBetweenAffiliatedProfileInvalidationServices) { |
| + // Register a consumer. Verify that the consumer is not called back |
| + // immediately as no connected invalidation service exists yet. |
| + MockConsumer consumer; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer); |
| + |
| + // Verify that a device-global invalidation service has been created but is |
| + // not being made available to consumers. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Log in as a first affiliated user. |
| + Profile* profile_1 = LogInAndReturnProfile(kAffiliatedUserID1); |
| + EXPECT_TRUE(profile_1); |
| + |
| + // Verify that a per-profile invalidation service fr the first user and an |
| + // observer for it have been created. |
| + invalidation::FakeInvalidationService* profile_1_invalidation_service = |
| + GetProfileInvalidationService(profile_1); |
| + ASSERT_TRUE(profile_1_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that a device-global invalidation service still exists. |
| + EXPECT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that no invalidation service is being made available to consumers. |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the first user's per-profile invalidation service has |
| + // connected. Verify that the consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, |
| + OnInvalidationServiceSet(profile_1_invalidation_service)) |
| + .Times(1); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + profile_1_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATIONS_ENABLED); |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(0); |
| + |
| + // Verify that the device-global invalidation service has been destroyed. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that the per-profile invalidation service for the first user is |
| + // being made available to consumers and an observer for it still exists. |
| + profile_1_invalidation_service = GetProfileInvalidationService(profile_1); |
| + EXPECT_TRUE(profile_1_invalidation_service); |
| + EXPECT_EQ(1, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); |
| + |
| + // Log in as a second affiliated user. |
| + Profile* profile_2 = LogInAndReturnProfile(kAffiliatedUserID2); |
| + EXPECT_TRUE(profile_2); |
| + |
| + // Verify that the device-global invalidation service still does not exist. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that a per-profile invalidation service still exists for the first |
| + // user and one has been created for the second user. |
| + profile_1_invalidation_service = GetProfileInvalidationService(profile_1); |
| + EXPECT_TRUE(profile_1_invalidation_service); |
| + invalidation::FakeInvalidationService* profile_2_invalidation_service = |
| + GetProfileInvalidationService(profile_2); |
| + ASSERT_TRUE(profile_2_invalidation_service); |
| + EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that the per-profile invalidation service for the first user is |
| + // being made available to consumers. |
| + EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); |
| + |
| + // Indicate that the second user's per-profile invalidation service has |
| + // connected. Verify that the consumer is not called back. |
| + profile_2_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that the device-global invalidation service still does not exist. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that per-profile invalidation services still exist for both users. |
| + profile_1_invalidation_service = GetProfileInvalidationService(profile_1); |
| + ASSERT_TRUE(profile_1_invalidation_service); |
| + profile_2_invalidation_service = GetProfileInvalidationService(profile_2); |
| + EXPECT_TRUE(profile_2_invalidation_service); |
| + EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that the per-profile invalidation service for the first user is |
| + // being made available to consumers. |
| + EXPECT_EQ(profile_1_invalidation_service, GetInvalidationService()); |
| + |
| + // Indicate that the first user's per-profile invalidation service has |
| + // disconnected. Verify that the consumer is informed that the first user's |
| + // per-profile invalidation service is no longer to be used and the second |
| + // user's per-profile invalidation service is to be used instead. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + Sequence sequence; |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()) |
| + .Times(1) |
| + .InSequence(sequence); |
| + EXPECT_CALL(consumer, |
| + OnInvalidationServiceSet(profile_2_invalidation_service)) |
| + .Times(1) |
| + .InSequence(sequence); |
| + profile_1_invalidation_service->SetInvalidatorState( |
| + syncer::INVALIDATION_CREDENTIALS_REJECTED); |
| + |
| + // Verify that the device-global invalidation service still does not exist. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + |
| + // Verify that per-profile invalidation services still exist for both users. |
| + profile_1_invalidation_service = GetProfileInvalidationService(profile_1); |
| + EXPECT_TRUE(profile_1_invalidation_service); |
| + profile_2_invalidation_service = GetProfileInvalidationService(profile_2); |
| + EXPECT_TRUE(profile_2_invalidation_service); |
| + EXPECT_EQ(2, GetProfileInvalidationServiceObserverCount()); |
| + |
| + // Verify that the per-profile invalidation service for the second user is |
| + // being made available to consumers. |
| + EXPECT_EQ(profile_2_invalidation_service, GetInvalidationService()); |
| + |
| + // Unregister the consumer. |
| + Mock::VerifyAndClearExpectations(&consumer); |
| + EXPECT_CALL(consumer, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer, OnInvalidationServiceReset()).Times(1); |
| + GetProvider()->UnregisterConsumer(&consumer); |
| +} |
| + |
| +// A consumer is registered with the AffiliatedInvalidationServiceProvider. A |
| +// device-global invalidation service exists, is connected and is made available |
| +// to the consumer. Verifies that when a second consumer registers, the |
| +// device-global invalidation service is made available to it as well. Further |
| +// verifies that when the first consumer unregisters, the device-global |
| +// invalidation service is not destroyed and remains available to the second |
| +// consumer. Further verifies that when the second consumer also unregisters, |
| +// the device-global invalidation service is destroyed. |
| +TEST_F(AffiliatedInvalidationServiceProviderTest, MultipleConsumers) { |
| + // Register a first consumer. Verify that the consumer is not called back |
| + // immediately as no connected invalidation service exists yet. |
| + MockConsumer consumer_1; |
| + EXPECT_CALL(consumer_1, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer_1, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer_1); |
| + |
| + // Verify that a device-global invalidation service has been created but is |
| + // not being made available to consumers. |
| + ASSERT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| + |
| + // Indicate that the device-global invalidation service has connected. Verify |
| + // that the first consumer is informed about this. |
| + Mock::VerifyAndClearExpectations(&consumer_1); |
| + EXPECT_CALL(consumer_1, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer_1, |
| + OnInvalidationServiceSet(GetDeviceInvalidationService())) |
| + .Times(1); |
| + EXPECT_CALL(consumer_1, OnInvalidationServiceReset()).Times(0); |
| + GetDeviceInvalidationService()->OnInvalidatorStateChange( |
| + syncer::INVALIDATIONS_ENABLED); |
| + |
| + // Verify that the device-global invalidation service still exists and is |
| + // being made available to consumers. |
| + ASSERT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Register a second consumer. Verify that the consumer is called back |
| + // immediately as a connected invalidation service is available. |
| + MockConsumer consumer_2; |
| + EXPECT_CALL(consumer_2, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer_2, |
| + OnInvalidationServiceSet(GetDeviceInvalidationService())) |
| + .Times(1); |
| + EXPECT_CALL(consumer_2, OnInvalidationServiceReset()).Times(0); |
| + GetProvider()->RegisterConsumer(&consumer_2); |
| + Mock::VerifyAndClearExpectations(&consumer_2); |
| + EXPECT_CALL(consumer_2, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer_2, OnInvalidationServiceReset()).Times(0); |
| + |
| + // Unregister the first consumer. |
| + Mock::VerifyAndClearExpectations(&consumer_1); |
| + EXPECT_CALL(consumer_1, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer_1, OnInvalidationServiceReset()).Times(1); |
| + GetProvider()->UnregisterConsumer(&consumer_1); |
| + Mock::VerifyAndClearExpectations(&consumer_1); |
| + EXPECT_CALL(consumer_1, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer_1, OnInvalidationServiceReset()).Times(0); |
| + |
| + // Verify that the device-global invalidation service still exists and is |
| + // being made available to consumers. |
| + ASSERT_TRUE(GetDeviceInvalidationService()); |
| + EXPECT_TRUE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_EQ(GetDeviceInvalidationService(), GetInvalidationService()); |
| + |
| + // Unregister the second consumer. |
| + Mock::VerifyAndClearExpectations(&consumer_2); |
| + EXPECT_CALL(consumer_2, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer_2, OnInvalidationServiceReset()).Times(1); |
| + GetProvider()->UnregisterConsumer(&consumer_2); |
| + Mock::VerifyAndClearExpectations(&consumer_2); |
| + EXPECT_CALL(consumer_2, OnInvalidationServiceSet(_)).Times(0); |
| + EXPECT_CALL(consumer_2, OnInvalidationServiceReset()).Times(0); |
| + |
| + // Verify that the device-global invalidation service has been destroyed. |
| + EXPECT_FALSE(GetDeviceInvalidationService()); |
| + EXPECT_FALSE(HasDeviceInvalidationServiceObserver()); |
| + EXPECT_EQ(0, GetProfileInvalidationServiceObserverCount()); |
| + EXPECT_FALSE(GetInvalidationService()); |
| +} |
| + |
| +} // namespace policy |