OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 HttpServerPropertiesImpl& impl) { | 39 HttpServerPropertiesImpl& impl) { |
40 impl.ExpireBrokenAlternateProtocolMappings(); | 40 impl.ExpireBrokenAlternateProtocolMappings(); |
41 } | 41 } |
42 }; | 42 }; |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 class HttpServerPropertiesImplTest : public testing::Test { | 46 class HttpServerPropertiesImplTest : public testing::Test { |
47 protected: | 47 protected: |
48 bool HasAlternativeService(const HostPortPair& origin) { | 48 bool HasAlternativeService(const HostPortPair& origin) { |
49 const AlternativeService alternative_service = | 49 const AlternativeServiceVector alternative_service_vector = |
50 impl_.GetAlternativeService(origin); | 50 impl_.GetAlternativeServices(origin); |
51 return alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; | 51 return !alternative_service_vector.empty(); |
52 } | 52 } |
53 | 53 |
54 HttpServerPropertiesImpl impl_; | 54 HttpServerPropertiesImpl impl_; |
55 }; | 55 }; |
56 | 56 |
57 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 57 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
58 | 58 |
59 TEST_F(SpdyServerPropertiesTest, Initialize) { | 59 TEST_F(SpdyServerPropertiesTest, Initialize) { |
60 HostPortPair spdy_server_google("www.google.com", 443); | 60 HostPortPair spdy_server_google("www.google.com", 443); |
61 std::string spdy_server_g = spdy_server_google.ToString(); | 61 std::string spdy_server_g = spdy_server_google.ToString(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 HostPortPair spdy_server_mail("mail.google.com", 443); | 112 HostPortPair spdy_server_mail("mail.google.com", 443); |
113 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 113 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
114 | 114 |
115 // Add docs.google.com:443 as supporting SPDY. | 115 // Add docs.google.com:443 as supporting SPDY. |
116 HostPortPair spdy_server_docs("docs.google.com", 443); | 116 HostPortPair spdy_server_docs("docs.google.com", 443); |
117 impl_.SetSupportsSpdy(spdy_server_docs, true); | 117 impl_.SetSupportsSpdy(spdy_server_docs, true); |
118 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 118 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
119 | 119 |
120 // Add www.youtube.com:443 as supporting QUIC. | 120 // Add www.youtube.com:443 as supporting QUIC. |
121 HostPortPair quic_server_youtube("www.youtube.com", 443); | 121 HostPortPair quic_server_youtube("www.youtube.com", 443); |
122 const AlternativeService alternative_service(QUIC, "www.youtube.com", 443); | 122 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); |
123 impl_.SetAlternativeService(quic_server_youtube, alternative_service, 1.0); | 123 impl_.AddAlternativeService(quic_server_youtube, alternative_service1, 1.0); |
124 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 124 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
125 | 125 |
| 126 // Add www.example.com:443 with two alternative services, one supporting QUIC. |
| 127 HostPortPair quic_server_example("www.example.com", 443); |
| 128 const AlternativeService alternative_service2(NPN_SPDY_4, "", 443); |
| 129 impl_.AddAlternativeService(quic_server_example, alternative_service2, 1.0); |
| 130 impl_.AddAlternativeService(quic_server_example, alternative_service1, 1.0); |
| 131 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); |
| 132 |
126 // Verify all the entries are the same after additions. | 133 // Verify all the entries are the same after additions. |
127 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 134 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
128 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 135 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
129 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 136 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
130 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 137 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
| 138 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); |
131 } | 139 } |
132 | 140 |
133 TEST_F(SpdyServerPropertiesTest, Clear) { | 141 TEST_F(SpdyServerPropertiesTest, Clear) { |
134 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. | 142 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. |
135 HostPortPair spdy_server_google("www.google.com", 443); | 143 HostPortPair spdy_server_google("www.google.com", 443); |
136 impl_.SetSupportsSpdy(spdy_server_google, true); | 144 impl_.SetSupportsSpdy(spdy_server_google, true); |
137 HostPortPair spdy_server_mail("mail.google.com", 443); | 145 HostPortPair spdy_server_mail("mail.google.com", 443); |
138 impl_.SetSupportsSpdy(spdy_server_mail, true); | 146 impl_.SetSupportsSpdy(spdy_server_mail, true); |
139 | 147 |
140 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 148 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 ASSERT_EQ(spdy_server_m, string_value_m); | 248 ASSERT_EQ(spdy_server_m, string_value_m); |
241 } | 249 } |
242 | 250 |
243 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 251 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
244 | 252 |
245 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 253 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
246 HostPortPair test_host_port_pair("foo", 80); | 254 HostPortPair test_host_port_pair("foo", 80); |
247 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 255 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
248 | 256 |
249 AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); | 257 AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); |
250 impl_.SetAlternativeService(test_host_port_pair, alternative_service, 1.0); | 258 impl_.AddAlternativeService(test_host_port_pair, alternative_service, 1.0); |
251 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); | 259 const AlternativeServiceVector alternative_service_vector = |
252 alternative_service = impl_.GetAlternativeService(test_host_port_pair); | 260 impl_.GetAlternativeServices(test_host_port_pair); |
253 EXPECT_EQ(443, alternative_service.port); | 261 ASSERT_EQ(1u, alternative_service_vector.size()); |
254 EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol); | 262 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
255 | 263 |
256 impl_.Clear(); | 264 impl_.Clear(); |
257 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 265 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
258 } | 266 } |
259 | 267 |
260 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { | 268 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { |
261 HostPortPair test_host_port_pair("foo", 80); | 269 HostPortPair test_host_port_pair("foo", 80); |
262 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); | 270 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); |
263 impl_.SetAlternativeService(test_host_port_pair, alternative_service, 0.99); | 271 impl_.AddAlternativeService(test_host_port_pair, alternative_service, 0.99); |
264 | 272 |
265 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 273 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
266 } | 274 } |
267 | 275 |
| 276 // GetAlternativeServices and HasAlternativeServices should only return the ones |
| 277 // with probability greater than or equal to the threshold. |
268 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { | 278 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { |
269 impl_.SetAlternativeServiceProbabilityThreshold(0.25); | 279 impl_.SetAlternativeServiceProbabilityThreshold(0.5); |
270 | 280 |
271 HostPortPair test_host_port_pair("foo", 80); | 281 HostPortPair test_host_port_pair("foo", 80); |
272 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); | 282 const AlternativeService alternative_service1(NPN_SPDY_4, "foo", 443); |
273 impl_.SetAlternativeService(test_host_port_pair, alternative_service, 0.5); | 283 impl_.AddAlternativeService(test_host_port_pair, alternative_service1, 0.3); |
| 284 |
| 285 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
| 286 |
| 287 const AlternativeService alternative_service2(QUIC, "bar", 123); |
| 288 impl_.AddAlternativeService(test_host_port_pair, alternative_service2, 0.7); |
| 289 const AlternativeService alternative_service3(NPN_SPDY_3_1, "baz", 443); |
| 290 impl_.AddAlternativeService(test_host_port_pair, alternative_service3, 0.4); |
| 291 const AlternativeService alternative_service4(NPN_SPDY_4, "qux", 1234); |
| 292 impl_.AddAlternativeService(test_host_port_pair, alternative_service4, 0.6); |
| 293 |
274 EXPECT_TRUE(HasAlternativeService(test_host_port_pair)); | 294 EXPECT_TRUE(HasAlternativeService(test_host_port_pair)); |
275 | 295 |
276 AlternativeServiceMap::const_iterator it = | 296 const AlternativeServiceVector alternative_service_vector = |
277 impl_.alternative_service_map().Peek(test_host_port_pair); | 297 impl_.GetAlternativeServices(test_host_port_pair); |
278 ASSERT_TRUE(it != impl_.alternative_service_map().end()); | 298 ASSERT_EQ(2u, alternative_service_vector.size()); |
279 EXPECT_EQ(443, it->second.alternative_service.port); | 299 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
280 EXPECT_EQ(NPN_SPDY_4, it->second.alternative_service.protocol); | 300 EXPECT_EQ(alternative_service4, alternative_service_vector[1]); |
281 EXPECT_EQ(0.5, it->second.probability); | |
282 } | 301 } |
283 | 302 |
284 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { | 303 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { |
285 impl_.SetAlternativeServiceProbabilityThreshold(0.75); | 304 impl_.SetAlternativeServiceProbabilityThreshold(0.75); |
286 | 305 |
287 HostPortPair test_host_port_pair("foo", 80); | 306 HostPortPair test_host_port_pair("foo", 80); |
288 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); | 307 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); |
289 impl_.SetAlternativeService(test_host_port_pair, alternative_service, 0.5); | 308 impl_.AddAlternativeService(test_host_port_pair, alternative_service, 0.5); |
290 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 309 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
291 } | 310 } |
292 | 311 |
293 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 312 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
| 313 // |test_host_port_pair1| has one alternative service, which is non-broken, |
| 314 // and thus will be removed by InitializeAlternativeServiceServers(). |
294 HostPortPair test_host_port_pair1("foo1", 80); | 315 HostPortPair test_host_port_pair1("foo1", 80); |
295 const AlternativeService alternative_service1(NPN_SPDY_4, "foo1", 443); | 316 const AlternativeService alternative_service1(NPN_SPDY_4, "bar1", 443); |
296 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0); | 317 impl_.AddAlternativeService(test_host_port_pair1, alternative_service1, 1.0); |
297 impl_.MarkAlternativeServiceBroken(alternative_service1); | |
298 | 318 |
| 319 // |test_host_port_pair2| has two alternative services. The broken one will |
| 320 // remain, the non-broken one will be removed by |
| 321 // InitializeAlternativeServiceServers(). |
299 HostPortPair test_host_port_pair2("foo2", 80); | 322 HostPortPair test_host_port_pair2("foo2", 80); |
300 const AlternativeService alternative_service2(NPN_SPDY_4, "foo2", 443); | 323 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); |
301 impl_.SetAlternativeService(test_host_port_pair2, alternative_service2, 1.0); | 324 impl_.AddAlternativeService(test_host_port_pair2, alternative_service2, 1.0); |
| 325 impl_.MarkAlternativeServiceBroken(alternative_service2); |
| 326 const AlternativeService alternative_service3(NPN_SPDY_3_1, "bar3", 1234); |
| 327 impl_.AddAlternativeService(test_host_port_pair2, alternative_service3, 0.8); |
302 | 328 |
| 329 // Prepare |alternative_service_map| to be loaded by |
| 330 // InitializeAlternativeServiceServers(). |
303 AlternativeServiceMap alternative_service_map( | 331 AlternativeServiceMap alternative_service_map( |
304 AlternativeServiceMap::NO_AUTO_EVICT); | 332 AlternativeServiceMap::NO_AUTO_EVICT); |
305 AlternativeServiceInfo alternative_service_info(NPN_SPDY_4, "bar", 123, 1.0); | 333 const AlternativeService alternative_service4(NPN_SPDY_4, "bar4", 123); |
306 alternative_service_map.Put(test_host_port_pair2, alternative_service_info); | 334 const AlternativeServiceInfo alternative_service_info1(alternative_service4, |
| 335 0.7); |
| 336 alternative_service_map.Put( |
| 337 test_host_port_pair2, |
| 338 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); |
| 339 |
307 HostPortPair test_host_port_pair3("foo3", 80); | 340 HostPortPair test_host_port_pair3("foo3", 80); |
308 alternative_service_info.alternative_service.port = 1234; | 341 const AlternativeService alternative_service5(NPN_SPDY_4, "bar5", 1234); |
309 alternative_service_map.Put(test_host_port_pair3, alternative_service_info); | 342 const AlternativeServiceInfo alternative_service_info2(alternative_service5, |
| 343 0.2); |
| 344 alternative_service_map.Put( |
| 345 test_host_port_pair3, |
| 346 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); |
| 347 |
310 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 348 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
311 | 349 |
312 // Verify test_host_port_pair3 is the MRU server. | 350 // Verify alternative_service_map. |
313 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 351 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
314 AlternativeServiceMap::const_iterator it = map.begin(); | 352 ASSERT_EQ(2u, map.size()); |
315 ASSERT_TRUE(it != map.end()); | 353 AlternativeServiceMap::const_iterator map_it = map.begin(); |
316 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); | 354 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3)); |
317 EXPECT_EQ(NPN_SPDY_4, it->second.alternative_service.protocol); | 355 ASSERT_EQ(1u, map_it->second.size()); |
318 EXPECT_EQ(1234, it->second.alternative_service.port); | 356 EXPECT_EQ(alternative_service5, map_it->second[0].alternative_service); |
| 357 EXPECT_EQ(0.2, map_it->second[0].probability); |
| 358 ++map_it; |
| 359 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2)); |
| 360 ASSERT_EQ(2u, map_it->second.size()); |
| 361 EXPECT_EQ(alternative_service2, map_it->second[0].alternative_service); |
| 362 EXPECT_EQ(1.0, map_it->second[0].probability); |
| 363 EXPECT_EQ(alternative_service4, map_it->second[1].alternative_service); |
| 364 EXPECT_EQ(0.7, map_it->second[1].probability); |
| 365 } |
319 | 366 |
320 ASSERT_TRUE(HasAlternativeService(test_host_port_pair1)); | 367 TEST_F(AlternateProtocolServerPropertiesTest, AddAlternativeService) { |
321 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 368 const HostPortPair host_port_pair("foo", 443); |
322 const AlternativeService alternative_service = | 369 const AlternativeService alternative_service1(NPN_SPDY_4, "bar", 123); |
323 impl_.GetAlternativeService(test_host_port_pair2); | 370 impl_.AddAlternativeService(host_port_pair, alternative_service1, 1.0); |
324 EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol); | 371 |
325 EXPECT_EQ(123, alternative_service.port); | 372 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 373 AlternativeServiceMap::const_iterator map_it = map.begin(); |
| 374 ASSERT_EQ("foo", map_it->first.host()); |
| 375 EXPECT_EQ(1u, map_it->second.size()); |
| 376 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); |
| 377 EXPECT_EQ(1.0, map_it->second[0].probability); |
| 378 |
| 379 // Same alternative service with same probability should cause no change. |
| 380 impl_.AddAlternativeService(host_port_pair, alternative_service1, 1.0); |
| 381 EXPECT_EQ(1u, map_it->second.size()); |
| 382 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); |
| 383 EXPECT_EQ(1.0, map_it->second[0].probability); |
| 384 |
| 385 // Same alternative service with different probability should overwrite. |
| 386 impl_.AddAlternativeService(host_port_pair, alternative_service1, 0.8); |
| 387 EXPECT_EQ(1u, map_it->second.size()); |
| 388 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); |
| 389 EXPECT_EQ(0.8, map_it->second[0].probability); |
| 390 |
| 391 // Different alternative service should be added. |
| 392 const AlternativeService alternative_service2(QUIC, "", 123); |
| 393 impl_.AddAlternativeService(host_port_pair, alternative_service2, 0.2); |
| 394 EXPECT_EQ(2u, map_it->second.size()); |
| 395 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); |
| 396 EXPECT_EQ(0.8, map_it->second[0].probability); |
| 397 EXPECT_EQ(alternative_service2, map_it->second[1].alternative_service); |
| 398 EXPECT_EQ(0.2, map_it->second[1].probability); |
| 399 |
| 400 impl_.ClearAlternativeServices(host_port_pair); |
| 401 EXPECT_EQ(0u, map.size()); |
326 } | 402 } |
327 | 403 |
328 // Regression test for https://crbug.com/504032: | 404 // Regression test for https://crbug.com/504032: |
329 // InitializeAlternativeServiceServers() should not crash if there is an empty | 405 // InitializeAlternativeServiceServers() should not crash if there is an empty |
330 // hostname is the mapping. | 406 // hostname is the mapping. |
331 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { | 407 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { |
332 const HostPortPair host_port_pair("foo", 443); | 408 const HostPortPair host_port_pair("foo", 443); |
333 const AlternativeService alternative_service_with_empty_hostname(NPN_SPDY_4, | 409 const AlternativeService alternative_service_with_empty_hostname(NPN_SPDY_4, |
334 "", 1234); | 410 "", 1234); |
335 const AlternativeService alternative_service_with_foo_hostname(NPN_SPDY_4, | 411 const AlternativeService alternative_service_with_foo_hostname(NPN_SPDY_4, |
336 "foo", 1234); | 412 "foo", 1234); |
337 impl_.SetAlternativeService(host_port_pair, | 413 impl_.AddAlternativeService(host_port_pair, |
338 alternative_service_with_empty_hostname, 1.0); | 414 alternative_service_with_empty_hostname, 1.0); |
339 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); | 415 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); |
340 | 416 |
341 AlternativeServiceMap alternative_service_map( | 417 AlternativeServiceMap alternative_service_map( |
342 AlternativeServiceMap::NO_AUTO_EVICT); | 418 AlternativeServiceMap::NO_AUTO_EVICT); |
343 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 419 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
344 | 420 |
345 EXPECT_TRUE( | 421 EXPECT_TRUE( |
346 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); | 422 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); |
347 EXPECT_TRUE(impl_.GetAlternativeService(host_port_pair) == | 423 const AlternativeServiceVector alternative_service_vector = |
348 alternative_service_with_foo_hostname); | 424 impl_.GetAlternativeServices(host_port_pair); |
| 425 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 426 EXPECT_EQ(alternative_service_with_foo_hostname, |
| 427 alternative_service_vector[0]); |
349 } | 428 } |
350 | 429 |
351 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { | 430 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { |
352 HostPortPair test_host_port_pair1("foo1", 80); | 431 HostPortPair test_host_port_pair1("foo1", 80); |
353 const AlternativeService alternative_service1(NPN_SPDY_4, "foo1", 443); | 432 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); |
354 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0); | 433 impl_.AddAlternativeService(test_host_port_pair1, alternative_service1, 1.0); |
355 HostPortPair test_host_port_pair2("foo2", 80); | 434 HostPortPair test_host_port_pair2("foo2", 80); |
356 const AlternativeService alternative_service2(NPN_SPDY_4, "foo2", 1234); | 435 const AlternativeService alternative_service2(NPN_SPDY_4, "foo2", 1234); |
357 impl_.SetAlternativeService(test_host_port_pair2, alternative_service2, 1.0); | 436 impl_.AddAlternativeService(test_host_port_pair2, alternative_service2, 1.0); |
358 | 437 |
359 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 438 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
360 AlternativeServiceMap::const_iterator it = map.begin(); | 439 AlternativeServiceMap::const_iterator it = map.begin(); |
361 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); | 440 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); |
362 EXPECT_EQ(NPN_SPDY_4, it->second.alternative_service.protocol); | 441 ASSERT_EQ(1u, it->second.size()); |
363 EXPECT_EQ(1234, it->second.alternative_service.port); | 442 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); |
364 | 443 |
365 // GetAlternativeService should reorder the AlternateProtocol map. | 444 const AlternativeServiceVector alternative_service_vector = |
366 const AlternativeService alternative_service = | 445 impl_.GetAlternativeServices(test_host_port_pair1); |
367 impl_.GetAlternativeService(test_host_port_pair1); | 446 ASSERT_EQ(1u, alternative_service_vector.size()); |
368 EXPECT_EQ(443, alternative_service.port); | 447 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
369 EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol); | 448 |
| 449 // GetAlternativeServices should reorder the AlternateProtocol map. |
370 it = map.begin(); | 450 it = map.begin(); |
371 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | 451 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); |
372 EXPECT_EQ(NPN_SPDY_4, it->second.alternative_service.protocol); | 452 ASSERT_EQ(1u, it->second.size()); |
373 EXPECT_EQ(443, it->second.alternative_service.port); | 453 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
374 } | 454 } |
375 | 455 |
376 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 456 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
377 HostPortPair test_host_port_pair("foo", 80); | 457 HostPortPair test_host_port_pair("foo", 80); |
378 const AlternativeService alternative_service1(NPN_SPDY_4, "foo", 443); | 458 const AlternativeService alternative_service1(NPN_SPDY_4, "foo", 443); |
379 impl_.SetAlternativeService(test_host_port_pair, alternative_service1, 1.0); | 459 impl_.AddAlternativeService(test_host_port_pair, alternative_service1, 1.0); |
| 460 AlternativeServiceVector alternative_service_vector = |
| 461 impl_.GetAlternativeServices(test_host_port_pair); |
| 462 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 463 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 464 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 465 |
| 466 // GetAlternativeServices should return broken alternative services as well. |
380 impl_.MarkAlternativeServiceBroken(alternative_service1); | 467 impl_.MarkAlternativeServiceBroken(alternative_service1); |
381 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); | 468 alternative_service_vector = |
| 469 impl_.GetAlternativeServices(test_host_port_pair); |
| 470 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 471 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
382 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 472 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
383 | 473 |
| 474 // AddAlternativeService should not change anything. |
| 475 impl_.AddAlternativeService(test_host_port_pair, alternative_service1, 1.0); |
| 476 alternative_service_vector = |
| 477 impl_.GetAlternativeServices(test_host_port_pair); |
| 478 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 479 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 480 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
| 481 |
| 482 // When adding another alternative service, the broken one should remain in |
| 483 // the mapping. |
384 const AlternativeService alternative_service2(NPN_SPDY_4, "foo", 1234); | 484 const AlternativeService alternative_service2(NPN_SPDY_4, "foo", 1234); |
385 impl_.SetAlternativeService(test_host_port_pair, alternative_service2, 1.0); | 485 impl_.AddAlternativeService(test_host_port_pair, alternative_service2, 1.0); |
386 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 486 alternative_service_vector = |
387 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2)); | 487 impl_.GetAlternativeServices(test_host_port_pair); |
388 EXPECT_EQ(1234, impl_.GetAlternativeService(test_host_port_pair).port); | 488 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 489 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 490 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
| 491 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
| 492 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1])); |
| 493 } |
| 494 |
| 495 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { |
| 496 HostPortPair test_host_port_pair("foo", 80); |
| 497 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 498 const AlternativeService alternative_service2(NPN_SPDY_4, "bar", 1234); |
| 499 impl_.AddAlternativeService(test_host_port_pair, alternative_service1, 1.0); |
| 500 impl_.AddAlternativeService(test_host_port_pair, alternative_service2, 1.0); |
| 501 |
| 502 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 503 net::AlternativeServiceMap::const_iterator it = map.begin(); |
| 504 EXPECT_TRUE(it->first.Equals(test_host_port_pair)); |
| 505 ASSERT_EQ(2u, it->second.size()); |
| 506 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
| 507 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); |
| 508 |
| 509 impl_.ClearAlternativeServices(test_host_port_pair); |
| 510 EXPECT_EQ(0u, map.size()); |
389 } | 511 } |
390 | 512 |
391 // A broken alternative service in the mapping carries meaningful information, | 513 // A broken alternative service in the mapping carries meaningful information, |
392 // therefore it should not be ignored by SetAlternativeService(). In | 514 // therefore it should not be ignored by AddAlternativeService(). In |
393 // particular, an alternative service mapped to an origin shadows alternative | 515 // particular, an alternative service mapped to an origin shadows alternative |
394 // services of canonical hosts. | 516 // services of canonical hosts. |
395 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { | 517 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { |
396 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 518 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
397 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 519 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
398 AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234); | 520 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
399 impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0); | 521 1234); |
400 EXPECT_TRUE(impl_.GetAlternativeService(test_host_port_pair) == | 522 impl_.AddAlternativeService(canonical_host_port_pair, |
401 canonical_altsvc); | 523 canonical_alternative_service, 1.0); |
| 524 AlternativeServiceVector alternative_service_vector = |
| 525 impl_.GetAlternativeServices(test_host_port_pair); |
| 526 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 527 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]); |
402 | 528 |
403 const AlternativeService broken_alternative_service(NPN_SPDY_4, "foo", 443); | 529 const AlternativeService broken_alternative_service(NPN_SPDY_4, "foo", 443); |
404 impl_.MarkAlternativeServiceBroken(broken_alternative_service); | 530 impl_.MarkAlternativeServiceBroken(broken_alternative_service); |
405 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 531 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
406 | 532 |
407 impl_.SetAlternativeService(test_host_port_pair, broken_alternative_service, | 533 impl_.AddAlternativeService(test_host_port_pair, broken_alternative_service, |
408 1.0); | 534 1.0); |
409 ASSERT_EQ(broken_alternative_service, | 535 alternative_service_vector = |
410 impl_.GetAlternativeService(test_host_port_pair)); | 536 impl_.GetAlternativeServices(test_host_port_pair); |
| 537 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 538 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]); |
411 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 539 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
412 } | 540 } |
413 | 541 |
414 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 542 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
415 HostPortPair test_host_port_pair("foo", 80); | 543 HostPortPair test_host_port_pair("foo", 80); |
416 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); | 544 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); |
417 impl_.SetAlternativeService(test_host_port_pair, alternative_service, 1.0); | 545 impl_.AddAlternativeService(test_host_port_pair, alternative_service, 1.0); |
418 impl_.MarkAlternativeServiceBroken(alternative_service); | 546 impl_.MarkAlternativeServiceBroken(alternative_service); |
419 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); | 547 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); |
420 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 548 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
421 impl_.ClearAlternativeService(test_host_port_pair); | 549 impl_.ClearAlternativeServices(test_host_port_pair); |
422 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 550 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
423 } | 551 } |
424 | 552 |
425 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { | 553 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { |
426 HostPortPair host_port_pair("foo", 80); | 554 HostPortPair host_port_pair("foo", 80); |
427 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); | 555 const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443); |
428 impl_.SetAlternativeService(host_port_pair, alternative_service, 1.0); | 556 impl_.AddAlternativeService(host_port_pair, alternative_service, 1.0); |
429 | 557 |
430 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 558 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
431 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 559 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
432 | 560 |
433 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); | 561 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); |
434 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 562 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
435 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 563 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
436 | 564 |
437 impl_.ConfirmAlternativeService(alternative_service); | 565 impl_.ConfirmAlternativeService(alternative_service); |
438 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 566 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
439 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 567 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
440 } | 568 } |
441 | 569 |
442 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { | 570 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { |
443 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 571 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
444 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 572 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
445 | 573 |
446 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 574 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
447 EXPECT_FALSE(HasAlternativeService(canonical_port_pair)); | 575 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); |
448 | 576 |
449 AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234); | 577 const AlternativeService canonical_alternative_service1( |
450 impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0); | 578 QUIC, "bar.c.youtube.com", 1234); |
451 // Verify the forced protocol. | 579 impl_.AddAlternativeService(canonical_host_port_pair, |
452 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); | 580 canonical_alternative_service1, 1.0); |
453 const AlternativeService alternative_service = | 581 const AlternativeService canonical_alternative_service2(NPN_SPDY_4, "", 443); |
454 impl_.GetAlternativeService(test_host_port_pair); | 582 impl_.AddAlternativeService(canonical_host_port_pair, |
455 EXPECT_EQ(canonical_altsvc.port, alternative_service.port); | 583 canonical_alternative_service2, 1.0); |
456 EXPECT_EQ(canonical_altsvc.protocol, alternative_service.protocol); | 584 |
| 585 // Since |test_host_port_pair| does not have an alternative service itself, |
| 586 // GetAlternativeServices should return those of |canonical_host_port_pair|. |
| 587 AlternativeServiceVector alternative_service_vector = |
| 588 impl_.GetAlternativeServices(test_host_port_pair); |
| 589 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 590 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]); |
| 591 |
| 592 // Since |canonical_alternative_service2| has an empty host, |
| 593 // GetAlternativeServices should substitute the hostname of its |origin| |
| 594 // argument. |
| 595 EXPECT_EQ(test_host_port_pair.host(), alternative_service_vector[1].host); |
| 596 EXPECT_EQ(canonical_alternative_service2.protocol, |
| 597 alternative_service_vector[1].protocol); |
| 598 EXPECT_EQ(canonical_alternative_service2.port, |
| 599 alternative_service_vector[1].port); |
457 | 600 |
458 // Verify the canonical suffix. | 601 // Verify the canonical suffix. |
459 EXPECT_EQ(".c.youtube.com", | 602 EXPECT_EQ(".c.youtube.com", |
460 impl_.GetCanonicalSuffix(test_host_port_pair.host())); | 603 impl_.GetCanonicalSuffix(test_host_port_pair.host())); |
461 EXPECT_EQ(".c.youtube.com", | 604 EXPECT_EQ(".c.youtube.com", |
462 impl_.GetCanonicalSuffix(canonical_port_pair.host())); | 605 impl_.GetCanonicalSuffix(canonical_host_port_pair.host())); |
463 } | |
464 | |
465 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalDefaultHost) { | |
466 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | |
467 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | |
468 | |
469 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | |
470 EXPECT_FALSE(HasAlternativeService(canonical_port_pair)); | |
471 | |
472 AlternativeService canonical_altsvc(QUIC, "", 1234); | |
473 impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0); | |
474 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); | |
475 const AlternativeService alternative_service = | |
476 impl_.GetAlternativeService(test_host_port_pair); | |
477 EXPECT_EQ(canonical_altsvc.protocol, alternative_service.protocol); | |
478 EXPECT_EQ(test_host_port_pair.host(), alternative_service.host); | |
479 EXPECT_EQ(canonical_altsvc.port, alternative_service.port); | |
480 } | 606 } |
481 | 607 |
482 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { | 608 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { |
483 impl_.SetAlternativeServiceProbabilityThreshold(0.02); | 609 impl_.SetAlternativeServiceProbabilityThreshold(0.02); |
484 | 610 |
485 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 611 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
486 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 612 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
487 AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234); | 613 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 614 1234); |
488 | 615 |
489 impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 0.01); | 616 impl_.AddAlternativeService(canonical_host_port_pair, |
490 EXPECT_FALSE(HasAlternativeService(canonical_port_pair)); | 617 canonical_alternative_service, 0.01); |
| 618 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); |
491 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 619 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
492 } | 620 } |
493 | 621 |
494 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { | 622 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { |
495 impl_.SetAlternativeServiceProbabilityThreshold(0.02); | 623 impl_.SetAlternativeServiceProbabilityThreshold(0.02); |
496 | 624 |
497 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 625 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
498 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 626 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
499 AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234); | 627 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 628 1234); |
500 | 629 |
501 impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 0.03); | 630 impl_.AddAlternativeService(canonical_host_port_pair, |
502 EXPECT_TRUE(HasAlternativeService(canonical_port_pair)); | 631 canonical_alternative_service, 0.03); |
| 632 EXPECT_TRUE(HasAlternativeService(canonical_host_port_pair)); |
503 EXPECT_TRUE(HasAlternativeService(test_host_port_pair)); | 633 EXPECT_TRUE(HasAlternativeService(test_host_port_pair)); |
504 } | 634 } |
505 | 635 |
506 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 636 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
507 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 637 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
508 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 638 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
509 AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234); | 639 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 640 1234); |
510 | 641 |
511 impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0); | 642 impl_.AddAlternativeService(canonical_host_port_pair, |
512 impl_.ClearAlternativeService(canonical_port_pair); | 643 canonical_alternative_service, 1.0); |
| 644 impl_.ClearAlternativeServices(canonical_host_port_pair); |
513 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 645 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
514 } | 646 } |
515 | 647 |
516 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { | 648 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { |
517 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 649 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
518 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 650 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
519 AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234); | 651 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 652 1234); |
520 | 653 |
521 impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0); | 654 impl_.AddAlternativeService(canonical_host_port_pair, |
522 impl_.MarkAlternativeServiceBroken(canonical_altsvc); | 655 canonical_alternative_service, 1.0); |
| 656 impl_.MarkAlternativeServiceBroken(canonical_alternative_service); |
523 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 657 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
524 } | 658 } |
525 | 659 |
526 // Adding an alternative service for a new host overrides canonical host. | 660 // Adding an alternative service for a new host overrides canonical host. |
527 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { | 661 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { |
528 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 662 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
529 HostPortPair bar_host_port_pair("bar.c.youtube.com", 80); | 663 HostPortPair bar_host_port_pair("bar.c.youtube.com", 80); |
530 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); | 664 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); |
531 impl_.SetAlternativeService(bar_host_port_pair, bar_alternative_service, 1.0); | 665 impl_.AddAlternativeService(bar_host_port_pair, bar_alternative_service, 1.0); |
532 AlternativeService altsvc = impl_.GetAlternativeService(test_host_port_pair); | 666 AlternativeServiceVector alternative_service_vector = |
533 EXPECT_EQ(1234, altsvc.port); | 667 impl_.GetAlternativeServices(test_host_port_pair); |
| 668 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 669 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]); |
534 | 670 |
535 HostPortPair qux_host_port_pair("qux.c.youtube.com", 80); | 671 HostPortPair qux_host_port_pair("qux.c.youtube.com", 80); |
536 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); | 672 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); |
537 impl_.SetAlternativeService(qux_host_port_pair, qux_alternative_service, 1.0); | 673 impl_.AddAlternativeService(qux_host_port_pair, qux_alternative_service, 1.0); |
538 altsvc = impl_.GetAlternativeService(test_host_port_pair); | 674 alternative_service_vector = |
539 EXPECT_EQ(443, altsvc.port); | 675 impl_.GetAlternativeServices(test_host_port_pair); |
| 676 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 677 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]); |
540 } | 678 } |
541 | 679 |
542 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 680 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
543 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 681 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
544 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 682 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
545 AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234); | 683 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 684 1234); |
546 | 685 |
547 impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0); | 686 impl_.AddAlternativeService(canonical_host_port_pair, |
| 687 canonical_alternative_service, 1.0); |
548 impl_.Clear(); | 688 impl_.Clear(); |
549 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 689 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
550 } | 690 } |
551 | 691 |
552 TEST_F(AlternateProtocolServerPropertiesTest, | 692 TEST_F(AlternateProtocolServerPropertiesTest, |
553 ExpireBrokenAlternateProtocolMappings) { | 693 ExpireBrokenAlternateProtocolMappings) { |
554 HostPortPair host_port_pair("foo", 443); | 694 HostPortPair host_port_pair("foo", 443); |
555 AlternativeService alternative_service(QUIC, "foo", 443); | 695 AlternativeService alternative_service(QUIC, "foo", 443); |
556 impl_.SetAlternativeService(host_port_pair, alternative_service, 1.0); | 696 impl_.AddAlternativeService(host_port_pair, alternative_service, 1.0); |
557 EXPECT_TRUE(HasAlternativeService(host_port_pair)); | 697 EXPECT_TRUE(HasAlternativeService(host_port_pair)); |
558 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 698 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
559 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 699 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
560 | 700 |
561 base::TimeTicks past = | 701 base::TimeTicks past = |
562 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); | 702 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); |
563 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( | 703 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( |
564 impl_, alternative_service, past); | 704 impl_, alternative_service, past); |
565 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 705 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
566 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 706 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 975 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); |
836 | 976 |
837 impl_.Clear(); | 977 impl_.Clear(); |
838 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); | 978 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); |
839 EXPECT_EQ(NULL, stats3); | 979 EXPECT_EQ(NULL, stats3); |
840 } | 980 } |
841 | 981 |
842 } // namespace | 982 } // namespace |
843 | 983 |
844 } // namespace net | 984 } // namespace net |
OLD | NEW |