#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
-#include "chrome/browser/invalidation/ticl_invalidation_service.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 "components/invalidation/fake_invalidation_state_tracker.h"
+#include "components/invalidation/invalidation_state_tracker.h"
+#include "components/invalidation/ticl_invalidation_service.h"
#include "components/invalidation/ticl_settings_provider.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 {
void TiclProfileSettingsProviderTest::SetUp() {
invalidation_service_.reset(new TiclInvalidationService(
+ "TestUserAgent",
scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)),
scoped_ptr<TiclSettingsProvider>(
new TiclProfileSettingsProvider(&profile_)),
- gcm::GCMProfileServiceFactory::GetForProfile(&profile_),
+ gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(),
profile_.GetRequestContext()));
invalidation_service_->Init(scoped_ptr<syncer::InvalidationStateTracker>(
new syncer::FakeInvalidationStateTracker));
}
void TiclProfileSettingsProviderTest::TearDown() {
- invalidation_service_->Shutdown();
+ invalidation_service_.reset();
}
TiclInvalidationService::InvalidationNetworkChannel
}
TEST_F(TiclProfileSettingsProviderTest, ChannelSelectionTest) {
- EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
+ // Default value should be GCM channel.
+ EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
PrefService* prefs = profile_.GetPrefs();
- // If stars align, use GCM channel.
+ // If GCM is enabled and invalidation channel setting is not set or set to
+ // true then 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());
+ EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
- prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
- EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
+ prefs->ClearPref(prefs::kGCMChannelEnabled);
+ prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
+ EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
- // If invalidation channel setting says use GCM but GCM is not ALWAYS_ENABLED,
- // fall back to push channel.
+ // If invalidation channel setting is set to false, fall back to push channel.
+ prefs->SetBoolean(prefs::kGCMChannelEnabled, true);
prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
-
- prefs->ClearPref(prefs::kGCMChannelEnabled);
EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
+ // If invalidation channel setting says use GCM but GCM is not enabled, fall
+ // back to push channel.
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());
+ EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
}
} // namespace invalidation