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/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 void ExpectPrefsUpdateRepeatedly() { | 129 void ExpectPrefsUpdateRepeatedly() { |
130 EXPECT_CALL(*http_server_props_manager_, | 130 EXPECT_CALL(*http_server_props_manager_, |
131 UpdatePrefsFromCacheOnNetworkThread(_)) | 131 UpdatePrefsFromCacheOnNetworkThread(_)) |
132 .WillRepeatedly( | 132 .WillRepeatedly( |
133 Invoke(http_server_props_manager_.get(), | 133 Invoke(http_server_props_manager_.get(), |
134 &TestingHttpServerPropertiesManager:: | 134 &TestingHttpServerPropertiesManager:: |
135 UpdatePrefsFromCacheOnNetworkThreadConcrete)); | 135 UpdatePrefsFromCacheOnNetworkThreadConcrete)); |
136 } | 136 } |
137 | 137 |
138 bool HasAlternateProtocol(const HostPortPair& server) { | 138 bool HasAlternateProtocol(const HostPortPair& server) { |
139 const AlternateProtocolInfo alternate = | 139 const AlternateProtocols alternates = |
140 http_server_props_manager_->GetAlternateProtocol(server); | 140 http_server_props_manager_->GetAlternateProtocols(server); |
141 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; | 141 return !alternates.empty(); |
142 } | 142 } |
143 | 143 |
144 //base::RunLoop loop_; | 144 //base::RunLoop loop_; |
145 TestingPrefServiceSimple pref_service_; | 145 TestingPrefServiceSimple pref_service_; |
146 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; | 146 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; |
147 | 147 |
148 private: | 148 private: |
149 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); | 149 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); |
150 }; | 150 }; |
151 | 151 |
152 TEST_F(HttpServerPropertiesManagerTest, | 152 TEST_F(HttpServerPropertiesManagerTest, |
153 SingleUpdateForTwoSpdyServerPrefChanges) { | 153 SingleUpdateForTwoSpdyServerPrefChanges) { |
154 ExpectCacheUpdate(); | 154 ExpectCacheUpdate(); |
155 | 155 |
156 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set | 156 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set |
157 // it twice. Only expect a single cache update. | 157 // it twice. Only expect a single cache update. |
158 | 158 |
159 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 159 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
160 HostPortPair google_server("www.google.com", 80); | 160 HostPortPair google_server("www.google.com", 80); |
161 HostPortPair mail_server("mail.google.com", 80); | 161 HostPortPair mail_server("mail.google.com", 80); |
162 | 162 |
163 // Set supports_spdy for www.google.com:80. | 163 // Set supports_spdy for www.google.com:80. |
164 server_pref_dict->SetBoolean("supports_spdy", true); | 164 server_pref_dict->SetBoolean("supports_spdy", true); |
165 | 165 |
166 // Set up alternate_protocol for www.google.com:80. | 166 // Set up alternative_services for www.google.com:80. |
167 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 167 base::DictionaryValue* alternate_protocol0 = new base::DictionaryValue; |
168 alternate_protocol->SetInteger("port", 443); | 168 alternate_protocol0->SetInteger("port", 443); |
169 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 169 alternate_protocol0->SetString("protocol_str", "npn-spdy/3"); |
170 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 170 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
171 alternate_protocol); | 171 alternate_protocol1->SetInteger("port", 1234); |
| 172 alternate_protocol1->SetString("protocol_str", "quic"); |
| 173 base::ListValue* alternative_services = new base::ListValue; |
| 174 alternative_services->Append(alternate_protocol0); |
| 175 alternative_services->Append(alternate_protocol1); |
| 176 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 177 alternative_services); |
172 | 178 |
173 // Set up ServerNetworkStats for www.google.com:80. | 179 // Set up ServerNetworkStats for www.google.com:80. |
174 base::DictionaryValue* stats = new base::DictionaryValue; | 180 base::DictionaryValue* stats = new base::DictionaryValue; |
175 stats->SetInteger("srtt", 10); | 181 stats->SetInteger("srtt", 10); |
176 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 182 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
177 | 183 |
178 // Set the server preference for www.google.com:80. | 184 // Set the server preference for www.google.com:80. |
179 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 185 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
180 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 186 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
181 | 187 |
182 // Set the preference for mail.google.com server. | 188 // Set the preference for mail.google.com server. |
183 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 189 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
184 | 190 |
185 // Set supports_spdy for mail.google.com:80 | 191 // Set supports_spdy for mail.google.com:80 |
186 server_pref_dict1->SetBoolean("supports_spdy", true); | 192 server_pref_dict1->SetBoolean("supports_spdy", true); |
187 | 193 |
188 // Set up alternate_protocol for mail.google.com:80 | 194 // Set up alternative_services for mail.google.com:80 |
189 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 195 base::DictionaryValue* alternate_protocol2 = new base::DictionaryValue; |
190 alternate_protocol1->SetInteger("port", 444); | 196 alternate_protocol2->SetInteger("port", 444); |
191 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); | 197 alternate_protocol2->SetString("protocol_str", "npn-spdy/3.1"); |
192 | 198 base::ListValue* alternative_services1 = new base::ListValue; |
193 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", | 199 alternative_services1->Append(alternate_protocol2); |
194 alternate_protocol1); | 200 server_pref_dict1->SetWithoutPathExpansion("alternative_services", |
| 201 alternative_services1); |
195 | 202 |
196 // Set up ServerNetworkStats for mail.google.com:80. | 203 // Set up ServerNetworkStats for mail.google.com:80. |
197 base::DictionaryValue* stats1 = new base::DictionaryValue; | 204 base::DictionaryValue* stats1 = new base::DictionaryValue; |
198 stats1->SetInteger("srtt", 20); | 205 stats1->SetInteger("srtt", 20); |
199 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); | 206 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); |
200 // Set the server preference for mail.google.com:80. | 207 // Set the server preference for mail.google.com:80. |
201 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 208 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
202 server_pref_dict1); | 209 server_pref_dict1); |
203 | 210 |
204 base::DictionaryValue* http_server_properties_dict = | 211 base::DictionaryValue* http_server_properties_dict = |
(...skipping 18 matching lines...) Expand all Loading... |
223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 230 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
224 | 231 |
225 // Verify SupportsSpdy. | 232 // Verify SupportsSpdy. |
226 EXPECT_TRUE( | 233 EXPECT_TRUE( |
227 http_server_props_manager_->SupportsRequestPriority(google_server)); | 234 http_server_props_manager_->SupportsRequestPriority(google_server)); |
228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 235 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 236 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
230 HostPortPair::FromString("foo.google.com:1337"))); | 237 HostPortPair::FromString("foo.google.com:1337"))); |
231 | 238 |
232 // Verify AlternateProtocol. | 239 // Verify AlternateProtocol. |
233 AlternateProtocolInfo port_alternate_protocol = | 240 const AlternateProtocolMap& map = |
234 http_server_props_manager_->GetAlternateProtocol(google_server); | 241 http_server_props_manager_->alternate_protocol_map(); |
235 EXPECT_EQ(443, port_alternate_protocol.port); | 242 AlternateProtocolMap::const_iterator www_it = map.Peek(google_server); |
236 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 243 ASSERT_TRUE(www_it != map.end()); |
237 port_alternate_protocol = | 244 const AlternateProtocols alternate_protocols0 = www_it->second; |
238 http_server_props_manager_->GetAlternateProtocol(mail_server); | 245 ASSERT_EQ(2u, alternate_protocols0.size()); |
239 EXPECT_EQ(444, port_alternate_protocol.port); | 246 EXPECT_EQ(443, alternate_protocols0[0].port); |
240 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); | 247 EXPECT_EQ(NPN_SPDY_3, alternate_protocols0[0].protocol); |
| 248 EXPECT_EQ(1234, alternate_protocols0[1].port); |
| 249 EXPECT_EQ(QUIC, alternate_protocols0[1].protocol); |
| 250 AlternateProtocolMap::const_iterator mail_it = map.Peek(mail_server); |
| 251 ASSERT_TRUE(mail_it != map.end()); |
| 252 const AlternateProtocols alternate_protocols1 = mail_it->second; |
| 253 ASSERT_EQ(1u, alternate_protocols1.size()); |
| 254 EXPECT_EQ(444, alternate_protocols1[0].port); |
| 255 EXPECT_EQ(NPN_SPDY_3_1, alternate_protocols1[0].protocol); |
241 | 256 |
242 // Verify SupportsQuic. | 257 // Verify SupportsQuic. |
243 IPAddressNumber last_address; | 258 IPAddressNumber last_address; |
244 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); | 259 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
245 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); | 260 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); |
246 | 261 |
247 // Verify ServerNetworkStats. | 262 // Verify ServerNetworkStats. |
248 const ServerNetworkStats* stats2 = | 263 const ServerNetworkStats* stats2 = |
249 http_server_props_manager_->GetServerNetworkStats(google_server); | 264 http_server_props_manager_->GetServerNetworkStats(google_server); |
250 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 265 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
251 const ServerNetworkStats* stats3 = | 266 const ServerNetworkStats* stats3 = |
252 http_server_props_manager_->GetServerNetworkStats(mail_server); | 267 http_server_props_manager_->GetServerNetworkStats(mail_server); |
253 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); | 268 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
254 } | 269 } |
255 | 270 |
256 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 271 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
257 ExpectCacheUpdate(); | 272 ExpectCacheUpdate(); |
258 // The prefs are automaticalls updated in the case corruption is detected. | 273 // The prefs are automaticalls updated in the case corruption is detected. |
259 ExpectPrefsUpdate(); | 274 ExpectPrefsUpdate(); |
260 | 275 |
261 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 276 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
262 | 277 |
263 // Set supports_spdy for www.google.com:65536. | 278 // Set supports_spdy for www.google.com:65536. |
264 server_pref_dict->SetBoolean("supports_spdy", true); | 279 server_pref_dict->SetBoolean("supports_spdy", true); |
265 | 280 |
266 // Set up alternate_protocol for www.google.com:65536. | 281 // Set up alternative_services for www.google.com:65536. |
267 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 282 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
268 alternate_protocol->SetInteger("port", 80); | 283 alternate_protocol->SetInteger("port", 80); |
269 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 284 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
270 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 285 base::ListValue* alternative_services = new base::ListValue; |
271 alternate_protocol); | 286 alternative_services->Append(alternate_protocol); |
| 287 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 288 alternative_services); |
272 | 289 |
273 // Set up ServerNetworkStats for www.google.com:65536. | 290 // Set up ServerNetworkStats for www.google.com:65536. |
274 base::DictionaryValue* stats = new base::DictionaryValue; | 291 base::DictionaryValue* stats = new base::DictionaryValue; |
275 stats->SetInteger("srtt", 10); | 292 stats->SetInteger("srtt", 10); |
276 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 293 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
277 | 294 |
278 // Set the server preference for www.google.com:65536. | 295 // Set the server preference for www.google.com:65536. |
279 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 296 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
280 servers_dict->SetWithoutPathExpansion("www.google.com:65536", | 297 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
281 server_pref_dict); | 298 server_pref_dict); |
(...skipping 24 matching lines...) Expand all Loading... |
306 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 323 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
307 ExpectCacheUpdate(); | 324 ExpectCacheUpdate(); |
308 // The prefs are automaticalls updated in the case corruption is detected. | 325 // The prefs are automaticalls updated in the case corruption is detected. |
309 ExpectPrefsUpdate(); | 326 ExpectPrefsUpdate(); |
310 | 327 |
311 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 328 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
312 | 329 |
313 // Set supports_spdy for www.google.com:80. | 330 // Set supports_spdy for www.google.com:80. |
314 server_pref_dict->SetBoolean("supports_spdy", true); | 331 server_pref_dict->SetBoolean("supports_spdy", true); |
315 | 332 |
316 // Set up alternate_protocol for www.google.com:80. | 333 // Set up alternative_services for www.google.com:80. |
317 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 334 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
318 alternate_protocol->SetInteger("port", 65536); | 335 alternate_protocol->SetInteger("port", 65536); |
319 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 336 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
320 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 337 base::ListValue* alternative_services = new base::ListValue; |
321 alternate_protocol); | 338 alternative_services->Append(alternate_protocol); |
| 339 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 340 alternative_services); |
322 | 341 |
323 // Set the server preference for www.google.com:80. | 342 // Set the server preference for www.google.com:80. |
324 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 343 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
325 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 344 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
326 | 345 |
327 base::DictionaryValue* http_server_properties_dict = | 346 base::DictionaryValue* http_server_properties_dict = |
328 new base::DictionaryValue; | 347 new base::DictionaryValue; |
329 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 348 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
330 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 349 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
331 | 350 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); | 479 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); |
461 | 480 |
462 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 481 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
463 } | 482 } |
464 | 483 |
465 TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) { | 484 TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) { |
466 ExpectPrefsUpdate(); | 485 ExpectPrefsUpdate(); |
467 | 486 |
468 HostPortPair spdy_server_mail("mail.google.com", 80); | 487 HostPortPair spdy_server_mail("mail.google.com", 80); |
469 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); | 488 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); |
470 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 489 http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
471 NPN_SPDY_3, 1.0); | 490 NPN_SPDY_3, 1.0); |
472 | 491 |
473 // Run the task. | 492 // Run the task. |
474 base::RunLoop().RunUntilIdle(); | 493 base::RunLoop().RunUntilIdle(); |
475 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 494 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
476 | 495 |
477 const AlternateProtocolInfo alternate_protocol = | 496 AlternateProtocols port_alternate_protocols = |
478 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 497 http_server_props_manager_->GetAlternateProtocols(spdy_server_mail); |
479 EXPECT_EQ(443, alternate_protocol.port); | 498 ASSERT_EQ(1u, port_alternate_protocols.size()); |
480 EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol); | 499 EXPECT_EQ(443, port_alternate_protocols[0].port); |
481 EXPECT_EQ(1.0, alternate_protocol.probability); | 500 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocols[0].protocol); |
482 } | 501 } |
483 | 502 |
484 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 503 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
485 ExpectPrefsUpdate(); | 504 ExpectPrefsUpdate(); |
486 | 505 |
487 IPAddressNumber address; | 506 IPAddressNumber address; |
488 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); | 507 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
489 | 508 |
490 IPAddressNumber actual_address; | 509 IPAddressNumber actual_address; |
491 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 510 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
(...skipping 25 matching lines...) Expand all Loading... |
517 const ServerNetworkStats* stats2 = | 536 const ServerNetworkStats* stats2 = |
518 http_server_props_manager_->GetServerNetworkStats(mail_server); | 537 http_server_props_manager_->GetServerNetworkStats(mail_server); |
519 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 538 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
520 } | 539 } |
521 | 540 |
522 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 541 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
523 ExpectPrefsUpdate(); | 542 ExpectPrefsUpdate(); |
524 | 543 |
525 HostPortPair spdy_server_mail("mail.google.com", 443); | 544 HostPortPair spdy_server_mail("mail.google.com", 443); |
526 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 545 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
527 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 546 http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
528 NPN_SPDY_3, 1.0); | 547 NPN_SPDY_3, 1.0); |
529 IPAddressNumber actual_address; | 548 IPAddressNumber actual_address; |
530 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 549 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
531 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 550 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
532 ServerNetworkStats stats; | 551 ServerNetworkStats stats; |
533 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 552 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
534 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 553 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
535 | 554 |
536 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 555 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
537 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 556 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 609 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
591 ExpectCacheUpdate(); | 610 ExpectCacheUpdate(); |
592 | 611 |
593 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 612 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
594 | 613 |
595 for (int i = 0; i < 200; ++i) { | 614 for (int i = 0; i < 200; ++i) { |
596 // Set up alternate_protocol for www.google.com:i. | 615 // Set up alternate_protocol for www.google.com:i. |
597 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 616 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
598 alternate_protocol->SetInteger("port", i); | 617 alternate_protocol->SetInteger("port", i); |
599 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 618 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 619 base::ListValue* alternative_services = new base::ListValue; |
| 620 alternative_services->Append(alternate_protocol); |
600 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 621 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
601 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 622 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
602 alternate_protocol); | 623 alternative_services); |
603 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), | 624 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), |
604 server_pref_dict); | 625 server_pref_dict); |
605 } | 626 } |
606 | 627 |
607 // Set the preference for mail.google.com server. | 628 // Set the preference for mail.google.com server. |
608 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 629 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
609 | 630 |
610 // Set the server preference for mail.google.com:80. | 631 // Set the server preference for mail.google.com:80. |
611 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 632 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
612 server_pref_dict1); | 633 server_pref_dict1); |
(...skipping 13 matching lines...) Expand all Loading... |
626 // Set up the pref. | 647 // Set up the pref. |
627 pref_service_.SetManagedPref(kTestHttpServerProperties, | 648 pref_service_.SetManagedPref(kTestHttpServerProperties, |
628 http_server_properties_dict); | 649 http_server_properties_dict); |
629 | 650 |
630 base::RunLoop().RunUntilIdle(); | 651 base::RunLoop().RunUntilIdle(); |
631 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
632 | 653 |
633 // Verify AlternateProtocol. | 654 // Verify AlternateProtocol. |
634 for (int i = 0; i < 200; ++i) { | 655 for (int i = 0; i < 200; ++i) { |
635 std::string server = StringPrintf("www.google.com:%d", i); | 656 std::string server = StringPrintf("www.google.com:%d", i); |
636 AlternateProtocolInfo port_alternate_protocol = | 657 AlternateProtocols alternate_protocols = |
637 http_server_props_manager_->GetAlternateProtocol( | 658 http_server_props_manager_->GetAlternateProtocols( |
638 HostPortPair::FromString(server)); | 659 HostPortPair::FromString(server)); |
639 EXPECT_EQ(i, port_alternate_protocol.port); | 660 ASSERT_EQ(1u, alternate_protocols.size()); |
640 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 661 EXPECT_EQ(i, alternate_protocols[0].port); |
| 662 EXPECT_EQ(NPN_SPDY_3, alternate_protocols[0].protocol); |
641 } | 663 } |
642 | 664 |
643 // Verify SupportsQuic. | 665 // Verify SupportsQuic. |
644 IPAddressNumber address; | 666 IPAddressNumber address; |
645 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 667 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
646 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); | 668 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); |
647 } | 669 } |
648 | 670 |
649 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 671 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
650 const HostPortPair server_www("www.google.com", 80); | 672 const HostPortPair server_www("www.google.com", 80); |
651 const HostPortPair server_mail("mail.google.com", 80); | 673 const HostPortPair server_mail("mail.google.com", 80); |
652 | 674 |
653 // Set alternate protocol. | 675 // Set AltSvc. |
654 http_server_props_manager_->SetAlternateProtocol(server_www, 443, NPN_SPDY_3, | 676 http_server_props_manager_->AddAlternateProtocol(server_www, 443, NPN_SPDY_3, |
655 1.0); | 677 1.0); |
656 http_server_props_manager_->SetAlternateProtocol(server_mail, 444, | 678 http_server_props_manager_->AddAlternateProtocol(server_www, 1234, |
| 679 NPN_SPDY_3_1, 0.7); |
| 680 http_server_props_manager_->AddAlternateProtocol(server_mail, 444, |
657 NPN_SPDY_3_1, 0.2); | 681 NPN_SPDY_3_1, 0.2); |
658 | 682 |
659 // Set ServerNetworkStats. | 683 // Set ServerNetworkStats. |
660 ServerNetworkStats stats; | 684 ServerNetworkStats stats; |
661 stats.srtt = base::TimeDelta::FromInternalValue(42); | 685 stats.srtt = base::TimeDelta::FromInternalValue(42); |
662 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 686 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); |
663 | 687 |
664 // Set SupportsQuic. | 688 // Set SupportsQuic. |
665 IPAddressNumber actual_address; | 689 IPAddressNumber actual_address; |
666 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 690 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
667 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 691 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
668 | 692 |
669 // Update cache. | 693 // Update cache. |
670 ExpectPrefsUpdate(); | 694 ExpectPrefsUpdate(); |
671 ExpectCacheUpdate(); | 695 ExpectCacheUpdate(); |
672 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 696 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
673 base::RunLoop().RunUntilIdle(); | 697 base::RunLoop().RunUntilIdle(); |
674 | 698 |
675 // Verify preferences. | 699 // Verify preferences. |
676 const char expected_json[] = "{" | 700 const char expected_json[] = |
677 "\"servers\":{" | 701 "{\"servers\":{\"mail.google.com:80\":{\"alternative_services\":[{" |
678 "\"mail.google.com:80\":{" | 702 "\"host\":\"mail.google.com\",\"port\":444,\"probability\":0.2," |
679 "\"alternate_protocol\":{" | 703 "\"protocol_str\":\"npn-spdy/3.1\"}],\"network_stats\":{\"srtt\":42}}," |
680 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"" | 704 "\"www.google.com:80\":{\"alternative_services\":[{\"host\":" |
681 "}," | 705 "\"www.google.com\",\"port\":443,\"probability\":1.0,\"protocol_str\":" |
682 "\"network_stats\":{" | 706 "\"npn-spdy/3\"},{\"host\":\"www.google.com\",\"port\":1234," |
683 "\"srtt\":42" | 707 "\"probability\":0.7,\"protocol_str\":\"npn-spdy/3.1\"}]}}," |
684 "}" | 708 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," |
685 "}," | 709 "\"version\":3}"; |
686 "\"www.google.com:80\":{" | |
687 "\"alternate_protocol\":{" | |
688 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-spdy/3\"" | |
689 "}" | |
690 "}" | |
691 "}," | |
692 "\"supports_quic\":{" | |
693 "\"address\":\"127.0.0.1\",\"used_quic\":true" | |
694 "}," | |
695 "\"version\":3" | |
696 "}"; | |
697 | 710 |
698 const base::Value* http_server_properties = | 711 const base::Value* http_server_properties = |
699 pref_service_.GetUserPref(kTestHttpServerProperties); | 712 pref_service_.GetUserPref(kTestHttpServerProperties); |
700 ASSERT_NE(nullptr, http_server_properties); | 713 ASSERT_NE(nullptr, http_server_properties); |
701 std::string preferences_json; | 714 std::string preferences_json; |
702 EXPECT_TRUE( | 715 EXPECT_TRUE( |
703 base::JSONWriter::Write(http_server_properties, &preferences_json)); | 716 base::JSONWriter::Write(http_server_properties, &preferences_json)); |
704 EXPECT_EQ(expected_json, preferences_json); | 717 EXPECT_EQ(expected_json, preferences_json); |
705 } | 718 } |
706 | 719 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 // Run the task after shutdown, but before deletion. | 785 // Run the task after shutdown, but before deletion. |
773 base::RunLoop().RunUntilIdle(); | 786 base::RunLoop().RunUntilIdle(); |
774 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 787 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
775 http_server_props_manager_.reset(); | 788 http_server_props_manager_.reset(); |
776 base::RunLoop().RunUntilIdle(); | 789 base::RunLoop().RunUntilIdle(); |
777 } | 790 } |
778 | 791 |
779 } // namespace | 792 } // namespace |
780 | 793 |
781 } // namespace net | 794 } // namespace net |
OLD | NEW |