OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/http_server_properties_manager.h" | 5 #include "chrome/browser/net/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" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // it twice. Only expect a single cache update. | 145 // it twice. Only expect a single cache update. |
146 | 146 |
147 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 147 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
148 | 148 |
149 // Set supports_spdy for www.google.com:80. | 149 // Set supports_spdy for www.google.com:80. |
150 server_pref_dict->SetBoolean("supports_spdy", true); | 150 server_pref_dict->SetBoolean("supports_spdy", true); |
151 | 151 |
152 // Set up alternate_protocol for www.google.com:80. | 152 // Set up alternate_protocol for www.google.com:80. |
153 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 153 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
154 alternate_protocol->SetInteger("port", 443); | 154 alternate_protocol->SetInteger("port", 443); |
155 alternate_protocol->SetString("protocol_str", "npn-spdy/2"); | 155 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
156 server_pref_dict->SetWithoutPathExpansion( | 156 server_pref_dict->SetWithoutPathExpansion( |
157 "alternate_protocol", alternate_protocol); | 157 "alternate_protocol", alternate_protocol); |
158 | 158 |
159 // Set pipeline capability for www.google.com:80. | 159 // Set pipeline capability for www.google.com:80. |
160 server_pref_dict->SetInteger("pipeline_capability", net::PIPELINE_CAPABLE); | 160 server_pref_dict->SetInteger("pipeline_capability", net::PIPELINE_CAPABLE); |
161 | 161 |
162 // Set the server preference for www.google.com:80. | 162 // Set the server preference for www.google.com:80. |
163 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 163 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
164 servers_dict->SetWithoutPathExpansion( | 164 servers_dict->SetWithoutPathExpansion( |
165 "www.google.com:80", server_pref_dict); | 165 "www.google.com:80", server_pref_dict); |
166 | 166 |
167 // Set the preference for mail.google.com server. | 167 // Set the preference for mail.google.com server. |
168 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 168 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
169 | 169 |
170 // Set supports_spdy for mail.google.com:80 | 170 // Set supports_spdy for mail.google.com:80 |
171 server_pref_dict1->SetBoolean("supports_spdy", true); | 171 server_pref_dict1->SetBoolean("supports_spdy", true); |
172 | 172 |
173 // Set up alternate_protocol for mail.google.com:80 | 173 // Set up alternate_protocol for mail.google.com:80 |
174 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 174 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
175 alternate_protocol1->SetInteger("port", 444); | 175 alternate_protocol1->SetInteger("port", 444); |
176 alternate_protocol1->SetString("protocol_str", "npn-spdy/3"); | 176 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); |
177 | 177 |
178 server_pref_dict1->SetWithoutPathExpansion( | 178 server_pref_dict1->SetWithoutPathExpansion( |
179 "alternate_protocol", alternate_protocol1); | 179 "alternate_protocol", alternate_protocol1); |
180 | 180 |
181 // Set pipelining capability for mail.google.com:80 | 181 // Set pipelining capability for mail.google.com:80 |
182 server_pref_dict1->SetInteger("pipeline_capability", net::PIPELINE_INCAPABLE); | 182 server_pref_dict1->SetInteger("pipeline_capability", net::PIPELINE_INCAPABLE); |
183 | 183 |
184 // Set the server preference for mail.google.com:80. | 184 // Set the server preference for mail.google.com:80. |
185 servers_dict->SetWithoutPathExpansion( | 185 servers_dict->SetWithoutPathExpansion( |
186 "mail.google.com:80", server_pref_dict1); | 186 "mail.google.com:80", server_pref_dict1); |
(...skipping 24 matching lines...) Expand all Loading... |
211 | 211 |
212 // Verify AlternateProtocol. | 212 // Verify AlternateProtocol. |
213 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | 213 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( |
214 net::HostPortPair::FromString("www.google.com:80"))); | 214 net::HostPortPair::FromString("www.google.com:80"))); |
215 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | 215 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( |
216 net::HostPortPair::FromString("mail.google.com:80"))); | 216 net::HostPortPair::FromString("mail.google.com:80"))); |
217 net::PortAlternateProtocolPair port_alternate_protocol = | 217 net::PortAlternateProtocolPair port_alternate_protocol = |
218 http_server_props_manager_->GetAlternateProtocol( | 218 http_server_props_manager_->GetAlternateProtocol( |
219 net::HostPortPair::FromString("www.google.com:80")); | 219 net::HostPortPair::FromString("www.google.com:80")); |
220 EXPECT_EQ(443, port_alternate_protocol.port); | 220 EXPECT_EQ(443, port_alternate_protocol.port); |
221 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); | 221 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); |
222 port_alternate_protocol = | 222 port_alternate_protocol = |
223 http_server_props_manager_->GetAlternateProtocol( | 223 http_server_props_manager_->GetAlternateProtocol( |
224 net::HostPortPair::FromString("mail.google.com:80")); | 224 net::HostPortPair::FromString("mail.google.com:80")); |
225 EXPECT_EQ(444, port_alternate_protocol.port); | 225 EXPECT_EQ(444, port_alternate_protocol.port); |
226 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 226 EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol); |
227 | 227 |
228 // Verify pipeline capability. | 228 // Verify pipeline capability. |
229 EXPECT_EQ(net::PIPELINE_CAPABLE, | 229 EXPECT_EQ(net::PIPELINE_CAPABLE, |
230 http_server_props_manager_->GetPipelineCapability( | 230 http_server_props_manager_->GetPipelineCapability( |
231 net::HostPortPair::FromString("www.google.com:80"))); | 231 net::HostPortPair::FromString("www.google.com:80"))); |
232 EXPECT_EQ(net::PIPELINE_INCAPABLE, | 232 EXPECT_EQ(net::PIPELINE_INCAPABLE, |
233 http_server_props_manager_->GetPipelineCapability( | 233 http_server_props_manager_->GetPipelineCapability( |
234 net::HostPortPair::FromString("mail.google.com:80"))); | 234 net::HostPortPair::FromString("mail.google.com:80"))); |
235 } | 235 } |
236 | 236 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 353 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
354 } | 354 } |
355 | 355 |
356 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { | 356 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { |
357 ExpectPrefsUpdate(); | 357 ExpectPrefsUpdate(); |
358 | 358 |
359 net::HostPortPair spdy_server_mail("mail.google.com", 80); | 359 net::HostPortPair spdy_server_mail("mail.google.com", 80); |
360 EXPECT_FALSE( | 360 EXPECT_FALSE( |
361 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 361 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
362 http_server_props_manager_->SetAlternateProtocol( | 362 http_server_props_manager_->SetAlternateProtocol( |
363 spdy_server_mail, 443, net::NPN_SPDY_2); | 363 spdy_server_mail, 443, net::NPN_SPDY_3); |
364 | 364 |
365 // Run the task. | 365 // Run the task. |
366 loop_.RunUntilIdle(); | 366 loop_.RunUntilIdle(); |
367 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 367 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
368 | 368 |
369 ASSERT_TRUE( | 369 ASSERT_TRUE( |
370 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 370 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
371 net::PortAlternateProtocolPair port_alternate_protocol = | 371 net::PortAlternateProtocolPair port_alternate_protocol = |
372 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 372 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
373 EXPECT_EQ(443, port_alternate_protocol.port); | 373 EXPECT_EQ(443, port_alternate_protocol.port); |
374 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); | 374 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); |
375 } | 375 } |
376 | 376 |
377 TEST_F(HttpServerPropertiesManagerTest, PipelineCapability) { | 377 TEST_F(HttpServerPropertiesManagerTest, PipelineCapability) { |
378 ExpectPrefsUpdate(); | 378 ExpectPrefsUpdate(); |
379 | 379 |
380 net::HostPortPair known_pipeliner("pipeline.com", 8080); | 380 net::HostPortPair known_pipeliner("pipeline.com", 8080); |
381 net::HostPortPair bad_pipeliner("wordpress.com", 80); | 381 net::HostPortPair bad_pipeliner("wordpress.com", 80); |
382 EXPECT_EQ(net::PIPELINE_UNKNOWN, | 382 EXPECT_EQ(net::PIPELINE_UNKNOWN, |
383 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | 383 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); |
384 EXPECT_EQ(net::PIPELINE_UNKNOWN, | 384 EXPECT_EQ(net::PIPELINE_UNKNOWN, |
(...skipping 15 matching lines...) Expand all Loading... |
400 http_server_props_manager_->GetPipelineCapability(bad_pipeliner)); | 400 http_server_props_manager_->GetPipelineCapability(bad_pipeliner)); |
401 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 401 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
402 } | 402 } |
403 | 403 |
404 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 404 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
405 ExpectPrefsUpdate(); | 405 ExpectPrefsUpdate(); |
406 | 406 |
407 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 407 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
408 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 408 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
409 http_server_props_manager_->SetAlternateProtocol( | 409 http_server_props_manager_->SetAlternateProtocol( |
410 spdy_server_mail, 443, net::NPN_SPDY_2); | 410 spdy_server_mail, 443, net::NPN_SPDY_3); |
411 | 411 |
412 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; | 412 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; |
413 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; | 413 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; |
414 const uint32 value1 = 31337; | 414 const uint32 value1 = 31337; |
415 http_server_props_manager_->SetSpdySetting( | 415 http_server_props_manager_->SetSpdySetting( |
416 spdy_server_mail, id1, flags1, value1); | 416 spdy_server_mail, id1, flags1, value1); |
417 | 417 |
418 net::HostPortPair known_pipeliner("pipeline.com", 8080); | 418 net::HostPortPair known_pipeliner("pipeline.com", 8080); |
419 http_server_props_manager_->SetPipelineCapability(known_pipeliner, | 419 http_server_props_manager_->SetPipelineCapability(known_pipeliner, |
420 net::PIPELINE_CAPABLE); | 420 net::PIPELINE_CAPABLE); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 // Run the task after shutdown, but before deletion. | 528 // Run the task after shutdown, but before deletion. |
529 loop_.RunUntilIdle(); | 529 loop_.RunUntilIdle(); |
530 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 530 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
531 http_server_props_manager_.reset(); | 531 http_server_props_manager_.reset(); |
532 loop_.RunUntilIdle(); | 532 loop_.RunUntilIdle(); |
533 } | 533 } |
534 | 534 |
535 } // namespace | 535 } // namespace |
536 | 536 |
537 } // namespace chrome_browser_net | 537 } // namespace chrome_browser_net |
OLD | NEW |