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

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