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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // when calling Serialize(). | 101 // when calling Serialize(). |
102 std::string spdy_server_g = https_www_server.Serialize(); | 102 std::string spdy_server_g = https_www_server.Serialize(); |
103 std::string spdy_server_p = http_photo_server.Serialize(); | 103 std::string spdy_server_p = http_photo_server.Serialize(); |
104 | 104 |
105 url::SchemeHostPort http_google_server("http", "www.google.com", 443); | 105 url::SchemeHostPort http_google_server("http", "www.google.com", 443); |
106 url::SchemeHostPort https_photos_server("https", "photos.google.com", 443); | 106 url::SchemeHostPort https_photos_server("https", "photos.google.com", 443); |
107 url::SchemeHostPort valid_google_server((GURL("https://www.google.com"))); | 107 url::SchemeHostPort valid_google_server((GURL("https://www.google.com"))); |
108 | 108 |
109 // Initializing https://www.google.com:443 and https://photos.google.com:443 | 109 // Initializing https://www.google.com:443 and https://photos.google.com:443 |
110 // as spdy servers. | 110 // as spdy servers. |
111 std::vector<std::string> spdy_servers1; | 111 std::unique_ptr<SpdyServersMap> spdy_servers1 = |
112 spdy_servers1.push_back(spdy_server_g); // Will be 0th index. | 112 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT); |
113 spdy_servers1.push_back(spdy_server_p); // Will be 1st index. | 113 spdy_servers1->Put(spdy_server_g, true); |
114 impl_.SetSpdyServers(&spdy_servers1, true); | 114 spdy_servers1->Put(spdy_server_p, true); |
| 115 impl_.SetSpdyServers(std::move(spdy_servers1)); |
115 EXPECT_TRUE(impl_.SupportsRequestPriority(http_photo_server)); | 116 EXPECT_TRUE(impl_.SupportsRequestPriority(http_photo_server)); |
116 EXPECT_TRUE(impl_.SupportsRequestPriority(https_www_server)); | 117 EXPECT_TRUE(impl_.SupportsRequestPriority(https_www_server)); |
117 EXPECT_FALSE(impl_.SupportsRequestPriority(http_google_server)); | 118 EXPECT_FALSE(impl_.SupportsRequestPriority(http_google_server)); |
118 EXPECT_FALSE(impl_.SupportsRequestPriority(https_photos_server)); | 119 EXPECT_FALSE(impl_.SupportsRequestPriority(https_photos_server)); |
119 EXPECT_TRUE(impl_.SupportsRequestPriority(valid_google_server)); | 120 EXPECT_TRUE(impl_.SupportsRequestPriority(valid_google_server)); |
120 } | 121 } |
121 | 122 |
122 TEST_F(SpdyServerPropertiesTest, Set) { | 123 TEST_F(SpdyServerPropertiesTest, Set) { |
123 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); | 124 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
124 std::string spdy_server_g = spdy_server_google.Serialize(); | 125 std::string spdy_server_g = spdy_server_google.Serialize(); |
125 | 126 |
126 url::SchemeHostPort spdy_server_photos("https", "photos.google.com", 443); | 127 url::SchemeHostPort spdy_server_photos("https", "photos.google.com", 443); |
127 std::string spdy_server_p = spdy_server_photos.Serialize(); | 128 std::string spdy_server_p = spdy_server_photos.Serialize(); |
128 | 129 |
129 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); | 130 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
130 std::string spdy_server_d = spdy_server_docs.Serialize(); | 131 std::string spdy_server_d = spdy_server_docs.Serialize(); |
131 | 132 |
132 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); | 133 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
133 std::string spdy_server_m = spdy_server_mail.Serialize(); | 134 std::string spdy_server_m = spdy_server_mail.Serialize(); |
134 | 135 |
135 // Check by initializing NULL spdy servers. | |
136 impl_.SetSpdyServers(NULL, true); | |
137 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | |
138 | |
139 // Check by initializing empty spdy servers. | 136 // Check by initializing empty spdy servers. |
140 std::vector<std::string> spdy_servers; | 137 std::unique_ptr<SpdyServersMap> spdy_servers = |
141 impl_.SetSpdyServers(&spdy_servers, true); | 138 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT); |
| 139 impl_.SetSpdyServers(std::move(spdy_servers)); |
142 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | 140 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
143 | 141 |
144 // Check by initializing www.google.com:443 and photos.google.com:443 as spdy | 142 // Check by initializing www.google.com:443 and photos.google.com:443 as spdy |
145 // servers. | 143 // servers. |
146 std::vector<std::string> spdy_servers1; | 144 std::unique_ptr<SpdyServersMap> spdy_servers1 = |
147 spdy_servers1.push_back(spdy_server_g); // Will be 0th index. | 145 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT); |
148 spdy_servers1.push_back(spdy_server_p); // Will be 1st index. | 146 spdy_servers1->Put(spdy_server_g, true); |
149 impl_.SetSpdyServers(&spdy_servers1, true); | 147 spdy_servers1->Put(spdy_server_p, true); |
| 148 impl_.SetSpdyServers(std::move(spdy_servers1)); |
| 149 // Note: these calls affect MRU order. |
| 150 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
150 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); | 151 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); |
151 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | |
152 | 152 |
153 // Verify spdy_server_g and spdy_server_d are in the list in the same order. | 153 // Verify spdy_server_g and spdy_server_d are in the list in MRU order. |
154 base::ListValue spdy_server_list; | 154 std::vector<std::string> returned_spdy_servers; |
155 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 155 impl_.GetSpdyServerList(&returned_spdy_servers, kMaxSupportsSpdyServerHosts); |
156 EXPECT_EQ(2U, spdy_server_list.GetSize()); | 156 ASSERT_EQ(2U, returned_spdy_servers.size()); |
157 std::string string_value_g; | 157 EXPECT_EQ(spdy_server_p, returned_spdy_servers[0]); |
158 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); // 0th index. | 158 EXPECT_EQ(spdy_server_g, returned_spdy_servers[1]); |
159 ASSERT_EQ(spdy_server_g, string_value_g); | |
160 std::string string_value_p; | |
161 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); // 1st index. | |
162 ASSERT_EQ(spdy_server_p, string_value_p); | |
163 | 159 |
164 // Check by initializing mail.google.com:443 and docs.google.com:443 as spdy | 160 // Check by initializing mail.google.com:443 and docs.google.com:443 as spdy |
165 // servers. | 161 // servers. |
166 std::vector<std::string> spdy_servers2; | 162 std::unique_ptr<SpdyServersMap> spdy_servers2 = |
167 spdy_servers2.push_back(spdy_server_m); // Will be 2nd index. | 163 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT); |
168 spdy_servers2.push_back(spdy_server_d); // Will be 3rd index. | 164 spdy_servers2->Put(spdy_server_m, true); |
169 impl_.SetSpdyServers(&spdy_servers2, true); | 165 spdy_servers2->Put(spdy_server_d, true); |
| 166 impl_.SetSpdyServers(std::move(spdy_servers2)); |
170 | 167 |
171 // Verify all the servers are in the list in the same order. | 168 // Verify all the servers are in the list in MRU order. Note that |
172 spdy_server_list.Clear(); | 169 // SetSpdyServers will put existing spdy server entries in front of newly |
173 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 170 // added entries. |
174 EXPECT_EQ(4U, spdy_server_list.GetSize()); | 171 returned_spdy_servers.clear(); |
| 172 impl_.GetSpdyServerList(&returned_spdy_servers, kMaxSupportsSpdyServerHosts); |
| 173 ASSERT_EQ(4U, returned_spdy_servers.size()); |
175 | 174 |
176 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 175 EXPECT_EQ(spdy_server_p, returned_spdy_servers[0]); |
177 ASSERT_EQ(spdy_server_g, string_value_g); | 176 EXPECT_EQ(spdy_server_g, returned_spdy_servers[1]); |
178 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); | 177 EXPECT_EQ(spdy_server_d, returned_spdy_servers[2]); |
179 ASSERT_EQ(spdy_server_p, string_value_p); | 178 EXPECT_EQ(spdy_server_m, returned_spdy_servers[3]); |
180 std::string string_value_m; | |
181 ASSERT_TRUE(spdy_server_list.GetString(2, &string_value_m)); | |
182 ASSERT_EQ(spdy_server_m, string_value_m); | |
183 std::string string_value_d; | |
184 ASSERT_TRUE(spdy_server_list.GetString(3, &string_value_d)); | |
185 ASSERT_EQ(spdy_server_d, string_value_d); | |
186 | 179 |
| 180 // Check these in reverse MRU order so that MRU order stays the same. |
| 181 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); |
187 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 182 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
188 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); | 183 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
189 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); | 184 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); |
190 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | |
191 | 185 |
192 // Verify new data that is being initialized overwrites what is already in the | 186 // Verify new data that is being initialized overwrites what is already in the |
193 // memory and also verify the recency list order. | 187 // memory and also verify the recency list order. |
194 // | 188 // |
195 // Change supports SPDY value for photos and mails servers and order of | 189 // Change supports SPDY value for photos and mails servers and order of |
196 // initalization shouldn't matter. | 190 // initalization shouldn't matter. |
197 std::vector<std::string> spdy_servers3; | 191 std::unique_ptr<SpdyServersMap> spdy_servers3 = |
198 spdy_servers3.push_back(spdy_server_m); | 192 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT); |
199 spdy_servers3.push_back(spdy_server_p); | 193 spdy_servers3->Put(spdy_server_m, false); |
200 impl_.SetSpdyServers(&spdy_servers3, false); | 194 spdy_servers3->Put(spdy_server_p, false); |
| 195 impl_.SetSpdyServers(std::move(spdy_servers3)); |
201 | 196 |
202 // Verify the entries are in the same order. | 197 // Verify the entries are in the same order. |
203 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 198 returned_spdy_servers.clear(); |
204 EXPECT_EQ(2U, spdy_server_list.GetSize()); | 199 impl_.GetSpdyServerList(&returned_spdy_servers, kMaxSupportsSpdyServerHosts); |
| 200 EXPECT_EQ(2U, returned_spdy_servers.size()); |
205 | 201 |
206 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 202 ASSERT_EQ(spdy_server_g, returned_spdy_servers[0]); |
207 ASSERT_EQ(spdy_server_g, string_value_g); | 203 ASSERT_EQ(spdy_server_d, returned_spdy_servers[1]); |
208 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_d)); | |
209 ASSERT_EQ(spdy_server_d, string_value_d); | |
210 | 204 |
211 // Verify photos and mail servers don't support SPDY and other servers support | 205 // Verify photos and mail servers don't support SPDY and other servers support |
212 // SPDY. | 206 // SPDY. |
| 207 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
213 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 208 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
214 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 209 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
215 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos)); | 210 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos)); |
216 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | |
217 } | 211 } |
218 | 212 |
219 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { | 213 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { |
220 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); | 214 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
221 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); | 215 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); |
222 | 216 |
223 // Add www.google.com:443 as supporting SPDY. | 217 // Add www.google.com:443 as supporting SPDY. |
224 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); | 218 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
225 impl_.SetSupportsSpdy(spdy_server_google, true); | 219 impl_.SetSupportsSpdy(spdy_server_google, true); |
226 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 220 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 259 |
266 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 260 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
267 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); | 261 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); |
268 | 262 |
269 impl_.Clear(); | 263 impl_.Clear(); |
270 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | 264 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
271 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 265 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
272 } | 266 } |
273 | 267 |
274 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { | 268 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { |
275 base::ListValue spdy_server_list; | 269 std::vector<std::string> spdy_servers; |
276 | 270 |
277 // Check there are no spdy_servers. | 271 // Check there are no spdy_servers. |
278 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 272 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
279 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 273 EXPECT_EQ(0U, spdy_servers.size()); |
280 | 274 |
281 // Check empty server is not added. | 275 // Check empty server is not added. |
282 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); | 276 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
283 impl_.SetSupportsSpdy(spdy_server_empty, true); | 277 impl_.SetSupportsSpdy(spdy_server_empty, true); |
284 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 278 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
285 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 279 EXPECT_EQ(0U, spdy_servers.size()); |
286 | 280 |
287 std::string string_value_g; | |
288 std::string string_value_m; | |
289 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); | 281 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
290 std::string spdy_server_g = spdy_server_google.Serialize(); | 282 std::string spdy_server_g = spdy_server_google.Serialize(); |
291 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); | 283 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
292 std::string spdy_server_m = spdy_server_mail.Serialize(); | 284 std::string spdy_server_m = spdy_server_mail.Serialize(); |
293 | 285 |
294 // Add www.google.com:443 as not supporting SPDY. | 286 // Add www.google.com:443 as not supporting SPDY. |
295 impl_.SetSupportsSpdy(spdy_server_google, false); | 287 impl_.SetSupportsSpdy(spdy_server_google, false); |
296 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 288 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
297 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 289 EXPECT_EQ(0U, spdy_servers.size()); |
298 | 290 |
299 // Add www.google.com:443 as supporting SPDY. | 291 // Add www.google.com:443 as supporting SPDY. |
300 impl_.SetSupportsSpdy(spdy_server_google, true); | 292 impl_.SetSupportsSpdy(spdy_server_google, true); |
301 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 293 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
302 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 294 ASSERT_EQ(1U, spdy_servers.size()); |
303 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 295 ASSERT_EQ(spdy_server_g, spdy_servers[0]); |
304 ASSERT_EQ(spdy_server_g, string_value_g); | |
305 | 296 |
306 // Add mail.google.com:443 as not supporting SPDY. | 297 // Add mail.google.com:443 as not supporting SPDY. |
307 impl_.SetSupportsSpdy(spdy_server_mail, false); | 298 impl_.SetSupportsSpdy(spdy_server_mail, false); |
308 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 299 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
309 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 300 ASSERT_EQ(1U, spdy_servers.size()); |
310 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 301 ASSERT_EQ(spdy_server_g, spdy_servers[0]); |
311 ASSERT_EQ(spdy_server_g, string_value_g); | |
312 | 302 |
313 // Add mail.google.com:443 as supporting SPDY. | 303 // Add mail.google.com:443 as supporting SPDY. |
314 impl_.SetSupportsSpdy(spdy_server_mail, true); | 304 impl_.SetSupportsSpdy(spdy_server_mail, true); |
315 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 305 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
316 ASSERT_EQ(2U, spdy_server_list.GetSize()); | 306 ASSERT_EQ(2U, spdy_servers.size()); |
317 | 307 |
318 // Verify www.google.com:443 and mail.google.com:443 are in the list. | 308 // Verify www.google.com:443 and mail.google.com:443 are in the list. |
319 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); | 309 ASSERT_EQ(spdy_server_m, spdy_servers[0]); |
320 ASSERT_EQ(spdy_server_m, string_value_m); | 310 ASSERT_EQ(spdy_server_g, spdy_servers[1]); |
321 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g)); | |
322 ASSERT_EQ(spdy_server_g, string_value_g); | |
323 | 311 |
324 // Request for only one server and verify that we get only one server. | 312 // Request for only one server and verify that we get only one server. |
325 impl_.GetSpdyServerList(&spdy_server_list, 1); | 313 impl_.GetSpdyServerList(&spdy_servers, 1); |
326 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 314 ASSERT_EQ(1U, spdy_servers.size()); |
327 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); | 315 ASSERT_EQ(spdy_server_m, spdy_servers[0]); |
328 ASSERT_EQ(spdy_server_m, string_value_m); | |
329 } | 316 } |
330 | 317 |
331 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { | 318 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServers) { |
332 base::ListValue spdy_server_list; | 319 std::vector<std::string> spdy_servers; |
333 | 320 |
334 std::string string_value_g; | |
335 std::string string_value_m; | |
336 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); | 321 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
337 std::string spdy_server_g = spdy_server_google.Serialize(); | 322 std::string spdy_server_g = spdy_server_google.Serialize(); |
338 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); | 323 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
339 std::string spdy_server_m = spdy_server_mail.Serialize(); | 324 std::string spdy_server_m = spdy_server_mail.Serialize(); |
340 | 325 |
341 // Add www.google.com:443 as supporting SPDY. | 326 // Add www.google.com:443 as supporting SPDY. |
342 impl_.SetSupportsSpdy(spdy_server_google, true); | 327 impl_.SetSupportsSpdy(spdy_server_google, true); |
343 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 328 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
344 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 329 ASSERT_EQ(1U, spdy_servers.size()); |
345 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 330 ASSERT_EQ(spdy_server_g, spdy_servers[0]); |
346 ASSERT_EQ(spdy_server_g, string_value_g); | |
347 | 331 |
348 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and | 332 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and |
349 // www.google.com:443 are in the list. | 333 // www.google.com:443 are in the list. |
350 impl_.SetSupportsSpdy(spdy_server_mail, true); | 334 impl_.SetSupportsSpdy(spdy_server_mail, true); |
351 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 335 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
352 ASSERT_EQ(2U, spdy_server_list.GetSize()); | 336 ASSERT_EQ(2U, spdy_servers.size()); |
353 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); | 337 ASSERT_EQ(spdy_server_m, spdy_servers[0]); |
354 ASSERT_EQ(spdy_server_m, string_value_m); | 338 ASSERT_EQ(spdy_server_g, spdy_servers[1]); |
355 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g)); | |
356 ASSERT_EQ(spdy_server_g, string_value_g); | |
357 | 339 |
358 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it | 340 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it |
359 // is www.google.com:443 is the MRU server. | 341 // is www.google.com:443 is the MRU server. |
360 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 342 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
361 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 343 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts); |
362 ASSERT_EQ(2U, spdy_server_list.GetSize()); | 344 ASSERT_EQ(2U, spdy_servers.size()); |
363 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 345 ASSERT_EQ(spdy_server_g, spdy_servers[0]); |
364 ASSERT_EQ(spdy_server_g, string_value_g); | 346 ASSERT_EQ(spdy_server_m, spdy_servers[1]); |
365 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | |
366 ASSERT_EQ(spdy_server_m, string_value_m); | |
367 } | 347 } |
368 | 348 |
369 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 349 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
370 | 350 |
371 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 351 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
372 url::SchemeHostPort test_server("http", "foo", 80); | 352 url::SchemeHostPort test_server("http", "foo", 80); |
373 EXPECT_FALSE(HasAlternativeService(test_server)); | 353 EXPECT_FALSE(HasAlternativeService(test_server)); |
374 | 354 |
375 AlternativeService alternative_service(kProtoHTTP2, "foo", 443); | 355 AlternativeService alternative_service(kProtoHTTP2, "foo", 443); |
376 SetAlternativeService(test_server, alternative_service); | 356 SetAlternativeService(test_server, alternative_service); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); | 415 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); |
436 base::Time expiration2 = now + base::TimeDelta::FromDays(2); | 416 base::Time expiration2 = now + base::TimeDelta::FromDays(2); |
437 alternative_service_info_vector.push_back( | 417 alternative_service_info_vector.push_back( |
438 AlternativeServiceInfo(alternative_service2, expiration2)); | 418 AlternativeServiceInfo(alternative_service2, expiration2)); |
439 url::SchemeHostPort test_server2("http", "foo2", 80); | 419 url::SchemeHostPort test_server2("http", "foo2", 80); |
440 // 0th entry in the memory. | 420 // 0th entry in the memory. |
441 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector); | 421 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector); |
442 | 422 |
443 // Prepare |alternative_service_map| to be loaded by | 423 // Prepare |alternative_service_map| to be loaded by |
444 // SetAlternativeServiceServers(). | 424 // SetAlternativeServiceServers(). |
445 AlternativeServiceMap alternative_service_map( | 425 std::unique_ptr<AlternativeServiceMap> alternative_service_map = |
446 AlternativeServiceMap::NO_AUTO_EVICT); | 426 base::MakeUnique<AlternativeServiceMap>( |
| 427 AlternativeServiceMap::NO_AUTO_EVICT); |
447 const AlternativeService alternative_service3(kProtoHTTP2, "bar3", 123); | 428 const AlternativeService alternative_service3(kProtoHTTP2, "bar3", 123); |
448 base::Time expiration3 = now + base::TimeDelta::FromDays(3); | 429 base::Time expiration3 = now + base::TimeDelta::FromDays(3); |
449 const AlternativeServiceInfo alternative_service_info1(alternative_service3, | 430 const AlternativeServiceInfo alternative_service_info1(alternative_service3, |
450 expiration3); | 431 expiration3); |
451 // Simulate updating data for 0th entry with data from Preferences. | 432 // Simulate updating data for 0th entry with data from Preferences. |
452 alternative_service_map.Put( | 433 alternative_service_map->Put( |
453 test_server2, | 434 test_server2, |
454 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); | 435 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); |
455 | 436 |
456 url::SchemeHostPort test_server3("http", "foo3", 80); | 437 url::SchemeHostPort test_server3("http", "foo3", 80); |
457 const AlternativeService alternative_service4(kProtoHTTP2, "bar4", 1234); | 438 const AlternativeService alternative_service4(kProtoHTTP2, "bar4", 1234); |
458 base::Time expiration4 = now + base::TimeDelta::FromDays(4); | 439 base::Time expiration4 = now + base::TimeDelta::FromDays(4); |
459 const AlternativeServiceInfo alternative_service_info2(alternative_service4, | 440 const AlternativeServiceInfo alternative_service_info2(alternative_service4, |
460 expiration4); | 441 expiration4); |
461 // Add an old entry from Preferences, this will be added to end of recency | 442 // Add an old entry from Preferences, this will be added to end of recency |
462 // list. | 443 // list. |
463 alternative_service_map.Put( | 444 alternative_service_map->Put( |
464 test_server3, | 445 test_server3, |
465 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); | 446 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); |
466 | 447 |
467 // MRU list will be test_server2, test_server1, test_server3. | 448 // MRU list will be test_server2, test_server1, test_server3. |
468 impl_.SetAlternativeServiceServers(&alternative_service_map); | 449 impl_.SetAlternativeServiceServers(std::move(alternative_service_map)); |
469 | 450 |
470 // Verify alternative_service_map. | 451 // Verify alternative_service_map. |
471 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 452 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
472 ASSERT_EQ(3u, map.size()); | 453 ASSERT_EQ(3u, map.size()); |
473 AlternativeServiceMap::const_iterator map_it = map.begin(); | 454 AlternativeServiceMap::const_iterator map_it = map.begin(); |
474 | 455 |
475 EXPECT_TRUE(map_it->first.Equals(test_server2)); | 456 EXPECT_TRUE(map_it->first.Equals(test_server2)); |
476 ASSERT_EQ(1u, map_it->second.size()); | 457 ASSERT_EQ(1u, map_it->second.size()); |
477 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service()); | 458 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service()); |
478 EXPECT_EQ(expiration3, map_it->second[0].expiration()); | 459 EXPECT_EQ(expiration3, map_it->second[0].expiration()); |
(...skipping 14 matching lines...) Expand all Loading... |
493 // hostname is the mapping. | 474 // hostname is the mapping. |
494 TEST_F(AlternateProtocolServerPropertiesTest, SetWithEmptyHostname) { | 475 TEST_F(AlternateProtocolServerPropertiesTest, SetWithEmptyHostname) { |
495 url::SchemeHostPort server("https", "foo", 443); | 476 url::SchemeHostPort server("https", "foo", 443); |
496 const AlternativeService alternative_service_with_empty_hostname(kProtoHTTP2, | 477 const AlternativeService alternative_service_with_empty_hostname(kProtoHTTP2, |
497 "", 1234); | 478 "", 1234); |
498 const AlternativeService alternative_service_with_foo_hostname(kProtoHTTP2, | 479 const AlternativeService alternative_service_with_foo_hostname(kProtoHTTP2, |
499 "foo", 1234); | 480 "foo", 1234); |
500 SetAlternativeService(server, alternative_service_with_empty_hostname); | 481 SetAlternativeService(server, alternative_service_with_empty_hostname); |
501 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); | 482 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); |
502 | 483 |
503 AlternativeServiceMap alternative_service_map( | 484 std::unique_ptr<AlternativeServiceMap> alternative_service_map = |
504 AlternativeServiceMap::NO_AUTO_EVICT); | 485 base::MakeUnique<AlternativeServiceMap>( |
505 impl_.SetAlternativeServiceServers(&alternative_service_map); | 486 AlternativeServiceMap::NO_AUTO_EVICT); |
| 487 impl_.SetAlternativeServiceServers(std::move(alternative_service_map)); |
506 | 488 |
507 EXPECT_TRUE( | 489 EXPECT_TRUE( |
508 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); | 490 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); |
509 const AlternativeServiceInfoVector alternative_service_info_vector = | 491 const AlternativeServiceInfoVector alternative_service_info_vector = |
510 impl_.GetAlternativeServiceInfos(server); | 492 impl_.GetAlternativeServiceInfos(server); |
511 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 493 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
512 EXPECT_EQ(alternative_service_with_foo_hostname, | 494 EXPECT_EQ(alternative_service_with_foo_hostname, |
513 alternative_service_info_vector[0].alternative_service()); | 495 alternative_service_info_vector[0].alternative_service()); |
514 } | 496 } |
515 | 497 |
516 // Regression test for https://crbug.com/516486: | 498 // Regression test for https://crbug.com/516486: |
517 // GetAlternativeServiceInfos() should remove |alternative_service_map_| | 499 // GetAlternativeServiceInfos() should remove |alternative_service_map_| |
518 // elements with empty value. | 500 // elements with empty value. |
519 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { | 501 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { |
520 url::SchemeHostPort server("https", "foo", 443); | 502 url::SchemeHostPort server("https", "foo", 443); |
521 const AlternativeService alternative_service(kProtoHTTP2, "bar", 443); | 503 const AlternativeService alternative_service(kProtoHTTP2, "bar", 443); |
522 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 504 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
523 const AlternativeServiceInfo alternative_service_info(alternative_service, | 505 const AlternativeServiceInfo alternative_service_info(alternative_service, |
524 expiration); | 506 expiration); |
525 AlternativeServiceMap alternative_service_map( | 507 std::unique_ptr<AlternativeServiceMap> alternative_service_map = |
526 AlternativeServiceMap::NO_AUTO_EVICT); | 508 base::MakeUnique<AlternativeServiceMap>( |
527 alternative_service_map.Put( | 509 AlternativeServiceMap::NO_AUTO_EVICT); |
| 510 alternative_service_map->Put( |
528 server, | 511 server, |
529 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 512 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
530 | 513 |
531 // Prepare |alternative_service_map_| with a single key that has a single | 514 // Prepare |alternative_service_map_| with a single key that has a single |
532 // AlternativeServiceInfo with identical hostname and port. | 515 // AlternativeServiceInfo with identical hostname and port. |
533 impl_.SetAlternativeServiceServers(&alternative_service_map); | 516 impl_.SetAlternativeServiceServers(std::move(alternative_service_map)); |
534 | 517 |
535 // GetAlternativeServiceInfos() should remove such AlternativeServiceInfo from | 518 // GetAlternativeServiceInfos() should remove such AlternativeServiceInfo from |
536 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector | 519 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector |
537 // corresponding to |server|. | 520 // corresponding to |server|. |
538 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); | 521 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); |
539 | 522 |
540 // GetAlternativeServiceInfos() should remove this key from | 523 // GetAlternativeServiceInfos() should remove this key from |
541 // |alternative_service_map_|, and SetAlternativeServices() should not crash. | 524 // |alternative_service_map_|, and SetAlternativeServices() should not crash. |
542 impl_.SetAlternativeServices( | 525 impl_.SetAlternativeServices( |
543 server, | 526 server, |
544 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 527 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
545 | 528 |
546 // There should still be no alternative service assigned to |server|. | 529 // There should still be no alternative service assigned to |server|. |
547 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); | 530 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); |
548 } | 531 } |
549 | 532 |
550 // Regression test for https://crbug.com/516486 for the canonical host case. | 533 // Regression test for https://crbug.com/516486 for the canonical host case. |
551 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { | 534 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { |
552 url::SchemeHostPort server("https", "foo.c.youtube.com", 443); | 535 url::SchemeHostPort server("https", "foo.c.youtube.com", 443); |
553 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); | 536 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
554 const AlternativeService alternative_service(kProtoHTTP2, "", 443); | 537 const AlternativeService alternative_service(kProtoHTTP2, "", 443); |
555 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 538 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
556 const AlternativeServiceInfo alternative_service_info(alternative_service, | 539 const AlternativeServiceInfo alternative_service_info(alternative_service, |
557 expiration); | 540 expiration); |
558 AlternativeServiceMap alternative_service_map( | 541 std::unique_ptr<AlternativeServiceMap> alternative_service_map = |
559 AlternativeServiceMap::NO_AUTO_EVICT); | 542 base::MakeUnique<AlternativeServiceMap>( |
560 alternative_service_map.Put( | 543 AlternativeServiceMap::NO_AUTO_EVICT); |
| 544 alternative_service_map->Put( |
561 canonical_server, | 545 canonical_server, |
562 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 546 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
563 | 547 |
564 // Prepare |alternative_service_map_| with a single key that has a single | 548 // Prepare |alternative_service_map_| with a single key that has a single |
565 // AlternativeServiceInfo with identical hostname and port. | 549 // AlternativeServiceInfo with identical hostname and port. |
566 impl_.SetAlternativeServiceServers(&alternative_service_map); | 550 impl_.SetAlternativeServiceServers(std::move(alternative_service_map)); |
567 | 551 |
568 // GetAlternativeServiceInfos() should remove such AlternativeServiceInfo from | 552 // GetAlternativeServiceInfos() should remove such AlternativeServiceInfo from |
569 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector | 553 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector |
570 // corresponding to |canonical_server|, even when looking up | 554 // corresponding to |canonical_server|, even when looking up |
571 // alternative services for |server|. | 555 // alternative services for |server|. |
572 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); | 556 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); |
573 | 557 |
574 // GetAlternativeServiceInfos() should remove this key from | 558 // GetAlternativeServiceInfos() should remove this key from |
575 // |alternative_service_map_|, and SetAlternativeServices() should not crash. | 559 // |alternative_service_map_|, and SetAlternativeServices() should not crash. |
576 impl_.SetAlternativeServices( | 560 impl_.SetAlternativeServices( |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2)); | 1070 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2)); |
1087 } | 1071 } |
1088 | 1072 |
1089 typedef HttpServerPropertiesImplTest SupportsQuicServerPropertiesTest; | 1073 typedef HttpServerPropertiesImplTest SupportsQuicServerPropertiesTest; |
1090 | 1074 |
1091 TEST_F(SupportsQuicServerPropertiesTest, Set) { | 1075 TEST_F(SupportsQuicServerPropertiesTest, Set) { |
1092 HostPortPair quic_server_google("www.google.com", 443); | 1076 HostPortPair quic_server_google("www.google.com", 443); |
1093 | 1077 |
1094 // Check by initializing empty address. | 1078 // Check by initializing empty address. |
1095 IPAddress initial_address; | 1079 IPAddress initial_address; |
1096 impl_.SetSupportsQuic(&initial_address); | 1080 impl_.SetSupportsQuic(initial_address); |
1097 | 1081 |
1098 IPAddress address; | 1082 IPAddress address; |
1099 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); | 1083 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); |
1100 EXPECT_TRUE(address.empty()); | 1084 EXPECT_TRUE(address.empty()); |
1101 | 1085 |
1102 // Check by initializing with a valid address. | 1086 // Check by initializing with a valid address. |
1103 initial_address = IPAddress::IPv4Localhost(); | 1087 initial_address = IPAddress::IPv4Localhost(); |
1104 impl_.SetSupportsQuic(&initial_address); | 1088 impl_.SetSupportsQuic(initial_address); |
1105 | 1089 |
1106 EXPECT_TRUE(impl_.GetSupportsQuic(&address)); | 1090 EXPECT_TRUE(impl_.GetSupportsQuic(&address)); |
1107 EXPECT_EQ(initial_address, address); | 1091 EXPECT_EQ(initial_address, address); |
1108 } | 1092 } |
1109 | 1093 |
1110 TEST_F(SupportsQuicServerPropertiesTest, SetSupportsQuic) { | 1094 TEST_F(SupportsQuicServerPropertiesTest, SetSupportsQuic) { |
1111 IPAddress address; | 1095 IPAddress address; |
1112 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); | 1096 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); |
1113 EXPECT_TRUE(address.empty()); | 1097 EXPECT_TRUE(address.empty()); |
1114 | 1098 |
1115 IPAddress actual_address(127, 0, 0, 1); | 1099 IPAddress actual_address(127, 0, 0, 1); |
1116 impl_.SetSupportsQuic(true, actual_address); | 1100 impl_.SetSupportsQuic(true, actual_address); |
1117 | 1101 |
1118 EXPECT_TRUE(impl_.GetSupportsQuic(&address)); | 1102 EXPECT_TRUE(impl_.GetSupportsQuic(&address)); |
1119 EXPECT_EQ(actual_address, address); | 1103 EXPECT_EQ(actual_address, address); |
1120 | 1104 |
1121 impl_.Clear(); | 1105 impl_.Clear(); |
1122 | 1106 |
1123 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); | 1107 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); |
1124 } | 1108 } |
1125 | 1109 |
1126 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest; | 1110 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest; |
1127 | 1111 |
1128 TEST_F(ServerNetworkStatsServerPropertiesTest, Set) { | 1112 TEST_F(ServerNetworkStatsServerPropertiesTest, Set) { |
1129 url::SchemeHostPort google_server("https", "www.google.com", 443); | 1113 url::SchemeHostPort google_server("https", "www.google.com", 443); |
1130 | 1114 |
1131 // Check by initializing empty ServerNetworkStats. | 1115 // Check by initializing empty ServerNetworkStats. |
1132 ServerNetworkStatsMap init_server_network_stats_map( | 1116 std::unique_ptr<ServerNetworkStatsMap> init_server_network_stats_map = |
1133 ServerNetworkStatsMap::NO_AUTO_EVICT); | 1117 base::MakeUnique<ServerNetworkStatsMap>( |
1134 impl_.SetServerNetworkStats(&init_server_network_stats_map); | 1118 ServerNetworkStatsMap::NO_AUTO_EVICT); |
| 1119 impl_.SetServerNetworkStats(std::move(init_server_network_stats_map)); |
1135 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server); | 1120 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server); |
1136 EXPECT_EQ(NULL, stats); | 1121 EXPECT_EQ(NULL, stats); |
1137 | 1122 |
1138 // Check by initializing with www.google.com:443. | 1123 // Check by initializing with www.google.com:443. |
1139 ServerNetworkStats stats_google; | 1124 ServerNetworkStats stats_google; |
1140 stats_google.srtt = base::TimeDelta::FromMicroseconds(10); | 1125 stats_google.srtt = base::TimeDelta::FromMicroseconds(10); |
1141 stats_google.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); | 1126 stats_google.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); |
1142 init_server_network_stats_map.Put(google_server, stats_google); | 1127 init_server_network_stats_map = base::MakeUnique<ServerNetworkStatsMap>( |
1143 impl_.SetServerNetworkStats(&init_server_network_stats_map); | 1128 ServerNetworkStatsMap::NO_AUTO_EVICT); |
| 1129 init_server_network_stats_map->Put(google_server, stats_google); |
| 1130 impl_.SetServerNetworkStats(std::move(init_server_network_stats_map)); |
1144 | 1131 |
1145 // Verify data for www.google.com:443. | 1132 // Verify data for www.google.com:443. |
1146 ASSERT_EQ(1u, impl_.server_network_stats_map().size()); | 1133 ASSERT_EQ(1u, impl_.server_network_stats_map().size()); |
1147 EXPECT_EQ(stats_google, *(impl_.GetServerNetworkStats(google_server))); | 1134 EXPECT_EQ(stats_google, *(impl_.GetServerNetworkStats(google_server))); |
1148 | 1135 |
1149 // Test recency order and overwriting of data. | 1136 // Test recency order and overwriting of data. |
1150 // | 1137 // |
1151 // |docs_server| has a ServerNetworkStats, which will be overwritten by | 1138 // |docs_server| has a ServerNetworkStats, which will be overwritten by |
1152 // SetServerNetworkStats(), because |server_network_stats_map| has an | 1139 // SetServerNetworkStats(), because |server_network_stats_map| has an |
1153 // entry for |docs_server|. | 1140 // entry for |docs_server|. |
1154 url::SchemeHostPort docs_server("https", "docs.google.com", 443); | 1141 url::SchemeHostPort docs_server("https", "docs.google.com", 443); |
1155 ServerNetworkStats stats_docs; | 1142 ServerNetworkStats stats_docs; |
1156 stats_docs.srtt = base::TimeDelta::FromMicroseconds(20); | 1143 stats_docs.srtt = base::TimeDelta::FromMicroseconds(20); |
1157 stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(200); | 1144 stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(200); |
1158 // Recency order will be |docs_server| and |google_server|. | 1145 // Recency order will be |docs_server| and |google_server|. |
1159 impl_.SetServerNetworkStats(docs_server, stats_docs); | 1146 impl_.SetServerNetworkStats(docs_server, stats_docs); |
1160 | 1147 |
1161 // Prepare |server_network_stats_map| to be loaded by | 1148 // Prepare |server_network_stats_map| to be loaded by |
1162 // SetServerNetworkStats(). | 1149 // SetServerNetworkStats(). |
1163 ServerNetworkStatsMap server_network_stats_map( | 1150 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map = |
1164 ServerNetworkStatsMap::NO_AUTO_EVICT); | 1151 base::MakeUnique<ServerNetworkStatsMap>( |
| 1152 ServerNetworkStatsMap::NO_AUTO_EVICT); |
1165 | 1153 |
1166 // Change the values for |docs_server|. | 1154 // Change the values for |docs_server|. |
1167 ServerNetworkStats new_stats_docs; | 1155 ServerNetworkStats new_stats_docs; |
1168 new_stats_docs.srtt = base::TimeDelta::FromMicroseconds(25); | 1156 new_stats_docs.srtt = base::TimeDelta::FromMicroseconds(25); |
1169 new_stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(250); | 1157 new_stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(250); |
1170 server_network_stats_map.Put(docs_server, new_stats_docs); | 1158 server_network_stats_map->Put(docs_server, new_stats_docs); |
1171 // Add data for mail.google.com:443. | 1159 // Add data for mail.google.com:443. |
1172 url::SchemeHostPort mail_server("https", "mail.google.com", 443); | 1160 url::SchemeHostPort mail_server("https", "mail.google.com", 443); |
1173 ServerNetworkStats stats_mail; | 1161 ServerNetworkStats stats_mail; |
1174 stats_mail.srtt = base::TimeDelta::FromMicroseconds(30); | 1162 stats_mail.srtt = base::TimeDelta::FromMicroseconds(30); |
1175 stats_mail.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(300); | 1163 stats_mail.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(300); |
1176 server_network_stats_map.Put(mail_server, stats_mail); | 1164 server_network_stats_map->Put(mail_server, stats_mail); |
1177 | 1165 |
1178 // Recency order will be |docs_server|, |google_server| and |mail_server|. | 1166 // Recency order will be |docs_server|, |google_server| and |mail_server|. |
1179 impl_.SetServerNetworkStats(&server_network_stats_map); | 1167 impl_.SetServerNetworkStats(std::move(server_network_stats_map)); |
1180 | 1168 |
1181 const ServerNetworkStatsMap& map = impl_.server_network_stats_map(); | 1169 const ServerNetworkStatsMap& map = impl_.server_network_stats_map(); |
1182 ASSERT_EQ(3u, map.size()); | 1170 ASSERT_EQ(3u, map.size()); |
1183 ServerNetworkStatsMap::const_iterator map_it = map.begin(); | 1171 ServerNetworkStatsMap::const_iterator map_it = map.begin(); |
1184 | 1172 |
1185 EXPECT_TRUE(map_it->first.Equals(docs_server)); | 1173 EXPECT_TRUE(map_it->first.Equals(docs_server)); |
1186 EXPECT_EQ(new_stats_docs, map_it->second); | 1174 EXPECT_EQ(new_stats_docs, map_it->second); |
1187 ++map_it; | 1175 ++map_it; |
1188 EXPECT_TRUE(map_it->first.Equals(google_server)); | 1176 EXPECT_TRUE(map_it->first.Equals(google_server)); |
1189 EXPECT_EQ(stats_google, map_it->second); | 1177 EXPECT_EQ(stats_google, map_it->second); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 TEST_F(QuicServerInfoServerPropertiesTest, Set) { | 1219 TEST_F(QuicServerInfoServerPropertiesTest, Set) { |
1232 HostPortPair google_server("www.google.com", 443); | 1220 HostPortPair google_server("www.google.com", 443); |
1233 QuicServerId google_quic_server_id(google_server, PRIVACY_MODE_ENABLED); | 1221 QuicServerId google_quic_server_id(google_server, PRIVACY_MODE_ENABLED); |
1234 | 1222 |
1235 EXPECT_EQ(QuicServerInfoMap::NO_AUTO_EVICT, | 1223 EXPECT_EQ(QuicServerInfoMap::NO_AUTO_EVICT, |
1236 impl_.quic_server_info_map().max_size()); | 1224 impl_.quic_server_info_map().max_size()); |
1237 impl_.SetMaxServerConfigsStoredInProperties(10); | 1225 impl_.SetMaxServerConfigsStoredInProperties(10); |
1238 EXPECT_EQ(10u, impl_.quic_server_info_map().max_size()); | 1226 EXPECT_EQ(10u, impl_.quic_server_info_map().max_size()); |
1239 | 1227 |
1240 // Check empty map. | 1228 // Check empty map. |
1241 QuicServerInfoMap init_quic_server_info_map(QuicServerInfoMap::NO_AUTO_EVICT); | 1229 std::unique_ptr<QuicServerInfoMap> init_quic_server_info_map = |
1242 impl_.SetQuicServerInfoMap(&init_quic_server_info_map); | 1230 base::MakeUnique<QuicServerInfoMap>(QuicServerInfoMap::NO_AUTO_EVICT); |
| 1231 impl_.SetQuicServerInfoMap(std::move(init_quic_server_info_map)); |
1243 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1232 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
1244 | 1233 |
1245 // Check by initializing with www.google.com:443. | 1234 // Check by initializing with www.google.com:443. |
1246 std::string google_server_info("google_quic_server_info"); | 1235 std::string google_server_info("google_quic_server_info"); |
1247 init_quic_server_info_map.Put(google_quic_server_id, google_server_info); | 1236 init_quic_server_info_map = |
1248 impl_.SetQuicServerInfoMap(&init_quic_server_info_map); | 1237 base::MakeUnique<QuicServerInfoMap>(QuicServerInfoMap::NO_AUTO_EVICT); |
| 1238 init_quic_server_info_map->Put(google_quic_server_id, google_server_info); |
| 1239 impl_.SetQuicServerInfoMap(std::move(init_quic_server_info_map)); |
1249 | 1240 |
1250 // Verify data for www.google.com:443. | 1241 // Verify data for www.google.com:443. |
1251 EXPECT_EQ(1u, impl_.quic_server_info_map().size()); | 1242 EXPECT_EQ(1u, impl_.quic_server_info_map().size()); |
1252 EXPECT_EQ(google_server_info, | 1243 EXPECT_EQ(google_server_info, |
1253 *impl_.GetQuicServerInfo(google_quic_server_id)); | 1244 *impl_.GetQuicServerInfo(google_quic_server_id)); |
1254 | 1245 |
1255 // Test recency order and overwriting of data. | 1246 // Test recency order and overwriting of data. |
1256 // | 1247 // |
1257 // |docs_server| has a QuicServerInfo, which will be overwritten by | 1248 // |docs_server| has a QuicServerInfo, which will be overwritten by |
1258 // SetQuicServerInfoMap(), because |quic_server_info_map| has an | 1249 // SetQuicServerInfoMap(), because |quic_server_info_map| has an |
1259 // entry for |docs_server|. | 1250 // entry for |docs_server|. |
1260 HostPortPair docs_server("docs.google.com", 443); | 1251 HostPortPair docs_server("docs.google.com", 443); |
1261 QuicServerId docs_quic_server_id(docs_server, PRIVACY_MODE_ENABLED); | 1252 QuicServerId docs_quic_server_id(docs_server, PRIVACY_MODE_ENABLED); |
1262 std::string docs_server_info("docs_quic_server_info"); | 1253 std::string docs_server_info("docs_quic_server_info"); |
1263 impl_.SetQuicServerInfo(docs_quic_server_id, docs_server_info); | 1254 impl_.SetQuicServerInfo(docs_quic_server_id, docs_server_info); |
1264 | 1255 |
1265 // Recency order will be |docs_server| and |google_server|. | 1256 // Recency order will be |docs_server| and |google_server|. |
1266 const QuicServerInfoMap& map = impl_.quic_server_info_map(); | 1257 const QuicServerInfoMap& map = impl_.quic_server_info_map(); |
1267 ASSERT_EQ(2u, map.size()); | 1258 ASSERT_EQ(2u, map.size()); |
1268 QuicServerInfoMap::const_iterator map_it = map.begin(); | 1259 QuicServerInfoMap::const_iterator map_it = map.begin(); |
1269 EXPECT_EQ(map_it->first, docs_quic_server_id); | 1260 EXPECT_EQ(map_it->first, docs_quic_server_id); |
1270 EXPECT_EQ(docs_server_info, map_it->second); | 1261 EXPECT_EQ(docs_server_info, map_it->second); |
1271 ++map_it; | 1262 ++map_it; |
1272 EXPECT_EQ(map_it->first, google_quic_server_id); | 1263 EXPECT_EQ(map_it->first, google_quic_server_id); |
1273 EXPECT_EQ(google_server_info, map_it->second); | 1264 EXPECT_EQ(google_server_info, map_it->second); |
1274 | 1265 |
1275 // Prepare |quic_server_info_map| to be loaded by | 1266 // Prepare |quic_server_info_map| to be loaded by |
1276 // SetQuicServerInfoMap(). | 1267 // SetQuicServerInfoMap(). |
1277 QuicServerInfoMap quic_server_info_map(QuicServerInfoMap::NO_AUTO_EVICT); | 1268 std::unique_ptr<QuicServerInfoMap> quic_server_info_map = |
| 1269 base::MakeUnique<QuicServerInfoMap>(QuicServerInfoMap::NO_AUTO_EVICT); |
1278 // Change the values for |docs_server|. | 1270 // Change the values for |docs_server|. |
1279 std::string new_docs_server_info("new_docs_quic_server_info"); | 1271 std::string new_docs_server_info("new_docs_quic_server_info"); |
1280 quic_server_info_map.Put(docs_quic_server_id, new_docs_server_info); | 1272 quic_server_info_map->Put(docs_quic_server_id, new_docs_server_info); |
1281 // Add data for mail.google.com:443. | 1273 // Add data for mail.google.com:443. |
1282 HostPortPair mail_server("mail.google.com", 443); | 1274 HostPortPair mail_server("mail.google.com", 443); |
1283 QuicServerId mail_quic_server_id(mail_server, PRIVACY_MODE_ENABLED); | 1275 QuicServerId mail_quic_server_id(mail_server, PRIVACY_MODE_ENABLED); |
1284 std::string mail_server_info("mail_quic_server_info"); | 1276 std::string mail_server_info("mail_quic_server_info"); |
1285 quic_server_info_map.Put(mail_quic_server_id, mail_server_info); | 1277 quic_server_info_map->Put(mail_quic_server_id, mail_server_info); |
1286 impl_.SetQuicServerInfoMap(&quic_server_info_map); | 1278 impl_.SetQuicServerInfoMap(std::move(quic_server_info_map)); |
1287 | 1279 |
1288 // Recency order will be |docs_server|, |google_server| and |mail_server|. | 1280 // Recency order will be |docs_server|, |google_server| and |mail_server|. |
1289 const QuicServerInfoMap& memory_map = impl_.quic_server_info_map(); | 1281 const QuicServerInfoMap& memory_map = impl_.quic_server_info_map(); |
1290 ASSERT_EQ(3u, memory_map.size()); | 1282 ASSERT_EQ(3u, memory_map.size()); |
1291 QuicServerInfoMap::const_iterator memory_map_it = memory_map.begin(); | 1283 QuicServerInfoMap::const_iterator memory_map_it = memory_map.begin(); |
1292 EXPECT_EQ(memory_map_it->first, docs_quic_server_id); | 1284 EXPECT_EQ(memory_map_it->first, docs_quic_server_id); |
1293 EXPECT_EQ(new_docs_server_info, memory_map_it->second); | 1285 EXPECT_EQ(new_docs_server_info, memory_map_it->second); |
1294 ++memory_map_it; | 1286 ++memory_map_it; |
1295 EXPECT_EQ(memory_map_it->first, google_quic_server_id); | 1287 EXPECT_EQ(memory_map_it->first, google_quic_server_id); |
1296 EXPECT_EQ(google_server_info, memory_map_it->second); | 1288 EXPECT_EQ(google_server_info, memory_map_it->second); |
(...skipping 30 matching lines...) Expand all Loading... |
1327 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1319 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
1328 | 1320 |
1329 impl_.Clear(); | 1321 impl_.Clear(); |
1330 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1322 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
1331 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1323 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
1332 } | 1324 } |
1333 | 1325 |
1334 } // namespace | 1326 } // namespace |
1335 | 1327 |
1336 } // namespace net | 1328 } // namespace net |
OLD | NEW |