OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 arraysize(data_reads)); | 736 arraysize(data_reads)); |
737 EXPECT_EQ(OK, out.rv); | 737 EXPECT_EQ(OK, out.rv); |
738 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); | 738 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
739 EXPECT_EQ("", out.response_data); | 739 EXPECT_EQ("", out.response_data); |
740 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 740 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
741 int64 response_size = reads_size - strlen(junk); | 741 int64 response_size = reads_size - strlen(junk); |
742 EXPECT_EQ(response_size, out.totalReceivedBytes); | 742 EXPECT_EQ(response_size, out.totalReceivedBytes); |
743 } | 743 } |
744 | 744 |
745 // A simple request using chunked encoding with some extra data after. | 745 // A simple request using chunked encoding with some extra data after. |
746 // (Like might be seen in a pipelined response.) | |
747 TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { | 746 TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
748 std::string final_chunk = "0\r\n\r\n"; | 747 std::string final_chunk = "0\r\n\r\n"; |
749 std::string extra_data = "HTTP/1.1 200 OK\r\n"; | 748 std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
750 std::string last_read = final_chunk + extra_data; | 749 std::string last_read = final_chunk + extra_data; |
751 MockRead data_reads[] = { | 750 MockRead data_reads[] = { |
752 MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), | 751 MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
753 MockRead("5\r\nHello\r\n"), | 752 MockRead("5\r\nHello\r\n"), |
754 MockRead("1\r\n"), | 753 MockRead("1\r\n"), |
755 MockRead(" \r\n"), | 754 MockRead(" \r\n"), |
756 MockRead("5\r\nworld\r\n"), | 755 MockRead("5\r\nworld\r\n"), |
(...skipping 10418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11175 ASSERT_TRUE(response->headers.get() != NULL); | 11174 ASSERT_TRUE(response->headers.get() != NULL); |
11176 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 11175 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
11177 EXPECT_TRUE(response->was_fetched_via_spdy); | 11176 EXPECT_TRUE(response->was_fetched_via_spdy); |
11178 EXPECT_TRUE(response->was_npn_negotiated); | 11177 EXPECT_TRUE(response->was_npn_negotiated); |
11179 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | 11178 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
11180 EXPECT_EQ("hello!", response_data); | 11179 EXPECT_EQ("hello!", response_data); |
11181 #endif | 11180 #endif |
11182 } | 11181 } |
11183 #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration | 11182 #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration |
11184 | 11183 |
11185 TEST_P(HttpNetworkTransactionTest, ReadPipelineEvictionFallback) { | |
11186 MockRead data_reads1[] = { | |
11187 MockRead(SYNCHRONOUS, ERR_PIPELINE_EVICTION), | |
11188 }; | |
11189 MockRead data_reads2[] = { | |
11190 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
11191 MockRead("hello world"), | |
11192 MockRead(SYNCHRONOUS, OK), | |
11193 }; | |
11194 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), NULL, 0); | |
11195 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), NULL, 0); | |
11196 StaticSocketDataProvider* data[] = { &data1, &data2 }; | |
11197 | |
11198 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); | |
11199 | |
11200 EXPECT_EQ(OK, out.rv); | |
11201 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | |
11202 EXPECT_EQ("hello world", out.response_data); | |
11203 } | |
11204 | |
11205 TEST_P(HttpNetworkTransactionTest, SendPipelineEvictionFallback) { | |
11206 MockWrite data_writes1[] = { | |
11207 MockWrite(SYNCHRONOUS, ERR_PIPELINE_EVICTION), | |
11208 }; | |
11209 MockWrite data_writes2[] = { | |
11210 MockWrite("GET / HTTP/1.1\r\n" | |
11211 "Host: www.google.com\r\n" | |
11212 "Connection: keep-alive\r\n\r\n"), | |
11213 }; | |
11214 MockRead data_reads2[] = { | |
11215 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | |
11216 MockRead("hello world"), | |
11217 MockRead(SYNCHRONOUS, OK), | |
11218 }; | |
11219 StaticSocketDataProvider data1(NULL, 0, | |
11220 data_writes1, arraysize(data_writes1)); | |
11221 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
11222 data_writes2, arraysize(data_writes2)); | |
11223 StaticSocketDataProvider* data[] = { &data1, &data2 }; | |
11224 | |
11225 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); | |
11226 | |
11227 EXPECT_EQ(OK, out.rv); | |
11228 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | |
11229 EXPECT_EQ("hello world", out.response_data); | |
11230 } | |
11231 | |
11232 TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { | 11184 TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
11233 const std::string https_url = "https://www.google.com/"; | 11185 const std::string https_url = "https://www.google.com/"; |
11234 const std::string http_url = "http://www.google.com:443/"; | 11186 const std::string http_url = "http://www.google.com:443/"; |
11235 | 11187 |
11236 // SPDY GET for HTTPS URL | 11188 // SPDY GET for HTTPS URL |
11237 scoped_ptr<SpdyFrame> req1( | 11189 scoped_ptr<SpdyFrame> req1( |
11238 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); | 11190 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
11239 | 11191 |
11240 MockWrite writes1[] = { | 11192 MockWrite writes1[] = { |
11241 CreateMockWrite(*req1, 0), | 11193 CreateMockWrite(*req1, 0), |
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12333 } | 12285 } |
12334 | 12286 |
12335 virtual void PreconnectStreams(int num_streams, | 12287 virtual void PreconnectStreams(int num_streams, |
12336 const HttpRequestInfo& info, | 12288 const HttpRequestInfo& info, |
12337 RequestPriority priority, | 12289 RequestPriority priority, |
12338 const SSLConfig& server_ssl_config, | 12290 const SSLConfig& server_ssl_config, |
12339 const SSLConfig& proxy_ssl_config) OVERRIDE { | 12291 const SSLConfig& proxy_ssl_config) OVERRIDE { |
12340 ADD_FAILURE(); | 12292 ADD_FAILURE(); |
12341 } | 12293 } |
12342 | 12294 |
12343 virtual base::Value* PipelineInfoToValue() const OVERRIDE { | |
12344 ADD_FAILURE(); | |
12345 return NULL; | |
12346 } | |
12347 | |
12348 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE { | 12295 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE { |
12349 ADD_FAILURE(); | 12296 ADD_FAILURE(); |
12350 return NULL; | 12297 return NULL; |
12351 } | 12298 } |
12352 | 12299 |
12353 private: | 12300 private: |
12354 base::WeakPtr<FakeStreamRequest> last_stream_request_; | 12301 base::WeakPtr<FakeStreamRequest> last_stream_request_; |
12355 | 12302 |
12356 DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); | 12303 DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
12357 }; | 12304 }; |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13133 EXPECT_EQ(ERR_IO_PENDING, rv); | 13080 EXPECT_EQ(ERR_IO_PENDING, rv); |
13134 | 13081 |
13135 rv = callback.WaitForResult(); | 13082 rv = callback.WaitForResult(); |
13136 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 13083 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
13137 | 13084 |
13138 const HttpResponseInfo* response = trans->GetResponseInfo(); | 13085 const HttpResponseInfo* response = trans->GetResponseInfo(); |
13139 EXPECT_TRUE(response == NULL); | 13086 EXPECT_TRUE(response == NULL); |
13140 } | 13087 } |
13141 | 13088 |
13142 } // namespace net | 13089 } // namespace net |
OLD | NEW |