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 26 matching lines...) Expand all Loading... |
37 static void ExpireBrokenAlternateProtocolMappings( | 37 static void ExpireBrokenAlternateProtocolMappings( |
38 HttpServerPropertiesImpl& impl) { | 38 HttpServerPropertiesImpl& impl) { |
39 impl.ExpireBrokenAlternateProtocolMappings(); | 39 impl.ExpireBrokenAlternateProtocolMappings(); |
40 } | 40 } |
41 }; | 41 }; |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 class HttpServerPropertiesImplTest : public testing::Test { | 45 class HttpServerPropertiesImplTest : public testing::Test { |
46 protected: | 46 protected: |
47 bool HasAlternateProtocol(const HostPortPair& server) { | 47 bool HasAlternativeService(const HostPortPair& origin) { |
48 const AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(server); | 48 const AlternativeService alternative_service = |
49 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; | 49 impl_.GetAlternativeService(origin); |
| 50 return alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; |
50 } | 51 } |
51 | 52 |
52 HttpServerPropertiesImpl impl_; | 53 HttpServerPropertiesImpl impl_; |
53 }; | 54 }; |
54 | 55 |
55 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 56 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
56 | 57 |
57 TEST_F(SpdyServerPropertiesTest, Initialize) { | 58 TEST_F(SpdyServerPropertiesTest, Initialize) { |
58 HostPortPair spdy_server_google("www.google.com", 443); | 59 HostPortPair spdy_server_google("www.google.com", 443); |
59 std::string spdy_server_g = spdy_server_google.ToString(); | 60 std::string spdy_server_g = spdy_server_google.ToString(); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 235 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
235 ASSERT_EQ(spdy_server_g, string_value_g); | 236 ASSERT_EQ(spdy_server_g, string_value_g); |
236 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | 237 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); |
237 ASSERT_EQ(spdy_server_m, string_value_m); | 238 ASSERT_EQ(spdy_server_m, string_value_m); |
238 } | 239 } |
239 | 240 |
240 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 241 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
241 | 242 |
242 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 243 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
243 HostPortPair test_host_port_pair("foo", 80); | 244 HostPortPair test_host_port_pair("foo", 80); |
244 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 245 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
245 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 246 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
246 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 247 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); |
247 const AlternateProtocolInfo alternate = | 248 const AlternativeService alternative_service = |
248 impl_.GetAlternateProtocol(test_host_port_pair); | 249 impl_.GetAlternativeService(test_host_port_pair); |
249 EXPECT_EQ(443, alternate.port); | 250 EXPECT_EQ(443, alternative_service.port); |
250 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 251 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); |
251 | 252 |
252 impl_.Clear(); | 253 impl_.Clear(); |
253 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 254 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
254 } | 255 } |
255 | 256 |
256 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { | 257 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { |
257 HostPortPair test_host_port_pair("foo", 80); | 258 HostPortPair test_host_port_pair("foo", 80); |
258 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .99); | 259 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .99); |
259 | 260 |
260 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 261 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
261 } | 262 } |
262 | 263 |
263 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { | 264 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { |
264 impl_.SetAlternateProtocolProbabilityThreshold(.25); | 265 impl_.SetAlternateProtocolProbabilityThreshold(.25); |
265 | 266 |
266 HostPortPair test_host_port_pair("foo", 80); | 267 HostPortPair test_host_port_pair("foo", 80); |
267 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); | 268 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 0.5); |
268 | 269 |
269 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 270 AlternateProtocolMap::const_iterator it = |
270 const AlternateProtocolInfo alternate = | 271 impl_.alternate_protocol_map().Peek(test_host_port_pair); |
271 impl_.GetAlternateProtocol(test_host_port_pair); | 272 EXPECT_TRUE(it != impl_.alternate_protocol_map().end()); |
272 EXPECT_EQ(443, alternate.port); | 273 EXPECT_EQ(443, it->second.port); |
273 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 274 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
274 EXPECT_EQ(.5, alternate.probability); | 275 EXPECT_EQ(0.5, it->second.probability); |
275 } | 276 } |
276 | 277 |
277 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { | 278 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { |
278 impl_.SetAlternateProtocolProbabilityThreshold(.75); | 279 impl_.SetAlternateProtocolProbabilityThreshold(.75); |
279 | 280 |
280 HostPortPair test_host_port_pair("foo", 80); | 281 HostPortPair test_host_port_pair("foo", 80); |
281 | 282 |
282 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); | 283 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); |
283 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 284 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
284 } | 285 } |
285 | 286 |
286 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 287 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
287 HostPortPair test_host_port_pair1("foo1", 80); | 288 HostPortPair test_host_port_pair1("foo1", 80); |
288 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); | 289 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); |
289 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); | 290 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); |
290 HostPortPair test_host_port_pair2("foo2", 80); | 291 HostPortPair test_host_port_pair2("foo2", 80); |
291 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1.0); | 292 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1.0); |
292 | 293 |
293 AlternateProtocolMap alternate_protocol_map( | 294 AlternateProtocolMap alternate_protocol_map( |
294 AlternateProtocolMap::NO_AUTO_EVICT); | 295 AlternateProtocolMap::NO_AUTO_EVICT); |
295 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); | 296 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); |
296 alternate_protocol_map.Put(test_host_port_pair2, alternate); | 297 alternate_protocol_map.Put(test_host_port_pair2, alternate); |
297 HostPortPair test_host_port_pair3("foo3", 80); | 298 HostPortPair test_host_port_pair3("foo3", 80); |
298 alternate.port = 1234; | 299 alternate.port = 1234; |
299 alternate_protocol_map.Put(test_host_port_pair3, alternate); | 300 alternate_protocol_map.Put(test_host_port_pair3, alternate); |
300 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); | 301 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); |
301 | 302 |
302 // Verify test_host_port_pair3 is the MRU server. | 303 // Verify test_host_port_pair3 is the MRU server. |
303 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 304 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
304 AlternateProtocolMap::const_iterator it = map.begin(); | 305 AlternateProtocolMap::const_iterator it = map.begin(); |
305 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); | 306 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); |
306 EXPECT_EQ(1234, it->second.port); | 307 EXPECT_EQ(1234, it->second.port); |
307 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 308 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
308 | 309 |
309 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair1)); | 310 ASSERT_TRUE(HasAlternativeService(test_host_port_pair1)); |
310 const AlternativeService alternative_service( | 311 AlternativeService alternative_service(NPN_SPDY_3, |
311 NPN_SPDY_3, test_host_port_pair1.host(), 443); | 312 test_host_port_pair1.host(), 443); |
312 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 313 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
313 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); | 314 alternative_service = impl_.GetAlternativeService(test_host_port_pair2); |
314 EXPECT_EQ(123, alternate.port); | 315 EXPECT_EQ(123, alternative_service.port); |
315 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 316 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); |
316 } | 317 } |
317 | 318 |
318 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { | 319 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { |
319 HostPortPair test_host_port_pair1("foo1", 80); | 320 HostPortPair test_host_port_pair1("foo1", 80); |
320 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); | 321 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); |
321 HostPortPair test_host_port_pair2("foo2", 80); | 322 HostPortPair test_host_port_pair2("foo2", 80); |
322 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); | 323 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); |
323 | 324 |
324 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 325 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
325 AlternateProtocolMap::const_iterator it = map.begin(); | 326 AlternateProtocolMap::const_iterator it = map.begin(); |
326 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); | 327 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); |
327 EXPECT_EQ(1234, it->second.port); | 328 EXPECT_EQ(1234, it->second.port); |
328 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 329 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
329 | 330 |
330 // GetAlternateProtocol should reorder the AlternateProtocol map. | 331 // GetAlternativeService should reorder the AlternateProtocol map. |
331 AlternateProtocolInfo alternate = | 332 const AlternativeService alternative_service = |
332 impl_.GetAlternateProtocol(test_host_port_pair1); | 333 impl_.GetAlternativeService(test_host_port_pair1); |
333 EXPECT_EQ(443, alternate.port); | 334 EXPECT_EQ(443, alternative_service.port); |
334 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 335 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); |
335 it = map.begin(); | 336 it = map.begin(); |
336 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | 337 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); |
337 EXPECT_EQ(443, it->second.port); | 338 EXPECT_EQ(443, it->second.port); |
338 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 339 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
339 } | 340 } |
340 | 341 |
341 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 342 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
342 HostPortPair test_host_port_pair("foo", 80); | 343 HostPortPair test_host_port_pair("foo", 80); |
343 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 344 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
344 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 345 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
345 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 346 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); |
346 const AlternativeService alternative_service(NPN_SPDY_3, | 347 const AlternativeService alternative_service(NPN_SPDY_3, |
347 test_host_port_pair.host(), 443); | 348 test_host_port_pair.host(), 443); |
348 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 349 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
349 | 350 |
350 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); | 351 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); |
351 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 352 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
352 const AlternateProtocolInfo alternate = | 353 EXPECT_EQ(1234, impl_.GetAlternativeService(test_host_port_pair).port); |
353 impl_.GetAlternateProtocol(test_host_port_pair); | |
354 EXPECT_EQ(1234, alternate.port); | |
355 } | 354 } |
356 | 355 |
357 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 356 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
358 HostPortPair test_host_port_pair("foo", 80); | 357 HostPortPair test_host_port_pair("foo", 80); |
359 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 358 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
360 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 359 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
361 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 360 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); |
362 const AlternativeService alternative_service(NPN_SPDY_3, | 361 const AlternativeService alternative_service(NPN_SPDY_3, |
363 test_host_port_pair.host(), 443); | 362 test_host_port_pair.host(), 443); |
364 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 363 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
365 impl_.ClearAlternateProtocol(test_host_port_pair); | 364 impl_.ClearAlternateProtocol(test_host_port_pair); |
366 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 365 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
367 } | 366 } |
368 | 367 |
369 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { | 368 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { |
370 HostPortPair host_port_pair("foo", 80); | 369 HostPortPair host_port_pair("foo", 80); |
371 impl_.SetAlternateProtocol(host_port_pair, 443, NPN_SPDY_4, 1.0); | 370 impl_.SetAlternateProtocol(host_port_pair, 443, NPN_SPDY_4, 1.0); |
(...skipping 12 matching lines...) Expand all Loading... |
384 } | 383 } |
385 | 384 |
386 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { | 385 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { |
387 // Test forced alternate protocols. | 386 // Test forced alternate protocols. |
388 | 387 |
389 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); | 388 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); |
390 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); | 389 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); |
391 | 390 |
392 // Verify the forced protocol. | 391 // Verify the forced protocol. |
393 HostPortPair test_host_port_pair("foo", 80); | 392 HostPortPair test_host_port_pair("foo", 80); |
394 EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 393 EXPECT_TRUE(HasAlternativeService(test_host_port_pair)); |
395 AlternateProtocolInfo alternate = | 394 AlternativeService alternative_service = |
396 impl_.GetAlternateProtocol(test_host_port_pair); | 395 impl_.GetAlternativeService(test_host_port_pair); |
397 EXPECT_EQ(default_protocol.port, alternate.port); | 396 EXPECT_EQ(default_protocol.port, alternative_service.port); |
398 EXPECT_EQ(default_protocol.protocol, alternate.protocol); | 397 EXPECT_EQ(default_protocol.protocol, alternative_service.protocol); |
399 | 398 |
400 // Verify the real protocol overrides the forced protocol. | 399 // Verify the real protocol overrides the forced protocol. |
401 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 400 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
402 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 401 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); |
403 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 402 alternative_service = impl_.GetAlternativeService(test_host_port_pair); |
404 EXPECT_EQ(443, alternate.port); | 403 EXPECT_EQ(443, alternative_service.port); |
405 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 404 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); |
406 | 405 |
407 // Turn off the static, forced alternate protocol so that tests don't | 406 // Turn off the static, forced alternate protocol so that tests don't |
408 // have this state. | 407 // have this state. |
409 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); | 408 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); |
410 | 409 |
411 // Verify the forced protocol is off. | 410 // Verify the forced protocol is off. |
412 HostPortPair test_host_port_pair2("bar", 80); | 411 HostPortPair test_host_port_pair2("bar", 80); |
413 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair2)); | 412 EXPECT_FALSE(HasAlternativeService(test_host_port_pair2)); |
414 } | 413 } |
415 | 414 |
416 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { | 415 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { |
417 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 416 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
418 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 417 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
419 | 418 |
420 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 419 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
421 EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); | 420 EXPECT_FALSE(HasAlternativeService(canonical_port_pair)); |
422 | 421 |
423 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 422 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
424 | 423 |
425 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 424 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
426 canonical_protocol.protocol, 1.0); | 425 canonical_protocol.protocol, 1.0); |
427 // Verify the forced protocol. | 426 // Verify the forced protocol. |
428 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 427 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); |
429 AlternateProtocolInfo alternate = | 428 const AlternativeService alternative_service = |
430 impl_.GetAlternateProtocol(test_host_port_pair); | 429 impl_.GetAlternativeService(test_host_port_pair); |
431 EXPECT_EQ(canonical_protocol.port, alternate.port); | 430 EXPECT_EQ(canonical_protocol.port, alternative_service.port); |
432 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol); | 431 EXPECT_EQ(canonical_protocol.protocol, alternative_service.protocol); |
433 | 432 |
434 // Verify the canonical suffix. | 433 // Verify the canonical suffix. |
435 EXPECT_EQ(".c.youtube.com", | 434 EXPECT_EQ(".c.youtube.com", |
436 impl_.GetCanonicalSuffix(test_host_port_pair.host())); | 435 impl_.GetCanonicalSuffix(test_host_port_pair.host())); |
437 EXPECT_EQ(".c.youtube.com", | 436 EXPECT_EQ(".c.youtube.com", |
438 impl_.GetCanonicalSuffix(canonical_port_pair.host())); | 437 impl_.GetCanonicalSuffix(canonical_port_pair.host())); |
439 } | 438 } |
440 | 439 |
441 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { | 440 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { |
442 impl_.SetAlternateProtocolProbabilityThreshold(0.02); | 441 impl_.SetAlternateProtocolProbabilityThreshold(0.02); |
443 | 442 |
444 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 443 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
445 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 444 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
446 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01); | 445 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01); |
447 | 446 |
448 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 447 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
449 canonical_protocol.protocol, | 448 canonical_protocol.protocol, |
450 canonical_protocol.probability); | 449 canonical_protocol.probability); |
451 EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); | 450 EXPECT_FALSE(HasAlternativeService(canonical_port_pair)); |
452 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 451 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
453 } | 452 } |
454 | 453 |
455 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { | 454 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { |
456 impl_.SetAlternateProtocolProbabilityThreshold(0.02); | 455 impl_.SetAlternateProtocolProbabilityThreshold(0.02); |
457 | 456 |
458 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 457 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
459 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 458 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
460 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03); | 459 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03); |
461 | 460 |
462 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 461 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
463 canonical_protocol.protocol, | 462 canonical_protocol.protocol, |
464 canonical_protocol.probability); | 463 canonical_protocol.probability); |
465 EXPECT_TRUE(HasAlternateProtocol(canonical_port_pair)); | 464 EXPECT_TRUE(HasAlternativeService(canonical_port_pair)); |
466 EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 465 EXPECT_TRUE(HasAlternativeService(test_host_port_pair)); |
467 } | 466 } |
468 | 467 |
469 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 468 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
470 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 469 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
471 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 470 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
472 | 471 |
473 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 472 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
474 | 473 |
475 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 474 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
476 canonical_protocol.protocol, | 475 canonical_protocol.protocol, |
477 canonical_protocol.probability); | 476 canonical_protocol.probability); |
478 | 477 |
479 impl_.ClearAlternateProtocol(canonical_port_pair); | 478 impl_.ClearAlternateProtocol(canonical_port_pair); |
480 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 479 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
481 } | 480 } |
482 | 481 |
483 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { | 482 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { |
484 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 483 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
485 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 484 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
486 | 485 |
487 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 486 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
488 | 487 |
489 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 488 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
490 canonical_protocol.protocol, | 489 canonical_protocol.protocol, |
491 canonical_protocol.probability); | 490 canonical_protocol.probability); |
492 | 491 |
493 impl_.SetBrokenAlternateProtocol(canonical_port_pair); | 492 impl_.SetBrokenAlternateProtocol(canonical_port_pair); |
494 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 493 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
495 } | 494 } |
496 | 495 |
497 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 496 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
498 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 497 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
499 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 498 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
500 | 499 |
501 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 500 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
502 | 501 |
503 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 502 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
504 canonical_protocol.protocol, | 503 canonical_protocol.protocol, |
505 canonical_protocol.probability); | 504 canonical_protocol.probability); |
506 | 505 |
507 impl_.Clear(); | 506 impl_.Clear(); |
508 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 507 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
509 } | 508 } |
510 | 509 |
511 TEST_F(AlternateProtocolServerPropertiesTest, | 510 TEST_F(AlternateProtocolServerPropertiesTest, |
512 ExpireBrokenAlternateProtocolMappings) { | 511 ExpireBrokenAlternateProtocolMappings) { |
513 HostPortPair host_port_pair("foo", 443); | 512 HostPortPair host_port_pair("foo", 443); |
514 AlternativeService alternative_service(QUIC, "foo", 443); | 513 AlternativeService alternative_service(QUIC, "foo", 443); |
515 impl_.SetAlternateProtocol(host_port_pair, 443, QUIC, 1.0); | 514 impl_.SetAlternateProtocol(host_port_pair, 443, QUIC, 1.0); |
516 EXPECT_TRUE(HasAlternateProtocol(host_port_pair)); | 515 EXPECT_TRUE(HasAlternativeService(host_port_pair)); |
517 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 516 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
518 EXPECT_FALSE(impl_.WasAlternateProtocolRecentlyBroken(host_port_pair)); | 517 EXPECT_FALSE(impl_.WasAlternateProtocolRecentlyBroken(host_port_pair)); |
519 | 518 |
520 base::TimeTicks past = | 519 base::TimeTicks past = |
521 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); | 520 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); |
522 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( | 521 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( |
523 impl_, alternative_service, past); | 522 impl_, alternative_service, past); |
524 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 523 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
525 EXPECT_TRUE(impl_.WasAlternateProtocolRecentlyBroken(host_port_pair)); | 524 EXPECT_TRUE(impl_.WasAlternateProtocolRecentlyBroken(host_port_pair)); |
526 | 525 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 793 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); |
795 | 794 |
796 impl_.Clear(); | 795 impl_.Clear(); |
797 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); | 796 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); |
798 EXPECT_EQ(NULL, stats3); | 797 EXPECT_EQ(NULL, stats3); |
799 } | 798 } |
800 | 799 |
801 } // namespace | 800 } // namespace |
802 | 801 |
803 } // namespace net | 802 } // namespace net |
OLD | NEW |