Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / invalidation / ticl_profile_settings_provider_unittest.cc
blobbaf1d0fcb9359f657c93683e3f89ad9d93950859
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
3 // found in the LICENSE file.
5 #include "chrome/browser/invalidation/ticl_profile_settings_provider.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/services/gcm/gcm_profile_service.h"
11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "components/gcm_driver/gcm_channel_status_syncer.h"
15 #include "components/invalidation/impl/fake_invalidation_state_tracker.h"
16 #include "components/invalidation/impl/invalidation_state_tracker.h"
17 #include "components/invalidation/impl/ticl_invalidation_service.h"
18 #include "components/invalidation/impl/ticl_settings_provider.h"
19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "google_apis/gaia/fake_identity_provider.h"
21 #include "google_apis/gaia/fake_oauth2_token_service.h"
22 #include "google_apis/gaia/identity_provider.h"
23 #include "net/url_request/url_request_context_getter.h"
24 #include "testing/gtest/include/gtest/gtest.h"
26 namespace invalidation {
28 class TiclProfileSettingsProviderTest : public testing::Test {
29 protected:
30 TiclProfileSettingsProviderTest();
31 ~TiclProfileSettingsProviderTest() override;
33 // testing::Test:
34 void SetUp() override;
35 void TearDown() override;
37 TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel();
39 content::TestBrowserThreadBundle thread_bundle_;
40 TestingProfile profile_;
41 FakeOAuth2TokenService token_service_;
43 scoped_ptr<TiclInvalidationService> invalidation_service_;
45 private:
46 DISALLOW_COPY_AND_ASSIGN(TiclProfileSettingsProviderTest);
49 TiclProfileSettingsProviderTest::TiclProfileSettingsProviderTest() {
52 TiclProfileSettingsProviderTest::~TiclProfileSettingsProviderTest() {
55 void TiclProfileSettingsProviderTest::SetUp() {
56 invalidation_service_.reset(new TiclInvalidationService(
57 "TestUserAgent",
58 scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)),
59 scoped_ptr<TiclSettingsProvider>(
60 new TiclProfileSettingsProvider(&profile_)),
61 gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(),
62 profile_.GetRequestContext()));
63 invalidation_service_->Init(scoped_ptr<syncer::InvalidationStateTracker>(
64 new syncer::FakeInvalidationStateTracker));
67 void TiclProfileSettingsProviderTest::TearDown() {
68 invalidation_service_.reset();
71 TiclInvalidationService::InvalidationNetworkChannel
72 TiclProfileSettingsProviderTest::GetNetworkChannel() {
73 return invalidation_service_->network_channel_type_;
76 TEST_F(TiclProfileSettingsProviderTest, ChannelSelectionTest) {
77 // Default value should be GCM channel.
78 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
79 PrefService* prefs = profile_.GetPrefs();
81 // If GCM is enabled and invalidation channel setting is not set or set to
82 // true then use GCM channel.
83 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, true);
84 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
85 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
87 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, true);
88 prefs->ClearPref(prefs::kInvalidationServiceUseGCMChannel);
89 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
91 prefs->ClearPref(gcm::prefs::kGCMChannelStatus);
92 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
93 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
95 // If invalidation channel setting says use GCM but GCM is not enabled, do not
96 // fall back to push channel.
97 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, false);
98 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
99 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
101 // If invalidation channel setting is set to false, fall back to push channel.
102 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, true);
103 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
104 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
107 } // namespace invalidation