| 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 "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 const base::Closure& completion)); | 136 const base::Closure& completion)); |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 139 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace | 142 } // namespace |
| 143 | 143 |
| 144 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated | 144 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated |
| 145 // to version 4, delete the following code. | 145 // to version 4, delete the following code. |
| 146 static const int kHttpServerPropertiesVersions[] = {3, 4}; | 146 static const int kHttpServerPropertiesVersions[] = {3, 4, 5}; |
| 147 | 147 |
| 148 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { | 148 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { |
| 149 protected: | 149 protected: |
| 150 HttpServerPropertiesManagerTest() {} | 150 HttpServerPropertiesManagerTest() {} |
| 151 | 151 |
| 152 void SetUp() override { | 152 void SetUp() override { |
| 153 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); | 153 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 154 pref_delegate_ = new MockPrefDelegate; | 154 pref_delegate_ = new MockPrefDelegate; |
| 155 http_server_props_manager_.reset( | 155 http_server_props_manager_.reset( |
| 156 new StrictMock<TestingHttpServerPropertiesManager>( | 156 new StrictMock<TestingHttpServerPropertiesManager>( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 ::testing::ValuesIn(kHttpServerPropertiesVersions)); | 226 ::testing::ValuesIn(kHttpServerPropertiesVersions)); |
| 227 | 227 |
| 228 TEST_P(HttpServerPropertiesManagerTest, | 228 TEST_P(HttpServerPropertiesManagerTest, |
| 229 SingleUpdateForTwoSpdyServerPrefChanges) { | 229 SingleUpdateForTwoSpdyServerPrefChanges) { |
| 230 ExpectCacheUpdate(); | 230 ExpectCacheUpdate(); |
| 231 | 231 |
| 232 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set | 232 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set |
| 233 // it twice. Only expect a single cache update. | 233 // it twice. Only expect a single cache update. |
| 234 | 234 |
| 235 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 235 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 236 // TODO(zhongyi): change scheme to http once Pref data is also migrated | 236 url::SchemeHostPort google_server(GetParam() >= 5 ? "http" : "https", |
| 237 // SchemeHostPort. | 237 "www.google.com", 80); |
| 238 url::SchemeHostPort google_server("https", "www.google.com", 80); | 238 url::SchemeHostPort mail_server(GetParam() >= 5 ? "http" : "https", |
| 239 url::SchemeHostPort mail_server("https", "mail.google.com", 80); | 239 "mail.google.com", 80); |
| 240 | 240 |
| 241 // Set supports_spdy for www.google.com:80. | 241 // Set supports_spdy for http://www.google.com:80. |
| 242 server_pref_dict->SetBoolean("supports_spdy", true); | 242 server_pref_dict->SetBoolean("supports_spdy", true); |
| 243 | 243 |
| 244 // Set up alternative_services for www.google.com:80. | 244 // Set up alternative_services for http://www.google.com:80. |
| 245 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue; | 245 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue; |
| 246 alternative_service_dict0->SetInteger("port", 443); | 246 alternative_service_dict0->SetInteger("port", 443); |
| 247 alternative_service_dict0->SetString("protocol_str", "npn-h2"); | 247 alternative_service_dict0->SetString("protocol_str", "npn-h2"); |
| 248 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue; | 248 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue; |
| 249 alternative_service_dict1->SetInteger("port", 1234); | 249 alternative_service_dict1->SetInteger("port", 1234); |
| 250 alternative_service_dict1->SetString("protocol_str", "quic"); | 250 alternative_service_dict1->SetString("protocol_str", "quic"); |
| 251 base::ListValue* alternative_service_list0 = new base::ListValue; | 251 base::ListValue* alternative_service_list0 = new base::ListValue; |
| 252 alternative_service_list0->Append(alternative_service_dict0); | 252 alternative_service_list0->Append(alternative_service_dict0); |
| 253 alternative_service_list0->Append(alternative_service_dict1); | 253 alternative_service_list0->Append(alternative_service_dict1); |
| 254 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 254 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 255 alternative_service_list0); | 255 alternative_service_list0); |
| 256 | 256 |
| 257 // Set up ServerNetworkStats for www.google.com:80. | 257 // Set up ServerNetworkStats for http://www.google.com:80. |
| 258 base::DictionaryValue* stats = new base::DictionaryValue; | 258 base::DictionaryValue* stats = new base::DictionaryValue; |
| 259 stats->SetInteger("srtt", 10); | 259 stats->SetInteger("srtt", 10); |
| 260 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 260 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 261 | 261 |
| 262 // Set the server preference for www.google.com:80. | 262 // Set the server preference for http://www.google.com:80. |
| 263 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 263 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 264 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 264 servers_dict->SetWithoutPathExpansion( |
| 265 GetParam() >= 5 ? "http://www.google.com" : "www.google.com:80", |
| 266 server_pref_dict); |
| 265 base::ListValue* servers_list = nullptr; | 267 base::ListValue* servers_list = nullptr; |
| 266 if (GetParam() == 4) { | 268 if (GetParam() >= 4) { |
| 267 servers_list = new base::ListValue; | 269 servers_list = new base::ListValue; |
| 268 // |servers_list| takes ownership of |servers_dict|. | 270 // |servers_list| takes ownership of |servers_dict|. |
| 269 servers_list->AppendIfNotPresent(servers_dict); | 271 servers_list->AppendIfNotPresent(servers_dict); |
| 270 servers_dict = new base::DictionaryValue; | 272 servers_dict = new base::DictionaryValue; |
| 271 } | 273 } |
| 272 | 274 |
| 273 // Set the preference for mail.google.com server. | 275 // Set the preference for mail.google.com server. |
| 274 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 276 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 275 | 277 |
| 276 // Set supports_spdy for mail.google.com:80 | 278 // Set supports_spdy for mail.google.com:80 |
| 277 server_pref_dict1->SetBoolean("supports_spdy", true); | 279 server_pref_dict1->SetBoolean("supports_spdy", true); |
| 278 | 280 |
| 279 // Set up alternative_services for mail.google.com:80. | 281 // Set up alternative_services for mail.google.com:80. |
| 280 base::DictionaryValue* alternative_service_dict2 = new base::DictionaryValue; | 282 base::DictionaryValue* alternative_service_dict2 = new base::DictionaryValue; |
| 281 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); | 283 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); |
| 282 alternative_service_dict2->SetInteger("port", 444); | 284 alternative_service_dict2->SetInteger("port", 444); |
| 283 base::ListValue* alternative_service_list1 = new base::ListValue; | 285 base::ListValue* alternative_service_list1 = new base::ListValue; |
| 284 alternative_service_list1->Append(alternative_service_dict2); | 286 alternative_service_list1->Append(alternative_service_dict2); |
| 285 server_pref_dict1->SetWithoutPathExpansion("alternative_service", | 287 server_pref_dict1->SetWithoutPathExpansion("alternative_service", |
| 286 alternative_service_list1); | 288 alternative_service_list1); |
| 287 | 289 |
| 288 // Set up ServerNetworkStats for mail.google.com:80 and it is the MRU server. | 290 // Set up ServerNetworkStats for http://mail.google.com:80 and it is the MRU |
| 291 // server. |
| 289 base::DictionaryValue* stats1 = new base::DictionaryValue; | 292 base::DictionaryValue* stats1 = new base::DictionaryValue; |
| 290 stats1->SetInteger("srtt", 20); | 293 stats1->SetInteger("srtt", 20); |
| 291 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); | 294 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); |
| 292 // Set the server preference for mail.google.com:80. | 295 // Set the server preference for http://mail.google.com:80. |
| 293 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 296 servers_dict->SetWithoutPathExpansion( |
| 294 server_pref_dict1); | 297 GetParam() >= 5 ? "http://mail.google.com" : "mail.google.com:80", |
| 298 server_pref_dict1); |
| 295 base::DictionaryValue http_server_properties_dict; | 299 base::DictionaryValue http_server_properties_dict; |
| 296 if (GetParam() == 4) { | 300 if (GetParam() >= 4) { |
| 297 // |servers_list| takes ownership of |servers_dict|. | 301 // |servers_list| takes ownership of |servers_dict|. |
| 298 servers_list->AppendIfNotPresent(servers_dict); | 302 servers_list->AppendIfNotPresent(servers_dict); |
| 299 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 303 if (GetParam() == 5) { |
| 304 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 305 } else { |
| 306 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 307 GetParam()); |
| 308 } |
| 300 http_server_properties_dict.SetWithoutPathExpansion("servers", | 309 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 301 servers_list); | 310 servers_list); |
| 302 } else { | 311 } else { |
| 303 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 312 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 304 GetParam()); | 313 GetParam()); |
| 305 http_server_properties_dict.SetWithoutPathExpansion("servers", | 314 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 306 servers_dict); | 315 servers_dict); |
| 307 } | 316 } |
| 308 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 317 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 309 supports_quic->SetBoolean("used_quic", true); | 318 supports_quic->SetBoolean("used_quic", true); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 http_server_props_manager_->SupportsRequestPriority(google_server)); | 363 http_server_props_manager_->SupportsRequestPriority(google_server)); |
| 355 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 364 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
| 356 HostPortPair foo_host_port_pair = | 365 HostPortPair foo_host_port_pair = |
| 357 HostPortPair::FromString("foo.google.com:1337"); | 366 HostPortPair::FromString("foo.google.com:1337"); |
| 358 url::SchemeHostPort foo_server("http", foo_host_port_pair.host(), | 367 url::SchemeHostPort foo_server("http", foo_host_port_pair.host(), |
| 359 foo_host_port_pair.port()); | 368 foo_host_port_pair.port()); |
| 360 | 369 |
| 361 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(foo_server)); | 370 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(foo_server)); |
| 362 | 371 |
| 363 // Verify alternative service. | 372 // Verify alternative service. |
| 364 if (GetParam() == 4) { | 373 if (GetParam() >= 4) { |
| 365 const AlternativeServiceMap& map = | 374 const AlternativeServiceMap& map = |
| 366 http_server_props_manager_->alternative_service_map(); | 375 http_server_props_manager_->alternative_service_map(); |
| 367 ASSERT_EQ(2u, map.size()); | 376 ASSERT_EQ(2u, map.size()); |
| 368 | 377 |
| 369 AlternativeServiceMap::const_iterator map_it = map.begin(); | 378 AlternativeServiceMap::const_iterator map_it = map.begin(); |
| 370 EXPECT_EQ("mail.google.com", map_it->first.host()); | 379 EXPECT_EQ("mail.google.com", map_it->first.host()); |
| 371 ASSERT_EQ(1u, map_it->second.size()); | 380 ASSERT_EQ(1u, map_it->second.size()); |
| 372 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); | 381 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); |
| 373 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 382 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
| 374 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 383 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 // Set up ServerNetworkStats for www.google.com:65536. | 465 // Set up ServerNetworkStats for www.google.com:65536. |
| 457 base::DictionaryValue* stats = new base::DictionaryValue; | 466 base::DictionaryValue* stats = new base::DictionaryValue; |
| 458 stats->SetInteger("srtt", 10); | 467 stats->SetInteger("srtt", 10); |
| 459 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 468 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 460 | 469 |
| 461 // Set the server preference for www.google.com:65536. | 470 // Set the server preference for www.google.com:65536. |
| 462 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 471 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 463 servers_dict->SetWithoutPathExpansion("www.google.com:65536", | 472 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
| 464 server_pref_dict); | 473 server_pref_dict); |
| 465 base::DictionaryValue http_server_properties_dict; | 474 base::DictionaryValue http_server_properties_dict; |
| 466 if (GetParam() == 4) { | 475 if (GetParam() >= 4) { |
| 467 base::ListValue* servers_list = new base::ListValue; | 476 base::ListValue* servers_list = new base::ListValue; |
| 468 // |servers_list| takes ownership of |servers_dict|. | 477 // |servers_list| takes ownership of |servers_dict|. |
| 469 servers_list->AppendIfNotPresent(servers_dict); | 478 servers_list->AppendIfNotPresent(servers_dict); |
| 470 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 479 if (GetParam() == 5) { |
| 480 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 481 } else { |
| 482 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 483 GetParam()); |
| 484 } |
| 471 http_server_properties_dict.SetWithoutPathExpansion("servers", | 485 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 472 servers_list); | 486 servers_list); |
| 473 } else { | 487 } else { |
| 474 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 488 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 475 GetParam()); | 489 GetParam()); |
| 476 http_server_properties_dict.SetWithoutPathExpansion("servers", | 490 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 477 servers_dict); | 491 servers_dict); |
| 478 } | 492 } |
| 479 | 493 |
| 480 // Set quic_server_info for www.google.com:65536. | 494 // Set quic_server_info for www.google.com:65536. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 alternative_service_dict->SetInteger("port", 65536); | 540 alternative_service_dict->SetInteger("port", 65536); |
| 527 base::ListValue* alternative_service_list = new base::ListValue; | 541 base::ListValue* alternative_service_list = new base::ListValue; |
| 528 alternative_service_list->Append(alternative_service_dict); | 542 alternative_service_list->Append(alternative_service_dict); |
| 529 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 543 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 530 alternative_service_list); | 544 alternative_service_list); |
| 531 | 545 |
| 532 // Set the server preference for www.google.com:80. | 546 // Set the server preference for www.google.com:80. |
| 533 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 547 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 534 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 548 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
| 535 base::DictionaryValue http_server_properties_dict; | 549 base::DictionaryValue http_server_properties_dict; |
| 536 if (GetParam() == 4) { | 550 if (GetParam() >= 4) { |
| 537 base::ListValue* servers_list = new base::ListValue; | 551 base::ListValue* servers_list = new base::ListValue; |
| 538 // |servers_list| takes ownership of |servers_dict|. | 552 // |servers_list| takes ownership of |servers_dict|. |
| 539 servers_list->AppendIfNotPresent(servers_dict); | 553 servers_list->AppendIfNotPresent(servers_dict); |
| 540 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 554 if (GetParam() == 5) { |
| 555 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 556 } else { |
| 557 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 558 GetParam()); |
| 559 } |
| 541 http_server_properties_dict.SetWithoutPathExpansion("servers", | 560 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 542 servers_list); | 561 servers_list); |
| 543 } else { | 562 } else { |
| 544 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 563 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 545 GetParam()); | 564 GetParam()); |
| 546 http_server_properties_dict.SetWithoutPathExpansion("servers", | 565 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 547 servers_dict); | 566 servers_dict); |
| 548 } | 567 } |
| 549 | 568 |
| 550 // Set up the pref. | 569 // Set up the pref. |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 980 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 962 } | 981 } |
| 963 | 982 |
| 964 // https://crbug.com/444956: Add 200 alternative_service servers followed by | 983 // https://crbug.com/444956: Add 200 alternative_service servers followed by |
| 965 // supports_quic and verify we have read supports_quic from prefs. | 984 // supports_quic and verify we have read supports_quic from prefs. |
| 966 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 985 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
| 967 ExpectCacheUpdate(); | 986 ExpectCacheUpdate(); |
| 968 | 987 |
| 969 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 988 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 970 base::ListValue* servers_list = nullptr; | 989 base::ListValue* servers_list = nullptr; |
| 971 if (GetParam() == 4) | 990 if (GetParam() >= 4) |
| 972 servers_list = new base::ListValue; | 991 servers_list = new base::ListValue; |
| 973 | 992 |
| 974 for (int i = 1; i <= 200; ++i) { | 993 for (int i = 1; i <= 200; ++i) { |
| 975 // Set up alternative_service for www.google.com:i. | 994 // Set up alternative_service for www.google.com:i. |
| 976 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; | 995 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
| 977 alternative_service_dict->SetString("protocol_str", "quic"); | 996 alternative_service_dict->SetString("protocol_str", "quic"); |
| 978 alternative_service_dict->SetInteger("port", i); | 997 alternative_service_dict->SetInteger("port", i); |
| 979 base::ListValue* alternative_service_list = new base::ListValue; | 998 base::ListValue* alternative_service_list = new base::ListValue; |
| 980 alternative_service_list->Append(alternative_service_dict); | 999 alternative_service_list->Append(alternative_service_dict); |
| 981 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 1000 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 982 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 1001 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 983 alternative_service_list); | 1002 alternative_service_list); |
| 984 if (GetParam() == 4) { | 1003 if (GetParam() >= 5) { |
| 985 // TODO(zhongyi): add scheme once disc data is migrated. | 1004 servers_dict->SetWithoutPathExpansion( |
| 1005 StringPrintf("http://www.google.com:%d", i), server_pref_dict); |
| 1006 } else { |
| 986 servers_dict->SetWithoutPathExpansion( | 1007 servers_dict->SetWithoutPathExpansion( |
| 987 StringPrintf("www.google.com:%d", i), server_pref_dict); | 1008 StringPrintf("www.google.com:%d", i), server_pref_dict); |
| 1009 } |
| 1010 if (GetParam() >= 4) { |
| 988 // |servers_list| takes ownership of |servers_dict|. | 1011 // |servers_list| takes ownership of |servers_dict|. |
| 989 servers_list->AppendIfNotPresent(servers_dict); | 1012 servers_list->AppendIfNotPresent(servers_dict); |
| 990 servers_dict = new base::DictionaryValue; | 1013 servers_dict = new base::DictionaryValue; |
| 991 } else { | |
| 992 // TODO(zhongyi): add scheme once disc data is migrated. | |
| 993 servers_dict->SetWithoutPathExpansion( | |
| 994 StringPrintf("www.google.com:%d", i), server_pref_dict); | |
| 995 } | 1014 } |
| 996 } | 1015 } |
| 997 | 1016 |
| 998 // Set the preference for mail.google.com server. | 1017 // Set the server preference for http://mail.google.com server. |
| 999 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 1018 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 1000 | 1019 if (GetParam() >= 5) { |
| 1001 // Set the server preference for mail.google.com:80. | 1020 servers_dict->SetWithoutPathExpansion("http://mail.google.com", |
| 1002 // TODO(zhongyi): add scheme once disc data is migrated. | 1021 server_pref_dict1); |
| 1003 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 1022 } else { |
| 1004 server_pref_dict1); | 1023 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
| 1024 server_pref_dict1); |
| 1025 } |
| 1005 base::DictionaryValue http_server_properties_dict; | 1026 base::DictionaryValue http_server_properties_dict; |
| 1006 if (GetParam() == 4) { | 1027 if (GetParam() >= 4) { |
| 1007 // |servers_list| takes ownership of |servers_dict|. | 1028 // |servers_list| takes ownership of |servers_dict|. |
| 1008 servers_list->AppendIfNotPresent(servers_dict); | 1029 servers_list->AppendIfNotPresent(servers_dict); |
| 1009 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 1030 if (GetParam() == 5) { |
| 1031 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 1032 } else { |
| 1033 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 1034 GetParam()); |
| 1035 } |
| 1010 http_server_properties_dict.SetWithoutPathExpansion("servers", | 1036 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 1011 servers_list); | 1037 servers_list); |
| 1012 } else { | 1038 } else { |
| 1013 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 1039 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 1014 GetParam()); | 1040 GetParam()); |
| 1015 http_server_properties_dict.SetWithoutPathExpansion("servers", | 1041 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 1016 servers_dict); | 1042 servers_dict); |
| 1017 } | 1043 } |
| 1018 | 1044 |
| 1019 // Set up SupportsQuic for 127.0.0.1 | 1045 // Set up SupportsQuic for 127.0.0.1 |
| 1020 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 1046 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 1021 supports_quic->SetBoolean("used_quic", true); | 1047 supports_quic->SetBoolean("used_quic", true); |
| 1022 supports_quic->SetString("address", "127.0.0.1"); | 1048 supports_quic->SetString("address", "127.0.0.1"); |
| 1023 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", | 1049 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", |
| 1024 supports_quic); | 1050 supports_quic); |
| 1025 | 1051 |
| 1026 // Set up the pref. | 1052 // Set up the pref. |
| 1027 pref_delegate_->SetPrefs(http_server_properties_dict); | 1053 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 1028 | 1054 |
| 1029 base::RunLoop().RunUntilIdle(); | 1055 base::RunLoop().RunUntilIdle(); |
| 1030 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1056 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1031 | 1057 |
| 1032 // Verify alternative service. | 1058 // Verify alternative service. |
| 1033 for (int i = 1; i <= 200; ++i) { | 1059 for (int i = 1; i <= 200; ++i) { |
| 1034 // TODO(zhongyi): remove hardcoded scheme once disc data is migrated. | 1060 GURL server_gurl; |
| 1035 GURL server_gurl(StringPrintf("https://www.google.com:%d", i)); | 1061 if (GetParam() >= 5) { |
| 1062 server_gurl = GURL(StringPrintf("http://www.google.com:%d", i)); |
| 1063 } else { |
| 1064 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); |
| 1065 } |
| 1036 url::SchemeHostPort server(server_gurl); | 1066 url::SchemeHostPort server(server_gurl); |
| 1037 AlternativeServiceVector alternative_service_vector = | 1067 AlternativeServiceVector alternative_service_vector = |
| 1038 http_server_props_manager_->GetAlternativeServices(server); | 1068 http_server_props_manager_->GetAlternativeServices(server); |
| 1039 ASSERT_EQ(1u, alternative_service_vector.size()); | 1069 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 1040 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); | 1070 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
| 1041 EXPECT_EQ(i, alternative_service_vector[0].port); | 1071 EXPECT_EQ(i, alternative_service_vector[0].port); |
| 1042 } | 1072 } |
| 1043 | 1073 |
| 1044 // Verify SupportsQuic. | 1074 // Verify SupportsQuic. |
| 1045 IPAddress address; | 1075 IPAddress address; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 ExpectPrefsUpdate(); | 1124 ExpectPrefsUpdate(); |
| 1095 ExpectCacheUpdate(); | 1125 ExpectCacheUpdate(); |
| 1096 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1126 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 1097 base::RunLoop().RunUntilIdle(); | 1127 base::RunLoop().RunUntilIdle(); |
| 1098 | 1128 |
| 1099 // Verify preferences. | 1129 // Verify preferences. |
| 1100 const char expected_json[] = | 1130 const char expected_json[] = |
| 1101 "{\"quic_servers\":{\"https://" | 1131 "{\"quic_servers\":{\"https://" |
| 1102 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," | 1132 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," |
| 1103 "\"servers\":[" | 1133 "\"servers\":[" |
| 1104 "{\"www.google.com:80\":{" | 1134 "{\"http://www.google.com\":{" |
| 1105 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," | 1135 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," |
| 1106 "\"port\":443,\"protocol_str\":\"npn-h2\"}," | 1136 "\"port\":443,\"protocol_str\":\"npn-h2\"}," |
| 1107 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," | 1137 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," |
| 1108 "\"port\":1234,\"protocol_str\":\"npn-h2\"}]}}," | 1138 "\"port\":1234,\"protocol_str\":\"npn-h2\"}]}}," |
| 1109 "{\"mail.google.com:80\":{\"alternative_service\":[{" | 1139 "{\"http://mail.google.com\":{\"alternative_service\":[{" |
| 1110 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," | 1140 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," |
| 1111 "\"port\":444,\"protocol_str\":\"npn-spdy/3.1\"}]," | 1141 "\"port\":444,\"protocol_str\":\"npn-spdy/3.1\"}]," |
| 1112 "\"network_stats\":{\"srtt\":42}}}" | 1142 "\"network_stats\":{\"srtt\":42}}}" |
| 1113 "]," | 1143 "]," |
| 1114 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," | 1144 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," |
| 1115 "\"version\":4}"; | 1145 "\"version\":5}"; |
| 1116 | 1146 |
| 1117 const base::Value* http_server_properties = | 1147 const base::Value* http_server_properties = |
| 1118 &pref_delegate_->GetServerProperties(); | 1148 &pref_delegate_->GetServerProperties(); |
| 1119 std::string preferences_json; | 1149 std::string preferences_json; |
| 1120 EXPECT_TRUE( | 1150 EXPECT_TRUE( |
| 1121 base::JSONWriter::Write(*http_server_properties, &preferences_json)); | 1151 base::JSONWriter::Write(*http_server_properties, &preferences_json)); |
| 1122 EXPECT_EQ(expected_json, preferences_json); | 1152 EXPECT_EQ(expected_json, preferences_json); |
| 1123 } | 1153 } |
| 1124 | 1154 |
| 1125 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { | 1155 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 const base::DictionaryValue& pref_dict = | 1242 const base::DictionaryValue& pref_dict = |
| 1213 pref_delegate_->GetServerProperties(); | 1243 pref_delegate_->GetServerProperties(); |
| 1214 | 1244 |
| 1215 const base::ListValue* servers_list = nullptr; | 1245 const base::ListValue* servers_list = nullptr; |
| 1216 ASSERT_TRUE(pref_dict.GetListWithoutPathExpansion("servers", &servers_list)); | 1246 ASSERT_TRUE(pref_dict.GetListWithoutPathExpansion("servers", &servers_list)); |
| 1217 base::ListValue::const_iterator it = servers_list->begin(); | 1247 base::ListValue::const_iterator it = servers_list->begin(); |
| 1218 const base::DictionaryValue* server_pref_dict; | 1248 const base::DictionaryValue* server_pref_dict; |
| 1219 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict)); | 1249 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict)); |
| 1220 | 1250 |
| 1221 const base::DictionaryValue* example_pref_dict; | 1251 const base::DictionaryValue* example_pref_dict; |
| 1252 |
| 1222 ASSERT_TRUE(server_pref_dict->GetDictionaryWithoutPathExpansion( | 1253 ASSERT_TRUE(server_pref_dict->GetDictionaryWithoutPathExpansion( |
| 1223 "www.example.com:443", &example_pref_dict)); | 1254 "https://www.example.com", &example_pref_dict)); |
| 1224 | 1255 |
| 1225 const base::ListValue* altsvc_list; | 1256 const base::ListValue* altsvc_list; |
| 1226 ASSERT_TRUE(example_pref_dict->GetList("alternative_service", &altsvc_list)); | 1257 ASSERT_TRUE(example_pref_dict->GetList("alternative_service", &altsvc_list)); |
| 1227 | 1258 |
| 1228 ASSERT_EQ(1u, altsvc_list->GetSize()); | 1259 ASSERT_EQ(1u, altsvc_list->GetSize()); |
| 1229 | 1260 |
| 1230 const base::DictionaryValue* altsvc_entry; | 1261 const base::DictionaryValue* altsvc_entry; |
| 1231 ASSERT_TRUE(altsvc_list->GetDictionary(0, &altsvc_entry)); | 1262 ASSERT_TRUE(altsvc_list->GetDictionary(0, &altsvc_entry)); |
| 1232 | 1263 |
| 1233 std::string hostname; | 1264 std::string hostname; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 // Shutdown comes before the task is executed. | 1376 // Shutdown comes before the task is executed. |
| 1346 http_server_props_manager_->ShutdownOnPrefThread(); | 1377 http_server_props_manager_->ShutdownOnPrefThread(); |
| 1347 // Run the task after shutdown, but before deletion. | 1378 // Run the task after shutdown, but before deletion. |
| 1348 base::RunLoop().RunUntilIdle(); | 1379 base::RunLoop().RunUntilIdle(); |
| 1349 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1380 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1350 http_server_props_manager_.reset(); | 1381 http_server_props_manager_.reset(); |
| 1351 base::RunLoop().RunUntilIdle(); | 1382 base::RunLoop().RunUntilIdle(); |
| 1352 } | 1383 } |
| 1353 | 1384 |
| 1354 } // namespace net | 1385 } // namespace net |
| OLD | NEW |