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

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

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

Powered by Google App Engine
This is Rietveld 408576698