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

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

Issue 1626673002: Separate prefs from HttpServerPropertiesManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: includes Created 4 years, 11 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"
11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/testing_pref_service.h"
13 #include "base/run_loop.h" 11 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
17 #include "base/test/test_simple_task_runner.h" 15 #include "base/test/test_simple_task_runner.h"
18 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
19 #include "base/values.h" 17 #include "base/values.h"
20 #include "net/base/ip_address_number.h" 18 #include "net/base/ip_address_number.h"
21 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
23 #include "url/gurl.h" 21 #include "url/gurl.h"
24 22
25 namespace net { 23 namespace net {
26 24
27 namespace { 25 namespace {
28 26
29 using base::StringPrintf; 27 using base::StringPrintf;
30 using ::testing::_; 28 using ::testing::_;
31 using ::testing::Invoke; 29 using ::testing::Invoke;
32 using ::testing::Mock; 30 using ::testing::Mock;
33 using ::testing::StrictMock; 31 using ::testing::StrictMock;
34 32
35 const char kTestHttpServerProperties[] = "TestHttpServerProperties"; 33 class MockPrefDelegate : public net::HttpServerPropertiesManager::PrefDelegate {
34 public:
35 MockPrefDelegate() {}
36 ~MockPrefDelegate() override {}
37
38 // HttpServerPropertiesManager::PrefDelegate implementation.
39 bool HasServerProperties() override { return true; }
40 const base::DictionaryValue& GetServerProperties() const override {
41 return prefs_;
42 }
43 void SetServerProperties(const base::Value& value) override {
44 const base::DictionaryValue* value_dict = nullptr;
45 CHECK(value.GetAsDictionary(&value_dict));
46
47 prefs_.Clear();
48 prefs_.MergeDictionary(value_dict);
49 if (!prefs_changed_callback_.is_null())
50 prefs_changed_callback_.Run();
51 }
52 void StartListeningForUpdates(const base::Closure& callback) override {
53 CHECK(prefs_changed_callback_.is_null());
54 prefs_changed_callback_ = callback;
55 }
56 void StopListeningForUpdates() override {
57 CHECK(!prefs_changed_callback_.is_null());
58 prefs_changed_callback_ = base::Closure();
59 }
60
61 void SetPrefs(const base::DictionaryValue& value) {
62 // prefs_ = value;
63 prefs_.Clear();
64 prefs_.MergeDictionary(&value);
65 if (!prefs_changed_callback_.is_null())
66 prefs_changed_callback_.Run();
67 }
68
69 private:
70 base::DictionaryValue prefs_;
71 base::Closure prefs_changed_callback_;
72
73 DISALLOW_COPY_AND_ASSIGN(MockPrefDelegate);
74 };
36 75
37 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { 76 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager {
38 public: 77 public:
39 TestingHttpServerPropertiesManager( 78 TestingHttpServerPropertiesManager(
40 PrefService* pref_service, 79 HttpServerPropertiesManager::PrefDelegate* pref_delegate,
41 const char* pref_path,
42 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 80 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
43 : HttpServerPropertiesManager(pref_service, pref_path, io_task_runner) { 81 : HttpServerPropertiesManager(pref_delegate, io_task_runner) {
44 InitializeOnNetworkThread(); 82 InitializeOnNetworkThread();
45 } 83 }
46 84
47 ~TestingHttpServerPropertiesManager() override {} 85 ~TestingHttpServerPropertiesManager() override {}
48 86
49 // Make these methods public for testing. 87 // Make these methods public for testing.
50 using HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread; 88 using HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread;
51 89
52 // Post tasks without a delay during tests. 90 // Post tasks without a delay during tests.
53 void StartPrefsUpdateTimerOnNetworkThread(base::TimeDelta delay) override { 91 void StartPrefsUpdateTimerOnNetworkThread(base::TimeDelta delay) override {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated 147 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated
110 // to version 4, delete the following code. 148 // to version 4, delete the following code.
111 static const int kHttpServerPropertiesVersions[] = {3, 4}; 149 static const int kHttpServerPropertiesVersions[] = {3, 4};
112 150
113 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { 151 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> {
114 protected: 152 protected:
115 HttpServerPropertiesManagerTest() {} 153 HttpServerPropertiesManagerTest() {}
116 154
117 void SetUp() override { 155 void SetUp() override {
118 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); 156 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1);
119 pref_service_.registry()->RegisterDictionaryPref(kTestHttpServerProperties); 157 pref_delegate_ = new MockPrefDelegate;
120 http_server_props_manager_.reset( 158 http_server_props_manager_.reset(
121 new StrictMock<TestingHttpServerPropertiesManager>( 159 new StrictMock<TestingHttpServerPropertiesManager>(
122 &pref_service_, kTestHttpServerProperties, 160 pref_delegate_, base::ThreadTaskRunnerHandle::Get()));
123 base::ThreadTaskRunnerHandle::Get()));
124 ExpectCacheUpdate(); 161 ExpectCacheUpdate();
125 base::RunLoop().RunUntilIdle(); 162 base::RunLoop().RunUntilIdle();
126 } 163 }
127 164
128 void TearDown() override { 165 void TearDown() override {
129 if (http_server_props_manager_.get()) 166 if (http_server_props_manager_.get())
130 http_server_props_manager_->ShutdownOnPrefThread(); 167 http_server_props_manager_->ShutdownOnPrefThread();
131 base::RunLoop().RunUntilIdle(); 168 base::RunLoop().RunUntilIdle();
132 http_server_props_manager_.reset(); 169 http_server_props_manager_.reset();
133 } 170 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 &TestingHttpServerPropertiesManager:: 208 &TestingHttpServerPropertiesManager::
172 UpdatePrefsFromCacheOnNetworkThreadConcrete)); 209 UpdatePrefsFromCacheOnNetworkThreadConcrete));
173 } 210 }
174 211
175 bool HasAlternativeService(const HostPortPair& server) { 212 bool HasAlternativeService(const HostPortPair& server) {
176 const AlternativeServiceVector alternative_service_vector = 213 const AlternativeServiceVector alternative_service_vector =
177 http_server_props_manager_->GetAlternativeServices(server); 214 http_server_props_manager_->GetAlternativeServices(server);
178 return !alternative_service_vector.empty(); 215 return !alternative_service_vector.empty();
179 } 216 }
180 217
181 //base::RunLoop loop_; 218 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager.
182 TestingPrefServiceSimple pref_service_;
183 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; 219 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_;
184 base::Time one_day_from_now_; 220 base::Time one_day_from_now_;
185 221
186 private: 222 private:
187 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 223 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
188 }; 224 };
189 225
190 INSTANTIATE_TEST_CASE_P(Tests, 226 INSTANTIATE_TEST_CASE_P(Tests,
191 HttpServerPropertiesManagerTest, 227 HttpServerPropertiesManagerTest,
192 ::testing::ValuesIn(kHttpServerPropertiesVersions)); 228 ::testing::ValuesIn(kHttpServerPropertiesVersions));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 server_pref_dict1->SetWithoutPathExpansion("alternative_service", 285 server_pref_dict1->SetWithoutPathExpansion("alternative_service",
250 alternative_service_list1); 286 alternative_service_list1);
251 287
252 // Set up ServerNetworkStats for mail.google.com:80 and it is the MRU server. 288 // Set up ServerNetworkStats for mail.google.com:80 and it is the MRU server.
253 base::DictionaryValue* stats1 = new base::DictionaryValue; 289 base::DictionaryValue* stats1 = new base::DictionaryValue;
254 stats1->SetInteger("srtt", 20); 290 stats1->SetInteger("srtt", 20);
255 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); 291 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1);
256 // Set the server preference for mail.google.com:80. 292 // Set the server preference for mail.google.com:80.
257 servers_dict->SetWithoutPathExpansion("mail.google.com:80", 293 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
258 server_pref_dict1); 294 server_pref_dict1);
259 base::DictionaryValue* http_server_properties_dict = 295 base::DictionaryValue http_server_properties_dict;
260 new base::DictionaryValue;
261 if (GetParam() == 4) { 296 if (GetParam() == 4) {
262 // |servers_list| takes ownership of |servers_dict|. 297 // |servers_list| takes ownership of |servers_dict|.
263 servers_list->AppendIfNotPresent(servers_dict); 298 servers_list->AppendIfNotPresent(servers_dict);
264 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 299 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
265 http_server_properties_dict->SetWithoutPathExpansion("servers", 300 http_server_properties_dict.SetWithoutPathExpansion("servers",
266 servers_list); 301 servers_list);
267 } else { 302 } else {
268 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, 303 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
269 GetParam()); 304 GetParam());
270 http_server_properties_dict->SetWithoutPathExpansion("servers", 305 http_server_properties_dict.SetWithoutPathExpansion("servers",
271 servers_dict); 306 servers_dict);
272 } 307 }
273 base::DictionaryValue* supports_quic = new base::DictionaryValue; 308 base::DictionaryValue* supports_quic = new base::DictionaryValue;
274 supports_quic->SetBoolean("used_quic", true); 309 supports_quic->SetBoolean("used_quic", true);
275 supports_quic->SetString("address", "127.0.0.1"); 310 supports_quic->SetString("address", "127.0.0.1");
276 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", 311 http_server_properties_dict.SetWithoutPathExpansion("supports_quic",
277 supports_quic); 312 supports_quic);
278 313
279 // Set quic_server_info for www.google.com:80, mail.google.com:80 and 314 // Set quic_server_info for www.google.com:80, mail.google.com:80 and
280 // play.google.com:80 and verify the MRU. 315 // play.google.com:80 and verify the MRU.
281 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(3); 316 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(3);
282 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; 317 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue;
283 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; 318 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue;
284 std::string quic_server_info1("quic_server_info1"); 319 std::string quic_server_info1("quic_server_info1");
285 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", 320 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info",
286 quic_server_info1); 321 quic_server_info1);
287 base::DictionaryValue* quic_server_pref_dict2 = new base::DictionaryValue; 322 base::DictionaryValue* quic_server_pref_dict2 = new base::DictionaryValue;
288 std::string quic_server_info2("quic_server_info2"); 323 std::string quic_server_info2("quic_server_info2");
289 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info", 324 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info",
290 quic_server_info2); 325 quic_server_info2);
291 base::DictionaryValue* quic_server_pref_dict3 = new base::DictionaryValue; 326 base::DictionaryValue* quic_server_pref_dict3 = new base::DictionaryValue;
292 std::string quic_server_info3("quic_server_info3"); 327 std::string quic_server_info3("quic_server_info3");
293 quic_server_pref_dict3->SetStringWithoutPathExpansion("server_info", 328 quic_server_pref_dict3->SetStringWithoutPathExpansion("server_info",
294 quic_server_info3); 329 quic_server_info3);
295 // Set the quic_server_info1 for www.google.com server. 330 // Set the quic_server_info1 for www.google.com server.
296 QuicServerId google_quic_server_id("www.google.com", 80); 331 QuicServerId google_quic_server_id("www.google.com", 80);
297 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(), 332 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(),
298 quic_server_pref_dict1); 333 quic_server_pref_dict1);
299 // Set the quic_server_info2 for mail.google.com server. 334 // Set the quic_server_info2 for mail.google.com server.
300 QuicServerId mail_quic_server_id("mail.google.com", 80); 335 QuicServerId mail_quic_server_id("mail.google.com", 80);
301 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(), 336 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(),
302 quic_server_pref_dict2); 337 quic_server_pref_dict2);
303 // Set the quic_server_info3 for play.google.com server. 338 // Set the quic_server_info3 for play.google.com server.
304 QuicServerId play_quic_server_id("play.google.com", 80); 339 QuicServerId play_quic_server_id("play.google.com", 80);
305 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(), 340 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(),
306 quic_server_pref_dict3); 341 quic_server_pref_dict3);
307 http_server_properties_dict->SetWithoutPathExpansion("quic_servers", 342 http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
308 quic_servers_dict); 343 quic_servers_dict);
309 344
310 // Set the same value for kHttpServerProperties multiple times. 345 // Set the same value for kHttpServerProperties multiple times.
311 pref_service_.SetManagedPref(kTestHttpServerProperties, 346 pref_delegate_->SetPrefs(http_server_properties_dict);
312 http_server_properties_dict); 347 pref_delegate_->SetPrefs(http_server_properties_dict);
313 base::DictionaryValue* http_server_properties_dict2 =
314 http_server_properties_dict->DeepCopy();
315 pref_service_.SetManagedPref(kTestHttpServerProperties,
316 http_server_properties_dict2);
317 348
318 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle();
319 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 350 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
320 351
321 // Verify SupportsSpdy. 352 // Verify SupportsSpdy.
322 EXPECT_TRUE( 353 EXPECT_TRUE(
323 http_server_props_manager_->SupportsRequestPriority(google_server)); 354 http_server_props_manager_->SupportsRequestPriority(google_server));
324 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); 355 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server));
325 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 356 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
326 HostPortPair::FromString("foo.google.com:1337"))); 357 HostPortPair::FromString("foo.google.com:1337")));
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 451
421 // Set up ServerNetworkStats for www.google.com:65536. 452 // Set up ServerNetworkStats for www.google.com:65536.
422 base::DictionaryValue* stats = new base::DictionaryValue; 453 base::DictionaryValue* stats = new base::DictionaryValue;
423 stats->SetInteger("srtt", 10); 454 stats->SetInteger("srtt", 10);
424 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 455 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
425 456
426 // Set the server preference for www.google.com:65536. 457 // Set the server preference for www.google.com:65536.
427 base::DictionaryValue* servers_dict = new base::DictionaryValue; 458 base::DictionaryValue* servers_dict = new base::DictionaryValue;
428 servers_dict->SetWithoutPathExpansion("www.google.com:65536", 459 servers_dict->SetWithoutPathExpansion("www.google.com:65536",
429 server_pref_dict); 460 server_pref_dict);
430 base::DictionaryValue* http_server_properties_dict = 461 base::DictionaryValue http_server_properties_dict;
431 new base::DictionaryValue;
432 if (GetParam() == 4) { 462 if (GetParam() == 4) {
433 base::ListValue* servers_list = new base::ListValue; 463 base::ListValue* servers_list = new base::ListValue;
434 // |servers_list| takes ownership of |servers_dict|. 464 // |servers_list| takes ownership of |servers_dict|.
435 servers_list->AppendIfNotPresent(servers_dict); 465 servers_list->AppendIfNotPresent(servers_dict);
436 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 466 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
437 http_server_properties_dict->SetWithoutPathExpansion("servers", 467 http_server_properties_dict.SetWithoutPathExpansion("servers",
438 servers_list); 468 servers_list);
439 } else { 469 } else {
440 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, 470 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
441 GetParam()); 471 GetParam());
442 http_server_properties_dict->SetWithoutPathExpansion("servers", 472 http_server_properties_dict.SetWithoutPathExpansion("servers",
443 servers_dict); 473 servers_dict);
444 } 474 }
445 475
446 // Set quic_server_info for www.google.com:65536. 476 // Set quic_server_info for www.google.com:65536.
447 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; 477 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue;
448 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; 478 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue;
449 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", 479 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info",
450 "quic_server_info1"); 480 "quic_server_info1");
451 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536", 481 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536",
452 quic_server_pref_dict1); 482 quic_server_pref_dict1);
453 483
454 http_server_properties_dict->SetWithoutPathExpansion("quic_servers", 484 http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
455 quic_servers_dict); 485 quic_servers_dict);
456 486
457 // Set up the pref. 487 // Set up the pref.
458 pref_service_.SetManagedPref(kTestHttpServerProperties, 488 pref_delegate_->SetPrefs(http_server_properties_dict);
459 http_server_properties_dict);
460 489
461 base::RunLoop().RunUntilIdle(); 490 base::RunLoop().RunUntilIdle();
462 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 491 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
463 492
464 // Verify that nothing is set. 493 // Verify that nothing is set.
465 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 494 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
466 HostPortPair::FromString("www.google.com:65536"))); 495 HostPortPair::FromString("www.google.com:65536")));
467 EXPECT_FALSE( 496 EXPECT_FALSE(
468 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); 497 HasAlternativeService(HostPortPair::FromString("www.google.com:65536")));
469 const ServerNetworkStats* stats1 = 498 const ServerNetworkStats* stats1 =
(...skipping 19 matching lines...) Expand all
489 alternative_service_dict->SetString("protocol_str", "npn-h2"); 518 alternative_service_dict->SetString("protocol_str", "npn-h2");
490 alternative_service_dict->SetInteger("port", 65536); 519 alternative_service_dict->SetInteger("port", 65536);
491 base::ListValue* alternative_service_list = new base::ListValue; 520 base::ListValue* alternative_service_list = new base::ListValue;
492 alternative_service_list->Append(alternative_service_dict); 521 alternative_service_list->Append(alternative_service_dict);
493 server_pref_dict->SetWithoutPathExpansion("alternative_service", 522 server_pref_dict->SetWithoutPathExpansion("alternative_service",
494 alternative_service_list); 523 alternative_service_list);
495 524
496 // Set the server preference for www.google.com:80. 525 // Set the server preference for www.google.com:80.
497 base::DictionaryValue* servers_dict = new base::DictionaryValue; 526 base::DictionaryValue* servers_dict = new base::DictionaryValue;
498 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); 527 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
499 base::DictionaryValue* http_server_properties_dict = 528 base::DictionaryValue http_server_properties_dict;
500 new base::DictionaryValue;
501 if (GetParam() == 4) { 529 if (GetParam() == 4) {
502 base::ListValue* servers_list = new base::ListValue; 530 base::ListValue* servers_list = new base::ListValue;
503 // |servers_list| takes ownership of |servers_dict|. 531 // |servers_list| takes ownership of |servers_dict|.
504 servers_list->AppendIfNotPresent(servers_dict); 532 servers_list->AppendIfNotPresent(servers_dict);
505 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 533 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
506 http_server_properties_dict->SetWithoutPathExpansion("servers", 534 http_server_properties_dict.SetWithoutPathExpansion("servers",
507 servers_list); 535 servers_list);
508 } else { 536 } else {
509 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, 537 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
510 GetParam()); 538 GetParam());
511 http_server_properties_dict->SetWithoutPathExpansion("servers", 539 http_server_properties_dict.SetWithoutPathExpansion("servers",
512 servers_dict); 540 servers_dict);
513 } 541 }
514 542
515 // Set up the pref. 543 // Set up the pref.
516 pref_service_.SetManagedPref(kTestHttpServerProperties, 544 pref_delegate_->SetPrefs(http_server_properties_dict);
517 http_server_properties_dict);
518 545
519 base::RunLoop().RunUntilIdle(); 546 base::RunLoop().RunUntilIdle();
520 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 547 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
521 548
522 // Verify alternative service is not set. 549 // Verify alternative service is not set.
523 EXPECT_FALSE( 550 EXPECT_FALSE(
524 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); 551 HasAlternativeService(HostPortPair::FromString("www.google.com:80")));
525 } 552 }
526 553
527 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { 554 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 StringPrintf("www.google.com:%d", i), server_pref_dict); 990 StringPrintf("www.google.com:%d", i), server_pref_dict);
964 } 991 }
965 } 992 }
966 993
967 // Set the preference for mail.google.com server. 994 // Set the preference for mail.google.com server.
968 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 995 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
969 996
970 // Set the server preference for mail.google.com:80. 997 // Set the server preference for mail.google.com:80.
971 servers_dict->SetWithoutPathExpansion("mail.google.com:80", 998 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
972 server_pref_dict1); 999 server_pref_dict1);
973 base::DictionaryValue* http_server_properties_dict = 1000 base::DictionaryValue http_server_properties_dict;
974 new base::DictionaryValue;
975 if (GetParam() == 4) { 1001 if (GetParam() == 4) {
976 // |servers_list| takes ownership of |servers_dict|. 1002 // |servers_list| takes ownership of |servers_dict|.
977 servers_list->AppendIfNotPresent(servers_dict); 1003 servers_list->AppendIfNotPresent(servers_dict);
978 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 1004 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
979 http_server_properties_dict->SetWithoutPathExpansion("servers", 1005 http_server_properties_dict.SetWithoutPathExpansion("servers",
980 servers_list); 1006 servers_list);
981 } else { 1007 } else {
982 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, 1008 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
983 GetParam()); 1009 GetParam());
984 http_server_properties_dict->SetWithoutPathExpansion("servers", 1010 http_server_properties_dict.SetWithoutPathExpansion("servers",
985 servers_dict); 1011 servers_dict);
986 } 1012 }
987 1013
988 // Set up SupportsQuic for 127.0.0.1 1014 // Set up SupportsQuic for 127.0.0.1
989 base::DictionaryValue* supports_quic = new base::DictionaryValue; 1015 base::DictionaryValue* supports_quic = new base::DictionaryValue;
990 supports_quic->SetBoolean("used_quic", true); 1016 supports_quic->SetBoolean("used_quic", true);
991 supports_quic->SetString("address", "127.0.0.1"); 1017 supports_quic->SetString("address", "127.0.0.1");
992 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", 1018 http_server_properties_dict.SetWithoutPathExpansion("supports_quic",
993 supports_quic); 1019 supports_quic);
994 1020
995 // Set up the pref. 1021 // Set up the pref.
996 pref_service_.SetManagedPref(kTestHttpServerProperties, 1022 pref_delegate_->SetPrefs(http_server_properties_dict);
997 http_server_properties_dict);
998 1023
999 base::RunLoop().RunUntilIdle(); 1024 base::RunLoop().RunUntilIdle();
1000 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1025 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1001 1026
1002 // Verify alternative service. 1027 // Verify alternative service.
1003 for (int i = 0; i < 200; ++i) { 1028 for (int i = 0; i < 200; ++i) {
1004 std::string server = StringPrintf("www.google.com:%d", i); 1029 std::string server = StringPrintf("www.google.com:%d", i);
1005 AlternativeServiceVector alternative_service_vector = 1030 AlternativeServiceVector alternative_service_vector =
1006 http_server_props_manager_->GetAlternativeServices( 1031 http_server_props_manager_->GetAlternativeServices(
1007 HostPortPair::FromString(server)); 1032 HostPortPair::FromString(server));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 "\"port\":1234,\"probability\":0.7,\"protocol_str\":\"npn-h2\"}]}}," 1103 "\"port\":1234,\"probability\":0.7,\"protocol_str\":\"npn-h2\"}]}},"
1079 "{\"mail.google.com:80\":{\"alternative_service\":[{" 1104 "{\"mail.google.com:80\":{\"alternative_service\":[{"
1080 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," 1105 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\","
1081 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"}]," 1106 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"}],"
1082 "\"network_stats\":{\"srtt\":42}}}" 1107 "\"network_stats\":{\"srtt\":42}}}"
1083 "]," 1108 "],"
1084 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," 1109 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true},"
1085 "\"version\":4}"; 1110 "\"version\":4}";
1086 1111
1087 const base::Value* http_server_properties = 1112 const base::Value* http_server_properties =
1088 pref_service_.GetUserPref(kTestHttpServerProperties); 1113 &pref_delegate_->GetServerProperties();
1089 ASSERT_NE(nullptr, http_server_properties);
1090 std::string preferences_json; 1114 std::string preferences_json;
1091 EXPECT_TRUE( 1115 EXPECT_TRUE(
1092 base::JSONWriter::Write(*http_server_properties, &preferences_json)); 1116 base::JSONWriter::Write(*http_server_properties, &preferences_json));
1093 EXPECT_EQ(expected_json, preferences_json); 1117 EXPECT_EQ(expected_json, preferences_json);
1094 } 1118 }
1095 1119
1096 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { 1120 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) {
1097 scoped_ptr<base::Value> server_value = base::JSONReader::Read( 1121 scoped_ptr<base::Value> server_value = base::JSONReader::Read(
1098 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," 1122 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"},"
1099 "{\"port\":123,\"protocol_str\":\"quic\",\"probability\":0.7," 1123 "{\"port\":123,\"protocol_str\":\"quic\",\"probability\":0.7,"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 const HostPortPair host_port_pair("www.example.com", 443); 1202 const HostPortPair host_port_pair("www.example.com", 443);
1179 http_server_props_manager_->SetAlternativeServices( 1203 http_server_props_manager_->SetAlternativeServices(
1180 host_port_pair, alternative_service_info_vector); 1204 host_port_pair, alternative_service_info_vector);
1181 1205
1182 // Update cache. 1206 // Update cache.
1183 ExpectPrefsUpdate(); 1207 ExpectPrefsUpdate();
1184 ExpectCacheUpdate(); 1208 ExpectCacheUpdate();
1185 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 1209 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
1186 base::RunLoop().RunUntilIdle(); 1210 base::RunLoop().RunUntilIdle();
1187 1211
1188 const base::Value* pref_value = 1212 const base::DictionaryValue& pref_dict =
1189 pref_service_.GetUserPref(kTestHttpServerProperties); 1213 pref_delegate_->GetServerProperties();
1190 ASSERT_NE(nullptr, pref_value);
1191
1192 const base::DictionaryValue* pref_dict;
1193 ASSERT_TRUE(pref_value->GetAsDictionary(&pref_dict));
1194 1214
1195 const base::ListValue* servers_list = nullptr; 1215 const base::ListValue* servers_list = nullptr;
1196 ASSERT_TRUE(pref_dict->GetListWithoutPathExpansion("servers", &servers_list)); 1216 ASSERT_TRUE(pref_dict.GetListWithoutPathExpansion("servers", &servers_list));
1197 base::ListValue::const_iterator it = servers_list->begin(); 1217 base::ListValue::const_iterator it = servers_list->begin();
1198 const base::DictionaryValue* server_pref_dict; 1218 const base::DictionaryValue* server_pref_dict;
1199 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict)); 1219 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict));
1200 1220
1201 const base::DictionaryValue* example_pref_dict; 1221 const base::DictionaryValue* example_pref_dict;
1202 ASSERT_TRUE(server_pref_dict->GetDictionaryWithoutPathExpansion( 1222 ASSERT_TRUE(server_pref_dict->GetDictionaryWithoutPathExpansion(
1203 "www.example.com:443", &example_pref_dict)); 1223 "www.example.com:443", &example_pref_dict));
1204 1224
1205 const base::ListValue* altsvc_list; 1225 const base::ListValue* altsvc_list;
1206 ASSERT_TRUE(example_pref_dict->GetList("alternative_service", &altsvc_list)); 1226 ASSERT_TRUE(example_pref_dict->GetList("alternative_service", &altsvc_list));
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 // Shutdown comes before the task is executed. 1348 // Shutdown comes before the task is executed.
1329 http_server_props_manager_->ShutdownOnPrefThread(); 1349 http_server_props_manager_->ShutdownOnPrefThread();
1330 // Run the task after shutdown, but before deletion. 1350 // Run the task after shutdown, but before deletion.
1331 base::RunLoop().RunUntilIdle(); 1351 base::RunLoop().RunUntilIdle();
1332 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1352 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1333 http_server_props_manager_.reset(); 1353 http_server_props_manager_.reset();
1334 base::RunLoop().RunUntilIdle(); 1354 base::RunLoop().RunUntilIdle();
1335 } 1355 }
1336 1356
1337 } // namespace net 1357 } // namespace net
OLDNEW
« net/http/http_server_properties_manager.h ('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