| Index: chrome/browser/invalidation/ticl_invalidation_service_unittest.cc
|
| diff --git a/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc b/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc
|
| index 44f33b05bbb709c9ca4a0cfae947e5af5e09b147..2f50e04ea567b2f523cdd603c9d276bc3b24aba9 100644
|
| --- a/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc
|
| +++ b/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc
|
| @@ -4,33 +4,89 @@
|
|
|
| #include "chrome/browser/invalidation/ticl_invalidation_service.h"
|
|
|
| -#include "base/prefs/pref_service.h"
|
| -#include "chrome/browser/invalidation/invalidation_service_factory.h"
|
| +#include "base/bind.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "chrome/browser/invalidation/gcm_invalidation_bridge.h"
|
| #include "chrome/browser/invalidation/invalidation_service_test_template.h"
|
| -#include "chrome/browser/invalidation/invalidator_storage.h"
|
| -#include "chrome/browser/services/gcm/gcm_profile_service.h"
|
| -#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
|
| #include "chrome/browser/services/gcm/gcm_service.h"
|
| -#include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
|
| -#include "chrome/browser/signin/fake_signin_manager.h"
|
| -#include "chrome/browser/signin/profile_identity_provider.h"
|
| -#include "chrome/browser/signin/signin_manager_factory.h"
|
| -#include "chrome/common/pref_names.h"
|
| -#include "chrome/test/base/testing_profile.h"
|
| -#include "components/signin/core/browser/signin_manager.h"
|
| -#include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "google_apis/gaia/fake_identity_provider.h"
|
| +#include "google_apis/gaia/fake_oauth2_token_service.h"
|
| #include "net/url_request/url_request_context_getter.h"
|
| -#include "sync/notifier/fake_invalidation_handler.h"
|
| +#include "sync/notifier/fake_invalidation_state_tracker.h"
|
| #include "sync/notifier/fake_invalidator.h"
|
| #include "sync/notifier/invalidation_state_tracker.h"
|
| -#include "sync/notifier/invalidation_util.h"
|
| +#include "sync/notifier/invalidator.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace invalidation {
|
|
|
| +namespace {
|
| +
|
| +class FakeTiclSettingsProvider : public TiclSettingsProvider {
|
| + public:
|
| + FakeTiclSettingsProvider();
|
| + virtual ~FakeTiclSettingsProvider();
|
| +
|
| + // TiclSettingsProvider:
|
| + virtual bool UseGCMChannel() const OVERRIDE;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(FakeTiclSettingsProvider);
|
| +};
|
| +
|
| +class FakeGCMService : public gcm::GCMService {
|
| + public:
|
| + explicit FakeGCMService(OAuth2TokenService* token_service);
|
| + virtual ~FakeGCMService();
|
| +
|
| + protected:
|
| + // gcm::GCMService:
|
| + virtual bool ShouldStartAutomatically() const OVERRIDE;
|
| + virtual base::FilePath GetStorePath() const OVERRIDE;
|
| + virtual scoped_refptr<net::URLRequestContextGetter>
|
| + GetURLRequestContextGetter() const OVERRIDE;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(FakeGCMService);
|
| +};
|
| +
|
| +FakeTiclSettingsProvider::FakeTiclSettingsProvider() {
|
| +}
|
| +
|
| +FakeTiclSettingsProvider::~FakeTiclSettingsProvider() {
|
| +}
|
| +
|
| +bool FakeTiclSettingsProvider::UseGCMChannel() const {
|
| + return false;
|
| +}
|
| +
|
| +FakeGCMService::FakeGCMService(OAuth2TokenService* token_service)
|
| + : GCMService(scoped_ptr<IdentityProvider>(
|
| + new FakeIdentityProvider(token_service))) {
|
| +}
|
| +
|
| +FakeGCMService::~FakeGCMService() {
|
| +}
|
| +
|
| +bool FakeGCMService::ShouldStartAutomatically() const {
|
| + return false;
|
| +}
|
| +
|
| +base::FilePath FakeGCMService::GetStorePath() const {
|
| + return base::FilePath();
|
| +}
|
| +
|
| +scoped_refptr<net::URLRequestContextGetter>
|
| +FakeGCMService::GetURLRequestContextGetter() const {
|
| + return NULL;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| class TiclInvalidationServiceTestDelegate {
|
| public:
|
| - TiclInvalidationServiceTestDelegate() { }
|
| + TiclInvalidationServiceTestDelegate() {}
|
|
|
| ~TiclInvalidationServiceTestDelegate() {
|
| DestroyInvalidationService();
|
| @@ -42,23 +98,19 @@ class TiclInvalidationServiceTestDelegate {
|
| }
|
|
|
| void CreateUninitializedInvalidationService() {
|
| - profile_.reset(new TestingProfile());
|
| - token_service_.reset(new FakeProfileOAuth2TokenService);
|
| + gcm_service_.reset(new FakeGCMService(&token_service_));
|
| invalidation_service_.reset(new TiclInvalidationService(
|
| - scoped_ptr<IdentityProvider>(new ProfileIdentityProvider(
|
| - SigninManagerFactory::GetForProfile(profile_.get()),
|
| - token_service_.get(),
|
| - NULL)),
|
| - gcm::GCMProfileServiceFactory::GetForProfile(profile_.get()),
|
| - profile_->GetRequestContext(),
|
| - profile_.get()));
|
| + scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)),
|
| + scoped_ptr<TiclSettingsProvider>(new FakeTiclSettingsProvider),
|
| + gcm_service_.get(),
|
| + NULL));
|
| }
|
|
|
| void InitializeInvalidationService() {
|
| fake_invalidator_ = new syncer::FakeInvalidator();
|
| invalidation_service_->InitForTest(
|
| scoped_ptr<syncer::InvalidationStateTracker>(
|
| - new InvalidatorStorage(profile_->GetPrefs())),
|
| + new syncer::FakeInvalidationStateTracker),
|
| fake_invalidator_);
|
| }
|
|
|
| @@ -79,9 +131,10 @@ class TiclInvalidationServiceTestDelegate {
|
| fake_invalidator_->EmitOnIncomingInvalidation(invalidation_map);
|
| }
|
|
|
| - syncer::FakeInvalidator* fake_invalidator_; // owned by the service.
|
| - scoped_ptr<TestingProfile> profile_;
|
| - scoped_ptr<FakeProfileOAuth2TokenService> token_service_;
|
| + FakeOAuth2TokenService token_service_;
|
| + scoped_ptr<gcm::GCMService> gcm_service_;
|
| + syncer::FakeInvalidator* fake_invalidator_; // Owned by the service.
|
| +
|
| scoped_ptr<TiclInvalidationService> invalidation_service_;
|
| };
|
|
|
| @@ -89,93 +142,12 @@ INSTANTIATE_TYPED_TEST_CASE_P(
|
| TiclInvalidationServiceTest, InvalidationServiceTest,
|
| TiclInvalidationServiceTestDelegate);
|
|
|
| -class TiclInvalidationServiceChannelTest : public ::testing::Test {
|
| - public:
|
| - TiclInvalidationServiceChannelTest() {}
|
| - virtual ~TiclInvalidationServiceChannelTest() {}
|
| -
|
| - virtual void SetUp() OVERRIDE {
|
| - TestingProfile::Builder builder;
|
| - builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
|
| - FakeSigninManagerBase::Build);
|
| - profile_ = builder.Build();
|
| - fake_signin_manager_ = static_cast<SigninManagerBase*>(
|
| - SigninManagerFactory::GetForProfile(profile_.get()));
|
| - token_service_.reset(new FakeProfileOAuth2TokenService);
|
| -
|
| - scoped_ptr<IdentityProvider> identity_provider(new ProfileIdentityProvider(
|
| - fake_signin_manager_, token_service_.get(), NULL));
|
| - invalidation_service_.reset(new TiclInvalidationService(
|
| - identity_provider.Pass(),
|
| - gcm::GCMProfileServiceFactory::GetForProfile(profile_.get()),
|
| - profile_->GetRequestContext(),
|
| - profile_.get()));
|
| - invalidation_service_->Init(scoped_ptr<syncer::InvalidationStateTracker>(
|
| - new InvalidatorStorage(profile_->GetPrefs())));
|
| - }
|
| -
|
| - virtual void TearDown() OVERRIDE {
|
| - invalidation_service_->Shutdown();
|
| - }
|
| -
|
| - TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel() {
|
| - return invalidation_service_->network_channel_type_;
|
| - }
|
| -
|
| - protected:
|
| - content::TestBrowserThreadBundle thread_bundle_;
|
| - scoped_ptr<TestingProfile> profile_;
|
| - SigninManagerBase* fake_signin_manager_;
|
| - scoped_ptr<FakeProfileOAuth2TokenService> token_service_;
|
| - scoped_ptr<TiclInvalidationService> invalidation_service_;
|
| -};
|
| -
|
| -TEST_F(TiclInvalidationServiceChannelTest, ChannelSelectionTest) {
|
| - EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| -
|
| - // If stars allign use GCM channel.
|
| - profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true);
|
| - profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel,
|
| - true);
|
| - EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
|
| -
|
| - // If Invalidation channel setting is not set or says false fall back to push
|
| - // channel.
|
| - profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true);
|
| -
|
| - profile_->GetPrefs()->ClearPref(prefs::kInvalidationServiceUseGCMChannel);
|
| - EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| -
|
| - profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel,
|
| - false);
|
| - EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| -
|
| - // If invalidation channel setting says use GCM but GCM is not ALWAYS_ENABLED
|
| - // then fall back to push channel.
|
| - profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel,
|
| - false);
|
| -
|
| - profile_->GetPrefs()->ClearPref(prefs::kGCMChannelEnabled);
|
| - EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| -
|
| - profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, false);
|
| - EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| -
|
| - // If first invalidation setting gets enabled and after that gcm setting gets
|
| - // enabled then should still switch to GCM channel.
|
| - profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel,
|
| - true);
|
| - profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true);
|
| - EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
|
| -}
|
| -
|
| namespace internal {
|
|
|
| class FakeCallbackContainer {
|
| public:
|
| - FakeCallbackContainer()
|
| - : called_(false),
|
| - weak_ptr_factory_(this) { }
|
| + FakeCallbackContainer() : called_(false),
|
| + weak_ptr_factory_(this) {}
|
|
|
| void FakeCallback(const base::DictionaryValue& value) {
|
| called_ = true;
|
| @@ -184,13 +156,12 @@ class FakeCallbackContainer {
|
| bool called_;
|
| base::WeakPtrFactory<FakeCallbackContainer> weak_ptr_factory_;
|
| };
|
| +
|
| } // namespace internal
|
|
|
| // Test that requesting for detailed status doesn't crash even if the
|
| // underlying invalidator is not initialized.
|
| TEST(TiclInvalidationServiceLoggingTest, DetailedStatusCallbacksWork) {
|
| - content::TestBrowserThreadBundle thread_bundle;
|
| -
|
| scoped_ptr<TiclInvalidationServiceTestDelegate> delegate (
|
| new TiclInvalidationServiceTestDelegate());
|
|
|
| @@ -200,15 +171,16 @@ TEST(TiclInvalidationServiceLoggingTest, DetailedStatusCallbacksWork) {
|
|
|
| internal::FakeCallbackContainer fake_container;
|
| invalidator->RequestDetailedStatus(
|
| - base::Bind(&internal::FakeCallbackContainer::FakeCallback,
|
| - fake_container.weak_ptr_factory_.GetWeakPtr()));
|
| + base::Bind(&internal::FakeCallbackContainer::FakeCallback,
|
| + fake_container.weak_ptr_factory_.GetWeakPtr()));
|
| EXPECT_FALSE(fake_container.called_);
|
|
|
| delegate->InitializeInvalidationService();
|
|
|
| invalidator->RequestDetailedStatus(
|
| - base::Bind(&internal::FakeCallbackContainer::FakeCallback,
|
| - fake_container.weak_ptr_factory_.GetWeakPtr()));
|
| + base::Bind(&internal::FakeCallbackContainer::FakeCallback,
|
| + fake_container.weak_ptr_factory_.GetWeakPtr()));
|
| EXPECT_TRUE(fake_container.called_);
|
| }
|
| +
|
| } // namespace invalidation
|
|
|