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 "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 const int num_rows = static_cast<int>( | 266 const int num_rows = static_cast<int>( |
267 ceil(static_cast<float>(size) / sizeof_row)); | 267 ceil(static_cast<float>(size) / sizeof_row)); |
268 const int sizeof_data = num_rows * sizeof_row; | 268 const int sizeof_data = num_rows * sizeof_row; |
269 DCHECK(sizeof_data >= size); | 269 DCHECK(sizeof_data >= size); |
270 str->reserve(sizeof_data); | 270 str->reserve(sizeof_data); |
271 | 271 |
272 for (int i = 0; i < num_rows; ++i) | 272 for (int i = 0; i < num_rows; ++i) |
273 str->append(row, sizeof_row); | 273 str->append(row, sizeof_row); |
274 } | 274 } |
275 | 275 |
276 void SetAlternateProtocol( | |
277 HttpServerProperties* http_server_properties, | |
278 const HostPortPair& server, | |
279 uint16 alternate_port, | |
280 AlternateProtocol alternate_protocol) { | |
281 http_server_properties->SetAlternateProtocol( | |
282 server, alternate_port, alternate_protocol); | |
283 HttpStreamFactory::set_highest_supported_alternate_protocol( | |
willchan no longer on Chromium
2012/02/29 20:15:27
Using a global like this messes up the test depend
ramant (doing other things)
2012/03/01 03:51:59
Done.
| |
284 alternate_protocol); | |
285 } | |
286 | |
276 // Alternative functions that eliminate randomness and dependency on the local | 287 // Alternative functions that eliminate randomness and dependency on the local |
277 // host name so that the generated NTLM messages are reproducible. | 288 // host name so that the generated NTLM messages are reproducible. |
278 void MockGenerateRandom1(uint8* output, size_t n) { | 289 void MockGenerateRandom1(uint8* output, size_t n) { |
279 static const uint8 bytes[] = { | 290 static const uint8 bytes[] = { |
280 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 | 291 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
281 }; | 292 }; |
282 static size_t current_byte = 0; | 293 static size_t current_byte = 0; |
283 for (size_t i = 0; i < n; ++i) { | 294 for (size_t i = 0; i < n; ++i) { |
284 output[i] = bytes[current_byte++]; | 295 output[i] = bytes[current_byte++]; |
285 current_byte %= arraysize(bytes); | 296 current_byte %= arraysize(bytes); |
(...skipping 5311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5597 std::string expected_group_name; | 5608 std::string expected_group_name; |
5598 bool ssl; | 5609 bool ssl; |
5599 }; | 5610 }; |
5600 | 5611 |
5601 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( | 5612 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
5602 SessionDependencies* session_deps) { | 5613 SessionDependencies* session_deps) { |
5603 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps)); | 5614 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps)); |
5604 | 5615 |
5605 HttpServerProperties* http_server_properties = | 5616 HttpServerProperties* http_server_properties = |
5606 session->http_server_properties(); | 5617 session->http_server_properties(); |
5607 http_server_properties->SetAlternateProtocol( | 5618 SetAlternateProtocol(http_server_properties, |
5608 HostPortPair("host.with.alternate", 80), 443, | 5619 HostPortPair("host.with.alternate", 80), |
5609 NPN_SPDY_21); | 5620 443, |
5610 | 5621 NPN_SPDY_21); |
5611 return session; | 5622 return session; |
5612 } | 5623 } |
5613 | 5624 |
5614 int GroupNameTransactionHelper( | 5625 int GroupNameTransactionHelper( |
5615 const std::string& url, | 5626 const std::string& url, |
5616 const scoped_refptr<HttpNetworkSession>& session) { | 5627 const scoped_refptr<HttpNetworkSession>& session) { |
5617 HttpRequestInfo request; | 5628 HttpRequestInfo request; |
5618 request.method = "GET"; | 5629 request.method = "GET"; |
5619 request.url = GURL(url); | 5630 request.url = GURL(url); |
5620 request.load_flags = 0; | 5631 request.load_flags = 0; |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6545 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); | 6556 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
6546 const PortAlternateProtocolPair alternate = | 6557 const PortAlternateProtocolPair alternate = |
6547 http_server_properties.GetAlternateProtocol(http_host_port_pair); | 6558 http_server_properties.GetAlternateProtocol(http_host_port_pair); |
6548 PortAlternateProtocolPair expected_alternate; | 6559 PortAlternateProtocolPair expected_alternate; |
6549 expected_alternate.port = 443; | 6560 expected_alternate.port = 443; |
6550 expected_alternate.protocol = NPN_SPDY_21; | 6561 expected_alternate.protocol = NPN_SPDY_21; |
6551 EXPECT_TRUE(expected_alternate.Equals(alternate)); | 6562 EXPECT_TRUE(expected_alternate.Equals(alternate)); |
6552 | 6563 |
6553 HttpStreamFactory::set_use_alternate_protocols(false); | 6564 HttpStreamFactory::set_use_alternate_protocols(false); |
6554 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 6565 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
6566 HttpStreamFactory::set_highest_supported_alternate_protocol(NPN_SPDY_21); | |
6555 } | 6567 } |
6556 | 6568 |
6557 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { | 6569 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
6558 HttpStreamFactory::set_use_alternate_protocols(true); | 6570 HttpStreamFactory::set_use_alternate_protocols(true); |
6559 SessionDependencies session_deps; | 6571 SessionDependencies session_deps; |
6560 | 6572 |
6561 HttpRequestInfo request; | 6573 HttpRequestInfo request; |
6562 request.method = "GET"; | 6574 request.method = "GET"; |
6563 request.url = GURL("http://www.google.com/"); | 6575 request.url = GURL("http://www.google.com/"); |
6564 request.load_flags = 0; | 6576 request.load_flags = 0; |
(...skipping 11 matching lines...) Expand all Loading... | |
6576 StaticSocketDataProvider second_data( | 6588 StaticSocketDataProvider second_data( |
6577 data_reads, arraysize(data_reads), NULL, 0); | 6589 data_reads, arraysize(data_reads), NULL, 0); |
6578 session_deps.socket_factory.AddSocketDataProvider(&second_data); | 6590 session_deps.socket_factory.AddSocketDataProvider(&second_data); |
6579 | 6591 |
6580 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 6592 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
6581 | 6593 |
6582 HttpServerProperties* http_server_properties = | 6594 HttpServerProperties* http_server_properties = |
6583 session->http_server_properties(); | 6595 session->http_server_properties(); |
6584 // Port must be < 1024, or the header will be ignored (since initial port was | 6596 // Port must be < 1024, or the header will be ignored (since initial port was |
6585 // port 80 (another restricted port). | 6597 // port 80 (another restricted port). |
6586 http_server_properties->SetAlternateProtocol( | 6598 SetAlternateProtocol(http_server_properties, |
6587 HostPortPair::FromURL(request.url), | 6599 HostPortPair::FromURL(request.url), |
6588 666 /* port is ignored by MockConnect anyway */, | 6600 666 /* port is ignored by MockConnect anyway */, |
6589 NPN_SPDY_21); | 6601 NPN_SPDY_21); |
6590 | 6602 |
6591 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 6603 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
6592 TestCompletionCallback callback; | 6604 TestCompletionCallback callback; |
6593 | 6605 |
6594 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6606 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
6595 EXPECT_EQ(ERR_IO_PENDING, rv); | 6607 EXPECT_EQ(ERR_IO_PENDING, rv); |
6596 EXPECT_EQ(OK, callback.WaitForResult()); | 6608 EXPECT_EQ(OK, callback.WaitForResult()); |
6597 | 6609 |
6598 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6610 const HttpResponseInfo* response = trans->GetResponseInfo(); |
6599 ASSERT_TRUE(response != NULL); | 6611 ASSERT_TRUE(response != NULL); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6638 }; | 6650 }; |
6639 StaticSocketDataProvider second_data( | 6651 StaticSocketDataProvider second_data( |
6640 data_reads, arraysize(data_reads), NULL, 0); | 6652 data_reads, arraysize(data_reads), NULL, 0); |
6641 session_deps.socket_factory.AddSocketDataProvider(&second_data); | 6653 session_deps.socket_factory.AddSocketDataProvider(&second_data); |
6642 | 6654 |
6643 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 6655 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
6644 | 6656 |
6645 HttpServerProperties* http_server_properties = | 6657 HttpServerProperties* http_server_properties = |
6646 session->http_server_properties(); | 6658 session->http_server_properties(); |
6647 const int kUnrestrictedAlternatePort = 1024; | 6659 const int kUnrestrictedAlternatePort = 1024; |
6648 http_server_properties->SetAlternateProtocol( | 6660 SetAlternateProtocol(http_server_properties, |
6649 HostPortPair::FromURL(restricted_port_request.url), | 6661 HostPortPair::FromURL(restricted_port_request.url), |
6650 kUnrestrictedAlternatePort, | 6662 kUnrestrictedAlternatePort, |
6651 NPN_SPDY_21); | 6663 NPN_SPDY_21); |
6652 | 6664 |
6653 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 6665 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
6654 TestCompletionCallback callback; | 6666 TestCompletionCallback callback; |
6655 | 6667 |
6656 int rv = trans->Start( | 6668 int rv = trans->Start( |
6657 &restricted_port_request, callback.callback(), BoundNetLog()); | 6669 &restricted_port_request, callback.callback(), BoundNetLog()); |
6658 EXPECT_EQ(ERR_IO_PENDING, rv); | 6670 EXPECT_EQ(ERR_IO_PENDING, rv); |
6659 // Invalid change to unrestricted port should fail. | 6671 // Invalid change to unrestricted port should fail. |
6660 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); | 6672 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
6661 | 6673 |
(...skipping 25 matching lines...) Expand all Loading... | |
6687 }; | 6699 }; |
6688 StaticSocketDataProvider second_data( | 6700 StaticSocketDataProvider second_data( |
6689 data_reads, arraysize(data_reads), NULL, 0); | 6701 data_reads, arraysize(data_reads), NULL, 0); |
6690 session_deps.socket_factory.AddSocketDataProvider(&second_data); | 6702 session_deps.socket_factory.AddSocketDataProvider(&second_data); |
6691 | 6703 |
6692 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 6704 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
6693 | 6705 |
6694 HttpServerProperties* http_server_properties = | 6706 HttpServerProperties* http_server_properties = |
6695 session->http_server_properties(); | 6707 session->http_server_properties(); |
6696 const int kRestrictedAlternatePort = 80; | 6708 const int kRestrictedAlternatePort = 80; |
6697 http_server_properties->SetAlternateProtocol( | 6709 SetAlternateProtocol(http_server_properties, |
6698 HostPortPair::FromURL(restricted_port_request.url), | 6710 HostPortPair::FromURL(restricted_port_request.url), |
6699 kRestrictedAlternatePort, | 6711 kRestrictedAlternatePort, |
6700 NPN_SPDY_21); | 6712 NPN_SPDY_21); |
6701 | 6713 |
6702 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 6714 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
6703 TestCompletionCallback callback; | 6715 TestCompletionCallback callback; |
6704 | 6716 |
6705 int rv = trans->Start( | 6717 int rv = trans->Start( |
6706 &restricted_port_request, callback.callback(), BoundNetLog()); | 6718 &restricted_port_request, callback.callback(), BoundNetLog()); |
6707 EXPECT_EQ(ERR_IO_PENDING, rv); | 6719 EXPECT_EQ(ERR_IO_PENDING, rv); |
6708 // Valid change to restricted port should pass. | 6720 // Valid change to restricted port should pass. |
6709 EXPECT_EQ(OK, callback.WaitForResult()); | 6721 EXPECT_EQ(OK, callback.WaitForResult()); |
6710 | 6722 |
(...skipping 25 matching lines...) Expand all Loading... | |
6736 }; | 6748 }; |
6737 StaticSocketDataProvider second_data( | 6749 StaticSocketDataProvider second_data( |
6738 data_reads, arraysize(data_reads), NULL, 0); | 6750 data_reads, arraysize(data_reads), NULL, 0); |
6739 session_deps.socket_factory.AddSocketDataProvider(&second_data); | 6751 session_deps.socket_factory.AddSocketDataProvider(&second_data); |
6740 | 6752 |
6741 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 6753 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
6742 | 6754 |
6743 HttpServerProperties* http_server_properties = | 6755 HttpServerProperties* http_server_properties = |
6744 session->http_server_properties(); | 6756 session->http_server_properties(); |
6745 const int kRestrictedAlternatePort = 80; | 6757 const int kRestrictedAlternatePort = 80; |
6746 http_server_properties->SetAlternateProtocol( | 6758 SetAlternateProtocol(http_server_properties, |
6747 HostPortPair::FromURL(unrestricted_port_request.url), | 6759 HostPortPair::FromURL(unrestricted_port_request.url), |
6748 kRestrictedAlternatePort, | 6760 kRestrictedAlternatePort, |
6749 NPN_SPDY_21); | 6761 NPN_SPDY_21); |
6750 | 6762 |
6751 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 6763 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
6752 TestCompletionCallback callback; | 6764 TestCompletionCallback callback; |
6753 | 6765 |
6754 int rv = trans->Start( | 6766 int rv = trans->Start( |
6755 &unrestricted_port_request, callback.callback(), BoundNetLog()); | 6767 &unrestricted_port_request, callback.callback(), BoundNetLog()); |
6756 EXPECT_EQ(ERR_IO_PENDING, rv); | 6768 EXPECT_EQ(ERR_IO_PENDING, rv); |
6757 // Valid change to restricted port should pass. | 6769 // Valid change to restricted port should pass. |
6758 EXPECT_EQ(OK, callback.WaitForResult()); | 6770 EXPECT_EQ(OK, callback.WaitForResult()); |
6759 | 6771 |
(...skipping 25 matching lines...) Expand all Loading... | |
6785 }; | 6797 }; |
6786 StaticSocketDataProvider second_data( | 6798 StaticSocketDataProvider second_data( |
6787 data_reads, arraysize(data_reads), NULL, 0); | 6799 data_reads, arraysize(data_reads), NULL, 0); |
6788 session_deps.socket_factory.AddSocketDataProvider(&second_data); | 6800 session_deps.socket_factory.AddSocketDataProvider(&second_data); |
6789 | 6801 |
6790 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 6802 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
6791 | 6803 |
6792 HttpServerProperties* http_server_properties = | 6804 HttpServerProperties* http_server_properties = |
6793 session->http_server_properties(); | 6805 session->http_server_properties(); |
6794 const int kUnrestrictedAlternatePort = 1024; | 6806 const int kUnrestrictedAlternatePort = 1024; |
6795 http_server_properties->SetAlternateProtocol( | 6807 SetAlternateProtocol(http_server_properties, |
6796 HostPortPair::FromURL(unrestricted_port_request.url), | 6808 HostPortPair::FromURL(unrestricted_port_request.url), |
6797 kUnrestrictedAlternatePort, | 6809 kUnrestrictedAlternatePort, |
6798 NPN_SPDY_21); | 6810 NPN_SPDY_21); |
6799 | 6811 |
6800 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 6812 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
6801 TestCompletionCallback callback; | 6813 TestCompletionCallback callback; |
6802 | 6814 |
6803 int rv = trans->Start( | 6815 int rv = trans->Start( |
6804 &unrestricted_port_request, callback.callback(), BoundNetLog()); | 6816 &unrestricted_port_request, callback.callback(), BoundNetLog()); |
6805 EXPECT_EQ(ERR_IO_PENDING, rv); | 6817 EXPECT_EQ(ERR_IO_PENDING, rv); |
6806 // Valid change to an unrestricted port should pass. | 6818 // Valid change to an unrestricted port should pass. |
6807 EXPECT_EQ(OK, callback.WaitForResult()); | 6819 EXPECT_EQ(OK, callback.WaitForResult()); |
6808 | 6820 |
(...skipping 21 matching lines...) Expand all Loading... | |
6830 }; | 6842 }; |
6831 StaticSocketDataProvider data( | 6843 StaticSocketDataProvider data( |
6832 data_reads, arraysize(data_reads), NULL, 0); | 6844 data_reads, arraysize(data_reads), NULL, 0); |
6833 session_deps.socket_factory.AddSocketDataProvider(&data); | 6845 session_deps.socket_factory.AddSocketDataProvider(&data); |
6834 | 6846 |
6835 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 6847 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
6836 | 6848 |
6837 HttpServerProperties* http_server_properties = | 6849 HttpServerProperties* http_server_properties = |
6838 session->http_server_properties(); | 6850 session->http_server_properties(); |
6839 const int kUnsafePort = 7; | 6851 const int kUnsafePort = 7; |
6840 http_server_properties->SetAlternateProtocol( | 6852 SetAlternateProtocol(http_server_properties, |
6841 HostPortPair::FromURL(request.url), | 6853 HostPortPair::FromURL(request.url), |
6842 kUnsafePort, | 6854 kUnsafePort, |
6843 NPN_SPDY_2); | 6855 NPN_SPDY_21); |
6844 | 6856 |
6845 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 6857 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
6846 TestCompletionCallback callback; | 6858 TestCompletionCallback callback; |
6847 | 6859 |
6848 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6860 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
6849 EXPECT_EQ(ERR_IO_PENDING, rv); | 6861 EXPECT_EQ(ERR_IO_PENDING, rv); |
6850 // The HTTP request should succeed. | 6862 // The HTTP request should succeed. |
6851 EXPECT_EQ(OK, callback.WaitForResult()); | 6863 EXPECT_EQ(OK, callback.WaitForResult()); |
6852 | 6864 |
6853 // Disable alternate protocol before the asserts. | 6865 // Disable alternate protocol before the asserts. |
(...skipping 2486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9340 StaticSocketDataProvider* data[] = { &data1, &data2 }; | 9352 StaticSocketDataProvider* data[] = { &data1, &data2 }; |
9341 | 9353 |
9342 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); | 9354 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
9343 | 9355 |
9344 EXPECT_EQ(OK, out.rv); | 9356 EXPECT_EQ(OK, out.rv); |
9345 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | 9357 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
9346 EXPECT_EQ("hello world", out.response_data); | 9358 EXPECT_EQ("hello world", out.response_data); |
9347 } | 9359 } |
9348 | 9360 |
9349 } // namespace net | 9361 } // namespace net |
OLD | NEW |