Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: components/invalidation/impl/ticl_profile_settings_provider_unittest.cc

Issue 1418573005: [invalidation] Componentize TiclProfileSettingsProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Maintain pref registration on Android Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/invalidation/impl/ticl_profile_settings_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/invalidation/ticl_profile_settings_provider.h" 5 #include "components/invalidation/impl/ticl_profile_settings_provider.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
8 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "components/gcm_driver/fake_gcm_driver.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" 11 #include "components/gcm_driver/gcm_channel_status_syncer.h"
15 #include "components/invalidation/impl/fake_invalidation_state_tracker.h" 12 #include "components/invalidation/impl/fake_invalidation_state_tracker.h"
13 #include "components/invalidation/impl/invalidation_prefs.h"
16 #include "components/invalidation/impl/invalidation_state_tracker.h" 14 #include "components/invalidation/impl/invalidation_state_tracker.h"
15 #include "components/invalidation/impl/profile_invalidation_provider.h"
17 #include "components/invalidation/impl/ticl_invalidation_service.h" 16 #include "components/invalidation/impl/ticl_invalidation_service.h"
18 #include "components/invalidation/impl/ticl_settings_provider.h" 17 #include "components/invalidation/impl/ticl_settings_provider.h"
19 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "components/pref_registry/testing_pref_service_syncable.h"
20 #include "google_apis/gaia/fake_identity_provider.h" 19 #include "google_apis/gaia/fake_identity_provider.h"
21 #include "google_apis/gaia/fake_oauth2_token_service.h" 20 #include "google_apis/gaia/fake_oauth2_token_service.h"
22 #include "google_apis/gaia/identity_provider.h" 21 #include "google_apis/gaia/identity_provider.h"
23 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
23 #include "net/url_request/url_request_test_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 namespace invalidation { 26 namespace invalidation {
27 27
28 class TiclProfileSettingsProviderTest : public testing::Test { 28 class TiclProfileSettingsProviderTest : public testing::Test {
29 protected: 29 protected:
30 TiclProfileSettingsProviderTest(); 30 TiclProfileSettingsProviderTest();
31 ~TiclProfileSettingsProviderTest() override; 31 ~TiclProfileSettingsProviderTest() override;
32 32
33 // testing::Test: 33 // testing::Test:
34 void SetUp() override; 34 void SetUp() override;
35 void TearDown() override; 35 void TearDown() override;
36 36
37 TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel(); 37 TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel();
38 38
39 content::TestBrowserThreadBundle thread_bundle_; 39 base::MessageLoop message_loop_;
40 TestingProfile profile_; 40 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
41 gcm::FakeGCMDriver gcm_driver_;
42 user_prefs::TestingPrefServiceSyncable pref_service_;
41 FakeOAuth2TokenService token_service_; 43 FakeOAuth2TokenService token_service_;
42 44
43 scoped_ptr<TiclInvalidationService> invalidation_service_; 45 scoped_ptr<TiclInvalidationService> invalidation_service_;
44 46
45 private: 47 private:
46 DISALLOW_COPY_AND_ASSIGN(TiclProfileSettingsProviderTest); 48 DISALLOW_COPY_AND_ASSIGN(TiclProfileSettingsProviderTest);
47 }; 49 };
48 50
49 TiclProfileSettingsProviderTest::TiclProfileSettingsProviderTest() { 51 TiclProfileSettingsProviderTest::TiclProfileSettingsProviderTest() {}
50 }
51 52
52 TiclProfileSettingsProviderTest::~TiclProfileSettingsProviderTest() { 53 TiclProfileSettingsProviderTest::~TiclProfileSettingsProviderTest() {}
53 }
54 54
55 void TiclProfileSettingsProviderTest::SetUp() { 55 void TiclProfileSettingsProviderTest::SetUp() {
56 gcm::GCMChannelStatusSyncer::RegisterProfilePrefs(pref_service_.registry());
57 ProfileInvalidationProvider::RegisterProfilePrefs(pref_service_.registry());
58
59 request_context_getter_ =
60 new net::TestURLRequestContextGetter(base::ThreadTaskRunnerHandle::Get());
61
56 invalidation_service_.reset(new TiclInvalidationService( 62 invalidation_service_.reset(new TiclInvalidationService(
57 "TestUserAgent", 63 "TestUserAgent",
58 scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)), 64 scoped_ptr<IdentityProvider>(new FakeIdentityProvider(&token_service_)),
59 scoped_ptr<TiclSettingsProvider>( 65 scoped_ptr<TiclSettingsProvider>(
60 new TiclProfileSettingsProvider(&profile_)), 66 new TiclProfileSettingsProvider(&pref_service_)),
61 gcm::GCMProfileServiceFactory::GetForProfile(&profile_)->driver(), 67 &gcm_driver_, request_context_getter_));
62 profile_.GetRequestContext()));
63 invalidation_service_->Init(scoped_ptr<syncer::InvalidationStateTracker>( 68 invalidation_service_->Init(scoped_ptr<syncer::InvalidationStateTracker>(
64 new syncer::FakeInvalidationStateTracker)); 69 new syncer::FakeInvalidationStateTracker));
65 } 70 }
66 71
67 void TiclProfileSettingsProviderTest::TearDown() { 72 void TiclProfileSettingsProviderTest::TearDown() {
68 invalidation_service_.reset(); 73 invalidation_service_.reset();
69 } 74 }
70 75
71 TiclInvalidationService::InvalidationNetworkChannel 76 TiclInvalidationService::InvalidationNetworkChannel
72 TiclProfileSettingsProviderTest::GetNetworkChannel() { 77 TiclProfileSettingsProviderTest::GetNetworkChannel() {
73 return invalidation_service_->network_channel_type_; 78 return invalidation_service_->network_channel_type_;
74 } 79 }
75 80
76 TEST_F(TiclProfileSettingsProviderTest, ChannelSelectionTest) { 81 TEST_F(TiclProfileSettingsProviderTest, ChannelSelectionTest) {
77 // Default value should be GCM channel. 82 // Default value should be GCM channel.
78 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); 83 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
79 PrefService* prefs = profile_.GetPrefs();
80 84
81 // If GCM is enabled and invalidation channel setting is not set or set to 85 // If GCM is enabled and invalidation channel setting is not set or set to
82 // true then use GCM channel. 86 // true then use GCM channel.
83 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, true); 87 pref_service_.SetBoolean(gcm::prefs::kGCMChannelStatus, true);
84 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true); 88 pref_service_.SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
85 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); 89 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
86 90
87 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, true); 91 pref_service_.SetBoolean(gcm::prefs::kGCMChannelStatus, true);
88 prefs->ClearPref(prefs::kInvalidationServiceUseGCMChannel); 92 pref_service_.ClearPref(prefs::kInvalidationServiceUseGCMChannel);
89 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); 93 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
90 94
91 prefs->ClearPref(gcm::prefs::kGCMChannelStatus); 95 pref_service_.ClearPref(gcm::prefs::kGCMChannelStatus);
92 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true); 96 pref_service_.SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
93 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); 97 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
94 98
95 // If invalidation channel setting says use GCM but GCM is not enabled, do not 99 // If invalidation channel setting says use GCM but GCM is not enabled, do not
96 // fall back to push channel. 100 // fall back to push channel.
97 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, false); 101 pref_service_.SetBoolean(gcm::prefs::kGCMChannelStatus, false);
98 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true); 102 pref_service_.SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true);
99 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); 103 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel());
100 104
101 // If invalidation channel setting is set to false, fall back to push channel. 105 // If invalidation channel setting is set to false, fall back to push channel.
102 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, true); 106 pref_service_.SetBoolean(gcm::prefs::kGCMChannelStatus, true);
103 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false); 107 pref_service_.SetBoolean(prefs::kInvalidationServiceUseGCMChannel, false);
104 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); 108 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel());
105 } 109 }
106 110
107 } // namespace invalidation 111 } // namespace invalidation
OLDNEW
« no previous file with comments | « components/invalidation/impl/ticl_profile_settings_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698