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

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

Issue 903273002: Update from https://crrev.com/315085 (Closed) Base URL: git@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_manager.cc ('k') | net/http/http_stream_factory.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/json/json_writer.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "base/test/test_simple_task_runner.h" 15 #include "base/test/test_simple_task_runner.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const base::Closure& callback) { 68 const base::Closure& callback) {
68 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); 69 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback);
69 } 70 }
70 71
71 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); 72 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void());
72 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); 73 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&));
73 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, 74 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread,
74 void(std::vector<std::string>* spdy_servers, 75 void(std::vector<std::string>* spdy_servers,
75 SpdySettingsMap* spdy_settings_map, 76 SpdySettingsMap* spdy_settings_map,
76 AlternateProtocolMap* alternate_protocol_map, 77 AlternateProtocolMap* alternate_protocol_map,
77 SupportsQuicMap* supports_quic_map, 78 IPAddressNumber* last_quic_address,
78 ServerNetworkStatsMap* server_network_stats_map, 79 ServerNetworkStatsMap* server_network_stats_map,
79 bool detected_corrupted_prefs)); 80 bool detected_corrupted_prefs));
80 MOCK_METHOD5(UpdatePrefsOnPref, 81 MOCK_METHOD5(UpdatePrefsOnPref,
81 void(base::ListValue* spdy_server_list, 82 void(base::ListValue* spdy_server_list,
82 SpdySettingsMap* spdy_settings_map, 83 SpdySettingsMap* spdy_settings_map,
83 AlternateProtocolMap* alternate_protocol_map, 84 AlternateProtocolMap* alternate_protocol_map,
84 SupportsQuicMap* supports_quic_map, 85 IPAddressNumber* last_quic_address,
85 ServerNetworkStatsMap* server_network_stats_map)); 86 ServerNetworkStatsMap* server_network_stats_map));
86 87
87 private: 88 private:
88 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); 89 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager);
89 }; 90 };
90 91
91 class HttpServerPropertiesManagerTest : public testing::Test { 92 class HttpServerPropertiesManagerTest : public testing::Test {
92 protected: 93 protected:
93 HttpServerPropertiesManagerTest() {} 94 HttpServerPropertiesManagerTest() {}
94 95
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 128
128 void ExpectPrefsUpdateRepeatedly() { 129 void ExpectPrefsUpdateRepeatedly() {
129 EXPECT_CALL(*http_server_props_manager_, 130 EXPECT_CALL(*http_server_props_manager_,
130 UpdatePrefsFromCacheOnNetworkThread(_)) 131 UpdatePrefsFromCacheOnNetworkThread(_))
131 .WillRepeatedly( 132 .WillRepeatedly(
132 Invoke(http_server_props_manager_.get(), 133 Invoke(http_server_props_manager_.get(),
133 &TestingHttpServerPropertiesManager:: 134 &TestingHttpServerPropertiesManager::
134 UpdatePrefsFromCacheOnNetworkThreadConcrete)); 135 UpdatePrefsFromCacheOnNetworkThreadConcrete));
135 } 136 }
136 137
138 bool HasAlternateProtocol(const HostPortPair& server) {
139 const AlternateProtocolInfo alternate =
140 http_server_props_manager_->GetAlternateProtocol(server);
141 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL;
142 }
143
137 //base::RunLoop loop_; 144 //base::RunLoop loop_;
138 TestingPrefServiceSimple pref_service_; 145 TestingPrefServiceSimple pref_service_;
139 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; 146 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_;
140 147
141 private: 148 private:
142 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 149 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
143 }; 150 };
144 151
145 TEST_F(HttpServerPropertiesManagerTest, 152 TEST_F(HttpServerPropertiesManagerTest,
146 SingleUpdateForTwoSpdyServerPrefChanges) { 153 SingleUpdateForTwoSpdyServerPrefChanges) {
147 ExpectCacheUpdate(); 154 ExpectCacheUpdate();
148 155
149 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set 156 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set
150 // it twice. Only expect a single cache update. 157 // it twice. Only expect a single cache update.
151 158
152 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 159 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
153 HostPortPair google_server("www.google.com", 80); 160 HostPortPair google_server("www.google.com", 80);
154 HostPortPair mail_server("mail.google.com", 80); 161 HostPortPair mail_server("mail.google.com", 80);
155 162
156 // Set supports_spdy for www.google.com:80. 163 // Set supports_spdy for www.google.com:80.
157 server_pref_dict->SetBoolean("supports_spdy", true); 164 server_pref_dict->SetBoolean("supports_spdy", true);
158 165
159 // Set up alternate_protocol for www.google.com:80. 166 // Set up alternate_protocol for www.google.com:80.
160 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; 167 base::DictionaryValue* alternate_protocol = new base::DictionaryValue;
161 alternate_protocol->SetInteger("port", 443); 168 alternate_protocol->SetInteger("port", 443);
162 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); 169 alternate_protocol->SetString("protocol_str", "npn-spdy/3");
163 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", 170 server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
164 alternate_protocol); 171 alternate_protocol);
165 172
166 // Set up SupportsQuic for www.google.com:80.
167 base::DictionaryValue* supports_quic = new base::DictionaryValue;
168 supports_quic->SetBoolean("used_quic", true);
169 supports_quic->SetString("address", "foo");
170 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic);
171
172 // Set up ServerNetworkStats for www.google.com:80. 173 // Set up ServerNetworkStats for www.google.com:80.
173 base::DictionaryValue* stats = new base::DictionaryValue; 174 base::DictionaryValue* stats = new base::DictionaryValue;
174 stats->SetInteger("srtt", 10); 175 stats->SetInteger("srtt", 10);
175 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 176 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
176 177
177 // Set the server preference for www.google.com:80. 178 // Set the server preference for www.google.com:80.
178 base::DictionaryValue* servers_dict = new base::DictionaryValue; 179 base::DictionaryValue* servers_dict = new base::DictionaryValue;
179 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); 180 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
180 181
181 // Set the preference for mail.google.com server. 182 // Set the preference for mail.google.com server.
182 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 183 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
183 184
184 // Set supports_spdy for mail.google.com:80 185 // Set supports_spdy for mail.google.com:80
185 server_pref_dict1->SetBoolean("supports_spdy", true); 186 server_pref_dict1->SetBoolean("supports_spdy", true);
186 187
187 // Set up alternate_protocol for mail.google.com:80 188 // Set up alternate_protocol for mail.google.com:80
188 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; 189 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue;
189 alternate_protocol1->SetInteger("port", 444); 190 alternate_protocol1->SetInteger("port", 444);
190 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); 191 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1");
191 192
192 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", 193 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol",
193 alternate_protocol1); 194 alternate_protocol1);
194 195
195 // Set up SupportsQuic for mail.google.com:80
196 base::DictionaryValue* supports_quic1 = new base::DictionaryValue;
197 supports_quic1->SetBoolean("used_quic", false);
198 supports_quic1->SetString("address", "bar");
199 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1);
200
201 // Set up ServerNetworkStats for mail.google.com:80. 196 // Set up ServerNetworkStats for mail.google.com:80.
202 base::DictionaryValue* stats1 = new base::DictionaryValue; 197 base::DictionaryValue* stats1 = new base::DictionaryValue;
203 stats1->SetInteger("srtt", 20); 198 stats1->SetInteger("srtt", 20);
204 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); 199 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1);
205 // Set the server preference for mail.google.com:80. 200 // Set the server preference for mail.google.com:80.
206 servers_dict->SetWithoutPathExpansion("mail.google.com:80", 201 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
207 server_pref_dict1); 202 server_pref_dict1);
208 203
209 base::DictionaryValue* http_server_properties_dict = 204 base::DictionaryValue* http_server_properties_dict =
210 new base::DictionaryValue; 205 new base::DictionaryValue;
211 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 206 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
212 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 207 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
208 base::DictionaryValue* supports_quic = new base::DictionaryValue;
209 supports_quic->SetBoolean("used_quic", true);
210 supports_quic->SetString("address", "127.0.0.1");
211 http_server_properties_dict->SetWithoutPathExpansion("supports_quic",
212 supports_quic);
213 213
214 // Set the same value for kHttpServerProperties multiple times. 214 // Set the same value for kHttpServerProperties multiple times.
215 pref_service_.SetManagedPref(kTestHttpServerProperties, 215 pref_service_.SetManagedPref(kTestHttpServerProperties,
216 http_server_properties_dict); 216 http_server_properties_dict);
217 base::DictionaryValue* http_server_properties_dict2 = 217 base::DictionaryValue* http_server_properties_dict2 =
218 http_server_properties_dict->DeepCopy(); 218 http_server_properties_dict->DeepCopy();
219 pref_service_.SetManagedPref(kTestHttpServerProperties, 219 pref_service_.SetManagedPref(kTestHttpServerProperties,
220 http_server_properties_dict2); 220 http_server_properties_dict2);
221 221
222 base::RunLoop().RunUntilIdle(); 222 base::RunLoop().RunUntilIdle();
223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
224 224
225 // Verify SupportsSpdy. 225 // Verify SupportsSpdy.
226 EXPECT_TRUE( 226 EXPECT_TRUE(
227 http_server_props_manager_->SupportsRequestPriority(google_server)); 227 http_server_props_manager_->SupportsRequestPriority(google_server));
228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); 228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server));
229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
230 HostPortPair::FromString("foo.google.com:1337"))); 230 HostPortPair::FromString("foo.google.com:1337")));
231 231
232 // Verify AlternateProtocol. 232 // Verify AlternateProtocol.
233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server));
234 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server));
235 AlternateProtocolInfo port_alternate_protocol = 233 AlternateProtocolInfo port_alternate_protocol =
236 http_server_props_manager_->GetAlternateProtocol(google_server); 234 http_server_props_manager_->GetAlternateProtocol(google_server);
237 EXPECT_EQ(443, port_alternate_protocol.port); 235 EXPECT_EQ(443, port_alternate_protocol.port);
238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); 236 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
239 port_alternate_protocol = 237 port_alternate_protocol =
240 http_server_props_manager_->GetAlternateProtocol(mail_server); 238 http_server_props_manager_->GetAlternateProtocol(mail_server);
241 EXPECT_EQ(444, port_alternate_protocol.port); 239 EXPECT_EQ(444, port_alternate_protocol.port);
242 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); 240 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol);
243 241
244 // Verify SupportsQuic. 242 // Verify SupportsQuic.
245 SupportsQuic supports_quic2 = 243 IPAddressNumber last_address;
246 http_server_props_manager_->GetSupportsQuic(google_server); 244 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address));
247 EXPECT_TRUE(supports_quic2.used_quic); 245 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address));
248 EXPECT_EQ("foo", supports_quic2.address);
249 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server);
250 EXPECT_FALSE(supports_quic2.used_quic);
251 EXPECT_EQ("bar", supports_quic2.address);
252 246
253 // Verify ServerNetworkStats. 247 // Verify ServerNetworkStats.
254 const ServerNetworkStats* stats2 = 248 const ServerNetworkStats* stats2 =
255 http_server_props_manager_->GetServerNetworkStats(google_server); 249 http_server_props_manager_->GetServerNetworkStats(google_server);
256 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 250 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
257 const ServerNetworkStats* stats3 = 251 const ServerNetworkStats* stats3 =
258 http_server_props_manager_->GetServerNetworkStats(mail_server); 252 http_server_props_manager_->GetServerNetworkStats(mail_server);
259 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); 253 EXPECT_EQ(20, stats3->srtt.ToInternalValue());
260 } 254 }
261 255
262 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { 256 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
263 ExpectCacheUpdate(); 257 ExpectCacheUpdate();
264 // The prefs are automaticalls updated in the case corruption is detected. 258 // The prefs are automaticalls updated in the case corruption is detected.
265 ExpectPrefsUpdate(); 259 ExpectPrefsUpdate();
266 260
267 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 261 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
268 262
269 // Set supports_spdy for www.google.com:65536. 263 // Set supports_spdy for www.google.com:65536.
270 server_pref_dict->SetBoolean("supports_spdy", true); 264 server_pref_dict->SetBoolean("supports_spdy", true);
271 265
272 // Set up alternate_protocol for www.google.com:65536. 266 // Set up alternate_protocol for www.google.com:65536.
273 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; 267 base::DictionaryValue* alternate_protocol = new base::DictionaryValue;
274 alternate_protocol->SetInteger("port", 80); 268 alternate_protocol->SetInteger("port", 80);
275 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); 269 alternate_protocol->SetString("protocol_str", "npn-spdy/3");
276 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", 270 server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
277 alternate_protocol); 271 alternate_protocol);
278 272
279 // Set up SupportsQuic for www.google.com:65536.
280 base::DictionaryValue* supports_quic = new base::DictionaryValue;
281 supports_quic->SetBoolean("used_quic", true);
282 supports_quic->SetString("address", "foo");
283 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic);
284
285 // Set up ServerNetworkStats for www.google.com:65536. 273 // Set up ServerNetworkStats for www.google.com:65536.
286 base::DictionaryValue* stats = new base::DictionaryValue; 274 base::DictionaryValue* stats = new base::DictionaryValue;
287 stats->SetInteger("srtt", 10); 275 stats->SetInteger("srtt", 10);
288 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 276 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
289 277
290 // Set the server preference for www.google.com:65536. 278 // Set the server preference for www.google.com:65536.
291 base::DictionaryValue* servers_dict = new base::DictionaryValue; 279 base::DictionaryValue* servers_dict = new base::DictionaryValue;
292 servers_dict->SetWithoutPathExpansion("www.google.com:65536", 280 servers_dict->SetWithoutPathExpansion("www.google.com:65536",
293 server_pref_dict); 281 server_pref_dict);
294 282
295 base::DictionaryValue* http_server_properties_dict = 283 base::DictionaryValue* http_server_properties_dict =
296 new base::DictionaryValue; 284 new base::DictionaryValue;
297 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 285 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
298 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 286 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
299 287
300 // Set up the pref. 288 // Set up the pref.
301 pref_service_.SetManagedPref(kTestHttpServerProperties, 289 pref_service_.SetManagedPref(kTestHttpServerProperties,
302 http_server_properties_dict); 290 http_server_properties_dict);
303 291
304 base::RunLoop().RunUntilIdle(); 292 base::RunLoop().RunUntilIdle();
305 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 293 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
306 294
307 // Verify that nothing is set. 295 // Verify that nothing is set.
308 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 296 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
309 HostPortPair::FromString("www.google.com:65536"))); 297 HostPortPair::FromString("www.google.com:65536")));
310 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( 298 EXPECT_FALSE(
311 HostPortPair::FromString("www.google.com:65536"))); 299 HasAlternateProtocol(HostPortPair::FromString("www.google.com:65536")));
312 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic(
313 HostPortPair::FromString("www.google.com:65536"));
314 EXPECT_FALSE(supports_quic2.used_quic);
315 const ServerNetworkStats* stats1 = 300 const ServerNetworkStats* stats1 =
316 http_server_props_manager_->GetServerNetworkStats( 301 http_server_props_manager_->GetServerNetworkStats(
317 HostPortPair::FromString("www.google.com:65536")); 302 HostPortPair::FromString("www.google.com:65536"));
318 EXPECT_EQ(NULL, stats1); 303 EXPECT_EQ(NULL, stats1);
319 } 304 }
320 305
321 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { 306 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
322 ExpectCacheUpdate(); 307 ExpectCacheUpdate();
323 // The prefs are automaticalls updated in the case corruption is detected. 308 // The prefs are automaticalls updated in the case corruption is detected.
324 ExpectPrefsUpdate(); 309 ExpectPrefsUpdate();
(...skipping 20 matching lines...) Expand all
345 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 330 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
346 331
347 // Set up the pref. 332 // Set up the pref.
348 pref_service_.SetManagedPref(kTestHttpServerProperties, 333 pref_service_.SetManagedPref(kTestHttpServerProperties,
349 http_server_properties_dict); 334 http_server_properties_dict);
350 335
351 base::RunLoop().RunUntilIdle(); 336 base::RunLoop().RunUntilIdle();
352 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 337 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
353 338
354 // Verify AlternateProtocol is not set. 339 // Verify AlternateProtocol is not set.
355 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( 340 EXPECT_FALSE(
356 HostPortPair::FromString("www.google.com:80"))); 341 HasAlternateProtocol(HostPortPair::FromString("www.google.com:80")));
357 } 342 }
358 343
359 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { 344 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) {
360 ExpectPrefsUpdate(); 345 ExpectPrefsUpdate();
361 346
362 // Post an update task to the network thread. SetSupportsSpdy calls 347 // Post an update task to the network thread. SetSupportsSpdy calls
363 // ScheduleUpdatePrefsOnNetworkThread. 348 // ScheduleUpdatePrefsOnNetworkThread.
364 349
365 // Add mail.google.com:443 as a supporting spdy server. 350 // Add mail.google.com:443 as a supporting spdy server.
366 HostPortPair spdy_server_mail("mail.google.com", 443); 351 HostPortPair spdy_server_mail("mail.google.com", 443);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 base::RunLoop().RunUntilIdle(); 455 base::RunLoop().RunUntilIdle();
471 456
472 // Verify that there are no entries in the settings map. 457 // Verify that there are no entries in the settings map.
473 const SpdySettingsMap& spdy_settings_map2_ret = 458 const SpdySettingsMap& spdy_settings_map2_ret =
474 http_server_props_manager_->spdy_settings_map(); 459 http_server_props_manager_->spdy_settings_map();
475 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); 460 ASSERT_EQ(0U, spdy_settings_map2_ret.size());
476 461
477 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 462 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
478 } 463 }
479 464
480 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { 465 TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) {
481 ExpectPrefsUpdate(); 466 ExpectPrefsUpdate();
482 467
483 HostPortPair spdy_server_mail("mail.google.com", 80); 468 HostPortPair spdy_server_mail("mail.google.com", 80);
484 EXPECT_FALSE( 469 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail));
485 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
486 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, 470 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443,
487 NPN_SPDY_3, 1.0); 471 NPN_SPDY_3, 1.0);
488 472
489 // Run the task. 473 // Run the task.
490 base::RunLoop().RunUntilIdle(); 474 base::RunLoop().RunUntilIdle();
491 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 475 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
492 476
493 ASSERT_TRUE( 477 const AlternateProtocolInfo alternate_protocol =
494 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
495 AlternateProtocolInfo port_alternate_protocol =
496 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); 478 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail);
497 EXPECT_EQ(443, port_alternate_protocol.port); 479 EXPECT_EQ(443, alternate_protocol.port);
498 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); 480 EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol);
481 EXPECT_EQ(1.0, alternate_protocol.probability);
499 } 482 }
500 483
501 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { 484 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) {
502 ExpectPrefsUpdate(); 485 ExpectPrefsUpdate();
503 486
504 HostPortPair quic_server_mail("mail.google.com", 80); 487 IPAddressNumber address;
505 SupportsQuic supports_quic = 488 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
506 http_server_props_manager_->GetSupportsQuic(quic_server_mail); 489
507 EXPECT_FALSE(supports_quic.used_quic); 490 IPAddressNumber actual_address;
508 EXPECT_EQ("", supports_quic.address); 491 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
509 http_server_props_manager_->SetSupportsQuic(quic_server_mail, true, "foo"); 492 http_server_props_manager_->SetSupportsQuic(true, actual_address);
510 493
511 // Run the task. 494 // Run the task.
512 base::RunLoop().RunUntilIdle(); 495 base::RunLoop().RunUntilIdle();
513 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 496 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
514 497
515 SupportsQuic supports_quic1 = 498 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
516 http_server_props_manager_->GetSupportsQuic(quic_server_mail); 499 EXPECT_EQ(actual_address, address);
517 EXPECT_TRUE(supports_quic1.used_quic);
518 EXPECT_EQ("foo", supports_quic1.address);
519 } 500 }
520 501
521 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { 502 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) {
522 ExpectPrefsUpdate(); 503 ExpectPrefsUpdate();
523 504
524 HostPortPair mail_server("mail.google.com", 80); 505 HostPortPair mail_server("mail.google.com", 80);
525 const ServerNetworkStats* stats = 506 const ServerNetworkStats* stats =
526 http_server_props_manager_->GetServerNetworkStats(mail_server); 507 http_server_props_manager_->GetServerNetworkStats(mail_server);
527 EXPECT_EQ(NULL, stats); 508 EXPECT_EQ(NULL, stats);
528 ServerNetworkStats stats1; 509 ServerNetworkStats stats1;
529 stats1.srtt = base::TimeDelta::FromMicroseconds(10); 510 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
530 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); 511 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1);
531 512
532 // Run the task. 513 // Run the task.
533 base::RunLoop().RunUntilIdle(); 514 base::RunLoop().RunUntilIdle();
534 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 515 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
535 516
536 const ServerNetworkStats* stats2 = 517 const ServerNetworkStats* stats2 =
537 http_server_props_manager_->GetServerNetworkStats(mail_server); 518 http_server_props_manager_->GetServerNetworkStats(mail_server);
538 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 519 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
539 } 520 }
540 521
541 TEST_F(HttpServerPropertiesManagerTest, Clear) { 522 TEST_F(HttpServerPropertiesManagerTest, Clear) {
542 ExpectPrefsUpdate(); 523 ExpectPrefsUpdate();
543 524
544 HostPortPair spdy_server_mail("mail.google.com", 443); 525 HostPortPair spdy_server_mail("mail.google.com", 443);
545 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 526 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
546 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, 527 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443,
547 NPN_SPDY_3, 1.0); 528 NPN_SPDY_3, 1.0);
548 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); 529 IPAddressNumber actual_address;
530 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
531 http_server_props_manager_->SetSupportsQuic(true, actual_address);
549 ServerNetworkStats stats; 532 ServerNetworkStats stats;
550 stats.srtt = base::TimeDelta::FromMicroseconds(10); 533 stats.srtt = base::TimeDelta::FromMicroseconds(10);
551 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); 534 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats);
552 535
553 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 536 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
554 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 537 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
555 const uint32 value1 = 31337; 538 const uint32 value1 = 31337;
556 http_server_props_manager_->SetSpdySetting( 539 http_server_props_manager_->SetSpdySetting(
557 spdy_server_mail, id1, flags1, value1); 540 spdy_server_mail, id1, flags1, value1);
558 541
559 // Run the task. 542 // Run the task.
560 base::RunLoop().RunUntilIdle(); 543 base::RunLoop().RunUntilIdle();
561 544
562 EXPECT_TRUE( 545 EXPECT_TRUE(
563 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); 546 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
564 EXPECT_TRUE( 547 EXPECT_TRUE(HasAlternateProtocol(spdy_server_mail));
565 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 548 IPAddressNumber address;
566 SupportsQuic supports_quic = 549 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
567 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); 550 EXPECT_EQ(actual_address, address);
568 EXPECT_TRUE(supports_quic.used_quic);
569 EXPECT_EQ("foo", supports_quic.address);
570 const ServerNetworkStats* stats1 = 551 const ServerNetworkStats* stats1 =
571 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 552 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
572 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); 553 EXPECT_EQ(10, stats1->srtt.ToInternalValue());
573 554
574 // Check SPDY settings values. 555 // Check SPDY settings values.
575 const SettingsMap& settings_map1_ret = 556 const SettingsMap& settings_map1_ret =
576 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 557 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
577 ASSERT_EQ(1U, settings_map1_ret.size()); 558 ASSERT_EQ(1U, settings_map1_ret.size());
578 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 559 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
579 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 560 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
580 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 561 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
581 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 562 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
582 EXPECT_EQ(value1, flags_and_value1_ret.second); 563 EXPECT_EQ(value1, flags_and_value1_ret.second);
583 564
584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 565 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
585 566
586 ExpectPrefsUpdate(); 567 ExpectPrefsUpdate();
587 568
588 // Clear http server data, time out if we do not get a completion callback. 569 // Clear http server data, time out if we do not get a completion callback.
589 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); 570 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure());
590 base::RunLoop().Run(); 571 base::RunLoop().Run();
591 572
592 EXPECT_FALSE( 573 EXPECT_FALSE(
593 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); 574 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
594 EXPECT_FALSE( 575 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail));
595 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 576 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
596 SupportsQuic supports_quic1 =
597 http_server_props_manager_->GetSupportsQuic(spdy_server_mail);
598 EXPECT_FALSE(supports_quic1.used_quic);
599 EXPECT_EQ("", supports_quic1.address);
600 const ServerNetworkStats* stats2 = 577 const ServerNetworkStats* stats2 =
601 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); 578 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
602 EXPECT_EQ(NULL, stats2); 579 EXPECT_EQ(NULL, stats2);
603 580
604 const SettingsMap& settings_map2_ret = 581 const SettingsMap& settings_map2_ret =
605 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 582 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
606 EXPECT_EQ(0U, settings_map2_ret.size()); 583 EXPECT_EQ(0U, settings_map2_ret.size());
607 584
608 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 585 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
609 } 586 }
(...skipping 12 matching lines...) Expand all
622 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); 599 alternate_protocol->SetString("protocol_str", "npn-spdy/3");
623 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 600 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
624 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", 601 server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
625 alternate_protocol); 602 alternate_protocol);
626 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), 603 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i),
627 server_pref_dict); 604 server_pref_dict);
628 } 605 }
629 606
630 // Set the preference for mail.google.com server. 607 // Set the preference for mail.google.com server.
631 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 608 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
632 // Set up SupportsQuic for mail.google.com:80
633 base::DictionaryValue* supports_quic = new base::DictionaryValue;
634 supports_quic->SetBoolean("used_quic", true);
635 supports_quic->SetString("address", "bar");
636 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic);
637 609
638 // Set the server preference for mail.google.com:80. 610 // Set the server preference for mail.google.com:80.
639 servers_dict->SetWithoutPathExpansion("mail.google.com:80", 611 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
640 server_pref_dict1); 612 server_pref_dict1);
641 613
642 base::DictionaryValue* http_server_properties_dict = 614 base::DictionaryValue* http_server_properties_dict =
643 new base::DictionaryValue; 615 new base::DictionaryValue;
644 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 616 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
645 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 617 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
646 618
619 // Set up SupportsQuic for 127.0.0.1
620 base::DictionaryValue* supports_quic = new base::DictionaryValue;
621 supports_quic->SetBoolean("used_quic", true);
622 supports_quic->SetString("address", "127.0.0.1");
623 http_server_properties_dict->SetWithoutPathExpansion("supports_quic",
624 supports_quic);
625
647 // Set up the pref. 626 // Set up the pref.
648 pref_service_.SetManagedPref(kTestHttpServerProperties, 627 pref_service_.SetManagedPref(kTestHttpServerProperties,
649 http_server_properties_dict); 628 http_server_properties_dict);
650 629
651 base::RunLoop().RunUntilIdle(); 630 base::RunLoop().RunUntilIdle();
652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 631 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
653 632
654 // Verify AlternateProtocol. 633 // Verify AlternateProtocol.
655 for (int i = 0; i < 200; ++i) { 634 for (int i = 0; i < 200; ++i) {
656 std::string server = StringPrintf("www.google.com:%d", i); 635 std::string server = StringPrintf("www.google.com:%d", i);
657 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
658 HostPortPair::FromString(server)));
659 AlternateProtocolInfo port_alternate_protocol = 636 AlternateProtocolInfo port_alternate_protocol =
660 http_server_props_manager_->GetAlternateProtocol( 637 http_server_props_manager_->GetAlternateProtocol(
661 HostPortPair::FromString(server)); 638 HostPortPair::FromString(server));
662 EXPECT_EQ(i, port_alternate_protocol.port); 639 EXPECT_EQ(i, port_alternate_protocol.port);
663 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); 640 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
664 } 641 }
665 642
666 // Verify SupportsQuic. 643 // Verify SupportsQuic.
667 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( 644 IPAddressNumber address;
668 HostPortPair::FromString("mail.google.com:80")); 645 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
669 EXPECT_TRUE(supports_quic1.used_quic); 646 EXPECT_EQ("127.0.0.1", IPAddressToString(address));
670 EXPECT_EQ("bar", supports_quic1.address); 647 }
648
649 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
650 const HostPortPair server_www("www.google.com", 80);
651 const HostPortPair server_mail("mail.google.com", 80);
652
653 // Set alternate protocol.
654 http_server_props_manager_->SetAlternateProtocol(server_www, 443, NPN_SPDY_3,
655 1.0);
656 http_server_props_manager_->SetAlternateProtocol(server_mail, 444,
657 NPN_SPDY_3_1, 0.2);
658
659 // Set ServerNetworkStats.
660 ServerNetworkStats stats;
661 stats.srtt = base::TimeDelta::FromInternalValue(42);
662 http_server_props_manager_->SetServerNetworkStats(server_mail, stats);
663
664 // Set SupportsQuic.
665 IPAddressNumber actual_address;
666 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
667 http_server_props_manager_->SetSupportsQuic(true, actual_address);
668
669 // Update cache.
670 ExpectPrefsUpdate();
671 ExpectCacheUpdate();
672 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
673 base::RunLoop().RunUntilIdle();
674
675 // Verify preferences.
676 const char expected_json[] = "{"
677 "\"servers\":{"
678 "\"mail.google.com:80\":{"
679 "\"alternate_protocol\":{"
680 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\""
681 "},"
682 "\"network_stats\":{"
683 "\"srtt\":42"
684 "}"
685 "},"
686 "\"www.google.com:80\":{"
687 "\"alternate_protocol\":{"
688 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-spdy/3\""
689 "}"
690 "}"
691 "},"
692 "\"supports_quic\":{"
693 "\"address\":\"127.0.0.1\",\"used_quic\":true"
694 "},"
695 "\"version\":3"
696 "}";
697
698 const base::Value* http_server_properties =
699 pref_service_.GetUserPref(kTestHttpServerProperties);
700 ASSERT_NE(nullptr, http_server_properties);
701 std::string preferences_json;
702 EXPECT_TRUE(
703 base::JSONWriter::Write(http_server_properties, &preferences_json));
704 EXPECT_EQ(expected_json, preferences_json);
671 } 705 }
672 706
673 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { 707 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) {
674 // Post an update task to the UI thread. 708 // Post an update task to the UI thread.
675 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 709 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
676 // Shutdown comes before the task is executed. 710 // Shutdown comes before the task is executed.
677 http_server_props_manager_->ShutdownOnPrefThread(); 711 http_server_props_manager_->ShutdownOnPrefThread();
678 http_server_props_manager_.reset(); 712 http_server_props_manager_.reset();
679 // Run the task after shutdown and deletion. 713 // Run the task after shutdown and deletion.
680 base::RunLoop().RunUntilIdle(); 714 base::RunLoop().RunUntilIdle();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 // Run the task after shutdown, but before deletion. 772 // Run the task after shutdown, but before deletion.
739 base::RunLoop().RunUntilIdle(); 773 base::RunLoop().RunUntilIdle();
740 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 774 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
741 http_server_props_manager_.reset(); 775 http_server_props_manager_.reset();
742 base::RunLoop().RunUntilIdle(); 776 base::RunLoop().RunUntilIdle();
743 } 777 }
744 778
745 } // namespace 779 } // namespace
746 780
747 } // namespace net 781 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698