| Index: chrome/browser/invalidation/ticl_invalidation_service_profile_settings_provider_unittest.cc
|
| diff --git a/chrome/browser/invalidation/ticl_invalidation_service_profile_settings_provider_unittest.cc b/chrome/browser/invalidation/ticl_invalidation_service_profile_settings_provider_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..05908ae0041f18c114daab8627794a5cfdec770d
|
| --- /dev/null
|
| +++ b/chrome/browser/invalidation/ticl_invalidation_service_profile_settings_provider_unittest.cc
|
| @@ -0,0 +1,114 @@
|
| +// 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/invalidation/ticl_invalidation_service_profile_settings_provider.h"
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/prefs/pref_service.h"
|
| +#include "chrome/browser/invalidation/ticl_invalidation_service.h"
|
| +#include "chrome/browser/invalidation/ticl_invalidation_service_settings_provider.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/services/gcm/gcm_profile_service.h"
|
| +#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "chrome/test/base/testing_profile.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 "google_apis/gaia/identity_provider.h"
|
| +#include "net/url_request/url_request_context_getter.h"
|
| +#include "sync/notifier/fake_invalidation_state_tracker.h"
|
| +#include "sync/notifier/invalidation_state_tracker.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace invalidation {
|
| +
|
| +class TiclInvalidationServiceProfileSettingsProviderTest
|
| + : public testing::Test {
|
| + protected:
|
| + TiclInvalidationServiceProfileSettingsProviderTest();
|
| + virtual ~TiclInvalidationServiceProfileSettingsProviderTest();
|
| +
|
| + // testing::Test:
|
| + virtual void SetUp() OVERRIDE;
|
| + virtual void TearDown() OVERRIDE;
|
| +
|
| + TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel();
|
| +
|
| + content::TestBrowserThreadBundle thread_bundle_;
|
| + TestingProfile profile_;
|
| + FakeOAuth2TokenService token_service_;
|
| +
|
| + scoped_ptr<TiclInvalidationService> invalidation_service_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(TiclInvalidationServiceProfileSettingsProviderTest);
|
| +};
|
| +
|
| +TiclInvalidationServiceProfileSettingsProviderTest::
|
| + TiclInvalidationServiceProfileSettingsProviderTest() {
|
| +}
|
| +
|
| +TiclInvalidationServiceProfileSettingsProviderTest::
|
| + ~TiclInvalidationServiceProfileSettingsProviderTest() {
|
| +}
|
| +
|
| +void TiclInvalidationServiceProfileSettingsProviderTest::SetUp() {
|
| + invalidation_service_.reset(new TiclInvalidationService(
|
| + scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)),
|
| + scoped_ptr<TiclInvalidationServiceSettingsProvider>(
|
| + new TiclInvalidationServiceProfileSettingsProvider(&profile_)),
|
| + gcm::GCMProfileServiceFactory::GetForProfile(&profile_),
|
| + profile_.GetRequestContext()));
|
| + invalidation_service_->Init(scoped_ptr<syncer::InvalidationStateTracker>(
|
| + new syncer::FakeInvalidationStateTracker));
|
| +}
|
| +
|
| +void TiclInvalidationServiceProfileSettingsProviderTest::TearDown() {
|
| + invalidation_service_->Shutdown();
|
| +}
|
| +
|
| +TiclInvalidationService::InvalidationNetworkChannel
|
| + TiclInvalidationServiceProfileSettingsProviderTest::GetNetworkChannel() {
|
| + return invalidation_service_->network_channel_type_;
|
| +}
|
| +
|
| +TEST_F(TiclInvalidationServiceProfileSettingsProviderTest,
|
| + ChannelSelectionTest) {
|
| + EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| + PrefService* prefs = profile_.GetPrefs();
|
| +
|
| + // If stars align, use GCM channel.
|
| + prefs->SetBoolean(prefs::kGCMChannelEnabled, true);
|
| + prefs->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.
|
| + prefs->SetBoolean(prefs::kGCMChannelEnabled, true);
|
| +
|
| + prefs->ClearPref(prefs::kInvalidationServiceUseGCMChannel);
|
| + EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| +
|
| + prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
|
| + EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| +
|
| + // If invalidation channel setting says use GCM but GCM is not ALWAYS_ENABLED,
|
| + // fall back to push channel.
|
| + prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
|
| +
|
| + prefs->ClearPref(prefs::kGCMChannelEnabled);
|
| + EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| +
|
| + prefs->SetBoolean(prefs::kGCMChannelEnabled, false);
|
| + EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
|
| +
|
| + // If invalidation channel setting is enabled first and the GCM setting is
|
| + // enabled after that, switch to GCM channel.
|
| + prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
|
| + prefs->SetBoolean(prefs::kGCMChannelEnabled, true);
|
| + EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
|
| +}
|
| +
|
| +} // namespace invalidation
|
|
|