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[] = "http://alternative.gcm.host"; | 17 const char kAlternativeMCSHostname[] = "alternative.gcm.host"; |
18 const int kAlternativeMCSSecurePort = 443; | 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 kDefaultMCSHostname[] = "https://mtalk.google.com"; | |
25 const int kDefaultMCSSecurePort = 5228; | |
26 const char kDefaultRegistrationURL[] = | 24 const char kDefaultRegistrationURL[] = |
27 "https://android.clients.google.com/c2dm/register3"; | 25 "https://android.clients.google.com/c2dm/register3"; |
28 | 26 |
29 } // namespace | 27 } // namespace |
30 | 28 |
31 class GServicesSettingsTest : public testing::Test { | 29 class GServicesSettingsTest : public testing::Test { |
32 public: | 30 public: |
33 GServicesSettingsTest(); | 31 GServicesSettingsTest(); |
34 virtual ~GServicesSettingsTest(); | 32 virtual ~GServicesSettingsTest(); |
35 | 33 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 alternative_settings_["gcm_hostname"] = kAlternativeMCSHostname; | 65 alternative_settings_["gcm_hostname"] = kAlternativeMCSHostname; |
68 alternative_settings_["gcm_secure_port"] = | 66 alternative_settings_["gcm_secure_port"] = |
69 base::IntToString(kAlternativeMCSSecurePort); | 67 base::IntToString(kAlternativeMCSSecurePort); |
70 alternative_settings_["gcm_registration_url"] = kAlternativeRegistrationURL; | 68 alternative_settings_["gcm_registration_url"] = kAlternativeRegistrationURL; |
71 } | 69 } |
72 | 70 |
73 void GServicesSettingsTest::CheckAllSetToDefault() { | 71 void GServicesSettingsTest::CheckAllSetToDefault() { |
74 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), | 72 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), |
75 settings().checkin_interval()); | 73 settings().checkin_interval()); |
76 EXPECT_EQ(GURL(kDefaultCheckinURL), settings().checkin_url()); | 74 EXPECT_EQ(GURL(kDefaultCheckinURL), settings().checkin_url()); |
77 EXPECT_EQ(kDefaultMCSHostname, settings().mcs_hostname()); | 75 EXPECT_EQ(GURL("https://mtalk.google.com:5228"), |
78 EXPECT_EQ(kDefaultMCSSecurePort, settings().mcs_secure_port()); | 76 settings().mcs_main_endpoint()); |
| 77 EXPECT_EQ(GURL("https://mtalk.google.com:443"), |
| 78 settings().mcs_fallback_endpoint()); |
79 EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().registration_url()); | 79 EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().registration_url()); |
80 } | 80 } |
81 | 81 |
82 void GServicesSettingsTest::CheckAllSetToAlternative() { | 82 void GServicesSettingsTest::CheckAllSetToAlternative() { |
83 EXPECT_EQ(base::TimeDelta::FromSeconds(kAlternativeCheckinInterval), | 83 EXPECT_EQ(base::TimeDelta::FromSeconds(kAlternativeCheckinInterval), |
84 settings().checkin_interval()); | 84 settings().checkin_interval()); |
85 EXPECT_EQ(GURL(kAlternativeCheckinURL), settings().checkin_url()); | 85 EXPECT_EQ(GURL(kAlternativeCheckinURL), settings().checkin_url()); |
86 EXPECT_EQ(kAlternativeMCSHostname, settings().mcs_hostname()); | 86 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), |
87 EXPECT_EQ(kAlternativeMCSSecurePort, settings().mcs_secure_port()); | 87 settings().mcs_main_endpoint()); |
| 88 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), |
| 89 settings().mcs_fallback_endpoint()); |
88 EXPECT_EQ(GURL(kAlternativeRegistrationURL), settings().registration_url()); | 90 EXPECT_EQ(GURL(kAlternativeRegistrationURL), settings().registration_url()); |
89 } | 91 } |
90 | 92 |
91 void GServicesSettingsTest::SetWithAlternativeSettings( | 93 void GServicesSettingsTest::SetWithAlternativeSettings( |
92 checkin_proto::AndroidCheckinResponse& checkin_response) { | 94 checkin_proto::AndroidCheckinResponse& checkin_response) { |
93 for (std::map<std::string, std::string>::const_iterator iter = | 95 for (std::map<std::string, std::string>::const_iterator iter = |
94 alternative_settings_.begin(); | 96 alternative_settings_.begin(); |
95 iter != alternative_settings_.end(); ++iter) { | 97 iter != alternative_settings_.end(); ++iter) { |
96 checkin_proto::GservicesSetting* setting = checkin_response.add_setting(); | 98 checkin_proto::GservicesSetting* setting = checkin_response.add_setting(); |
97 setting->set_name(iter->first); | 99 setting->set_name(iter->first); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 checkin_proto::AndroidCheckinResponse checkin_response; | 207 checkin_proto::AndroidCheckinResponse checkin_response; |
206 checkin_response.set_digest("old_digest"); | 208 checkin_response.set_digest("old_digest"); |
207 SetWithAlternativeSettings(checkin_response); | 209 SetWithAlternativeSettings(checkin_response); |
208 EXPECT_FALSE(settings().UpdateFromCheckinResponse(checkin_response)); | 210 EXPECT_FALSE(settings().UpdateFromCheckinResponse(checkin_response)); |
209 | 211 |
210 CheckAllSetToAlternative(); | 212 CheckAllSetToAlternative(); |
211 EXPECT_EQ("old_digest", settings().digest()); | 213 EXPECT_EQ("old_digest", settings().digest()); |
212 } | 214 } |
213 | 215 |
214 } // namespace gcm | 216 } // namespace gcm |
OLD | NEW |