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 "net/http/http_server_properties_manager.h" | 5 #include "net/http/http_server_properties_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 277 |
278 // Set the preference for mail.google.com server. | 278 // Set the preference for mail.google.com server. |
279 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 279 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
280 | 280 |
281 // Set supports_spdy for https://mail.google.com. | 281 // Set supports_spdy for https://mail.google.com. |
282 server_pref_dict1->SetBoolean("supports_spdy", true); | 282 server_pref_dict1->SetBoolean("supports_spdy", true); |
283 | 283 |
284 // Set up alternative_services for https://mail.google.com. | 284 // Set up alternative_services for https://mail.google.com. |
285 std::unique_ptr<base::DictionaryValue> alternative_service_dict2( | 285 std::unique_ptr<base::DictionaryValue> alternative_service_dict2( |
286 new base::DictionaryValue); | 286 new base::DictionaryValue); |
287 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); | 287 alternative_service_dict2->SetString("protocol_str", "h2"); |
288 alternative_service_dict2->SetInteger("port", 444); | 288 alternative_service_dict2->SetInteger("port", 444); |
289 base::ListValue* alternative_service_list1 = new base::ListValue; | 289 base::ListValue* alternative_service_list1 = new base::ListValue; |
290 alternative_service_list1->Append(std::move(alternative_service_dict2)); | 290 alternative_service_list1->Append(std::move(alternative_service_dict2)); |
291 server_pref_dict1->SetWithoutPathExpansion("alternative_service", | 291 server_pref_dict1->SetWithoutPathExpansion("alternative_service", |
292 alternative_service_list1); | 292 alternative_service_list1); |
293 | 293 |
294 // Set up ServerNetworkStats for https://mail.google.com and it is the MRU | 294 // Set up ServerNetworkStats for https://mail.google.com and it is the MRU |
295 // server. | 295 // server. |
296 base::DictionaryValue* stats1 = new base::DictionaryValue; | 296 base::DictionaryValue* stats1 = new base::DictionaryValue; |
297 stats1->SetInteger("srtt", 20); | 297 stats1->SetInteger("srtt", 20); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 374 |
375 // Verify alternative service. | 375 // Verify alternative service. |
376 if (GetParam() >= 4) { | 376 if (GetParam() >= 4) { |
377 const AlternativeServiceMap& map = | 377 const AlternativeServiceMap& map = |
378 http_server_props_manager_->alternative_service_map(); | 378 http_server_props_manager_->alternative_service_map(); |
379 ASSERT_EQ(2u, map.size()); | 379 ASSERT_EQ(2u, map.size()); |
380 | 380 |
381 AlternativeServiceMap::const_iterator map_it = map.begin(); | 381 AlternativeServiceMap::const_iterator map_it = map.begin(); |
382 EXPECT_EQ("mail.google.com", map_it->first.host()); | 382 EXPECT_EQ("mail.google.com", map_it->first.host()); |
383 ASSERT_EQ(1u, map_it->second.size()); | 383 ASSERT_EQ(1u, map_it->second.size()); |
384 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); | 384 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); |
385 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 385 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
386 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 386 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
387 ++map_it; | 387 ++map_it; |
388 EXPECT_EQ("www.google.com", map_it->first.host()); | 388 EXPECT_EQ("www.google.com", map_it->first.host()); |
389 ASSERT_EQ(2u, map_it->second.size()); | 389 ASSERT_EQ(2u, map_it->second.size()); |
390 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); | 390 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); |
391 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 391 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
392 EXPECT_EQ(443, map_it->second[0].alternative_service.port); | 392 EXPECT_EQ(443, map_it->second[0].alternative_service.port); |
393 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); | 393 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); |
394 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); | 394 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); |
395 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); | 395 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); |
396 } else { | 396 } else { |
397 const AlternativeServiceMap& map = | 397 const AlternativeServiceMap& map = |
398 http_server_props_manager_->alternative_service_map(); | 398 http_server_props_manager_->alternative_service_map(); |
399 ASSERT_EQ(2u, map.size()); | 399 ASSERT_EQ(2u, map.size()); |
400 AlternativeServiceMap::const_iterator map_it = map.begin(); | 400 AlternativeServiceMap::const_iterator map_it = map.begin(); |
401 EXPECT_EQ("www.google.com", map_it->first.host()); | 401 EXPECT_EQ("www.google.com", map_it->first.host()); |
402 ASSERT_EQ(2u, map_it->second.size()); | 402 ASSERT_EQ(2u, map_it->second.size()); |
403 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); | 403 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); |
404 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 404 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
405 EXPECT_EQ(443, map_it->second[0].alternative_service.port); | 405 EXPECT_EQ(443, map_it->second[0].alternative_service.port); |
406 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); | 406 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); |
407 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); | 407 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); |
408 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); | 408 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); |
409 ++map_it; | 409 ++map_it; |
410 EXPECT_EQ("mail.google.com", map_it->first.host()); | 410 EXPECT_EQ("mail.google.com", map_it->first.host()); |
411 ASSERT_EQ(1u, map_it->second.size()); | 411 ASSERT_EQ(1u, map_it->second.size()); |
412 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); | 412 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); |
413 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 413 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
414 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 414 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
415 } | 415 } |
416 | 416 |
417 // Verify SupportsQuic. | 417 // Verify SupportsQuic. |
418 IPAddress last_address; | 418 IPAddress last_address; |
419 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); | 419 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
420 EXPECT_EQ("127.0.0.1", last_address.ToString()); | 420 EXPECT_EQ("127.0.0.1", last_address.ToString()); |
421 | 421 |
422 /* | 422 /* |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 AlternativeServiceInfo(www_alternative_service1, expiration1)); | 1075 AlternativeServiceInfo(www_alternative_service1, expiration1)); |
1076 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", | 1076 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", |
1077 1234); | 1077 1234); |
1078 base::Time expiration2; | 1078 base::Time expiration2; |
1079 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); | 1079 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); |
1080 alternative_service_info_vector.push_back( | 1080 alternative_service_info_vector.push_back( |
1081 AlternativeServiceInfo(www_alternative_service2, expiration2)); | 1081 AlternativeServiceInfo(www_alternative_service2, expiration2)); |
1082 http_server_props_manager_->SetAlternativeServices( | 1082 http_server_props_manager_->SetAlternativeServices( |
1083 server_www, alternative_service_info_vector); | 1083 server_www, alternative_service_info_vector); |
1084 | 1084 |
1085 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", | 1085 AlternativeService mail_alternative_service(NPN_HTTP_2, "foo.google.com", |
1086 444); | 1086 444); |
1087 base::Time expiration3 = base::Time::Max(); | 1087 base::Time expiration3 = base::Time::Max(); |
1088 http_server_props_manager_->SetAlternativeService( | 1088 http_server_props_manager_->SetAlternativeService( |
1089 server_mail, mail_alternative_service, expiration3); | 1089 server_mail, mail_alternative_service, expiration3); |
1090 | 1090 |
1091 // Set ServerNetworkStats. | 1091 // Set ServerNetworkStats. |
1092 ServerNetworkStats stats; | 1092 ServerNetworkStats stats; |
1093 stats.srtt = base::TimeDelta::FromInternalValue(42); | 1093 stats.srtt = base::TimeDelta::FromInternalValue(42); |
1094 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 1094 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); |
1095 | 1095 |
(...skipping 18 matching lines...) Expand all Loading... |
1114 "{\"quic_servers\":{\"https://" | 1114 "{\"quic_servers\":{\"https://" |
1115 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," | 1115 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," |
1116 "\"servers\":[" | 1116 "\"servers\":[" |
1117 "{\"http://www.google.com\":{" | 1117 "{\"http://www.google.com\":{" |
1118 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," | 1118 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," |
1119 "\"port\":443,\"protocol_str\":\"h2\"}," | 1119 "\"port\":443,\"protocol_str\":\"h2\"}," |
1120 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," | 1120 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," |
1121 "\"port\":1234,\"protocol_str\":\"h2\"}]}}," | 1121 "\"port\":1234,\"protocol_str\":\"h2\"}]}}," |
1122 "{\"http://mail.google.com\":{\"alternative_service\":[{" | 1122 "{\"http://mail.google.com\":{\"alternative_service\":[{" |
1123 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," | 1123 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," |
1124 "\"port\":444,\"protocol_str\":\"npn-spdy/3.1\"}]," | 1124 "\"port\":444,\"protocol_str\":\"h2\"}]," |
1125 "\"network_stats\":{\"srtt\":42}}}" | 1125 "\"network_stats\":{\"srtt\":42}}}" |
1126 "]," | 1126 "]," |
1127 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," | 1127 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," |
1128 "\"version\":5}"; | 1128 "\"version\":5}"; |
1129 | 1129 |
1130 const base::Value* http_server_properties = | 1130 const base::Value* http_server_properties = |
1131 &pref_delegate_->GetServerProperties(); | 1131 &pref_delegate_->GetServerProperties(); |
1132 std::string preferences_json; | 1132 std::string preferences_json; |
1133 EXPECT_TRUE( | 1133 EXPECT_TRUE( |
1134 base::JSONWriter::Write(*http_server_properties, &preferences_json)); | 1134 base::JSONWriter::Write(*http_server_properties, &preferences_json)); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 // Shutdown comes before the task is executed. | 1378 // Shutdown comes before the task is executed. |
1379 http_server_props_manager_->ShutdownOnPrefThread(); | 1379 http_server_props_manager_->ShutdownOnPrefThread(); |
1380 // Run the task after shutdown, but before deletion. | 1380 // Run the task after shutdown, but before deletion. |
1381 base::RunLoop().RunUntilIdle(); | 1381 base::RunLoop().RunUntilIdle(); |
1382 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1382 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1383 http_server_props_manager_.reset(); | 1383 http_server_props_manager_.reset(); |
1384 base::RunLoop().RunUntilIdle(); | 1384 base::RunLoop().RunUntilIdle(); |
1385 } | 1385 } |
1386 | 1386 |
1387 } // namespace net | 1387 } // namespace net |
OLD | NEW |