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

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

Issue 7827033: Introduce net::HttpServerPropertiesManager to manage server-specific properties. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "net/http/http_server_properties_impl.h"
6
7 #include <string>
8
9 #include "base/basictypes.h"
10 #include "base/hash_tables.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/values.h"
14 #include "net/base/host_port_pair.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace base {
18 class ListValue;
19 }
20
21 namespace net {
22
23 namespace {
24
25 class HttpServerPropertiesImplTest : public testing::Test {
26 protected:
27 HttpServerPropertiesImpl impl_;
28 };
29
30 TEST_F(HttpServerPropertiesImplTest, InitializeTest) {
31 HostPortPair spdy_server_google("www.google.com", 443);
32 std::string spdy_server_g =
33 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google);
34
35 HostPortPair spdy_server_docs("docs.google.com", 443);
36 std::string spdy_server_d =
37 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_docs);
38
39 // Check by initializing NULL spdy servers.
40 impl_.Initialize(NULL, true);
41 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
42
43 // Check by initializing empty spdy servers.
44 HttpServerProperties::StringVector spdy_servers;
45 impl_.Initialize(&spdy_servers, true);
46 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
47
48 // Check by initializing with www.google.com:443 spdy server.
49 HttpServerProperties::StringVector spdy_servers1;
50 spdy_servers1.push_back(spdy_server_g);
51 impl_.Initialize(&spdy_servers1, true);
52 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
53
54 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy
55 // servers.
56 HttpServerProperties::StringVector spdy_servers2;
57 spdy_servers2.push_back(spdy_server_g);
58 spdy_servers2.push_back(spdy_server_d);
59 impl_.Initialize(&spdy_servers2, true);
60 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
61 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs));
62 }
63
64 TEST_F(HttpServerPropertiesImplTest, SupportsSpdyTest) {
65 HostPortPair spdy_server_empty("", 443);
66 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty));
67
68 // Add www.google.com:443 as supporting SPDY.
69 HostPortPair spdy_server_google("www.google.com", 443);
70 impl_.SetSupportsSpdy(spdy_server_google, true);
71 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
72
73 // Add mail.google.com:443 as not supporting SPDY.
74 HostPortPair spdy_server_mail("mail.google.com", 443);
75 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
76
77 // Add docs.google.com:443 as supporting SPDY.
78 HostPortPair spdy_server_docs("docs.google.com", 443);
79 impl_.SetSupportsSpdy(spdy_server_docs, true);
80 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs));
81
82 // Verify all the entries are the same after additions.
83 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
84 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
85 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs));
86 }
87
88 TEST_F(HttpServerPropertiesImplTest, SetSupportsSpdyTest) {
89 HostPortPair spdy_server_empty("", 443);
90 impl_.SetSupportsSpdy(spdy_server_empty, true);
91 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty));
92
93 // Add www.google.com:443 as supporting SPDY.
94 HostPortPair spdy_server_google("www.google.com", 443);
95 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
96 impl_.SetSupportsSpdy(spdy_server_google, true);
97 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
98
99 // Make www.google.com:443 as not supporting SPDY.
100 impl_.SetSupportsSpdy(spdy_server_google, false);
101 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
102
103 // Add mail.google.com:443 as supporting SPDY.
104 HostPortPair spdy_server_mail("mail.google.com", 443);
105 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
106 impl_.SetSupportsSpdy(spdy_server_mail, true);
107 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail));
108 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
109 }
110
111 TEST_F(HttpServerPropertiesImplTest, DeleteAllTest) {
112 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY.
113 HostPortPair spdy_server_google("www.google.com", 443);
114 impl_.SetSupportsSpdy(spdy_server_google, true);
115 HostPortPair spdy_server_mail("mail.google.com", 443);
116 impl_.SetSupportsSpdy(spdy_server_mail, true);
117
118 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
119 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail));
120
121 impl_.DeleteAll();
122 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
123 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
124 }
125
126 TEST_F(HttpServerPropertiesImplTest, GetSpdyServerListTest) {
127 base::ListValue spdy_server_list;
128
129 // Check there are no spdy_servers.
130 impl_.GetSpdyServerList(&spdy_server_list);
131 EXPECT_EQ(0u, spdy_server_list.GetSize());
132
133 // Check empty server is not added.
134 HostPortPair spdy_server_empty("", 443);
135 impl_.SetSupportsSpdy(spdy_server_empty, true);
136 impl_.GetSpdyServerList(&spdy_server_list);
137 EXPECT_EQ(0u, spdy_server_list.GetSize());
138
139 std::string string_value_g;
140 std::string string_value_m;
141 HostPortPair spdy_server_google("www.google.com", 443);
142 std::string spdy_server_g =
143 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google);
144 HostPortPair spdy_server_mail("mail.google.com", 443);
145 std::string spdy_server_m =
146 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail);
147
148 // Add www.google.com:443 as not supporting SPDY.
149 impl_.SetSupportsSpdy(spdy_server_google, false);
150 impl_.GetSpdyServerList(&spdy_server_list);
151 EXPECT_EQ(0u, spdy_server_list.GetSize());
152
153 // Add www.google.com:443 as supporting SPDY.
154 impl_.SetSupportsSpdy(spdy_server_google, true);
155 impl_.GetSpdyServerList(&spdy_server_list);
156 EXPECT_EQ(1u, spdy_server_list.GetSize());
157 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
158 ASSERT_EQ(spdy_server_g, string_value_g);
159
160 // Add mail.google.com:443 as not supporting SPDY.
161 impl_.SetSupportsSpdy(spdy_server_mail, false);
162 impl_.GetSpdyServerList(&spdy_server_list);
163 EXPECT_EQ(1u, spdy_server_list.GetSize());
164 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
165 ASSERT_EQ(spdy_server_g, string_value_g);
166
167 // Add mail.google.com:443 as supporting SPDY.
168 impl_.SetSupportsSpdy(spdy_server_mail, true);
169 impl_.GetSpdyServerList(&spdy_server_list);
170 EXPECT_EQ(2u, spdy_server_list.GetSize());
171
172 // Verify www.google.com:443 and mail.google.com:443 are in the list.
173 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
174 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m));
175 if (string_value_g.compare(spdy_server_g) == 0) {
176 ASSERT_EQ(spdy_server_g, string_value_g);
177 ASSERT_EQ(spdy_server_m, string_value_m);
178 } else {
179 ASSERT_EQ(spdy_server_g, string_value_m);
180 ASSERT_EQ(spdy_server_m, string_value_g);
181 }
182 }
183
184 } // namespace
185
186 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698