OLD | NEW |
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/json/json_writer.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void UpdatePrefsFromCacheOnNetworkThreadConcrete( | 67 void UpdatePrefsFromCacheOnNetworkThreadConcrete( |
68 const base::Closure& callback) { | 68 const base::Closure& callback) { |
69 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); | 69 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); |
70 } | 70 } |
71 | 71 |
72 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); | 72 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); |
73 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); | 73 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); |
74 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, | 74 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, |
75 void(std::vector<std::string>* spdy_servers, | 75 void(std::vector<std::string>* spdy_servers, |
76 SpdySettingsMap* spdy_settings_map, | 76 SpdySettingsMap* spdy_settings_map, |
77 AlternateProtocolMap* alternate_protocol_map, | 77 AlternativeServiceMap* alternative_service_map, |
78 IPAddressNumber* last_quic_address, | 78 IPAddressNumber* last_quic_address, |
79 ServerNetworkStatsMap* server_network_stats_map, | 79 ServerNetworkStatsMap* server_network_stats_map, |
80 bool detected_corrupted_prefs)); | 80 bool detected_corrupted_prefs)); |
81 MOCK_METHOD5(UpdatePrefsOnPref, | 81 MOCK_METHOD5(UpdatePrefsOnPref, |
82 void(base::ListValue* spdy_server_list, | 82 void(base::ListValue* spdy_server_list, |
83 SpdySettingsMap* spdy_settings_map, | 83 SpdySettingsMap* spdy_settings_map, |
84 AlternateProtocolMap* alternate_protocol_map, | 84 AlternativeServiceMap* alternative_service_map, |
85 IPAddressNumber* last_quic_address, | 85 IPAddressNumber* last_quic_address, |
86 ServerNetworkStatsMap* server_network_stats_map)); | 86 ServerNetworkStatsMap* server_network_stats_map)); |
87 | 87 |
88 private: | 88 private: |
89 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 89 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
90 }; | 90 }; |
91 | 91 |
92 class HttpServerPropertiesManagerTest : public testing::Test { | 92 class HttpServerPropertiesManagerTest : public testing::Test { |
93 protected: | 93 protected: |
94 HttpServerPropertiesManagerTest() {} | 94 HttpServerPropertiesManagerTest() {} |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // 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 |
157 // it twice. Only expect a single cache update. | 157 // it twice. Only expect a single cache update. |
158 | 158 |
159 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 159 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
160 HostPortPair google_server("www.google.com", 80); | 160 HostPortPair google_server("www.google.com", 80); |
161 HostPortPair mail_server("mail.google.com", 80); | 161 HostPortPair mail_server("mail.google.com", 80); |
162 | 162 |
163 // Set supports_spdy for www.google.com:80. | 163 // Set supports_spdy for www.google.com:80. |
164 server_pref_dict->SetBoolean("supports_spdy", true); | 164 server_pref_dict->SetBoolean("supports_spdy", true); |
165 | 165 |
166 // Set up alternate_protocol for www.google.com:80. | 166 // Set up alternative_service for www.google.com:80. |
167 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 167 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
168 alternate_protocol->SetInteger("port", 443); | 168 alternative_service_dict->SetString("protocol_str", "npn-spdy/3"); |
169 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 169 alternative_service_dict->SetString("host", "maps.google.com"); |
170 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 170 alternative_service_dict->SetInteger("port", 443); |
171 alternate_protocol); | 171 base::ListValue* alternative_service_list = new base::ListValue; |
| 172 alternative_service_list->Append(alternative_service_dict); |
| 173 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 174 alternative_service_list); |
172 | 175 |
173 // Set up ServerNetworkStats for www.google.com:80. | 176 // Set up ServerNetworkStats for www.google.com:80. |
174 base::DictionaryValue* stats = new base::DictionaryValue; | 177 base::DictionaryValue* stats = new base::DictionaryValue; |
175 stats->SetInteger("srtt", 10); | 178 stats->SetInteger("srtt", 10); |
176 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 179 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
177 | 180 |
178 // Set the server preference for www.google.com:80. | 181 // Set the server preference for www.google.com:80. |
179 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 182 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
180 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 183 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
181 | 184 |
182 // Set the preference for mail.google.com server. | 185 // Set the preference for mail.google.com server. |
183 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 186 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
184 | 187 |
185 // Set supports_spdy for mail.google.com:80 | 188 // Set supports_spdy for mail.google.com:80 |
186 server_pref_dict1->SetBoolean("supports_spdy", true); | 189 server_pref_dict1->SetBoolean("supports_spdy", true); |
187 | 190 |
188 // Set up alternate_protocol for mail.google.com:80 | 191 // Set up alternate_protocol for mail.google.com:80 to test migration to |
189 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 192 // alternative-service. |
190 alternate_protocol1->SetInteger("port", 444); | 193 base::DictionaryValue* alternate_protocol_dict = new base::DictionaryValue; |
191 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); | 194 alternate_protocol_dict->SetString("protocol_str", "npn-spdy/3.1"); |
192 | 195 alternate_protocol_dict->SetInteger("port", 444); |
193 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", | 196 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", |
194 alternate_protocol1); | 197 alternate_protocol_dict); |
195 | 198 |
196 // Set up ServerNetworkStats for mail.google.com:80. | 199 // Set up ServerNetworkStats for mail.google.com:80. |
197 base::DictionaryValue* stats1 = new base::DictionaryValue; | 200 base::DictionaryValue* stats1 = new base::DictionaryValue; |
198 stats1->SetInteger("srtt", 20); | 201 stats1->SetInteger("srtt", 20); |
199 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); | 202 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); |
200 // Set the server preference for mail.google.com:80. | 203 // Set the server preference for mail.google.com:80. |
201 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 204 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
202 server_pref_dict1); | 205 server_pref_dict1); |
203 | 206 |
204 base::DictionaryValue* http_server_properties_dict = | 207 base::DictionaryValue* http_server_properties_dict = |
(...skipping 17 matching lines...) Expand all Loading... |
222 base::RunLoop().RunUntilIdle(); | 225 base::RunLoop().RunUntilIdle(); |
223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 226 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
224 | 227 |
225 // Verify SupportsSpdy. | 228 // Verify SupportsSpdy. |
226 EXPECT_TRUE( | 229 EXPECT_TRUE( |
227 http_server_props_manager_->SupportsRequestPriority(google_server)); | 230 http_server_props_manager_->SupportsRequestPriority(google_server)); |
228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 231 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 232 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
230 HostPortPair::FromString("foo.google.com:1337"))); | 233 HostPortPair::FromString("foo.google.com:1337"))); |
231 | 234 |
232 // Verify AlternateProtocol. | 235 // Verify alternative service. |
233 AlternativeService alternative_service = | 236 AlternativeService alternative_service = |
234 http_server_props_manager_->GetAlternativeService(google_server); | 237 http_server_props_manager_->GetAlternativeService(google_server); |
| 238 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); |
| 239 EXPECT_EQ("maps.google.com", alternative_service.host); |
235 EXPECT_EQ(443, alternative_service.port); | 240 EXPECT_EQ(443, alternative_service.port); |
236 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); | |
237 alternative_service = | 241 alternative_service = |
238 http_server_props_manager_->GetAlternativeService(mail_server); | 242 http_server_props_manager_->GetAlternativeService(mail_server); |
| 243 EXPECT_EQ(NPN_SPDY_3_1, alternative_service.protocol); |
| 244 EXPECT_EQ("mail.google.com", alternative_service.host); |
239 EXPECT_EQ(444, alternative_service.port); | 245 EXPECT_EQ(444, alternative_service.port); |
240 EXPECT_EQ(NPN_SPDY_3_1, alternative_service.protocol); | |
241 | 246 |
242 // Verify SupportsQuic. | 247 // Verify SupportsQuic. |
243 IPAddressNumber last_address; | 248 IPAddressNumber last_address; |
244 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); | 249 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
245 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); | 250 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); |
246 | 251 |
247 // Verify ServerNetworkStats. | 252 // Verify ServerNetworkStats. |
248 const ServerNetworkStats* stats2 = | 253 const ServerNetworkStats* stats2 = |
249 http_server_props_manager_->GetServerNetworkStats(google_server); | 254 http_server_props_manager_->GetServerNetworkStats(google_server); |
250 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 255 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
251 const ServerNetworkStats* stats3 = | 256 const ServerNetworkStats* stats3 = |
252 http_server_props_manager_->GetServerNetworkStats(mail_server); | 257 http_server_props_manager_->GetServerNetworkStats(mail_server); |
253 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); | 258 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
254 } | 259 } |
255 | 260 |
256 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 261 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
257 ExpectCacheUpdate(); | 262 ExpectCacheUpdate(); |
258 // The prefs are automaticalls updated in the case corruption is detected. | 263 // The prefs are automaticalls updated in the case corruption is detected. |
259 ExpectPrefsUpdate(); | 264 ExpectPrefsUpdate(); |
260 | 265 |
261 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 266 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
262 | 267 |
263 // Set supports_spdy for www.google.com:65536. | 268 // Set supports_spdy for www.google.com:65536. |
264 server_pref_dict->SetBoolean("supports_spdy", true); | 269 server_pref_dict->SetBoolean("supports_spdy", true); |
265 | 270 |
266 // Set up alternate_protocol for www.google.com:65536. | 271 // Set up alternative_service for www.google.com:65536. |
267 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 272 |
268 alternate_protocol->SetInteger("port", 80); | 273 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
269 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 274 alternative_service_dict->SetString("protocol_str", "npn-spdy/3"); |
270 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 275 alternative_service_dict->SetInteger("port", 80); |
271 alternate_protocol); | 276 base::ListValue* alternative_service_list = new base::ListValue; |
| 277 alternative_service_list->Append(alternative_service_dict); |
| 278 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 279 alternative_service_list); |
272 | 280 |
273 // Set up ServerNetworkStats for www.google.com:65536. | 281 // Set up ServerNetworkStats for www.google.com:65536. |
274 base::DictionaryValue* stats = new base::DictionaryValue; | 282 base::DictionaryValue* stats = new base::DictionaryValue; |
275 stats->SetInteger("srtt", 10); | 283 stats->SetInteger("srtt", 10); |
276 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 284 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
277 | 285 |
278 // Set the server preference for www.google.com:65536. | 286 // Set the server preference for www.google.com:65536. |
279 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 287 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
280 servers_dict->SetWithoutPathExpansion("www.google.com:65536", | 288 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
281 server_pref_dict); | 289 server_pref_dict); |
(...skipping 24 matching lines...) Expand all Loading... |
306 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 314 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
307 ExpectCacheUpdate(); | 315 ExpectCacheUpdate(); |
308 // The prefs are automaticalls updated in the case corruption is detected. | 316 // The prefs are automaticalls updated in the case corruption is detected. |
309 ExpectPrefsUpdate(); | 317 ExpectPrefsUpdate(); |
310 | 318 |
311 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 319 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
312 | 320 |
313 // Set supports_spdy for www.google.com:80. | 321 // Set supports_spdy for www.google.com:80. |
314 server_pref_dict->SetBoolean("supports_spdy", true); | 322 server_pref_dict->SetBoolean("supports_spdy", true); |
315 | 323 |
316 // Set up alternate_protocol for www.google.com:80. | 324 // Set up alternative_service for www.google.com:80. |
317 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 325 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
318 alternate_protocol->SetInteger("port", 65536); | 326 alternative_service_dict->SetString("protocol_str", "npn-spdy/3"); |
319 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 327 alternative_service_dict->SetInteger("port", 65536); |
320 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 328 base::ListValue* alternative_service_list = new base::ListValue; |
321 alternate_protocol); | 329 alternative_service_list->Append(alternative_service_dict); |
| 330 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 331 alternative_service_list); |
322 | 332 |
323 // Set the server preference for www.google.com:80. | 333 // Set the server preference for www.google.com:80. |
324 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 334 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
325 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 335 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
326 | 336 |
327 base::DictionaryValue* http_server_properties_dict = | 337 base::DictionaryValue* http_server_properties_dict = |
328 new base::DictionaryValue; | 338 new base::DictionaryValue; |
329 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 339 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
330 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 340 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
331 | 341 |
332 // Set up the pref. | 342 // Set up the pref. |
333 pref_service_.SetManagedPref(kTestHttpServerProperties, | 343 pref_service_.SetManagedPref(kTestHttpServerProperties, |
334 http_server_properties_dict); | 344 http_server_properties_dict); |
335 | 345 |
336 base::RunLoop().RunUntilIdle(); | 346 base::RunLoop().RunUntilIdle(); |
337 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 347 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
338 | 348 |
339 // Verify AlternateProtocol is not set. | 349 // Verify alternative service is not set. |
340 EXPECT_FALSE( | 350 EXPECT_FALSE( |
341 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); | 351 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); |
342 } | 352 } |
343 | 353 |
344 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 354 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
345 ExpectPrefsUpdate(); | 355 ExpectPrefsUpdate(); |
346 | 356 |
347 // Post an update task to the network thread. SetSupportsSpdy calls | 357 // Post an update task to the network thread. SetSupportsSpdy calls |
348 // ScheduleUpdatePrefsOnNetworkThread. | 358 // ScheduleUpdatePrefsOnNetworkThread. |
349 | 359 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 589 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
580 EXPECT_EQ(NULL, stats2); | 590 EXPECT_EQ(NULL, stats2); |
581 | 591 |
582 const SettingsMap& settings_map2_ret = | 592 const SettingsMap& settings_map2_ret = |
583 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 593 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
584 EXPECT_EQ(0U, settings_map2_ret.size()); | 594 EXPECT_EQ(0U, settings_map2_ret.size()); |
585 | 595 |
586 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 596 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
587 } | 597 } |
588 | 598 |
589 // https://crbug.com/444956: Add 200 alternate_protocol servers followed by | 599 // https://crbug.com/444956: Add 200 alternative_service servers followed by |
590 // supports_quic and verify we have read supports_quic from prefs. | 600 // supports_quic and verify we have read supports_quic from prefs. |
591 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 601 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
592 ExpectCacheUpdate(); | 602 ExpectCacheUpdate(); |
593 | 603 |
594 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 604 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
595 | 605 |
596 for (int i = 0; i < 200; ++i) { | 606 for (int i = 0; i < 200; ++i) { |
597 // Set up alternate_protocol for www.google.com:i. | 607 // Set up alternative_service for www.google.com:i. |
598 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 608 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
599 alternate_protocol->SetInteger("port", i); | 609 alternative_service_dict->SetString("protocol_str", "npn-spdy/3"); |
600 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 610 alternative_service_dict->SetString("host", ""); |
| 611 alternative_service_dict->SetInteger("port", i); |
| 612 base::ListValue* alternative_service_list = new base::ListValue; |
| 613 alternative_service_list->Append(alternative_service_dict); |
601 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 614 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
602 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 615 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
603 alternate_protocol); | 616 alternative_service_list); |
604 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), | 617 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), |
605 server_pref_dict); | 618 server_pref_dict); |
606 } | 619 } |
607 | 620 |
608 // Set the preference for mail.google.com server. | 621 // Set the preference for mail.google.com server. |
609 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 622 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
610 | 623 |
611 // Set the server preference for mail.google.com:80. | 624 // Set the server preference for mail.google.com:80. |
612 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 625 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
613 server_pref_dict1); | 626 server_pref_dict1); |
(...skipping 10 matching lines...) Expand all Loading... |
624 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", | 637 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", |
625 supports_quic); | 638 supports_quic); |
626 | 639 |
627 // Set up the pref. | 640 // Set up the pref. |
628 pref_service_.SetManagedPref(kTestHttpServerProperties, | 641 pref_service_.SetManagedPref(kTestHttpServerProperties, |
629 http_server_properties_dict); | 642 http_server_properties_dict); |
630 | 643 |
631 base::RunLoop().RunUntilIdle(); | 644 base::RunLoop().RunUntilIdle(); |
632 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 645 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
633 | 646 |
634 // Verify AlternateProtocol. | 647 // Verify alternative service. |
635 for (int i = 0; i < 200; ++i) { | 648 for (int i = 0; i < 200; ++i) { |
636 std::string server = StringPrintf("www.google.com:%d", i); | 649 std::string server = StringPrintf("www.google.com:%d", i); |
637 AlternativeService alternative_service = | 650 AlternativeService alternative_service = |
638 http_server_props_manager_->GetAlternativeService( | 651 http_server_props_manager_->GetAlternativeService( |
639 HostPortPair::FromString(server)); | 652 HostPortPair::FromString(server)); |
640 EXPECT_EQ(i, alternative_service.port); | 653 EXPECT_EQ(i, alternative_service.port); |
641 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); | 654 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); |
642 } | 655 } |
643 | 656 |
644 // Verify SupportsQuic. | 657 // Verify SupportsQuic. |
645 IPAddressNumber address; | 658 IPAddressNumber address; |
646 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 659 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
647 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); | 660 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); |
648 } | 661 } |
649 | 662 |
650 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 663 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
651 const HostPortPair server_www("www.google.com", 80); | 664 const HostPortPair server_www("www.google.com", 80); |
652 const HostPortPair server_mail("mail.google.com", 80); | 665 const HostPortPair server_mail("mail.google.com", 80); |
653 | 666 |
654 // Set alternate protocol. | 667 // Set alternate protocol. |
655 AlternativeService www_altsvc(NPN_SPDY_3, "www.google.com", 443); | 668 AlternativeService www_altsvc(NPN_SPDY_3, "", 443); |
656 AlternativeService mail_altsvc(NPN_SPDY_3_1, "mail.google.com", 444); | 669 AlternativeService mail_altsvc(NPN_SPDY_3_1, "mail.google.com", 444); |
657 http_server_props_manager_->SetAlternativeService(server_www, www_altsvc, | 670 http_server_props_manager_->SetAlternativeService(server_www, www_altsvc, |
658 1.0); | 671 1.0); |
659 http_server_props_manager_->SetAlternativeService(server_mail, mail_altsvc, | 672 http_server_props_manager_->SetAlternativeService(server_mail, mail_altsvc, |
660 0.2); | 673 0.2); |
661 | 674 |
662 // Set ServerNetworkStats. | 675 // Set ServerNetworkStats. |
663 ServerNetworkStats stats; | 676 ServerNetworkStats stats; |
664 stats.srtt = base::TimeDelta::FromInternalValue(42); | 677 stats.srtt = base::TimeDelta::FromInternalValue(42); |
665 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 678 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); |
666 | 679 |
667 // Set SupportsQuic. | 680 // Set SupportsQuic. |
668 IPAddressNumber actual_address; | 681 IPAddressNumber actual_address; |
669 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 682 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
670 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 683 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
671 | 684 |
672 // Update cache. | 685 // Update cache. |
673 ExpectPrefsUpdate(); | 686 ExpectPrefsUpdate(); |
674 ExpectCacheUpdate(); | 687 ExpectCacheUpdate(); |
675 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 688 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
676 base::RunLoop().RunUntilIdle(); | 689 base::RunLoop().RunUntilIdle(); |
677 | 690 |
678 // Verify preferences. | 691 // Verify preferences. |
679 const char expected_json[] = "{" | 692 const char expected_json[] = |
680 "\"servers\":{" | 693 "{\"servers\":{\"mail.google.com:80\":{\"alternative_service\":[{" |
681 "\"mail.google.com:80\":{" | 694 "\"host\":" |
682 "\"alternate_protocol\":{" | 695 "\"mail.google.com\",\"port\":444,\"probability\":0.2,\"protocol_str\":" |
683 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"" | 696 "\"npn-spdy/" |
684 "}," | 697 "3.1\"}],\"network_stats\":{\"srtt\":42}},\"www.google.com:80\":" |
685 "\"network_stats\":{" | 698 "{\"alternative_service\":[{\"port\":443,\"probability\":1.0," |
686 "\"srtt\":42" | 699 "\"protocol_str\":\"npn-spdy/3\"}]}},\"supports_quic\":" |
687 "}" | 700 "{\"address\":\"127.0.0.1\",\"used_quic\":true},\"version\":3}"; |
688 "}," | |
689 "\"www.google.com:80\":{" | |
690 "\"alternate_protocol\":{" | |
691 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-spdy/3\"" | |
692 "}" | |
693 "}" | |
694 "}," | |
695 "\"supports_quic\":{" | |
696 "\"address\":\"127.0.0.1\",\"used_quic\":true" | |
697 "}," | |
698 "\"version\":3" | |
699 "}"; | |
700 | 701 |
701 const base::Value* http_server_properties = | 702 const base::Value* http_server_properties = |
702 pref_service_.GetUserPref(kTestHttpServerProperties); | 703 pref_service_.GetUserPref(kTestHttpServerProperties); |
703 ASSERT_NE(nullptr, http_server_properties); | 704 ASSERT_NE(nullptr, http_server_properties); |
704 std::string preferences_json; | 705 std::string preferences_json; |
705 EXPECT_TRUE( | 706 EXPECT_TRUE( |
706 base::JSONWriter::Write(http_server_properties, &preferences_json)); | 707 base::JSONWriter::Write(http_server_properties, &preferences_json)); |
707 EXPECT_EQ(expected_json, preferences_json); | 708 EXPECT_EQ(expected_json, preferences_json); |
708 } | 709 } |
709 | 710 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 // Run the task after shutdown, but before deletion. | 776 // Run the task after shutdown, but before deletion. |
776 base::RunLoop().RunUntilIdle(); | 777 base::RunLoop().RunUntilIdle(); |
777 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 778 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
778 http_server_props_manager_.reset(); | 779 http_server_props_manager_.reset(); |
779 base::RunLoop().RunUntilIdle(); | 780 base::RunLoop().RunUntilIdle(); |
780 } | 781 } |
781 | 782 |
782 } // namespace | 783 } // namespace |
783 | 784 |
784 } // namespace net | 785 } // namespace net |
OLD | NEW |