OLD | NEW |
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set | 149 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set |
150 // it twice. Only expect a single cache update. | 150 // it twice. Only expect a single cache update. |
151 | 151 |
152 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 152 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
153 HostPortPair google_server("www.google.com", 80); | 153 HostPortPair google_server("www.google.com", 80); |
154 HostPortPair mail_server("mail.google.com", 80); | 154 HostPortPair mail_server("mail.google.com", 80); |
155 | 155 |
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 alternative_services 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 base::ListValue* alternative_services = new base::ListValue; |
164 alternate_protocol); | 164 alternative_services->Append(alternate_protocol); |
| 165 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 166 alternative_services); |
165 | 167 |
166 // Set up SupportsQuic for www.google.com:80. | 168 // Set up SupportsQuic for www.google.com:80. |
167 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 169 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
168 supports_quic->SetBoolean("used_quic", true); | 170 supports_quic->SetBoolean("used_quic", true); |
169 supports_quic->SetString("address", "foo"); | 171 supports_quic->SetString("address", "foo"); |
170 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); | 172 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); |
171 | 173 |
172 // Set up ServerNetworkStats for www.google.com:80. | 174 // Set up ServerNetworkStats for www.google.com:80. |
173 base::DictionaryValue* stats = new base::DictionaryValue; | 175 base::DictionaryValue* stats = new base::DictionaryValue; |
174 stats->SetInteger("srtt", 10); | 176 stats->SetInteger("srtt", 10); |
175 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 177 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
176 | 178 |
177 // Set the server preference for www.google.com:80. | 179 // Set the server preference for www.google.com:80. |
178 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 180 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
179 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 181 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
180 | 182 |
181 // Set the preference for mail.google.com server. | 183 // Set the preference for mail.google.com server. |
182 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 184 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
183 | 185 |
184 // Set supports_spdy for mail.google.com:80 | 186 // Set supports_spdy for mail.google.com:80 |
185 server_pref_dict1->SetBoolean("supports_spdy", true); | 187 server_pref_dict1->SetBoolean("supports_spdy", true); |
186 | 188 |
187 // Set up alternate_protocol for mail.google.com:80 | 189 // Set up alternative_services for mail.google.com:80 |
188 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 190 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
189 alternate_protocol1->SetInteger("port", 444); | 191 alternate_protocol1->SetInteger("port", 444); |
190 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); | 192 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); |
191 | 193 base::ListValue* alternative_services1 = new base::ListValue; |
192 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", | 194 alternative_services1->Append(alternate_protocol1); |
193 alternate_protocol1); | 195 server_pref_dict1->SetWithoutPathExpansion("alternative_services", |
| 196 alternative_services1); |
194 | 197 |
195 // Set up SupportsQuic for mail.google.com:80 | 198 // Set up SupportsQuic for mail.google.com:80 |
196 base::DictionaryValue* supports_quic1 = new base::DictionaryValue; | 199 base::DictionaryValue* supports_quic1 = new base::DictionaryValue; |
197 supports_quic1->SetBoolean("used_quic", false); | 200 supports_quic1->SetBoolean("used_quic", false); |
198 supports_quic1->SetString("address", "bar"); | 201 supports_quic1->SetString("address", "bar"); |
199 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1); | 202 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1); |
200 | 203 |
201 // Set up ServerNetworkStats for mail.google.com:80. | 204 // Set up ServerNetworkStats for mail.google.com:80. |
202 base::DictionaryValue* stats1 = new base::DictionaryValue; | 205 base::DictionaryValue* stats1 = new base::DictionaryValue; |
203 stats1->SetInteger("srtt", 20); | 206 stats1->SetInteger("srtt", 20); |
(...skipping 20 matching lines...) Expand all Loading... |
224 | 227 |
225 // Verify SupportsSpdy. | 228 // Verify SupportsSpdy. |
226 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); | 229 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); |
227 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); | 230 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); |
228 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( | 231 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( |
229 HostPortPair::FromString("foo.google.com:1337"))); | 232 HostPortPair::FromString("foo.google.com:1337"))); |
230 | 233 |
231 // Verify AlternateProtocol. | 234 // Verify AlternateProtocol. |
232 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); | 235 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); |
233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); | 236 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); |
234 AlternateProtocolInfo port_alternate_protocol = | 237 AlternateProtocols port_alternate_protocols = |
235 http_server_props_manager_->GetAlternateProtocol(google_server); | 238 http_server_props_manager_->GetAlternateProtocols(google_server); |
236 EXPECT_EQ(443, port_alternate_protocol.port); | 239 ASSERT_EQ(1u, port_alternate_protocols.size()); |
237 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 240 EXPECT_EQ(443, port_alternate_protocols[0].port); |
238 port_alternate_protocol = | 241 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocols[0].protocol); |
239 http_server_props_manager_->GetAlternateProtocol(mail_server); | 242 port_alternate_protocols = |
240 EXPECT_EQ(444, port_alternate_protocol.port); | 243 http_server_props_manager_->GetAlternateProtocols(mail_server); |
241 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); | 244 ASSERT_EQ(1u, port_alternate_protocols.size()); |
| 245 EXPECT_EQ(444, port_alternate_protocols[0].port); |
| 246 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocols[0].protocol); |
242 | 247 |
243 // Verify SupportsQuic. | 248 // Verify SupportsQuic. |
244 SupportsQuic supports_quic2 = | 249 SupportsQuic supports_quic2 = |
245 http_server_props_manager_->GetSupportsQuic(google_server); | 250 http_server_props_manager_->GetSupportsQuic(google_server); |
246 EXPECT_TRUE(supports_quic2.used_quic); | 251 EXPECT_TRUE(supports_quic2.used_quic); |
247 EXPECT_EQ("foo", supports_quic2.address); | 252 EXPECT_EQ("foo", supports_quic2.address); |
248 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server); | 253 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server); |
249 EXPECT_FALSE(supports_quic2.used_quic); | 254 EXPECT_FALSE(supports_quic2.used_quic); |
250 EXPECT_EQ("bar", supports_quic2.address); | 255 EXPECT_EQ("bar", supports_quic2.address); |
251 | 256 |
252 // Verify ServerNetworkStats. | 257 // Verify ServerNetworkStats. |
253 const ServerNetworkStats* stats2 = | 258 const ServerNetworkStats* stats2 = |
254 http_server_props_manager_->GetServerNetworkStats(google_server); | 259 http_server_props_manager_->GetServerNetworkStats(google_server); |
255 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 260 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
256 const ServerNetworkStats* stats3 = | 261 const ServerNetworkStats* stats3 = |
257 http_server_props_manager_->GetServerNetworkStats(mail_server); | 262 http_server_props_manager_->GetServerNetworkStats(mail_server); |
258 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); | 263 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
259 } | 264 } |
260 | 265 |
261 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 266 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
262 ExpectCacheUpdate(); | 267 ExpectCacheUpdate(); |
263 // The prefs are automaticalls updated in the case corruption is detected. | 268 // The prefs are automaticalls updated in the case corruption is detected. |
264 ExpectPrefsUpdate(); | 269 ExpectPrefsUpdate(); |
265 | 270 |
266 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 271 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
267 | 272 |
268 // Set supports_spdy for www.google.com:65536. | 273 // Set supports_spdy for www.google.com:65536. |
269 server_pref_dict->SetBoolean("supports_spdy", true); | 274 server_pref_dict->SetBoolean("supports_spdy", true); |
270 | 275 |
271 // Set up alternate_protocol for www.google.com:65536. | 276 // Set up alternative_services for www.google.com:65536. |
272 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 277 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
273 alternate_protocol->SetInteger("port", 80); | 278 alternate_protocol->SetInteger("port", 80); |
274 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 279 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
275 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 280 base::ListValue* alternative_services = new base::ListValue; |
276 alternate_protocol); | 281 alternative_services->Append(alternate_protocol); |
| 282 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 283 alternative_services); |
277 | 284 |
278 // Set up SupportsQuic for www.google.com:65536. | 285 // Set up SupportsQuic for www.google.com:65536. |
279 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 286 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
280 supports_quic->SetBoolean("used_quic", true); | 287 supports_quic->SetBoolean("used_quic", true); |
281 supports_quic->SetString("address", "foo"); | 288 supports_quic->SetString("address", "foo"); |
282 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); | 289 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); |
283 | 290 |
284 // Set up ServerNetworkStats for www.google.com:65536. | 291 // Set up ServerNetworkStats for www.google.com:65536. |
285 base::DictionaryValue* stats = new base::DictionaryValue; | 292 base::DictionaryValue* stats = new base::DictionaryValue; |
286 stats->SetInteger("srtt", 10); | 293 stats->SetInteger("srtt", 10); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 327 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
321 ExpectCacheUpdate(); | 328 ExpectCacheUpdate(); |
322 // The prefs are automaticalls updated in the case corruption is detected. | 329 // The prefs are automaticalls updated in the case corruption is detected. |
323 ExpectPrefsUpdate(); | 330 ExpectPrefsUpdate(); |
324 | 331 |
325 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 332 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
326 | 333 |
327 // Set supports_spdy for www.google.com:80. | 334 // Set supports_spdy for www.google.com:80. |
328 server_pref_dict->SetBoolean("supports_spdy", true); | 335 server_pref_dict->SetBoolean("supports_spdy", true); |
329 | 336 |
330 // Set up alternate_protocol for www.google.com:80. | 337 // Set up alternative_services for www.google.com:80. |
331 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 338 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
332 alternate_protocol->SetInteger("port", 65536); | 339 alternate_protocol->SetInteger("port", 65536); |
333 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 340 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
334 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 341 base::ListValue* alternative_services = new base::ListValue; |
335 alternate_protocol); | 342 alternative_services->Append(alternate_protocol); |
| 343 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 344 alternative_services); |
336 | 345 |
337 // Set the server preference for www.google.com:80. | 346 // Set the server preference for www.google.com:80. |
338 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 347 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
339 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 348 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
340 | 349 |
341 base::DictionaryValue* http_server_properties_dict = | 350 base::DictionaryValue* http_server_properties_dict = |
342 new base::DictionaryValue; | 351 new base::DictionaryValue; |
343 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 352 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
344 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 353 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
345 | 354 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 482 |
474 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 483 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
475 } | 484 } |
476 | 485 |
477 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { | 486 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { |
478 ExpectPrefsUpdate(); | 487 ExpectPrefsUpdate(); |
479 | 488 |
480 HostPortPair spdy_server_mail("mail.google.com", 80); | 489 HostPortPair spdy_server_mail("mail.google.com", 80); |
481 EXPECT_FALSE( | 490 EXPECT_FALSE( |
482 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 491 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
483 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 492 http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
484 NPN_SPDY_3, 1); | 493 NPN_SPDY_3, 1); |
485 | 494 |
486 // Run the task. | 495 // Run the task. |
487 base::RunLoop().RunUntilIdle(); | 496 base::RunLoop().RunUntilIdle(); |
488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 497 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
489 | 498 |
490 ASSERT_TRUE( | 499 ASSERT_TRUE( |
491 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 500 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
492 AlternateProtocolInfo port_alternate_protocol = | 501 AlternateProtocols port_alternate_protocols = |
493 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 502 http_server_props_manager_->GetAlternateProtocols(spdy_server_mail); |
494 EXPECT_EQ(443, port_alternate_protocol.port); | 503 ASSERT_EQ(1u, port_alternate_protocols.size()); |
495 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 504 EXPECT_EQ(443, port_alternate_protocols[0].port); |
| 505 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocols[0].protocol); |
496 } | 506 } |
497 | 507 |
498 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 508 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
499 ExpectPrefsUpdate(); | 509 ExpectPrefsUpdate(); |
500 | 510 |
501 HostPortPair quic_server_mail("mail.google.com", 80); | 511 HostPortPair quic_server_mail("mail.google.com", 80); |
502 SupportsQuic supports_quic = | 512 SupportsQuic supports_quic = |
503 http_server_props_manager_->GetSupportsQuic(quic_server_mail); | 513 http_server_props_manager_->GetSupportsQuic(quic_server_mail); |
504 EXPECT_FALSE(supports_quic.used_quic); | 514 EXPECT_FALSE(supports_quic.used_quic); |
505 EXPECT_EQ("", supports_quic.address); | 515 EXPECT_EQ("", supports_quic.address); |
(...skipping 27 matching lines...) Expand all Loading... |
533 const ServerNetworkStats* stats2 = | 543 const ServerNetworkStats* stats2 = |
534 http_server_props_manager_->GetServerNetworkStats(mail_server); | 544 http_server_props_manager_->GetServerNetworkStats(mail_server); |
535 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 545 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
536 } | 546 } |
537 | 547 |
538 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 548 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
539 ExpectPrefsUpdate(); | 549 ExpectPrefsUpdate(); |
540 | 550 |
541 HostPortPair spdy_server_mail("mail.google.com", 443); | 551 HostPortPair spdy_server_mail("mail.google.com", 443); |
542 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 552 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
543 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 553 http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
544 NPN_SPDY_3, 1); | 554 NPN_SPDY_3, 1); |
545 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); | 555 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); |
546 ServerNetworkStats stats; | 556 ServerNetworkStats stats; |
547 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 557 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
548 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 558 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
549 | 559 |
550 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 560 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
551 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 561 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
552 const uint32 value1 = 31337; | 562 const uint32 value1 = 31337; |
553 http_server_props_manager_->SetSpdySetting( | 563 http_server_props_manager_->SetSpdySetting( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 606 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
597 EXPECT_EQ(NULL, stats2); | 607 EXPECT_EQ(NULL, stats2); |
598 | 608 |
599 const SettingsMap& settings_map2_ret = | 609 const SettingsMap& settings_map2_ret = |
600 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 610 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
601 EXPECT_EQ(0U, settings_map2_ret.size()); | 611 EXPECT_EQ(0U, settings_map2_ret.size()); |
602 | 612 |
603 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 613 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
604 } | 614 } |
605 | 615 |
606 // crbug.com/444956: Add 200 alternate_protocol servers followed by | 616 // https://crbug.com/444956: Add 200 alternate_protocol servers followed by |
607 // supports_quic and verify we have read supports_quic from prefs. | 617 // supports_quic and verify we have read supports_quic from prefs. |
608 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 618 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
609 ExpectCacheUpdate(); | 619 ExpectCacheUpdate(); |
610 | 620 |
611 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 621 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
612 | 622 |
613 for (int i = 0; i < 200; ++i) { | 623 for (int i = 0; i < 200; ++i) { |
614 // Set up alternate_protocol for www.google.com:i. | 624 // Set up alternate_protocol for www.google.com:i. |
615 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 625 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
616 alternate_protocol->SetInteger("port", i); | 626 alternate_protocol->SetInteger("port", i); |
617 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 627 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 628 base::ListValue* alternative_services = new base::ListValue; |
| 629 alternative_services->Append(alternate_protocol); |
618 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 630 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
619 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 631 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
620 alternate_protocol); | 632 alternative_services); |
621 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), | 633 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), |
622 server_pref_dict); | 634 server_pref_dict); |
623 } | 635 } |
624 | 636 |
625 // Set the preference for mail.google.com server. | 637 // Set the preference for mail.google.com server. |
626 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 638 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
627 // Set up SupportsQuic for mail.google.com:80 | 639 // Set up SupportsQuic for mail.google.com:80 |
628 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 640 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
629 supports_quic->SetBoolean("used_quic", true); | 641 supports_quic->SetBoolean("used_quic", true); |
630 supports_quic->SetString("address", "bar"); | 642 supports_quic->SetString("address", "bar"); |
(...skipping 12 matching lines...) Expand all Loading... |
643 pref_service_.SetManagedPref(kTestHttpServerProperties, | 655 pref_service_.SetManagedPref(kTestHttpServerProperties, |
644 http_server_properties_dict); | 656 http_server_properties_dict); |
645 | 657 |
646 base::RunLoop().RunUntilIdle(); | 658 base::RunLoop().RunUntilIdle(); |
647 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 659 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
648 | 660 |
649 // Verify AlternateProtocol. | 661 // Verify AlternateProtocol. |
650 for (int i = 0; i < 200; ++i) { | 662 for (int i = 0; i < 200; ++i) { |
651 std::string server = StringPrintf("www.google.com:%d", i); | 663 std::string server = StringPrintf("www.google.com:%d", i); |
652 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | 664 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( |
653 net::HostPortPair::FromString(server))); | 665 HostPortPair::FromString(server))); |
654 net::AlternateProtocolInfo port_alternate_protocol = | 666 AlternateProtocols port_alternate_protocols = |
655 http_server_props_manager_->GetAlternateProtocol( | 667 http_server_props_manager_->GetAlternateProtocols( |
656 net::HostPortPair::FromString(server)); | 668 HostPortPair::FromString(server)); |
657 EXPECT_EQ(i, port_alternate_protocol.port); | 669 EXPECT_EQ(1u, port_alternate_protocols.size()); |
658 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 670 EXPECT_EQ(i, port_alternate_protocols[0].port); |
| 671 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocols[0].protocol); |
659 } | 672 } |
660 | 673 |
661 // Verify SupportsQuic. | 674 // Verify SupportsQuic. |
662 net::SupportsQuic supports_quic1 = | 675 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( |
663 http_server_props_manager_->GetSupportsQuic( | 676 HostPortPair::FromString("mail.google.com:80")); |
664 net::HostPortPair::FromString("mail.google.com:80")); | |
665 EXPECT_TRUE(supports_quic1.used_quic); | 677 EXPECT_TRUE(supports_quic1.used_quic); |
666 EXPECT_EQ("bar", supports_quic1.address); | 678 EXPECT_EQ("bar", supports_quic1.address); |
667 } | 679 } |
668 | 680 |
669 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 681 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
670 // Post an update task to the UI thread. | 682 // Post an update task to the UI thread. |
671 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 683 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
672 // Shutdown comes before the task is executed. | 684 // Shutdown comes before the task is executed. |
673 http_server_props_manager_->ShutdownOnPrefThread(); | 685 http_server_props_manager_->ShutdownOnPrefThread(); |
674 http_server_props_manager_.reset(); | 686 http_server_props_manager_.reset(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 // Run the task after shutdown, but before deletion. | 746 // Run the task after shutdown, but before deletion. |
735 base::RunLoop().RunUntilIdle(); | 747 base::RunLoop().RunUntilIdle(); |
736 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 748 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
737 http_server_props_manager_.reset(); | 749 http_server_props_manager_.reset(); |
738 base::RunLoop().RunUntilIdle(); | 750 base::RunLoop().RunUntilIdle(); |
739 } | 751 } |
740 | 752 |
741 } // namespace | 753 } // namespace |
742 | 754 |
743 } // namespace net | 755 } // namespace net |
OLD | NEW |