OLD | NEW |
---|---|
(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 | |
willchan no longer on Chromium
2011/10/06 22:13:22
Please put everything in an anonymous namespace wi
ramant (doing other things)
2011/10/07 01:40:20
Done.
| |
23 class HttpServerPropertiesImplTest : public testing::Test { | |
24 public: | |
willchan no longer on Chromium
2011/10/06 22:13:22
Make this protected.
ramant (doing other things)
2011/10/07 01:40:20
Done.
| |
25 scoped_ptr<HttpServerPropertiesImpl> impl_; | |
willchan no longer on Chromium
2011/10/06 22:13:22
member variables come after methods according to t
ramant (doing other things)
2011/10/07 01:40:20
Done.
| |
26 | |
27 HttpServerPropertiesImplTest() { | |
28 impl_.reset(new HttpServerPropertiesImpl()); | |
29 } | |
30 | |
31 ~HttpServerPropertiesImplTest() { | |
32 impl_.reset(); | |
willchan no longer on Chromium
2011/10/06 22:13:22
No need to call scoped_ptr<T>::reset() in the dest
ramant (doing other things)
2011/10/07 01:40:20
Done.
| |
33 } | |
34 }; | |
35 | |
36 TEST_F(HttpServerPropertiesImplTest, InitializeTest) { | |
37 // Check by initializing NULL spdy servers. | |
38 impl_->Initialize(NULL, true); | |
39 EXPECT_EQ(impl_->spdy_servers_table_.size(), 0u); | |
40 | |
41 // Check by initializing empty spdy servers. | |
42 HttpServerProperties::StringVector spdy_servers; | |
43 impl_->Initialize(&spdy_servers, true); | |
44 EXPECT_EQ(impl_->spdy_servers_table_.size(), 0u); | |
45 | |
46 HostPortPair spdy_server_google("www.google.com", 443); | |
47 std::string spdy_server_g = | |
48 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); | |
49 | |
50 HostPortPair spdy_server_docs("docs.google.com", 443); | |
51 std::string spdy_server_d = | |
52 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_docs); | |
53 | |
54 // Check by initializing with www.google.com:443 spdy server. | |
55 HttpServerProperties::StringVector spdy_servers1; | |
56 spdy_servers1.push_back(spdy_server_g); | |
57 impl_->Initialize(&spdy_servers1, true); | |
58 EXPECT_EQ(impl_->spdy_servers_table_.size(), 1u); | |
59 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_google)); | |
60 | |
61 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy | |
62 // servers. | |
63 HttpServerProperties::StringVector spdy_servers2; | |
64 spdy_servers2.push_back(spdy_server_g); | |
65 spdy_servers2.push_back(spdy_server_d); | |
66 impl_->Initialize(&spdy_servers2, true); | |
67 EXPECT_EQ(impl_->spdy_servers_table_.size(), 2u); | |
68 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_google)); | |
69 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_docs)); | |
70 } | |
71 | |
72 TEST_F(HttpServerPropertiesImplTest, SupportsSpdyTest) { | |
73 HostPortPair spdy_server_empty("", 443); | |
74 EXPECT_FALSE(impl_->SupportsSpdy(spdy_server_empty)); | |
75 | |
76 // Add www.google.com:443 as supporting SPDY. | |
77 HostPortPair spdy_server_google("www.google.com", 443); | |
78 impl_->SetSupportsSpdy(spdy_server_google, true); | |
79 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_google)); | |
80 | |
81 // Add mail.google.com:443 as not supporting SPDY. | |
82 HostPortPair spdy_server_mail("mail.google.com", 443); | |
83 EXPECT_FALSE(impl_->SupportsSpdy(spdy_server_mail)); | |
84 | |
85 // Add docs.google.com:443 as supporting SPDY. | |
86 HostPortPair spdy_server_docs("docs.google.com", 443); | |
87 impl_->SetSupportsSpdy(spdy_server_docs, true); | |
88 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_docs)); | |
89 | |
90 // Verify all the entries are the same after additions. | |
91 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_google)); | |
92 EXPECT_FALSE(impl_->SupportsSpdy(spdy_server_mail)); | |
93 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_docs)); | |
94 } | |
95 | |
96 TEST_F(HttpServerPropertiesImplTest, SetSupportsSpdyTest) { | |
97 HostPortPair spdy_server_empty("", 443); | |
98 impl_->SetSupportsSpdy(spdy_server_empty, true); | |
99 EXPECT_FALSE(impl_->SupportsSpdy(spdy_server_empty)); | |
100 | |
101 // Add www.google.com:443 as supporting SPDY. | |
102 HostPortPair spdy_server_google("www.google.com", 443); | |
103 EXPECT_FALSE(impl_->SupportsSpdy(spdy_server_google)); | |
104 impl_->SetSupportsSpdy(spdy_server_google, true); | |
105 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_google)); | |
106 | |
107 // Make www.google.com:443 as not supporting SPDY. | |
108 impl_->SetSupportsSpdy(spdy_server_google, false); | |
109 EXPECT_FALSE(impl_->SupportsSpdy(spdy_server_google)); | |
110 | |
111 // Add mail.google.com:443 as supporting SPDY. | |
112 HostPortPair spdy_server_mail("mail.google.com", 443); | |
113 EXPECT_FALSE(impl_->SupportsSpdy(spdy_server_mail)); | |
114 impl_->SetSupportsSpdy(spdy_server_mail, true); | |
115 EXPECT_TRUE(impl_->SupportsSpdy(spdy_server_mail)); | |
116 EXPECT_FALSE(impl_->SupportsSpdy(spdy_server_google)); | |
117 } | |
118 | |
119 TEST_F(HttpServerPropertiesImplTest, DeleteAllTest) { | |
120 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. | |
121 HostPortPair spdy_server_google("www.google.com", 443); | |
122 impl_->SetSupportsSpdy(spdy_server_google, true); | |
123 HostPortPair spdy_server_mail("mail.google.com", 443); | |
124 impl_->SetSupportsSpdy(spdy_server_mail, true); | |
125 | |
126 EXPECT_EQ(impl_->spdy_servers_table_.size(), 2u); | |
willchan no longer on Chromium
2011/10/06 22:13:22
Your expectations are reversed. The expected value
ramant (doing other things)
2011/10/07 01:40:20
Done.
| |
127 | |
128 impl_->DeleteAll(); | |
129 EXPECT_EQ(impl_->spdy_servers_table_.size(), 0u); | |
130 } | |
131 | |
132 TEST_F(HttpServerPropertiesImplTest, GetSpdyServerListTest) { | |
133 base::ListValue spdy_server_list; | |
134 | |
135 // Check there are no spdy_servers. | |
136 impl_->GetSpdyServerList(&spdy_server_list); | |
137 EXPECT_EQ(0u, spdy_server_list.GetSize()); | |
138 | |
139 // Check empty server is not added. | |
140 HostPortPair spdy_server_empty("", 443); | |
141 impl_->SetSupportsSpdy(spdy_server_empty, true); | |
142 impl_->GetSpdyServerList(&spdy_server_list); | |
143 EXPECT_EQ(0u, spdy_server_list.GetSize()); | |
144 | |
145 std::string string_value_g; | |
146 std::string string_value_m; | |
147 HostPortPair spdy_server_google("www.google.com", 443); | |
148 std::string spdy_server_g = | |
149 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); | |
150 HostPortPair spdy_server_mail("mail.google.com", 443); | |
151 std::string spdy_server_m = | |
152 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail); | |
153 | |
154 // Add www.google.com:443 as not supporting SPDY. | |
155 impl_->SetSupportsSpdy(spdy_server_google, false); | |
156 impl_->GetSpdyServerList(&spdy_server_list); | |
157 EXPECT_EQ(0u, spdy_server_list.GetSize()); | |
158 | |
159 // Add www.google.com:443 as supporting SPDY. | |
160 impl_->SetSupportsSpdy(spdy_server_google, true); | |
161 impl_->GetSpdyServerList(&spdy_server_list); | |
162 EXPECT_EQ(1u, spdy_server_list.GetSize()); | |
163 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | |
164 ASSERT_EQ(spdy_server_g, string_value_g); | |
165 | |
166 // Add mail.google.com:443 as not supporting SPDY. | |
167 impl_->SetSupportsSpdy(spdy_server_mail, false); | |
168 impl_->GetSpdyServerList(&spdy_server_list); | |
169 EXPECT_EQ(1u, spdy_server_list.GetSize()); | |
170 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | |
171 ASSERT_EQ(spdy_server_g, string_value_g); | |
172 | |
173 // Add mail.google.com:443 as supporting SPDY. | |
174 impl_->SetSupportsSpdy(spdy_server_mail, true); | |
175 impl_->GetSpdyServerList(&spdy_server_list); | |
176 EXPECT_EQ(2u, spdy_server_list.GetSize()); | |
177 | |
178 // Verify www.google.com:443 and mail.google.com:443 are in the list. | |
179 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | |
180 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | |
181 if (string_value_g.compare(spdy_server_g) == 0) { | |
182 ASSERT_EQ(spdy_server_g, string_value_g); | |
183 ASSERT_EQ(spdy_server_m, string_value_m); | |
184 } else { | |
185 ASSERT_EQ(spdy_server_g, string_value_m); | |
186 ASSERT_EQ(spdy_server_m, string_value_g); | |
187 } | |
188 } | |
189 | |
190 } // namespace net | |
OLD | NEW |