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/bind.h" | 10 #include "base/bind.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 HttpServerPropertiesManagerTest, | 253 HttpServerPropertiesManagerTest, |
254 ::testing::ValuesIn(kHttpServerPropertiesVersions)); | 254 ::testing::ValuesIn(kHttpServerPropertiesVersions)); |
255 | 255 |
256 TEST_P(HttpServerPropertiesManagerTest, | 256 TEST_P(HttpServerPropertiesManagerTest, |
257 SingleUpdateForTwoSpdyServerPrefChanges) { | 257 SingleUpdateForTwoSpdyServerPrefChanges) { |
258 ExpectCacheUpdate(); | 258 ExpectCacheUpdate(); |
259 | 259 |
260 // Set up the prefs for https://www.google.com and https://mail.google.com and | 260 // Set up the prefs for https://www.google.com and https://mail.google.com and |
261 // then set it twice. Only expect a single cache update. | 261 // then set it twice. Only expect a single cache update. |
262 | 262 |
263 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 263 auto server_pref_dict = base::MakeUnique<base::DictionaryValue>(); |
264 url::SchemeHostPort google_server("https", "www.google.com", 443); | 264 url::SchemeHostPort google_server("https", "www.google.com", 443); |
265 url::SchemeHostPort mail_server("https", "mail.google.com", 443); | 265 url::SchemeHostPort mail_server("https", "mail.google.com", 443); |
266 | 266 |
267 // Set supports_spdy for https://www.google.com:443. | 267 // Set supports_spdy for https://www.google.com:443. |
268 server_pref_dict->SetBoolean("supports_spdy", true); | 268 server_pref_dict->SetBoolean("supports_spdy", true); |
269 | 269 |
270 // Set up alternative_services for https://www.google.com. | 270 // Set up alternative_services for https://www.google.com. |
271 std::unique_ptr<base::DictionaryValue> alternative_service_dict0( | 271 auto alternative_service_dict0 = base::MakeUnique<base::DictionaryValue>(); |
272 new base::DictionaryValue); | |
273 alternative_service_dict0->SetInteger("port", 443); | 272 alternative_service_dict0->SetInteger("port", 443); |
274 alternative_service_dict0->SetString("protocol_str", "h2"); | 273 alternative_service_dict0->SetString("protocol_str", "h2"); |
275 std::unique_ptr<base::DictionaryValue> alternative_service_dict1( | 274 auto alternative_service_dict1 = base::MakeUnique<base::DictionaryValue>(); |
276 new base::DictionaryValue); | |
277 alternative_service_dict1->SetInteger("port", 1234); | 275 alternative_service_dict1->SetInteger("port", 1234); |
278 alternative_service_dict1->SetString("protocol_str", "quic"); | 276 alternative_service_dict1->SetString("protocol_str", "quic"); |
279 base::ListValue* alternative_service_list0 = new base::ListValue; | 277 auto alternative_service_list0 = base::MakeUnique<base::ListValue>(); |
280 alternative_service_list0->Append(std::move(alternative_service_dict0)); | 278 alternative_service_list0->Append(std::move(alternative_service_dict0)); |
281 alternative_service_list0->Append(std::move(alternative_service_dict1)); | 279 alternative_service_list0->Append(std::move(alternative_service_dict1)); |
282 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 280 server_pref_dict->SetWithoutPathExpansion( |
283 alternative_service_list0); | 281 "alternative_service", std::move(alternative_service_list0)); |
284 | 282 |
285 // Set up ServerNetworkStats for https://www.google.com. | 283 // Set up ServerNetworkStats for https://www.google.com. |
286 base::DictionaryValue* stats = new base::DictionaryValue; | 284 auto stats = base::MakeUnique<base::DictionaryValue>(); |
287 stats->SetInteger("srtt", 10); | 285 stats->SetInteger("srtt", 10); |
288 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 286 server_pref_dict->SetWithoutPathExpansion("network_stats", std::move(stats)); |
289 | 287 |
290 // Set the server preference for https://www.google.com. | 288 // Set the server preference for https://www.google.com. |
291 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); | 289 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); |
292 servers_dict->SetWithoutPathExpansion( | 290 servers_dict->SetWithoutPathExpansion( |
293 GetParam() >= 5 ? "https://www.google.com" : "www.google.com:443", | 291 GetParam() >= 5 ? "https://www.google.com" : "www.google.com:443", |
294 server_pref_dict); | 292 std::move(server_pref_dict)); |
295 base::ListValue* servers_list = nullptr; | 293 std::unique_ptr<base::ListValue> servers_list; |
296 if (GetParam() >= 4) { | 294 if (GetParam() >= 4) { |
297 servers_list = new base::ListValue; | 295 servers_list = base::MakeUnique<base::ListValue>(); |
298 servers_list->AppendIfNotPresent(std::move(servers_dict)); | 296 servers_list->Append(std::move(servers_dict)); |
299 servers_dict = base::MakeUnique<base::DictionaryValue>(); | 297 servers_dict = base::MakeUnique<base::DictionaryValue>(); |
300 } | 298 } |
301 | 299 |
302 // Set the preference for mail.google.com server. | 300 // Set the preference for mail.google.com server. |
303 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 301 auto server_pref_dict1 = base::MakeUnique<base::DictionaryValue>(); |
304 | 302 |
305 // Set supports_spdy for https://mail.google.com. | 303 // Set supports_spdy for https://mail.google.com. |
306 server_pref_dict1->SetBoolean("supports_spdy", true); | 304 server_pref_dict1->SetBoolean("supports_spdy", true); |
307 | 305 |
308 // Set up alternative_services for https://mail.google.com. | 306 // Set up alternative_services for https://mail.google.com. |
309 std::unique_ptr<base::DictionaryValue> alternative_service_dict2( | 307 auto alternative_service_dict2 = base::MakeUnique<base::DictionaryValue>(); |
310 new base::DictionaryValue); | |
311 alternative_service_dict2->SetString("protocol_str", "h2"); | 308 alternative_service_dict2->SetString("protocol_str", "h2"); |
312 alternative_service_dict2->SetInteger("port", 444); | 309 alternative_service_dict2->SetInteger("port", 444); |
313 base::ListValue* alternative_service_list1 = new base::ListValue; | 310 auto alternative_service_list1 = base::MakeUnique<base::ListValue>(); |
314 alternative_service_list1->Append(std::move(alternative_service_dict2)); | 311 alternative_service_list1->Append(std::move(alternative_service_dict2)); |
315 server_pref_dict1->SetWithoutPathExpansion("alternative_service", | 312 server_pref_dict1->SetWithoutPathExpansion( |
316 alternative_service_list1); | 313 "alternative_service", std::move(alternative_service_list1)); |
317 | 314 |
318 // Set up ServerNetworkStats for https://mail.google.com and it is the MRU | 315 // Set up ServerNetworkStats for https://mail.google.com and it is the MRU |
319 // server. | 316 // server. |
320 base::DictionaryValue* stats1 = new base::DictionaryValue; | 317 auto stats1 = base::MakeUnique<base::DictionaryValue>(); |
321 stats1->SetInteger("srtt", 20); | 318 stats1->SetInteger("srtt", 20); |
322 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); | 319 server_pref_dict1->SetWithoutPathExpansion("network_stats", |
| 320 std::move(stats1)); |
323 // Set the server preference for https://mail.google.com. | 321 // Set the server preference for https://mail.google.com. |
324 servers_dict->SetWithoutPathExpansion( | 322 servers_dict->SetWithoutPathExpansion( |
325 GetParam() >= 5 ? "https://mail.google.com" : "mail.google.com:443", | 323 GetParam() >= 5 ? "https://mail.google.com" : "mail.google.com:443", |
326 server_pref_dict1); | 324 std::move(server_pref_dict1)); |
327 base::DictionaryValue http_server_properties_dict; | 325 base::DictionaryValue http_server_properties_dict; |
328 if (GetParam() >= 4) { | 326 if (GetParam() >= 4) { |
329 servers_list->AppendIfNotPresent(std::move(servers_dict)); | 327 servers_list->AppendIfNotPresent(std::move(servers_dict)); |
330 if (GetParam() == 5) { | 328 if (GetParam() == 5) { |
331 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 329 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
332 } else { | 330 } else { |
333 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 331 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
334 GetParam()); | 332 GetParam()); |
335 } | 333 } |
336 http_server_properties_dict.SetWithoutPathExpansion("servers", | 334 http_server_properties_dict.SetWithoutPathExpansion( |
337 servers_list); | 335 "servers", std::move(servers_list)); |
338 } else { | 336 } else { |
339 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 337 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
340 GetParam()); | 338 GetParam()); |
341 http_server_properties_dict.SetWithoutPathExpansion( | 339 http_server_properties_dict.SetWithoutPathExpansion( |
342 "servers", std::move(servers_dict)); | 340 "servers", std::move(servers_dict)); |
343 } | 341 } |
344 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 342 auto supports_quic = base::MakeUnique<base::DictionaryValue>(); |
345 supports_quic->SetBoolean("used_quic", true); | 343 supports_quic->SetBoolean("used_quic", true); |
346 supports_quic->SetString("address", "127.0.0.1"); | 344 supports_quic->SetString("address", "127.0.0.1"); |
347 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", | 345 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", |
348 supports_quic); | 346 std::move(supports_quic)); |
349 | 347 |
350 // Set quic_server_info for https://www.google.com, https://mail.google.com | 348 // Set quic_server_info for https://www.google.com, https://mail.google.com |
351 // and https://play.google.com and verify the MRU. | 349 // and https://play.google.com and verify the MRU. |
352 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(3); | 350 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(3); |
353 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; | 351 auto quic_servers_dict = base::MakeUnique<base::DictionaryValue>(); |
354 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; | 352 auto quic_server_pref_dict1 = base::MakeUnique<base::DictionaryValue>(); |
355 std::string quic_server_info1("quic_server_info1"); | 353 std::string quic_server_info1("quic_server_info1"); |
356 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", | 354 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", |
357 quic_server_info1); | 355 quic_server_info1); |
358 base::DictionaryValue* quic_server_pref_dict2 = new base::DictionaryValue; | 356 auto quic_server_pref_dict2 = base::MakeUnique<base::DictionaryValue>(); |
359 std::string quic_server_info2("quic_server_info2"); | 357 std::string quic_server_info2("quic_server_info2"); |
360 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info", | 358 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info", |
361 quic_server_info2); | 359 quic_server_info2); |
362 base::DictionaryValue* quic_server_pref_dict3 = new base::DictionaryValue; | 360 auto quic_server_pref_dict3 = base::MakeUnique<base::DictionaryValue>(); |
363 std::string quic_server_info3("quic_server_info3"); | 361 std::string quic_server_info3("quic_server_info3"); |
364 quic_server_pref_dict3->SetStringWithoutPathExpansion("server_info", | 362 quic_server_pref_dict3->SetStringWithoutPathExpansion("server_info", |
365 quic_server_info3); | 363 quic_server_info3); |
366 // Set the quic_server_info1 for https://www.google.com. | 364 // Set the quic_server_info1 for https://www.google.com. |
367 QuicServerId google_quic_server_id("www.google.com", 443); | 365 QuicServerId google_quic_server_id("www.google.com", 443); |
368 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(), | 366 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(), |
369 quic_server_pref_dict1); | 367 std::move(quic_server_pref_dict1)); |
370 // Set the quic_server_info2 for https://mail.google.com. | 368 // Set the quic_server_info2 for https://mail.google.com. |
371 QuicServerId mail_quic_server_id("mail.google.com", 443); | 369 QuicServerId mail_quic_server_id("mail.google.com", 443); |
372 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(), | 370 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(), |
373 quic_server_pref_dict2); | 371 std::move(quic_server_pref_dict2)); |
374 // Set the quic_server_info3 for https://play.google.com. | 372 // Set the quic_server_info3 for https://play.google.com. |
375 QuicServerId play_quic_server_id("play.google.com", 443); | 373 QuicServerId play_quic_server_id("play.google.com", 443); |
376 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(), | 374 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(), |
377 quic_server_pref_dict3); | 375 std::move(quic_server_pref_dict3)); |
378 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", | 376 http_server_properties_dict.SetWithoutPathExpansion( |
379 quic_servers_dict); | 377 "quic_servers", std::move(quic_servers_dict)); |
380 | 378 |
381 // Set the same value for kHttpServerProperties multiple times. | 379 // Set the same value for kHttpServerProperties multiple times. |
382 pref_delegate_->SetPrefs(http_server_properties_dict); | 380 pref_delegate_->SetPrefs(http_server_properties_dict); |
383 pref_delegate_->SetPrefs(http_server_properties_dict); | 381 pref_delegate_->SetPrefs(http_server_properties_dict); |
384 | 382 |
385 EXPECT_TRUE(pref_test_task_runner_->HasPendingTask()); | 383 EXPECT_TRUE(pref_test_task_runner_->HasPendingTask()); |
386 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); | 384 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); |
387 pref_test_task_runner_->FastForwardUntilNoTasksRemain(); | 385 pref_test_task_runner_->FastForwardUntilNoTasksRemain(); |
388 EXPECT_TRUE(net_test_task_runner_->HasPendingTask()); | 386 EXPECT_TRUE(net_test_task_runner_->HasPendingTask()); |
389 net_test_task_runner_->FastForwardUntilNoTasksRemain(); | 387 net_test_task_runner_->FastForwardUntilNoTasksRemain(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( | 473 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( |
476 play_quic_server_id)); | 474 play_quic_server_id)); |
477 } | 475 } |
478 | 476 |
479 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 477 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
480 ExpectCacheUpdate(); | 478 ExpectCacheUpdate(); |
481 // The prefs are automatically updated in the case corruption is detected. | 479 // The prefs are automatically updated in the case corruption is detected. |
482 ExpectPrefsUpdate(1); | 480 ExpectPrefsUpdate(1); |
483 ExpectScheduleUpdatePrefsOnNetworkThread(); | 481 ExpectScheduleUpdatePrefsOnNetworkThread(); |
484 | 482 |
485 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 483 auto server_pref_dict = base::MakeUnique<base::DictionaryValue>(); |
486 | 484 |
487 // Set supports_spdy for www.google.com:65536. | 485 // Set supports_spdy for www.google.com:65536. |
488 server_pref_dict->SetBoolean("supports_spdy", true); | 486 server_pref_dict->SetBoolean("supports_spdy", true); |
489 | 487 |
490 // Set up alternative_service for www.google.com:65536. | 488 // Set up alternative_service for www.google.com:65536. |
491 std::unique_ptr<base::DictionaryValue> alternative_service_dict( | 489 auto alternative_service_dict = base::MakeUnique<base::DictionaryValue>(); |
492 new base::DictionaryValue); | |
493 alternative_service_dict->SetString("protocol_str", "h2"); | 490 alternative_service_dict->SetString("protocol_str", "h2"); |
494 alternative_service_dict->SetInteger("port", 80); | 491 alternative_service_dict->SetInteger("port", 80); |
495 base::ListValue* alternative_service_list = new base::ListValue; | 492 auto alternative_service_list = base::MakeUnique<base::ListValue>(); |
496 alternative_service_list->Append(std::move(alternative_service_dict)); | 493 alternative_service_list->Append(std::move(alternative_service_dict)); |
497 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 494 server_pref_dict->SetWithoutPathExpansion( |
498 alternative_service_list); | 495 "alternative_service", std::move(alternative_service_list)); |
499 | 496 |
500 // Set up ServerNetworkStats for www.google.com:65536. | 497 // Set up ServerNetworkStats for www.google.com:65536. |
501 base::DictionaryValue* stats = new base::DictionaryValue; | 498 auto stats = base::MakeUnique<base::DictionaryValue>(); |
502 stats->SetInteger("srtt", 10); | 499 stats->SetInteger("srtt", 10); |
503 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 500 server_pref_dict->SetWithoutPathExpansion("network_stats", std::move(stats)); |
504 | 501 |
505 // Set the server preference for www.google.com:65536. | 502 // Set the server preference for www.google.com:65536. |
506 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); | 503 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); |
507 servers_dict->SetWithoutPathExpansion("www.google.com:65536", | 504 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
508 server_pref_dict); | 505 std::move(server_pref_dict)); |
509 base::DictionaryValue http_server_properties_dict; | 506 base::DictionaryValue http_server_properties_dict; |
510 if (GetParam() >= 4) { | 507 if (GetParam() >= 4) { |
511 base::ListValue* servers_list = new base::ListValue; | 508 auto servers_list = base::MakeUnique<base::ListValue>(); |
512 servers_list->AppendIfNotPresent(std::move(servers_dict)); | 509 servers_list->Append(std::move(servers_dict)); |
513 if (GetParam() == 5) { | 510 if (GetParam() == 5) { |
514 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 511 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
515 } else { | 512 } else { |
516 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 513 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
517 GetParam()); | 514 GetParam()); |
518 } | 515 } |
519 http_server_properties_dict.SetWithoutPathExpansion("servers", | 516 http_server_properties_dict.SetWithoutPathExpansion( |
520 servers_list); | 517 "servers", std::move(servers_list)); |
521 } else { | 518 } else { |
522 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 519 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
523 GetParam()); | 520 GetParam()); |
524 http_server_properties_dict.SetWithoutPathExpansion( | 521 http_server_properties_dict.SetWithoutPathExpansion( |
525 "servers", std::move(servers_dict)); | 522 "servers", std::move(servers_dict)); |
526 } | 523 } |
527 | 524 |
528 // Set quic_server_info for www.google.com:65536. | 525 // Set quic_server_info for www.google.com:65536. |
529 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; | 526 auto quic_servers_dict = base::MakeUnique<base::DictionaryValue>(); |
530 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; | 527 auto quic_server_pref_dict1 = base::MakeUnique<base::DictionaryValue>(); |
531 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", | 528 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", |
532 "quic_server_info1"); | 529 "quic_server_info1"); |
533 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536", | 530 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536", |
534 quic_server_pref_dict1); | 531 std::move(quic_server_pref_dict1)); |
535 | 532 |
536 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", | 533 http_server_properties_dict.SetWithoutPathExpansion( |
537 quic_servers_dict); | 534 "quic_servers", std::move(quic_servers_dict)); |
538 | 535 |
539 // Set up the pref. | 536 // Set up the pref. |
540 pref_delegate_->SetPrefs(http_server_properties_dict); | 537 pref_delegate_->SetPrefs(http_server_properties_dict); |
541 | 538 |
542 EXPECT_TRUE(pref_test_task_runner_->HasPendingTask()); | 539 EXPECT_TRUE(pref_test_task_runner_->HasPendingTask()); |
543 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); | 540 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); |
544 pref_test_task_runner_->FastForwardUntilNoTasksRemain(); | 541 pref_test_task_runner_->FastForwardUntilNoTasksRemain(); |
545 EXPECT_FALSE(pref_test_task_runner_->HasPendingTask()); | 542 EXPECT_FALSE(pref_test_task_runner_->HasPendingTask()); |
546 EXPECT_TRUE(net_test_task_runner_->HasPendingTask()); | 543 EXPECT_TRUE(net_test_task_runner_->HasPendingTask()); |
547 net_test_task_runner_->FastForwardUntilNoTasksRemain(); | 544 net_test_task_runner_->FastForwardUntilNoTasksRemain(); |
(...skipping 17 matching lines...) Expand all Loading... |
565 EXPECT_EQ(nullptr, stats1); | 562 EXPECT_EQ(nullptr, stats1); |
566 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); | 563 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); |
567 } | 564 } |
568 | 565 |
569 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 566 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
570 ExpectCacheUpdate(); | 567 ExpectCacheUpdate(); |
571 // The prefs are automatically updated in the case corruption is detected. | 568 // The prefs are automatically updated in the case corruption is detected. |
572 ExpectPrefsUpdate(1); | 569 ExpectPrefsUpdate(1); |
573 ExpectScheduleUpdatePrefsOnNetworkThread(); | 570 ExpectScheduleUpdatePrefsOnNetworkThread(); |
574 | 571 |
575 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 572 auto server_pref_dict = base::MakeUnique<base::DictionaryValue>(); |
576 | 573 |
577 // Set supports_spdy for www.google.com:80. | 574 // Set supports_spdy for www.google.com:80. |
578 server_pref_dict->SetBoolean("supports_spdy", true); | 575 server_pref_dict->SetBoolean("supports_spdy", true); |
579 | 576 |
580 // Set up alternative_service for www.google.com:80. | 577 // Set up alternative_service for www.google.com:80. |
581 std::unique_ptr<base::DictionaryValue> alternative_service_dict( | 578 auto alternative_service_dict = base::MakeUnique<base::DictionaryValue>(); |
582 new base::DictionaryValue); | |
583 alternative_service_dict->SetString("protocol_str", "h2"); | 579 alternative_service_dict->SetString("protocol_str", "h2"); |
584 alternative_service_dict->SetInteger("port", 65536); | 580 alternative_service_dict->SetInteger("port", 65536); |
585 base::ListValue* alternative_service_list = new base::ListValue; | 581 auto alternative_service_list = base::MakeUnique<base::ListValue>(); |
586 alternative_service_list->Append(std::move(alternative_service_dict)); | 582 alternative_service_list->Append(std::move(alternative_service_dict)); |
587 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 583 server_pref_dict->SetWithoutPathExpansion( |
588 alternative_service_list); | 584 "alternative_service", std::move(alternative_service_list)); |
589 | 585 |
590 // Set the server preference for www.google.com:80. | 586 // Set the server preference for www.google.com:80. |
591 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); | 587 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); |
592 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 588 servers_dict->SetWithoutPathExpansion("www.google.com:80", |
| 589 std::move(server_pref_dict)); |
593 base::DictionaryValue http_server_properties_dict; | 590 base::DictionaryValue http_server_properties_dict; |
594 if (GetParam() >= 4) { | 591 if (GetParam() >= 4) { |
595 base::ListValue* servers_list = new base::ListValue; | 592 auto servers_list = base::MakeUnique<base::ListValue>(); |
596 servers_list->AppendIfNotPresent(std::move(servers_dict)); | 593 servers_list->Append(std::move(servers_dict)); |
597 if (GetParam() == 5) { | 594 if (GetParam() == 5) { |
598 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 595 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
599 } else { | 596 } else { |
600 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 597 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
601 GetParam()); | 598 GetParam()); |
602 } | 599 } |
603 http_server_properties_dict.SetWithoutPathExpansion("servers", | 600 http_server_properties_dict.SetWithoutPathExpansion( |
604 servers_list); | 601 "servers", std::move(servers_list)); |
605 } else { | 602 } else { |
606 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 603 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
607 GetParam()); | 604 GetParam()); |
608 http_server_properties_dict.SetWithoutPathExpansion( | 605 http_server_properties_dict.SetWithoutPathExpansion( |
609 "servers", std::move(servers_dict)); | 606 "servers", std::move(servers_dict)); |
610 } | 607 } |
611 | 608 |
612 // Set up the pref. | 609 // Set up the pref. |
613 pref_delegate_->SetPrefs(http_server_properties_dict); | 610 pref_delegate_->SetPrefs(http_server_properties_dict); |
614 | 611 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 | 1044 |
1048 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1045 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1049 } | 1046 } |
1050 | 1047 |
1051 // https://crbug.com/444956: Add 200 alternative_service servers followed by | 1048 // https://crbug.com/444956: Add 200 alternative_service servers followed by |
1052 // supports_quic and verify we have read supports_quic from prefs. | 1049 // supports_quic and verify we have read supports_quic from prefs. |
1053 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 1050 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
1054 ExpectCacheUpdate(); | 1051 ExpectCacheUpdate(); |
1055 | 1052 |
1056 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); | 1053 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); |
1057 base::ListValue* servers_list = nullptr; | 1054 std::unique_ptr<base::ListValue> servers_list; |
1058 if (GetParam() >= 4) | 1055 if (GetParam() >= 4) |
1059 servers_list = new base::ListValue; | 1056 servers_list = base::MakeUnique<base::ListValue>(); |
1060 | 1057 |
1061 for (int i = 1; i <= 200; ++i) { | 1058 for (int i = 1; i <= 200; ++i) { |
1062 // Set up alternative_service for www.google.com:i. | 1059 // Set up alternative_service for www.google.com:i. |
1063 std::unique_ptr<base::DictionaryValue> alternative_service_dict( | 1060 auto alternative_service_dict = base::MakeUnique<base::DictionaryValue>(); |
1064 new base::DictionaryValue); | |
1065 alternative_service_dict->SetString("protocol_str", "quic"); | 1061 alternative_service_dict->SetString("protocol_str", "quic"); |
1066 alternative_service_dict->SetInteger("port", i); | 1062 alternative_service_dict->SetInteger("port", i); |
1067 base::ListValue* alternative_service_list = new base::ListValue; | 1063 auto alternative_service_list = base::MakeUnique<base::ListValue>(); |
1068 alternative_service_list->Append(std::move(alternative_service_dict)); | 1064 alternative_service_list->Append(std::move(alternative_service_dict)); |
1069 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 1065 auto server_pref_dict = base::MakeUnique<base::DictionaryValue>(); |
1070 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 1066 server_pref_dict->SetWithoutPathExpansion( |
1071 alternative_service_list); | 1067 "alternative_service", std::move(alternative_service_list)); |
1072 if (GetParam() >= 5) { | 1068 if (GetParam() >= 5) { |
1073 servers_dict->SetWithoutPathExpansion( | 1069 servers_dict->SetWithoutPathExpansion( |
1074 StringPrintf("https://www.google.com:%d", i), server_pref_dict); | 1070 StringPrintf("https://www.google.com:%d", i), |
| 1071 std::move(server_pref_dict)); |
1075 } else { | 1072 } else { |
1076 servers_dict->SetWithoutPathExpansion( | 1073 servers_dict->SetWithoutPathExpansion( |
1077 StringPrintf("www.google.com:%d", i), server_pref_dict); | 1074 StringPrintf("www.google.com:%d", i), std::move(server_pref_dict)); |
1078 } | 1075 } |
1079 if (GetParam() >= 4) { | 1076 if (GetParam() >= 4) { |
1080 servers_list->AppendIfNotPresent(std::move(servers_dict)); | 1077 servers_list->AppendIfNotPresent(std::move(servers_dict)); |
1081 servers_dict = base::MakeUnique<base::DictionaryValue>(); | 1078 servers_dict = base::MakeUnique<base::DictionaryValue>(); |
1082 } | 1079 } |
1083 } | 1080 } |
1084 | 1081 |
1085 // Set the server preference for http://mail.google.com server. | 1082 // Set the server preference for http://mail.google.com server. |
1086 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 1083 auto server_pref_dict1 = base::MakeUnique<base::DictionaryValue>(); |
1087 if (GetParam() >= 5) { | 1084 if (GetParam() >= 5) { |
1088 servers_dict->SetWithoutPathExpansion("https://mail.google.com", | 1085 servers_dict->SetWithoutPathExpansion("https://mail.google.com", |
1089 server_pref_dict1); | 1086 std::move(server_pref_dict1)); |
1090 } else { | 1087 } else { |
1091 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 1088 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
1092 server_pref_dict1); | 1089 std::move(server_pref_dict1)); |
1093 } | 1090 } |
1094 base::DictionaryValue http_server_properties_dict; | 1091 base::DictionaryValue http_server_properties_dict; |
1095 if (GetParam() >= 4) { | 1092 if (GetParam() >= 4) { |
1096 servers_list->AppendIfNotPresent(std::move(servers_dict)); | 1093 servers_list->AppendIfNotPresent(std::move(servers_dict)); |
1097 if (GetParam() == 5) { | 1094 if (GetParam() == 5) { |
1098 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 1095 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
1099 } else { | 1096 } else { |
1100 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 1097 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
1101 GetParam()); | 1098 GetParam()); |
1102 } | 1099 } |
1103 http_server_properties_dict.SetWithoutPathExpansion("servers", | 1100 http_server_properties_dict.SetWithoutPathExpansion( |
1104 servers_list); | 1101 "servers", std::move(servers_list)); |
1105 } else { | 1102 } else { |
1106 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 1103 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
1107 GetParam()); | 1104 GetParam()); |
1108 http_server_properties_dict.SetWithoutPathExpansion( | 1105 http_server_properties_dict.SetWithoutPathExpansion( |
1109 "servers", std::move(servers_dict)); | 1106 "servers", std::move(servers_dict)); |
1110 } | 1107 } |
1111 | 1108 |
1112 // Set up SupportsQuic for 127.0.0.1 | 1109 // Set up SupportsQuic for 127.0.0.1 |
1113 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 1110 auto supports_quic = base::MakeUnique<base::DictionaryValue>(); |
1114 supports_quic->SetBoolean("used_quic", true); | 1111 supports_quic->SetBoolean("used_quic", true); |
1115 supports_quic->SetString("address", "127.0.0.1"); | 1112 supports_quic->SetString("address", "127.0.0.1"); |
1116 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", | 1113 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", |
1117 supports_quic); | 1114 std::move(supports_quic)); |
1118 | 1115 |
1119 // Set up the pref. | 1116 // Set up the pref. |
1120 pref_delegate_->SetPrefs(http_server_properties_dict); | 1117 pref_delegate_->SetPrefs(http_server_properties_dict); |
1121 | 1118 |
1122 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); | 1119 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); |
1123 EXPECT_TRUE(pref_test_task_runner_->HasPendingTask()); | 1120 EXPECT_TRUE(pref_test_task_runner_->HasPendingTask()); |
1124 pref_test_task_runner_->FastForwardUntilNoTasksRemain(); | 1121 pref_test_task_runner_->FastForwardUntilNoTasksRemain(); |
1125 EXPECT_TRUE(net_test_task_runner_->HasPendingTask()); | 1122 EXPECT_TRUE(net_test_task_runner_->HasPendingTask()); |
1126 net_test_task_runner_->FastForwardUntilNoTasksRemain(); | 1123 net_test_task_runner_->FastForwardUntilNoTasksRemain(); |
1127 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); | 1124 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 const base::DictionaryValue* altsvc_entry; | 1410 const base::DictionaryValue* altsvc_entry; |
1414 ASSERT_TRUE(altsvc_list->GetDictionary(0, &altsvc_entry)); | 1411 ASSERT_TRUE(altsvc_list->GetDictionary(0, &altsvc_entry)); |
1415 | 1412 |
1416 std::string hostname; | 1413 std::string hostname; |
1417 ASSERT_TRUE(altsvc_entry->GetString("host", &hostname)); | 1414 ASSERT_TRUE(altsvc_entry->GetString("host", &hostname)); |
1418 EXPECT_EQ("valid.example.com", hostname); | 1415 EXPECT_EQ("valid.example.com", hostname); |
1419 } | 1416 } |
1420 | 1417 |
1421 // Test that expired alternative service entries on disk are ignored. | 1418 // Test that expired alternative service entries on disk are ignored. |
1422 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) { | 1419 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) { |
1423 std::unique_ptr<base::ListValue> alternative_service_list( | 1420 auto alternative_service_list = base::MakeUnique<base::ListValue>(); |
1424 new base::ListValue); | 1421 auto expired_dict = base::MakeUnique<base::DictionaryValue>(); |
1425 std::unique_ptr<base::DictionaryValue> expired_dict( | |
1426 new base::DictionaryValue); | |
1427 expired_dict->SetString("protocol_str", "h2"); | 1422 expired_dict->SetString("protocol_str", "h2"); |
1428 expired_dict->SetString("host", "expired.example.com"); | 1423 expired_dict->SetString("host", "expired.example.com"); |
1429 expired_dict->SetInteger("port", 443); | 1424 expired_dict->SetInteger("port", 443); |
1430 base::Time time_one_day_ago = | 1425 base::Time time_one_day_ago = |
1431 base::Time::Now() - base::TimeDelta::FromDays(1); | 1426 base::Time::Now() - base::TimeDelta::FromDays(1); |
1432 expired_dict->SetString( | 1427 expired_dict->SetString( |
1433 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue())); | 1428 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue())); |
1434 alternative_service_list->Append(std::move(expired_dict)); | 1429 alternative_service_list->Append(std::move(expired_dict)); |
1435 | 1430 |
1436 std::unique_ptr<base::DictionaryValue> valid_dict(new base::DictionaryValue); | 1431 auto valid_dict = base::MakeUnique<base::DictionaryValue>(); |
1437 valid_dict->SetString("protocol_str", "h2"); | 1432 valid_dict->SetString("protocol_str", "h2"); |
1438 valid_dict->SetString("host", "valid.example.com"); | 1433 valid_dict->SetString("host", "valid.example.com"); |
1439 valid_dict->SetInteger("port", 443); | 1434 valid_dict->SetInteger("port", 443); |
1440 valid_dict->SetString( | 1435 valid_dict->SetString( |
1441 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); | 1436 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); |
1442 alternative_service_list->Append(std::move(valid_dict)); | 1437 alternative_service_list->Append(std::move(valid_dict)); |
1443 | 1438 |
1444 base::DictionaryValue server_pref_dict; | 1439 base::DictionaryValue server_pref_dict; |
1445 server_pref_dict.SetWithoutPathExpansion("alternative_service", | 1440 server_pref_dict.SetWithoutPathExpansion("alternative_service", |
1446 alternative_service_list.release()); | 1441 std::move(alternative_service_list)); |
1447 | 1442 |
1448 const url::SchemeHostPort server("https", "example.com", 443); | 1443 const url::SchemeHostPort server("https", "example.com", 443); |
1449 AlternativeServiceMap alternative_service_map(/*max_size=*/5); | 1444 AlternativeServiceMap alternative_service_map(/*max_size=*/5); |
1450 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( | 1445 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( |
1451 server, server_pref_dict, &alternative_service_map)); | 1446 server, server_pref_dict, &alternative_service_map)); |
1452 | 1447 |
1453 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); | 1448 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); |
1454 ASSERT_NE(alternative_service_map.end(), it); | 1449 ASSERT_NE(alternative_service_map.end(), it); |
1455 AlternativeServiceInfoVector alternative_service_info_vector = it->second; | 1450 AlternativeServiceInfoVector alternative_service_info_vector = it->second; |
1456 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 1451 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 pref_test_task_runner_->FastForwardUntilNoTasksRemain(); | 1553 pref_test_task_runner_->FastForwardUntilNoTasksRemain(); |
1559 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); | 1554 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); |
1560 EXPECT_FALSE(pref_test_task_runner_->HasPendingTask()); | 1555 EXPECT_FALSE(pref_test_task_runner_->HasPendingTask()); |
1561 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1556 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1562 http_server_props_manager_.reset(); | 1557 http_server_props_manager_.reset(); |
1563 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); | 1558 EXPECT_FALSE(net_test_task_runner_->HasPendingTask()); |
1564 EXPECT_FALSE(pref_test_task_runner_->HasPendingTask()); | 1559 EXPECT_FALSE(pref_test_task_runner_->HasPendingTask()); |
1565 } | 1560 } |
1566 | 1561 |
1567 } // namespace net | 1562 } // namespace net |
OLD | NEW |