OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/invalidation/ticl_profile_settings_provider.h" | |
6 | |
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" | |
25 | |
26 namespace invalidation { | |
27 | |
28 class TiclProfileSettingsProviderTest : public testing::Test { | |
29 protected: | |
30 TiclProfileSettingsProviderTest(); | |
31 ~TiclProfileSettingsProviderTest() override; | |
32 | |
33 // testing::Test: | |
34 void SetUp() override; | |
35 void TearDown() override; | |
36 | |
37 TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel(); | |
38 | |
39 content::TestBrowserThreadBundle thread_bundle_; | |
40 TestingProfile profile_; | |
41 FakeOAuth2TokenService token_service_; | |
42 | |
43 scoped_ptr<TiclInvalidationService> invalidation_service_; | |
44 | |
45 private: | |
46 DISALLOW_COPY_AND_ASSIGN(TiclProfileSettingsProviderTest); | |
47 }; | |
48 | |
49 TiclProfileSettingsProviderTest::TiclProfileSettingsProviderTest() { | |
50 } | |
51 | |
52 TiclProfileSettingsProviderTest::~TiclProfileSettingsProviderTest() { | |
53 } | |
54 | |
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)); | |
65 } | |
66 | |
67 void TiclProfileSettingsProviderTest::TearDown() { | |
68 invalidation_service_.reset(); | |
69 } | |
70 | |
71 TiclInvalidationService::InvalidationNetworkChannel | |
72 TiclProfileSettingsProviderTest::GetNetworkChannel() { | |
73 return invalidation_service_->network_channel_type_; | |
74 } | |
75 | |
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(); | |
80 | |
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()); | |
86 | |
87 prefs->SetBoolean(gcm::prefs::kGCMChannelStatus, true); | |
88 prefs->ClearPref(prefs::kInvalidationServiceUseGCMChannel); | |
89 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); | |
90 | |
91 prefs->ClearPref(gcm::prefs::kGCMChannelStatus); | |
92 prefs->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, true); | |
93 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); | |
94 | |
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()); | |
100 | |
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()); | |
105 } | |
106 | |
107 } // namespace invalidation | |
OLD | NEW |