Add a function to create a bookmark app from a WebApplicationInfo.
[chromium-blink-merge.git] / net / http / http_server_properties_impl_unittest.cc
blob7a1ea824e450eb7b447bfb7f3f38e485c6340509
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
3 // found in the LICENSE file.
5 #include "net/http/http_server_properties_impl.h"
7 #include <string>
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h"
15 #include "net/base/host_port_pair.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace base {
19 class ListValue;
22 namespace net {
24 namespace {
26 class HttpServerPropertiesImplTest : public testing::Test {
27 protected:
28 HttpServerPropertiesImpl impl_;
31 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest;
33 TEST_F(SpdyServerPropertiesTest, Initialize) {
34 HostPortPair spdy_server_google("www.google.com", 443);
35 std::string spdy_server_g =
36 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google);
38 HostPortPair spdy_server_docs("docs.google.com", 443);
39 std::string spdy_server_d =
40 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_docs);
42 // Check by initializing NULL spdy servers.
43 impl_.InitializeSpdyServers(NULL, true);
44 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
46 // Check by initializing empty spdy servers.
47 std::vector<std::string> spdy_servers;
48 impl_.InitializeSpdyServers(&spdy_servers, true);
49 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
51 // Check by initializing with www.google.com:443 spdy server.
52 std::vector<std::string> spdy_servers1;
53 spdy_servers1.push_back(spdy_server_g);
54 impl_.InitializeSpdyServers(&spdy_servers1, true);
55 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
57 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy
58 // servers.
59 std::vector<std::string> spdy_servers2;
60 spdy_servers2.push_back(spdy_server_g);
61 spdy_servers2.push_back(spdy_server_d);
62 impl_.InitializeSpdyServers(&spdy_servers2, true);
63 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
64 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs));
67 TEST_F(SpdyServerPropertiesTest, SupportsSpdyTest) {
68 HostPortPair spdy_server_empty(std::string(), 443);
69 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty));
71 // Add www.google.com:443 as supporting SPDY.
72 HostPortPair spdy_server_google("www.google.com", 443);
73 impl_.SetSupportsSpdy(spdy_server_google, true);
74 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
76 // Add mail.google.com:443 as not supporting SPDY.
77 HostPortPair spdy_server_mail("mail.google.com", 443);
78 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
80 // Add docs.google.com:443 as supporting SPDY.
81 HostPortPair spdy_server_docs("docs.google.com", 443);
82 impl_.SetSupportsSpdy(spdy_server_docs, true);
83 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs));
85 // Verify all the entries are the same after additions.
86 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
87 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
88 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs));
91 TEST_F(SpdyServerPropertiesTest, SetSupportsSpdy) {
92 HostPortPair spdy_server_empty(std::string(), 443);
93 impl_.SetSupportsSpdy(spdy_server_empty, true);
94 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty));
96 // Add www.google.com:443 as supporting SPDY.
97 HostPortPair spdy_server_google("www.google.com", 443);
98 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
99 impl_.SetSupportsSpdy(spdy_server_google, true);
100 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
102 // Make www.google.com:443 as not supporting SPDY.
103 impl_.SetSupportsSpdy(spdy_server_google, false);
104 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
106 // Add mail.google.com:443 as supporting SPDY.
107 HostPortPair spdy_server_mail("mail.google.com", 443);
108 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
109 impl_.SetSupportsSpdy(spdy_server_mail, true);
110 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail));
111 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
114 TEST_F(SpdyServerPropertiesTest, Clear) {
115 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY.
116 HostPortPair spdy_server_google("www.google.com", 443);
117 impl_.SetSupportsSpdy(spdy_server_google, true);
118 HostPortPair spdy_server_mail("mail.google.com", 443);
119 impl_.SetSupportsSpdy(spdy_server_mail, true);
121 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
122 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail));
124 impl_.Clear();
125 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
126 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
129 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) {
130 base::ListValue spdy_server_list;
132 // Check there are no spdy_servers.
133 impl_.GetSpdyServerList(&spdy_server_list);
134 EXPECT_EQ(0U, spdy_server_list.GetSize());
136 // Check empty server is not added.
137 HostPortPair spdy_server_empty(std::string(), 443);
138 impl_.SetSupportsSpdy(spdy_server_empty, true);
139 impl_.GetSpdyServerList(&spdy_server_list);
140 EXPECT_EQ(0U, spdy_server_list.GetSize());
142 std::string string_value_g;
143 std::string string_value_m;
144 HostPortPair spdy_server_google("www.google.com", 443);
145 std::string spdy_server_g =
146 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google);
147 HostPortPair spdy_server_mail("mail.google.com", 443);
148 std::string spdy_server_m =
149 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail);
151 // Add www.google.com:443 as not supporting SPDY.
152 impl_.SetSupportsSpdy(spdy_server_google, false);
153 impl_.GetSpdyServerList(&spdy_server_list);
154 EXPECT_EQ(0U, spdy_server_list.GetSize());
156 // Add www.google.com:443 as supporting SPDY.
157 impl_.SetSupportsSpdy(spdy_server_google, true);
158 impl_.GetSpdyServerList(&spdy_server_list);
159 ASSERT_EQ(1U, spdy_server_list.GetSize());
160 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
161 ASSERT_EQ(spdy_server_g, string_value_g);
163 // Add mail.google.com:443 as not supporting SPDY.
164 impl_.SetSupportsSpdy(spdy_server_mail, false);
165 impl_.GetSpdyServerList(&spdy_server_list);
166 ASSERT_EQ(1U, spdy_server_list.GetSize());
167 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
168 ASSERT_EQ(spdy_server_g, string_value_g);
170 // Add mail.google.com:443 as supporting SPDY.
171 impl_.SetSupportsSpdy(spdy_server_mail, true);
172 impl_.GetSpdyServerList(&spdy_server_list);
173 ASSERT_EQ(2U, spdy_server_list.GetSize());
175 // Verify www.google.com:443 and mail.google.com:443 are in the list.
176 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
177 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m));
178 if (string_value_g.compare(spdy_server_g) == 0) {
179 ASSERT_EQ(spdy_server_g, string_value_g);
180 ASSERT_EQ(spdy_server_m, string_value_m);
181 } else {
182 ASSERT_EQ(spdy_server_g, string_value_m);
183 ASSERT_EQ(spdy_server_m, string_value_g);
187 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest;
189 TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
190 HostPortPair test_host_port_pair("foo", 80);
191 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
192 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3);
193 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
194 const PortAlternateProtocolPair alternate =
195 impl_.GetAlternateProtocol(test_host_port_pair);
196 EXPECT_EQ(443, alternate.port);
197 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
199 impl_.Clear();
200 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
203 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) {
204 HostPortPair test_host_port_pair1("foo1", 80);
205 impl_.SetBrokenAlternateProtocol(test_host_port_pair1);
206 HostPortPair test_host_port_pair2("foo2", 80);
207 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3);
209 AlternateProtocolMap alternate_protocol_map(
210 AlternateProtocolMap::NO_AUTO_EVICT);
211 PortAlternateProtocolPair port_alternate_protocol_pair;
212 port_alternate_protocol_pair.port = 123;
213 port_alternate_protocol_pair.protocol = NPN_SPDY_3;
214 alternate_protocol_map.Put(test_host_port_pair2,
215 port_alternate_protocol_pair);
216 HostPortPair test_host_port_pair3("foo3", 80);
217 port_alternate_protocol_pair.port = 1234;
218 alternate_protocol_map.Put(test_host_port_pair3,
219 port_alternate_protocol_pair);
220 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map);
222 // Verify test_host_port_pair3 is the MRU server.
223 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map();
224 net::AlternateProtocolMap::const_iterator it = map.begin();
225 it = map.begin();
226 EXPECT_TRUE(it->first.Equals(test_host_port_pair3));
227 EXPECT_EQ(1234, it->second.port);
228 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
230 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
231 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2));
232 port_alternate_protocol_pair =
233 impl_.GetAlternateProtocol(test_host_port_pair1);
234 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, port_alternate_protocol_pair.protocol);
235 port_alternate_protocol_pair =
236 impl_.GetAlternateProtocol(test_host_port_pair2);
237 EXPECT_EQ(123, port_alternate_protocol_pair.port);
238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol_pair.protocol);
241 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) {
242 HostPortPair test_host_port_pair1("foo1", 80);
243 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3);
244 HostPortPair test_host_port_pair2("foo2", 80);
245 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3);
247 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map();
248 net::AlternateProtocolMap::const_iterator it = map.begin();
249 EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
250 EXPECT_EQ(1234, it->second.port);
251 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
253 // HasAlternateProtocol should reoder the AlternateProtocol map.
254 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
255 it = map.begin();
256 EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
257 EXPECT_EQ(443, it->second.port);
258 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
261 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) {
262 HostPortPair test_host_port_pair1("foo1", 80);
263 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3);
264 HostPortPair test_host_port_pair2("foo2", 80);
265 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3);
267 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map();
268 net::AlternateProtocolMap::const_iterator it = map.begin();
269 EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
270 EXPECT_EQ(1234, it->second.port);
271 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
273 // GetAlternateProtocol should reoder the AlternateProtocol map.
274 PortAlternateProtocolPair alternate =
275 impl_.GetAlternateProtocol(test_host_port_pair1);
276 EXPECT_EQ(443, alternate.port);
277 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
278 it = map.begin();
279 EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
280 EXPECT_EQ(443, it->second.port);
281 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
284 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) {
285 HostPortPair test_host_port_pair("foo", 80);
286 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
287 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
288 PortAlternateProtocolPair alternate =
289 impl_.GetAlternateProtocol(test_host_port_pair);
290 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol);
292 impl_.SetAlternateProtocol(
293 test_host_port_pair,
294 1234,
295 NPN_SPDY_3);
296 alternate = impl_.GetAlternateProtocol(test_host_port_pair);
297 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol)
298 << "Second attempt should be ignored.";
301 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) {
302 HostPortPair test_host_port_pair("foo", 80);
303 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
304 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
305 PortAlternateProtocolPair alternate =
306 impl_.GetAlternateProtocol(test_host_port_pair);
307 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol);
308 impl_.ClearAlternateProtocol(test_host_port_pair);
309 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
312 TEST_F(AlternateProtocolServerPropertiesTest, Forced) {
313 // Test forced alternate protocols.
315 PortAlternateProtocolPair default_protocol;
316 default_protocol.port = 1234;
317 default_protocol.protocol = NPN_SPDY_3;
318 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol);
320 // Verify the forced protocol.
321 HostPortPair test_host_port_pair("foo", 80);
322 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
323 PortAlternateProtocolPair alternate =
324 impl_.GetAlternateProtocol(test_host_port_pair);
325 EXPECT_EQ(default_protocol.port, alternate.port);
326 EXPECT_EQ(default_protocol.protocol, alternate.protocol);
328 // Verify the real protocol overrides the forced protocol.
329 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3);
330 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
331 alternate = impl_.GetAlternateProtocol(test_host_port_pair);
332 EXPECT_EQ(443, alternate.port);
333 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
335 // Turn off the static, forced alternate protocol so that tests don't
336 // have this state.
337 HttpServerPropertiesImpl::DisableForcedAlternateProtocol();
339 // Verify the forced protocol is off.
340 HostPortPair test_host_port_pair2("bar", 80);
341 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair2));
344 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) {
345 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
346 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
348 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
349 EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair));
351 PortAlternateProtocolPair canonical_protocol;
352 canonical_protocol.port = 1234;
353 canonical_protocol.protocol = QUIC;
355 impl_.SetAlternateProtocol(canonical_port_pair,
356 canonical_protocol.port,
357 canonical_protocol.protocol);
358 // Verify the forced protocol.
359 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
360 PortAlternateProtocolPair alternate =
361 impl_.GetAlternateProtocol(test_host_port_pair);
362 EXPECT_EQ(canonical_protocol.port, alternate.port);
363 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol);
366 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest;
368 TEST_F(SpdySettingsServerPropertiesTest, Initialize) {
369 HostPortPair spdy_server_google("www.google.com", 443);
371 // Check by initializing empty spdy settings.
372 SpdySettingsMap spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT);
373 impl_.InitializeSpdySettingsServers(&spdy_settings_map);
374 EXPECT_TRUE(impl_.GetSpdySettings(spdy_server_google).empty());
376 // Check by initializing with www.google.com:443 spdy server settings.
377 SettingsMap settings_map;
378 const SpdySettingsIds id = SETTINGS_UPLOAD_BANDWIDTH;
379 const SpdySettingsFlags flags = SETTINGS_FLAG_PERSISTED;
380 const uint32 value = 31337;
381 SettingsFlagsAndValue flags_and_value(flags, value);
382 settings_map[id] = flags_and_value;
383 spdy_settings_map.Put(spdy_server_google, settings_map);
384 impl_.InitializeSpdySettingsServers(&spdy_settings_map);
386 const SettingsMap& settings_map2 = impl_.GetSpdySettings(spdy_server_google);
387 ASSERT_EQ(1U, settings_map2.size());
388 SettingsMap::const_iterator it = settings_map2.find(id);
389 EXPECT_TRUE(it != settings_map2.end());
390 SettingsFlagsAndValue flags_and_value2 = it->second;
391 EXPECT_EQ(flags, flags_and_value2.first);
392 EXPECT_EQ(value, flags_and_value2.second);
395 TEST_F(SpdySettingsServerPropertiesTest, SetSpdySetting) {
396 HostPortPair spdy_server_empty(std::string(), 443);
397 const SettingsMap& settings_map0 = impl_.GetSpdySettings(spdy_server_empty);
398 EXPECT_EQ(0U, settings_map0.size()); // Returns kEmptySettingsMap.
400 // Add www.google.com:443 as persisting.
401 HostPortPair spdy_server_google("www.google.com", 443);
402 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
403 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
404 const uint32 value1 = 31337;
405 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1));
406 // Check the values.
407 const SettingsMap& settings_map1_ret =
408 impl_.GetSpdySettings(spdy_server_google);
409 ASSERT_EQ(1U, settings_map1_ret.size());
410 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
411 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
412 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
413 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
414 EXPECT_EQ(value1, flags_and_value1_ret.second);
416 // Add mail.google.com:443 as not persisting.
417 HostPortPair spdy_server_mail("mail.google.com", 443);
418 const SpdySettingsIds id2 = SETTINGS_DOWNLOAD_BANDWIDTH;
419 const SpdySettingsFlags flags2 = SETTINGS_FLAG_NONE;
420 const uint32 value2 = 62667;
421 EXPECT_FALSE(impl_.SetSpdySetting(spdy_server_mail, id2, flags2, value2));
422 const SettingsMap& settings_map2_ret =
423 impl_.GetSpdySettings(spdy_server_mail);
424 EXPECT_EQ(0U, settings_map2_ret.size()); // Returns kEmptySettingsMap.
426 // Add docs.google.com:443 as persisting
427 HostPortPair spdy_server_docs("docs.google.com", 443);
428 const SpdySettingsIds id3 = SETTINGS_ROUND_TRIP_TIME;
429 const SpdySettingsFlags flags3 = SETTINGS_FLAG_PLEASE_PERSIST;
430 const uint32 value3 = 93997;
431 SettingsFlagsAndValue flags_and_value3(flags3, value3);
432 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id3, flags3, value3));
433 // Check the values.
434 const SettingsMap& settings_map3_ret =
435 impl_.GetSpdySettings(spdy_server_docs);
436 ASSERT_EQ(1U, settings_map3_ret.size());
437 SettingsMap::const_iterator it3_ret = settings_map3_ret.find(id3);
438 EXPECT_TRUE(it3_ret != settings_map3_ret.end());
439 SettingsFlagsAndValue flags_and_value3_ret = it3_ret->second;
440 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3_ret.first);
441 EXPECT_EQ(value3, flags_and_value3_ret.second);
443 // Check data for www.google.com:443 (id1).
444 const SettingsMap& settings_map4_ret =
445 impl_.GetSpdySettings(spdy_server_google);
446 ASSERT_EQ(1U, settings_map4_ret.size());
447 SettingsMap::const_iterator it4_ret = settings_map4_ret.find(id1);
448 EXPECT_TRUE(it4_ret != settings_map4_ret.end());
449 SettingsFlagsAndValue flags_and_value4_ret = it4_ret->second;
450 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value4_ret.first);
451 EXPECT_EQ(value1, flags_and_value1_ret.second);
453 // Clear www.google.com:443 as persisting.
454 impl_.ClearSpdySettings(spdy_server_google);
455 // Check the values.
456 const SettingsMap& settings_map5_ret =
457 impl_.GetSpdySettings(spdy_server_google);
458 ASSERT_EQ(0U, settings_map5_ret.size());
460 // Clear all settings.
461 ASSERT_GT(impl_.spdy_settings_map().size(), 0U);
462 impl_.ClearAllSpdySettings();
463 ASSERT_EQ(0U, impl_.spdy_settings_map().size());
466 TEST_F(SpdySettingsServerPropertiesTest, Clear) {
467 // Add www.google.com:443 as persisting.
468 HostPortPair spdy_server_google("www.google.com", 443);
469 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
470 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
471 const uint32 value1 = 31337;
472 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1));
473 // Check the values.
474 const SettingsMap& settings_map1_ret =
475 impl_.GetSpdySettings(spdy_server_google);
476 ASSERT_EQ(1U, settings_map1_ret.size());
477 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
478 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
479 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
480 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
481 EXPECT_EQ(value1, flags_and_value1_ret.second);
483 // Add docs.google.com:443 as persisting
484 HostPortPair spdy_server_docs("docs.google.com", 443);
485 const SpdySettingsIds id3 = SETTINGS_ROUND_TRIP_TIME;
486 const SpdySettingsFlags flags3 = SETTINGS_FLAG_PLEASE_PERSIST;
487 const uint32 value3 = 93997;
488 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id3, flags3, value3));
489 // Check the values.
490 const SettingsMap& settings_map3_ret =
491 impl_.GetSpdySettings(spdy_server_docs);
492 ASSERT_EQ(1U, settings_map3_ret.size());
493 SettingsMap::const_iterator it3_ret = settings_map3_ret.find(id3);
494 EXPECT_TRUE(it3_ret != settings_map3_ret.end());
495 SettingsFlagsAndValue flags_and_value3_ret = it3_ret->second;
496 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3_ret.first);
497 EXPECT_EQ(value3, flags_and_value3_ret.second);
499 impl_.Clear();
500 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_google).size());
501 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_docs).size());
504 TEST_F(SpdySettingsServerPropertiesTest, MRUOfGetSpdySettings) {
505 // Add www.google.com:443 as persisting.
506 HostPortPair spdy_server_google("www.google.com", 443);
507 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
508 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
509 const uint32 value1 = 31337;
510 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1));
512 // Add docs.google.com:443 as persisting
513 HostPortPair spdy_server_docs("docs.google.com", 443);
514 const SpdySettingsIds id2 = SETTINGS_ROUND_TRIP_TIME;
515 const SpdySettingsFlags flags2 = SETTINGS_FLAG_PLEASE_PERSIST;
516 const uint32 value2 = 93997;
517 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id2, flags2, value2));
519 // Verify the first element is docs.google.com:443.
520 const net::SpdySettingsMap& map = impl_.spdy_settings_map();
521 net::SpdySettingsMap::const_iterator it = map.begin();
522 EXPECT_TRUE(it->first.Equals(spdy_server_docs));
523 const SettingsMap& settings_map2_ret = it->second;
524 ASSERT_EQ(1U, settings_map2_ret.size());
525 SettingsMap::const_iterator it2_ret = settings_map2_ret.find(id2);
526 EXPECT_TRUE(it2_ret != settings_map2_ret.end());
527 SettingsFlagsAndValue flags_and_value2_ret = it2_ret->second;
528 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2_ret.first);
529 EXPECT_EQ(value2, flags_and_value2_ret.second);
531 // GetSpdySettings should reoder the SpdySettingsMap.
532 const SettingsMap& settings_map1_ret =
533 impl_.GetSpdySettings(spdy_server_google);
534 ASSERT_EQ(1U, settings_map1_ret.size());
535 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
536 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
537 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
538 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
539 EXPECT_EQ(value1, flags_and_value1_ret.second);
541 // Check the first entry is spdy_server_google by accessing it via iterator.
542 it = map.begin();
543 EXPECT_TRUE(it->first.Equals(spdy_server_google));
544 const SettingsMap& settings_map1_it_ret = it->second;
545 ASSERT_EQ(1U, settings_map1_it_ret.size());
546 it1_ret = settings_map1_it_ret.find(id1);
547 EXPECT_TRUE(it1_ret != settings_map1_it_ret.end());
548 flags_and_value1_ret = it1_ret->second;
549 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
550 EXPECT_EQ(value1, flags_and_value1_ret.second);
553 } // namespace
555 } // namespace net