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; |
| 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 class HttpServerPropertiesImplTest : public testing::Test { | 28 class HttpServerPropertiesImplTest : public testing::Test { |
27 protected: | 29 protected: |
28 HttpServerPropertiesImpl impl_; | 30 HttpServerPropertiesImpl impl_; |
29 }; | 31 }; |
30 | 32 |
31 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 33 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
32 | 34 |
33 TEST_F(SpdyServerPropertiesTest, Initialize) { | 35 TEST_F(SpdyServerPropertiesTest, Initialize) { |
(...skipping 19 matching lines...) Expand all Loading... |
53 spdy_servers1.push_back(spdy_server_g); | 55 spdy_servers1.push_back(spdy_server_g); |
54 impl_.InitializeSpdyServers(&spdy_servers1, true); | 56 impl_.InitializeSpdyServers(&spdy_servers1, true); |
55 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | 57 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); |
56 | 58 |
57 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy | 59 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy |
58 // servers. | 60 // servers. |
59 std::vector<std::string> spdy_servers2; | 61 std::vector<std::string> spdy_servers2; |
60 spdy_servers2.push_back(spdy_server_g); | 62 spdy_servers2.push_back(spdy_server_g); |
61 spdy_servers2.push_back(spdy_server_d); | 63 spdy_servers2.push_back(spdy_server_d); |
62 impl_.InitializeSpdyServers(&spdy_servers2, true); | 64 impl_.InitializeSpdyServers(&spdy_servers2, true); |
| 65 |
| 66 // Verify spdy_server_g and spdy_server_d are in the list in the same order. |
| 67 base::ListValue spdy_server_list; |
| 68 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 69 EXPECT_EQ(2U, spdy_server_list.GetSize()); |
| 70 std::string string_value_g; |
| 71 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 72 ASSERT_EQ(spdy_server_g, string_value_g); |
| 73 std::string string_value_d; |
| 74 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_d)); |
| 75 ASSERT_EQ(spdy_server_d, string_value_d); |
63 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | 76 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); |
64 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs)); | 77 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs)); |
65 } | 78 } |
66 | 79 |
67 TEST_F(SpdyServerPropertiesTest, SupportsSpdyTest) { | 80 TEST_F(SpdyServerPropertiesTest, SupportsSpdyTest) { |
68 HostPortPair spdy_server_empty(std::string(), 443); | 81 HostPortPair spdy_server_empty(std::string(), 443); |
69 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty)); | 82 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty)); |
70 | 83 |
71 // Add www.google.com:443 as supporting SPDY. | 84 // Add www.google.com:443 as supporting SPDY. |
72 HostPortPair spdy_server_google("www.google.com", 443); | 85 HostPortPair spdy_server_google("www.google.com", 443); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 136 |
124 impl_.Clear(); | 137 impl_.Clear(); |
125 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | 138 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); |
126 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); | 139 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); |
127 } | 140 } |
128 | 141 |
129 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { | 142 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { |
130 base::ListValue spdy_server_list; | 143 base::ListValue spdy_server_list; |
131 | 144 |
132 // Check there are no spdy_servers. | 145 // Check there are no spdy_servers. |
133 impl_.GetSpdyServerList(&spdy_server_list); | 146 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
134 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 147 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
135 | 148 |
136 // Check empty server is not added. | 149 // Check empty server is not added. |
137 HostPortPair spdy_server_empty(std::string(), 443); | 150 HostPortPair spdy_server_empty(std::string(), 443); |
138 impl_.SetSupportsSpdy(spdy_server_empty, true); | 151 impl_.SetSupportsSpdy(spdy_server_empty, true); |
139 impl_.GetSpdyServerList(&spdy_server_list); | 152 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
140 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 153 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
141 | 154 |
142 std::string string_value_g; | 155 std::string string_value_g; |
143 std::string string_value_m; | 156 std::string string_value_m; |
144 HostPortPair spdy_server_google("www.google.com", 443); | 157 HostPortPair spdy_server_google("www.google.com", 443); |
145 std::string spdy_server_g = | 158 std::string spdy_server_g = |
146 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); | 159 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); |
147 HostPortPair spdy_server_mail("mail.google.com", 443); | 160 HostPortPair spdy_server_mail("mail.google.com", 443); |
148 std::string spdy_server_m = | 161 std::string spdy_server_m = |
149 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail); | 162 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail); |
150 | 163 |
151 // Add www.google.com:443 as not supporting SPDY. | 164 // Add www.google.com:443 as not supporting SPDY. |
152 impl_.SetSupportsSpdy(spdy_server_google, false); | 165 impl_.SetSupportsSpdy(spdy_server_google, false); |
153 impl_.GetSpdyServerList(&spdy_server_list); | 166 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
154 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 167 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
155 | 168 |
156 // Add www.google.com:443 as supporting SPDY. | 169 // Add www.google.com:443 as supporting SPDY. |
157 impl_.SetSupportsSpdy(spdy_server_google, true); | 170 impl_.SetSupportsSpdy(spdy_server_google, true); |
158 impl_.GetSpdyServerList(&spdy_server_list); | 171 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
159 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 172 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
160 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 173 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
161 ASSERT_EQ(spdy_server_g, string_value_g); | 174 ASSERT_EQ(spdy_server_g, string_value_g); |
162 | 175 |
163 // Add mail.google.com:443 as not supporting SPDY. | 176 // Add mail.google.com:443 as not supporting SPDY. |
164 impl_.SetSupportsSpdy(spdy_server_mail, false); | 177 impl_.SetSupportsSpdy(spdy_server_mail, false); |
165 impl_.GetSpdyServerList(&spdy_server_list); | 178 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
166 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 179 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
167 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 180 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
168 ASSERT_EQ(spdy_server_g, string_value_g); | 181 ASSERT_EQ(spdy_server_g, string_value_g); |
169 | 182 |
170 // Add mail.google.com:443 as supporting SPDY. | 183 // Add mail.google.com:443 as supporting SPDY. |
171 impl_.SetSupportsSpdy(spdy_server_mail, true); | 184 impl_.SetSupportsSpdy(spdy_server_mail, true); |
172 impl_.GetSpdyServerList(&spdy_server_list); | 185 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
173 ASSERT_EQ(2U, spdy_server_list.GetSize()); | 186 ASSERT_EQ(2U, spdy_server_list.GetSize()); |
174 | 187 |
175 // Verify www.google.com:443 and mail.google.com:443 are in the list. | 188 // Verify www.google.com:443 and mail.google.com:443 are in the list. |
| 189 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); |
| 190 ASSERT_EQ(spdy_server_m, string_value_m); |
| 191 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g)); |
| 192 ASSERT_EQ(spdy_server_g, string_value_g); |
| 193 |
| 194 // Request for only one server and verify that we get only one server. |
| 195 impl_.GetSpdyServerList(&spdy_server_list, 1); |
| 196 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
| 197 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); |
| 198 ASSERT_EQ(spdy_server_m, string_value_m); |
| 199 } |
| 200 |
| 201 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { |
| 202 base::ListValue spdy_server_list; |
| 203 |
| 204 std::string string_value_g; |
| 205 std::string string_value_m; |
| 206 HostPortPair spdy_server_google("www.google.com", 443); |
| 207 std::string spdy_server_g = |
| 208 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); |
| 209 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 210 std::string spdy_server_m = |
| 211 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail); |
| 212 |
| 213 // Add www.google.com:443 as supporting SPDY. |
| 214 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 215 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 216 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
176 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 217 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 218 ASSERT_EQ(spdy_server_g, string_value_g); |
| 219 |
| 220 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and |
| 221 // www.google.com:443 are in the list. |
| 222 impl_.SetSupportsSpdy(spdy_server_mail, true); |
| 223 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 224 ASSERT_EQ(2U, spdy_server_list.GetSize()); |
| 225 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); |
| 226 ASSERT_EQ(spdy_server_m, string_value_m); |
| 227 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g)); |
| 228 ASSERT_EQ(spdy_server_g, string_value_g); |
| 229 |
| 230 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it |
| 231 // is www.google.com:443 is the MRU server. |
| 232 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); |
| 233 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 234 ASSERT_EQ(2U, spdy_server_list.GetSize()); |
| 235 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 236 ASSERT_EQ(spdy_server_g, string_value_g); |
177 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | 237 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); |
178 if (string_value_g.compare(spdy_server_g) == 0) { | 238 ASSERT_EQ(spdy_server_m, string_value_m); |
179 ASSERT_EQ(spdy_server_g, string_value_g); | |
180 ASSERT_EQ(spdy_server_m, string_value_m); | |
181 } else { | |
182 ASSERT_EQ(spdy_server_g, string_value_m); | |
183 ASSERT_EQ(spdy_server_m, string_value_g); | |
184 } | |
185 } | 239 } |
186 | 240 |
187 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 241 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
188 | 242 |
189 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 243 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
190 HostPortPair test_host_port_pair("foo", 80); | 244 HostPortPair test_host_port_pair("foo", 80); |
191 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 245 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); |
192 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3); | 246 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3); |
193 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 247 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); |
194 const PortAlternateProtocolPair alternate = | 248 const PortAlternateProtocolPair alternate = |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 it1_ret = settings_map1_it_ret.find(id1); | 600 it1_ret = settings_map1_it_ret.find(id1); |
547 EXPECT_TRUE(it1_ret != settings_map1_it_ret.end()); | 601 EXPECT_TRUE(it1_ret != settings_map1_it_ret.end()); |
548 flags_and_value1_ret = it1_ret->second; | 602 flags_and_value1_ret = it1_ret->second; |
549 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 603 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
550 EXPECT_EQ(value1, flags_and_value1_ret.second); | 604 EXPECT_EQ(value1, flags_and_value1_ret.second); |
551 } | 605 } |
552 | 606 |
553 } // namespace | 607 } // namespace |
554 | 608 |
555 } // namespace net | 609 } // namespace net |
OLD | NEW |