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/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 ServerNetworkStatsMap* server_network_stats_map, | 99 ServerNetworkStatsMap* server_network_stats_map, |
100 QuicServerInfoMap* quic_server_info_map, | 100 QuicServerInfoMap* quic_server_info_map, |
101 const base::Closure& completion)); | 101 const base::Closure& completion)); |
102 | 102 |
103 private: | 103 private: |
104 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 104 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
105 }; | 105 }; |
106 | 106 |
107 } // namespace | 107 } // namespace |
108 | 108 |
109 class HttpServerPropertiesManagerTest : public testing::Test { | 109 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated |
| 110 // to version 4, delete the following code. |
| 111 static const int kHttpServerPropertiesVersions[] = {3, 4}; |
| 112 |
| 113 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { |
110 protected: | 114 protected: |
111 HttpServerPropertiesManagerTest() {} | 115 HttpServerPropertiesManagerTest() {} |
112 | 116 |
113 void SetUp() override { | 117 void SetUp() override { |
114 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); | 118 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); |
115 pref_service_.registry()->RegisterDictionaryPref(kTestHttpServerProperties); | 119 pref_service_.registry()->RegisterDictionaryPref(kTestHttpServerProperties); |
116 http_server_props_manager_.reset( | 120 http_server_props_manager_.reset( |
117 new StrictMock<TestingHttpServerPropertiesManager>( | 121 new StrictMock<TestingHttpServerPropertiesManager>( |
118 &pref_service_, kTestHttpServerProperties, | 122 &pref_service_, kTestHttpServerProperties, |
119 base::ThreadTaskRunnerHandle::Get())); | 123 base::ThreadTaskRunnerHandle::Get())); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 180 |
177 //base::RunLoop loop_; | 181 //base::RunLoop loop_; |
178 TestingPrefServiceSimple pref_service_; | 182 TestingPrefServiceSimple pref_service_; |
179 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; | 183 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; |
180 base::Time one_day_from_now_; | 184 base::Time one_day_from_now_; |
181 | 185 |
182 private: | 186 private: |
183 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); | 187 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); |
184 }; | 188 }; |
185 | 189 |
186 TEST_F(HttpServerPropertiesManagerTest, | 190 INSTANTIATE_TEST_CASE_P(Tests, |
| 191 HttpServerPropertiesManagerTest, |
| 192 ::testing::ValuesIn(kHttpServerPropertiesVersions)); |
| 193 |
| 194 TEST_P(HttpServerPropertiesManagerTest, |
187 SingleUpdateForTwoSpdyServerPrefChanges) { | 195 SingleUpdateForTwoSpdyServerPrefChanges) { |
188 ExpectCacheUpdate(); | 196 ExpectCacheUpdate(); |
189 | 197 |
190 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set | 198 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set |
191 // it twice. Only expect a single cache update. | 199 // it twice. Only expect a single cache update. |
192 | 200 |
193 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 201 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
194 HostPortPair google_server("www.google.com", 80); | 202 HostPortPair google_server("www.google.com", 80); |
195 HostPortPair mail_server("mail.google.com", 80); | 203 HostPortPair mail_server("mail.google.com", 80); |
196 | 204 |
(...skipping 14 matching lines...) Expand all Loading... |
211 alternative_service_list0); | 219 alternative_service_list0); |
212 | 220 |
213 // Set up ServerNetworkStats for www.google.com:80. | 221 // Set up ServerNetworkStats for www.google.com:80. |
214 base::DictionaryValue* stats = new base::DictionaryValue; | 222 base::DictionaryValue* stats = new base::DictionaryValue; |
215 stats->SetInteger("srtt", 10); | 223 stats->SetInteger("srtt", 10); |
216 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 224 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
217 | 225 |
218 // Set the server preference for www.google.com:80. | 226 // Set the server preference for www.google.com:80. |
219 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 227 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
220 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 228 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
| 229 base::ListValue* servers_list = nullptr; |
| 230 if (GetParam() == 4) { |
| 231 servers_list = new base::ListValue; |
| 232 // |servers_list| takes ownership of |servers_dict|. |
| 233 servers_list->AppendIfNotPresent(servers_dict); |
| 234 servers_dict = new base::DictionaryValue; |
| 235 } |
221 | 236 |
222 // Set the preference for mail.google.com server. | 237 // Set the preference for mail.google.com server. |
223 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 238 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
224 | 239 |
225 // Set supports_spdy for mail.google.com:80 | 240 // Set supports_spdy for mail.google.com:80 |
226 server_pref_dict1->SetBoolean("supports_spdy", true); | 241 server_pref_dict1->SetBoolean("supports_spdy", true); |
227 | 242 |
228 // Set up alternative_services for mail.google.com:80. | 243 // Set up alternative_services for mail.google.com:80. |
229 base::DictionaryValue* alternative_service_dict2 = new base::DictionaryValue; | 244 base::DictionaryValue* alternative_service_dict2 = new base::DictionaryValue; |
230 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); | 245 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); |
231 alternative_service_dict2->SetInteger("port", 444); | 246 alternative_service_dict2->SetInteger("port", 444); |
232 base::ListValue* alternative_service_list1 = new base::ListValue; | 247 base::ListValue* alternative_service_list1 = new base::ListValue; |
233 alternative_service_list1->Append(alternative_service_dict2); | 248 alternative_service_list1->Append(alternative_service_dict2); |
234 server_pref_dict1->SetWithoutPathExpansion("alternative_service", | 249 server_pref_dict1->SetWithoutPathExpansion("alternative_service", |
235 alternative_service_list1); | 250 alternative_service_list1); |
236 | 251 |
237 // Set up ServerNetworkStats for mail.google.com:80. | 252 // Set up ServerNetworkStats for mail.google.com:80 and it is the MRU server. |
238 base::DictionaryValue* stats1 = new base::DictionaryValue; | 253 base::DictionaryValue* stats1 = new base::DictionaryValue; |
239 stats1->SetInteger("srtt", 20); | 254 stats1->SetInteger("srtt", 20); |
240 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); | 255 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); |
241 // Set the server preference for mail.google.com:80. | 256 // Set the server preference for mail.google.com:80. |
242 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 257 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
243 server_pref_dict1); | 258 server_pref_dict1); |
244 | |
245 base::DictionaryValue* http_server_properties_dict = | 259 base::DictionaryValue* http_server_properties_dict = |
246 new base::DictionaryValue; | 260 new base::DictionaryValue; |
247 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 261 if (GetParam() == 4) { |
248 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 262 // |servers_list| takes ownership of |servers_dict|. |
| 263 servers_list->AppendIfNotPresent(servers_dict); |
| 264 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 265 http_server_properties_dict->SetWithoutPathExpansion("servers", |
| 266 servers_list); |
| 267 } else { |
| 268 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, |
| 269 GetParam()); |
| 270 http_server_properties_dict->SetWithoutPathExpansion("servers", |
| 271 servers_dict); |
| 272 } |
249 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 273 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
250 supports_quic->SetBoolean("used_quic", true); | 274 supports_quic->SetBoolean("used_quic", true); |
251 supports_quic->SetString("address", "127.0.0.1"); | 275 supports_quic->SetString("address", "127.0.0.1"); |
252 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", | 276 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", |
253 supports_quic); | 277 supports_quic); |
254 | 278 |
255 // Set quic_server_info for www.google.com:80 and mail.google.com:80. | 279 // Set quic_server_info for www.google.com:80 and mail.google.com:80. |
256 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; | 280 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; |
257 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; | 281 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; |
258 std::string quic_server_info1("quic_server_info1"); | 282 std::string quic_server_info1("quic_server_info1"); |
(...skipping 26 matching lines...) Expand all Loading... |
285 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 309 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
286 | 310 |
287 // Verify SupportsSpdy. | 311 // Verify SupportsSpdy. |
288 EXPECT_TRUE( | 312 EXPECT_TRUE( |
289 http_server_props_manager_->SupportsRequestPriority(google_server)); | 313 http_server_props_manager_->SupportsRequestPriority(google_server)); |
290 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 314 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
291 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 315 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
292 HostPortPair::FromString("foo.google.com:1337"))); | 316 HostPortPair::FromString("foo.google.com:1337"))); |
293 | 317 |
294 // Verify alternative service. | 318 // Verify alternative service. |
295 const AlternativeServiceMap& map = | 319 if (GetParam() == 4) { |
296 http_server_props_manager_->alternative_service_map(); | 320 const AlternativeServiceMap& map = |
297 ASSERT_EQ(2u, map.size()); | 321 http_server_props_manager_->alternative_service_map(); |
298 AlternativeServiceMap::const_iterator map_it = map.begin(); | 322 ASSERT_EQ(2u, map.size()); |
299 EXPECT_EQ("www.google.com", map_it->first.host()); | 323 |
300 ASSERT_EQ(2u, map_it->second.size()); | 324 AlternativeServiceMap::const_iterator map_it = map.begin(); |
301 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); | 325 EXPECT_EQ("mail.google.com", map_it->first.host()); |
302 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 326 ASSERT_EQ(1u, map_it->second.size()); |
303 EXPECT_EQ(443, map_it->second[0].alternative_service.port); | 327 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); |
304 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); | 328 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
305 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); | 329 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
306 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); | 330 ++map_it; |
307 ++map_it; | 331 EXPECT_EQ("www.google.com", map_it->first.host()); |
308 EXPECT_EQ("mail.google.com", map_it->first.host()); | 332 ASSERT_EQ(2u, map_it->second.size()); |
309 ASSERT_EQ(1u, map_it->second.size()); | 333 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); |
310 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); | 334 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
311 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 335 EXPECT_EQ(443, map_it->second[0].alternative_service.port); |
312 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 336 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); |
| 337 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); |
| 338 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); |
| 339 } else { |
| 340 const AlternativeServiceMap& map = |
| 341 http_server_props_manager_->alternative_service_map(); |
| 342 ASSERT_EQ(2u, map.size()); |
| 343 AlternativeServiceMap::const_iterator map_it = map.begin(); |
| 344 EXPECT_EQ("www.google.com", map_it->first.host()); |
| 345 ASSERT_EQ(2u, map_it->second.size()); |
| 346 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); |
| 347 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
| 348 EXPECT_EQ(443, map_it->second[0].alternative_service.port); |
| 349 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); |
| 350 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); |
| 351 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); |
| 352 ++map_it; |
| 353 EXPECT_EQ("mail.google.com", map_it->first.host()); |
| 354 ASSERT_EQ(1u, map_it->second.size()); |
| 355 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); |
| 356 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
| 357 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
| 358 } |
313 | 359 |
314 // Verify SupportsQuic. | 360 // Verify SupportsQuic. |
315 IPAddressNumber last_address; | 361 IPAddressNumber last_address; |
316 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); | 362 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
317 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); | 363 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); |
318 | 364 |
319 // Verify ServerNetworkStats. | 365 // Verify ServerNetworkStats. |
320 const ServerNetworkStats* stats2 = | 366 const ServerNetworkStats* stats2 = |
321 http_server_props_manager_->GetServerNetworkStats(google_server); | 367 http_server_props_manager_->GetServerNetworkStats(google_server); |
322 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 368 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
323 const ServerNetworkStats* stats3 = | 369 const ServerNetworkStats* stats3 = |
324 http_server_props_manager_->GetServerNetworkStats(mail_server); | 370 http_server_props_manager_->GetServerNetworkStats(mail_server); |
325 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); | 371 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
326 | 372 |
327 // Verify QuicServerInfo. | 373 // Verify QuicServerInfo. |
328 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 374 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
329 google_quic_server_id)); | 375 google_quic_server_id)); |
330 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( | 376 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( |
331 mail_quic_server_id)); | 377 mail_quic_server_id)); |
332 } | 378 } |
333 | 379 |
334 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 380 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
335 ExpectCacheUpdate(); | 381 ExpectCacheUpdate(); |
336 // The prefs are automaticalls updated in the case corruption is detected. | 382 // The prefs are automaticalls updated in the case corruption is detected. |
337 ExpectPrefsUpdate(); | 383 ExpectPrefsUpdate(); |
338 ExpectScheduleUpdatePrefsOnNetworkThread(); | 384 ExpectScheduleUpdatePrefsOnNetworkThread(); |
339 | 385 |
340 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 386 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
341 | 387 |
342 // Set supports_spdy for www.google.com:65536. | 388 // Set supports_spdy for www.google.com:65536. |
343 server_pref_dict->SetBoolean("supports_spdy", true); | 389 server_pref_dict->SetBoolean("supports_spdy", true); |
344 | 390 |
345 // Set up alternative_service for www.google.com:65536. | 391 // Set up alternative_service for www.google.com:65536. |
346 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; | 392 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
347 alternative_service_dict->SetString("protocol_str", "npn-h2"); | 393 alternative_service_dict->SetString("protocol_str", "npn-h2"); |
348 alternative_service_dict->SetInteger("port", 80); | 394 alternative_service_dict->SetInteger("port", 80); |
349 base::ListValue* alternative_service_list = new base::ListValue; | 395 base::ListValue* alternative_service_list = new base::ListValue; |
350 alternative_service_list->Append(alternative_service_dict); | 396 alternative_service_list->Append(alternative_service_dict); |
351 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 397 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
352 alternative_service_list); | 398 alternative_service_list); |
353 | 399 |
354 // Set up ServerNetworkStats for www.google.com:65536. | 400 // Set up ServerNetworkStats for www.google.com:65536. |
355 base::DictionaryValue* stats = new base::DictionaryValue; | 401 base::DictionaryValue* stats = new base::DictionaryValue; |
356 stats->SetInteger("srtt", 10); | 402 stats->SetInteger("srtt", 10); |
357 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 403 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
358 | 404 |
359 // Set the server preference for www.google.com:65536. | 405 // Set the server preference for www.google.com:65536. |
360 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 406 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
361 servers_dict->SetWithoutPathExpansion("www.google.com:65536", | 407 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
362 server_pref_dict); | 408 server_pref_dict); |
| 409 base::DictionaryValue* http_server_properties_dict = |
| 410 new base::DictionaryValue; |
| 411 if (GetParam() == 4) { |
| 412 base::ListValue* servers_list = new base::ListValue; |
| 413 // |servers_list| takes ownership of |servers_dict|. |
| 414 servers_list->AppendIfNotPresent(servers_dict); |
| 415 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 416 http_server_properties_dict->SetWithoutPathExpansion("servers", |
| 417 servers_list); |
| 418 } else { |
| 419 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, |
| 420 GetParam()); |
| 421 http_server_properties_dict->SetWithoutPathExpansion("servers", |
| 422 servers_dict); |
| 423 } |
363 | 424 |
364 // Set quic_server_info for www.google.com:65536. | 425 // Set quic_server_info for www.google.com:65536. |
365 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; | 426 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; |
366 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; | 427 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; |
367 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", | 428 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", |
368 "quic_server_info1"); | 429 "quic_server_info1"); |
369 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536", | 430 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536", |
370 quic_server_pref_dict1); | 431 quic_server_pref_dict1); |
371 | 432 |
372 base::DictionaryValue* http_server_properties_dict = | |
373 new base::DictionaryValue; | |
374 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | |
375 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | |
376 http_server_properties_dict->SetWithoutPathExpansion("quic_servers", | 433 http_server_properties_dict->SetWithoutPathExpansion("quic_servers", |
377 quic_servers_dict); | 434 quic_servers_dict); |
378 | 435 |
379 // Set up the pref. | 436 // Set up the pref. |
380 pref_service_.SetManagedPref(kTestHttpServerProperties, | 437 pref_service_.SetManagedPref(kTestHttpServerProperties, |
381 http_server_properties_dict); | 438 http_server_properties_dict); |
382 | 439 |
383 base::RunLoop().RunUntilIdle(); | 440 base::RunLoop().RunUntilIdle(); |
384 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 441 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
385 | 442 |
386 // Verify that nothing is set. | 443 // Verify that nothing is set. |
387 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 444 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
388 HostPortPair::FromString("www.google.com:65536"))); | 445 HostPortPair::FromString("www.google.com:65536"))); |
389 EXPECT_FALSE( | 446 EXPECT_FALSE( |
390 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); | 447 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); |
391 const ServerNetworkStats* stats1 = | 448 const ServerNetworkStats* stats1 = |
392 http_server_props_manager_->GetServerNetworkStats( | 449 http_server_props_manager_->GetServerNetworkStats( |
393 HostPortPair::FromString("www.google.com:65536")); | 450 HostPortPair::FromString("www.google.com:65536")); |
394 EXPECT_EQ(NULL, stats1); | 451 EXPECT_EQ(nullptr, stats1); |
395 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); | 452 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); |
396 } | 453 } |
397 | 454 |
398 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 455 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
399 ExpectCacheUpdate(); | 456 ExpectCacheUpdate(); |
400 // The prefs are automaticalls updated in the case corruption is detected. | 457 // The prefs are automaticalls updated in the case corruption is detected. |
401 ExpectPrefsUpdate(); | 458 ExpectPrefsUpdate(); |
402 ExpectScheduleUpdatePrefsOnNetworkThread(); | 459 ExpectScheduleUpdatePrefsOnNetworkThread(); |
403 | 460 |
404 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 461 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
405 | 462 |
406 // Set supports_spdy for www.google.com:80. | 463 // Set supports_spdy for www.google.com:80. |
407 server_pref_dict->SetBoolean("supports_spdy", true); | 464 server_pref_dict->SetBoolean("supports_spdy", true); |
408 | 465 |
409 // Set up alternative_service for www.google.com:80. | 466 // Set up alternative_service for www.google.com:80. |
410 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; | 467 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
411 alternative_service_dict->SetString("protocol_str", "npn-h2"); | 468 alternative_service_dict->SetString("protocol_str", "npn-h2"); |
412 alternative_service_dict->SetInteger("port", 65536); | 469 alternative_service_dict->SetInteger("port", 65536); |
413 base::ListValue* alternative_service_list = new base::ListValue; | 470 base::ListValue* alternative_service_list = new base::ListValue; |
414 alternative_service_list->Append(alternative_service_dict); | 471 alternative_service_list->Append(alternative_service_dict); |
415 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 472 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
416 alternative_service_list); | 473 alternative_service_list); |
417 | 474 |
418 // Set the server preference for www.google.com:80. | 475 // Set the server preference for www.google.com:80. |
419 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 476 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
420 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 477 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
421 | |
422 base::DictionaryValue* http_server_properties_dict = | 478 base::DictionaryValue* http_server_properties_dict = |
423 new base::DictionaryValue; | 479 new base::DictionaryValue; |
424 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 480 if (GetParam() == 4) { |
425 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 481 base::ListValue* servers_list = new base::ListValue; |
| 482 // |servers_list| takes ownership of |servers_dict|. |
| 483 servers_list->AppendIfNotPresent(servers_dict); |
| 484 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 485 http_server_properties_dict->SetWithoutPathExpansion("servers", |
| 486 servers_list); |
| 487 } else { |
| 488 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, |
| 489 GetParam()); |
| 490 http_server_properties_dict->SetWithoutPathExpansion("servers", |
| 491 servers_dict); |
| 492 } |
426 | 493 |
427 // Set up the pref. | 494 // Set up the pref. |
428 pref_service_.SetManagedPref(kTestHttpServerProperties, | 495 pref_service_.SetManagedPref(kTestHttpServerProperties, |
429 http_server_properties_dict); | 496 http_server_properties_dict); |
430 | 497 |
431 base::RunLoop().RunUntilIdle(); | 498 base::RunLoop().RunUntilIdle(); |
432 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 499 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
433 | 500 |
434 // Verify alternative service is not set. | 501 // Verify alternative service is not set. |
435 EXPECT_FALSE( | 502 EXPECT_FALSE( |
436 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); | 503 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); |
437 } | 504 } |
438 | 505 |
439 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 506 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { |
440 ExpectPrefsUpdate(); | 507 ExpectPrefsUpdate(); |
441 ExpectScheduleUpdatePrefsOnNetworkThread(); | 508 ExpectScheduleUpdatePrefsOnNetworkThread(); |
442 | 509 |
443 // Post an update task to the network thread. SetSupportsSpdy calls | 510 // Post an update task to the network thread. SetSupportsSpdy calls |
444 // ScheduleUpdatePrefsOnNetworkThread. | 511 // ScheduleUpdatePrefsOnNetworkThread. |
445 | 512 |
446 // Add mail.google.com:443 as a supporting spdy server. | 513 // Add mail.google.com:443 as a supporting spdy server. |
447 HostPortPair spdy_server_mail("mail.google.com", 443); | 514 HostPortPair spdy_server_mail("mail.google.com", 443); |
448 EXPECT_FALSE( | 515 EXPECT_FALSE( |
449 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 516 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
450 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 517 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
451 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 518 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
452 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 519 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
453 | 520 |
454 // Run the task. | 521 // Run the task. |
455 base::RunLoop().RunUntilIdle(); | 522 base::RunLoop().RunUntilIdle(); |
456 | 523 |
457 EXPECT_TRUE( | 524 EXPECT_TRUE( |
458 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 525 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
459 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 526 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
460 } | 527 } |
461 | 528 |
462 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { | 529 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) { |
463 ExpectPrefsUpdate(); | 530 ExpectPrefsUpdate(); |
464 ExpectScheduleUpdatePrefsOnNetworkThread(); | 531 ExpectScheduleUpdatePrefsOnNetworkThread(); |
465 | 532 |
466 // Add SpdySetting for mail.google.com:443. | 533 // Add SpdySetting for mail.google.com:443. |
467 HostPortPair spdy_server_mail("mail.google.com", 443); | 534 HostPortPair spdy_server_mail("mail.google.com", 443); |
468 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 535 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
469 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 536 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
470 const uint32_t value1 = 31337; | 537 const uint32_t value1 = 31337; |
471 http_server_props_manager_->SetSpdySetting( | 538 http_server_props_manager_->SetSpdySetting( |
472 spdy_server_mail, id1, flags1, value1); | 539 spdy_server_mail, id1, flags1, value1); |
473 | 540 |
474 // Run the task. | 541 // Run the task. |
475 base::RunLoop().RunUntilIdle(); | 542 base::RunLoop().RunUntilIdle(); |
476 | 543 |
477 const SettingsMap& settings_map1_ret = | 544 const SettingsMap& settings_map1_ret = |
478 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 545 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
479 ASSERT_EQ(1U, settings_map1_ret.size()); | 546 ASSERT_EQ(1U, settings_map1_ret.size()); |
480 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 547 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
481 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 548 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
482 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 549 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
483 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 550 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
484 EXPECT_EQ(value1, flags_and_value1_ret.second); | 551 EXPECT_EQ(value1, flags_and_value1_ret.second); |
485 | 552 |
486 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 553 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
487 } | 554 } |
488 | 555 |
489 TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { | 556 TEST_P(HttpServerPropertiesManagerTest, ClearSpdySetting) { |
490 ExpectPrefsUpdateRepeatedly(); | 557 ExpectPrefsUpdateRepeatedly(); |
491 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 558 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
492 | 559 |
493 // Add SpdySetting for mail.google.com:443. | 560 // Add SpdySetting for mail.google.com:443. |
494 HostPortPair spdy_server_mail("mail.google.com", 443); | 561 HostPortPair spdy_server_mail("mail.google.com", 443); |
495 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 562 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
496 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 563 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
497 const uint32_t value1 = 31337; | 564 const uint32_t value1 = 31337; |
498 http_server_props_manager_->SetSpdySetting( | 565 http_server_props_manager_->SetSpdySetting( |
499 spdy_server_mail, id1, flags1, value1); | 566 spdy_server_mail, id1, flags1, value1); |
(...skipping 18 matching lines...) Expand all Loading... |
518 | 585 |
519 // Verify that there are no entries in the settings map for | 586 // Verify that there are no entries in the settings map for |
520 // mail.google.com:443. | 587 // mail.google.com:443. |
521 const SettingsMap& settings_map2_ret = | 588 const SettingsMap& settings_map2_ret = |
522 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 589 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
523 ASSERT_EQ(0U, settings_map2_ret.size()); | 590 ASSERT_EQ(0U, settings_map2_ret.size()); |
524 | 591 |
525 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 592 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
526 } | 593 } |
527 | 594 |
528 TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { | 595 TEST_P(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { |
529 ExpectPrefsUpdateRepeatedly(); | 596 ExpectPrefsUpdateRepeatedly(); |
530 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 597 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
531 | 598 |
532 // Add SpdySetting for mail.google.com:443. | 599 // Add SpdySetting for mail.google.com:443. |
533 HostPortPair spdy_server_mail("mail.google.com", 443); | 600 HostPortPair spdy_server_mail("mail.google.com", 443); |
534 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 601 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
535 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 602 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
536 const uint32_t value1 = 31337; | 603 const uint32_t value1 = 31337; |
537 http_server_props_manager_->SetSpdySetting( | 604 http_server_props_manager_->SetSpdySetting( |
538 spdy_server_mail, id1, flags1, value1); | 605 spdy_server_mail, id1, flags1, value1); |
(...skipping 17 matching lines...) Expand all Loading... |
556 base::RunLoop().RunUntilIdle(); | 623 base::RunLoop().RunUntilIdle(); |
557 | 624 |
558 // Verify that there are no entries in the settings map. | 625 // Verify that there are no entries in the settings map. |
559 const SpdySettingsMap& spdy_settings_map2_ret = | 626 const SpdySettingsMap& spdy_settings_map2_ret = |
560 http_server_props_manager_->spdy_settings_map(); | 627 http_server_props_manager_->spdy_settings_map(); |
561 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); | 628 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); |
562 | 629 |
563 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 630 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
564 } | 631 } |
565 | 632 |
566 TEST_F(HttpServerPropertiesManagerTest, GetAlternativeServices) { | 633 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { |
567 ExpectPrefsUpdate(); | 634 ExpectPrefsUpdate(); |
568 ExpectScheduleUpdatePrefsOnNetworkThread(); | 635 ExpectScheduleUpdatePrefsOnNetworkThread(); |
569 | 636 |
570 HostPortPair spdy_server_mail("mail.google.com", 80); | 637 HostPortPair spdy_server_mail("mail.google.com", 80); |
571 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 638 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
572 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", | 639 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", |
573 443); | 640 443); |
574 http_server_props_manager_->SetAlternativeService( | 641 http_server_props_manager_->SetAlternativeService( |
575 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 642 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); |
576 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 643 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
577 http_server_props_manager_->SetAlternativeService( | 644 http_server_props_manager_->SetAlternativeService( |
578 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 645 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); |
579 | 646 |
580 // Run the task. | 647 // Run the task. |
581 base::RunLoop().RunUntilIdle(); | 648 base::RunLoop().RunUntilIdle(); |
582 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 649 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
583 | 650 |
584 AlternativeServiceVector alternative_service_vector = | 651 AlternativeServiceVector alternative_service_vector = |
585 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); | 652 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); |
586 ASSERT_EQ(1u, alternative_service_vector.size()); | 653 ASSERT_EQ(1u, alternative_service_vector.size()); |
587 EXPECT_EQ(alternative_service, alternative_service_vector[0]); | 654 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
588 } | 655 } |
589 | 656 |
590 TEST_F(HttpServerPropertiesManagerTest, SetAlternativeServices) { | 657 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { |
591 ExpectPrefsUpdate(); | 658 ExpectPrefsUpdate(); |
592 ExpectScheduleUpdatePrefsOnNetworkThread(); | 659 ExpectScheduleUpdatePrefsOnNetworkThread(); |
593 | 660 |
594 HostPortPair spdy_server_mail("mail.google.com", 80); | 661 HostPortPair spdy_server_mail("mail.google.com", 80); |
595 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 662 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
596 AlternativeServiceInfoVector alternative_service_info_vector; | 663 AlternativeServiceInfoVector alternative_service_info_vector; |
597 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", | 664 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", |
598 443); | 665 443); |
599 alternative_service_info_vector.push_back( | 666 alternative_service_info_vector.push_back( |
600 AlternativeServiceInfo(alternative_service1, 1.0, one_day_from_now_)); | 667 AlternativeServiceInfo(alternative_service1, 1.0, one_day_from_now_)); |
(...skipping 10 matching lines...) Expand all Loading... |
611 base::RunLoop().RunUntilIdle(); | 678 base::RunLoop().RunUntilIdle(); |
612 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 679 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
613 | 680 |
614 AlternativeServiceVector alternative_service_vector = | 681 AlternativeServiceVector alternative_service_vector = |
615 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); | 682 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); |
616 ASSERT_EQ(2u, alternative_service_vector.size()); | 683 ASSERT_EQ(2u, alternative_service_vector.size()); |
617 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 684 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
618 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); | 685 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
619 } | 686 } |
620 | 687 |
621 TEST_F(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { | 688 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { |
622 HostPortPair spdy_server_mail("mail.google.com", 80); | 689 HostPortPair spdy_server_mail("mail.google.com", 80); |
623 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 690 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
624 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", | 691 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", |
625 443); | 692 443); |
626 http_server_props_manager_->SetAlternativeServices( | 693 http_server_props_manager_->SetAlternativeServices( |
627 spdy_server_mail, AlternativeServiceInfoVector()); | 694 spdy_server_mail, AlternativeServiceInfoVector()); |
628 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. | 695 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. |
629 | 696 |
630 // Run the task. | 697 // Run the task. |
631 base::RunLoop().RunUntilIdle(); | 698 base::RunLoop().RunUntilIdle(); |
632 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 699 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
633 | 700 |
634 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 701 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
635 } | 702 } |
636 | 703 |
637 TEST_F(HttpServerPropertiesManagerTest, ClearAlternativeServices) { | 704 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) { |
638 ExpectPrefsUpdate(); | 705 ExpectPrefsUpdate(); |
639 ExpectScheduleUpdatePrefsOnNetworkThread(); | 706 ExpectScheduleUpdatePrefsOnNetworkThread(); |
640 | 707 |
641 HostPortPair spdy_server_mail("mail.google.com", 80); | 708 HostPortPair spdy_server_mail("mail.google.com", 80); |
642 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 709 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
643 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); | 710 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); |
644 http_server_props_manager_->SetAlternativeService( | 711 http_server_props_manager_->SetAlternativeService( |
645 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 712 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); |
646 ExpectScheduleUpdatePrefsOnNetworkThread(); | 713 ExpectScheduleUpdatePrefsOnNetworkThread(); |
647 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); | 714 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); |
648 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 715 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
649 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); | 716 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); |
650 | 717 |
651 // Run the task. | 718 // Run the task. |
652 base::RunLoop().RunUntilIdle(); | 719 base::RunLoop().RunUntilIdle(); |
653 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 720 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
654 | 721 |
655 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 722 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
656 } | 723 } |
657 | 724 |
658 TEST_F(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { | 725 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { |
659 ExpectPrefsUpdate(); | 726 ExpectPrefsUpdate(); |
660 | 727 |
661 HostPortPair spdy_server_mail("mail.google.com", 80); | 728 HostPortPair spdy_server_mail("mail.google.com", 80); |
662 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 729 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
663 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); | 730 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); |
664 | 731 |
665 ExpectScheduleUpdatePrefsOnNetworkThread(); | 732 ExpectScheduleUpdatePrefsOnNetworkThread(); |
666 http_server_props_manager_->SetAlternativeService( | 733 http_server_props_manager_->SetAlternativeService( |
667 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 734 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); |
668 | 735 |
(...skipping 25 matching lines...) Expand all Loading... |
694 // Run the task. | 761 // Run the task. |
695 base::RunLoop().RunUntilIdle(); | 762 base::RunLoop().RunUntilIdle(); |
696 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 763 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
697 | 764 |
698 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( | 765 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( |
699 alternative_service)); | 766 alternative_service)); |
700 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( | 767 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( |
701 alternative_service)); | 768 alternative_service)); |
702 } | 769 } |
703 | 770 |
704 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 771 TEST_P(HttpServerPropertiesManagerTest, SupportsQuic) { |
705 ExpectPrefsUpdate(); | 772 ExpectPrefsUpdate(); |
706 ExpectScheduleUpdatePrefsOnNetworkThread(); | 773 ExpectScheduleUpdatePrefsOnNetworkThread(); |
707 | 774 |
708 IPAddressNumber address; | 775 IPAddressNumber address; |
709 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); | 776 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
710 | 777 |
711 IPAddressNumber actual_address; | 778 IPAddressNumber actual_address; |
712 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 779 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
713 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 780 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
714 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 781 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
715 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 782 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
716 | 783 |
717 // Run the task. | 784 // Run the task. |
718 base::RunLoop().RunUntilIdle(); | 785 base::RunLoop().RunUntilIdle(); |
719 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 786 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
720 | 787 |
721 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 788 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
722 EXPECT_EQ(actual_address, address); | 789 EXPECT_EQ(actual_address, address); |
723 } | 790 } |
724 | 791 |
725 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { | 792 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) { |
726 ExpectPrefsUpdate(); | 793 ExpectPrefsUpdate(); |
727 ExpectScheduleUpdatePrefsOnNetworkThread(); | 794 ExpectScheduleUpdatePrefsOnNetworkThread(); |
728 | 795 |
729 HostPortPair mail_server("mail.google.com", 80); | 796 HostPortPair mail_server("mail.google.com", 80); |
730 const ServerNetworkStats* stats = | 797 const ServerNetworkStats* stats = |
731 http_server_props_manager_->GetServerNetworkStats(mail_server); | 798 http_server_props_manager_->GetServerNetworkStats(mail_server); |
732 EXPECT_EQ(NULL, stats); | 799 EXPECT_EQ(nullptr, stats); |
733 ServerNetworkStats stats1; | 800 ServerNetworkStats stats1; |
734 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 801 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
735 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); | 802 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); |
736 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 803 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
737 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); | 804 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); |
738 | 805 |
739 // Run the task. | 806 // Run the task. |
740 base::RunLoop().RunUntilIdle(); | 807 base::RunLoop().RunUntilIdle(); |
741 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 808 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
742 | 809 |
743 const ServerNetworkStats* stats2 = | 810 const ServerNetworkStats* stats2 = |
744 http_server_props_manager_->GetServerNetworkStats(mail_server); | 811 http_server_props_manager_->GetServerNetworkStats(mail_server); |
745 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 812 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
746 } | 813 } |
747 | 814 |
748 TEST_F(HttpServerPropertiesManagerTest, QuicServerInfo) { | 815 TEST_P(HttpServerPropertiesManagerTest, QuicServerInfo) { |
749 ExpectPrefsUpdate(); | 816 ExpectPrefsUpdate(); |
750 ExpectScheduleUpdatePrefsOnNetworkThread(); | 817 ExpectScheduleUpdatePrefsOnNetworkThread(); |
751 | 818 |
752 QuicServerId mail_quic_server_id("mail.google.com", 80); | 819 QuicServerId mail_quic_server_id("mail.google.com", 80); |
753 EXPECT_EQ(nullptr, | 820 EXPECT_EQ(nullptr, |
754 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); | 821 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); |
755 std::string quic_server_info1("quic_server_info1"); | 822 std::string quic_server_info1("quic_server_info1"); |
756 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 823 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
757 quic_server_info1); | 824 quic_server_info1); |
758 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 825 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
759 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 826 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
760 quic_server_info1); | 827 quic_server_info1); |
761 | 828 |
762 // Run the task. | 829 // Run the task. |
763 base::RunLoop().RunUntilIdle(); | 830 base::RunLoop().RunUntilIdle(); |
764 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 831 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
765 | 832 |
766 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 833 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
767 mail_quic_server_id)); | 834 mail_quic_server_id)); |
768 } | 835 } |
769 | 836 |
770 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 837 TEST_P(HttpServerPropertiesManagerTest, Clear) { |
771 ExpectPrefsUpdate(); | 838 ExpectPrefsUpdate(); |
772 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 839 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
773 | 840 |
774 HostPortPair spdy_server_mail("mail.google.com", 443); | 841 HostPortPair spdy_server_mail("mail.google.com", 443); |
775 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 842 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
776 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); | 843 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); |
777 http_server_props_manager_->SetAlternativeService( | 844 http_server_props_manager_->SetAlternativeService( |
778 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 845 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); |
779 IPAddressNumber actual_address; | 846 IPAddressNumber actual_address; |
780 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 847 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 // Clear http server data, time out if we do not get a completion callback. | 893 // Clear http server data, time out if we do not get a completion callback. |
827 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); | 894 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); |
828 base::RunLoop().Run(); | 895 base::RunLoop().Run(); |
829 | 896 |
830 EXPECT_FALSE( | 897 EXPECT_FALSE( |
831 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 898 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
832 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 899 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
833 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); | 900 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
834 const ServerNetworkStats* stats2 = | 901 const ServerNetworkStats* stats2 = |
835 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 902 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
836 EXPECT_EQ(NULL, stats2); | 903 EXPECT_EQ(nullptr, stats2); |
837 EXPECT_EQ(nullptr, | 904 EXPECT_EQ(nullptr, |
838 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); | 905 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); |
839 | 906 |
840 const SettingsMap& settings_map2_ret = | 907 const SettingsMap& settings_map2_ret = |
841 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 908 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
842 EXPECT_EQ(0U, settings_map2_ret.size()); | 909 EXPECT_EQ(0U, settings_map2_ret.size()); |
843 | 910 |
844 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 911 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
845 } | 912 } |
846 | 913 |
847 // https://crbug.com/444956: Add 200 alternative_service servers followed by | 914 // https://crbug.com/444956: Add 200 alternative_service servers followed by |
848 // supports_quic and verify we have read supports_quic from prefs. | 915 // supports_quic and verify we have read supports_quic from prefs. |
849 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 916 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
850 ExpectCacheUpdate(); | 917 ExpectCacheUpdate(); |
851 | 918 |
852 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 919 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 920 base::ListValue* servers_list = nullptr; |
| 921 if (GetParam() == 4) |
| 922 servers_list = new base::ListValue; |
853 | 923 |
854 for (int i = 0; i < 200; ++i) { | 924 for (int i = 0; i < 200; ++i) { |
855 // Set up alternative_service for www.google.com:i. | 925 // Set up alternative_service for www.google.com:i. |
856 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; | 926 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
857 alternative_service_dict->SetString("protocol_str", "quic"); | 927 alternative_service_dict->SetString("protocol_str", "quic"); |
858 alternative_service_dict->SetInteger("port", i); | 928 alternative_service_dict->SetInteger("port", i); |
859 base::ListValue* alternative_service_list = new base::ListValue; | 929 base::ListValue* alternative_service_list = new base::ListValue; |
860 alternative_service_list->Append(alternative_service_dict); | 930 alternative_service_list->Append(alternative_service_dict); |
861 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 931 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
862 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 932 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
863 alternative_service_list); | 933 alternative_service_list); |
864 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), | 934 if (GetParam() == 4) { |
865 server_pref_dict); | 935 servers_dict->SetWithoutPathExpansion( |
| 936 StringPrintf("www.google.com:%d", i), server_pref_dict); |
| 937 // |servers_list| takes ownership of |servers_dict|. |
| 938 servers_list->AppendIfNotPresent(servers_dict); |
| 939 servers_dict = new base::DictionaryValue; |
| 940 } else { |
| 941 servers_dict->SetWithoutPathExpansion( |
| 942 StringPrintf("www.google.com:%d", i), server_pref_dict); |
| 943 } |
866 } | 944 } |
867 | 945 |
868 // Set the preference for mail.google.com server. | 946 // Set the preference for mail.google.com server. |
869 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 947 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
870 | 948 |
871 // Set the server preference for mail.google.com:80. | 949 // Set the server preference for mail.google.com:80. |
872 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 950 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
873 server_pref_dict1); | 951 server_pref_dict1); |
874 | |
875 base::DictionaryValue* http_server_properties_dict = | 952 base::DictionaryValue* http_server_properties_dict = |
876 new base::DictionaryValue; | 953 new base::DictionaryValue; |
877 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 954 if (GetParam() == 4) { |
878 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 955 // |servers_list| takes ownership of |servers_dict|. |
| 956 servers_list->AppendIfNotPresent(servers_dict); |
| 957 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 958 http_server_properties_dict->SetWithoutPathExpansion("servers", |
| 959 servers_list); |
| 960 } else { |
| 961 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, |
| 962 GetParam()); |
| 963 http_server_properties_dict->SetWithoutPathExpansion("servers", |
| 964 servers_dict); |
| 965 } |
879 | 966 |
880 // Set up SupportsQuic for 127.0.0.1 | 967 // Set up SupportsQuic for 127.0.0.1 |
881 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 968 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
882 supports_quic->SetBoolean("used_quic", true); | 969 supports_quic->SetBoolean("used_quic", true); |
883 supports_quic->SetString("address", "127.0.0.1"); | 970 supports_quic->SetString("address", "127.0.0.1"); |
884 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", | 971 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", |
885 supports_quic); | 972 supports_quic); |
886 | 973 |
887 // Set up the pref. | 974 // Set up the pref. |
888 pref_service_.SetManagedPref(kTestHttpServerProperties, | 975 pref_service_.SetManagedPref(kTestHttpServerProperties, |
(...skipping 12 matching lines...) Expand all Loading... |
901 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); | 988 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
902 EXPECT_EQ(i, alternative_service_vector[0].port); | 989 EXPECT_EQ(i, alternative_service_vector[0].port); |
903 } | 990 } |
904 | 991 |
905 // Verify SupportsQuic. | 992 // Verify SupportsQuic. |
906 IPAddressNumber address; | 993 IPAddressNumber address; |
907 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 994 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
908 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); | 995 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); |
909 } | 996 } |
910 | 997 |
911 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 998 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
912 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 999 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
913 | 1000 |
914 const HostPortPair server_www("www.google.com", 80); | 1001 const HostPortPair server_www("www.google.com", 80); |
915 const HostPortPair server_mail("mail.google.com", 80); | 1002 const HostPortPair server_mail("mail.google.com", 80); |
916 | 1003 |
917 // Set alternate protocol. | 1004 // Set alternate protocol. |
918 AlternativeServiceInfoVector alternative_service_info_vector; | 1005 AlternativeServiceInfoVector alternative_service_info_vector; |
919 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); | 1006 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); |
920 base::Time expiration1; | 1007 base::Time expiration1; |
921 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); | 1008 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 // Update cache. | 1042 // Update cache. |
956 ExpectPrefsUpdate(); | 1043 ExpectPrefsUpdate(); |
957 ExpectCacheUpdate(); | 1044 ExpectCacheUpdate(); |
958 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1045 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
959 base::RunLoop().RunUntilIdle(); | 1046 base::RunLoop().RunUntilIdle(); |
960 | 1047 |
961 // Verify preferences. | 1048 // Verify preferences. |
962 const char expected_json[] = | 1049 const char expected_json[] = |
963 "{\"quic_servers\":{\"https://" | 1050 "{\"quic_servers\":{\"https://" |
964 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," | 1051 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," |
965 "\"servers\":{\"mail.google.com:80\":{\"alternative_service\":[{" | 1052 "\"servers\":[" |
966 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," | 1053 "{\"www.google.com:80\":{" |
967 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"}]," | |
968 "\"network_stats\":{\"srtt\":42}},\"www.google.com:80\":{" | |
969 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," | 1054 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," |
970 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-h2\"}," | 1055 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-h2\"}," |
971 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," | 1056 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," |
972 "\"port\":1234,\"probability\":0.7,\"protocol_str\":\"npn-h2\"}]}}," | 1057 "\"port\":1234,\"probability\":0.7,\"protocol_str\":\"npn-h2\"}]}}," |
| 1058 "{\"mail.google.com:80\":{\"alternative_service\":[{" |
| 1059 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," |
| 1060 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"}]," |
| 1061 "\"network_stats\":{\"srtt\":42}}}" |
| 1062 "]," |
973 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," | 1063 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," |
974 "\"version\":3}"; | 1064 "\"version\":4}"; |
975 | 1065 |
976 const base::Value* http_server_properties = | 1066 const base::Value* http_server_properties = |
977 pref_service_.GetUserPref(kTestHttpServerProperties); | 1067 pref_service_.GetUserPref(kTestHttpServerProperties); |
978 ASSERT_NE(nullptr, http_server_properties); | 1068 ASSERT_NE(nullptr, http_server_properties); |
979 std::string preferences_json; | 1069 std::string preferences_json; |
980 EXPECT_TRUE( | 1070 EXPECT_TRUE( |
981 base::JSONWriter::Write(*http_server_properties, &preferences_json)); | 1071 base::JSONWriter::Write(*http_server_properties, &preferences_json)); |
982 EXPECT_EQ(expected_json, preferences_json); | 1072 EXPECT_EQ(expected_json, preferences_json); |
983 } | 1073 } |
984 | 1074 |
985 TEST_F(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { | 1075 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { |
986 scoped_ptr<base::Value> server_value = base::JSONReader::Read( | 1076 scoped_ptr<base::Value> server_value = base::JSONReader::Read( |
987 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," | 1077 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," |
988 "{\"port\":123,\"protocol_str\":\"quic\",\"probability\":0.7," | 1078 "{\"port\":123,\"protocol_str\":\"quic\",\"probability\":0.7," |
989 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," | 1079 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," |
990 "\"port\":1234,\"protocol_str\":\"npn-h2\",\"probability\":0.2," | 1080 "\"port\":1234,\"protocol_str\":\"npn-h2\",\"probability\":0.2," |
991 "\"expiration\":\"13758804000000000\"}]}"); | 1081 "\"expiration\":\"13758804000000000\"}]}"); |
992 ASSERT_TRUE(server_value); | 1082 ASSERT_TRUE(server_value); |
993 base::DictionaryValue* server_dict; | 1083 base::DictionaryValue* server_dict; |
994 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); | 1084 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); |
995 | 1085 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 alternative_service_info_vector[2].alternative_service.host); | 1120 alternative_service_info_vector[2].alternative_service.host); |
1031 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); | 1121 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); |
1032 EXPECT_DOUBLE_EQ(0.2, alternative_service_info_vector[2].probability); | 1122 EXPECT_DOUBLE_EQ(0.2, alternative_service_info_vector[2].probability); |
1033 base::Time expected_expiration; | 1123 base::Time expected_expiration; |
1034 ASSERT_TRUE( | 1124 ASSERT_TRUE( |
1035 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration)); | 1125 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration)); |
1036 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration); | 1126 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration); |
1037 } | 1127 } |
1038 | 1128 |
1039 // Do not persist expired or broken alternative service entries to disk. | 1129 // Do not persist expired or broken alternative service entries to disk. |
1040 TEST_F(HttpServerPropertiesManagerTest, | 1130 TEST_P(HttpServerPropertiesManagerTest, |
1041 DoNotPersistExpiredOrBrokenAlternativeService) { | 1131 DoNotPersistExpiredOrBrokenAlternativeService) { |
1042 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 1132 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
1043 | 1133 |
1044 AlternativeServiceInfoVector alternative_service_info_vector; | 1134 AlternativeServiceInfoVector alternative_service_info_vector; |
1045 | 1135 |
1046 const AlternativeService broken_alternative_service( | 1136 const AlternativeService broken_alternative_service( |
1047 NPN_HTTP_2, "broken.example.com", 443); | 1137 NPN_HTTP_2, "broken.example.com", 443); |
1048 const base::Time time_one_day_later = | 1138 const base::Time time_one_day_later = |
1049 base::Time::Now() + base::TimeDelta::FromDays(1); | 1139 base::Time::Now() + base::TimeDelta::FromDays(1); |
1050 alternative_service_info_vector.push_back(AlternativeServiceInfo( | 1140 alternative_service_info_vector.push_back(AlternativeServiceInfo( |
(...skipping 23 matching lines...) Expand all Loading... |
1074 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1164 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
1075 base::RunLoop().RunUntilIdle(); | 1165 base::RunLoop().RunUntilIdle(); |
1076 | 1166 |
1077 const base::Value* pref_value = | 1167 const base::Value* pref_value = |
1078 pref_service_.GetUserPref(kTestHttpServerProperties); | 1168 pref_service_.GetUserPref(kTestHttpServerProperties); |
1079 ASSERT_NE(nullptr, pref_value); | 1169 ASSERT_NE(nullptr, pref_value); |
1080 | 1170 |
1081 const base::DictionaryValue* pref_dict; | 1171 const base::DictionaryValue* pref_dict; |
1082 ASSERT_TRUE(pref_value->GetAsDictionary(&pref_dict)); | 1172 ASSERT_TRUE(pref_value->GetAsDictionary(&pref_dict)); |
1083 | 1173 |
| 1174 const base::ListValue* servers_list = nullptr; |
| 1175 ASSERT_TRUE(pref_dict->GetListWithoutPathExpansion("servers", &servers_list)); |
| 1176 base::ListValue::const_iterator it = servers_list->begin(); |
1084 const base::DictionaryValue* server_pref_dict; | 1177 const base::DictionaryValue* server_pref_dict; |
1085 ASSERT_TRUE(pref_dict->GetDictionary("servers", &server_pref_dict)); | 1178 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict)); |
1086 | 1179 |
1087 const base::DictionaryValue* example_pref_dict; | 1180 const base::DictionaryValue* example_pref_dict; |
1088 ASSERT_TRUE(server_pref_dict->GetDictionaryWithoutPathExpansion( | 1181 ASSERT_TRUE(server_pref_dict->GetDictionaryWithoutPathExpansion( |
1089 "www.example.com:443", &example_pref_dict)); | 1182 "www.example.com:443", &example_pref_dict)); |
1090 | 1183 |
1091 const base::ListValue* altsvc_list; | 1184 const base::ListValue* altsvc_list; |
1092 ASSERT_TRUE(example_pref_dict->GetList("alternative_service", &altsvc_list)); | 1185 ASSERT_TRUE(example_pref_dict->GetList("alternative_service", &altsvc_list)); |
1093 | 1186 |
1094 ASSERT_EQ(1u, altsvc_list->GetSize()); | 1187 ASSERT_EQ(1u, altsvc_list->GetSize()); |
1095 | 1188 |
1096 const base::DictionaryValue* altsvc_entry; | 1189 const base::DictionaryValue* altsvc_entry; |
1097 ASSERT_TRUE(altsvc_list->GetDictionary(0, &altsvc_entry)); | 1190 ASSERT_TRUE(altsvc_list->GetDictionary(0, &altsvc_entry)); |
1098 | 1191 |
1099 std::string hostname; | 1192 std::string hostname; |
1100 ASSERT_TRUE(altsvc_entry->GetString("host", &hostname)); | 1193 ASSERT_TRUE(altsvc_entry->GetString("host", &hostname)); |
1101 EXPECT_EQ("valid.example.com", hostname); | 1194 EXPECT_EQ("valid.example.com", hostname); |
1102 } | 1195 } |
1103 | 1196 |
1104 // Test that expired alternative service entries on disk are ignored. | 1197 // Test that expired alternative service entries on disk are ignored. |
1105 TEST_F(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) { | 1198 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) { |
1106 scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue); | 1199 scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue); |
1107 base::DictionaryValue* expired_dict = new base::DictionaryValue; | 1200 base::DictionaryValue* expired_dict = new base::DictionaryValue; |
1108 expired_dict->SetString("protocol_str", "npn-h2"); | 1201 expired_dict->SetString("protocol_str", "npn-h2"); |
1109 expired_dict->SetString("host", "expired.example.com"); | 1202 expired_dict->SetString("host", "expired.example.com"); |
1110 expired_dict->SetInteger("port", 443); | 1203 expired_dict->SetInteger("port", 443); |
1111 expired_dict->SetDouble("probability", 1.0); | 1204 expired_dict->SetDouble("probability", 1.0); |
1112 base::Time time_one_day_ago = | 1205 base::Time time_one_day_ago = |
1113 base::Time::Now() - base::TimeDelta::FromDays(1); | 1206 base::Time::Now() - base::TimeDelta::FromDays(1); |
1114 expired_dict->SetString( | 1207 expired_dict->SetString( |
1115 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue())); | 1208 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue())); |
(...skipping 25 matching lines...) Expand all Loading... |
1141 | 1234 |
1142 EXPECT_EQ(NPN_HTTP_2, | 1235 EXPECT_EQ(NPN_HTTP_2, |
1143 alternative_service_info_vector[0].alternative_service.protocol); | 1236 alternative_service_info_vector[0].alternative_service.protocol); |
1144 EXPECT_EQ("valid.example.com", | 1237 EXPECT_EQ("valid.example.com", |
1145 alternative_service_info_vector[0].alternative_service.host); | 1238 alternative_service_info_vector[0].alternative_service.host); |
1146 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); | 1239 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); |
1147 EXPECT_DOUBLE_EQ(1.0, alternative_service_info_vector[0].probability); | 1240 EXPECT_DOUBLE_EQ(1.0, alternative_service_info_vector[0].probability); |
1148 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration); | 1241 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration); |
1149 } | 1242 } |
1150 | 1243 |
1151 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 1244 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
1152 // Post an update task to the UI thread. | 1245 // Post an update task to the UI thread. |
1153 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1246 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
1154 // Shutdown comes before the task is executed. | 1247 // Shutdown comes before the task is executed. |
1155 http_server_props_manager_->ShutdownOnPrefThread(); | 1248 http_server_props_manager_->ShutdownOnPrefThread(); |
1156 http_server_props_manager_.reset(); | 1249 http_server_props_manager_.reset(); |
1157 // Run the task after shutdown and deletion. | 1250 // Run the task after shutdown and deletion. |
1158 base::RunLoop().RunUntilIdle(); | 1251 base::RunLoop().RunUntilIdle(); |
1159 } | 1252 } |
1160 | 1253 |
1161 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache1) { | 1254 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache1) { |
1162 // Post an update task. | 1255 // Post an update task. |
1163 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1256 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
1164 // Shutdown comes before the task is executed. | 1257 // Shutdown comes before the task is executed. |
1165 http_server_props_manager_->ShutdownOnPrefThread(); | 1258 http_server_props_manager_->ShutdownOnPrefThread(); |
1166 // Run the task after shutdown, but before deletion. | 1259 // Run the task after shutdown, but before deletion. |
1167 base::RunLoop().RunUntilIdle(); | 1260 base::RunLoop().RunUntilIdle(); |
1168 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1261 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1169 http_server_props_manager_.reset(); | 1262 http_server_props_manager_.reset(); |
1170 base::RunLoop().RunUntilIdle(); | 1263 base::RunLoop().RunUntilIdle(); |
1171 } | 1264 } |
1172 | 1265 |
1173 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache2) { | 1266 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache2) { |
1174 http_server_props_manager_->UpdateCacheFromPrefsOnUIConcrete(); | 1267 http_server_props_manager_->UpdateCacheFromPrefsOnUIConcrete(); |
1175 // Shutdown comes before the task is executed. | 1268 // Shutdown comes before the task is executed. |
1176 http_server_props_manager_->ShutdownOnPrefThread(); | 1269 http_server_props_manager_->ShutdownOnPrefThread(); |
1177 // Run the task after shutdown, but before deletion. | 1270 // Run the task after shutdown, but before deletion. |
1178 base::RunLoop().RunUntilIdle(); | 1271 base::RunLoop().RunUntilIdle(); |
1179 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1272 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1180 http_server_props_manager_.reset(); | 1273 http_server_props_manager_.reset(); |
1181 base::RunLoop().RunUntilIdle(); | 1274 base::RunLoop().RunUntilIdle(); |
1182 } | 1275 } |
1183 | 1276 |
1184 // | 1277 // |
1185 // Tests for shutdown when updating prefs. | 1278 // Tests for shutdown when updating prefs. |
1186 // | 1279 // |
1187 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs0) { | 1280 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs0) { |
1188 // Post an update task to the IO thread. | 1281 // Post an update task to the IO thread. |
1189 http_server_props_manager_->ScheduleUpdatePrefsOnNetworkThread(); | 1282 http_server_props_manager_->ScheduleUpdatePrefsOnNetworkThread(); |
1190 // Shutdown comes before the task is executed. | 1283 // Shutdown comes before the task is executed. |
1191 http_server_props_manager_->ShutdownOnPrefThread(); | 1284 http_server_props_manager_->ShutdownOnPrefThread(); |
1192 http_server_props_manager_.reset(); | 1285 http_server_props_manager_.reset(); |
1193 // Run the task after shutdown and deletion. | 1286 // Run the task after shutdown and deletion. |
1194 base::RunLoop().RunUntilIdle(); | 1287 base::RunLoop().RunUntilIdle(); |
1195 } | 1288 } |
1196 | 1289 |
1197 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) { | 1290 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) { |
1198 ExpectPrefsUpdate(); | 1291 ExpectPrefsUpdate(); |
1199 // Post an update task. | 1292 // Post an update task. |
1200 http_server_props_manager_->ScheduleUpdatePrefsOnNetworkThread(); | 1293 http_server_props_manager_->ScheduleUpdatePrefsOnNetworkThread(); |
1201 // Shutdown comes before the task is executed. | 1294 // Shutdown comes before the task is executed. |
1202 http_server_props_manager_->ShutdownOnPrefThread(); | 1295 http_server_props_manager_->ShutdownOnPrefThread(); |
1203 // Run the task after shutdown, but before deletion. | 1296 // Run the task after shutdown, but before deletion. |
1204 base::RunLoop().RunUntilIdle(); | 1297 base::RunLoop().RunUntilIdle(); |
1205 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1298 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1206 http_server_props_manager_.reset(); | 1299 http_server_props_manager_.reset(); |
1207 base::RunLoop().RunUntilIdle(); | 1300 base::RunLoop().RunUntilIdle(); |
1208 } | 1301 } |
1209 | 1302 |
1210 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) { | 1303 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) { |
1211 // This posts a task to the UI thread. | 1304 // This posts a task to the UI thread. |
1212 http_server_props_manager_->UpdatePrefsFromCacheOnNetworkThreadConcrete( | 1305 http_server_props_manager_->UpdatePrefsFromCacheOnNetworkThreadConcrete( |
1213 base::Closure()); | 1306 base::Closure()); |
1214 // Shutdown comes before the task is executed. | 1307 // Shutdown comes before the task is executed. |
1215 http_server_props_manager_->ShutdownOnPrefThread(); | 1308 http_server_props_manager_->ShutdownOnPrefThread(); |
1216 // Run the task after shutdown, but before deletion. | 1309 // Run the task after shutdown, but before deletion. |
1217 base::RunLoop().RunUntilIdle(); | 1310 base::RunLoop().RunUntilIdle(); |
1218 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1311 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1219 http_server_props_manager_.reset(); | 1312 http_server_props_manager_.reset(); |
1220 base::RunLoop().RunUntilIdle(); | 1313 base::RunLoop().RunUntilIdle(); |
1221 } | 1314 } |
1222 | 1315 |
1223 } // namespace net | 1316 } // namespace net |
OLD | NEW |