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" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class ListValue; | 19 class ListValue; |
20 } | 20 } |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 const int kMaxSupportsSpdyServerHosts = 500; | 24 const int kMaxSupportsSpdyServerHosts = 500; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 class HttpServerPropertiesImplTest : public testing::Test { | 28 class HttpServerPropertiesImplTest : public testing::Test { |
29 protected: | 29 protected: |
| 30 bool HasAlternateProtocol(const HostPortPair& server) { |
| 31 const AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(server); |
| 32 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 33 } |
| 34 |
30 HttpServerPropertiesImpl impl_; | 35 HttpServerPropertiesImpl impl_; |
31 }; | 36 }; |
32 | 37 |
33 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 38 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
34 | 39 |
35 TEST_F(SpdyServerPropertiesTest, Initialize) { | 40 TEST_F(SpdyServerPropertiesTest, Initialize) { |
36 HostPortPair spdy_server_google("www.google.com", 443); | 41 HostPortPair spdy_server_google("www.google.com", 443); |
37 std::string spdy_server_g = spdy_server_google.ToString(); | 42 std::string spdy_server_g = spdy_server_google.ToString(); |
38 | 43 |
39 HostPortPair spdy_server_docs("docs.google.com", 443); | 44 HostPortPair spdy_server_docs("docs.google.com", 443); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 217 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
213 ASSERT_EQ(spdy_server_g, string_value_g); | 218 ASSERT_EQ(spdy_server_g, string_value_g); |
214 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | 219 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); |
215 ASSERT_EQ(spdy_server_m, string_value_m); | 220 ASSERT_EQ(spdy_server_m, string_value_m); |
216 } | 221 } |
217 | 222 |
218 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 223 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
219 | 224 |
220 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 225 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
221 HostPortPair test_host_port_pair("foo", 80); | 226 HostPortPair test_host_port_pair("foo", 80); |
222 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 227 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
223 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 228 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
224 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 229 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
225 const AlternateProtocolInfo alternate = | 230 const AlternateProtocolInfo alternate = |
226 impl_.GetAlternateProtocol(test_host_port_pair); | 231 impl_.GetAlternateProtocol(test_host_port_pair); |
227 EXPECT_EQ(443, alternate.port); | 232 EXPECT_EQ(443, alternate.port); |
228 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 233 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); |
229 | 234 |
230 impl_.Clear(); | 235 impl_.Clear(); |
231 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 236 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
232 } | 237 } |
233 | 238 |
234 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { | 239 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { |
235 HostPortPair test_host_port_pair("foo", 80); | 240 HostPortPair test_host_port_pair("foo", 80); |
236 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .99); | 241 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .99); |
237 | 242 |
238 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 243 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
239 } | 244 } |
240 | 245 |
241 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { | 246 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { |
242 impl_.SetAlternateProtocolProbabilityThreshold(.25); | 247 impl_.SetAlternateProtocolProbabilityThreshold(.25); |
243 | 248 |
244 HostPortPair test_host_port_pair("foo", 80); | 249 HostPortPair test_host_port_pair("foo", 80); |
245 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); | 250 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); |
246 | 251 |
247 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 252 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
248 const AlternateProtocolInfo alternate = | 253 const AlternateProtocolInfo alternate = |
249 impl_.GetAlternateProtocol(test_host_port_pair); | 254 impl_.GetAlternateProtocol(test_host_port_pair); |
250 EXPECT_EQ(443, alternate.port); | 255 EXPECT_EQ(443, alternate.port); |
251 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 256 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); |
252 EXPECT_EQ(.5, alternate.probability); | 257 EXPECT_EQ(.5, alternate.probability); |
253 } | 258 } |
254 | 259 |
255 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { | 260 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { |
256 impl_.SetAlternateProtocolProbabilityThreshold(.75); | 261 impl_.SetAlternateProtocolProbabilityThreshold(.75); |
257 | 262 |
258 HostPortPair test_host_port_pair("foo", 80); | 263 HostPortPair test_host_port_pair("foo", 80); |
259 | 264 |
260 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); | 265 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); |
261 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 266 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
262 } | 267 } |
263 | 268 |
264 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 269 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
265 HostPortPair test_host_port_pair1("foo1", 80); | 270 HostPortPair test_host_port_pair1("foo1", 80); |
266 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); | 271 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); |
267 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); | 272 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); |
268 HostPortPair test_host_port_pair2("foo2", 80); | 273 HostPortPair test_host_port_pair2("foo2", 80); |
269 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1.0); | 274 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1.0); |
270 | 275 |
271 AlternateProtocolMap alternate_protocol_map( | 276 AlternateProtocolMap alternate_protocol_map( |
272 AlternateProtocolMap::NO_AUTO_EVICT); | 277 AlternateProtocolMap::NO_AUTO_EVICT); |
273 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); | 278 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); |
274 alternate_protocol_map.Put(test_host_port_pair2, alternate); | 279 alternate_protocol_map.Put(test_host_port_pair2, alternate); |
275 HostPortPair test_host_port_pair3("foo3", 80); | 280 HostPortPair test_host_port_pair3("foo3", 80); |
276 alternate.port = 1234; | 281 alternate.port = 1234; |
277 alternate_protocol_map.Put(test_host_port_pair3, alternate); | 282 alternate_protocol_map.Put(test_host_port_pair3, alternate); |
278 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); | 283 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); |
279 | 284 |
280 // Verify test_host_port_pair3 is the MRU server. | 285 // Verify test_host_port_pair3 is the MRU server. |
281 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 286 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
282 AlternateProtocolMap::const_iterator it = map.begin(); | 287 AlternateProtocolMap::const_iterator it = map.begin(); |
283 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); | 288 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); |
284 EXPECT_EQ(1234, it->second.port); | 289 EXPECT_EQ(1234, it->second.port); |
285 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 290 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
286 | 291 |
287 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); | 292 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair1)); |
288 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); | 293 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair2)); |
289 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); | 294 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); |
290 EXPECT_TRUE(alternate.is_broken); | 295 EXPECT_TRUE(alternate.is_broken); |
291 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); | 296 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); |
292 EXPECT_EQ(123, alternate.port); | 297 EXPECT_EQ(123, alternate.port); |
293 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 298 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); |
294 } | 299 } |
295 | 300 |
296 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) { | |
297 HostPortPair test_host_port_pair1("foo1", 80); | |
298 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); | |
299 HostPortPair test_host_port_pair2("foo2", 80); | |
300 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); | |
301 | |
302 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); | |
303 AlternateProtocolMap::const_iterator it = map.begin(); | |
304 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); | |
305 EXPECT_EQ(1234, it->second.port); | |
306 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | |
307 | |
308 // HasAlternateProtocol should reorder the AlternateProtocol map. | |
309 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); | |
310 it = map.begin(); | |
311 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | |
312 EXPECT_EQ(443, it->second.port); | |
313 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | |
314 } | |
315 | |
316 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { | 301 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { |
317 HostPortPair test_host_port_pair1("foo1", 80); | 302 HostPortPair test_host_port_pair1("foo1", 80); |
318 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); | 303 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); |
319 HostPortPair test_host_port_pair2("foo2", 80); | 304 HostPortPair test_host_port_pair2("foo2", 80); |
320 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); | 305 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); |
321 | 306 |
322 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 307 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
323 AlternateProtocolMap::const_iterator it = map.begin(); | 308 AlternateProtocolMap::const_iterator it = map.begin(); |
324 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); | 309 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); |
325 EXPECT_EQ(1234, it->second.port); | 310 EXPECT_EQ(1234, it->second.port); |
326 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 311 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
327 | 312 |
328 // GetAlternateProtocol should reorder the AlternateProtocol map. | 313 // GetAlternateProtocol should reorder the AlternateProtocol map. |
329 AlternateProtocolInfo alternate = | 314 AlternateProtocolInfo alternate = |
330 impl_.GetAlternateProtocol(test_host_port_pair1); | 315 impl_.GetAlternateProtocol(test_host_port_pair1); |
331 EXPECT_EQ(443, alternate.port); | 316 EXPECT_EQ(443, alternate.port); |
332 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 317 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); |
333 it = map.begin(); | 318 it = map.begin(); |
334 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | 319 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); |
335 EXPECT_EQ(443, it->second.port); | 320 EXPECT_EQ(443, it->second.port); |
336 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 321 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
337 } | 322 } |
338 | 323 |
339 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 324 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
340 HostPortPair test_host_port_pair("foo", 80); | 325 HostPortPair test_host_port_pair("foo", 80); |
341 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 326 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
342 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 327 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
343 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 328 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
344 AlternateProtocolInfo alternate = | 329 AlternateProtocolInfo alternate = |
345 impl_.GetAlternateProtocol(test_host_port_pair); | 330 impl_.GetAlternateProtocol(test_host_port_pair); |
346 EXPECT_TRUE(alternate.is_broken); | 331 EXPECT_TRUE(alternate.is_broken); |
347 | 332 |
348 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); | 333 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); |
349 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 334 alternate = impl_.GetAlternateProtocol(test_host_port_pair); |
350 EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored."; | 335 EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored."; |
351 } | 336 } |
352 | 337 |
353 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 338 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
354 HostPortPair test_host_port_pair("foo", 80); | 339 HostPortPair test_host_port_pair("foo", 80); |
355 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 340 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
356 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 341 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
357 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 342 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
358 AlternateProtocolInfo alternate = | 343 AlternateProtocolInfo alternate = |
359 impl_.GetAlternateProtocol(test_host_port_pair); | 344 impl_.GetAlternateProtocol(test_host_port_pair); |
360 EXPECT_TRUE(alternate.is_broken); | 345 EXPECT_TRUE(alternate.is_broken); |
361 impl_.ClearAlternateProtocol(test_host_port_pair); | 346 impl_.ClearAlternateProtocol(test_host_port_pair); |
362 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 347 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
363 } | 348 } |
364 | 349 |
365 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { | 350 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { |
366 // Test forced alternate protocols. | 351 // Test forced alternate protocols. |
367 | 352 |
368 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); | 353 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); |
369 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); | 354 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); |
370 | 355 |
371 // Verify the forced protocol. | 356 // Verify the forced protocol. |
372 HostPortPair test_host_port_pair("foo", 80); | 357 HostPortPair test_host_port_pair("foo", 80); |
373 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 358 EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
374 AlternateProtocolInfo alternate = | 359 AlternateProtocolInfo alternate = |
375 impl_.GetAlternateProtocol(test_host_port_pair); | 360 impl_.GetAlternateProtocol(test_host_port_pair); |
376 EXPECT_EQ(default_protocol.port, alternate.port); | 361 EXPECT_EQ(default_protocol.port, alternate.port); |
377 EXPECT_EQ(default_protocol.protocol, alternate.protocol); | 362 EXPECT_EQ(default_protocol.protocol, alternate.protocol); |
378 | 363 |
379 // Verify the real protocol overrides the forced protocol. | 364 // Verify the real protocol overrides the forced protocol. |
380 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 365 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
381 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 366 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
382 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 367 alternate = impl_.GetAlternateProtocol(test_host_port_pair); |
383 EXPECT_EQ(443, alternate.port); | 368 EXPECT_EQ(443, alternate.port); |
384 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 369 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); |
385 | 370 |
386 // Turn off the static, forced alternate protocol so that tests don't | 371 // Turn off the static, forced alternate protocol so that tests don't |
387 // have this state. | 372 // have this state. |
388 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); | 373 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); |
389 | 374 |
390 // Verify the forced protocol is off. | 375 // Verify the forced protocol is off. |
391 HostPortPair test_host_port_pair2("bar", 80); | 376 HostPortPair test_host_port_pair2("bar", 80); |
392 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair2)); | 377 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair2)); |
393 } | 378 } |
394 | 379 |
395 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { | 380 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { |
396 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 381 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
397 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 382 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
398 | 383 |
399 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 384 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
400 EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair)); | 385 EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); |
401 | 386 |
402 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 387 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
403 | 388 |
404 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 389 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
405 canonical_protocol.protocol, 1.0); | 390 canonical_protocol.protocol, 1.0); |
406 // Verify the forced protocol. | 391 // Verify the forced protocol. |
407 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 392 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
408 AlternateProtocolInfo alternate = | 393 AlternateProtocolInfo alternate = |
409 impl_.GetAlternateProtocol(test_host_port_pair); | 394 impl_.GetAlternateProtocol(test_host_port_pair); |
410 EXPECT_EQ(canonical_protocol.port, alternate.port); | 395 EXPECT_EQ(canonical_protocol.port, alternate.port); |
411 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol); | 396 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol); |
412 | 397 |
413 // Verify the canonical suffix. | 398 // Verify the canonical suffix. |
414 EXPECT_EQ(".c.youtube.com", | 399 EXPECT_EQ(".c.youtube.com", |
415 impl_.GetCanonicalSuffix(test_host_port_pair.host())); | 400 impl_.GetCanonicalSuffix(test_host_port_pair.host())); |
416 EXPECT_EQ(".c.youtube.com", | 401 EXPECT_EQ(".c.youtube.com", |
417 impl_.GetCanonicalSuffix(canonical_port_pair.host())); | 402 impl_.GetCanonicalSuffix(canonical_port_pair.host())); |
418 } | 403 } |
419 | 404 |
420 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { | 405 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { |
421 impl_.SetAlternateProtocolProbabilityThreshold(0.02); | 406 impl_.SetAlternateProtocolProbabilityThreshold(0.02); |
422 | 407 |
423 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 408 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
424 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 409 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
425 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01); | 410 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01); |
426 | 411 |
427 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 412 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
428 canonical_protocol.protocol, | 413 canonical_protocol.protocol, |
429 canonical_protocol.probability); | 414 canonical_protocol.probability); |
430 EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair)); | 415 EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); |
431 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 416 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
432 } | 417 } |
433 | 418 |
434 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { | 419 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { |
435 impl_.SetAlternateProtocolProbabilityThreshold(0.02); | 420 impl_.SetAlternateProtocolProbabilityThreshold(0.02); |
436 | 421 |
437 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 422 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
438 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 423 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
439 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03); | 424 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03); |
440 | 425 |
441 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 426 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
442 canonical_protocol.protocol, | 427 canonical_protocol.protocol, |
443 canonical_protocol.probability); | 428 canonical_protocol.probability); |
444 EXPECT_TRUE(impl_.HasAlternateProtocol(canonical_port_pair)); | 429 EXPECT_TRUE(HasAlternateProtocol(canonical_port_pair)); |
445 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 430 EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
446 } | 431 } |
447 | 432 |
448 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 433 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
449 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 434 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
450 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 435 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
451 | 436 |
452 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 437 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
453 | 438 |
454 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 439 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
455 canonical_protocol.protocol, | 440 canonical_protocol.protocol, |
456 canonical_protocol.probability); | 441 canonical_protocol.probability); |
457 | 442 |
458 impl_.ClearAlternateProtocol(canonical_port_pair); | 443 impl_.ClearAlternateProtocol(canonical_port_pair); |
459 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 444 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
460 } | 445 } |
461 | 446 |
462 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { | 447 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { |
463 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 448 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
464 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 449 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
465 | 450 |
466 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 451 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
467 | 452 |
468 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 453 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
469 canonical_protocol.protocol, | 454 canonical_protocol.protocol, |
470 canonical_protocol.probability); | 455 canonical_protocol.probability); |
471 | 456 |
472 impl_.SetBrokenAlternateProtocol(canonical_port_pair); | 457 impl_.SetBrokenAlternateProtocol(canonical_port_pair); |
473 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 458 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
474 } | 459 } |
475 | 460 |
476 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) { | 461 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) { |
477 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 462 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
478 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 463 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
479 | 464 |
480 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 465 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
481 | 466 |
482 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 467 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
483 canonical_protocol.protocol, | 468 canonical_protocol.protocol, |
484 canonical_protocol.probability); | 469 canonical_protocol.probability); |
485 | 470 |
486 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 471 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
487 AlternateProtocolInfo alternate = | 472 AlternateProtocolInfo alternate = |
488 impl_.GetAlternateProtocol(test_host_port_pair); | 473 impl_.GetAlternateProtocol(test_host_port_pair); |
489 EXPECT_TRUE(alternate.is_broken); | 474 EXPECT_TRUE(alternate.is_broken); |
490 } | 475 } |
491 | 476 |
492 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 477 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
493 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 478 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
494 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 479 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
495 | 480 |
496 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 481 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
497 | 482 |
498 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 483 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
499 canonical_protocol.protocol, | 484 canonical_protocol.protocol, |
500 canonical_protocol.probability); | 485 canonical_protocol.probability); |
501 | 486 |
502 impl_.Clear(); | 487 impl_.Clear(); |
503 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 488 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
504 } | 489 } |
505 | 490 |
506 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; | 491 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; |
507 | 492 |
508 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { | 493 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { |
509 HostPortPair spdy_server_google("www.google.com", 443); | 494 HostPortPair spdy_server_google("www.google.com", 443); |
510 | 495 |
511 // Check by initializing empty spdy settings. | 496 // Check by initializing empty spdy settings. |
512 SpdySettingsMap spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT); | 497 SpdySettingsMap spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT); |
513 impl_.InitializeSpdySettingsServers(&spdy_settings_map); | 498 impl_.InitializeSpdySettingsServers(&spdy_settings_map); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 752 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); |
768 | 753 |
769 impl_.Clear(); | 754 impl_.Clear(); |
770 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); | 755 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); |
771 EXPECT_EQ(NULL, stats3); | 756 EXPECT_EQ(NULL, stats3); |
772 } | 757 } |
773 | 758 |
774 } // namespace | 759 } // namespace |
775 | 760 |
776 } // namespace net | 761 } // namespace net |
OLD | NEW |