OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_invalidation_service.h" | 5 #include "chrome/browser/invalidation/ticl_invalidation_service.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/invalidation/invalidation_service_factory.h" | 8 #include "chrome/browser/invalidation/invalidation_service_factory.h" |
9 #include "chrome/browser/invalidation/invalidation_service_test_template.h" | 9 #include "chrome/browser/invalidation/invalidation_service_test_template.h" |
10 #include "chrome/browser/invalidation/profile_invalidation_auth_provider.h" | 10 #include "chrome/browser/invalidation/profile_invalidation_auth_provider.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 | 100 |
101 protected: | 101 protected: |
102 scoped_ptr<TestingProfile> profile_; | 102 scoped_ptr<TestingProfile> profile_; |
103 SigninManagerBase* fake_signin_manager_; | 103 SigninManagerBase* fake_signin_manager_; |
104 scoped_ptr<FakeProfileOAuth2TokenService> token_service_; | 104 scoped_ptr<FakeProfileOAuth2TokenService> token_service_; |
105 scoped_ptr<TiclInvalidationService> invalidation_service_; | 105 scoped_ptr<TiclInvalidationService> invalidation_service_; |
106 }; | 106 }; |
107 | 107 |
108 TEST_F(TiclInvalidationServiceChannelTest, ChannelSelectionTest) { | 108 TEST_F(TiclInvalidationServiceChannelTest, ChannelSelectionTest) { |
109 TiclInvalidationService::InvalidationNetworkChannel expected_gcm_channel = | |
110 TiclInvalidationService::GCM_NETWORK_CHANNEL; | |
111 #if defined(OS_IOS) | |
112 expected_gcm_channel = TiclInvalidationService::PUSH_CLIENT_CHANNEL; | |
113 #endif | |
114 | |
115 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); | 109 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); |
116 | 110 |
117 // If stars allign use GCM channel. | 111 // If stars allign use GCM channel. |
118 profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); | 112 profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); |
119 profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, | 113 profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, |
120 true); | 114 true); |
121 EXPECT_EQ(expected_gcm_channel, GetNetworkChannel()); | 115 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); |
122 | 116 |
123 // If Invalidation channel setting is not set or says false fall back to push | 117 // If Invalidation channel setting is not set or says false fall back to push |
124 // channel. | 118 // channel. |
125 profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); | 119 profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); |
126 | 120 |
127 profile_->GetPrefs()->ClearPref(prefs::kInvalidationServiceUseGCMChannel); | 121 profile_->GetPrefs()->ClearPref(prefs::kInvalidationServiceUseGCMChannel); |
128 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); | 122 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); |
129 | 123 |
130 profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, | 124 profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, |
131 false); | 125 false); |
132 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); | 126 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); |
133 | 127 |
134 // If invalidation channel setting says use GCM but GCM is not ALWAYS_ENABLED | 128 // If invalidation channel setting says use GCM but GCM is not ALWAYS_ENABLED |
135 // then fall back to push channel. | 129 // then fall back to push channel. |
136 profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, | 130 profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, |
137 false); | 131 false); |
138 | 132 |
139 profile_->GetPrefs()->ClearPref(prefs::kGCMChannelEnabled); | 133 profile_->GetPrefs()->ClearPref(prefs::kGCMChannelEnabled); |
140 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); | 134 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); |
141 | 135 |
142 profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, false); | 136 profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, false); |
143 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); | 137 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); |
144 | 138 |
145 // If first invalidation setting gets enabled and after that gcm setting gets | 139 // If first invalidation setting gets enabled and after that gcm setting gets |
146 // enabled then should still switch to GCM channel. | 140 // enabled then should still switch to GCM channel. |
147 profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, | 141 profile_->GetPrefs()->SetBoolean(prefs::kInvalidationServiceUseGCMChannel, |
148 true); | 142 true); |
149 profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); | 143 profile_->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); |
150 EXPECT_EQ(expected_gcm_channel, GetNetworkChannel()); | 144 EXPECT_EQ(TiclInvalidationService::GCM_NETWORK_CHANNEL, GetNetworkChannel()); |
151 } | 145 } |
152 | 146 |
153 } // namespace invalidation | 147 } // namespace invalidation |
OLD | NEW |