[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | // |
| 5 | // HttpAlternateProtocols is an in-memory data structure used for keeping track |
| 6 | // of which HTTP HostPortPairs have an alternate protocol that can be used |
| 7 | // instead of HTTP on a different port. |
| 8 | |
| 9 | #include "net/http/http_alternate_protocols.h" |
| 10 | #include "testing/gtest/include/gtest/gtest.h" |
| 11 | |
| 12 | namespace net { |
| 13 | namespace { |
| 14 | |
| 15 | TEST(HttpAlternateProtocols, Basic) { |
| 16 | HttpAlternateProtocols alternate_protocols; |
| 17 | HostPortPair test_host_port_pair; |
| 18 | test_host_port_pair.host = "foo"; |
| 19 | test_host_port_pair.port = 80; |
| 20 | EXPECT_FALSE( |
| 21 | alternate_protocols.HasAlternateProtocolFor(test_host_port_pair)); |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 22 | alternate_protocols.SetAlternateProtocolFor( |
| 23 | test_host_port_pair, 443, HttpAlternateProtocols::NPN_SPDY_1); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 24 | ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(test_host_port_pair)); |
| 25 | const HttpAlternateProtocols::PortProtocolPair alternate = |
| 26 | alternate_protocols.GetAlternateProtocolFor(test_host_port_pair); |
| 27 | EXPECT_EQ(443, alternate.port); |
[email protected] | 31e2c69e | 2010-04-15 18:06:06 | [diff] [blame] | 28 | EXPECT_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | TEST(HttpAlternateProtocols, SetBroken) { |
| 32 | HttpAlternateProtocols alternate_protocols; |
| 33 | HostPortPair test_host_port_pair; |
| 34 | test_host_port_pair.host = "foo"; |
| 35 | test_host_port_pair.port = 80; |
| 36 | alternate_protocols.MarkBrokenAlternateProtocolFor(test_host_port_pair); |
| 37 | ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(test_host_port_pair)); |
| 38 | HttpAlternateProtocols::PortProtocolPair alternate = |
| 39 | alternate_protocols.GetAlternateProtocolFor(test_host_port_pair); |
| 40 | EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol); |
| 41 | |
| 42 | alternate_protocols.SetAlternateProtocolFor( |
| 43 | test_host_port_pair, |
| 44 | 1234, |
[email protected] | 9f898098 | 2010-04-29 19:30:35 | [diff] [blame] | 45 | HttpAlternateProtocols::NPN_SPDY_1); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 46 | alternate = alternate_protocols.GetAlternateProtocolFor(test_host_port_pair); |
| 47 | EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol) |
| 48 | << "Second attempt should be ignored."; |
| 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 | } // namespace net |