Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: net/http/http_server_properties_impl_unittest.cc

Issue 1824903002: Change the AlternativeServiceMap with SchemeOriginPair key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittests Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const SpdySettingsIds kSpdySettingsId = SETTINGS_UPLOAD_BANDWIDTH; 48 const SpdySettingsIds kSpdySettingsId = SETTINGS_UPLOAD_BANDWIDTH;
49 const SpdySettingsFlags kSpdySettingsFlags = SETTINGS_FLAG_PERSISTED; 49 const SpdySettingsFlags kSpdySettingsFlags = SETTINGS_FLAG_PERSISTED;
50 50
51 struct SpdySettingsDataToVerify { 51 struct SpdySettingsDataToVerify {
52 HostPortPair spdy_server; 52 HostPortPair spdy_server;
53 uint32_t value; 53 uint32_t value;
54 }; 54 };
55 55
56 class HttpServerPropertiesImplTest : public testing::Test { 56 class HttpServerPropertiesImplTest : public testing::Test {
57 protected: 57 protected:
58 bool HasAlternativeService(const HostPortPair& origin) { 58 bool HasAlternativeService(const SchemeOriginPair& origin) {
59 const AlternativeServiceVector alternative_service_vector = 59 const AlternativeServiceVector alternative_service_vector =
60 impl_.GetAlternativeServices(origin); 60 impl_.GetAlternativeServices(origin);
61 return !alternative_service_vector.empty(); 61 return !alternative_service_vector.empty();
62 } 62 }
63 63
64 bool SetAlternativeService(const HostPortPair& origin, 64 bool SetAlternativeService(const SchemeOriginPair& origin,
65 const AlternativeService& alternative_service, 65 const AlternativeService& alternative_service,
66 double alternative_probability) { 66 double alternative_probability) {
67 const base::Time expiration = 67 const base::Time expiration =
68 base::Time::Now() + base::TimeDelta::FromDays(1); 68 base::Time::Now() + base::TimeDelta::FromDays(1);
69 return impl_.SetAlternativeService(origin, alternative_service, 69 return impl_.SetAlternativeService(origin, alternative_service,
70 alternative_probability, expiration); 70 alternative_probability, expiration);
71 } 71 }
72 72
73 void InitializeSpdySettingsUploadBandwidth(SpdySettingsMap* spdy_settings_map, 73 void InitializeSpdySettingsUploadBandwidth(SpdySettingsMap* spdy_settings_map,
74 const HostPortPair& spdy_server, 74 const HostPortPair& spdy_server,
(...skipping 24 matching lines...) Expand all
99 } 99 }
100 } 100 }
101 101
102 HttpServerPropertiesImpl impl_; 102 HttpServerPropertiesImpl impl_;
103 }; 103 };
104 104
105 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; 105 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest;
106 106
107 TEST_F(SpdyServerPropertiesTest, Initialize) { 107 TEST_F(SpdyServerPropertiesTest, Initialize) {
108 HostPortPair spdy_server_google("www.google.com", 443); 108 HostPortPair spdy_server_google("www.google.com", 443);
109 SchemeOriginPair google_server("https", spdy_server_google);
109 std::string spdy_server_g = spdy_server_google.ToString(); 110 std::string spdy_server_g = spdy_server_google.ToString();
110 111
111 HostPortPair spdy_server_photos("photos.google.com", 443); 112 HostPortPair spdy_server_photos("photos.google.com", 443);
113 SchemeOriginPair photos_server("https", spdy_server_photos);
112 std::string spdy_server_p = spdy_server_photos.ToString(); 114 std::string spdy_server_p = spdy_server_photos.ToString();
113 115
114 HostPortPair spdy_server_docs("docs.google.com", 443); 116 HostPortPair spdy_server_docs("docs.google.com", 443);
117 SchemeOriginPair docs_server("https", spdy_server_docs);
115 std::string spdy_server_d = spdy_server_docs.ToString(); 118 std::string spdy_server_d = spdy_server_docs.ToString();
116 119
117 HostPortPair spdy_server_mail("mail.google.com", 443); 120 HostPortPair spdy_server_mail("mail.google.com", 443);
121 SchemeOriginPair mail_server("https", spdy_server_mail);
118 std::string spdy_server_m = spdy_server_mail.ToString(); 122 std::string spdy_server_m = spdy_server_mail.ToString();
119 123
120 // Check by initializing NULL spdy servers. 124 // Check by initializing NULL spdy servers.
121 impl_.InitializeSpdyServers(NULL, true); 125 impl_.InitializeSpdyServers(NULL, true);
122 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); 126 EXPECT_FALSE(impl_.SupportsRequestPriority(google_server));
123 127
124 // Check by initializing empty spdy servers. 128 // Check by initializing empty spdy servers.
125 std::vector<std::string> spdy_servers; 129 std::vector<std::string> spdy_servers;
126 impl_.InitializeSpdyServers(&spdy_servers, true); 130 impl_.InitializeSpdyServers(&spdy_servers, true);
127 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); 131 EXPECT_FALSE(impl_.SupportsRequestPriority(google_server));
128 132
129 // Check by initializing www.google.com:443 and photos.google.com:443 as spdy 133 // Check by initializing www.google.com:443 and photos.google.com:443 as spdy
130 // servers. 134 // servers.
131 std::vector<std::string> spdy_servers1; 135 std::vector<std::string> spdy_servers1;
132 spdy_servers1.push_back(spdy_server_g); // Will be 0th index. 136 spdy_servers1.push_back(spdy_server_g); // Will be 0th index.
133 spdy_servers1.push_back(spdy_server_p); // Will be 1st index. 137 spdy_servers1.push_back(spdy_server_p); // Will be 1st index.
134 impl_.InitializeSpdyServers(&spdy_servers1, true); 138 impl_.InitializeSpdyServers(&spdy_servers1, true);
135 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); 139 EXPECT_TRUE(impl_.SupportsRequestPriority(photos_server));
136 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 140 EXPECT_TRUE(impl_.SupportsRequestPriority(google_server));
137 141
138 // Verify spdy_server_g and spdy_server_d are in the list in the same order. 142 // Verify spdy_server_g and spdy_server_d are in the list in the same order.
139 base::ListValue spdy_server_list; 143 base::ListValue spdy_server_list;
140 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 144 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
141 EXPECT_EQ(2U, spdy_server_list.GetSize()); 145 EXPECT_EQ(2U, spdy_server_list.GetSize());
142 std::string string_value_g; 146 std::string string_value_g;
143 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); // 0th index. 147 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); // 0th index.
144 ASSERT_EQ(spdy_server_g, string_value_g); 148 ASSERT_EQ(spdy_server_g, string_value_g);
145 std::string string_value_p; 149 std::string string_value_p;
146 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); // 1st index. 150 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); // 1st index.
(...skipping 15 matching lines...) Expand all
162 ASSERT_EQ(spdy_server_g, string_value_g); 166 ASSERT_EQ(spdy_server_g, string_value_g);
163 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); 167 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p));
164 ASSERT_EQ(spdy_server_p, string_value_p); 168 ASSERT_EQ(spdy_server_p, string_value_p);
165 std::string string_value_m; 169 std::string string_value_m;
166 ASSERT_TRUE(spdy_server_list.GetString(2, &string_value_m)); 170 ASSERT_TRUE(spdy_server_list.GetString(2, &string_value_m));
167 ASSERT_EQ(spdy_server_m, string_value_m); 171 ASSERT_EQ(spdy_server_m, string_value_m);
168 std::string string_value_d; 172 std::string string_value_d;
169 ASSERT_TRUE(spdy_server_list.GetString(3, &string_value_d)); 173 ASSERT_TRUE(spdy_server_list.GetString(3, &string_value_d));
170 ASSERT_EQ(spdy_server_d, string_value_d); 174 ASSERT_EQ(spdy_server_d, string_value_d);
171 175
172 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); 176 EXPECT_TRUE(impl_.SupportsRequestPriority(docs_server));
173 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); 177 EXPECT_TRUE(impl_.SupportsRequestPriority(mail_server));
174 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); 178 EXPECT_TRUE(impl_.SupportsRequestPriority(photos_server));
175 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 179 EXPECT_TRUE(impl_.SupportsRequestPriority(google_server));
176 180
177 // Verify new data that is being initialized overwrites what is already in the 181 // Verify new data that is being initialized overwrites what is already in the
178 // memory and also verify the recency list order. 182 // memory and also verify the recency list order.
179 // 183 //
180 // Change supports SPDY value for photos and mails servers and order of 184 // Change supports SPDY value for photos and mails servers and order of
181 // initalization shouldn't matter. 185 // initalization shouldn't matter.
182 std::vector<std::string> spdy_servers3; 186 std::vector<std::string> spdy_servers3;
183 spdy_servers3.push_back(spdy_server_m); 187 spdy_servers3.push_back(spdy_server_m);
184 spdy_servers3.push_back(spdy_server_p); 188 spdy_servers3.push_back(spdy_server_p);
185 impl_.InitializeSpdyServers(&spdy_servers3, false); 189 impl_.InitializeSpdyServers(&spdy_servers3, false);
186 190
187 // Verify the entries are in the same order. 191 // Verify the entries are in the same order.
188 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 192 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
189 ASSERT_EQ(spdy_server_g, string_value_g); 193 ASSERT_EQ(spdy_server_g, string_value_g);
190 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); 194 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p));
191 ASSERT_EQ(spdy_server_p, string_value_p); 195 ASSERT_EQ(spdy_server_p, string_value_p);
192 ASSERT_TRUE(spdy_server_list.GetString(2, &string_value_m)); 196 ASSERT_TRUE(spdy_server_list.GetString(2, &string_value_m));
193 ASSERT_EQ(spdy_server_m, string_value_m); 197 ASSERT_EQ(spdy_server_m, string_value_m);
194 ASSERT_TRUE(spdy_server_list.GetString(3, &string_value_d)); 198 ASSERT_TRUE(spdy_server_list.GetString(3, &string_value_d));
195 ASSERT_EQ(spdy_server_d, string_value_d); 199 ASSERT_EQ(spdy_server_d, string_value_d);
196 200
197 // Verify photos and mail servers don't support SPDY and other servers support 201 // Verify photos and mail servers don't support SPDY and other servers support
198 // SPDY. 202 // SPDY.
199 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); 203 EXPECT_TRUE(impl_.SupportsRequestPriority(docs_server));
200 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); 204 EXPECT_FALSE(impl_.SupportsRequestPriority(mail_server));
201 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos)); 205 EXPECT_FALSE(impl_.SupportsRequestPriority(photos_server));
202 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 206 EXPECT_TRUE(impl_.SupportsRequestPriority(google_server));
203 } 207 }
204 208
205 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { 209 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) {
206 HostPortPair spdy_server_empty(std::string(), 443); 210 SchemeOriginPair spdy_server_empty("https", std::string(), 443);
211
207 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); 212 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty));
208 213
209 // Add www.google.com:443 as supporting SPDY. 214 // Add www.google.com:443 as supporting SPDY.
210 HostPortPair spdy_server_google("www.google.com", 443); 215 HostPortPair spdy_server_google("www.google.com", 443);
216 SchemeOriginPair google_server("https", spdy_server_google);
211 impl_.SetSupportsSpdy(spdy_server_google, true); 217 impl_.SetSupportsSpdy(spdy_server_google, true);
212 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 218 EXPECT_TRUE(impl_.SupportsRequestPriority(google_server));
213 219
214 // Add mail.google.com:443 as not supporting SPDY. 220 // Add mail.google.com:443 as not supporting SPDY.
215 HostPortPair spdy_server_mail("mail.google.com", 443); 221 SchemeOriginPair spdy_server_mail("https", "mail.google.com", 443);
216 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); 222 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail));
217 223
218 // Add docs.google.com:443 as supporting SPDY. 224 // Add docs.google.com:443 as supporting SPDY.
219 HostPortPair spdy_server_docs("docs.google.com", 443); 225 HostPortPair spdy_server_docs("docs.google.com", 443);
226 SchemeOriginPair docs_server("https", spdy_server_docs);
220 impl_.SetSupportsSpdy(spdy_server_docs, true); 227 impl_.SetSupportsSpdy(spdy_server_docs, true);
221 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); 228 EXPECT_TRUE(impl_.SupportsRequestPriority(docs_server));
222 229
223 // Add www.youtube.com:443 as supporting QUIC. 230 // Add www.youtube.com:443 as supporting QUIC.
224 HostPortPair quic_server_youtube("www.youtube.com", 443); 231 SchemeOriginPair quic_server_youtube("https", "www.youtube.com", 443);
225 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); 232 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443);
226 SetAlternativeService(quic_server_youtube, alternative_service1, 1.0); 233 SetAlternativeService(quic_server_youtube, alternative_service1, 1.0);
227 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); 234 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube));
228 235
229 // Add www.example.com:443 with two alternative services, one supporting QUIC. 236 // Add www.example.com:443 with two alternative services, one supporting QUIC.
230 HostPortPair quic_server_example("www.example.com", 443); 237 SchemeOriginPair quic_server_example("https", "www.example.com", 443);
231 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); 238 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443);
232 SetAlternativeService(quic_server_example, alternative_service2, 1.0); 239 SetAlternativeService(quic_server_example, alternative_service2, 1.0);
233 SetAlternativeService(quic_server_example, alternative_service1, 1.0); 240 SetAlternativeService(quic_server_example, alternative_service1, 1.0);
234 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); 241 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example));
235 242
236 // Verify all the entries are the same after additions. 243 // Verify all the entries are the same after additions.
237 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 244 EXPECT_TRUE(impl_.SupportsRequestPriority(google_server));
238 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); 245 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail));
239 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); 246 EXPECT_TRUE(impl_.SupportsRequestPriority(docs_server));
240 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); 247 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube));
241 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); 248 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example));
242 } 249 }
243 250
244 TEST_F(SpdyServerPropertiesTest, Clear) { 251 TEST_F(SpdyServerPropertiesTest, Clear) {
245 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. 252 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY.
246 HostPortPair spdy_server_google("www.google.com", 443); 253 HostPortPair spdy_server_google("www.google.com", 443);
254 SchemeOriginPair google_server("https", spdy_server_google);
247 impl_.SetSupportsSpdy(spdy_server_google, true); 255 impl_.SetSupportsSpdy(spdy_server_google, true);
248 HostPortPair spdy_server_mail("mail.google.com", 443); 256 HostPortPair spdy_server_mail("mail.google.com", 443);
257 SchemeOriginPair mail_server("https", spdy_server_mail);
249 impl_.SetSupportsSpdy(spdy_server_mail, true); 258 impl_.SetSupportsSpdy(spdy_server_mail, true);
250 259
251 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 260 EXPECT_TRUE(impl_.SupportsRequestPriority(google_server));
252 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); 261 EXPECT_TRUE(impl_.SupportsRequestPriority(mail_server));
253 262
254 impl_.Clear(); 263 impl_.Clear();
255 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); 264 EXPECT_FALSE(impl_.SupportsRequestPriority(google_server));
256 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); 265 EXPECT_FALSE(impl_.SupportsRequestPriority(mail_server));
257 } 266 }
258 267
259 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { 268 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) {
260 base::ListValue spdy_server_list; 269 base::ListValue spdy_server_list;
261 270
262 // Check there are no spdy_servers. 271 // Check there are no spdy_servers.
263 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 272 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
264 EXPECT_EQ(0U, spdy_server_list.GetSize()); 273 EXPECT_EQ(0U, spdy_server_list.GetSize());
265 274
266 // Check empty server is not added. 275 // Check empty server is not added.
267 HostPortPair spdy_server_empty(std::string(), 443); 276 HostPortPair spdy_server_empty(std::string(), 443);
277 SchemeOriginPair empty_server("https", spdy_server_empty);
268 impl_.SetSupportsSpdy(spdy_server_empty, true); 278 impl_.SetSupportsSpdy(spdy_server_empty, true);
269 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 279 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
270 EXPECT_EQ(0U, spdy_server_list.GetSize()); 280 EXPECT_EQ(0U, spdy_server_list.GetSize());
271 281
272 std::string string_value_g; 282 std::string string_value_g;
273 std::string string_value_m; 283 std::string string_value_m;
274 HostPortPair spdy_server_google("www.google.com", 443); 284 HostPortPair spdy_server_google("www.google.com", 443);
285 SchemeOriginPair google_server("https", spdy_server_google);
275 std::string spdy_server_g = spdy_server_google.ToString(); 286 std::string spdy_server_g = spdy_server_google.ToString();
276 HostPortPair spdy_server_mail("mail.google.com", 443); 287 HostPortPair spdy_server_mail("mail.google.com", 443);
288 SchemeOriginPair mail_server("https", spdy_server_mail);
277 std::string spdy_server_m = spdy_server_mail.ToString(); 289 std::string spdy_server_m = spdy_server_mail.ToString();
278 290
279 // Add www.google.com:443 as not supporting SPDY. 291 // Add www.google.com:443 as not supporting SPDY.
280 impl_.SetSupportsSpdy(spdy_server_google, false); 292 impl_.SetSupportsSpdy(spdy_server_google, false);
281 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 293 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
282 EXPECT_EQ(0U, spdy_server_list.GetSize()); 294 EXPECT_EQ(0U, spdy_server_list.GetSize());
283 295
284 // Add www.google.com:443 as supporting SPDY. 296 // Add www.google.com:443 as supporting SPDY.
285 impl_.SetSupportsSpdy(spdy_server_google, true); 297 impl_.SetSupportsSpdy(spdy_server_google, true);
286 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 298 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
(...skipping 25 matching lines...) Expand all
312 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); 324 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m));
313 ASSERT_EQ(spdy_server_m, string_value_m); 325 ASSERT_EQ(spdy_server_m, string_value_m);
314 } 326 }
315 327
316 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { 328 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) {
317 base::ListValue spdy_server_list; 329 base::ListValue spdy_server_list;
318 330
319 std::string string_value_g; 331 std::string string_value_g;
320 std::string string_value_m; 332 std::string string_value_m;
321 HostPortPair spdy_server_google("www.google.com", 443); 333 HostPortPair spdy_server_google("www.google.com", 443);
334 SchemeOriginPair google_server("https", spdy_server_google);
322 std::string spdy_server_g = spdy_server_google.ToString(); 335 std::string spdy_server_g = spdy_server_google.ToString();
323 HostPortPair spdy_server_mail("mail.google.com", 443); 336 HostPortPair spdy_server_mail("mail.google.com", 443);
337 SchemeOriginPair mail_server("https", spdy_server_mail);
324 std::string spdy_server_m = spdy_server_mail.ToString(); 338 std::string spdy_server_m = spdy_server_mail.ToString();
325 339
326 // Add www.google.com:443 as supporting SPDY. 340 // Add www.google.com:443 as supporting SPDY.
327 impl_.SetSupportsSpdy(spdy_server_google, true); 341 impl_.SetSupportsSpdy(spdy_server_google, true);
328 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 342 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
329 ASSERT_EQ(1U, spdy_server_list.GetSize()); 343 ASSERT_EQ(1U, spdy_server_list.GetSize());
330 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 344 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
331 ASSERT_EQ(spdy_server_g, string_value_g); 345 ASSERT_EQ(spdy_server_g, string_value_g);
332 346
333 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and 347 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and
334 // www.google.com:443 are in the list. 348 // www.google.com:443 are in the list.
335 impl_.SetSupportsSpdy(spdy_server_mail, true); 349 impl_.SetSupportsSpdy(spdy_server_mail, true);
336 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 350 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
337 ASSERT_EQ(2U, spdy_server_list.GetSize()); 351 ASSERT_EQ(2U, spdy_server_list.GetSize());
338 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); 352 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m));
339 ASSERT_EQ(spdy_server_m, string_value_m); 353 ASSERT_EQ(spdy_server_m, string_value_m);
340 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g)); 354 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g));
341 ASSERT_EQ(spdy_server_g, string_value_g); 355 ASSERT_EQ(spdy_server_g, string_value_g);
342 356
343 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it 357 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it
344 // is www.google.com:443 is the MRU server. 358 // is www.google.com:443 is the MRU server.
345 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 359 EXPECT_TRUE(impl_.SupportsRequestPriority(google_server));
346 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 360 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
347 ASSERT_EQ(2U, spdy_server_list.GetSize()); 361 ASSERT_EQ(2U, spdy_server_list.GetSize());
348 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 362 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
349 ASSERT_EQ(spdy_server_g, string_value_g); 363 ASSERT_EQ(spdy_server_g, string_value_g);
350 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); 364 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m));
351 ASSERT_EQ(spdy_server_m, string_value_m); 365 ASSERT_EQ(spdy_server_m, string_value_m);
352 } 366 }
353 367
354 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; 368 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest;
355 369
356 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { 370 TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
357 HostPortPair test_host_port_pair("foo", 80); 371 SchemeOriginPair scheme_origin("http", "foo", 80);
358 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 372 EXPECT_FALSE(HasAlternativeService(scheme_origin));
359 373
360 AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); 374 AlternativeService alternative_service(NPN_HTTP_2, "foo", 443);
361 SetAlternativeService(test_host_port_pair, alternative_service, 1.0); 375 SetAlternativeService(scheme_origin, alternative_service, 1.0);
362 const AlternativeServiceVector alternative_service_vector = 376 const AlternativeServiceVector alternative_service_vector =
363 impl_.GetAlternativeServices(test_host_port_pair); 377 impl_.GetAlternativeServices(scheme_origin);
364 ASSERT_EQ(1u, alternative_service_vector.size()); 378 ASSERT_EQ(1u, alternative_service_vector.size());
365 EXPECT_EQ(alternative_service, alternative_service_vector[0]); 379 EXPECT_EQ(alternative_service, alternative_service_vector[0]);
366 380
367 impl_.Clear(); 381 impl_.Clear();
368 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 382 EXPECT_FALSE(HasAlternativeService(scheme_origin));
369 } 383 }
370 384
371 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { 385 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) {
372 AlternativeServiceInfoVector alternative_service_info_vector; 386 AlternativeServiceInfoVector alternative_service_info_vector;
373 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 387 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
374 // Same hostname, same port, TCP: should be ignored. 388 // Same hostname, same port, TCP: should be ignored.
375 AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); 389 AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443);
376 alternative_service_info_vector.push_back( 390 alternative_service_info_vector.push_back(
377 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); 391 AlternativeServiceInfo(alternative_service1, 1.0, expiration));
378 // Different hostname: GetAlternativeServices should return this one. 392 // Different hostname: GetAlternativeServices should return this one.
379 AlternativeService alternative_service2(NPN_HTTP_2, "bar", 443); 393 AlternativeService alternative_service2(NPN_HTTP_2, "bar", 443);
380 alternative_service_info_vector.push_back( 394 alternative_service_info_vector.push_back(
381 AlternativeServiceInfo(alternative_service2, 1.0, expiration)); 395 AlternativeServiceInfo(alternative_service2, 1.0, expiration));
382 // Different port: GetAlternativeServices should return this one too. 396 // Different port: GetAlternativeServices should return this one too.
383 AlternativeService alternative_service3(NPN_HTTP_2, "foo", 80); 397 AlternativeService alternative_service3(NPN_HTTP_2, "foo", 80);
384 alternative_service_info_vector.push_back( 398 alternative_service_info_vector.push_back(
385 AlternativeServiceInfo(alternative_service3, 1.0, expiration)); 399 AlternativeServiceInfo(alternative_service3, 1.0, expiration));
386 // QUIC: GetAlternativeServices should return this one too. 400 // QUIC: GetAlternativeServices should return this one too.
387 AlternativeService alternative_service4(QUIC, "foo", 443); 401 AlternativeService alternative_service4(QUIC, "foo", 443);
388 alternative_service_info_vector.push_back( 402 alternative_service_info_vector.push_back(
389 AlternativeServiceInfo(alternative_service4, 1.0, expiration)); 403 AlternativeServiceInfo(alternative_service4, 1.0, expiration));
390 404
391 HostPortPair test_host_port_pair("foo", 443); 405 SchemeOriginPair scheme_origin("https", "foo", 443);
392 impl_.SetAlternativeServices(test_host_port_pair, 406 impl_.SetAlternativeServices(scheme_origin, alternative_service_info_vector);
393 alternative_service_info_vector);
394 407
395 const AlternativeServiceVector alternative_service_vector = 408 const AlternativeServiceVector alternative_service_vector =
396 impl_.GetAlternativeServices(test_host_port_pair); 409 impl_.GetAlternativeServices(scheme_origin);
397 ASSERT_EQ(3u, alternative_service_vector.size()); 410 ASSERT_EQ(3u, alternative_service_vector.size());
398 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); 411 EXPECT_EQ(alternative_service2, alternative_service_vector[0]);
399 EXPECT_EQ(alternative_service3, alternative_service_vector[1]); 412 EXPECT_EQ(alternative_service3, alternative_service_vector[1]);
400 EXPECT_EQ(alternative_service4, alternative_service_vector[2]); 413 EXPECT_EQ(alternative_service4, alternative_service_vector[2]);
401 } 414 }
402 415
403 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { 416 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) {
404 HostPortPair test_host_port_pair("foo", 80); 417 SchemeOriginPair scheme_origin("http", "foo", 80);
405 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); 418 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443);
406 SetAlternativeService(test_host_port_pair, alternative_service, 0.99); 419 SetAlternativeService(scheme_origin, alternative_service, 0.99);
407 420
408 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 421 EXPECT_FALSE(HasAlternativeService(scheme_origin));
409 } 422 }
410 423
411 // GetAlternativeServices and HasAlternativeServices should only return the ones 424 // GetAlternativeServices and HasAlternativeServices should only return the ones
412 // with probability greater than or equal to the threshold. 425 // with probability greater than or equal to the threshold.
413 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { 426 TEST_F(AlternateProtocolServerPropertiesTest, Probability) {
414 impl_.SetAlternativeServiceProbabilityThreshold(0.5); 427 impl_.SetAlternativeServiceProbabilityThreshold(0.5);
415 428
416 AlternativeServiceInfoVector alternative_service_info_vector; 429 AlternativeServiceInfoVector alternative_service_info_vector;
417 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 430 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
418 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); 431 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443);
419 alternative_service_info_vector.push_back( 432 alternative_service_info_vector.push_back(
420 AlternativeServiceInfo(alternative_service1, 0.3, expiration)); 433 AlternativeServiceInfo(alternative_service1, 0.3, expiration));
421 const AlternativeService alternative_service2(QUIC, "bar", 123); 434 const AlternativeService alternative_service2(QUIC, "bar", 123);
422 alternative_service_info_vector.push_back( 435 alternative_service_info_vector.push_back(
423 AlternativeServiceInfo(alternative_service2, 0.7, expiration)); 436 AlternativeServiceInfo(alternative_service2, 0.7, expiration));
424 const AlternativeService alternative_service3(NPN_SPDY_3_1, "baz", 443); 437 const AlternativeService alternative_service3(NPN_SPDY_3_1, "baz", 443);
425 alternative_service_info_vector.push_back( 438 alternative_service_info_vector.push_back(
426 AlternativeServiceInfo(alternative_service3, 0.4, expiration)); 439 AlternativeServiceInfo(alternative_service3, 0.4, expiration));
427 const AlternativeService alternative_service4(NPN_HTTP_2, "qux", 1234); 440 const AlternativeService alternative_service4(NPN_HTTP_2, "qux", 1234);
428 alternative_service_info_vector.push_back( 441 alternative_service_info_vector.push_back(
429 AlternativeServiceInfo(alternative_service4, 0.6, expiration)); 442 AlternativeServiceInfo(alternative_service4, 0.6, expiration));
430 443
431 HostPortPair test_host_port_pair("foo", 80); 444 SchemeOriginPair scheme_origin("http", "foo", 80);
432 impl_.SetAlternativeServices(test_host_port_pair, 445 impl_.SetAlternativeServices(scheme_origin, alternative_service_info_vector);
433 alternative_service_info_vector);
434 446
435 const AlternativeServiceVector alternative_service_vector = 447 const AlternativeServiceVector alternative_service_vector =
436 impl_.GetAlternativeServices(test_host_port_pair); 448 impl_.GetAlternativeServices(scheme_origin);
437 ASSERT_EQ(2u, alternative_service_vector.size()); 449 ASSERT_EQ(2u, alternative_service_vector.size());
438 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); 450 EXPECT_EQ(alternative_service2, alternative_service_vector[0]);
439 EXPECT_EQ(alternative_service4, alternative_service_vector[1]); 451 EXPECT_EQ(alternative_service4, alternative_service_vector[1]);
440 } 452 }
441 453
442 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { 454 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) {
443 impl_.SetAlternativeServiceProbabilityThreshold(0.75); 455 impl_.SetAlternativeServiceProbabilityThreshold(0.75);
444 456
445 HostPortPair test_host_port_pair("foo", 80); 457 SchemeOriginPair scheme_origin("http", "foo", 80);
446 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); 458 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443);
447 SetAlternativeService(test_host_port_pair, alternative_service, 0.5); 459 SetAlternativeService(scheme_origin, alternative_service, 0.5);
448 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 460 EXPECT_FALSE(HasAlternativeService(scheme_origin));
449 } 461 }
450 462
451 TEST_F(AlternateProtocolServerPropertiesTest, ZeroProbabilityAlwaysExcluded) { 463 TEST_F(AlternateProtocolServerPropertiesTest, ZeroProbabilityAlwaysExcluded) {
452 impl_.SetAlternativeServiceProbabilityThreshold(0.0); 464 impl_.SetAlternativeServiceProbabilityThreshold(0.0);
453 465
454 HostPortPair test_host_port_pair("foo", 80); 466 SchemeOriginPair scheme_origin("http", "foo", 80);
455 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); 467 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443);
456 SetAlternativeService(test_host_port_pair, alternative_service, 0); 468 SetAlternativeService(scheme_origin, alternative_service, 0);
457 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 469 EXPECT_FALSE(HasAlternativeService(scheme_origin));
458 } 470 }
459 471
460 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { 472 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) {
461 // |test_host_port_pair1| has an alternative service, which will not be 473 // |test_host_port_pair1| has an alternative service, which will not be
462 // affected by InitializeAlternativeServiceServers(), because 474 // affected by InitializeAlternativeServiceServers(), because
463 // |alternative_service_map| does not have an entry for 475 // |alternative_service_map| does not have an entry for
464 // |test_host_port_pair1|. 476 // |test_host_port_pair1|.
465 HostPortPair test_host_port_pair1("foo1", 80); 477 HostPortPair test_host_port_pair1("foo1", 80);
478 SchemeOriginPair scheme_origin1("http", test_host_port_pair1);
466 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); 479 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443);
467 const base::Time now = base::Time::Now(); 480 const base::Time now = base::Time::Now();
468 base::Time expiration1 = now + base::TimeDelta::FromDays(1); 481 base::Time expiration1 = now + base::TimeDelta::FromDays(1);
469 // 1st entry in the memory. 482 // 1st entry in the memory.
470 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0, 483 impl_.SetAlternativeService(scheme_origin1, alternative_service1, 1.0,
471 expiration1); 484 expiration1);
472 485
473 // |test_host_port_pair2| has an alternative service, which will be 486 // |test_host_port_pair2| has an alternative service, which will be
474 // overwritten by InitializeAlternativeServiceServers(), because 487 // overwritten by InitializeAlternativeServiceServers(), because
475 // |alternative_service_map| has an entry for 488 // |alternative_service_map| has an entry for
476 // |test_host_port_pair2|. 489 // |test_host_port_pair2|.
477 AlternativeServiceInfoVector alternative_service_info_vector; 490 AlternativeServiceInfoVector alternative_service_info_vector;
478 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); 491 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443);
479 base::Time expiration2 = now + base::TimeDelta::FromDays(2); 492 base::Time expiration2 = now + base::TimeDelta::FromDays(2);
480 alternative_service_info_vector.push_back( 493 alternative_service_info_vector.push_back(
481 AlternativeServiceInfo(alternative_service2, 1.0, expiration2)); 494 AlternativeServiceInfo(alternative_service2, 1.0, expiration2));
482 HostPortPair test_host_port_pair2("foo2", 80); 495 HostPortPair test_host_port_pair2("foo2", 80);
496 SchemeOriginPair scheme_origin2("http", test_host_port_pair2);
483 // 0th entry in the memory. 497 // 0th entry in the memory.
484 impl_.SetAlternativeServices(test_host_port_pair2, 498 impl_.SetAlternativeServices(scheme_origin2, alternative_service_info_vector);
485 alternative_service_info_vector);
486 499
487 // Prepare |alternative_service_map| to be loaded by 500 // Prepare |alternative_service_map| to be loaded by
488 // InitializeAlternativeServiceServers(). 501 // InitializeAlternativeServiceServers().
489 AlternativeServiceMap alternative_service_map( 502 AlternativeServiceMap alternative_service_map(
490 AlternativeServiceMap::NO_AUTO_EVICT); 503 AlternativeServiceMap::NO_AUTO_EVICT);
491 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); 504 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123);
492 base::Time expiration3 = now + base::TimeDelta::FromDays(3); 505 base::Time expiration3 = now + base::TimeDelta::FromDays(3);
493 const AlternativeServiceInfo alternative_service_info1(alternative_service3, 506 const AlternativeServiceInfo alternative_service_info1(alternative_service3,
494 0.7, expiration3); 507 0.7, expiration3);
495 // Simulate updating data for 0th entry with data from Preferences. 508 // Simulate updating data for 0th entry with data from Preferences.
496 alternative_service_map.Put( 509 alternative_service_map.Put(
497 test_host_port_pair2, 510 scheme_origin2,
498 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); 511 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1));
499 512
500 HostPortPair test_host_port_pair3("foo3", 80); 513 HostPortPair test_host_port_pair3("foo3", 80);
514 SchemeOriginPair scheme_origin3("http", test_host_port_pair3);
501 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); 515 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234);
502 base::Time expiration4 = now + base::TimeDelta::FromDays(4); 516 base::Time expiration4 = now + base::TimeDelta::FromDays(4);
503 const AlternativeServiceInfo alternative_service_info2(alternative_service4, 517 const AlternativeServiceInfo alternative_service_info2(alternative_service4,
504 0.2, expiration4); 518 0.2, expiration4);
505 // Add an old entry from Preferences, this will be added to end of recency 519 // Add an old entry from Preferences, this will be added to end of recency
506 // list. 520 // list.
507 alternative_service_map.Put( 521 alternative_service_map.Put(
508 test_host_port_pair3, 522 scheme_origin3,
509 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); 523 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2));
510 524
511 // MRU list will be test_host_port_pair2, test_host_port_pair1, 525 // MRU list will be test_host_port_pair2, test_host_port_pair1,
512 // test_host_port_pair3. 526 // test_host_port_pair3.
513 impl_.InitializeAlternativeServiceServers(&alternative_service_map); 527 impl_.InitializeAlternativeServiceServers(&alternative_service_map);
514 528
515 // Verify alternative_service_map. 529 // Verify alternative_service_map.
516 const AlternativeServiceMap& map = impl_.alternative_service_map(); 530 const AlternativeServiceMap& map = impl_.alternative_service_map();
517 ASSERT_EQ(3u, map.size()); 531 ASSERT_EQ(3u, map.size());
518 AlternativeServiceMap::const_iterator map_it = map.begin(); 532 AlternativeServiceMap::const_iterator map_it = map.begin();
519 533
520 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2)); 534 EXPECT_TRUE(map_it->first.host_port_pair().Equals(test_host_port_pair2));
521 ASSERT_EQ(1u, map_it->second.size()); 535 ASSERT_EQ(1u, map_it->second.size());
522 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); 536 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service);
523 EXPECT_EQ(0.7, map_it->second[0].probability); 537 EXPECT_EQ(0.7, map_it->second[0].probability);
524 EXPECT_EQ(expiration3, map_it->second[0].expiration); 538 EXPECT_EQ(expiration3, map_it->second[0].expiration);
525 ++map_it; 539 ++map_it;
526 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair1)); 540 EXPECT_TRUE(map_it->first.host_port_pair().Equals(test_host_port_pair1));
527 ASSERT_EQ(1u, map_it->second.size()); 541 ASSERT_EQ(1u, map_it->second.size());
528 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); 542 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service);
529 EXPECT_EQ(1.0, map_it->second[0].probability); 543 EXPECT_EQ(1.0, map_it->second[0].probability);
530 EXPECT_EQ(expiration1, map_it->second[0].expiration); 544 EXPECT_EQ(expiration1, map_it->second[0].expiration);
531 ++map_it; 545 ++map_it;
532 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3)); 546 EXPECT_TRUE(map_it->first.host_port_pair().Equals(test_host_port_pair3));
533 ASSERT_EQ(1u, map_it->second.size()); 547 ASSERT_EQ(1u, map_it->second.size());
534 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); 548 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service);
535 EXPECT_EQ(0.2, map_it->second[0].probability); 549 EXPECT_EQ(0.2, map_it->second[0].probability);
536 EXPECT_EQ(expiration4, map_it->second[0].expiration); 550 EXPECT_EQ(expiration4, map_it->second[0].expiration);
537 } 551 }
538 552
539 // Regression test for https://crbug.com/504032: 553 // Regression test for https://crbug.com/504032:
540 // InitializeAlternativeServiceServers() should not crash if there is an empty 554 // InitializeAlternativeServiceServers() should not crash if there is an empty
541 // hostname is the mapping. 555 // hostname is the mapping.
542 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { 556 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) {
543 const HostPortPair host_port_pair("foo", 443); 557 SchemeOriginPair scheme_origin("https", "foo", 443);
544 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, 558 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2,
545 "", 1234); 559 "", 1234);
546 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, 560 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2,
547 "foo", 1234); 561 "foo", 1234);
548 SetAlternativeService(host_port_pair, alternative_service_with_empty_hostname, 562 SetAlternativeService(scheme_origin, alternative_service_with_empty_hostname,
549 1.0); 563 1.0);
550 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); 564 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname);
551 565
552 AlternativeServiceMap alternative_service_map( 566 AlternativeServiceMap alternative_service_map(
553 AlternativeServiceMap::NO_AUTO_EVICT); 567 AlternativeServiceMap::NO_AUTO_EVICT);
554 impl_.InitializeAlternativeServiceServers(&alternative_service_map); 568 impl_.InitializeAlternativeServiceServers(&alternative_service_map);
555 569
556 EXPECT_TRUE( 570 EXPECT_TRUE(
557 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); 571 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname));
558 const AlternativeServiceVector alternative_service_vector = 572 const AlternativeServiceVector alternative_service_vector =
559 impl_.GetAlternativeServices(host_port_pair); 573 impl_.GetAlternativeServices(scheme_origin);
560 ASSERT_EQ(1u, alternative_service_vector.size()); 574 ASSERT_EQ(1u, alternative_service_vector.size());
561 EXPECT_EQ(alternative_service_with_foo_hostname, 575 EXPECT_EQ(alternative_service_with_foo_hostname,
562 alternative_service_vector[0]); 576 alternative_service_vector[0]);
563 } 577 }
564 578
565 // Regression test for https://crbug.com/516486: 579 // Regression test for https://crbug.com/516486:
566 // GetAlternativeServices() should remove |alternative_service_map_| elements 580 // GetAlternativeServices() should remove |alternative_service_map_| elements
567 // with empty value. 581 // with empty value.
568 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { 582 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) {
569 HostPortPair host_port_pair("foo", 443); 583 HostPortPair host_port_pair("foo", 443);
584 SchemeOriginPair scheme_origin("https", host_port_pair);
570 const AlternativeService alternative_service(NPN_HTTP_2, "bar", 443); 585 const AlternativeService alternative_service(NPN_HTTP_2, "bar", 443);
571 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); 586 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1);
572 const AlternativeServiceInfo alternative_service_info(alternative_service, 587 const AlternativeServiceInfo alternative_service_info(alternative_service,
573 1.0, expiration); 588 1.0, expiration);
574 AlternativeServiceMap alternative_service_map( 589 AlternativeServiceMap alternative_service_map(
575 AlternativeServiceMap::NO_AUTO_EVICT); 590 AlternativeServiceMap::NO_AUTO_EVICT);
576 alternative_service_map.Put( 591 alternative_service_map.Put(
577 host_port_pair, 592 scheme_origin,
578 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 593 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
579 594
580 // Prepare |alternative_service_map_| with a single key that has a single 595 // Prepare |alternative_service_map_| with a single key that has a single
581 // AlternativeServiceInfo with identical hostname and port. 596 // AlternativeServiceInfo with identical hostname and port.
582 impl_.InitializeAlternativeServiceServers(&alternative_service_map); 597 impl_.InitializeAlternativeServiceServers(&alternative_service_map);
583 598
584 // GetAlternativeServices() should remove such AlternativeServiceInfo from 599 // GetAlternativeServices() should remove such AlternativeServiceInfo from
585 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector 600 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector
586 // corresponding to |host_port_pair|. 601 // corresponding to |host_port_pair|.
587 AlternativeServiceVector alternative_service_vector = 602 AlternativeServiceVector alternative_service_vector =
588 impl_.GetAlternativeServices(host_port_pair); 603 impl_.GetAlternativeServices(scheme_origin);
589 ASSERT_TRUE(alternative_service_vector.empty()); 604 ASSERT_TRUE(alternative_service_vector.empty());
590 605
591 // GetAlternativeServices() should remove this key from 606 // GetAlternativeServices() should remove this key from
592 // |alternative_service_map_|, and SetAlternativeServices() should not crash. 607 // |alternative_service_map_|, and SetAlternativeServices() should not crash.
593 impl_.SetAlternativeServices( 608 impl_.SetAlternativeServices(
594 host_port_pair, 609 scheme_origin,
595 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 610 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
596 611
597 // There should still be no alternative service assigned to |host_port_pair|. 612 // There should still be no alternative service assigned to |host_port_pair|.
598 alternative_service_vector = impl_.GetAlternativeServices(host_port_pair); 613 alternative_service_vector = impl_.GetAlternativeServices(scheme_origin);
599 ASSERT_TRUE(alternative_service_vector.empty()); 614 ASSERT_TRUE(alternative_service_vector.empty());
600 } 615 }
601 616
602 // Regression test for https://crbug.com/516486 for the canonical host case. 617 // Regression test for https://crbug.com/516486 for the canonical host case.
603 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { 618 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) {
604 HostPortPair host_port_pair("foo.c.youtube.com", 443); 619 HostPortPair host_port_pair("foo.c.youtube.com", 443);
620 SchemeOriginPair scheme_origin("https", host_port_pair);
605 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 443); 621 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 443);
622 SchemeOriginPair canonical_scheme_origin("https", canonical_host_port_pair);
606 const AlternativeService alternative_service(NPN_HTTP_2, "", 443); 623 const AlternativeService alternative_service(NPN_HTTP_2, "", 443);
607 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); 624 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1);
608 const AlternativeServiceInfo alternative_service_info(alternative_service, 625 const AlternativeServiceInfo alternative_service_info(alternative_service,
609 1.0, expiration); 626 1.0, expiration);
610 AlternativeServiceMap alternative_service_map( 627 AlternativeServiceMap alternative_service_map(
611 AlternativeServiceMap::NO_AUTO_EVICT); 628 AlternativeServiceMap::NO_AUTO_EVICT);
612 alternative_service_map.Put( 629 alternative_service_map.Put(
613 canonical_host_port_pair, 630 canonical_scheme_origin,
614 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 631 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
615 632
616 // Prepare |alternative_service_map_| with a single key that has a single 633 // Prepare |alternative_service_map_| with a single key that has a single
617 // AlternativeServiceInfo with identical hostname and port. 634 // AlternativeServiceInfo with identical hostname and port.
618 impl_.InitializeAlternativeServiceServers(&alternative_service_map); 635 impl_.InitializeAlternativeServiceServers(&alternative_service_map);
619 636
620 // GetAlternativeServices() should remove such AlternativeServiceInfo from 637 // GetAlternativeServices() should remove such AlternativeServiceInfo from
621 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector 638 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector
622 // corresponding to |canonical_host_port_pair|, even when looking up 639 // corresponding to |canonical_host_port_pair|, even when looking up
623 // alternative services for |host_port_pair|. 640 // alternative services for |host_port_pair|.
624 AlternativeServiceVector alternative_service_vector = 641 AlternativeServiceVector alternative_service_vector =
625 impl_.GetAlternativeServices(host_port_pair); 642 impl_.GetAlternativeServices(scheme_origin);
626 ASSERT_TRUE(alternative_service_vector.empty()); 643 ASSERT_TRUE(alternative_service_vector.empty());
627 644
628 // GetAlternativeServices() should remove this key from 645 // GetAlternativeServices() should remove this key from
629 // |alternative_service_map_|, and SetAlternativeServices() should not crash. 646 // |alternative_service_map_|, and SetAlternativeServices() should not crash.
630 impl_.SetAlternativeServices( 647 impl_.SetAlternativeServices(
631 canonical_host_port_pair, 648 canonical_scheme_origin,
632 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 649 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
633 650
634 // There should still be no alternative service assigned to 651 // There should still be no alternative service assigned to
635 // |canonical_host_port_pair|. 652 // |canonical_host_port_pair|.
636 alternative_service_vector = 653 alternative_service_vector =
637 impl_.GetAlternativeServices(canonical_host_port_pair); 654 impl_.GetAlternativeServices(canonical_scheme_origin);
638 ASSERT_TRUE(alternative_service_vector.empty()); 655 ASSERT_TRUE(alternative_service_vector.empty());
639 } 656 }
640 657
641 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { 658 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) {
642 HostPortPair test_host_port_pair1("foo1", 80); 659 HostPortPair test_host_port_pair1("foo1", 80);
660 SchemeOriginPair scheme_origin1("http", test_host_port_pair1);
643 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); 661 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443);
644 SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0); 662 SetAlternativeService(scheme_origin1, alternative_service1, 1.0);
645 HostPortPair test_host_port_pair2("foo2", 80); 663 HostPortPair test_host_port_pair2("foo2", 80);
664 SchemeOriginPair scheme_origin2("http", test_host_port_pair2);
646 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); 665 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234);
647 SetAlternativeService(test_host_port_pair2, alternative_service2, 1.0); 666 SetAlternativeService(scheme_origin2, alternative_service2, 1.0);
648 667
649 const AlternativeServiceMap& map = impl_.alternative_service_map(); 668 const AlternativeServiceMap& map = impl_.alternative_service_map();
650 AlternativeServiceMap::const_iterator it = map.begin(); 669 AlternativeServiceMap::const_iterator it = map.begin();
651 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); 670 EXPECT_TRUE(it->first.host_port_pair().Equals(test_host_port_pair2));
652 ASSERT_EQ(1u, it->second.size()); 671 ASSERT_EQ(1u, it->second.size());
653 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); 672 EXPECT_EQ(alternative_service2, it->second[0].alternative_service);
654 673
655 const AlternativeServiceVector alternative_service_vector = 674 const AlternativeServiceVector alternative_service_vector =
656 impl_.GetAlternativeServices(test_host_port_pair1); 675 impl_.GetAlternativeServices(scheme_origin1);
657 ASSERT_EQ(1u, alternative_service_vector.size()); 676 ASSERT_EQ(1u, alternative_service_vector.size());
658 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); 677 EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
659 678
660 // GetAlternativeServices should reorder the AlternateProtocol map. 679 // GetAlternativeServices should reorder the AlternateProtocol map.
661 it = map.begin(); 680 it = map.begin();
662 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); 681 EXPECT_TRUE(it->first.host_port_pair().Equals(test_host_port_pair1));
663 ASSERT_EQ(1u, it->second.size()); 682 ASSERT_EQ(1u, it->second.size());
664 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); 683 EXPECT_EQ(alternative_service1, it->second[0].alternative_service);
665 } 684 }
666 685
667 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { 686 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) {
668 HostPortPair test_host_port_pair("foo", 80); 687 SchemeOriginPair scheme_origin("http", "foo", 80);
669 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); 688 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443);
670 SetAlternativeService(test_host_port_pair, alternative_service1, 1.0); 689 SetAlternativeService(scheme_origin, alternative_service1, 1.0);
671 AlternativeServiceVector alternative_service_vector = 690 AlternativeServiceVector alternative_service_vector =
672 impl_.GetAlternativeServices(test_host_port_pair); 691 impl_.GetAlternativeServices(scheme_origin);
673 ASSERT_EQ(1u, alternative_service_vector.size()); 692 ASSERT_EQ(1u, alternative_service_vector.size());
674 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); 693 EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
675 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); 694 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1));
676 695
677 // GetAlternativeServices should return the broken alternative service. 696 // GetAlternativeServices should return the broken alternative service.
678 impl_.MarkAlternativeServiceBroken(alternative_service1); 697 impl_.MarkAlternativeServiceBroken(alternative_service1);
679 alternative_service_vector = 698 alternative_service_vector = impl_.GetAlternativeServices(scheme_origin);
680 impl_.GetAlternativeServices(test_host_port_pair);
681 ASSERT_EQ(1u, alternative_service_vector.size()); 699 ASSERT_EQ(1u, alternative_service_vector.size());
682 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); 700 EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
683 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); 701 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1));
684 702
685 // SetAlternativeServices should add a broken alternative service to the map. 703 // SetAlternativeServices should add a broken alternative service to the map.
686 AlternativeServiceInfoVector alternative_service_info_vector; 704 AlternativeServiceInfoVector alternative_service_info_vector;
687 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 705 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
688 alternative_service_info_vector.push_back( 706 alternative_service_info_vector.push_back(
689 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); 707 AlternativeServiceInfo(alternative_service1, 1.0, expiration));
690 const AlternativeService alternative_service2(NPN_HTTP_2, "foo", 1234); 708 const AlternativeService alternative_service2(NPN_HTTP_2, "foo", 1234);
691 alternative_service_info_vector.push_back( 709 alternative_service_info_vector.push_back(
692 AlternativeServiceInfo(alternative_service2, 1.0, expiration)); 710 AlternativeServiceInfo(alternative_service2, 1.0, expiration));
693 impl_.SetAlternativeServices(test_host_port_pair, 711 impl_.SetAlternativeServices(scheme_origin, alternative_service_info_vector);
694 alternative_service_info_vector); 712 alternative_service_vector = impl_.GetAlternativeServices(scheme_origin);
695 alternative_service_vector =
696 impl_.GetAlternativeServices(test_host_port_pair);
697 ASSERT_EQ(2u, alternative_service_vector.size()); 713 ASSERT_EQ(2u, alternative_service_vector.size());
698 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); 714 EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
699 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); 715 EXPECT_EQ(alternative_service2, alternative_service_vector[1]);
700 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); 716 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0]));
701 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1])); 717 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1]));
702 718
703 // SetAlternativeService should add a broken alternative service to the map. 719 // SetAlternativeService should add a broken alternative service to the map.
704 SetAlternativeService(test_host_port_pair, alternative_service1, 1.0); 720 SetAlternativeService(scheme_origin, alternative_service1, 1.0);
705 alternative_service_vector = 721 alternative_service_vector = impl_.GetAlternativeServices(scheme_origin);
706 impl_.GetAlternativeServices(test_host_port_pair);
707 ASSERT_EQ(1u, alternative_service_vector.size()); 722 ASSERT_EQ(1u, alternative_service_vector.size());
708 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); 723 EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
709 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); 724 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0]));
710 } 725 }
711 726
712 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { 727 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) {
713 AlternativeServiceInfoVector alternative_service_info_vector; 728 AlternativeServiceInfoVector alternative_service_info_vector;
714 base::Time now = base::Time::Now(); 729 base::Time now = base::Time::Now();
715 base::TimeDelta one_day = base::TimeDelta::FromDays(1); 730 base::TimeDelta one_day = base::TimeDelta::FromDays(1);
716 731
717 // First alternative service expired one day ago, should not be returned by 732 // First alternative service expired one day ago, should not be returned by
718 // GetAlternativeServices(). 733 // GetAlternativeServices().
719 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); 734 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443);
720 alternative_service_info_vector.push_back( 735 alternative_service_info_vector.push_back(
721 AlternativeServiceInfo(alternative_service1, 1.0, now - one_day)); 736 AlternativeServiceInfo(alternative_service1, 1.0, now - one_day));
722 737
723 // Second alterrnative service will expire one day from now, should be 738 // Second alterrnative service will expire one day from now, should be
724 // returned by GetAlternativeSerices(). 739 // returned by GetAlternativeSerices().
725 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); 740 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234);
726 alternative_service_info_vector.push_back( 741 alternative_service_info_vector.push_back(
727 AlternativeServiceInfo(alternative_service2, 1.0, now + one_day)); 742 AlternativeServiceInfo(alternative_service2, 1.0, now + one_day));
728 743
729 HostPortPair test_host_port_pair("foo", 80); 744 SchemeOriginPair scheme_origin("http", "foo", 80);
730 impl_.SetAlternativeServices(test_host_port_pair, 745 impl_.SetAlternativeServices(scheme_origin, alternative_service_info_vector);
731 alternative_service_info_vector);
732 746
733 AlternativeServiceVector alternative_service_vector = 747 AlternativeServiceVector alternative_service_vector =
734 impl_.GetAlternativeServices(test_host_port_pair); 748 impl_.GetAlternativeServices(scheme_origin);
735 ASSERT_EQ(1u, alternative_service_vector.size()); 749 ASSERT_EQ(1u, alternative_service_vector.size());
736 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); 750 EXPECT_EQ(alternative_service2, alternative_service_vector[0]);
737 } 751 }
738 752
739 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { 753 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) {
740 AlternativeServiceInfoVector alternative_service_info_vector; 754 AlternativeServiceInfoVector alternative_service_info_vector;
741 base::Time now = base::Time::Now(); 755 base::Time now = base::Time::Now();
742 base::TimeDelta one_day = base::TimeDelta::FromDays(1); 756 base::TimeDelta one_day = base::TimeDelta::FromDays(1);
743 757
744 // First alternative service expired one day ago, should not be returned by 758 // First alternative service expired one day ago, should not be returned by
745 // GetAlternativeServices(). 759 // GetAlternativeServices().
746 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); 760 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443);
747 alternative_service_info_vector.push_back( 761 alternative_service_info_vector.push_back(
748 AlternativeServiceInfo(alternative_service1, 1.0, now - one_day)); 762 AlternativeServiceInfo(alternative_service1, 1.0, now - one_day));
749 763
750 // Second alterrnative service will expire one day from now, should be 764 // Second alternative service will expire one day from now, should be
751 // returned by GetAlternativeSerices(). 765 // returned by GetAlternativeSerices().
752 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); 766 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234);
753 alternative_service_info_vector.push_back( 767 alternative_service_info_vector.push_back(
754 AlternativeServiceInfo(alternative_service2, 1.0, now + one_day)); 768 AlternativeServiceInfo(alternative_service2, 1.0, now + one_day));
755 769
756 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); 770 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
757 impl_.SetAlternativeServices(canonical_host_port_pair, 771 impl_.SetAlternativeServices(canonical_scheme_origin,
758 alternative_service_info_vector); 772 alternative_service_info_vector);
759 773
760 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 774 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
761 AlternativeServiceVector alternative_service_vector = 775 AlternativeServiceVector alternative_service_vector =
762 impl_.GetAlternativeServices(test_host_port_pair); 776 impl_.GetAlternativeServices(scheme_origin);
763 ASSERT_EQ(1u, alternative_service_vector.size()); 777 ASSERT_EQ(1u, alternative_service_vector.size());
764 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); 778 EXPECT_EQ(alternative_service2, alternative_service_vector[0]);
765 } 779 }
766 780
781 TEST_F(AlternateProtocolServerPropertiesTest,
782 SetAlternativeServicesWithScheme) {
783 AlternativeServiceInfoVector alternative_service_info_vector;
784 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443);
785 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
786 alternative_service_info_vector.push_back(
787 AlternativeServiceInfo(alternative_service1, 1.0, expiration));
788 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234);
789 alternative_service_info_vector.push_back(
790 AlternativeServiceInfo(alternative_service2, 1.0, expiration));
791 SchemeOriginPair http_origin("http", "foo", 80);
792 SchemeOriginPair https_origin("https", "foo", 80);
793 impl_.SetAlternativeServices(http_origin, alternative_service_info_vector);
794
795 ASSERT_EQ(2u, impl_.GetAlternativeServices(http_origin).size());
796 ASSERT_EQ(0u, impl_.GetAlternativeServices(https_origin).size());
797 }
798
767 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { 799 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) {
768 AlternativeServiceInfoVector alternative_service_info_vector; 800 AlternativeServiceInfoVector alternative_service_info_vector;
769 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); 801 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443);
770 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 802 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
771 alternative_service_info_vector.push_back( 803 alternative_service_info_vector.push_back(
772 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); 804 AlternativeServiceInfo(alternative_service1, 1.0, expiration));
773 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); 805 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234);
774 alternative_service_info_vector.push_back( 806 alternative_service_info_vector.push_back(
775 AlternativeServiceInfo(alternative_service2, 1.0, expiration)); 807 AlternativeServiceInfo(alternative_service2, 1.0, expiration));
776 HostPortPair test_host_port_pair("foo", 80); 808 HostPortPair test_host_port_pair("foo", 80);
777 impl_.SetAlternativeServices(test_host_port_pair, 809 SchemeOriginPair scheme_origin("http", test_host_port_pair);
778 alternative_service_info_vector); 810 impl_.SetAlternativeServices(scheme_origin, alternative_service_info_vector);
779 811
780 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); 812 const net::AlternativeServiceMap& map = impl_.alternative_service_map();
781 net::AlternativeServiceMap::const_iterator it = map.begin(); 813 net::AlternativeServiceMap::const_iterator it = map.begin();
782 EXPECT_TRUE(it->first.Equals(test_host_port_pair)); 814 EXPECT_TRUE(it->first.host_port_pair().Equals(test_host_port_pair));
783 ASSERT_EQ(2u, it->second.size()); 815 ASSERT_EQ(2u, it->second.size());
784 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); 816 EXPECT_EQ(alternative_service1, it->second[0].alternative_service);
785 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); 817 EXPECT_EQ(alternative_service2, it->second[1].alternative_service);
786 818
787 impl_.ClearAlternativeServices(test_host_port_pair); 819 impl_.ClearAlternativeServices(scheme_origin);
788 EXPECT_TRUE(map.empty()); 820 EXPECT_TRUE(map.empty());
789 } 821 }
790 822
791 // A broken alternative service in the mapping carries meaningful information, 823 // A broken alternative service in the mapping carries meaningful information,
792 // therefore it should not be ignored by SetAlternativeService(). In 824 // therefore it should not be ignored by SetAlternativeService(). In
793 // particular, an alternative service mapped to an origin shadows alternative 825 // particular, an alternative service mapped to an origin shadows alternative
794 // services of canonical hosts. 826 // services of canonical hosts.
795 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { 827 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) {
796 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 828 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
797 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); 829 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
798 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", 830 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
799 1234); 831 1234);
800 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, 832 SetAlternativeService(canonical_scheme_origin, canonical_alternative_service,
801 1.0); 833 1.0);
802 AlternativeServiceVector alternative_service_vector = 834 AlternativeServiceVector alternative_service_vector =
803 impl_.GetAlternativeServices(test_host_port_pair); 835 impl_.GetAlternativeServices(scheme_origin);
804 ASSERT_EQ(1u, alternative_service_vector.size()); 836 ASSERT_EQ(1u, alternative_service_vector.size());
805 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]); 837 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]);
806 838
807 const AlternativeService broken_alternative_service(NPN_HTTP_2, "foo", 443); 839 const AlternativeService broken_alternative_service(NPN_HTTP_2, "foo", 443);
808 impl_.MarkAlternativeServiceBroken(broken_alternative_service); 840 impl_.MarkAlternativeServiceBroken(broken_alternative_service);
809 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); 841 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service));
810 842
811 SetAlternativeService(test_host_port_pair, broken_alternative_service, 1.0); 843 SetAlternativeService(scheme_origin, broken_alternative_service, 1.0);
812 alternative_service_vector = 844 alternative_service_vector = impl_.GetAlternativeServices(scheme_origin);
813 impl_.GetAlternativeServices(test_host_port_pair);
814 ASSERT_EQ(1u, alternative_service_vector.size()); 845 ASSERT_EQ(1u, alternative_service_vector.size());
815 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]); 846 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]);
816 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); 847 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service));
817 } 848 }
818 849
819 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { 850 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) {
820 HostPortPair test_host_port_pair("foo", 80); 851 SchemeOriginPair scheme_origin("http", "foo", 80);
821 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); 852 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443);
822 SetAlternativeService(test_host_port_pair, alternative_service, 1.0); 853 SetAlternativeService(scheme_origin, alternative_service, 1.0);
823 impl_.MarkAlternativeServiceBroken(alternative_service); 854 impl_.MarkAlternativeServiceBroken(alternative_service);
824 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); 855 ASSERT_TRUE(HasAlternativeService(scheme_origin));
825 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); 856 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
826 // ClearAlternativeServices should leave a broken alternative service marked 857 // ClearAlternativeServices should leave a broken alternative service marked
827 // as such. 858 // as such.
828 impl_.ClearAlternativeServices(test_host_port_pair); 859 impl_.ClearAlternativeServices(scheme_origin);
829 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); 860 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
830 } 861 }
831 862
832 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { 863 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) {
833 HostPortPair host_port_pair("foo", 80); 864 SchemeOriginPair scheme_origin("http", "foo", 80);
834 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); 865 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443);
835 SetAlternativeService(host_port_pair, alternative_service, 1.0); 866 SetAlternativeService(scheme_origin, alternative_service, 1.0);
836 867
837 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); 868 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
838 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 869 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
839 870
840 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); 871 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service);
841 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); 872 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
842 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 873 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
843 874
844 impl_.ConfirmAlternativeService(alternative_service); 875 impl_.ConfirmAlternativeService(alternative_service);
845 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); 876 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
846 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 877 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
847 } 878 }
848 879
849 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { 880 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) {
850 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 881 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
851 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 882 SchemeOriginPair scheme_origin("https", test_host_port_pair);
883 EXPECT_FALSE(HasAlternativeService(scheme_origin));
852 884
853 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); 885 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80);
854 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); 886 SchemeOriginPair canonical_scheme_origin("https", canonical_host_port_pair);
887 EXPECT_FALSE(HasAlternativeService(canonical_scheme_origin));
855 888
856 AlternativeServiceInfoVector alternative_service_info_vector; 889 AlternativeServiceInfoVector alternative_service_info_vector;
857 const AlternativeService canonical_alternative_service1( 890 const AlternativeService canonical_alternative_service1(
858 QUIC, "bar.c.youtube.com", 1234); 891 QUIC, "bar.c.youtube.com", 1234);
859 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 892 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
860 alternative_service_info_vector.push_back( 893 alternative_service_info_vector.push_back(
861 AlternativeServiceInfo(canonical_alternative_service1, 1.0, expiration)); 894 AlternativeServiceInfo(canonical_alternative_service1, 1.0, expiration));
862 const AlternativeService canonical_alternative_service2(NPN_HTTP_2, "", 443); 895 const AlternativeService canonical_alternative_service2(NPN_HTTP_2, "", 443);
863 alternative_service_info_vector.push_back( 896 alternative_service_info_vector.push_back(
864 AlternativeServiceInfo(canonical_alternative_service2, 1.0, expiration)); 897 AlternativeServiceInfo(canonical_alternative_service2, 1.0, expiration));
865 impl_.SetAlternativeServices(canonical_host_port_pair, 898 impl_.SetAlternativeServices(canonical_scheme_origin,
866 alternative_service_info_vector); 899 alternative_service_info_vector);
867 900
868 // Since |test_host_port_pair| does not have an alternative service itself, 901 // Since |test_host_port_pair| does not have an alternative service itself,
869 // GetAlternativeServices should return those of |canonical_host_port_pair|. 902 // GetAlternativeServices should return those of |canonical_host_port_pair|.
870 AlternativeServiceVector alternative_service_vector = 903 AlternativeServiceVector alternative_service_vector =
871 impl_.GetAlternativeServices(test_host_port_pair); 904 impl_.GetAlternativeServices(scheme_origin);
872 ASSERT_EQ(2u, alternative_service_vector.size()); 905 ASSERT_EQ(2u, alternative_service_vector.size());
873 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]); 906 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]);
874 907
875 // Since |canonical_alternative_service2| has an empty host, 908 // Since |canonical_alternative_service2| has an empty host,
876 // GetAlternativeServices should substitute the hostname of its |origin| 909 // GetAlternativeServices should substitute the hostname of its |origin|
877 // argument. 910 // argument.
878 EXPECT_EQ(test_host_port_pair.host(), alternative_service_vector[1].host); 911 EXPECT_EQ(test_host_port_pair.host(), alternative_service_vector[1].host);
879 EXPECT_EQ(canonical_alternative_service2.protocol, 912 EXPECT_EQ(canonical_alternative_service2.protocol,
880 alternative_service_vector[1].protocol); 913 alternative_service_vector[1].protocol);
881 EXPECT_EQ(canonical_alternative_service2.port, 914 EXPECT_EQ(canonical_alternative_service2.port,
882 alternative_service_vector[1].port); 915 alternative_service_vector[1].port);
883 916
884 // Verify the canonical suffix. 917 // Verify the canonical suffix.
885 EXPECT_EQ(".c.youtube.com", 918 EXPECT_EQ(".c.youtube.com",
886 impl_.GetCanonicalSuffix(test_host_port_pair.host())); 919 impl_.GetCanonicalSuffix(test_host_port_pair.host()));
887 EXPECT_EQ(".c.youtube.com", 920 EXPECT_EQ(".c.youtube.com",
888 impl_.GetCanonicalSuffix(canonical_host_port_pair.host())); 921 impl_.GetCanonicalSuffix(canonical_host_port_pair.host()));
889 } 922 }
890 923
924 TEST_F(AlternateProtocolServerPropertiesTest, NoCanonicalMappingForHttpOrigin) {
925 impl_.SetAlternativeServiceProbabilityThreshold(0.02);
926
927 SchemeOriginPair scheme_origin("http", "foo.c.youtube.com", 80);
928 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
929 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
930 1234);
931 // Set alternative service for canonical_scheme_origin.
932 SetAlternativeService(canonical_scheme_origin, canonical_alternative_service,
933 0.03);
934 EXPECT_TRUE(HasAlternativeService(canonical_scheme_origin));
935 EXPECT_FALSE(HasAlternativeService(scheme_origin));
936 }
937
938 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalMappingForHttpsOrigin) {
939 impl_.SetAlternativeServiceProbabilityThreshold(0.02);
940
941 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
942 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
943 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
944 1234);
945 // Set alternative service for canonical_scheme_origin.
946 SetAlternativeService(canonical_scheme_origin, canonical_alternative_service,
947 0.03);
948 EXPECT_TRUE(HasAlternativeService(canonical_scheme_origin));
949 EXPECT_TRUE(HasAlternativeService(scheme_origin));
950 }
951
891 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { 952 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) {
892 impl_.SetAlternativeServiceProbabilityThreshold(0.02); 953 impl_.SetAlternativeServiceProbabilityThreshold(0.02);
893 954
894 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 955 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
895 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); 956 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
896 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", 957 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
897 1234); 958 1234);
898 959
899 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, 960 SetAlternativeService(canonical_scheme_origin, canonical_alternative_service,
900 0.01); 961 0.01);
901 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); 962 EXPECT_FALSE(HasAlternativeService(canonical_scheme_origin));
902 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 963 EXPECT_FALSE(HasAlternativeService(scheme_origin));
903 } 964 }
904 965
905 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { 966 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) {
906 impl_.SetAlternativeServiceProbabilityThreshold(0.02); 967 impl_.SetAlternativeServiceProbabilityThreshold(0.02);
907 968
908 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 969 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
909 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); 970 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
910 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", 971 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
911 1234); 972 1234);
912 973
913 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, 974 SetAlternativeService(canonical_scheme_origin, canonical_alternative_service,
914 0.03); 975 0.03);
915 EXPECT_TRUE(HasAlternativeService(canonical_host_port_pair)); 976 EXPECT_TRUE(HasAlternativeService(canonical_scheme_origin));
916 EXPECT_TRUE(HasAlternativeService(test_host_port_pair)); 977 EXPECT_TRUE(HasAlternativeService(scheme_origin));
917 } 978 }
918 979
919 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { 980 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) {
920 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 981 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
921 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); 982 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
922 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", 983 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
923 1234); 984 1234);
924 985
925 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, 986 SetAlternativeService(canonical_scheme_origin, canonical_alternative_service,
926 1.0); 987 1.0);
927 impl_.ClearAlternativeServices(canonical_host_port_pair); 988 impl_.ClearAlternativeServices(canonical_scheme_origin);
928 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 989 EXPECT_FALSE(HasAlternativeService(scheme_origin));
929 } 990 }
930 991
931 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { 992 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) {
932 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 993 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
933 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); 994 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
934 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", 995 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
935 1234); 996 1234);
936 997
937 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, 998 SetAlternativeService(canonical_scheme_origin, canonical_alternative_service,
938 1.0); 999 1.0);
939 impl_.MarkAlternativeServiceBroken(canonical_alternative_service); 1000 impl_.MarkAlternativeServiceBroken(canonical_alternative_service);
940 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 1001 EXPECT_FALSE(HasAlternativeService(scheme_origin));
941 } 1002 }
942 1003
943 // Adding an alternative service for a new host overrides canonical host. 1004 // Adding an alternative service for a new host overrides canonical host.
944 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { 1005 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) {
945 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 1006 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
946 HostPortPair bar_host_port_pair("bar.c.youtube.com", 80); 1007 SchemeOriginPair bar_scheme_origin("https", "bar.c.youtube.com", 80);
947 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); 1008 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234);
948 SetAlternativeService(bar_host_port_pair, bar_alternative_service, 1.0); 1009 SetAlternativeService(bar_scheme_origin, bar_alternative_service, 1.0);
949 AlternativeServiceVector alternative_service_vector = 1010 AlternativeServiceVector alternative_service_vector =
950 impl_.GetAlternativeServices(test_host_port_pair); 1011 impl_.GetAlternativeServices(scheme_origin);
951 ASSERT_EQ(1u, alternative_service_vector.size()); 1012 ASSERT_EQ(1u, alternative_service_vector.size());
952 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]); 1013 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]);
953 1014
954 HostPortPair qux_host_port_pair("qux.c.youtube.com", 80); 1015 SchemeOriginPair qux_scheme_origin_pair("https", "qux.c.youtube.com", 80);
955 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); 1016 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443);
956 SetAlternativeService(qux_host_port_pair, qux_alternative_service, 1.0); 1017 SetAlternativeService(qux_scheme_origin_pair, qux_alternative_service, 1.0);
957 alternative_service_vector = 1018 alternative_service_vector = impl_.GetAlternativeServices(scheme_origin);
958 impl_.GetAlternativeServices(test_host_port_pair);
959 ASSERT_EQ(1u, alternative_service_vector.size()); 1019 ASSERT_EQ(1u, alternative_service_vector.size());
960 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]); 1020 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]);
961 } 1021 }
962 1022
963 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { 1023 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) {
964 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 1024 SchemeOriginPair scheme_origin("https", "foo.c.youtube.com", 80);
965 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); 1025 SchemeOriginPair canonical_scheme_origin("https", "bar.c.youtube.com", 80);
966 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", 1026 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
967 1234); 1027 1234);
968 1028
969 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, 1029 SetAlternativeService(canonical_scheme_origin, canonical_alternative_service,
970 1.0); 1030 1.0);
971 impl_.Clear(); 1031 impl_.Clear();
972 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); 1032 EXPECT_FALSE(HasAlternativeService(scheme_origin));
973 } 1033 }
974 1034
975 TEST_F(AlternateProtocolServerPropertiesTest, 1035 TEST_F(AlternateProtocolServerPropertiesTest,
976 ExpireBrokenAlternateProtocolMappings) { 1036 ExpireBrokenAlternateProtocolMappings) {
977 HostPortPair host_port_pair("foo", 443); 1037 SchemeOriginPair scheme_origin("https", "foo", 443);
978 AlternativeService alternative_service(QUIC, "foo", 443); 1038 AlternativeService alternative_service(QUIC, "foo", 443);
979 SetAlternativeService(host_port_pair, alternative_service, 1.0); 1039 SetAlternativeService(scheme_origin, alternative_service, 1.0);
980 EXPECT_TRUE(HasAlternativeService(host_port_pair)); 1040 EXPECT_TRUE(HasAlternativeService(scheme_origin));
981 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); 1041 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
982 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 1042 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
983 1043
984 base::TimeTicks past = 1044 base::TimeTicks past =
985 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); 1045 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42);
986 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( 1046 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime(
987 impl_, alternative_service, past); 1047 impl_, alternative_service, past);
988 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); 1048 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
989 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 1049 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
990 1050
991 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); 1051 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_);
992 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); 1052 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
993 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 1053 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
994 } 1054 }
995 1055
996 // Regression test for https://crbug.com/505413. 1056 // Regression test for https://crbug.com/505413.
997 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) { 1057 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) {
998 HostPortPair foo_host_port_pair("foo", 443); 1058 SchemeOriginPair foo_scheme_origin("https", "foo", 443);
999 AlternativeService bar_alternative_service(QUIC, "bar", 443); 1059 AlternativeService bar_alternative_service(QUIC, "bar", 443);
1000 SetAlternativeService(foo_host_port_pair, bar_alternative_service, 1.0); 1060 SetAlternativeService(foo_scheme_origin, bar_alternative_service, 1.0);
1001 EXPECT_TRUE(HasAlternativeService(foo_host_port_pair)); 1061 EXPECT_TRUE(HasAlternativeService(foo_scheme_origin));
1002 1062
1003 HostPortPair bar_host_port_pair1("bar", 80); 1063 SchemeOriginPair bar_scheme_origin1("http", "bar", 80);
1004 AlternativeService nohost_alternative_service(QUIC, "", 443); 1064 AlternativeService nohost_alternative_service(QUIC, "", 443);
1005 SetAlternativeService(bar_host_port_pair1, nohost_alternative_service, 1.0); 1065 SetAlternativeService(bar_scheme_origin1, nohost_alternative_service, 1.0);
1006 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair1)); 1066 EXPECT_TRUE(HasAlternativeService(bar_scheme_origin1));
1007 1067
1008 HostPortPair bar_host_port_pair2("bar", 443); 1068 SchemeOriginPair bar_scheme_origin2("https", "bar", 443);
1009 AlternativeService baz_alternative_service(QUIC, "baz", 1234); 1069 AlternativeService baz_alternative_service(QUIC, "baz", 1234);
1010 SetAlternativeService(bar_host_port_pair2, baz_alternative_service, 1.0); 1070 SetAlternativeService(bar_scheme_origin2, baz_alternative_service, 1.0);
1011 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair2)); 1071 EXPECT_TRUE(HasAlternativeService(bar_scheme_origin2));
1012 1072
1013 // Mark "bar:443" as broken. 1073 // Mark "bar:443" as broken.
1014 base::TimeTicks past = 1074 base::TimeTicks past =
1015 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); 1075 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42);
1016 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( 1076 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime(
1017 impl_, bar_alternative_service, past); 1077 impl_, bar_alternative_service, past);
1018 1078
1019 // Expire brokenness of "bar:443". 1079 // Expire brokenness of "bar:443".
1020 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); 1080 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_);
1021 1081
1022 // "foo:443" should have no alternative service now. 1082 // "foo:443" should have no alternative service now.
1023 EXPECT_FALSE(HasAlternativeService(foo_host_port_pair)); 1083 EXPECT_FALSE(HasAlternativeService(foo_scheme_origin));
1024 // "bar:80" should have no alternative service now. 1084 // "bar:80" should have no alternative service now.
1025 EXPECT_FALSE(HasAlternativeService(bar_host_port_pair1)); 1085 EXPECT_FALSE(HasAlternativeService(bar_scheme_origin1));
1026 // The alternative service of "bar:443" should be unaffected. 1086 // The alternative service of "bar:443" should be unaffected.
1027 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair2)); 1087 EXPECT_TRUE(HasAlternativeService(bar_scheme_origin2));
1028 1088
1029 EXPECT_TRUE( 1089 EXPECT_TRUE(
1030 impl_.WasAlternativeServiceRecentlyBroken(bar_alternative_service)); 1090 impl_.WasAlternativeServiceRecentlyBroken(bar_alternative_service));
1031 EXPECT_FALSE( 1091 EXPECT_FALSE(
1032 impl_.WasAlternativeServiceRecentlyBroken(baz_alternative_service)); 1092 impl_.WasAlternativeServiceRecentlyBroken(baz_alternative_service));
1033 } 1093 }
1034 1094
1035 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; 1095 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest;
1036 1096
1037 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { 1097 TEST_F(SpdySettingsServerPropertiesTest, Initialize) {
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); 1543 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id)));
1484 1544
1485 impl_.Clear(); 1545 impl_.Clear();
1486 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1546 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1487 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); 1547 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id));
1488 } 1548 }
1489 1549
1490 } // namespace 1550 } // namespace
1491 1551
1492 } // namespace net 1552 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698