| 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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" |
| 12 #include "base/test/test_simple_task_runner.h" | 14 #include "base/test/test_simple_task_runner.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 17 | 19 |
| 18 namespace net { | 20 namespace net { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 24 using base::StringPrintf; |
| 22 using ::testing::_; | 25 using ::testing::_; |
| 23 using ::testing::Invoke; | 26 using ::testing::Invoke; |
| 24 using ::testing::Mock; | 27 using ::testing::Mock; |
| 25 using ::testing::StrictMock; | 28 using ::testing::StrictMock; |
| 26 | 29 |
| 27 const char kTestHttpServerProperties[] = "TestHttpServerProperties"; | 30 const char kTestHttpServerProperties[] = "TestHttpServerProperties"; |
| 28 | 31 |
| 29 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { | 32 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { |
| 30 public: | 33 public: |
| 31 TestingHttpServerPropertiesManager( | 34 TestingHttpServerPropertiesManager( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 60 base::TimeDelta()); | 63 base::TimeDelta()); |
| 61 } | 64 } |
| 62 | 65 |
| 63 void UpdatePrefsFromCacheOnNetworkThreadConcrete( | 66 void UpdatePrefsFromCacheOnNetworkThreadConcrete( |
| 64 const base::Closure& callback) { | 67 const base::Closure& callback) { |
| 65 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); | 68 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); |
| 66 } | 69 } |
| 67 | 70 |
| 68 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); | 71 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); |
| 69 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); | 72 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); |
| 70 MOCK_METHOD5(UpdateCacheFromPrefsOnNetworkThread, | 73 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, |
| 71 void(std::vector<std::string>* spdy_servers, | 74 void(std::vector<std::string>* spdy_servers, |
| 72 net::SpdySettingsMap* spdy_settings_map, | 75 SpdySettingsMap* spdy_settings_map, |
| 73 net::AlternateProtocolMap* alternate_protocol_map, | 76 AlternateProtocolMap* alternate_protocol_map, |
| 74 net::SupportsQuicMap* supports_quic_map, | 77 SupportsQuicMap* supports_quic_map, |
| 78 ServerNetworkStatsMap* server_network_stats_map, |
| 75 bool detected_corrupted_prefs)); | 79 bool detected_corrupted_prefs)); |
| 76 MOCK_METHOD4(UpdatePrefsOnPref, | 80 MOCK_METHOD5(UpdatePrefsOnPref, |
| 77 void(base::ListValue* spdy_server_list, | 81 void(base::ListValue* spdy_server_list, |
| 78 net::SpdySettingsMap* spdy_settings_map, | 82 SpdySettingsMap* spdy_settings_map, |
| 79 net::AlternateProtocolMap* alternate_protocol_map, | 83 AlternateProtocolMap* alternate_protocol_map, |
| 80 net::SupportsQuicMap* supports_quic_map)); | 84 SupportsQuicMap* supports_quic_map, |
| 85 ServerNetworkStatsMap* server_network_stats_map)); |
| 81 | 86 |
| 82 private: | 87 private: |
| 83 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 88 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
| 84 }; | 89 }; |
| 85 | 90 |
| 86 class HttpServerPropertiesManagerTest : public testing::Test { | 91 class HttpServerPropertiesManagerTest : public testing::Test { |
| 87 protected: | 92 protected: |
| 88 HttpServerPropertiesManagerTest() {} | 93 HttpServerPropertiesManagerTest() {} |
| 89 | 94 |
| 90 void SetUp() override { | 95 void SetUp() override { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 }; | 143 }; |
| 139 | 144 |
| 140 TEST_F(HttpServerPropertiesManagerTest, | 145 TEST_F(HttpServerPropertiesManagerTest, |
| 141 SingleUpdateForTwoSpdyServerPrefChanges) { | 146 SingleUpdateForTwoSpdyServerPrefChanges) { |
| 142 ExpectCacheUpdate(); | 147 ExpectCacheUpdate(); |
| 143 | 148 |
| 144 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set | 149 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set |
| 145 // it twice. Only expect a single cache update. | 150 // it twice. Only expect a single cache update. |
| 146 | 151 |
| 147 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 152 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 153 HostPortPair google_server("www.google.com", 80); |
| 154 HostPortPair mail_server("mail.google.com", 80); |
| 148 | 155 |
| 149 // Set supports_spdy for www.google.com:80. | 156 // Set supports_spdy for www.google.com:80. |
| 150 server_pref_dict->SetBoolean("supports_spdy", true); | 157 server_pref_dict->SetBoolean("supports_spdy", true); |
| 151 | 158 |
| 152 // Set up alternate_protocol for www.google.com:80. | 159 // Set up alternate_protocol for www.google.com:80. |
| 153 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 160 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 154 alternate_protocol->SetInteger("port", 443); | 161 alternate_protocol->SetInteger("port", 443); |
| 155 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 162 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 156 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 163 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
| 157 alternate_protocol); | 164 alternate_protocol); |
| 158 | 165 |
| 159 // Set up SupportsQuic for www.google.com:80. | 166 // Set up SupportsQuic for www.google.com:80. |
| 160 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 167 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 161 supports_quic->SetBoolean("used_quic", true); | 168 supports_quic->SetBoolean("used_quic", true); |
| 162 supports_quic->SetString("address", "foo"); | 169 supports_quic->SetString("address", "foo"); |
| 163 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); | 170 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); |
| 164 | 171 |
| 172 // Set up ServerNetworkStats for www.google.com:80. |
| 173 base::DictionaryValue* stats = new base::DictionaryValue; |
| 174 stats->SetInteger("srtt", 10); |
| 175 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 176 |
| 165 // Set the server preference for www.google.com:80. | 177 // Set the server preference for www.google.com:80. |
| 166 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 178 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 167 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 179 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
| 168 | 180 |
| 169 // Set the preference for mail.google.com server. | 181 // Set the preference for mail.google.com server. |
| 170 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 182 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 171 | 183 |
| 172 // Set supports_spdy for mail.google.com:80 | 184 // Set supports_spdy for mail.google.com:80 |
| 173 server_pref_dict1->SetBoolean("supports_spdy", true); | 185 server_pref_dict1->SetBoolean("supports_spdy", true); |
| 174 | 186 |
| 175 // Set up alternate_protocol for mail.google.com:80 | 187 // Set up alternate_protocol for mail.google.com:80 |
| 176 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 188 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
| 177 alternate_protocol1->SetInteger("port", 444); | 189 alternate_protocol1->SetInteger("port", 444); |
| 178 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); | 190 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); |
| 179 | 191 |
| 180 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", | 192 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", |
| 181 alternate_protocol1); | 193 alternate_protocol1); |
| 182 | 194 |
| 183 // Set up SupportsQuic for mail.google.com:80 | 195 // Set up SupportsQuic for mail.google.com:80 |
| 184 base::DictionaryValue* supports_quic1 = new base::DictionaryValue; | 196 base::DictionaryValue* supports_quic1 = new base::DictionaryValue; |
| 185 supports_quic1->SetBoolean("used_quic", false); | 197 supports_quic1->SetBoolean("used_quic", false); |
| 186 supports_quic1->SetString("address", "bar"); | 198 supports_quic1->SetString("address", "bar"); |
| 187 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1); | 199 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1); |
| 188 | 200 |
| 201 // Set up ServerNetworkStats for mail.google.com:80. |
| 202 base::DictionaryValue* stats1 = new base::DictionaryValue; |
| 203 stats1->SetInteger("srtt", 20); |
| 204 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); |
| 189 // Set the server preference for mail.google.com:80. | 205 // Set the server preference for mail.google.com:80. |
| 190 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 206 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
| 191 server_pref_dict1); | 207 server_pref_dict1); |
| 192 | 208 |
| 193 base::DictionaryValue* http_server_properties_dict = | 209 base::DictionaryValue* http_server_properties_dict = |
| 194 new base::DictionaryValue; | 210 new base::DictionaryValue; |
| 195 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 211 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 196 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 212 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 197 | 213 |
| 198 // Set the same value for kHttpServerProperties multiple times. | 214 // Set the same value for kHttpServerProperties multiple times. |
| 199 pref_service_.SetManagedPref(kTestHttpServerProperties, | 215 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 200 http_server_properties_dict); | 216 http_server_properties_dict); |
| 201 base::DictionaryValue* http_server_properties_dict2 = | 217 base::DictionaryValue* http_server_properties_dict2 = |
| 202 http_server_properties_dict->DeepCopy(); | 218 http_server_properties_dict->DeepCopy(); |
| 203 pref_service_.SetManagedPref(kTestHttpServerProperties, | 219 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 204 http_server_properties_dict2); | 220 http_server_properties_dict2); |
| 205 | 221 |
| 206 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
| 207 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 208 | 224 |
| 209 // Verify SupportsSpdy. | 225 // Verify SupportsSpdy. |
| 210 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( | 226 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); |
| 211 net::HostPortPair::FromString("www.google.com:80"))); | 227 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); |
| 212 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( | |
| 213 net::HostPortPair::FromString("mail.google.com:80"))); | |
| 214 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( | 228 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( |
| 215 net::HostPortPair::FromString("foo.google.com:1337"))); | 229 HostPortPair::FromString("foo.google.com:1337"))); |
| 216 | 230 |
| 217 // Verify AlternateProtocol. | 231 // Verify AlternateProtocol. |
| 218 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | 232 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); |
| 219 net::HostPortPair::FromString("www.google.com:80"))); | 233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); |
| 220 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | 234 AlternateProtocolInfo port_alternate_protocol = |
| 221 net::HostPortPair::FromString("mail.google.com:80"))); | 235 http_server_props_manager_->GetAlternateProtocol(google_server); |
| 222 net::AlternateProtocolInfo port_alternate_protocol = | |
| 223 http_server_props_manager_->GetAlternateProtocol( | |
| 224 net::HostPortPair::FromString("www.google.com:80")); | |
| 225 EXPECT_EQ(443, port_alternate_protocol.port); | 236 EXPECT_EQ(443, port_alternate_protocol.port); |
| 226 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 237 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 227 port_alternate_protocol = http_server_props_manager_->GetAlternateProtocol( | 238 port_alternate_protocol = |
| 228 net::HostPortPair::FromString("mail.google.com:80")); | 239 http_server_props_manager_->GetAlternateProtocol(mail_server); |
| 229 EXPECT_EQ(444, port_alternate_protocol.port); | 240 EXPECT_EQ(444, port_alternate_protocol.port); |
| 230 EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol); | 241 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); |
| 231 | 242 |
| 232 // Verify SupportsQuic. | 243 // Verify SupportsQuic. |
| 233 net::SupportsQuic supports_quic2 = | 244 SupportsQuic supports_quic2 = |
| 234 http_server_props_manager_->GetSupportsQuic( | 245 http_server_props_manager_->GetSupportsQuic(google_server); |
| 235 net::HostPortPair::FromString("www.google.com:80")); | |
| 236 EXPECT_TRUE(supports_quic2.used_quic); | 246 EXPECT_TRUE(supports_quic2.used_quic); |
| 237 EXPECT_EQ("foo", supports_quic2.address); | 247 EXPECT_EQ("foo", supports_quic2.address); |
| 238 supports_quic2 = http_server_props_manager_->GetSupportsQuic( | 248 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server); |
| 239 net::HostPortPair::FromString("mail.google.com:80")); | |
| 240 EXPECT_FALSE(supports_quic2.used_quic); | 249 EXPECT_FALSE(supports_quic2.used_quic); |
| 241 EXPECT_EQ("bar", supports_quic2.address); | 250 EXPECT_EQ("bar", supports_quic2.address); |
| 251 |
| 252 // Verify ServerNetworkStats. |
| 253 const ServerNetworkStats* stats2 = |
| 254 http_server_props_manager_->GetServerNetworkStats(google_server); |
| 255 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 256 const ServerNetworkStats* stats3 = |
| 257 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 258 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
| 242 } | 259 } |
| 243 | 260 |
| 244 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 261 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
| 245 ExpectCacheUpdate(); | 262 ExpectCacheUpdate(); |
| 246 // The prefs are automaticalls updated in the case corruption is detected. | 263 // The prefs are automaticalls updated in the case corruption is detected. |
| 247 ExpectPrefsUpdate(); | 264 ExpectPrefsUpdate(); |
| 248 | 265 |
| 249 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 266 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 250 | 267 |
| 251 // Set supports_spdy for www.google.com:65536. | 268 // Set supports_spdy for www.google.com:65536. |
| 252 server_pref_dict->SetBoolean("supports_spdy", true); | 269 server_pref_dict->SetBoolean("supports_spdy", true); |
| 253 | 270 |
| 254 // Set up alternate_protocol for www.google.com:65536. | 271 // Set up alternate_protocol for www.google.com:65536. |
| 255 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 272 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 256 alternate_protocol->SetInteger("port", 80); | 273 alternate_protocol->SetInteger("port", 80); |
| 257 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 274 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 258 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 275 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
| 259 alternate_protocol); | 276 alternate_protocol); |
| 260 | 277 |
| 261 // Set up SupportsQuic for www.google.com:65536. | 278 // Set up SupportsQuic for www.google.com:65536. |
| 262 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 279 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 263 supports_quic->SetBoolean("used_quic", true); | 280 supports_quic->SetBoolean("used_quic", true); |
| 264 supports_quic->SetString("address", "foo"); | 281 supports_quic->SetString("address", "foo"); |
| 265 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); | 282 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); |
| 266 | 283 |
| 284 // Set up ServerNetworkStats for www.google.com:65536. |
| 285 base::DictionaryValue* stats = new base::DictionaryValue; |
| 286 stats->SetInteger("srtt", 10); |
| 287 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 288 |
| 267 // Set the server preference for www.google.com:65536. | 289 // Set the server preference for www.google.com:65536. |
| 268 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 290 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 269 servers_dict->SetWithoutPathExpansion("www.google.com:65536", | 291 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
| 270 server_pref_dict); | 292 server_pref_dict); |
| 271 | 293 |
| 272 base::DictionaryValue* http_server_properties_dict = | 294 base::DictionaryValue* http_server_properties_dict = |
| 273 new base::DictionaryValue; | 295 new base::DictionaryValue; |
| 274 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 296 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 275 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 297 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 276 | 298 |
| 277 // Set up the pref. | 299 // Set up the pref. |
| 278 pref_service_.SetManagedPref(kTestHttpServerProperties, | 300 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 279 http_server_properties_dict); | 301 http_server_properties_dict); |
| 280 | 302 |
| 281 base::RunLoop().RunUntilIdle(); | 303 base::RunLoop().RunUntilIdle(); |
| 282 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 304 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 283 | 305 |
| 284 // Verify that nothing is set. | 306 // Verify that nothing is set. |
| 285 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( | 307 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( |
| 286 net::HostPortPair::FromString("www.google.com:65536"))); | 308 HostPortPair::FromString("www.google.com:65536"))); |
| 287 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( | 309 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( |
| 288 net::HostPortPair::FromString("www.google.com:65536"))); | 310 HostPortPair::FromString("www.google.com:65536"))); |
| 289 net::SupportsQuic supports_quic2 = | 311 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( |
| 290 http_server_props_manager_->GetSupportsQuic( | 312 HostPortPair::FromString("www.google.com:65536")); |
| 291 net::HostPortPair::FromString("www.google.com:65536")); | |
| 292 EXPECT_FALSE(supports_quic2.used_quic); | 313 EXPECT_FALSE(supports_quic2.used_quic); |
| 314 const ServerNetworkStats* stats1 = |
| 315 http_server_props_manager_->GetServerNetworkStats( |
| 316 HostPortPair::FromString("www.google.com:65536")); |
| 317 EXPECT_EQ(NULL, stats1); |
| 293 } | 318 } |
| 294 | 319 |
| 295 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 320 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| 296 ExpectCacheUpdate(); | 321 ExpectCacheUpdate(); |
| 297 // The prefs are automaticalls updated in the case corruption is detected. | 322 // The prefs are automaticalls updated in the case corruption is detected. |
| 298 ExpectPrefsUpdate(); | 323 ExpectPrefsUpdate(); |
| 299 | 324 |
| 300 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 325 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 301 | 326 |
| 302 // Set supports_spdy for www.google.com:80. | 327 // Set supports_spdy for www.google.com:80. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 320 | 345 |
| 321 // Set up the pref. | 346 // Set up the pref. |
| 322 pref_service_.SetManagedPref(kTestHttpServerProperties, | 347 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 323 http_server_properties_dict); | 348 http_server_properties_dict); |
| 324 | 349 |
| 325 base::RunLoop().RunUntilIdle(); | 350 base::RunLoop().RunUntilIdle(); |
| 326 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 351 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 327 | 352 |
| 328 // Verify AlternateProtocol is not set. | 353 // Verify AlternateProtocol is not set. |
| 329 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( | 354 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( |
| 330 net::HostPortPair::FromString("www.google.com:80"))); | 355 HostPortPair::FromString("www.google.com:80"))); |
| 331 } | 356 } |
| 332 | 357 |
| 333 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 358 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
| 334 ExpectPrefsUpdate(); | 359 ExpectPrefsUpdate(); |
| 335 | 360 |
| 336 // Post an update task to the network thread. SetSupportsSpdy calls | 361 // Post an update task to the network thread. SetSupportsSpdy calls |
| 337 // ScheduleUpdatePrefsOnNetworkThread. | 362 // ScheduleUpdatePrefsOnNetworkThread. |
| 338 | 363 |
| 339 // Add mail.google.com:443 as a supporting spdy server. | 364 // Add mail.google.com:443 as a supporting spdy server. |
| 340 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 365 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 341 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 366 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
| 342 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 367 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 343 | 368 |
| 344 // Run the task. | 369 // Run the task. |
| 345 base::RunLoop().RunUntilIdle(); | 370 base::RunLoop().RunUntilIdle(); |
| 346 | 371 |
| 347 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 372 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
| 348 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 373 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 349 } | 374 } |
| 350 | 375 |
| 351 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { | 376 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { |
| 352 ExpectPrefsUpdate(); | 377 ExpectPrefsUpdate(); |
| 353 | 378 |
| 354 // Add SpdySetting for mail.google.com:443. | 379 // Add SpdySetting for mail.google.com:443. |
| 355 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 380 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 356 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; | 381 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 357 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; | 382 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 358 const uint32 value1 = 31337; | 383 const uint32 value1 = 31337; |
| 359 http_server_props_manager_->SetSpdySetting( | 384 http_server_props_manager_->SetSpdySetting( |
| 360 spdy_server_mail, id1, flags1, value1); | 385 spdy_server_mail, id1, flags1, value1); |
| 361 | 386 |
| 362 // Run the task. | 387 // Run the task. |
| 363 base::RunLoop().RunUntilIdle(); | 388 base::RunLoop().RunUntilIdle(); |
| 364 | 389 |
| 365 const net::SettingsMap& settings_map1_ret = | 390 const SettingsMap& settings_map1_ret = |
| 366 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 391 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 367 ASSERT_EQ(1U, settings_map1_ret.size()); | 392 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 368 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 393 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 369 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 394 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 370 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 395 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 371 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 396 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 372 EXPECT_EQ(value1, flags_and_value1_ret.second); | 397 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 373 | 398 |
| 374 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 399 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 375 } | 400 } |
| 376 | 401 |
| 377 TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { | 402 TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { |
| 378 ExpectPrefsUpdateRepeatedly(); | 403 ExpectPrefsUpdateRepeatedly(); |
| 379 | 404 |
| 380 // Add SpdySetting for mail.google.com:443. | 405 // Add SpdySetting for mail.google.com:443. |
| 381 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 406 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 382 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; | 407 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 383 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; | 408 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 384 const uint32 value1 = 31337; | 409 const uint32 value1 = 31337; |
| 385 http_server_props_manager_->SetSpdySetting( | 410 http_server_props_manager_->SetSpdySetting( |
| 386 spdy_server_mail, id1, flags1, value1); | 411 spdy_server_mail, id1, flags1, value1); |
| 387 | 412 |
| 388 // Run the task. | 413 // Run the task. |
| 389 base::RunLoop().RunUntilIdle(); | 414 base::RunLoop().RunUntilIdle(); |
| 390 | 415 |
| 391 const net::SettingsMap& settings_map1_ret = | 416 const SettingsMap& settings_map1_ret = |
| 392 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 417 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 393 ASSERT_EQ(1U, settings_map1_ret.size()); | 418 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 394 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 419 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 395 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 420 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 396 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 421 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 397 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 422 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 398 EXPECT_EQ(value1, flags_and_value1_ret.second); | 423 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 399 | 424 |
| 400 // Clear SpdySetting for mail.google.com:443. | 425 // Clear SpdySetting for mail.google.com:443. |
| 401 http_server_props_manager_->ClearSpdySettings(spdy_server_mail); | 426 http_server_props_manager_->ClearSpdySettings(spdy_server_mail); |
| 402 | 427 |
| 403 // Run the task. | 428 // Run the task. |
| 404 base::RunLoop().RunUntilIdle(); | 429 base::RunLoop().RunUntilIdle(); |
| 405 | 430 |
| 406 // Verify that there are no entries in the settings map for | 431 // Verify that there are no entries in the settings map for |
| 407 // mail.google.com:443. | 432 // mail.google.com:443. |
| 408 const net::SettingsMap& settings_map2_ret = | 433 const SettingsMap& settings_map2_ret = |
| 409 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 434 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 410 ASSERT_EQ(0U, settings_map2_ret.size()); | 435 ASSERT_EQ(0U, settings_map2_ret.size()); |
| 411 | 436 |
| 412 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 437 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 413 } | 438 } |
| 414 | 439 |
| 415 TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { | 440 TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { |
| 416 ExpectPrefsUpdateRepeatedly(); | 441 ExpectPrefsUpdateRepeatedly(); |
| 417 | 442 |
| 418 // Add SpdySetting for mail.google.com:443. | 443 // Add SpdySetting for mail.google.com:443. |
| 419 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 444 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 420 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; | 445 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 421 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; | 446 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 422 const uint32 value1 = 31337; | 447 const uint32 value1 = 31337; |
| 423 http_server_props_manager_->SetSpdySetting( | 448 http_server_props_manager_->SetSpdySetting( |
| 424 spdy_server_mail, id1, flags1, value1); | 449 spdy_server_mail, id1, flags1, value1); |
| 425 | 450 |
| 426 // Run the task. | 451 // Run the task. |
| 427 base::RunLoop().RunUntilIdle(); | 452 base::RunLoop().RunUntilIdle(); |
| 428 | 453 |
| 429 const net::SettingsMap& settings_map1_ret = | 454 const SettingsMap& settings_map1_ret = |
| 430 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 455 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 431 ASSERT_EQ(1U, settings_map1_ret.size()); | 456 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 432 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 457 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 433 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 458 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 434 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 459 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 435 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 460 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 436 EXPECT_EQ(value1, flags_and_value1_ret.second); | 461 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 437 | 462 |
| 438 // Clear All SpdySettings. | 463 // Clear All SpdySettings. |
| 439 http_server_props_manager_->ClearAllSpdySettings(); | 464 http_server_props_manager_->ClearAllSpdySettings(); |
| 440 | 465 |
| 441 // Run the task. | 466 // Run the task. |
| 442 base::RunLoop().RunUntilIdle(); | 467 base::RunLoop().RunUntilIdle(); |
| 443 | 468 |
| 444 // Verify that there are no entries in the settings map. | 469 // Verify that there are no entries in the settings map. |
| 445 const net::SpdySettingsMap& spdy_settings_map2_ret = | 470 const SpdySettingsMap& spdy_settings_map2_ret = |
| 446 http_server_props_manager_->spdy_settings_map(); | 471 http_server_props_manager_->spdy_settings_map(); |
| 447 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); | 472 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); |
| 448 | 473 |
| 449 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 474 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 450 } | 475 } |
| 451 | 476 |
| 452 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { | 477 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { |
| 453 ExpectPrefsUpdate(); | 478 ExpectPrefsUpdate(); |
| 454 | 479 |
| 455 net::HostPortPair spdy_server_mail("mail.google.com", 80); | 480 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 456 EXPECT_FALSE( | 481 EXPECT_FALSE( |
| 457 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 482 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 458 http_server_props_manager_->SetAlternateProtocol( | 483 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
| 459 spdy_server_mail, 443, net::NPN_SPDY_3, 1); | 484 NPN_SPDY_3, 1); |
| 460 | 485 |
| 461 // Run the task. | 486 // Run the task. |
| 462 base::RunLoop().RunUntilIdle(); | 487 base::RunLoop().RunUntilIdle(); |
| 463 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 464 | 489 |
| 465 ASSERT_TRUE( | 490 ASSERT_TRUE( |
| 466 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 491 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 467 net::AlternateProtocolInfo port_alternate_protocol = | 492 AlternateProtocolInfo port_alternate_protocol = |
| 468 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 493 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
| 469 EXPECT_EQ(443, port_alternate_protocol.port); | 494 EXPECT_EQ(443, port_alternate_protocol.port); |
| 470 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 495 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 471 } | 496 } |
| 472 | 497 |
| 473 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 498 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
| 474 ExpectPrefsUpdate(); | 499 ExpectPrefsUpdate(); |
| 475 | 500 |
| 476 net::HostPortPair quic_server_mail("mail.google.com", 80); | 501 HostPortPair quic_server_mail("mail.google.com", 80); |
| 477 net::SupportsQuic supports_quic = http_server_props_manager_->GetSupportsQuic( | 502 SupportsQuic supports_quic = |
| 478 quic_server_mail); | 503 http_server_props_manager_->GetSupportsQuic(quic_server_mail); |
| 479 EXPECT_FALSE(supports_quic.used_quic); | 504 EXPECT_FALSE(supports_quic.used_quic); |
| 480 EXPECT_EQ("", supports_quic.address); | 505 EXPECT_EQ("", supports_quic.address); |
| 481 http_server_props_manager_->SetSupportsQuic(quic_server_mail, true, "foo"); | 506 http_server_props_manager_->SetSupportsQuic(quic_server_mail, true, "foo"); |
| 482 | 507 |
| 483 // Run the task. | 508 // Run the task. |
| 484 base::RunLoop().RunUntilIdle(); | 509 base::RunLoop().RunUntilIdle(); |
| 485 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 510 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 486 | 511 |
| 487 net::SupportsQuic supports_quic1 = | 512 SupportsQuic supports_quic1 = |
| 488 http_server_props_manager_->GetSupportsQuic(quic_server_mail); | 513 http_server_props_manager_->GetSupportsQuic(quic_server_mail); |
| 489 EXPECT_TRUE(supports_quic1.used_quic); | 514 EXPECT_TRUE(supports_quic1.used_quic); |
| 490 EXPECT_EQ("foo", supports_quic1.address); | 515 EXPECT_EQ("foo", supports_quic1.address); |
| 491 } | 516 } |
| 492 | 517 |
| 518 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { |
| 519 ExpectPrefsUpdate(); |
| 520 |
| 521 HostPortPair mail_server("mail.google.com", 80); |
| 522 const ServerNetworkStats* stats = |
| 523 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 524 EXPECT_EQ(NULL, stats); |
| 525 ServerNetworkStats stats1; |
| 526 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 527 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); |
| 528 |
| 529 // Run the task. |
| 530 base::RunLoop().RunUntilIdle(); |
| 531 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 532 |
| 533 const ServerNetworkStats* stats2 = |
| 534 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 535 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 536 } |
| 537 |
| 493 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 538 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
| 494 ExpectPrefsUpdate(); | 539 ExpectPrefsUpdate(); |
| 495 | 540 |
| 496 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 541 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 497 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 542 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 498 http_server_props_manager_->SetAlternateProtocol( | 543 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
| 499 spdy_server_mail, 443, net::NPN_SPDY_3, 1); | 544 NPN_SPDY_3, 1); |
| 500 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); | 545 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); |
| 546 ServerNetworkStats stats; |
| 547 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 548 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
| 501 | 549 |
| 502 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; | 550 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 503 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; | 551 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 504 const uint32 value1 = 31337; | 552 const uint32 value1 = 31337; |
| 505 http_server_props_manager_->SetSpdySetting( | 553 http_server_props_manager_->SetSpdySetting( |
| 506 spdy_server_mail, id1, flags1, value1); | 554 spdy_server_mail, id1, flags1, value1); |
| 507 | 555 |
| 508 // Run the task. | 556 // Run the task. |
| 509 base::RunLoop().RunUntilIdle(); | 557 base::RunLoop().RunUntilIdle(); |
| 510 | 558 |
| 511 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 559 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
| 512 EXPECT_TRUE( | 560 EXPECT_TRUE( |
| 513 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 561 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 514 net::SupportsQuic supports_quic = http_server_props_manager_->GetSupportsQuic( | 562 SupportsQuic supports_quic = |
| 515 spdy_server_mail); | 563 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
| 516 EXPECT_TRUE(supports_quic.used_quic); | 564 EXPECT_TRUE(supports_quic.used_quic); |
| 517 EXPECT_EQ("foo", supports_quic.address); | 565 EXPECT_EQ("foo", supports_quic.address); |
| 566 const ServerNetworkStats* stats1 = |
| 567 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 568 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
| 518 | 569 |
| 519 // Check SPDY settings values. | 570 // Check SPDY settings values. |
| 520 const net::SettingsMap& settings_map1_ret = | 571 const SettingsMap& settings_map1_ret = |
| 521 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 572 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 522 ASSERT_EQ(1U, settings_map1_ret.size()); | 573 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 523 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 574 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 524 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 575 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 525 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 576 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 526 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 577 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 527 EXPECT_EQ(value1, flags_and_value1_ret.second); | 578 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 528 | 579 |
| 529 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 580 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 530 | 581 |
| 531 ExpectPrefsUpdate(); | 582 ExpectPrefsUpdate(); |
| 532 | 583 |
| 533 // Clear http server data, time out if we do not get a completion callback. | 584 // Clear http server data, time out if we do not get a completion callback. |
| 534 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); | 585 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); |
| 535 base::RunLoop().Run(); | 586 base::RunLoop().Run(); |
| 536 | 587 |
| 537 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 588 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
| 538 EXPECT_FALSE( | 589 EXPECT_FALSE( |
| 539 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 590 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 540 net::SupportsQuic supports_quic1 = | 591 SupportsQuic supports_quic1 = |
| 541 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | 592 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
| 542 EXPECT_FALSE(supports_quic1.used_quic); | 593 EXPECT_FALSE(supports_quic1.used_quic); |
| 543 EXPECT_EQ("", supports_quic1.address); | 594 EXPECT_EQ("", supports_quic1.address); |
| 595 const ServerNetworkStats* stats2 = |
| 596 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 597 EXPECT_EQ(NULL, stats2); |
| 544 | 598 |
| 545 const net::SettingsMap& settings_map2_ret = | 599 const SettingsMap& settings_map2_ret = |
| 546 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 600 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 547 EXPECT_EQ(0U, settings_map2_ret.size()); | 601 EXPECT_EQ(0U, settings_map2_ret.size()); |
| 548 | 602 |
| 549 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 603 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 550 } | 604 } |
| 551 | 605 |
| 606 // crbug.com/444956: Add 200 alternate_protocol servers followed by |
| 607 // supports_quic and verify we have read supports_quic from prefs. |
| 608 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
| 609 ExpectCacheUpdate(); |
| 610 |
| 611 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 612 |
| 613 for (int i = 0; i < 200; ++i) { |
| 614 // Set up alternate_protocol for www.google.com:i. |
| 615 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 616 alternate_protocol->SetInteger("port", i); |
| 617 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 618 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 619 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
| 620 alternate_protocol); |
| 621 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), |
| 622 server_pref_dict); |
| 623 } |
| 624 |
| 625 // Set the preference for mail.google.com server. |
| 626 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 627 // Set up SupportsQuic for mail.google.com:80 |
| 628 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 629 supports_quic->SetBoolean("used_quic", true); |
| 630 supports_quic->SetString("address", "bar"); |
| 631 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic); |
| 632 |
| 633 // Set the server preference for mail.google.com:80. |
| 634 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
| 635 server_pref_dict1); |
| 636 |
| 637 base::DictionaryValue* http_server_properties_dict = |
| 638 new base::DictionaryValue; |
| 639 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 640 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 641 |
| 642 // Set up the pref. |
| 643 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 644 http_server_properties_dict); |
| 645 |
| 646 base::RunLoop().RunUntilIdle(); |
| 647 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 648 |
| 649 // Verify AlternateProtocol. |
| 650 for (int i = 0; i < 200; ++i) { |
| 651 std::string server = StringPrintf("www.google.com:%d", i); |
| 652 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( |
| 653 net::HostPortPair::FromString(server))); |
| 654 net::AlternateProtocolInfo port_alternate_protocol = |
| 655 http_server_props_manager_->GetAlternateProtocol( |
| 656 net::HostPortPair::FromString(server)); |
| 657 EXPECT_EQ(i, port_alternate_protocol.port); |
| 658 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); |
| 659 } |
| 660 |
| 661 // Verify SupportsQuic. |
| 662 net::SupportsQuic supports_quic1 = |
| 663 http_server_props_manager_->GetSupportsQuic( |
| 664 net::HostPortPair::FromString("mail.google.com:80")); |
| 665 EXPECT_TRUE(supports_quic1.used_quic); |
| 666 EXPECT_EQ("bar", supports_quic1.address); |
| 667 } |
| 668 |
| 552 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 669 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
| 553 // Post an update task to the UI thread. | 670 // Post an update task to the UI thread. |
| 554 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 671 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 555 // Shutdown comes before the task is executed. | 672 // Shutdown comes before the task is executed. |
| 556 http_server_props_manager_->ShutdownOnPrefThread(); | 673 http_server_props_manager_->ShutdownOnPrefThread(); |
| 557 http_server_props_manager_.reset(); | 674 http_server_props_manager_.reset(); |
| 558 // Run the task after shutdown and deletion. | 675 // Run the task after shutdown and deletion. |
| 559 base::RunLoop().RunUntilIdle(); | 676 base::RunLoop().RunUntilIdle(); |
| 560 } | 677 } |
| 561 | 678 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 // Run the task after shutdown, but before deletion. | 734 // Run the task after shutdown, but before deletion. |
| 618 base::RunLoop().RunUntilIdle(); | 735 base::RunLoop().RunUntilIdle(); |
| 619 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 736 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 620 http_server_props_manager_.reset(); | 737 http_server_props_manager_.reset(); |
| 621 base::RunLoop().RunUntilIdle(); | 738 base::RunLoop().RunUntilIdle(); |
| 622 } | 739 } |
| 623 | 740 |
| 624 } // namespace | 741 } // namespace |
| 625 | 742 |
| 626 } // namespace net | 743 } // namespace net |
| OLD | NEW |