| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 ASSERT_EQ(spdy_server_g, string_value_m); | 182 ASSERT_EQ(spdy_server_g, string_value_m); |
| 183 ASSERT_EQ(spdy_server_m, string_value_g); | 183 ASSERT_EQ(spdy_server_m, string_value_g); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 187 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
| 188 | 188 |
| 189 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 189 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
| 190 HostPortPair test_host_port_pair("foo", 80); | 190 HostPortPair test_host_port_pair("foo", 80); |
| 191 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 191 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 192 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_1); | 192 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_2); |
| 193 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 193 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 194 const PortAlternateProtocolPair alternate = | 194 const PortAlternateProtocolPair alternate = |
| 195 impl_.GetAlternateProtocol(test_host_port_pair); | 195 impl_.GetAlternateProtocol(test_host_port_pair); |
| 196 EXPECT_EQ(443, alternate.port); | 196 EXPECT_EQ(443, alternate.port); |
| 197 EXPECT_EQ(NPN_SPDY_1, alternate.protocol); | 197 EXPECT_EQ(NPN_SPDY_2, alternate.protocol); |
| 198 | 198 |
| 199 impl_.Clear(); | 199 impl_.Clear(); |
| 200 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 200 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 203 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
| 204 HostPortPair test_host_port_pair1("foo1", 80); | 204 HostPortPair test_host_port_pair1("foo1", 80); |
| 205 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); | 205 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); |
| 206 HostPortPair test_host_port_pair2("foo2", 80); | 206 HostPortPair test_host_port_pair2("foo2", 80); |
| 207 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_1); | 207 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_2); |
| 208 | 208 |
| 209 AlternateProtocolMap alternate_protocol_map; | 209 AlternateProtocolMap alternate_protocol_map; |
| 210 PortAlternateProtocolPair port_alternate_protocol_pair; | 210 PortAlternateProtocolPair port_alternate_protocol_pair; |
| 211 port_alternate_protocol_pair.port = 123; | 211 port_alternate_protocol_pair.port = 123; |
| 212 port_alternate_protocol_pair.protocol = NPN_SPDY_2; | 212 port_alternate_protocol_pair.protocol = NPN_SPDY_2; |
| 213 alternate_protocol_map[test_host_port_pair2] = port_alternate_protocol_pair; | 213 alternate_protocol_map[test_host_port_pair2] = port_alternate_protocol_pair; |
| 214 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); | 214 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); |
| 215 | 215 |
| 216 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); | 216 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); |
| 217 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); | 217 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 228 HostPortPair test_host_port_pair("foo", 80); | 228 HostPortPair test_host_port_pair("foo", 80); |
| 229 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 229 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
| 230 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 230 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 231 PortAlternateProtocolPair alternate = | 231 PortAlternateProtocolPair alternate = |
| 232 impl_.GetAlternateProtocol(test_host_port_pair); | 232 impl_.GetAlternateProtocol(test_host_port_pair); |
| 233 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | 233 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
| 234 | 234 |
| 235 impl_.SetAlternateProtocol( | 235 impl_.SetAlternateProtocol( |
| 236 test_host_port_pair, | 236 test_host_port_pair, |
| 237 1234, | 237 1234, |
| 238 NPN_SPDY_1); | 238 NPN_SPDY_2); |
| 239 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 239 alternate = impl_.GetAlternateProtocol(test_host_port_pair); |
| 240 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol) | 240 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol) |
| 241 << "Second attempt should be ignored."; | 241 << "Second attempt should be ignored."; |
| 242 } | 242 } |
| 243 | 243 |
| 244 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { | 244 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { |
| 245 // Test forced alternate protocols. | 245 // Test forced alternate protocols. |
| 246 | 246 |
| 247 PortAlternateProtocolPair default_protocol; | 247 PortAlternateProtocolPair default_protocol; |
| 248 default_protocol.port = 1234; | 248 default_protocol.port = 1234; |
| 249 default_protocol.protocol = NPN_SPDY_2; | 249 default_protocol.protocol = NPN_SPDY_2; |
| 250 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); | 250 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); |
| 251 | 251 |
| 252 // Verify the forced protocol. | 252 // Verify the forced protocol. |
| 253 HostPortPair test_host_port_pair("foo", 80); | 253 HostPortPair test_host_port_pair("foo", 80); |
| 254 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 254 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 255 PortAlternateProtocolPair alternate = | 255 PortAlternateProtocolPair alternate = |
| 256 impl_.GetAlternateProtocol(test_host_port_pair); | 256 impl_.GetAlternateProtocol(test_host_port_pair); |
| 257 EXPECT_EQ(default_protocol.port, alternate.port); | 257 EXPECT_EQ(default_protocol.port, alternate.port); |
| 258 EXPECT_EQ(default_protocol.protocol, alternate.protocol); | 258 EXPECT_EQ(default_protocol.protocol, alternate.protocol); |
| 259 | 259 |
| 260 // Verify the real protocol overrides the forced protocol. | 260 // Verify the real protocol overrides the forced protocol. |
| 261 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_1); | 261 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_2); |
| 262 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 262 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 263 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 263 alternate = impl_.GetAlternateProtocol(test_host_port_pair); |
| 264 EXPECT_EQ(443, alternate.port); | 264 EXPECT_EQ(443, alternate.port); |
| 265 EXPECT_EQ(NPN_SPDY_1, alternate.protocol); | 265 EXPECT_EQ(NPN_SPDY_2, alternate.protocol); |
| 266 | 266 |
| 267 // Turn off the static, forced alternate protocol so that tests don't | 267 // Turn off the static, forced alternate protocol so that tests don't |
| 268 // have this state. | 268 // have this state. |
| 269 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); | 269 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); |
| 270 | 270 |
| 271 // Verify the forced protocol is off. | 271 // Verify the forced protocol is off. |
| 272 HostPortPair test_host_port_pair2("bar", 80); | 272 HostPortPair test_host_port_pair2("bar", 80); |
| 273 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair2)); | 273 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair2)); |
| 274 } | 274 } |
| 275 | 275 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 EXPECT_EQ(value3, flags_and_value3_ret.second); | 407 EXPECT_EQ(value3, flags_and_value3_ret.second); |
| 408 | 408 |
| 409 impl_.Clear(); | 409 impl_.Clear(); |
| 410 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_google).size()); | 410 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_google).size()); |
| 411 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_docs).size()); | 411 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_docs).size()); |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace | 414 } // namespace |
| 415 | 415 |
| 416 } // namespace net | 416 } // namespace net |
| OLD | NEW |