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

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

Issue 2058233002: Rewrite simple uses of base::ListValue::Append() taking a raw pointer var. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less comments more ownership Created 4 years, 6 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/log/net_log_util.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 <memory>
8 #include <utility>
9
7 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
9 #include "base/macros.h" 12 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 14 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
13 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
15 #include "base/test/test_simple_task_runner.h" 18 #include "base/test/test_simple_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 238 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
236 url::SchemeHostPort google_server(GetParam() >= 5 ? "http" : "https", 239 url::SchemeHostPort google_server(GetParam() >= 5 ? "http" : "https",
237 "www.google.com", 80); 240 "www.google.com", 80);
238 url::SchemeHostPort mail_server(GetParam() >= 5 ? "http" : "https", 241 url::SchemeHostPort mail_server(GetParam() >= 5 ? "http" : "https",
239 "mail.google.com", 80); 242 "mail.google.com", 80);
240 243
241 // Set supports_spdy for http://www.google.com:80. 244 // Set supports_spdy for http://www.google.com:80.
242 server_pref_dict->SetBoolean("supports_spdy", true); 245 server_pref_dict->SetBoolean("supports_spdy", true);
243 246
244 // Set up alternative_services for http://www.google.com:80. 247 // Set up alternative_services for http://www.google.com:80.
245 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue; 248 std::unique_ptr<base::DictionaryValue> alternative_service_dict0(
249 new base::DictionaryValue);
246 alternative_service_dict0->SetInteger("port", 443); 250 alternative_service_dict0->SetInteger("port", 443);
247 alternative_service_dict0->SetString("protocol_str", "npn-h2"); 251 alternative_service_dict0->SetString("protocol_str", "npn-h2");
248 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue; 252 std::unique_ptr<base::DictionaryValue> alternative_service_dict1(
253 new base::DictionaryValue);
249 alternative_service_dict1->SetInteger("port", 1234); 254 alternative_service_dict1->SetInteger("port", 1234);
250 alternative_service_dict1->SetString("protocol_str", "quic"); 255 alternative_service_dict1->SetString("protocol_str", "quic");
251 base::ListValue* alternative_service_list0 = new base::ListValue; 256 base::ListValue* alternative_service_list0 = new base::ListValue;
252 alternative_service_list0->Append(alternative_service_dict0); 257 alternative_service_list0->Append(std::move(alternative_service_dict0));
253 alternative_service_list0->Append(alternative_service_dict1); 258 alternative_service_list0->Append(std::move(alternative_service_dict1));
254 server_pref_dict->SetWithoutPathExpansion("alternative_service", 259 server_pref_dict->SetWithoutPathExpansion("alternative_service",
255 alternative_service_list0); 260 alternative_service_list0);
256 261
257 // Set up ServerNetworkStats for http://www.google.com:80. 262 // Set up ServerNetworkStats for http://www.google.com:80.
258 base::DictionaryValue* stats = new base::DictionaryValue; 263 base::DictionaryValue* stats = new base::DictionaryValue;
259 stats->SetInteger("srtt", 10); 264 stats->SetInteger("srtt", 10);
260 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 265 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
261 266
262 // Set the server preference for http://www.google.com:80. 267 // Set the server preference for http://www.google.com:80.
263 base::DictionaryValue* servers_dict = new base::DictionaryValue; 268 base::DictionaryValue* servers_dict = new base::DictionaryValue;
264 servers_dict->SetWithoutPathExpansion( 269 servers_dict->SetWithoutPathExpansion(
265 GetParam() >= 5 ? "http://www.google.com" : "www.google.com:80", 270 GetParam() >= 5 ? "http://www.google.com" : "www.google.com:80",
266 server_pref_dict); 271 server_pref_dict);
267 base::ListValue* servers_list = nullptr; 272 base::ListValue* servers_list = nullptr;
268 if (GetParam() >= 4) { 273 if (GetParam() >= 4) {
269 servers_list = new base::ListValue; 274 servers_list = new base::ListValue;
270 // |servers_list| takes ownership of |servers_dict|. 275 // |servers_list| takes ownership of |servers_dict|.
271 servers_list->AppendIfNotPresent(servers_dict); 276 servers_list->AppendIfNotPresent(servers_dict);
272 servers_dict = new base::DictionaryValue; 277 servers_dict = new base::DictionaryValue;
273 } 278 }
274 279
275 // Set the preference for mail.google.com server. 280 // Set the preference for mail.google.com server.
276 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 281 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
277 282
278 // Set supports_spdy for mail.google.com:80 283 // Set supports_spdy for mail.google.com:80
279 server_pref_dict1->SetBoolean("supports_spdy", true); 284 server_pref_dict1->SetBoolean("supports_spdy", true);
280 285
281 // Set up alternative_services for mail.google.com:80. 286 // Set up alternative_services for mail.google.com:80.
282 base::DictionaryValue* alternative_service_dict2 = new base::DictionaryValue; 287 std::unique_ptr<base::DictionaryValue> alternative_service_dict2(
288 new base::DictionaryValue);
283 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); 289 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1");
284 alternative_service_dict2->SetInteger("port", 444); 290 alternative_service_dict2->SetInteger("port", 444);
285 base::ListValue* alternative_service_list1 = new base::ListValue; 291 base::ListValue* alternative_service_list1 = new base::ListValue;
286 alternative_service_list1->Append(alternative_service_dict2); 292 alternative_service_list1->Append(std::move(alternative_service_dict2));
287 server_pref_dict1->SetWithoutPathExpansion("alternative_service", 293 server_pref_dict1->SetWithoutPathExpansion("alternative_service",
288 alternative_service_list1); 294 alternative_service_list1);
289 295
290 // Set up ServerNetworkStats for http://mail.google.com:80 and it is the MRU 296 // Set up ServerNetworkStats for http://mail.google.com:80 and it is the MRU
291 // server. 297 // server.
292 base::DictionaryValue* stats1 = new base::DictionaryValue; 298 base::DictionaryValue* stats1 = new base::DictionaryValue;
293 stats1->SetInteger("srtt", 20); 299 stats1->SetInteger("srtt", 20);
294 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); 300 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1);
295 // Set the server preference for http://mail.google.com:80. 301 // Set the server preference for http://mail.google.com:80.
296 servers_dict->SetWithoutPathExpansion( 302 servers_dict->SetWithoutPathExpansion(
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 // The prefs are automaticalls updated in the case corruption is detected. 453 // The prefs are automaticalls updated in the case corruption is detected.
448 ExpectPrefsUpdate(); 454 ExpectPrefsUpdate();
449 ExpectScheduleUpdatePrefsOnNetworkThread(); 455 ExpectScheduleUpdatePrefsOnNetworkThread();
450 456
451 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 457 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
452 458
453 // Set supports_spdy for www.google.com:65536. 459 // Set supports_spdy for www.google.com:65536.
454 server_pref_dict->SetBoolean("supports_spdy", true); 460 server_pref_dict->SetBoolean("supports_spdy", true);
455 461
456 // Set up alternative_service for www.google.com:65536. 462 // Set up alternative_service for www.google.com:65536.
457 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; 463 std::unique_ptr<base::DictionaryValue> alternative_service_dict(
464 new base::DictionaryValue);
458 alternative_service_dict->SetString("protocol_str", "npn-h2"); 465 alternative_service_dict->SetString("protocol_str", "npn-h2");
459 alternative_service_dict->SetInteger("port", 80); 466 alternative_service_dict->SetInteger("port", 80);
460 base::ListValue* alternative_service_list = new base::ListValue; 467 base::ListValue* alternative_service_list = new base::ListValue;
461 alternative_service_list->Append(alternative_service_dict); 468 alternative_service_list->Append(std::move(alternative_service_dict));
462 server_pref_dict->SetWithoutPathExpansion("alternative_service", 469 server_pref_dict->SetWithoutPathExpansion("alternative_service",
463 alternative_service_list); 470 alternative_service_list);
464 471
465 // Set up ServerNetworkStats for www.google.com:65536. 472 // Set up ServerNetworkStats for www.google.com:65536.
466 base::DictionaryValue* stats = new base::DictionaryValue; 473 base::DictionaryValue* stats = new base::DictionaryValue;
467 stats->SetInteger("srtt", 10); 474 stats->SetInteger("srtt", 10);
468 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 475 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
469 476
470 // Set the server preference for www.google.com:65536. 477 // Set the server preference for www.google.com:65536.
471 base::DictionaryValue* servers_dict = new base::DictionaryValue; 478 base::DictionaryValue* servers_dict = new base::DictionaryValue;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 // The prefs are automaticalls updated in the case corruption is detected. 535 // The prefs are automaticalls updated in the case corruption is detected.
529 ExpectPrefsUpdate(); 536 ExpectPrefsUpdate();
530 ExpectScheduleUpdatePrefsOnNetworkThread(); 537 ExpectScheduleUpdatePrefsOnNetworkThread();
531 538
532 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 539 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
533 540
534 // Set supports_spdy for www.google.com:80. 541 // Set supports_spdy for www.google.com:80.
535 server_pref_dict->SetBoolean("supports_spdy", true); 542 server_pref_dict->SetBoolean("supports_spdy", true);
536 543
537 // Set up alternative_service for www.google.com:80. 544 // Set up alternative_service for www.google.com:80.
538 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; 545 std::unique_ptr<base::DictionaryValue> alternative_service_dict(
546 new base::DictionaryValue);
539 alternative_service_dict->SetString("protocol_str", "npn-h2"); 547 alternative_service_dict->SetString("protocol_str", "npn-h2");
540 alternative_service_dict->SetInteger("port", 65536); 548 alternative_service_dict->SetInteger("port", 65536);
541 base::ListValue* alternative_service_list = new base::ListValue; 549 base::ListValue* alternative_service_list = new base::ListValue;
542 alternative_service_list->Append(alternative_service_dict); 550 alternative_service_list->Append(std::move(alternative_service_dict));
543 server_pref_dict->SetWithoutPathExpansion("alternative_service", 551 server_pref_dict->SetWithoutPathExpansion("alternative_service",
544 alternative_service_list); 552 alternative_service_list);
545 553
546 // Set the server preference for www.google.com:80. 554 // Set the server preference for www.google.com:80.
547 base::DictionaryValue* servers_dict = new base::DictionaryValue; 555 base::DictionaryValue* servers_dict = new base::DictionaryValue;
548 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); 556 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
549 base::DictionaryValue http_server_properties_dict; 557 base::DictionaryValue http_server_properties_dict;
550 if (GetParam() >= 4) { 558 if (GetParam() >= 4) {
551 base::ListValue* servers_list = new base::ListValue; 559 base::ListValue* servers_list = new base::ListValue;
552 // |servers_list| takes ownership of |servers_dict|. 560 // |servers_list| takes ownership of |servers_dict|.
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { 993 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
986 ExpectCacheUpdate(); 994 ExpectCacheUpdate();
987 995
988 base::DictionaryValue* servers_dict = new base::DictionaryValue; 996 base::DictionaryValue* servers_dict = new base::DictionaryValue;
989 base::ListValue* servers_list = nullptr; 997 base::ListValue* servers_list = nullptr;
990 if (GetParam() >= 4) 998 if (GetParam() >= 4)
991 servers_list = new base::ListValue; 999 servers_list = new base::ListValue;
992 1000
993 for (int i = 1; i <= 200; ++i) { 1001 for (int i = 1; i <= 200; ++i) {
994 // Set up alternative_service for www.google.com:i. 1002 // Set up alternative_service for www.google.com:i.
995 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; 1003 std::unique_ptr<base::DictionaryValue> alternative_service_dict(
1004 new base::DictionaryValue);
996 alternative_service_dict->SetString("protocol_str", "quic"); 1005 alternative_service_dict->SetString("protocol_str", "quic");
997 alternative_service_dict->SetInteger("port", i); 1006 alternative_service_dict->SetInteger("port", i);
998 base::ListValue* alternative_service_list = new base::ListValue; 1007 base::ListValue* alternative_service_list = new base::ListValue;
999 alternative_service_list->Append(alternative_service_dict); 1008 alternative_service_list->Append(std::move(alternative_service_dict));
1000 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 1009 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
1001 server_pref_dict->SetWithoutPathExpansion("alternative_service", 1010 server_pref_dict->SetWithoutPathExpansion("alternative_service",
1002 alternative_service_list); 1011 alternative_service_list);
1003 if (GetParam() >= 5) { 1012 if (GetParam() >= 5) {
1004 servers_dict->SetWithoutPathExpansion( 1013 servers_dict->SetWithoutPathExpansion(
1005 StringPrintf("http://www.google.com:%d", i), server_pref_dict); 1014 StringPrintf("http://www.google.com:%d", i), server_pref_dict);
1006 } else { 1015 } else {
1007 servers_dict->SetWithoutPathExpansion( 1016 servers_dict->SetWithoutPathExpansion(
1008 StringPrintf("www.google.com:%d", i), server_pref_dict); 1017 StringPrintf("www.google.com:%d", i), server_pref_dict);
1009 } 1018 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 1272
1264 std::string hostname; 1273 std::string hostname;
1265 ASSERT_TRUE(altsvc_entry->GetString("host", &hostname)); 1274 ASSERT_TRUE(altsvc_entry->GetString("host", &hostname));
1266 EXPECT_EQ("valid.example.com", hostname); 1275 EXPECT_EQ("valid.example.com", hostname);
1267 } 1276 }
1268 1277
1269 // Test that expired alternative service entries on disk are ignored. 1278 // Test that expired alternative service entries on disk are ignored.
1270 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) { 1279 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) {
1271 std::unique_ptr<base::ListValue> alternative_service_list( 1280 std::unique_ptr<base::ListValue> alternative_service_list(
1272 new base::ListValue); 1281 new base::ListValue);
1273 base::DictionaryValue* expired_dict = new base::DictionaryValue; 1282 std::unique_ptr<base::DictionaryValue> expired_dict(
1283 new base::DictionaryValue);
1274 expired_dict->SetString("protocol_str", "npn-h2"); 1284 expired_dict->SetString("protocol_str", "npn-h2");
1275 expired_dict->SetString("host", "expired.example.com"); 1285 expired_dict->SetString("host", "expired.example.com");
1276 expired_dict->SetInteger("port", 443); 1286 expired_dict->SetInteger("port", 443);
1277 base::Time time_one_day_ago = 1287 base::Time time_one_day_ago =
1278 base::Time::Now() - base::TimeDelta::FromDays(1); 1288 base::Time::Now() - base::TimeDelta::FromDays(1);
1279 expired_dict->SetString( 1289 expired_dict->SetString(
1280 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue())); 1290 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue()));
1281 alternative_service_list->Append(expired_dict); 1291 alternative_service_list->Append(std::move(expired_dict));
1282 1292
1283 base::DictionaryValue* valid_dict = new base::DictionaryValue; 1293 std::unique_ptr<base::DictionaryValue> valid_dict(new base::DictionaryValue);
1284 valid_dict->SetString("protocol_str", "npn-h2"); 1294 valid_dict->SetString("protocol_str", "npn-h2");
1285 valid_dict->SetString("host", "valid.example.com"); 1295 valid_dict->SetString("host", "valid.example.com");
1286 valid_dict->SetInteger("port", 443); 1296 valid_dict->SetInteger("port", 443);
1287 valid_dict->SetString( 1297 valid_dict->SetString(
1288 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); 1298 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue()));
1289 alternative_service_list->Append(valid_dict); 1299 alternative_service_list->Append(std::move(valid_dict));
1290 1300
1291 base::DictionaryValue server_pref_dict; 1301 base::DictionaryValue server_pref_dict;
1292 server_pref_dict.SetWithoutPathExpansion("alternative_service", 1302 server_pref_dict.SetWithoutPathExpansion("alternative_service",
1293 alternative_service_list.release()); 1303 alternative_service_list.release());
1294 1304
1295 const url::SchemeHostPort server("https", "example.com", 443); 1305 const url::SchemeHostPort server("https", "example.com", 443);
1296 AlternativeServiceMap alternative_service_map(/*max_size=*/5); 1306 AlternativeServiceMap alternative_service_map(/*max_size=*/5);
1297 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( 1307 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap(
1298 server, server_pref_dict, &alternative_service_map)); 1308 server, server_pref_dict, &alternative_service_map));
1299 1309
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 // Shutdown comes before the task is executed. 1386 // Shutdown comes before the task is executed.
1377 http_server_props_manager_->ShutdownOnPrefThread(); 1387 http_server_props_manager_->ShutdownOnPrefThread();
1378 // Run the task after shutdown, but before deletion. 1388 // Run the task after shutdown, but before deletion.
1379 base::RunLoop().RunUntilIdle(); 1389 base::RunLoop().RunUntilIdle();
1380 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1390 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1381 http_server_props_manager_.reset(); 1391 http_server_props_manager_.reset();
1382 base::RunLoop().RunUntilIdle(); 1392 base::RunLoop().RunUntilIdle();
1383 } 1393 }
1384 1394
1385 } // namespace net 1395 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/log/net_log_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698