Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 126 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 127 &delegate) | 127 &delegate) |
| 128 .Pass(); | 128 .Pass(); |
| 129 | 129 |
| 130 request->Start(); | 130 request->Start(); |
| 131 ASSERT_TRUE(request->is_pending()); | 131 ASSERT_TRUE(request->is_pending()); |
| 132 base::RunLoop().Run(); | 132 base::RunLoop().Run(); |
| 133 | 133 |
| 134 EXPECT_TRUE(request->status().is_success()); | 134 EXPECT_TRUE(request->status().is_success()); |
| 135 EXPECT_EQ(12, request->received_response_content_length()); | 135 EXPECT_EQ(12, request->received_response_content_length()); |
| 136 EXPECT_EQ(51, network_delegate_.total_network_bytes_received()); | |
| 136 } | 137 } |
| 137 | 138 |
| 138 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthAbortedRequest) { | 139 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthAbortedRequest) { |
| 139 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 140 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 140 "Content-Length: 20\r\n\r\n"), | 141 "Content-Length: 20\r\n\r\n"), |
| 141 MockRead("Test Content"), | 142 MockRead("Test Content"), |
| 142 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; | 143 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; |
| 143 | 144 |
| 144 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); | 145 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); |
| 145 socket_factory_.AddSocketDataProvider(&socket_data); | 146 socket_factory_.AddSocketDataProvider(&socket_data); |
| 146 | 147 |
| 147 TestDelegate delegate; | 148 TestDelegate delegate; |
| 148 scoped_ptr<URLRequest> request = | 149 scoped_ptr<URLRequest> request = |
| 149 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 150 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 150 &delegate) | 151 &delegate) |
| 151 .Pass(); | 152 .Pass(); |
| 152 | 153 |
| 153 request->Start(); | 154 request->Start(); |
| 154 ASSERT_TRUE(request->is_pending()); | 155 ASSERT_TRUE(request->is_pending()); |
| 155 base::RunLoop().Run(); | 156 base::RunLoop().Run(); |
| 156 | 157 |
| 157 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); | 158 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); |
| 158 EXPECT_EQ(12, request->received_response_content_length()); | 159 EXPECT_EQ(12, request->received_response_content_length()); |
| 160 EXPECT_EQ(51, network_delegate_.total_network_bytes_received()); | |
|
tbansal1
2015/08/18 00:49:49
nit and optional:
It is not clear where 51 is com
sclittle
2015/08/18 18:06:16
The 51 is actually quite a bit more than headers.l
| |
| 159 } | 161 } |
| 160 | 162 |
| 161 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 163 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 162 TestContentLengthCancelledRequest) { | 164 TestContentLengthCancelledRequest) { |
| 163 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 165 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 164 "Content-Length: 20\r\n\r\n"), | 166 "Content-Length: 20\r\n\r\n"), |
| 165 MockRead("Test Content"), | 167 MockRead("Test Content"), |
| 166 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; | 168 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; |
| 167 | 169 |
| 168 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); | 170 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); |
| 169 socket_factory_.AddSocketDataProvider(&socket_data); | 171 socket_factory_.AddSocketDataProvider(&socket_data); |
| 170 | 172 |
| 171 TestDelegate delegate; | 173 TestDelegate delegate; |
| 172 scoped_ptr<URLRequest> request = | 174 scoped_ptr<URLRequest> request = |
| 173 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 175 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 174 &delegate) | 176 &delegate) |
| 175 .Pass(); | 177 .Pass(); |
| 176 | 178 |
| 179 delegate.set_cancel_in_received_data(true); | |
| 180 request->Start(); | |
| 181 base::RunLoop().RunUntilIdle(); | |
| 182 | |
| 183 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); | |
| 184 EXPECT_EQ(12, request->received_response_content_length()); | |
| 185 EXPECT_EQ(51, network_delegate_.total_network_bytes_received()); | |
| 186 } | |
| 187 | |
| 188 TEST_F(URLRequestHttpJobWithMockSocketsTest, | |
| 189 TestNetworkBytesRedirectedRequest) { | |
| 190 MockRead redirect_read( | |
| 191 "HTTP/1.1 302 Found\r\n" | |
| 192 "Location: http://www.example.com\r\n\r\n"); | |
| 193 StaticSocketDataProvider redirect_socket_data(&redirect_read, 1, nullptr, 0); | |
| 194 socket_factory_.AddSocketDataProvider(&redirect_socket_data); | |
| 195 | |
| 196 MockRead response_reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | |
| 197 "Content-Length: 12\r\n\r\n"), | |
| 198 MockRead("Test Content")}; | |
| 199 StaticSocketDataProvider response_socket_data( | |
| 200 response_reads, arraysize(response_reads), nullptr, 0); | |
| 201 socket_factory_.AddSocketDataProvider(&response_socket_data); | |
| 202 | |
| 203 TestDelegate delegate; | |
| 204 scoped_ptr<URLRequest> request = | |
| 205 context_->CreateRequest(GURL("http://www.redirect.com"), DEFAULT_PRIORITY, | |
| 206 &delegate) | |
| 207 .Pass(); | |
| 208 | |
| 177 request->Start(); | 209 request->Start(); |
| 210 ASSERT_TRUE(request->is_pending()); | |
| 178 base::RunLoop().RunUntilIdle(); | 211 base::RunLoop().RunUntilIdle(); |
| 179 request->Cancel(); | 212 |
| 180 base::RunLoop().Run(); | 213 EXPECT_TRUE(request->status().is_success()); |
| 214 EXPECT_EQ(12, request->received_response_content_length()); | |
| 215 EXPECT_EQ(107, network_delegate_.total_network_bytes_received()); | |
| 216 } | |
| 217 | |
| 218 TEST_F(URLRequestHttpJobWithMockSocketsTest, | |
| 219 TestNetworkBytesCancelledAfterHeaders) { | |
| 220 MockRead read("HTTP/1.1 200 OK\r\n\r\n"); | |
| 221 StaticSocketDataProvider socket_data(&read, 1, nullptr, 0); | |
| 222 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 223 | |
| 224 TestDelegate delegate; | |
| 225 scoped_ptr<URLRequest> request = | |
| 226 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | |
| 227 &delegate) | |
| 228 .Pass(); | |
| 229 | |
| 230 delegate.set_cancel_in_response_started(true); | |
| 231 request->Start(); | |
| 232 base::RunLoop().RunUntilIdle(); | |
| 181 | 233 |
| 182 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); | 234 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); |
| 183 EXPECT_EQ(12, request->received_response_content_length()); | 235 EXPECT_EQ(19, network_delegate_.total_network_bytes_received()); |
| 184 } | 236 } |
| 185 | 237 |
| 186 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeader) { | 238 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeader) { |
| 187 MockWrite writes[] = {MockWrite( | 239 MockWrite writes[] = {MockWrite( |
| 188 "GET / HTTP/1.1\r\n" | 240 "GET / HTTP/1.1\r\n" |
| 189 "Host: www.example.com\r\n" | 241 "Host: www.example.com\r\n" |
| 190 "Connection: keep-alive\r\n" | 242 "Connection: keep-alive\r\n" |
| 191 "User-Agent:\r\n" | 243 "User-Agent:\r\n" |
| 192 "Accept-Encoding: gzip, deflate\r\n" | 244 "Accept-Encoding: gzip, deflate\r\n" |
| 193 "Accept-Language: en-us,fr\r\n\r\n")}; | 245 "Accept-Language: en-us,fr\r\n\r\n")}; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 req_->SetLoadFlags(LOAD_DISABLE_CACHE); | 624 req_->SetLoadFlags(LOAD_DISABLE_CACHE); |
| 573 job->Start(); | 625 job->Start(); |
| 574 base::RunLoop().RunUntilIdle(); | 626 base::RunLoop().RunUntilIdle(); |
| 575 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 627 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
| 576 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 628 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 577 } | 629 } |
| 578 | 630 |
| 579 } // namespace | 631 } // namespace |
| 580 | 632 |
| 581 } // namespace net | 633 } // namespace net |
| OLD | NEW |