| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/http/http_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/ip_address.h" | 15 #include "net/base/ip_address.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class ListValue; | 20 class ListValue; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 class HttpServerPropertiesImplPeer { | 25 class HttpServerPropertiesImplPeer { |
| 25 public: | 26 public: |
| 26 static void AddBrokenAlternativeServiceWithExpirationTime( | 27 static void AddBrokenAlternativeServiceWithExpirationTime( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 EXPECT_EQ(kSpdySettingsFlags, flags_and_value_memory.first); | 96 EXPECT_EQ(kSpdySettingsFlags, flags_and_value_memory.first); |
| 96 EXPECT_EQ(data.value, flags_and_value_memory.second); | 97 EXPECT_EQ(data.value, flags_and_value_memory.second); |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 | 100 |
| 100 HttpServerPropertiesImpl impl_; | 101 HttpServerPropertiesImpl impl_; |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 104 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
| 104 | 105 |
| 106 TEST_F(SpdyServerPropertiesTest, InitializeWithSchemeHostPort) { |
| 107 // Check spdy servers are correctly set with SchemeHostPort key. |
| 108 url::SchemeHostPort https_www_server("https", "www.google.com", 443); |
| 109 url::SchemeHostPort http_photo_server("http", "photos.google.com", 80); |
| 110 // Servers with port equal to default port in scheme will drop port components |
| 111 // when calling Serialize(). |
| 112 std::string spdy_server_g = https_www_server.Serialize(); |
| 113 std::string spdy_server_p = http_photo_server.Serialize(); |
| 114 |
| 115 url::SchemeHostPort http_google_server("http", "www.google.com", 443); |
| 116 url::SchemeHostPort https_photos_server("https", "photos.google.com", 443); |
| 117 url::SchemeHostPort valid_google_server((GURL("https://www.google.com"))); |
| 118 |
| 119 // Initializing https://www.google.com:443 and https://photos.google.com:443 |
| 120 // as spdy servers. |
| 121 std::vector<std::string> spdy_servers1; |
| 122 spdy_servers1.push_back(spdy_server_g); // Will be 0th index. |
| 123 spdy_servers1.push_back(spdy_server_p); // Will be 1st index. |
| 124 impl_.InitializeSpdyServers(&spdy_servers1, true); |
| 125 EXPECT_TRUE(impl_.SupportsRequestPriority(http_photo_server)); |
| 126 EXPECT_TRUE(impl_.SupportsRequestPriority(https_www_server)); |
| 127 EXPECT_FALSE(impl_.SupportsRequestPriority(http_google_server)); |
| 128 EXPECT_FALSE(impl_.SupportsRequestPriority(https_photos_server)); |
| 129 EXPECT_TRUE(impl_.SupportsRequestPriority(valid_google_server)); |
| 130 } |
| 131 |
| 105 TEST_F(SpdyServerPropertiesTest, Initialize) { | 132 TEST_F(SpdyServerPropertiesTest, Initialize) { |
| 106 HostPortPair spdy_server_google("www.google.com", 443); | 133 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 107 std::string spdy_server_g = spdy_server_google.ToString(); | 134 std::string spdy_server_g = spdy_server_google.Serialize(); |
| 108 | 135 |
| 109 HostPortPair spdy_server_photos("photos.google.com", 443); | 136 url::SchemeHostPort spdy_server_photos("https", "photos.google.com", 443); |
| 110 std::string spdy_server_p = spdy_server_photos.ToString(); | 137 std::string spdy_server_p = spdy_server_photos.Serialize(); |
| 111 | 138 |
| 112 HostPortPair spdy_server_docs("docs.google.com", 443); | 139 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 113 std::string spdy_server_d = spdy_server_docs.ToString(); | 140 std::string spdy_server_d = spdy_server_docs.Serialize(); |
| 114 | 141 |
| 115 HostPortPair spdy_server_mail("mail.google.com", 443); | 142 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 116 std::string spdy_server_m = spdy_server_mail.ToString(); | 143 std::string spdy_server_m = spdy_server_mail.Serialize(); |
| 117 | 144 |
| 118 // Check by initializing NULL spdy servers. | 145 // Check by initializing NULL spdy servers. |
| 119 impl_.InitializeSpdyServers(NULL, true); | 146 impl_.InitializeSpdyServers(NULL, true); |
| 120 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | 147 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 121 | 148 |
| 122 // Check by initializing empty spdy servers. | 149 // Check by initializing empty spdy servers. |
| 123 std::vector<std::string> spdy_servers; | 150 std::vector<std::string> spdy_servers; |
| 124 impl_.InitializeSpdyServers(&spdy_servers, true); | 151 impl_.InitializeSpdyServers(&spdy_servers, true); |
| 125 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | 152 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 126 | 153 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 221 |
| 195 // Verify photos and mail servers don't support SPDY and other servers support | 222 // Verify photos and mail servers don't support SPDY and other servers support |
| 196 // SPDY. | 223 // SPDY. |
| 197 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 224 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 198 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 225 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 199 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos)); | 226 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos)); |
| 200 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 227 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 201 } | 228 } |
| 202 | 229 |
| 203 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { | 230 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { |
| 204 HostPortPair spdy_server_empty(std::string(), 443); | 231 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
| 205 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); | 232 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); |
| 206 | 233 |
| 207 // Add www.google.com:443 as supporting SPDY. | 234 // Add www.google.com:443 as supporting SPDY. |
| 208 HostPortPair spdy_server_google("www.google.com", 443); | 235 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 209 impl_.SetSupportsSpdy(spdy_server_google, true); | 236 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 210 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 237 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 211 | 238 |
| 212 // Add mail.google.com:443 as not supporting SPDY. | 239 // Add mail.google.com:443 as not supporting SPDY. |
| 213 HostPortPair spdy_server_mail("mail.google.com", 443); | 240 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 214 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 241 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 215 | 242 |
| 216 // Add docs.google.com:443 as supporting SPDY. | 243 // Add docs.google.com:443 as supporting SPDY. |
| 217 HostPortPair spdy_server_docs("docs.google.com", 443); | 244 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 218 impl_.SetSupportsSpdy(spdy_server_docs, true); | 245 impl_.SetSupportsSpdy(spdy_server_docs, true); |
| 219 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 246 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 220 | 247 |
| 221 // Add www.youtube.com:443 as supporting QUIC. | 248 // Add www.youtube.com:443 as supporting QUIC. |
| 222 HostPortPair quic_server_youtube("www.youtube.com", 443); | 249 HostPortPair quic_server_youtube("www.youtube.com", 443); |
| 250 url::SchemeHostPort youtube_server("https", "www.youtube.com", 443); |
| 223 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); | 251 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); |
| 224 SetAlternativeService(quic_server_youtube, alternative_service1); | 252 SetAlternativeService(quic_server_youtube, alternative_service1); |
| 225 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 253 EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); |
| 226 | 254 |
| 227 // Add www.example.com:443 with two alternative services, one supporting QUIC. | 255 // Add www.example.com:443 with two alternative services, one supporting QUIC. |
| 228 HostPortPair quic_server_example("www.example.com", 443); | 256 HostPortPair quic_server_example("www.example.com", 443); |
| 257 url::SchemeHostPort example_server("https", "www.example.com", 443); |
| 229 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); | 258 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); |
| 230 SetAlternativeService(quic_server_example, alternative_service2); | 259 SetAlternativeService(quic_server_example, alternative_service2); |
| 231 SetAlternativeService(quic_server_example, alternative_service1); | 260 SetAlternativeService(quic_server_example, alternative_service1); |
| 232 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); | 261 EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); |
| 233 | 262 |
| 234 // Verify all the entries are the same after additions. | 263 // Verify all the entries are the same after additions. |
| 235 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 264 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 236 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 265 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 237 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 266 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 238 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 267 EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); |
| 239 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); | 268 EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); |
| 240 } | 269 } |
| 241 | 270 |
| 242 TEST_F(SpdyServerPropertiesTest, Clear) { | 271 TEST_F(SpdyServerPropertiesTest, Clear) { |
| 243 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. | 272 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. |
| 244 HostPortPair spdy_server_google("www.google.com", 443); | 273 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 245 impl_.SetSupportsSpdy(spdy_server_google, true); | 274 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 246 HostPortPair spdy_server_mail("mail.google.com", 443); | 275 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 247 impl_.SetSupportsSpdy(spdy_server_mail, true); | 276 impl_.SetSupportsSpdy(spdy_server_mail, true); |
| 248 | 277 |
| 249 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 278 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 250 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); | 279 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 251 | 280 |
| 252 impl_.Clear(); | 281 impl_.Clear(); |
| 253 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | 282 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 254 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 283 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 255 } | 284 } |
| 256 | 285 |
| 257 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { | 286 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { |
| 258 base::ListValue spdy_server_list; | 287 base::ListValue spdy_server_list; |
| 259 | 288 |
| 260 // Check there are no spdy_servers. | 289 // Check there are no spdy_servers. |
| 261 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 290 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 262 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 291 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| 263 | 292 |
| 264 // Check empty server is not added. | 293 // Check empty server is not added. |
| 265 HostPortPair spdy_server_empty(std::string(), 443); | 294 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
| 266 impl_.SetSupportsSpdy(spdy_server_empty, true); | 295 impl_.SetSupportsSpdy(spdy_server_empty, true); |
| 267 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 296 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 268 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 297 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| 269 | 298 |
| 270 std::string string_value_g; | 299 std::string string_value_g; |
| 271 std::string string_value_m; | 300 std::string string_value_m; |
| 272 HostPortPair spdy_server_google("www.google.com", 443); | 301 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 273 std::string spdy_server_g = spdy_server_google.ToString(); | 302 std::string spdy_server_g = spdy_server_google.Serialize(); |
| 274 HostPortPair spdy_server_mail("mail.google.com", 443); | 303 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 275 std::string spdy_server_m = spdy_server_mail.ToString(); | 304 std::string spdy_server_m = spdy_server_mail.Serialize(); |
| 276 | 305 |
| 277 // Add www.google.com:443 as not supporting SPDY. | 306 // Add www.google.com:443 as not supporting SPDY. |
| 278 impl_.SetSupportsSpdy(spdy_server_google, false); | 307 impl_.SetSupportsSpdy(spdy_server_google, false); |
| 279 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 308 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 280 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 309 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| 281 | 310 |
| 282 // Add www.google.com:443 as supporting SPDY. | 311 // Add www.google.com:443 as supporting SPDY. |
| 283 impl_.SetSupportsSpdy(spdy_server_google, true); | 312 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 284 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 313 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 285 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 314 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 309 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 338 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
| 310 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); | 339 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); |
| 311 ASSERT_EQ(spdy_server_m, string_value_m); | 340 ASSERT_EQ(spdy_server_m, string_value_m); |
| 312 } | 341 } |
| 313 | 342 |
| 314 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { | 343 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { |
| 315 base::ListValue spdy_server_list; | 344 base::ListValue spdy_server_list; |
| 316 | 345 |
| 317 std::string string_value_g; | 346 std::string string_value_g; |
| 318 std::string string_value_m; | 347 std::string string_value_m; |
| 319 HostPortPair spdy_server_google("www.google.com", 443); | 348 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 320 std::string spdy_server_g = spdy_server_google.ToString(); | 349 std::string spdy_server_g = spdy_server_google.Serialize(); |
| 321 HostPortPair spdy_server_mail("mail.google.com", 443); | 350 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 322 std::string spdy_server_m = spdy_server_mail.ToString(); | 351 std::string spdy_server_m = spdy_server_mail.Serialize(); |
| 323 | 352 |
| 324 // Add www.google.com:443 as supporting SPDY. | 353 // Add www.google.com:443 as supporting SPDY. |
| 325 impl_.SetSupportsSpdy(spdy_server_google, true); | 354 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 326 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 355 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 327 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 356 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
| 328 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 357 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 329 ASSERT_EQ(spdy_server_g, string_value_g); | 358 ASSERT_EQ(spdy_server_g, string_value_g); |
| 330 | 359 |
| 331 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and | 360 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and |
| 332 // www.google.com:443 are in the list. | 361 // www.google.com:443 are in the list. |
| (...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1422 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
| 1394 | 1423 |
| 1395 impl_.Clear(); | 1424 impl_.Clear(); |
| 1396 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1425 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
| 1397 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1426 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
| 1398 } | 1427 } |
| 1399 | 1428 |
| 1400 } // namespace | 1429 } // namespace |
| 1401 | 1430 |
| 1402 } // namespace net | 1431 } // namespace net |
| OLD | NEW |