Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: net/http/http_server_properties_manager_unittest.cc

Issue 1858093002: Alt-Svc 8: Change Supports SPDY list using SHP as the key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@alt_svc_7
Patch Set: server pref changes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 base::Time one_day_from_now_; 217 base::Time one_day_from_now_;
218 218
219 private: 219 private:
220 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 220 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
221 }; 221 };
222 222
223 INSTANTIATE_TEST_CASE_P(Tests, 223 INSTANTIATE_TEST_CASE_P(Tests,
224 HttpServerPropertiesManagerTest, 224 HttpServerPropertiesManagerTest,
225 ::testing::ValuesIn(kHttpServerPropertiesVersions)); 225 ::testing::ValuesIn(kHttpServerPropertiesVersions));
226 226
227 TEST_P(HttpServerPropertiesManagerTest,
228 SingleUpdateForTwoSpdyServerPrefChanges) {
229 ExpectCacheUpdate();
230
231 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set
232 // it twice. Only expect a single cache update.
233
234 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
235 HostPortPair google_server("www.google.com", 80);
236 url::SchemeHostPort google_scheme_origin_pair("https", "www.google.com", 80);
237 HostPortPair mail_server("mail.google.com", 80);
238 url::SchemeHostPort mail_scheme_origin_pair("https", "mail.google.com", 80);
239
240 // Set supports_spdy for www.google.com:80.
241 server_pref_dict->SetBoolean("supports_spdy", true);
242
243 // Set up alternative_services for www.google.com:80.
244 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue;
245 alternative_service_dict0->SetInteger("port", 443);
246 alternative_service_dict0->SetString("protocol_str", "npn-h2");
247 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue;
248 alternative_service_dict1->SetInteger("port", 1234);
249 alternative_service_dict1->SetString("protocol_str", "quic");
250 base::ListValue* alternative_service_list0 = new base::ListValue;
251 alternative_service_list0->Append(alternative_service_dict0);
252 alternative_service_list0->Append(alternative_service_dict1);
253 server_pref_dict->SetWithoutPathExpansion("alternative_service",
254 alternative_service_list0);
255
256 // Set up ServerNetworkStats for www.google.com:80.
257 base::DictionaryValue* stats = new base::DictionaryValue;
258 stats->SetInteger("srtt", 10);
259 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
260
261 // Set the server preference for www.google.com:80.
262 base::DictionaryValue* servers_dict = new base::DictionaryValue;
263 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
264 base::ListValue* servers_list = nullptr;
265 if (GetParam() == 4) {
266 servers_list = new base::ListValue;
267 // |servers_list| takes ownership of |servers_dict|.
268 servers_list->AppendIfNotPresent(servers_dict);
269 servers_dict = new base::DictionaryValue;
270 }
271
272 // Set the preference for mail.google.com server.
273 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
274
275 // Set supports_spdy for mail.google.com:80
276 server_pref_dict1->SetBoolean("supports_spdy", true);
277
278 // Set up alternative_services for mail.google.com:80.
279 base::DictionaryValue* alternative_service_dict2 = new base::DictionaryValue;
280 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1");
281 alternative_service_dict2->SetInteger("port", 444);
282 base::ListValue* alternative_service_list1 = new base::ListValue;
283 alternative_service_list1->Append(alternative_service_dict2);
284 server_pref_dict1->SetWithoutPathExpansion("alternative_service",
285 alternative_service_list1);
286
287 // Set up ServerNetworkStats for mail.google.com:80 and it is the MRU server.
288 base::DictionaryValue* stats1 = new base::DictionaryValue;
289 stats1->SetInteger("srtt", 20);
290 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1);
291 // Set the server preference for mail.google.com:80.
292 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
293 server_pref_dict1);
294 base::DictionaryValue http_server_properties_dict;
295 if (GetParam() == 4) {
296 // |servers_list| takes ownership of |servers_dict|.
297 servers_list->AppendIfNotPresent(servers_dict);
298 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
299 http_server_properties_dict.SetWithoutPathExpansion("servers",
300 servers_list);
301 } else {
302 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
303 GetParam());
304 http_server_properties_dict.SetWithoutPathExpansion("servers",
305 servers_dict);
306 }
307 base::DictionaryValue* supports_quic = new base::DictionaryValue;
308 supports_quic->SetBoolean("used_quic", true);
309 supports_quic->SetString("address", "127.0.0.1");
310 http_server_properties_dict.SetWithoutPathExpansion("supports_quic",
311 supports_quic);
312
313 // Set quic_server_info for www.google.com:80, mail.google.com:80 and
314 // play.google.com:80 and verify the MRU.
315 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(3);
316 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue;
317 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue;
318 std::string quic_server_info1("quic_server_info1");
319 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info",
320 quic_server_info1);
321 base::DictionaryValue* quic_server_pref_dict2 = new base::DictionaryValue;
322 std::string quic_server_info2("quic_server_info2");
323 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info",
324 quic_server_info2);
325 base::DictionaryValue* quic_server_pref_dict3 = new base::DictionaryValue;
326 std::string quic_server_info3("quic_server_info3");
327 quic_server_pref_dict3->SetStringWithoutPathExpansion("server_info",
328 quic_server_info3);
329 // Set the quic_server_info1 for www.google.com server.
330 QuicServerId google_quic_server_id("www.google.com", 80);
331 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(),
332 quic_server_pref_dict1);
333 // Set the quic_server_info2 for mail.google.com server.
334 QuicServerId mail_quic_server_id("mail.google.com", 80);
335 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(),
336 quic_server_pref_dict2);
337 // Set the quic_server_info3 for play.google.com server.
338 QuicServerId play_quic_server_id("play.google.com", 80);
339 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(),
340 quic_server_pref_dict3);
341 http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
342 quic_servers_dict);
343
344 // Set the same value for kHttpServerProperties multiple times.
345 pref_delegate_->SetPrefs(http_server_properties_dict);
346 pref_delegate_->SetPrefs(http_server_properties_dict);
347
348 base::RunLoop().RunUntilIdle();
349 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
350
351 // Verify SupportsSpdy.
352 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(
353 google_scheme_origin_pair));
354 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(
355 mail_scheme_origin_pair));
356 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
357 url::SchemeHostPort("http", "foo.google.com", 1337)));
358
359 // Verify alternative service.
360 if (GetParam() == 4) {
361 const AlternativeServiceMap& map =
362 http_server_props_manager_->alternative_service_map();
363 ASSERT_EQ(2u, map.size());
364
365 AlternativeServiceMap::const_iterator map_it = map.begin();
366 EXPECT_EQ("mail.google.com", map_it->first.host());
367 ASSERT_EQ(1u, map_it->second.size());
368 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol);
369 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty());
370 EXPECT_EQ(444, map_it->second[0].alternative_service.port);
371 ++map_it;
372 EXPECT_EQ("www.google.com", map_it->first.host());
373 ASSERT_EQ(2u, map_it->second.size());
374 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol);
375 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty());
376 EXPECT_EQ(443, map_it->second[0].alternative_service.port);
377 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol);
378 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty());
379 EXPECT_EQ(1234, map_it->second[1].alternative_service.port);
380 } else {
381 const AlternativeServiceMap& map =
382 http_server_props_manager_->alternative_service_map();
383 ASSERT_EQ(2u, map.size());
384 AlternativeServiceMap::const_iterator map_it = map.begin();
385 EXPECT_EQ("www.google.com", map_it->first.host());
386 ASSERT_EQ(2u, map_it->second.size());
387 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol);
388 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty());
389 EXPECT_EQ(443, map_it->second[0].alternative_service.port);
390 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol);
391 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty());
392 EXPECT_EQ(1234, map_it->second[1].alternative_service.port);
393 ++map_it;
394 EXPECT_EQ("mail.google.com", map_it->first.host());
395 ASSERT_EQ(1u, map_it->second.size());
396 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol);
397 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty());
398 EXPECT_EQ(444, map_it->second[0].alternative_service.port);
399 }
400
401 // Verify SupportsQuic.
402 IPAddress last_address;
403 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address));
404 EXPECT_EQ("127.0.0.1", last_address.ToString());
405
406 // Verify ServerNetworkStats.
407 const ServerNetworkStats* stats2 =
408 http_server_props_manager_->GetServerNetworkStats(google_server);
409 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
410 const ServerNetworkStats* stats3 =
411 http_server_props_manager_->GetServerNetworkStats(mail_server);
412 EXPECT_EQ(20, stats3->srtt.ToInternalValue());
413
414 // Verify QuicServerInfo.
415 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
416 google_quic_server_id));
417 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo(
418 mail_quic_server_id));
419 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo(
420 play_quic_server_id));
421
422 // Verify the MRU order.
423 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(2);
424 EXPECT_EQ(nullptr, http_server_props_manager_->GetQuicServerInfo(
425 google_quic_server_id));
426 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo(
427 mail_quic_server_id));
428 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo(
429 play_quic_server_id));
430 }
431
432 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { 227 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
433 ExpectCacheUpdate(); 228 ExpectCacheUpdate();
434 // The prefs are automaticalls updated in the case corruption is detected. 229 // The prefs are automaticalls updated in the case corruption is detected.
435 ExpectPrefsUpdate(); 230 ExpectPrefsUpdate();
436 ExpectScheduleUpdatePrefsOnNetworkThread(); 231 ExpectScheduleUpdatePrefsOnNetworkThread();
437 232
438 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 233 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
439 234
440 // Set supports_spdy for www.google.com:65536. 235 // Set supports_spdy for www.google.com:65536.
441 server_pref_dict->SetBoolean("supports_spdy", true); 236 server_pref_dict->SetBoolean("supports_spdy", true);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // Verify that nothing is set. 288 // Verify that nothing is set.
494 HostPortPair host_port_pair = 289 HostPortPair host_port_pair =
495 HostPortPair::FromString("www.google.com:65536"); 290 HostPortPair::FromString("www.google.com:65536");
496 url::SchemeHostPort scheme_origin("https", host_port_pair.host(), 291 url::SchemeHostPort scheme_origin("https", host_port_pair.host(),
497 host_port_pair.port()); 292 host_port_pair.port());
498 EXPECT_FALSE( 293 EXPECT_FALSE(
499 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); 294 http_server_props_manager_->SupportsRequestPriority(scheme_origin));
500 295
501 EXPECT_FALSE(HasAlternativeService(scheme_origin)); 296 EXPECT_FALSE(HasAlternativeService(scheme_origin));
502 const ServerNetworkStats* stats1 = 297 const ServerNetworkStats* stats1 =
503 http_server_props_manager_->GetServerNetworkStats(host_port_pair); 298 http_server_props_manager_->GetServerNetworkStats(scheme_origin);
504 EXPECT_EQ(nullptr, stats1); 299 EXPECT_EQ(nullptr, stats1);
505 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); 300 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size());
506 } 301 }
507 302
508 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { 303 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
509 ExpectCacheUpdate(); 304 ExpectCacheUpdate();
510 // The prefs are automaticalls updated in the case corruption is detected. 305 // The prefs are automaticalls updated in the case corruption is detected.
511 ExpectPrefsUpdate(); 306 ExpectPrefsUpdate();
512 ExpectScheduleUpdatePrefsOnNetworkThread(); 307 ExpectScheduleUpdatePrefsOnNetworkThread();
513 308
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 350 }
556 351
557 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { 352 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
558 ExpectPrefsUpdate(); 353 ExpectPrefsUpdate();
559 ExpectScheduleUpdatePrefsOnNetworkThread(); 354 ExpectScheduleUpdatePrefsOnNetworkThread();
560 355
561 // Post an update task to the network thread. SetSupportsSpdy calls 356 // Post an update task to the network thread. SetSupportsSpdy calls
562 // ScheduleUpdatePrefsOnNetworkThread. 357 // ScheduleUpdatePrefsOnNetworkThread.
563 358
564 // Add mail.google.com:443 as a supporting spdy server. 359 // Add mail.google.com:443 as a supporting spdy server.
565 HostPortPair spdy_server_mail("mail.google.com", 443); 360 // HostPortPair spdy_server_mail("mail.google.com", 443);
566 url::SchemeHostPort scheme_origin("https", "mail.google.com", 443); 361 url::SchemeHostPort scheme_origin("https", "mail.google.com", 443);
567 EXPECT_FALSE( 362 EXPECT_FALSE(
568 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); 363 http_server_props_manager_->SupportsRequestPriority(scheme_origin));
569 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 364 http_server_props_manager_->SetSupportsSpdy(scheme_origin, true);
570 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 365 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
571 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 366 http_server_props_manager_->SetSupportsSpdy(scheme_origin, true);
572 367
573 // Run the task. 368 // Run the task.
574 base::RunLoop().RunUntilIdle(); 369 base::RunLoop().RunUntilIdle();
575 370
576 EXPECT_TRUE( 371 EXPECT_TRUE(
577 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); 372 http_server_props_manager_->SupportsRequestPriority(scheme_origin));
578 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 373 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
579 } 374 }
580 375
581 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) { 376 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) {
582 ExpectPrefsUpdate(); 377 ExpectPrefsUpdate();
583 ExpectScheduleUpdatePrefsOnNetworkThread(); 378 ExpectScheduleUpdatePrefsOnNetworkThread();
584 379
585 // Add SpdySetting for mail.google.com:443. 380 // Add SpdySetting for mail.google.com:443.
586 HostPortPair spdy_server_mail("mail.google.com", 443); 381 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443);
587 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 382 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
588 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 383 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
589 const uint32_t value1 = 31337; 384 const uint32_t value1 = 31337;
590 http_server_props_manager_->SetSpdySetting( 385 http_server_props_manager_->SetSpdySetting(
591 spdy_server_mail, id1, flags1, value1); 386 spdy_server_mail, id1, flags1, value1);
592 387
593 // Run the task. 388 // Run the task.
594 base::RunLoop().RunUntilIdle(); 389 base::RunLoop().RunUntilIdle();
595 390
596 const SettingsMap& settings_map1_ret = 391 const SettingsMap& settings_map1_ret =
597 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 392 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
598 ASSERT_EQ(1U, settings_map1_ret.size()); 393 ASSERT_EQ(1U, settings_map1_ret.size());
599 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 394 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
600 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 395 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
601 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 396 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
602 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 397 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
603 EXPECT_EQ(value1, flags_and_value1_ret.second); 398 EXPECT_EQ(value1, flags_and_value1_ret.second);
604 399
605 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 400 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
606 } 401 }
607 402
608 TEST_P(HttpServerPropertiesManagerTest, ClearSpdySetting) { 403 TEST_P(HttpServerPropertiesManagerTest, ClearSpdySetting) {
609 ExpectPrefsUpdateRepeatedly(); 404 ExpectPrefsUpdateRepeatedly();
610 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 405 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
611 406
612 // Add SpdySetting for mail.google.com:443. 407 // Add SpdySetting for mail.google.com:443.
613 HostPortPair spdy_server_mail("mail.google.com", 443); 408 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443);
614 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 409 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
615 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 410 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
616 const uint32_t value1 = 31337; 411 const uint32_t value1 = 31337;
617 http_server_props_manager_->SetSpdySetting( 412 http_server_props_manager_->SetSpdySetting(
618 spdy_server_mail, id1, flags1, value1); 413 spdy_server_mail, id1, flags1, value1);
619 414
620 // Run the task. 415 // Run the task.
621 base::RunLoop().RunUntilIdle(); 416 base::RunLoop().RunUntilIdle();
622 417
623 const SettingsMap& settings_map1_ret = 418 const SettingsMap& settings_map1_ret =
(...skipping 18 matching lines...) Expand all
642 ASSERT_EQ(0U, settings_map2_ret.size()); 437 ASSERT_EQ(0U, settings_map2_ret.size());
643 438
644 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 439 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
645 } 440 }
646 441
647 TEST_P(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { 442 TEST_P(HttpServerPropertiesManagerTest, ClearAllSpdySetting) {
648 ExpectPrefsUpdateRepeatedly(); 443 ExpectPrefsUpdateRepeatedly();
649 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 444 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
650 445
651 // Add SpdySetting for mail.google.com:443. 446 // Add SpdySetting for mail.google.com:443.
652 HostPortPair spdy_server_mail("mail.google.com", 443); 447 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443);
653 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 448 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
654 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 449 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
655 const uint32_t value1 = 31337; 450 const uint32_t value1 = 31337;
656 http_server_props_manager_->SetSpdySetting( 451 http_server_props_manager_->SetSpdySetting(
657 spdy_server_mail, id1, flags1, value1); 452 spdy_server_mail, id1, flags1, value1);
658 453
659 // Run the task. 454 // Run the task.
660 base::RunLoop().RunUntilIdle(); 455 base::RunLoop().RunUntilIdle();
661 456
662 const SettingsMap& settings_map1_ret = 457 const SettingsMap& settings_map1_ret =
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 632 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
838 633
839 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 634 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
840 EXPECT_EQ(actual_address, address); 635 EXPECT_EQ(actual_address, address);
841 } 636 }
842 637
843 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) { 638 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) {
844 ExpectPrefsUpdate(); 639 ExpectPrefsUpdate();
845 ExpectScheduleUpdatePrefsOnNetworkThread(); 640 ExpectScheduleUpdatePrefsOnNetworkThread();
846 641
847 HostPortPair mail_server("mail.google.com", 80); 642 url::SchemeHostPort mail_server("http", "mail.google.com", 80);
848 const ServerNetworkStats* stats = 643 const ServerNetworkStats* stats =
849 http_server_props_manager_->GetServerNetworkStats(mail_server); 644 http_server_props_manager_->GetServerNetworkStats(mail_server);
850 EXPECT_EQ(nullptr, stats); 645 EXPECT_EQ(nullptr, stats);
851 ServerNetworkStats stats1; 646 ServerNetworkStats stats1;
852 stats1.srtt = base::TimeDelta::FromMicroseconds(10); 647 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
853 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); 648 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1);
854 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 649 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
855 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); 650 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1);
856 651
857 // Run the task. 652 // Run the task.
(...skipping 24 matching lines...) Expand all
882 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 677 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
883 678
884 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 679 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
885 mail_quic_server_id)); 680 mail_quic_server_id));
886 } 681 }
887 682
888 TEST_P(HttpServerPropertiesManagerTest, Clear) { 683 TEST_P(HttpServerPropertiesManagerTest, Clear) {
889 ExpectPrefsUpdate(); 684 ExpectPrefsUpdate();
890 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 685 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
891 686
892 HostPortPair spdy_server_mail("mail.google.com", 443); 687 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443);
893 url::SchemeHostPort scheme_origin("http", "mail.google.com", 443);
894 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 688 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
895 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); 689 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234);
896 http_server_props_manager_->SetAlternativeService( 690 http_server_props_manager_->SetAlternativeService(
897 scheme_origin, alternative_service, one_day_from_now_); 691 spdy_server_mail, alternative_service, one_day_from_now_);
898 IPAddress actual_address(127, 0, 0, 1); 692 IPAddress actual_address(127, 0, 0, 1);
899 http_server_props_manager_->SetSupportsQuic(true, actual_address); 693 http_server_props_manager_->SetSupportsQuic(true, actual_address);
900 ServerNetworkStats stats; 694 ServerNetworkStats stats;
901 stats.srtt = base::TimeDelta::FromMicroseconds(10); 695 stats.srtt = base::TimeDelta::FromMicroseconds(10);
902 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); 696 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats);
903 697
904 QuicServerId mail_quic_server_id("mail.google.com", 80); 698 QuicServerId mail_quic_server_id("mail.google.com", 80);
905 std::string quic_server_info1("quic_server_info1"); 699 std::string quic_server_info1("quic_server_info1");
906 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 700 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
907 quic_server_info1); 701 quic_server_info1);
908 702
909 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 703 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
910 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 704 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
911 const uint32_t value1 = 31337; 705 const uint32_t value1 = 31337;
912 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, 706 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1,
913 value1); 707 value1);
914 708
915 // Run the task. 709 // Run the task.
916 base::RunLoop().RunUntilIdle(); 710 base::RunLoop().RunUntilIdle();
917 711
918 EXPECT_TRUE( 712 EXPECT_TRUE(
919 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); 713 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
920 EXPECT_TRUE(HasAlternativeService(scheme_origin)); 714 EXPECT_TRUE(HasAlternativeService(spdy_server_mail));
921 IPAddress address; 715 IPAddress address;
922 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 716 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
923 EXPECT_EQ(actual_address, address); 717 EXPECT_EQ(actual_address, address);
924 const ServerNetworkStats* stats1 = 718 const ServerNetworkStats* stats1 =
925 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 719 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
926 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); 720 EXPECT_EQ(10, stats1->srtt.ToInternalValue());
927 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( 721 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
928 mail_quic_server_id)); 722 mail_quic_server_id));
929 723
930 // Check SPDY settings values. 724 // Check SPDY settings values.
931 const SettingsMap& settings_map1_ret = 725 const SettingsMap& settings_map1_ret =
932 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 726 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
933 ASSERT_EQ(1U, settings_map1_ret.size()); 727 ASSERT_EQ(1U, settings_map1_ret.size());
934 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 728 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
935 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 729 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
936 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 730 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
937 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 731 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
938 EXPECT_EQ(value1, flags_and_value1_ret.second); 732 EXPECT_EQ(value1, flags_and_value1_ret.second);
939 733
940 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 734 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
941 735
942 ExpectPrefsUpdate(); 736 ExpectPrefsUpdate();
943 737
944 // Clear http server data, time out if we do not get a completion callback. 738 // Clear http server data, time out if we do not get a completion callback.
945 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); 739 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure());
946 base::RunLoop().Run(); 740 base::RunLoop().Run();
947 741
948 EXPECT_FALSE( 742 EXPECT_FALSE(
949 http_server_props_manager_->SupportsRequestPriority(scheme_origin)); 743 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
950 EXPECT_FALSE(HasAlternativeService(scheme_origin)); 744 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
951 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); 745 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
952 const ServerNetworkStats* stats2 = 746 const ServerNetworkStats* stats2 =
953 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 747 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
954 EXPECT_EQ(nullptr, stats2); 748 EXPECT_EQ(nullptr, stats2);
955 EXPECT_EQ(nullptr, 749 EXPECT_EQ(nullptr,
956 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); 750 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id));
957 751
958 const SettingsMap& settings_map2_ret = 752 const SettingsMap& settings_map2_ret =
959 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 753 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
960 EXPECT_EQ(0U, settings_map2_ret.size()); 754 EXPECT_EQ(0U, settings_map2_ret.size());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 820
1027 base::RunLoop().RunUntilIdle(); 821 base::RunLoop().RunUntilIdle();
1028 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 822 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1029 823
1030 // Verify alternative service. 824 // Verify alternative service.
1031 for (int i = 0; i < 200; ++i) { 825 for (int i = 0; i < 200; ++i) {
1032 std::string server = StringPrintf("www.google.com:%d", i); 826 std::string server = StringPrintf("www.google.com:%d", i);
1033 AlternativeServiceVector alternative_service_vector = 827 AlternativeServiceVector alternative_service_vector =
1034 http_server_props_manager_->GetAlternativeServices( 828 http_server_props_manager_->GetAlternativeServices(
1035 url::SchemeHostPort("https", "www.google.com", i)); 829 url::SchemeHostPort("https", "www.google.com", i));
1036 if (GetParam() > 4) { 830 ASSERT_EQ(1u, alternative_service_vector.size());
1037 ASSERT_EQ(1u, alternative_service_vector.size()); 831 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol);
1038 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); 832 EXPECT_EQ(i, alternative_service_vector[0].port);
1039 EXPECT_EQ(i, alternative_service_vector[0].port);
1040 } else {
1041 EXPECT_EQ(0u, alternative_service_vector.size());
1042 }
1043 } 833 }
1044 834
1045 // Verify SupportsQuic. 835 // Verify SupportsQuic.
1046 IPAddress address; 836 IPAddress address;
1047 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 837 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
1048 EXPECT_EQ("127.0.0.1", address.ToString()); 838 EXPECT_EQ("127.0.0.1", address.ToString());
1049 } 839 }
1050 840
1051 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { 841 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
1052 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 842 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
1053 843
1054 url::SchemeHostPort server_www("http", "www.google.com", 80); 844 const url::SchemeHostPort server_www("http", "www.google.com", 80);
1055 const HostPortPair server_mail("mail.google.com", 80); 845 const url::SchemeHostPort server_mail("http", "mail.google.com", 80);
1056 url::SchemeHostPort mail_server("http", "mail.google.com", 80);
1057 846
1058 // Set alternate protocol. 847 // Set alternate protocol.
1059 AlternativeServiceInfoVector alternative_service_info_vector; 848 AlternativeServiceInfoVector alternative_service_info_vector;
1060 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); 849 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443);
1061 base::Time expiration1; 850 base::Time expiration1;
1062 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); 851 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1));
1063 alternative_service_info_vector.push_back( 852 alternative_service_info_vector.push_back(
1064 AlternativeServiceInfo(www_alternative_service1, expiration1)); 853 AlternativeServiceInfo(www_alternative_service1, expiration1));
1065 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", 854 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com",
1066 1234); 855 1234);
1067 base::Time expiration2; 856 base::Time expiration2;
1068 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); 857 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2));
1069 alternative_service_info_vector.push_back( 858 alternative_service_info_vector.push_back(
1070 AlternativeServiceInfo(www_alternative_service2, expiration2)); 859 AlternativeServiceInfo(www_alternative_service2, expiration2));
1071 http_server_props_manager_->SetAlternativeServices( 860 http_server_props_manager_->SetAlternativeServices(
1072 server_www, alternative_service_info_vector); 861 server_www, alternative_service_info_vector);
1073 862
1074 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", 863 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com",
1075 444); 864 444);
1076 base::Time expiration3 = base::Time::Max(); 865 base::Time expiration3 = base::Time::Max();
1077 http_server_props_manager_->SetAlternativeService( 866 http_server_props_manager_->SetAlternativeService(
1078 mail_server, mail_alternative_service, expiration3); 867 server_mail, mail_alternative_service, expiration3);
1079 868
1080 // Set ServerNetworkStats. 869 // Set ServerNetworkStats.
1081 ServerNetworkStats stats; 870 ServerNetworkStats stats;
1082 stats.srtt = base::TimeDelta::FromInternalValue(42); 871 stats.srtt = base::TimeDelta::FromInternalValue(42);
1083 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); 872 http_server_props_manager_->SetServerNetworkStats(server_mail, stats);
1084 873
1085 // Set quic_server_info string. 874 // Set quic_server_info string.
1086 QuicServerId mail_quic_server_id("mail.google.com", 80); 875 QuicServerId mail_quic_server_id("mail.google.com", 80);
1087 std::string quic_server_info1("quic_server_info1"); 876 std::string quic_server_info1("quic_server_info1");
1088 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 877 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 // Shutdown comes before the task is executed. 1137 // Shutdown comes before the task is executed.
1349 http_server_props_manager_->ShutdownOnPrefThread(); 1138 http_server_props_manager_->ShutdownOnPrefThread();
1350 // Run the task after shutdown, but before deletion. 1139 // Run the task after shutdown, but before deletion.
1351 base::RunLoop().RunUntilIdle(); 1140 base::RunLoop().RunUntilIdle();
1352 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1141 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1353 http_server_props_manager_.reset(); 1142 http_server_props_manager_.reset();
1354 base::RunLoop().RunUntilIdle(); 1143 base::RunLoop().RunUntilIdle();
1355 } 1144 }
1356 1145
1357 } // namespace net 1146 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698