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