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

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

Issue 892203004: Make HttpServerProperties::GetSupportsQuic not host-specific. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const base::Closure& callback) { 67 const base::Closure& callback) {
68 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); 68 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback);
69 } 69 }
70 70
71 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); 71 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void());
72 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); 72 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&));
73 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, 73 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread,
74 void(std::vector<std::string>* spdy_servers, 74 void(std::vector<std::string>* spdy_servers,
75 SpdySettingsMap* spdy_settings_map, 75 SpdySettingsMap* spdy_settings_map,
76 AlternateProtocolMap* alternate_protocol_map, 76 AlternateProtocolMap* alternate_protocol_map,
77 SupportsQuicMap* supports_quic_map, 77 IPAddressNumber* last_quic_address,
78 ServerNetworkStatsMap* server_network_stats_map, 78 ServerNetworkStatsMap* server_network_stats_map,
79 bool detected_corrupted_prefs)); 79 bool detected_corrupted_prefs));
80 MOCK_METHOD5(UpdatePrefsOnPref, 80 MOCK_METHOD5(UpdatePrefsOnPref,
81 void(base::ListValue* spdy_server_list, 81 void(base::ListValue* spdy_server_list,
82 SpdySettingsMap* spdy_settings_map, 82 SpdySettingsMap* spdy_settings_map,
83 AlternateProtocolMap* alternate_protocol_map, 83 AlternateProtocolMap* alternate_protocol_map,
84 SupportsQuicMap* supports_quic_map, 84 IPAddressNumber* last_quic_address,
85 ServerNetworkStatsMap* server_network_stats_map)); 85 ServerNetworkStatsMap* server_network_stats_map));
86 86
87 private: 87 private:
88 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); 88 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager);
89 }; 89 };
90 90
91 class HttpServerPropertiesManagerTest : public testing::Test { 91 class HttpServerPropertiesManagerTest : public testing::Test {
92 protected: 92 protected:
93 HttpServerPropertiesManagerTest() {} 93 HttpServerPropertiesManagerTest() {}
94 94
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Set supports_spdy for www.google.com:80. 156 // Set supports_spdy for www.google.com:80.
157 server_pref_dict->SetBoolean("supports_spdy", true); 157 server_pref_dict->SetBoolean("supports_spdy", true);
158 158
159 // Set up alternate_protocol for www.google.com:80. 159 // Set up alternate_protocol for www.google.com:80.
160 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; 160 base::DictionaryValue* alternate_protocol = new base::DictionaryValue;
161 alternate_protocol->SetInteger("port", 443); 161 alternate_protocol->SetInteger("port", 443);
162 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); 162 alternate_protocol->SetString("protocol_str", "npn-spdy/3");
163 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", 163 server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
164 alternate_protocol); 164 alternate_protocol);
165 165
166 // Set up SupportsQuic for www.google.com:80.
167 base::DictionaryValue* supports_quic = new base::DictionaryValue;
168 supports_quic->SetBoolean("used_quic", true);
169 supports_quic->SetString("address", "foo");
170 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic);
171
172 // Set up ServerNetworkStats for www.google.com:80. 166 // Set up ServerNetworkStats for www.google.com:80.
173 base::DictionaryValue* stats = new base::DictionaryValue; 167 base::DictionaryValue* stats = new base::DictionaryValue;
174 stats->SetInteger("srtt", 10); 168 stats->SetInteger("srtt", 10);
175 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 169 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
176 170
177 // Set the server preference for www.google.com:80. 171 // Set the server preference for www.google.com:80.
178 base::DictionaryValue* servers_dict = new base::DictionaryValue; 172 base::DictionaryValue* servers_dict = new base::DictionaryValue;
179 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); 173 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
180 174
181 // Set the preference for mail.google.com server. 175 // Set the preference for mail.google.com server.
182 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 176 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
183 177
184 // Set supports_spdy for mail.google.com:80 178 // Set supports_spdy for mail.google.com:80
185 server_pref_dict1->SetBoolean("supports_spdy", true); 179 server_pref_dict1->SetBoolean("supports_spdy", true);
186 180
187 // Set up alternate_protocol for mail.google.com:80 181 // Set up alternate_protocol for mail.google.com:80
188 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; 182 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue;
189 alternate_protocol1->SetInteger("port", 444); 183 alternate_protocol1->SetInteger("port", 444);
190 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); 184 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1");
191 185
192 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", 186 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol",
193 alternate_protocol1); 187 alternate_protocol1);
194 188
195 // Set up SupportsQuic for mail.google.com:80
196 base::DictionaryValue* supports_quic1 = new base::DictionaryValue;
197 supports_quic1->SetBoolean("used_quic", false);
198 supports_quic1->SetString("address", "bar");
199 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1);
200
201 // Set up ServerNetworkStats for mail.google.com:80. 189 // Set up ServerNetworkStats for mail.google.com:80.
202 base::DictionaryValue* stats1 = new base::DictionaryValue; 190 base::DictionaryValue* stats1 = new base::DictionaryValue;
203 stats1->SetInteger("srtt", 20); 191 stats1->SetInteger("srtt", 20);
204 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); 192 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1);
205 // Set the server preference for mail.google.com:80. 193 // Set the server preference for mail.google.com:80.
206 servers_dict->SetWithoutPathExpansion("mail.google.com:80", 194 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
207 server_pref_dict1); 195 server_pref_dict1);
208 196
209 base::DictionaryValue* http_server_properties_dict = 197 base::DictionaryValue* http_server_properties_dict =
210 new base::DictionaryValue; 198 new base::DictionaryValue;
211 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 199 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
212 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 200 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
201 base::DictionaryValue* supports_quic = new base::DictionaryValue;
202 supports_quic->SetBoolean("used_quic", true);
203 supports_quic->SetString("address", "127.0.0.1");
204 http_server_properties_dict->SetWithoutPathExpansion("supports_quic",
205 supports_quic);
213 206
214 // Set the same value for kHttpServerProperties multiple times. 207 // Set the same value for kHttpServerProperties multiple times.
215 pref_service_.SetManagedPref(kTestHttpServerProperties, 208 pref_service_.SetManagedPref(kTestHttpServerProperties,
216 http_server_properties_dict); 209 http_server_properties_dict);
217 base::DictionaryValue* http_server_properties_dict2 = 210 base::DictionaryValue* http_server_properties_dict2 =
218 http_server_properties_dict->DeepCopy(); 211 http_server_properties_dict->DeepCopy();
219 pref_service_.SetManagedPref(kTestHttpServerProperties, 212 pref_service_.SetManagedPref(kTestHttpServerProperties,
220 http_server_properties_dict2); 213 http_server_properties_dict2);
221 214
222 base::RunLoop().RunUntilIdle(); 215 base::RunLoop().RunUntilIdle();
(...skipping 12 matching lines...) Expand all
235 AlternateProtocolInfo port_alternate_protocol = 228 AlternateProtocolInfo port_alternate_protocol =
236 http_server_props_manager_->GetAlternateProtocol(google_server); 229 http_server_props_manager_->GetAlternateProtocol(google_server);
237 EXPECT_EQ(443, port_alternate_protocol.port); 230 EXPECT_EQ(443, port_alternate_protocol.port);
238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); 231 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
239 port_alternate_protocol = 232 port_alternate_protocol =
240 http_server_props_manager_->GetAlternateProtocol(mail_server); 233 http_server_props_manager_->GetAlternateProtocol(mail_server);
241 EXPECT_EQ(444, port_alternate_protocol.port); 234 EXPECT_EQ(444, port_alternate_protocol.port);
242 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); 235 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol);
243 236
244 // Verify SupportsQuic. 237 // Verify SupportsQuic.
245 SupportsQuic supports_quic2 = 238 IPAddressNumber last_address;
246 http_server_props_manager_->GetSupportsQuic(google_server); 239 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address));
247 EXPECT_TRUE(supports_quic2.used_quic); 240 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address));
248 EXPECT_EQ("foo", supports_quic2.address);
249 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server);
250 EXPECT_FALSE(supports_quic2.used_quic);
251 EXPECT_EQ("bar", supports_quic2.address);
252 241
253 // Verify ServerNetworkStats. 242 // Verify ServerNetworkStats.
254 const ServerNetworkStats* stats2 = 243 const ServerNetworkStats* stats2 =
255 http_server_props_manager_->GetServerNetworkStats(google_server); 244 http_server_props_manager_->GetServerNetworkStats(google_server);
256 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 245 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
257 const ServerNetworkStats* stats3 = 246 const ServerNetworkStats* stats3 =
258 http_server_props_manager_->GetServerNetworkStats(mail_server); 247 http_server_props_manager_->GetServerNetworkStats(mail_server);
259 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); 248 EXPECT_EQ(20, stats3->srtt.ToInternalValue());
260 } 249 }
261 250
262 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { 251 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
263 ExpectCacheUpdate(); 252 ExpectCacheUpdate();
264 // The prefs are automaticalls updated in the case corruption is detected. 253 // The prefs are automaticalls updated in the case corruption is detected.
265 ExpectPrefsUpdate(); 254 ExpectPrefsUpdate();
266 255
267 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 256 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
268 257
269 // Set supports_spdy for www.google.com:65536. 258 // Set supports_spdy for www.google.com:65536.
270 server_pref_dict->SetBoolean("supports_spdy", true); 259 server_pref_dict->SetBoolean("supports_spdy", true);
271 260
272 // Set up alternate_protocol for www.google.com:65536. 261 // Set up alternate_protocol for www.google.com:65536.
273 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; 262 base::DictionaryValue* alternate_protocol = new base::DictionaryValue;
274 alternate_protocol->SetInteger("port", 80); 263 alternate_protocol->SetInteger("port", 80);
275 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); 264 alternate_protocol->SetString("protocol_str", "npn-spdy/3");
276 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", 265 server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
277 alternate_protocol); 266 alternate_protocol);
278 267
279 // Set up SupportsQuic for www.google.com:65536.
280 base::DictionaryValue* supports_quic = new base::DictionaryValue;
281 supports_quic->SetBoolean("used_quic", true);
282 supports_quic->SetString("address", "foo");
283 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic);
284
285 // Set up ServerNetworkStats for www.google.com:65536. 268 // Set up ServerNetworkStats for www.google.com:65536.
286 base::DictionaryValue* stats = new base::DictionaryValue; 269 base::DictionaryValue* stats = new base::DictionaryValue;
287 stats->SetInteger("srtt", 10); 270 stats->SetInteger("srtt", 10);
288 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 271 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
289 272
290 // Set the server preference for www.google.com:65536. 273 // Set the server preference for www.google.com:65536.
291 base::DictionaryValue* servers_dict = new base::DictionaryValue; 274 base::DictionaryValue* servers_dict = new base::DictionaryValue;
292 servers_dict->SetWithoutPathExpansion("www.google.com:65536", 275 servers_dict->SetWithoutPathExpansion("www.google.com:65536",
293 server_pref_dict); 276 server_pref_dict);
294 277
295 base::DictionaryValue* http_server_properties_dict = 278 base::DictionaryValue* http_server_properties_dict =
296 new base::DictionaryValue; 279 new base::DictionaryValue;
297 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 280 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
298 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 281 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
299 282
300 // Set up the pref. 283 // Set up the pref.
301 pref_service_.SetManagedPref(kTestHttpServerProperties, 284 pref_service_.SetManagedPref(kTestHttpServerProperties,
302 http_server_properties_dict); 285 http_server_properties_dict);
303 286
304 base::RunLoop().RunUntilIdle(); 287 base::RunLoop().RunUntilIdle();
305 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 288 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
306 289
307 // Verify that nothing is set. 290 // Verify that nothing is set.
308 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 291 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
309 HostPortPair::FromString("www.google.com:65536"))); 292 HostPortPair::FromString("www.google.com:65536")));
310 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( 293 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol(
311 HostPortPair::FromString("www.google.com:65536"))); 294 HostPortPair::FromString("www.google.com:65536")));
312 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic(
313 HostPortPair::FromString("www.google.com:65536"));
314 EXPECT_FALSE(supports_quic2.used_quic);
315 const ServerNetworkStats* stats1 = 295 const ServerNetworkStats* stats1 =
316 http_server_props_manager_->GetServerNetworkStats( 296 http_server_props_manager_->GetServerNetworkStats(
317 HostPortPair::FromString("www.google.com:65536")); 297 HostPortPair::FromString("www.google.com:65536"));
318 EXPECT_EQ(NULL, stats1); 298 EXPECT_EQ(NULL, stats1);
319 } 299 }
320 300
321 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { 301 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
322 ExpectCacheUpdate(); 302 ExpectCacheUpdate();
323 // The prefs are automaticalls updated in the case corruption is detected. 303 // The prefs are automaticalls updated in the case corruption is detected.
324 ExpectPrefsUpdate(); 304 ExpectPrefsUpdate();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 474 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
495 AlternateProtocolInfo port_alternate_protocol = 475 AlternateProtocolInfo port_alternate_protocol =
496 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); 476 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail);
497 EXPECT_EQ(443, port_alternate_protocol.port); 477 EXPECT_EQ(443, port_alternate_protocol.port);
498 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); 478 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
499 } 479 }
500 480
501 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { 481 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) {
502 ExpectPrefsUpdate(); 482 ExpectPrefsUpdate();
503 483
504 HostPortPair quic_server_mail("mail.google.com", 80); 484 IPAddressNumber address;
505 SupportsQuic supports_quic = 485 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
506 http_server_props_manager_->GetSupportsQuic(quic_server_mail); 486
507 EXPECT_FALSE(supports_quic.used_quic); 487 IPAddressNumber actual_address;
508 EXPECT_EQ("", supports_quic.address); 488 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
509 http_server_props_manager_->SetSupportsQuic(quic_server_mail, true, "foo"); 489 http_server_props_manager_->SetSupportsQuic(true, actual_address);
510 490
511 // Run the task. 491 // Run the task.
512 base::RunLoop().RunUntilIdle(); 492 base::RunLoop().RunUntilIdle();
513 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 493 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
514 494
515 SupportsQuic supports_quic1 = 495 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
516 http_server_props_manager_->GetSupportsQuic(quic_server_mail); 496 EXPECT_EQ(actual_address, address);
517 EXPECT_TRUE(supports_quic1.used_quic);
518 EXPECT_EQ("foo", supports_quic1.address);
519 } 497 }
520 498
521 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { 499 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) {
522 ExpectPrefsUpdate(); 500 ExpectPrefsUpdate();
523 501
524 HostPortPair mail_server("mail.google.com", 80); 502 HostPortPair mail_server("mail.google.com", 80);
525 const ServerNetworkStats* stats = 503 const ServerNetworkStats* stats =
526 http_server_props_manager_->GetServerNetworkStats(mail_server); 504 http_server_props_manager_->GetServerNetworkStats(mail_server);
527 EXPECT_EQ(NULL, stats); 505 EXPECT_EQ(NULL, stats);
528 ServerNetworkStats stats1; 506 ServerNetworkStats stats1;
529 stats1.srtt = base::TimeDelta::FromMicroseconds(10); 507 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
530 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); 508 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1);
531 509
532 // Run the task. 510 // Run the task.
533 base::RunLoop().RunUntilIdle(); 511 base::RunLoop().RunUntilIdle();
534 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 512 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
535 513
536 const ServerNetworkStats* stats2 = 514 const ServerNetworkStats* stats2 =
537 http_server_props_manager_->GetServerNetworkStats(mail_server); 515 http_server_props_manager_->GetServerNetworkStats(mail_server);
538 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 516 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
539 } 517 }
540 518
541 TEST_F(HttpServerPropertiesManagerTest, Clear) { 519 TEST_F(HttpServerPropertiesManagerTest, Clear) {
542 ExpectPrefsUpdate(); 520 ExpectPrefsUpdate();
543 521
544 HostPortPair spdy_server_mail("mail.google.com", 443); 522 HostPortPair spdy_server_mail("mail.google.com", 443);
545 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 523 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
546 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, 524 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443,
547 NPN_SPDY_3, 1.0); 525 NPN_SPDY_3, 1.0);
548 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); 526 IPAddressNumber actual_address;
527 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
528 http_server_props_manager_->SetSupportsQuic(true, actual_address);
549 ServerNetworkStats stats; 529 ServerNetworkStats stats;
550 stats.srtt = base::TimeDelta::FromMicroseconds(10); 530 stats.srtt = base::TimeDelta::FromMicroseconds(10);
551 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); 531 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats);
552 532
553 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 533 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
554 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 534 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
555 const uint32 value1 = 31337; 535 const uint32 value1 = 31337;
556 http_server_props_manager_->SetSpdySetting( 536 http_server_props_manager_->SetSpdySetting(
557 spdy_server_mail, id1, flags1, value1); 537 spdy_server_mail, id1, flags1, value1);
558 538
559 // Run the task. 539 // Run the task.
560 base::RunLoop().RunUntilIdle(); 540 base::RunLoop().RunUntilIdle();
561 541
562 EXPECT_TRUE( 542 EXPECT_TRUE(
563 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); 543 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
564 EXPECT_TRUE( 544 EXPECT_TRUE(
565 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 545 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
566 SupportsQuic supports_quic = 546 IPAddressNumber address;
567 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); 547 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
568 EXPECT_TRUE(supports_quic.used_quic); 548 EXPECT_EQ(actual_address, address);
569 EXPECT_EQ("foo", supports_quic.address);
570 const ServerNetworkStats* stats1 = 549 const ServerNetworkStats* stats1 =
571 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 550 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
572 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); 551 EXPECT_EQ(10, stats1->srtt.ToInternalValue());
573 552
574 // Check SPDY settings values. 553 // Check SPDY settings values.
575 const SettingsMap& settings_map1_ret = 554 const SettingsMap& settings_map1_ret =
576 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 555 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
577 ASSERT_EQ(1U, settings_map1_ret.size()); 556 ASSERT_EQ(1U, settings_map1_ret.size());
578 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 557 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
579 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 558 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
580 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 559 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
581 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 560 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
582 EXPECT_EQ(value1, flags_and_value1_ret.second); 561 EXPECT_EQ(value1, flags_and_value1_ret.second);
583 562
584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 563 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
585 564
586 ExpectPrefsUpdate(); 565 ExpectPrefsUpdate();
587 566
588 // Clear http server data, time out if we do not get a completion callback. 567 // Clear http server data, time out if we do not get a completion callback.
589 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); 568 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure());
590 base::RunLoop().Run(); 569 base::RunLoop().Run();
591 570
592 EXPECT_FALSE( 571 EXPECT_FALSE(
593 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); 572 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
594 EXPECT_FALSE( 573 EXPECT_FALSE(
595 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 574 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
596 SupportsQuic supports_quic1 = 575 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
597 http_server_props_manager_->GetSupportsQuic(spdy_server_mail);
598 EXPECT_FALSE(supports_quic1.used_quic);
599 EXPECT_EQ("", supports_quic1.address);
600 const ServerNetworkStats* stats2 = 576 const ServerNetworkStats* stats2 =
601 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 577 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
602 EXPECT_EQ(NULL, stats2); 578 EXPECT_EQ(NULL, stats2);
603 579
604 const SettingsMap& settings_map2_ret = 580 const SettingsMap& settings_map2_ret =
605 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 581 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
606 EXPECT_EQ(0U, settings_map2_ret.size()); 582 EXPECT_EQ(0U, settings_map2_ret.size());
607 583
608 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
609 } 585 }
(...skipping 12 matching lines...) Expand all
622 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); 598 alternate_protocol->SetString("protocol_str", "npn-spdy/3");
623 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 599 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
624 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", 600 server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
625 alternate_protocol); 601 alternate_protocol);
626 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), 602 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i),
627 server_pref_dict); 603 server_pref_dict);
628 } 604 }
629 605
630 // Set the preference for mail.google.com server. 606 // Set the preference for mail.google.com server.
631 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 607 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
632 // Set up SupportsQuic for mail.google.com:80
633 base::DictionaryValue* supports_quic = new base::DictionaryValue;
634 supports_quic->SetBoolean("used_quic", true);
635 supports_quic->SetString("address", "bar");
636 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic);
637 608
638 // Set the server preference for mail.google.com:80. 609 // Set the server preference for mail.google.com:80.
639 servers_dict->SetWithoutPathExpansion("mail.google.com:80", 610 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
640 server_pref_dict1); 611 server_pref_dict1);
641 612
642 base::DictionaryValue* http_server_properties_dict = 613 base::DictionaryValue* http_server_properties_dict =
643 new base::DictionaryValue; 614 new base::DictionaryValue;
644 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 615 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
645 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 616 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
646 617
618 // Set up SupportsQuic for 127.0.0.1
619 base::DictionaryValue* supports_quic = new base::DictionaryValue;
620 supports_quic->SetBoolean("used_quic", true);
621 supports_quic->SetString("address", "127.0.0.1");
622 http_server_properties_dict->SetWithoutPathExpansion("supports_quic",
623 supports_quic);
624
647 // Set up the pref. 625 // Set up the pref.
648 pref_service_.SetManagedPref(kTestHttpServerProperties, 626 pref_service_.SetManagedPref(kTestHttpServerProperties,
649 http_server_properties_dict); 627 http_server_properties_dict);
650 628
651 base::RunLoop().RunUntilIdle(); 629 base::RunLoop().RunUntilIdle();
652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 630 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
653 631
654 // Verify AlternateProtocol. 632 // Verify AlternateProtocol.
655 for (int i = 0; i < 200; ++i) { 633 for (int i = 0; i < 200; ++i) {
656 std::string server = StringPrintf("www.google.com:%d", i); 634 std::string server = StringPrintf("www.google.com:%d", i);
657 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( 635 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
658 HostPortPair::FromString(server))); 636 HostPortPair::FromString(server)));
659 AlternateProtocolInfo port_alternate_protocol = 637 AlternateProtocolInfo port_alternate_protocol =
660 http_server_props_manager_->GetAlternateProtocol( 638 http_server_props_manager_->GetAlternateProtocol(
661 HostPortPair::FromString(server)); 639 HostPortPair::FromString(server));
662 EXPECT_EQ(i, port_alternate_protocol.port); 640 EXPECT_EQ(i, port_alternate_protocol.port);
663 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); 641 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
664 } 642 }
665 643
666 // Verify SupportsQuic. 644 // Verify SupportsQuic.
667 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( 645 IPAddressNumber address;
668 HostPortPair::FromString("mail.google.com:80")); 646 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
669 EXPECT_TRUE(supports_quic1.used_quic); 647 EXPECT_EQ("127.0.0.1", IPAddressToString(address));
670 EXPECT_EQ("bar", supports_quic1.address);
671 } 648 }
672 649
673 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { 650 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) {
674 // Post an update task to the UI thread. 651 // Post an update task to the UI thread.
675 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 652 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
676 // Shutdown comes before the task is executed. 653 // Shutdown comes before the task is executed.
677 http_server_props_manager_->ShutdownOnPrefThread(); 654 http_server_props_manager_->ShutdownOnPrefThread();
678 http_server_props_manager_.reset(); 655 http_server_props_manager_.reset();
679 // Run the task after shutdown and deletion. 656 // Run the task after shutdown and deletion.
680 base::RunLoop().RunUntilIdle(); 657 base::RunLoop().RunUntilIdle();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 // Run the task after shutdown, but before deletion. 715 // Run the task after shutdown, but before deletion.
739 base::RunLoop().RunUntilIdle(); 716 base::RunLoop().RunUntilIdle();
740 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 717 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
741 http_server_props_manager_.reset(); 718 http_server_props_manager_.reset();
742 base::RunLoop().RunUntilIdle(); 719 base::RunLoop().RunUntilIdle();
743 } 720 }
744 721
745 } // namespace 722 } // namespace
746 723
747 } // namespace net 724 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698