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

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

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/http/http_server_properties_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 23 matching lines...) Expand all
34 34
35 TEST_F(SpdyServerPropertiesTest, Initialize) { 35 TEST_F(SpdyServerPropertiesTest, Initialize) {
36 HostPortPair spdy_server_google("www.google.com", 443); 36 HostPortPair spdy_server_google("www.google.com", 443);
37 std::string spdy_server_g = spdy_server_google.ToString(); 37 std::string spdy_server_g = spdy_server_google.ToString();
38 38
39 HostPortPair spdy_server_docs("docs.google.com", 443); 39 HostPortPair spdy_server_docs("docs.google.com", 443);
40 std::string spdy_server_d = spdy_server_docs.ToString(); 40 std::string spdy_server_d = spdy_server_docs.ToString();
41 41
42 // Check by initializing NULL spdy servers. 42 // Check by initializing NULL spdy servers.
43 impl_.InitializeSpdyServers(NULL, true); 43 impl_.InitializeSpdyServers(NULL, true);
44 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); 44 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google));
45 45
46 // Check by initializing empty spdy servers. 46 // Check by initializing empty spdy servers.
47 std::vector<std::string> spdy_servers; 47 std::vector<std::string> spdy_servers;
48 impl_.InitializeSpdyServers(&spdy_servers, true); 48 impl_.InitializeSpdyServers(&spdy_servers, true);
49 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); 49 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google));
50 50
51 // Check by initializing with www.google.com:443 spdy server. 51 // Check by initializing with www.google.com:443 spdy server.
52 std::vector<std::string> spdy_servers1; 52 std::vector<std::string> spdy_servers1;
53 spdy_servers1.push_back(spdy_server_g); 53 spdy_servers1.push_back(spdy_server_g);
54 impl_.InitializeSpdyServers(&spdy_servers1, true); 54 impl_.InitializeSpdyServers(&spdy_servers1, true);
55 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); 55 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
56 56
57 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy 57 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy
58 // servers. 58 // servers.
59 std::vector<std::string> spdy_servers2; 59 std::vector<std::string> spdy_servers2;
60 spdy_servers2.push_back(spdy_server_g); 60 spdy_servers2.push_back(spdy_server_g);
61 spdy_servers2.push_back(spdy_server_d); 61 spdy_servers2.push_back(spdy_server_d);
62 impl_.InitializeSpdyServers(&spdy_servers2, true); 62 impl_.InitializeSpdyServers(&spdy_servers2, true);
63 63
64 // Verify spdy_server_g and spdy_server_d are in the list in the same order. 64 // Verify spdy_server_g and spdy_server_d are in the list in the same order.
65 base::ListValue spdy_server_list; 65 base::ListValue spdy_server_list;
66 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 66 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
67 EXPECT_EQ(2U, spdy_server_list.GetSize()); 67 EXPECT_EQ(2U, spdy_server_list.GetSize());
68 std::string string_value_g; 68 std::string string_value_g;
69 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 69 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
70 ASSERT_EQ(spdy_server_g, string_value_g); 70 ASSERT_EQ(spdy_server_g, string_value_g);
71 std::string string_value_d; 71 std::string string_value_d;
72 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_d)); 72 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_d));
73 ASSERT_EQ(spdy_server_d, string_value_d); 73 ASSERT_EQ(spdy_server_d, string_value_d);
74 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); 74 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
75 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs)); 75 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs));
76 } 76 }
77 77
78 TEST_F(SpdyServerPropertiesTest, SupportsSpdyTest) { 78 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) {
79 HostPortPair spdy_server_empty(std::string(), 443); 79 HostPortPair spdy_server_empty(std::string(), 443);
80 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty)); 80 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty));
81 81
82 // Add www.google.com:443 as supporting SPDY. 82 // Add www.google.com:443 as supporting SPDY.
83 HostPortPair spdy_server_google("www.google.com", 443); 83 HostPortPair spdy_server_google("www.google.com", 443);
84 impl_.SetSupportsSpdy(spdy_server_google, true); 84 impl_.SetSupportsSpdy(spdy_server_google, true);
85 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); 85 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
86 86
87 // Add mail.google.com:443 as not supporting SPDY. 87 // Add mail.google.com:443 as not supporting SPDY.
88 HostPortPair spdy_server_mail("mail.google.com", 443); 88 HostPortPair spdy_server_mail("mail.google.com", 443);
89 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); 89 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail));
90 90
91 // Add docs.google.com:443 as supporting SPDY. 91 // Add docs.google.com:443 as supporting SPDY.
92 HostPortPair spdy_server_docs("docs.google.com", 443); 92 HostPortPair spdy_server_docs("docs.google.com", 443);
93 impl_.SetSupportsSpdy(spdy_server_docs, true); 93 impl_.SetSupportsSpdy(spdy_server_docs, true);
94 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs)); 94 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs));
95
96 // Add www.youtube.com:443 as supporting QUIC.
97 HostPortPair quic_server_youtube("www.youtube.com", 443);
98 impl_.SetAlternateProtocol(quic_server_youtube, 443, QUIC, 1);
99 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube));
95 100
96 // Verify all the entries are the same after additions. 101 // Verify all the entries are the same after additions.
97 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); 102 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
98 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); 103 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail));
99 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs)); 104 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs));
100 } 105 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube));
101
102 TEST_F(SpdyServerPropertiesTest, SetSupportsSpdy) {
103 HostPortPair spdy_server_empty(std::string(), 443);
104 impl_.SetSupportsSpdy(spdy_server_empty, true);
105 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty));
106
107 // Add www.google.com:443 as supporting SPDY.
108 HostPortPair spdy_server_google("www.google.com", 443);
109 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
110 impl_.SetSupportsSpdy(spdy_server_google, true);
111 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
112
113 // Make www.google.com:443 as not supporting SPDY.
114 impl_.SetSupportsSpdy(spdy_server_google, false);
115 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
116
117 // Add mail.google.com:443 as supporting SPDY.
118 HostPortPair spdy_server_mail("mail.google.com", 443);
119 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
120 impl_.SetSupportsSpdy(spdy_server_mail, true);
121 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail));
122 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
123 } 106 }
124 107
125 TEST_F(SpdyServerPropertiesTest, Clear) { 108 TEST_F(SpdyServerPropertiesTest, Clear) {
126 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. 109 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY.
127 HostPortPair spdy_server_google("www.google.com", 443); 110 HostPortPair spdy_server_google("www.google.com", 443);
128 impl_.SetSupportsSpdy(spdy_server_google, true); 111 impl_.SetSupportsSpdy(spdy_server_google, true);
129 HostPortPair spdy_server_mail("mail.google.com", 443); 112 HostPortPair spdy_server_mail("mail.google.com", 443);
130 impl_.SetSupportsSpdy(spdy_server_mail, true); 113 impl_.SetSupportsSpdy(spdy_server_mail, true);
131 114
132 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); 115 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
133 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail)); 116 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail));
134 117
135 impl_.Clear(); 118 impl_.Clear();
136 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); 119 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google));
137 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); 120 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail));
138 } 121 }
139 122
140 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { 123 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) {
141 base::ListValue spdy_server_list; 124 base::ListValue spdy_server_list;
142 125
143 // Check there are no spdy_servers. 126 // Check there are no spdy_servers.
144 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 127 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
145 EXPECT_EQ(0U, spdy_server_list.GetSize()); 128 EXPECT_EQ(0U, spdy_server_list.GetSize());
146 129
147 // Check empty server is not added. 130 // Check empty server is not added.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 impl_.SetSupportsSpdy(spdy_server_mail, true); 199 impl_.SetSupportsSpdy(spdy_server_mail, true);
217 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 200 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
218 ASSERT_EQ(2U, spdy_server_list.GetSize()); 201 ASSERT_EQ(2U, spdy_server_list.GetSize());
219 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); 202 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m));
220 ASSERT_EQ(spdy_server_m, string_value_m); 203 ASSERT_EQ(spdy_server_m, string_value_m);
221 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g)); 204 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g));
222 ASSERT_EQ(spdy_server_g, string_value_g); 205 ASSERT_EQ(spdy_server_g, string_value_g);
223 206
224 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it 207 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it
225 // is www.google.com:443 is the MRU server. 208 // is www.google.com:443 is the MRU server.
226 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); 209 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
227 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 210 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts);
228 ASSERT_EQ(2U, spdy_server_list.GetSize()); 211 ASSERT_EQ(2U, spdy_server_list.GetSize());
229 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 212 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
230 ASSERT_EQ(spdy_server_g, string_value_g); 213 ASSERT_EQ(spdy_server_g, string_value_g);
231 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); 214 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m));
232 ASSERT_EQ(spdy_server_m, string_value_m); 215 ASSERT_EQ(spdy_server_m, string_value_m);
233 } 216 }
234 217
235 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; 218 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest;
236 219
237 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { 220 TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
238 HostPortPair test_host_port_pair("foo", 80); 221 HostPortPair test_host_port_pair("foo", 80);
239 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 222 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
240 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1); 223 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0);
241 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); 224 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
242 const AlternateProtocolInfo alternate = 225 const AlternateProtocolInfo alternate =
243 impl_.GetAlternateProtocol(test_host_port_pair); 226 impl_.GetAlternateProtocol(test_host_port_pair);
244 EXPECT_EQ(443, alternate.port); 227 EXPECT_EQ(443, alternate.port);
245 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); 228 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
246 229
247 impl_.Clear(); 230 impl_.Clear();
248 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 231 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
249 } 232 }
250 233
(...skipping 22 matching lines...) Expand all
273 impl_.SetAlternateProtocolProbabilityThreshold(.75); 256 impl_.SetAlternateProtocolProbabilityThreshold(.75);
274 257
275 HostPortPair test_host_port_pair("foo", 80); 258 HostPortPair test_host_port_pair("foo", 80);
276 259
277 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); 260 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5);
278 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 261 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
279 } 262 }
280 263
281 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { 264 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) {
282 HostPortPair test_host_port_pair1("foo1", 80); 265 HostPortPair test_host_port_pair1("foo1", 80);
283 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1); 266 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0);
284 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); 267 impl_.SetBrokenAlternateProtocol(test_host_port_pair1);
285 HostPortPair test_host_port_pair2("foo2", 80); 268 HostPortPair test_host_port_pair2("foo2", 80);
286 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1); 269 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1.0);
287 270
288 AlternateProtocolMap alternate_protocol_map( 271 AlternateProtocolMap alternate_protocol_map(
289 AlternateProtocolMap::NO_AUTO_EVICT); 272 AlternateProtocolMap::NO_AUTO_EVICT);
290 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); 273 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1);
291 alternate_protocol_map.Put(test_host_port_pair2, alternate); 274 alternate_protocol_map.Put(test_host_port_pair2, alternate);
292 HostPortPair test_host_port_pair3("foo3", 80); 275 HostPortPair test_host_port_pair3("foo3", 80);
293 alternate.port = 1234; 276 alternate.port = 1234;
294 alternate_protocol_map.Put(test_host_port_pair3, alternate); 277 alternate_protocol_map.Put(test_host_port_pair3, alternate);
295 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); 278 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map);
296 279
297 // Verify test_host_port_pair3 is the MRU server. 280 // Verify test_host_port_pair3 is the MRU server.
298 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); 281 const AlternateProtocolMap& map = impl_.alternate_protocol_map();
299 AlternateProtocolMap::const_iterator it = map.begin(); 282 AlternateProtocolMap::const_iterator it = map.begin();
300 it = map.begin();
301 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); 283 EXPECT_TRUE(it->first.Equals(test_host_port_pair3));
302 EXPECT_EQ(1234, it->second.port); 284 EXPECT_EQ(1234, it->second.port);
303 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 285 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
304 286
305 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); 287 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
306 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); 288 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2));
307 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); 289 alternate = impl_.GetAlternateProtocol(test_host_port_pair1);
308 EXPECT_TRUE(alternate.is_broken); 290 EXPECT_TRUE(alternate.is_broken);
309 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); 291 alternate = impl_.GetAlternateProtocol(test_host_port_pair2);
310 EXPECT_EQ(123, alternate.port); 292 EXPECT_EQ(123, alternate.port);
311 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); 293 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
312 } 294 }
313 295
314 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) { 296 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) {
315 HostPortPair test_host_port_pair1("foo1", 80); 297 HostPortPair test_host_port_pair1("foo1", 80);
316 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1); 298 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0);
317 HostPortPair test_host_port_pair2("foo2", 80); 299 HostPortPair test_host_port_pair2("foo2", 80);
318 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1); 300 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0);
319 301
320 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); 302 const AlternateProtocolMap& map = impl_.alternate_protocol_map();
321 AlternateProtocolMap::const_iterator it = map.begin(); 303 AlternateProtocolMap::const_iterator it = map.begin();
322 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); 304 EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
323 EXPECT_EQ(1234, it->second.port); 305 EXPECT_EQ(1234, it->second.port);
324 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 306 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
325 307
326 // HasAlternateProtocol should reoder the AlternateProtocol map. 308 // HasAlternateProtocol should reorder the AlternateProtocol map.
327 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); 309 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
328 it = map.begin(); 310 it = map.begin();
329 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); 311 EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
330 EXPECT_EQ(443, it->second.port); 312 EXPECT_EQ(443, it->second.port);
331 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 313 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
332 } 314 }
333 315
334 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { 316 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) {
335 HostPortPair test_host_port_pair1("foo1", 80); 317 HostPortPair test_host_port_pair1("foo1", 80);
336 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1); 318 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0);
337 HostPortPair test_host_port_pair2("foo2", 80); 319 HostPortPair test_host_port_pair2("foo2", 80);
338 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1); 320 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0);
339 321
340 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); 322 const AlternateProtocolMap& map = impl_.alternate_protocol_map();
341 AlternateProtocolMap::const_iterator it = map.begin(); 323 AlternateProtocolMap::const_iterator it = map.begin();
342 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); 324 EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
343 EXPECT_EQ(1234, it->second.port); 325 EXPECT_EQ(1234, it->second.port);
344 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 326 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
345 327
346 // GetAlternateProtocol should reoder the AlternateProtocol map. 328 // GetAlternateProtocol should reorder the AlternateProtocol map.
347 AlternateProtocolInfo alternate = 329 AlternateProtocolInfo alternate =
348 impl_.GetAlternateProtocol(test_host_port_pair1); 330 impl_.GetAlternateProtocol(test_host_port_pair1);
349 EXPECT_EQ(443, alternate.port); 331 EXPECT_EQ(443, alternate.port);
350 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); 332 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
351 it = map.begin(); 333 it = map.begin();
352 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); 334 EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
353 EXPECT_EQ(443, it->second.port); 335 EXPECT_EQ(443, it->second.port);
354 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 336 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
355 } 337 }
356 338
357 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { 339 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) {
358 HostPortPair test_host_port_pair("foo", 80); 340 HostPortPair test_host_port_pair("foo", 80);
359 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1); 341 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0);
360 impl_.SetBrokenAlternateProtocol(test_host_port_pair); 342 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
361 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); 343 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
362 AlternateProtocolInfo alternate = 344 AlternateProtocolInfo alternate =
363 impl_.GetAlternateProtocol(test_host_port_pair); 345 impl_.GetAlternateProtocol(test_host_port_pair);
364 EXPECT_TRUE(alternate.is_broken); 346 EXPECT_TRUE(alternate.is_broken);
365 347
366 impl_.SetAlternateProtocol( 348 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0);
367 test_host_port_pair,
368 1234,
369 NPN_SPDY_3,
370 1);
371 alternate = impl_.GetAlternateProtocol(test_host_port_pair); 349 alternate = impl_.GetAlternateProtocol(test_host_port_pair);
372 EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored."; 350 EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored.";
373 } 351 }
374 352
375 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { 353 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) {
376 HostPortPair test_host_port_pair("foo", 80); 354 HostPortPair test_host_port_pair("foo", 80);
377 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1); 355 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0);
378 impl_.SetBrokenAlternateProtocol(test_host_port_pair); 356 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
379 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); 357 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
380 AlternateProtocolInfo alternate = 358 AlternateProtocolInfo alternate =
381 impl_.GetAlternateProtocol(test_host_port_pair); 359 impl_.GetAlternateProtocol(test_host_port_pair);
382 EXPECT_TRUE(alternate.is_broken); 360 EXPECT_TRUE(alternate.is_broken);
383 impl_.ClearAlternateProtocol(test_host_port_pair); 361 impl_.ClearAlternateProtocol(test_host_port_pair);
384 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 362 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
385 } 363 }
386 364
387 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { 365 TEST_F(AlternateProtocolServerPropertiesTest, Forced) {
388 // Test forced alternate protocols. 366 // Test forced alternate protocols.
389 367
390 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); 368 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1);
391 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); 369 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol);
392 370
393 // Verify the forced protocol. 371 // Verify the forced protocol.
394 HostPortPair test_host_port_pair("foo", 80); 372 HostPortPair test_host_port_pair("foo", 80);
395 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); 373 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
396 AlternateProtocolInfo alternate = 374 AlternateProtocolInfo alternate =
397 impl_.GetAlternateProtocol(test_host_port_pair); 375 impl_.GetAlternateProtocol(test_host_port_pair);
398 EXPECT_EQ(default_protocol.port, alternate.port); 376 EXPECT_EQ(default_protocol.port, alternate.port);
399 EXPECT_EQ(default_protocol.protocol, alternate.protocol); 377 EXPECT_EQ(default_protocol.protocol, alternate.protocol);
400 378
401 // Verify the real protocol overrides the forced protocol. 379 // Verify the real protocol overrides the forced protocol.
402 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1); 380 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0);
403 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); 381 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
404 alternate = impl_.GetAlternateProtocol(test_host_port_pair); 382 alternate = impl_.GetAlternateProtocol(test_host_port_pair);
405 EXPECT_EQ(443, alternate.port); 383 EXPECT_EQ(443, alternate.port);
406 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); 384 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
407 385
408 // Turn off the static, forced alternate protocol so that tests don't 386 // Turn off the static, forced alternate protocol so that tests don't
409 // have this state. 387 // have this state.
410 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); 388 HttpServerPropertiesImpl::DisableForcedAlternateProtocol();
411 389
412 // Verify the forced protocol is off. 390 // Verify the forced protocol is off.
413 HostPortPair test_host_port_pair2("bar", 80); 391 HostPortPair test_host_port_pair2("bar", 80);
414 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair2)); 392 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair2));
415 } 393 }
416 394
417 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { 395 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) {
418 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 396 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
419 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 397 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
420 398
421 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); 399 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
422 EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair)); 400 EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair));
423 401
424 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); 402 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
425 403
426 impl_.SetAlternateProtocol(canonical_port_pair, 404 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
427 canonical_protocol.port, 405 canonical_protocol.protocol, 1.0);
428 canonical_protocol.protocol,
429 1);
430 // Verify the forced protocol. 406 // Verify the forced protocol.
431 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); 407 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
432 AlternateProtocolInfo alternate = 408 AlternateProtocolInfo alternate =
433 impl_.GetAlternateProtocol(test_host_port_pair); 409 impl_.GetAlternateProtocol(test_host_port_pair);
434 EXPECT_EQ(canonical_protocol.port, alternate.port); 410 EXPECT_EQ(canonical_protocol.port, alternate.port);
435 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol); 411 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol);
436 412
437 // Verify the canonical suffix. 413 // Verify the canonical suffix.
438 EXPECT_EQ(".c.youtube.com", impl_.GetCanonicalSuffix(test_host_port_pair)); 414 EXPECT_EQ(".c.youtube.com",
439 EXPECT_EQ(".c.youtube.com", impl_.GetCanonicalSuffix(canonical_port_pair)); 415 impl_.GetCanonicalSuffix(test_host_port_pair.host()));
416 EXPECT_EQ(".c.youtube.com",
417 impl_.GetCanonicalSuffix(canonical_port_pair.host()));
440 } 418 }
441 419
442 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { 420 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) {
443 impl_.SetAlternateProtocolProbabilityThreshold(0.02); 421 impl_.SetAlternateProtocolProbabilityThreshold(0.02);
444 422
445 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 423 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
446 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); 424 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
447 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01); 425 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01);
448 426
449 impl_.SetAlternateProtocol(canonical_port_pair, 427 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
450 canonical_protocol.port,
451 canonical_protocol.protocol, 428 canonical_protocol.protocol,
452 canonical_protocol.probability); 429 canonical_protocol.probability);
453 EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair)); 430 EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair));
454 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 431 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
455 } 432 }
456 433
457 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { 434 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) {
458 impl_.SetAlternateProtocolProbabilityThreshold(0.02); 435 impl_.SetAlternateProtocolProbabilityThreshold(0.02);
459 436
460 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 437 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
461 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); 438 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
462 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03); 439 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03);
463 440
464 impl_.SetAlternateProtocol(canonical_port_pair, 441 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
465 canonical_protocol.port,
466 canonical_protocol.protocol, 442 canonical_protocol.protocol,
467 canonical_protocol.probability); 443 canonical_protocol.probability);
468 EXPECT_TRUE(impl_.HasAlternateProtocol(canonical_port_pair)); 444 EXPECT_TRUE(impl_.HasAlternateProtocol(canonical_port_pair));
469 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); 445 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
470 } 446 }
471 447
472 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { 448 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) {
473 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 449 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
474 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); 450 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
475 451
476 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); 452 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
477 453
478 impl_.SetAlternateProtocol(canonical_port_pair, 454 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
479 canonical_protocol.port,
480 canonical_protocol.protocol, 455 canonical_protocol.protocol,
481 canonical_protocol.probability); 456 canonical_protocol.probability);
482 457
483 impl_.ClearAlternateProtocol(canonical_port_pair); 458 impl_.ClearAlternateProtocol(canonical_port_pair);
484 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 459 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
485 } 460 }
486 461
487 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { 462 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) {
488 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 463 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
489 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); 464 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
490 465
491 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); 466 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
492 467
493 impl_.SetAlternateProtocol(canonical_port_pair, 468 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
494 canonical_protocol.port,
495 canonical_protocol.protocol, 469 canonical_protocol.protocol,
496 canonical_protocol.probability); 470 canonical_protocol.probability);
497 471
498 impl_.SetBrokenAlternateProtocol(canonical_port_pair); 472 impl_.SetBrokenAlternateProtocol(canonical_port_pair);
499 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 473 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
500 } 474 }
501 475
502 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) { 476 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) {
503 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 477 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
504 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); 478 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
505 479
506 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); 480 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
507 481
508 impl_.SetAlternateProtocol(canonical_port_pair, 482 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
509 canonical_protocol.port,
510 canonical_protocol.protocol, 483 canonical_protocol.protocol,
511 canonical_protocol.probability); 484 canonical_protocol.probability);
512 485
513 impl_.SetBrokenAlternateProtocol(test_host_port_pair); 486 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
514 AlternateProtocolInfo alternate = 487 AlternateProtocolInfo alternate =
515 impl_.GetAlternateProtocol(test_host_port_pair); 488 impl_.GetAlternateProtocol(test_host_port_pair);
516 EXPECT_TRUE(alternate.is_broken); 489 EXPECT_TRUE(alternate.is_broken);
517 } 490 }
518 491
519 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { 492 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) {
520 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 493 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
521 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); 494 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
522 495
523 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); 496 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
524 497
525 impl_.SetAlternateProtocol(canonical_port_pair, 498 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
526 canonical_protocol.port,
527 canonical_protocol.protocol, 499 canonical_protocol.protocol,
528 canonical_protocol.probability); 500 canonical_protocol.probability);
529 501
530 impl_.Clear(); 502 impl_.Clear();
531 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 503 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
532 } 504 }
533 505
534 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; 506 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest;
535 507
536 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { 508 TEST_F(SpdySettingsServerPropertiesTest, Initialize) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 SpdySettingsMap::const_iterator it = map.begin(); 661 SpdySettingsMap::const_iterator it = map.begin();
690 EXPECT_TRUE(it->first.Equals(spdy_server_docs)); 662 EXPECT_TRUE(it->first.Equals(spdy_server_docs));
691 const SettingsMap& settings_map2_ret = it->second; 663 const SettingsMap& settings_map2_ret = it->second;
692 ASSERT_EQ(1U, settings_map2_ret.size()); 664 ASSERT_EQ(1U, settings_map2_ret.size());
693 SettingsMap::const_iterator it2_ret = settings_map2_ret.find(id2); 665 SettingsMap::const_iterator it2_ret = settings_map2_ret.find(id2);
694 EXPECT_TRUE(it2_ret != settings_map2_ret.end()); 666 EXPECT_TRUE(it2_ret != settings_map2_ret.end());
695 SettingsFlagsAndValue flags_and_value2_ret = it2_ret->second; 667 SettingsFlagsAndValue flags_and_value2_ret = it2_ret->second;
696 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2_ret.first); 668 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2_ret.first);
697 EXPECT_EQ(value2, flags_and_value2_ret.second); 669 EXPECT_EQ(value2, flags_and_value2_ret.second);
698 670
699 // GetSpdySettings should reoder the SpdySettingsMap. 671 // GetSpdySettings should reorder the SpdySettingsMap.
700 const SettingsMap& settings_map1_ret = 672 const SettingsMap& settings_map1_ret =
701 impl_.GetSpdySettings(spdy_server_google); 673 impl_.GetSpdySettings(spdy_server_google);
702 ASSERT_EQ(1U, settings_map1_ret.size()); 674 ASSERT_EQ(1U, settings_map1_ret.size());
703 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 675 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
704 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 676 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
705 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 677 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
706 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 678 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
707 EXPECT_EQ(value1, flags_and_value1_ret.second); 679 EXPECT_EQ(value1, flags_and_value1_ret.second);
708 680
709 // Check the first entry is spdy_server_google by accessing it via iterator. 681 // Check the first entry is spdy_server_google by accessing it via iterator.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); 767 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond());
796 768
797 impl_.Clear(); 769 impl_.Clear();
798 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); 770 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server);
799 EXPECT_EQ(NULL, stats3); 771 EXPECT_EQ(NULL, stats3);
800 } 772 }
801 773
802 } // namespace 774 } // namespace
803 775
804 } // namespace net 776 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/http/http_server_properties_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698