| OLD | NEW |
| 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 "base/strings/string_number_conversions.h" | 5 #include "base/strings/string_number_conversions.h" |
| 6 #include "google_apis/gcm/engine/gservices_settings.h" | 6 #include "google_apis/gcm/engine/gservices_settings.h" |
| 7 #include "google_apis/gcm/engine/registration_info.h" | 7 #include "google_apis/gcm/engine/registration_info.h" |
| 8 #include "google_apis/gcm/gcm_client.h" | 8 #include "google_apis/gcm/gcm_client.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace gcm { | 11 namespace gcm { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const int64 kAlternativeCheckinInterval = 16 * 60 * 60; | 15 const int64 kAlternativeCheckinInterval = 16 * 60 * 60; |
| 16 const char kAlternativeCheckinURL[] = "http://alternative.url/checkin"; | 16 const char kAlternativeCheckinURL[] = "http://alternative.url/checkin"; |
| 17 const char kAlternativeMCSHostname[] = "alternative.gcm.host"; | 17 const char kAlternativeMCSHostname[] = "alternative.gcm.host"; |
| 18 const int kAlternativeMCSSecurePort = 7777; | 18 const int kAlternativeMCSSecurePort = 7777; |
| 19 const char kAlternativeRegistrationURL[] = | 19 const char kAlternativeRegistrationURL[] = |
| 20 "http://alternative.url/registration"; | 20 "http://alternative.url/registration"; |
| 21 | 21 |
| 22 const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days. | 22 const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days. |
| 23 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin"; | 23 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin"; |
| 24 const char kDefaultRegistrationURL[] = | 24 const char kDefaultRegistrationURL[] = |
| 25 "https://android.clients.google.com/c2dm/register3"; | 25 "https://android.clients.google.com/c2dm/register3"; |
| 26 const char kDefaultSettingsDigest[] = |
| 27 "1-da39a3ee5e6b4b0d3255bfef95601890afd80709"; |
| 28 const char kAlternativeSettingsDigest[] = |
| 29 "1-7da4aa4eb38a8bd3e330e3751cc0899924499134"; |
| 30 |
| 31 void AddSettingsToResponse( |
| 32 checkin_proto::AndroidCheckinResponse& checkin_response, |
| 33 const GServicesSettings::SettingsMap& settings, |
| 34 bool settings_diff) { |
| 35 for (GServicesSettings::SettingsMap::const_iterator iter = settings.begin(); |
| 36 iter != settings.end(); |
| 37 ++iter) { |
| 38 checkin_proto::GservicesSetting* setting = checkin_response.add_setting(); |
| 39 setting->set_name(iter->first); |
| 40 setting->set_value(iter->second); |
| 41 } |
| 42 checkin_response.set_settings_diff(settings_diff); |
| 43 } |
| 26 | 44 |
| 27 } // namespace | 45 } // namespace |
| 28 | 46 |
| 29 class GServicesSettingsTest : public testing::Test { | 47 class GServicesSettingsTest : public testing::Test { |
| 30 public: | 48 public: |
| 31 GServicesSettingsTest(); | 49 GServicesSettingsTest(); |
| 32 virtual ~GServicesSettingsTest(); | 50 virtual ~GServicesSettingsTest(); |
| 33 | 51 |
| 34 virtual void SetUp() OVERRIDE; | |
| 35 | |
| 36 void CheckAllSetToDefault(); | 52 void CheckAllSetToDefault(); |
| 37 void CheckAllSetToAlternative(); | |
| 38 void SetWithAlternativeSettings( | |
| 39 checkin_proto::AndroidCheckinResponse& checkin_response); | |
| 40 | 53 |
| 41 GServicesSettings& settings() { | 54 GServicesSettings& settings() { |
| 42 return gserivces_settings_; | 55 return gserivces_settings_; |
| 43 } | 56 } |
| 44 | 57 |
| 45 const std::map<std::string, std::string>& alternative_settings() { | |
| 46 return alternative_settings_; | |
| 47 } | |
| 48 | |
| 49 std::map<std::string, std::string> alternative_settings_; | |
| 50 | |
| 51 private: | 58 private: |
| 52 GServicesSettings gserivces_settings_; | 59 GServicesSettings gserivces_settings_; |
| 53 }; | 60 }; |
| 54 | 61 |
| 55 GServicesSettingsTest::GServicesSettingsTest() | 62 GServicesSettingsTest::GServicesSettingsTest() |
| 56 : gserivces_settings_() { | 63 : gserivces_settings_() { |
| 57 } | 64 } |
| 58 | 65 |
| 59 GServicesSettingsTest::~GServicesSettingsTest() {} | 66 GServicesSettingsTest::~GServicesSettingsTest() {} |
| 60 | 67 |
| 61 void GServicesSettingsTest::SetUp() { | |
| 62 alternative_settings_["checkin_interval"] = | |
| 63 base::Int64ToString(kAlternativeCheckinInterval); | |
| 64 alternative_settings_["checkin_url"] = kAlternativeCheckinURL; | |
| 65 alternative_settings_["gcm_hostname"] = kAlternativeMCSHostname; | |
| 66 alternative_settings_["gcm_secure_port"] = | |
| 67 base::IntToString(kAlternativeMCSSecurePort); | |
| 68 alternative_settings_["gcm_registration_url"] = kAlternativeRegistrationURL; | |
| 69 } | |
| 70 | |
| 71 void GServicesSettingsTest::CheckAllSetToDefault() { | 68 void GServicesSettingsTest::CheckAllSetToDefault() { |
| 72 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), | 69 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), |
| 73 settings().checkin_interval()); | 70 settings().GetCheckinInterval()); |
| 74 EXPECT_EQ(GURL(kDefaultCheckinURL), settings().checkin_url()); | 71 EXPECT_EQ(GURL(kDefaultCheckinURL), settings().GetCheckinURL()); |
| 75 EXPECT_EQ(GURL("https://mtalk.google.com:5228"), | 72 EXPECT_EQ(GURL("https://mtalk.google.com:5228"), |
| 76 settings().mcs_main_endpoint()); | 73 settings().GetMCSMainEndpoint()); |
| 77 EXPECT_EQ(GURL("https://mtalk.google.com:443"), | 74 EXPECT_EQ(GURL("https://mtalk.google.com:443"), |
| 78 settings().mcs_fallback_endpoint()); | 75 settings().GetMCSFallbackEndpoint()); |
| 79 EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().registration_url()); | 76 EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().GetRegistrationURL()); |
| 80 } | |
| 81 | |
| 82 void GServicesSettingsTest::CheckAllSetToAlternative() { | |
| 83 EXPECT_EQ(base::TimeDelta::FromSeconds(kAlternativeCheckinInterval), | |
| 84 settings().checkin_interval()); | |
| 85 EXPECT_EQ(GURL(kAlternativeCheckinURL), settings().checkin_url()); | |
| 86 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), | |
| 87 settings().mcs_main_endpoint()); | |
| 88 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), | |
| 89 settings().mcs_fallback_endpoint()); | |
| 90 EXPECT_EQ(GURL(kAlternativeRegistrationURL), settings().registration_url()); | |
| 91 } | |
| 92 | |
| 93 void GServicesSettingsTest::SetWithAlternativeSettings( | |
| 94 checkin_proto::AndroidCheckinResponse& checkin_response) { | |
| 95 for (std::map<std::string, std::string>::const_iterator iter = | |
| 96 alternative_settings_.begin(); | |
| 97 iter != alternative_settings_.end(); ++iter) { | |
| 98 checkin_proto::GservicesSetting* setting = checkin_response.add_setting(); | |
| 99 setting->set_name(iter->first); | |
| 100 setting->set_value(iter->second); | |
| 101 } | |
| 102 } | 77 } |
| 103 | 78 |
| 104 // Verifies default values of the G-services settings and settings digest. | 79 // Verifies default values of the G-services settings and settings digest. |
| 105 TEST_F(GServicesSettingsTest, DefaultSettingsAndDigest) { | 80 TEST_F(GServicesSettingsTest, DefaultSettingsAndDigest) { |
| 106 CheckAllSetToDefault(); | 81 CheckAllSetToDefault(); |
| 107 EXPECT_EQ(std::string(), settings().digest()); | 82 EXPECT_EQ(kDefaultSettingsDigest, settings().digest()); |
| 83 EXPECT_EQ(kDefaultSettingsDigest, |
| 84 GServicesSettings::CalculateDigest(settings().settings_map())); |
| 85 } |
| 86 |
| 87 // Verifies digest calculation for the sample provided by protocol owners. |
| 88 TEST_F(GServicesSettingsTest, CalculateDigest) { |
| 89 GServicesSettings::SettingsMap settings_map; |
| 90 settings_map["android_id"] = "55XXXXXXXXXXXXXXXX0"; |
| 91 settings_map["checkin_interval"] = "86400"; |
| 92 settings_map["checkin_url"] = |
| 93 "https://fake.address.google.com/canary/checkin"; |
| 94 settings_map["chrome_device"] = "1"; |
| 95 settings_map["device_country"] = "us"; |
| 96 settings_map["gcm_hostname"] = "fake.address.google.com"; |
| 97 settings_map["gcm_secure_port"] = "443"; |
| 98 |
| 99 EXPECT_EQ("1-33381ccd1cf5791dc0e6dfa234266fa9f1259197", |
| 100 GServicesSettings::CalculateDigest(settings_map)); |
| 108 } | 101 } |
| 109 | 102 |
| 110 // Verifies that settings are not updated when load result is empty. | 103 // Verifies that settings are not updated when load result is empty. |
| 111 TEST_F(GServicesSettingsTest, UpdateFromEmptyLoadResult) { | 104 TEST_F(GServicesSettingsTest, UpdateFromEmptyLoadResult) { |
| 112 GCMStore::LoadResult result; | 105 GCMStore::LoadResult result; |
| 106 result.gservices_digest = ""; |
| 107 settings().UpdateFromLoadResult(result); |
| 108 |
| 109 CheckAllSetToDefault(); |
| 110 EXPECT_EQ(kDefaultSettingsDigest, settings().digest()); |
| 111 } |
| 112 |
| 113 // Verifies that settings are not when digest value does not match. |
| 114 TEST_F(GServicesSettingsTest, UpdateFromLoadResultWithSettingMissing) { |
| 115 GCMStore::LoadResult result; |
| 116 result.gservices_settings["checkin_internval"] = "100000"; |
| 113 result.gservices_digest = "digest_value"; | 117 result.gservices_digest = "digest_value"; |
| 114 settings().UpdateFromLoadResult(result); | 118 settings().UpdateFromLoadResult(result); |
| 115 | 119 |
| 116 CheckAllSetToDefault(); | 120 CheckAllSetToDefault(); |
| 117 EXPECT_EQ(std::string(), settings().digest()); | 121 EXPECT_EQ(kDefaultSettingsDigest, settings().digest()); |
| 118 } | |
| 119 | |
| 120 // Verifies that settings are not updated when one of them is missing. | |
| 121 TEST_F(GServicesSettingsTest, UpdateFromLoadResultWithSettingMissing) { | |
| 122 GCMStore::LoadResult result; | |
| 123 result.gservices_settings = alternative_settings(); | |
| 124 result.gservices_digest = "digest_value"; | |
| 125 result.gservices_settings.erase("gcm_hostname"); | |
| 126 settings().UpdateFromLoadResult(result); | |
| 127 | |
| 128 CheckAllSetToDefault(); | |
| 129 EXPECT_EQ(std::string(), settings().digest()); | |
| 130 } | 122 } |
| 131 | 123 |
| 132 // Verifies that the settings are set correctly based on the load result. | 124 // Verifies that the settings are set correctly based on the load result. |
| 133 TEST_F(GServicesSettingsTest, UpdateFromLoadResult) { | 125 TEST_F(GServicesSettingsTest, UpdateFromLoadResult) { |
| 134 GCMStore::LoadResult result; | 126 GCMStore::LoadResult result; |
| 135 result.gservices_settings = alternative_settings(); | 127 result.gservices_settings["checkin_interval"] = |
| 136 result.gservices_digest = "digest_value"; | 128 base::Int64ToString(kAlternativeCheckinInterval); |
| 129 result.gservices_settings["checkin_url"] = kAlternativeCheckinURL; |
| 130 result.gservices_settings["gcm_hostname"] = kAlternativeMCSHostname; |
| 131 result.gservices_settings["gcm_secure_port"] = |
| 132 base::IntToString(kAlternativeMCSSecurePort); |
| 133 result.gservices_settings["gcm_registration_url"] = |
| 134 kAlternativeRegistrationURL; |
| 135 result.gservices_digest = kAlternativeSettingsDigest; |
| 137 settings().UpdateFromLoadResult(result); | 136 settings().UpdateFromLoadResult(result); |
| 138 | 137 |
| 139 CheckAllSetToAlternative(); | 138 EXPECT_EQ(base::TimeDelta::FromSeconds(kAlternativeCheckinInterval), |
| 140 EXPECT_EQ("digest_value", settings().digest()); | 139 settings().GetCheckinInterval()); |
| 141 } | 140 EXPECT_EQ(GURL(kAlternativeCheckinURL), settings().GetCheckinURL()); |
| 142 | 141 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), |
| 143 // Verifies that the settings are set correctly after parsing a checkin | 142 settings().GetMCSMainEndpoint()); |
| 144 // response. | 143 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), |
| 145 TEST_F(GServicesSettingsTest, UpdateFromCheckinResponse) { | 144 settings().GetMCSFallbackEndpoint()); |
| 146 checkin_proto::AndroidCheckinResponse checkin_response; | 145 EXPECT_EQ(GURL(kAlternativeRegistrationURL), settings().GetRegistrationURL()); |
| 147 | 146 EXPECT_EQ(GServicesSettings::CalculateDigest(result.gservices_settings), |
| 148 checkin_response.set_digest("digest_value"); | 147 settings().digest()); |
| 149 SetWithAlternativeSettings(checkin_response); | |
| 150 | |
| 151 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); | |
| 152 | |
| 153 CheckAllSetToAlternative(); | |
| 154 EXPECT_EQ(alternative_settings_, settings().GetSettingsMap()); | |
| 155 EXPECT_EQ("digest_value", settings().digest()); | |
| 156 } | 148 } |
| 157 | 149 |
| 158 // Verifies that the checkin interval is updated to minimum if the original | 150 // Verifies that the checkin interval is updated to minimum if the original |
| 159 // value is less than minimum. | 151 // value is less than minimum. |
| 160 TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseMinimumCheckinInterval) { | 152 TEST_F(GServicesSettingsTest, CheckinResponseMinimumCheckinInterval) { |
| 161 checkin_proto::AndroidCheckinResponse checkin_response; | |
| 162 | |
| 163 checkin_response.set_digest("digest_value"); | |
| 164 // Setting the checkin interval to less than minimum. | 153 // Setting the checkin interval to less than minimum. |
| 165 alternative_settings_["checkin_interval"] = base::IntToString(3600); | 154 checkin_proto::AndroidCheckinResponse checkin_response; |
| 166 SetWithAlternativeSettings(checkin_response); | 155 GServicesSettings::SettingsMap new_settings; |
| 156 new_settings["checkin_interval"] = "3600"; |
| 157 AddSettingsToResponse(checkin_response, new_settings, false); |
| 167 | 158 |
| 168 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); | 159 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); |
| 169 | 160 |
| 170 EXPECT_EQ(GServicesSettings::MinimumCheckinInterval(), | 161 EXPECT_EQ(GServicesSettings::MinimumCheckinInterval(), |
| 171 settings().checkin_interval()); | 162 settings().GetCheckinInterval()); |
| 172 EXPECT_EQ("digest_value", settings().digest()); | 163 EXPECT_EQ(GServicesSettings::CalculateDigest(new_settings), |
| 173 } | 164 settings().digest()); |
| 174 | 165 } |
| 175 // Verifies that settings are not updated when one of them is missing. | 166 |
| 176 TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseWithSettingMissing) { | 167 // Verifies that default checkin interval can be selectively overwritten. |
| 177 checkin_proto::AndroidCheckinResponse checkin_response; | 168 TEST_F(GServicesSettingsTest, CheckinResponseUpdateCheckinInterval) { |
| 178 | 169 checkin_proto::AndroidCheckinResponse checkin_response; |
| 179 checkin_response.set_digest("digest_value"); | 170 GServicesSettings::SettingsMap new_settings; |
| 180 alternative_settings_.erase("gcm_hostname"); | 171 new_settings["checkin_interval"] = "86400"; |
| 181 SetWithAlternativeSettings(checkin_response); | 172 AddSettingsToResponse(checkin_response, new_settings, false); |
| 182 | 173 |
| 183 EXPECT_FALSE(settings().UpdateFromCheckinResponse(checkin_response)); | 174 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); |
| 184 | 175 |
| 185 CheckAllSetToDefault(); | 176 // Only the checkin interval was updated: |
| 186 EXPECT_EQ(std::string(), settings().digest()); | 177 EXPECT_EQ(base::TimeDelta::FromSeconds(86400), |
| 187 } | 178 settings().GetCheckinInterval()); |
| 188 | 179 |
| 189 // Verifies that no update is done, when a checkin response misses digest. | 180 // Other settings still set to default. |
| 190 TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseNoDigest) { | 181 EXPECT_EQ(GURL("https://mtalk.google.com:5228"), |
| 191 checkin_proto::AndroidCheckinResponse checkin_response; | 182 settings().GetMCSMainEndpoint()); |
| 192 | 183 EXPECT_EQ(GURL("https://mtalk.google.com:443"), |
| 193 SetWithAlternativeSettings(checkin_response); | 184 settings().GetMCSFallbackEndpoint()); |
| 194 EXPECT_FALSE(settings().UpdateFromCheckinResponse(checkin_response)); | 185 EXPECT_EQ(GURL(kDefaultCheckinURL), settings().GetCheckinURL()); |
| 195 | 186 EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().GetRegistrationURL()); |
| 196 CheckAllSetToDefault(); | 187 |
| 197 EXPECT_EQ(std::string(), settings().digest()); | 188 EXPECT_EQ(GServicesSettings::CalculateDigest(new_settings), |
| 198 } | 189 settings().digest()); |
| 199 | 190 } |
| 200 // Verifies that no update is done, when a checkin response digest is the same. | 191 |
| 201 TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseSameDigest) { | 192 // Verifies that default registration URL can be selectively overwritten. |
| 202 GCMStore::LoadResult load_result; | 193 TEST_F(GServicesSettingsTest, CheckinResponseUpdateRegistrationURL) { |
| 203 load_result.gservices_digest = "old_digest"; | 194 checkin_proto::AndroidCheckinResponse checkin_response; |
| 204 load_result.gservices_settings = alternative_settings(); | 195 GServicesSettings::SettingsMap new_settings; |
| 205 settings().UpdateFromLoadResult(load_result); | 196 new_settings["gcm_registration_url"] = "https://new.registration.url"; |
| 206 | 197 AddSettingsToResponse(checkin_response, new_settings, false); |
| 207 checkin_proto::AndroidCheckinResponse checkin_response; | 198 |
| 208 checkin_response.set_digest("old_digest"); | 199 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); |
| 209 SetWithAlternativeSettings(checkin_response); | 200 |
| 210 EXPECT_FALSE(settings().UpdateFromCheckinResponse(checkin_response)); | 201 // Only the registration URL was updated: |
| 211 | 202 EXPECT_EQ(GURL("https://new.registration.url"), |
| 212 CheckAllSetToAlternative(); | 203 settings().GetRegistrationURL()); |
| 213 EXPECT_EQ("old_digest", settings().digest()); | 204 |
| 205 // Other settings still set to default. |
| 206 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), |
| 207 settings().GetCheckinInterval()); |
| 208 EXPECT_EQ(GURL("https://mtalk.google.com:5228"), |
| 209 settings().GetMCSMainEndpoint()); |
| 210 EXPECT_EQ(GURL("https://mtalk.google.com:443"), |
| 211 settings().GetMCSFallbackEndpoint()); |
| 212 EXPECT_EQ(GURL(kDefaultCheckinURL), settings().GetCheckinURL()); |
| 213 |
| 214 EXPECT_EQ(GServicesSettings::CalculateDigest(new_settings), |
| 215 settings().digest()); |
| 216 } |
| 217 |
| 218 // Verifies that default checkin URL can be selectively overwritten. |
| 219 TEST_F(GServicesSettingsTest, CheckinResponseUpdateCheckinURL) { |
| 220 checkin_proto::AndroidCheckinResponse checkin_response; |
| 221 GServicesSettings::SettingsMap new_settings; |
| 222 new_settings["checkin_url"] = "https://new.checkin.url"; |
| 223 AddSettingsToResponse(checkin_response, new_settings, false); |
| 224 |
| 225 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); |
| 226 |
| 227 // Only the checkin URL was updated: |
| 228 EXPECT_EQ(GURL("https://new.checkin.url"), settings().GetCheckinURL()); |
| 229 |
| 230 // Other settings still set to default. |
| 231 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), |
| 232 settings().GetCheckinInterval()); |
| 233 EXPECT_EQ(GURL("https://mtalk.google.com:5228"), |
| 234 settings().GetMCSMainEndpoint()); |
| 235 EXPECT_EQ(GURL("https://mtalk.google.com:443"), |
| 236 settings().GetMCSFallbackEndpoint()); |
| 237 EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().GetRegistrationURL()); |
| 238 |
| 239 EXPECT_EQ(GServicesSettings::CalculateDigest(new_settings), |
| 240 settings().digest()); |
| 241 } |
| 242 |
| 243 // Verifies that default MCS hostname can be selectively overwritten. |
| 244 TEST_F(GServicesSettingsTest, CheckinResponseUpdateMCSHostname) { |
| 245 checkin_proto::AndroidCheckinResponse checkin_response; |
| 246 GServicesSettings::SettingsMap new_settings; |
| 247 new_settings["gcm_hostname"] = "new.gcm.hostname"; |
| 248 AddSettingsToResponse(checkin_response, new_settings, false); |
| 249 |
| 250 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); |
| 251 |
| 252 // Only the MCS endpoints were updated: |
| 253 EXPECT_EQ(GURL("https://new.gcm.hostname:5228"), |
| 254 settings().GetMCSMainEndpoint()); |
| 255 EXPECT_EQ(GURL("https://new.gcm.hostname:443"), |
| 256 settings().GetMCSFallbackEndpoint()); |
| 257 |
| 258 // Other settings still set to default. |
| 259 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), |
| 260 settings().GetCheckinInterval()); |
| 261 EXPECT_EQ(GURL(kDefaultCheckinURL), settings().GetCheckinURL()); |
| 262 EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().GetRegistrationURL()); |
| 263 |
| 264 EXPECT_EQ(GServicesSettings::CalculateDigest(new_settings), |
| 265 settings().digest()); |
| 266 } |
| 267 |
| 268 // Verifies that default MCS secure port can be selectively overwritten. |
| 269 TEST_F(GServicesSettingsTest, CheckinResponseUpdateMCSSecurePort) { |
| 270 checkin_proto::AndroidCheckinResponse checkin_response; |
| 271 GServicesSettings::SettingsMap new_settings; |
| 272 new_settings["gcm_secure_port"] = "5229"; |
| 273 AddSettingsToResponse(checkin_response, new_settings, false); |
| 274 |
| 275 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); |
| 276 |
| 277 // Only the main MCS endpoint was updated: |
| 278 EXPECT_EQ(GURL("https://mtalk.google.com:5229"), |
| 279 settings().GetMCSMainEndpoint()); |
| 280 |
| 281 // Other settings still set to default. |
| 282 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), |
| 283 settings().GetCheckinInterval()); |
| 284 EXPECT_EQ(GURL(kDefaultCheckinURL), settings().GetCheckinURL()); |
| 285 EXPECT_EQ(GURL("https://mtalk.google.com:443"), |
| 286 settings().GetMCSFallbackEndpoint()); |
| 287 EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().GetRegistrationURL()); |
| 288 |
| 289 EXPECT_EQ(GServicesSettings::CalculateDigest(new_settings), |
| 290 settings().digest()); |
| 291 } |
| 292 |
| 293 // Update from checkin response should also do incremental update for both cases |
| 294 // where some settings are removed or added. |
| 295 TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseSettingsDiff) { |
| 296 checkin_proto::AndroidCheckinResponse checkin_response; |
| 297 |
| 298 // Only the new settings will be included in the response with settings diff. |
| 299 GServicesSettings::SettingsMap settings_diff; |
| 300 settings_diff["new_setting_1"] = "new_setting_1_value"; |
| 301 settings_diff["new_setting_2"] = "new_setting_2_value"; |
| 302 settings_diff["gcm_secure_port"] = "5229"; |
| 303 |
| 304 // Full settings are necessary to calculate digest. |
| 305 GServicesSettings::SettingsMap full_settings(settings_diff); |
| 306 std::string digest = GServicesSettings::CalculateDigest(full_settings); |
| 307 |
| 308 checkin_response.Clear(); |
| 309 AddSettingsToResponse(checkin_response, settings_diff, true); |
| 310 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); |
| 311 EXPECT_EQ(full_settings, settings().settings_map()); |
| 312 // Default setting overwritten by settings diff. |
| 313 EXPECT_EQ(GURL("https://mtalk.google.com:5229"), |
| 314 settings().GetMCSMainEndpoint()); |
| 315 |
| 316 // Setting up diff removing some of the values (including default setting). |
| 317 settings_diff.clear(); |
| 318 settings_diff["delete_new_setting_1"] = ""; |
| 319 settings_diff["delete_gcm_secure_port"] = ""; |
| 320 settings_diff["new_setting_3"] = "new_setting_3_value"; |
| 321 |
| 322 // Updating full settings to calculate digest. |
| 323 full_settings.erase(full_settings.find("new_setting_1")); |
| 324 full_settings.erase(full_settings.find("gcm_secure_port")); |
| 325 full_settings["new_setting_3"] = "new_setting_3_value"; |
| 326 digest = GServicesSettings::CalculateDigest(full_settings); |
| 327 |
| 328 checkin_response.Clear(); |
| 329 AddSettingsToResponse(checkin_response, settings_diff, true); |
| 330 EXPECT_TRUE(settings().UpdateFromCheckinResponse(checkin_response)); |
| 331 EXPECT_EQ(full_settings, settings().settings_map()); |
| 332 // Default setting back to norm. |
| 333 EXPECT_EQ(GURL("https://mtalk.google.com:5228"), |
| 334 settings().GetMCSMainEndpoint()); |
| 214 } | 335 } |
| 215 | 336 |
| 216 } // namespace gcm | 337 } // namespace gcm |
| OLD | NEW |