| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 context_->set_backoff_manager(&manager_); | 107 context_->set_backoff_manager(&manager_); |
| 108 context_->Init(); | 108 context_->Init(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 MockClientSocketFactory socket_factory_; | 111 MockClientSocketFactory socket_factory_; |
| 112 TestNetworkDelegate network_delegate_; | 112 TestNetworkDelegate network_delegate_; |
| 113 URLRequestBackoffManager manager_; | 113 URLRequestBackoffManager manager_; |
| 114 scoped_ptr<TestURLRequestContext> context_; | 114 scoped_ptr<TestURLRequestContext> context_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 const char kSimpleGetMockWrite[] = |
| 118 "GET / HTTP/1.1\r\n" |
| 119 "Host: www.example.com\r\n" |
| 120 "Connection: keep-alive\r\n" |
| 121 "User-Agent:\r\n" |
| 122 "Accept-Encoding: gzip, deflate\r\n" |
| 123 "Accept-Language: en-us,fr\r\n\r\n"; |
| 124 |
| 117 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 125 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 118 TestContentLengthSuccessfulRequest) { | 126 TestContentLengthSuccessfulRequest) { |
| 127 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 119 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 128 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 120 "Content-Length: 12\r\n\r\n"), | 129 "Content-Length: 12\r\n\r\n"), |
| 121 MockRead("Test Content")}; | 130 MockRead("Test Content")}; |
| 122 | 131 |
| 123 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); | 132 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 133 arraysize(writes)); |
| 124 socket_factory_.AddSocketDataProvider(&socket_data); | 134 socket_factory_.AddSocketDataProvider(&socket_data); |
| 125 | 135 |
| 126 TestDelegate delegate; | 136 TestDelegate delegate; |
| 127 scoped_ptr<URLRequest> request = | 137 scoped_ptr<URLRequest> request = |
| 128 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 138 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 129 &delegate) | 139 &delegate) |
| 130 .Pass(); | 140 .Pass(); |
| 131 | 141 |
| 132 request->Start(); | 142 request->Start(); |
| 133 ASSERT_TRUE(request->is_pending()); | 143 ASSERT_TRUE(request->is_pending()); |
| 134 base::RunLoop().Run(); | 144 base::RunLoop().Run(); |
| 135 | 145 |
| 136 EXPECT_TRUE(request->status().is_success()); | 146 EXPECT_TRUE(request->status().is_success()); |
| 137 EXPECT_EQ(12, request->received_response_content_length()); | 147 EXPECT_EQ(12, request->received_response_content_length()); |
| 138 EXPECT_EQ(51, network_delegate_.total_network_bytes_received()); | 148 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 149 request->GetTotalSentBytes()); |
| 150 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 151 request->GetTotalReceivedBytes()); |
| 152 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 153 network_delegate_.total_network_bytes_received()); |
| 139 } | 154 } |
| 140 | 155 |
| 141 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 156 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 142 TestContentLengthSuccessfulHttp09Request) { | 157 TestContentLengthSuccessfulHttp09Request) { |
| 158 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 143 MockRead reads[] = {MockRead("Test Content"), | 159 MockRead reads[] = {MockRead("Test Content"), |
| 144 MockRead(net::SYNCHRONOUS, net::OK)}; | 160 MockRead(net::SYNCHRONOUS, net::OK)}; |
| 145 | 161 |
| 146 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); | 162 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); |
| 147 socket_factory_.AddSocketDataProvider(&socket_data); | 163 socket_factory_.AddSocketDataProvider(&socket_data); |
| 148 | 164 |
| 149 TestDelegate delegate; | 165 TestDelegate delegate; |
| 150 scoped_ptr<URLRequest> request = | 166 scoped_ptr<URLRequest> request = |
| 151 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 167 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 152 &delegate) | 168 &delegate) |
| 153 .Pass(); | 169 .Pass(); |
| 154 | 170 |
| 155 request->Start(); | 171 request->Start(); |
| 156 ASSERT_TRUE(request->is_pending()); | 172 ASSERT_TRUE(request->is_pending()); |
| 157 base::RunLoop().Run(); | 173 base::RunLoop().Run(); |
| 158 | 174 |
| 159 EXPECT_TRUE(request->status().is_success()); | 175 EXPECT_TRUE(request->status().is_success()); |
| 160 EXPECT_EQ(12, request->received_response_content_length()); | 176 EXPECT_EQ(12, request->received_response_content_length()); |
| 161 EXPECT_EQ(12, network_delegate_.total_network_bytes_received()); | 177 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 178 request->GetTotalSentBytes()); |
| 179 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 180 request->GetTotalReceivedBytes()); |
| 181 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 182 network_delegate_.total_network_bytes_received()); |
| 162 } | 183 } |
| 163 | 184 |
| 164 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthAbortedRequest) { | 185 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthFailedRequest) { |
| 186 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 165 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 187 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 166 "Content-Length: 20\r\n\r\n"), | 188 "Content-Length: 20\r\n\r\n"), |
| 167 MockRead("Test Content"), | 189 MockRead("Test Content"), |
| 168 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; | 190 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; |
| 169 | 191 |
| 170 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); | 192 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 193 arraysize(writes)); |
| 171 socket_factory_.AddSocketDataProvider(&socket_data); | 194 socket_factory_.AddSocketDataProvider(&socket_data); |
| 172 | 195 |
| 173 TestDelegate delegate; | 196 TestDelegate delegate; |
| 174 scoped_ptr<URLRequest> request = | 197 scoped_ptr<URLRequest> request = |
| 175 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 198 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 176 &delegate) | 199 &delegate) |
| 177 .Pass(); | 200 .Pass(); |
| 178 | 201 |
| 179 request->Start(); | 202 request->Start(); |
| 180 ASSERT_TRUE(request->is_pending()); | 203 ASSERT_TRUE(request->is_pending()); |
| 181 base::RunLoop().Run(); | 204 base::RunLoop().Run(); |
| 182 | 205 |
| 183 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); | 206 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); |
| 184 EXPECT_EQ(12, request->received_response_content_length()); | 207 EXPECT_EQ(12, request->received_response_content_length()); |
| 185 EXPECT_EQ(51, network_delegate_.total_network_bytes_received()); | 208 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 209 request->GetTotalSentBytes()); |
| 210 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 211 request->GetTotalReceivedBytes()); |
| 212 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 213 network_delegate_.total_network_bytes_received()); |
| 186 } | 214 } |
| 187 | 215 |
| 188 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 216 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 189 TestContentLengthCancelledRequest) { | 217 TestContentLengthCancelledRequest) { |
| 218 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 190 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 219 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 191 "Content-Length: 20\r\n\r\n"), | 220 "Content-Length: 20\r\n\r\n"), |
| 192 MockRead("Test Content"), | 221 MockRead("Test Content"), |
| 193 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; | 222 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; |
| 194 | 223 |
| 195 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); | 224 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 225 arraysize(writes)); |
| 196 socket_factory_.AddSocketDataProvider(&socket_data); | 226 socket_factory_.AddSocketDataProvider(&socket_data); |
| 197 | 227 |
| 198 TestDelegate delegate; | 228 TestDelegate delegate; |
| 199 scoped_ptr<URLRequest> request = | 229 scoped_ptr<URLRequest> request = |
| 200 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 230 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 201 &delegate) | 231 &delegate) |
| 202 .Pass(); | 232 .Pass(); |
| 203 | 233 |
| 204 delegate.set_cancel_in_received_data(true); | 234 delegate.set_cancel_in_received_data(true); |
| 205 request->Start(); | 235 request->Start(); |
| 206 base::RunLoop().RunUntilIdle(); | 236 base::RunLoop().RunUntilIdle(); |
| 207 | 237 |
| 208 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); | 238 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); |
| 209 EXPECT_EQ(12, request->received_response_content_length()); | 239 EXPECT_EQ(12, request->received_response_content_length()); |
| 210 EXPECT_EQ(51, network_delegate_.total_network_bytes_received()); | 240 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 241 request->GetTotalSentBytes()); |
| 242 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 243 request->GetTotalReceivedBytes()); |
| 244 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 245 network_delegate_.total_network_bytes_received()); |
| 211 } | 246 } |
| 212 | 247 |
| 213 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 248 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 214 TestNetworkBytesRedirectedRequest) { | 249 TestNetworkBytesRedirectedRequest) { |
| 215 MockRead redirect_read( | 250 MockWrite redirect_writes[] = { |
| 216 "HTTP/1.1 302 Found\r\n" | 251 MockWrite("GET / HTTP/1.1\r\n" |
| 217 "Location: http://www.example.com\r\n\r\n"); | 252 "Host: www.redirect.com\r\n" |
| 218 StaticSocketDataProvider redirect_socket_data(&redirect_read, 1, nullptr, 0); | 253 "Connection: keep-alive\r\n" |
| 254 "User-Agent:\r\n" |
| 255 "Accept-Encoding: gzip, deflate\r\n" |
| 256 "Accept-Language: en-us,fr\r\n\r\n")}; |
| 257 |
| 258 MockRead redirect_reads[] = { |
| 259 MockRead("HTTP/1.1 302 Found\r\n" |
| 260 "Location: http://www.example.com\r\n\r\n"), |
| 261 }; |
| 262 StaticSocketDataProvider redirect_socket_data( |
| 263 redirect_reads, arraysize(redirect_reads), redirect_writes, |
| 264 arraysize(redirect_writes)); |
| 219 socket_factory_.AddSocketDataProvider(&redirect_socket_data); | 265 socket_factory_.AddSocketDataProvider(&redirect_socket_data); |
| 220 | 266 |
| 221 MockRead response_reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 267 MockWrite final_writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 222 "Content-Length: 12\r\n\r\n"), | 268 MockRead final_reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 223 MockRead("Test Content")}; | 269 "Content-Length: 12\r\n\r\n"), |
| 224 StaticSocketDataProvider response_socket_data( | 270 MockRead("Test Content")}; |
| 225 response_reads, arraysize(response_reads), nullptr, 0); | 271 StaticSocketDataProvider final_socket_data( |
| 226 socket_factory_.AddSocketDataProvider(&response_socket_data); | 272 final_reads, arraysize(final_reads), final_writes, |
| 273 arraysize(final_writes)); |
| 274 socket_factory_.AddSocketDataProvider(&final_socket_data); |
| 227 | 275 |
| 228 TestDelegate delegate; | 276 TestDelegate delegate; |
| 229 scoped_ptr<URLRequest> request = | 277 scoped_ptr<URLRequest> request = |
| 230 context_->CreateRequest(GURL("http://www.redirect.com"), DEFAULT_PRIORITY, | 278 context_->CreateRequest(GURL("http://www.redirect.com"), DEFAULT_PRIORITY, |
| 231 &delegate) | 279 &delegate) |
| 232 .Pass(); | 280 .Pass(); |
| 233 | 281 |
| 234 request->Start(); | 282 request->Start(); |
| 235 ASSERT_TRUE(request->is_pending()); | 283 ASSERT_TRUE(request->is_pending()); |
| 236 base::RunLoop().RunUntilIdle(); | 284 base::RunLoop().RunUntilIdle(); |
| 237 | 285 |
| 238 EXPECT_TRUE(request->status().is_success()); | 286 EXPECT_TRUE(request->status().is_success()); |
| 239 EXPECT_EQ(12, request->received_response_content_length()); | 287 EXPECT_EQ(12, request->received_response_content_length()); |
| 240 EXPECT_EQ(107, network_delegate_.total_network_bytes_received()); | 288 // Should not include the redirect. |
| 289 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)), |
| 290 request->GetTotalSentBytes()); |
| 291 EXPECT_EQ(CountReadBytes(final_reads, arraysize(final_reads)), |
| 292 request->GetTotalReceivedBytes()); |
| 293 // Should include the redirect as well as the final response. |
| 294 EXPECT_EQ(CountReadBytes(redirect_reads, arraysize(redirect_reads)) + |
| 295 CountReadBytes(final_reads, arraysize(final_reads)), |
| 296 network_delegate_.total_network_bytes_received()); |
| 241 } | 297 } |
| 242 | 298 |
| 243 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 299 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 244 TestNetworkBytesCancelledAfterHeaders) { | 300 TestNetworkBytesCancelledAfterHeaders) { |
| 245 MockRead read("HTTP/1.1 200 OK\r\n\r\n"); | 301 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 246 StaticSocketDataProvider socket_data(&read, 1, nullptr, 0); | 302 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n\r\n")}; |
| 303 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 304 arraysize(writes)); |
| 247 socket_factory_.AddSocketDataProvider(&socket_data); | 305 socket_factory_.AddSocketDataProvider(&socket_data); |
| 248 | 306 |
| 249 TestDelegate delegate; | 307 TestDelegate delegate; |
| 250 scoped_ptr<URLRequest> request = | 308 scoped_ptr<URLRequest> request = |
| 251 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 309 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 252 &delegate) | 310 &delegate) |
| 253 .Pass(); | 311 .Pass(); |
| 254 | 312 |
| 255 delegate.set_cancel_in_response_started(true); | 313 delegate.set_cancel_in_response_started(true); |
| 256 request->Start(); | 314 request->Start(); |
| 257 base::RunLoop().RunUntilIdle(); | 315 base::RunLoop().RunUntilIdle(); |
| 258 | 316 |
| 259 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); | 317 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); |
| 260 EXPECT_EQ(19, network_delegate_.total_network_bytes_received()); | 318 EXPECT_EQ(0, request->received_response_content_length()); |
| 319 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 320 request->GetTotalSentBytes()); |
| 321 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 322 request->GetTotalReceivedBytes()); |
| 323 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 324 network_delegate_.total_network_bytes_received()); |
| 261 } | 325 } |
| 262 | 326 |
| 263 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 327 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 264 TestNetworkBytesCancelledImmediately) { | 328 TestNetworkBytesCancelledImmediately) { |
| 265 StaticSocketDataProvider socket_data(nullptr, 0, nullptr, 0); | 329 StaticSocketDataProvider socket_data(nullptr, 0, nullptr, 0); |
| 266 socket_factory_.AddSocketDataProvider(&socket_data); | 330 socket_factory_.AddSocketDataProvider(&socket_data); |
| 267 | 331 |
| 268 TestDelegate delegate; | 332 TestDelegate delegate; |
| 269 scoped_ptr<URLRequest> request = | 333 scoped_ptr<URLRequest> request = |
| 270 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 334 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 271 &delegate) | 335 &delegate) |
| 272 .Pass(); | 336 .Pass(); |
| 273 | 337 |
| 274 request->Start(); | 338 request->Start(); |
| 275 request->Cancel(); | 339 request->Cancel(); |
| 276 base::RunLoop().RunUntilIdle(); | 340 base::RunLoop().RunUntilIdle(); |
| 277 | 341 |
| 278 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); | 342 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); |
| 343 EXPECT_EQ(0, request->received_response_content_length()); |
| 344 EXPECT_EQ(0, request->GetTotalSentBytes()); |
| 345 EXPECT_EQ(0, request->GetTotalReceivedBytes()); |
| 279 EXPECT_EQ(0, network_delegate_.total_network_bytes_received()); | 346 EXPECT_EQ(0, network_delegate_.total_network_bytes_received()); |
| 280 } | 347 } |
| 281 | 348 |
| 282 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeader) { | 349 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeader) { |
| 283 MockWrite writes[] = {MockWrite( | 350 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 284 "GET / HTTP/1.1\r\n" | |
| 285 "Host: www.example.com\r\n" | |
| 286 "Connection: keep-alive\r\n" | |
| 287 "User-Agent:\r\n" | |
| 288 "Accept-Encoding: gzip, deflate\r\n" | |
| 289 "Accept-Language: en-us,fr\r\n\r\n")}; | |
| 290 | |
| 291 MockRead reads[] = {MockRead( | 351 MockRead reads[] = {MockRead( |
| 292 "HTTP/1.1 200 OK\r\n" | 352 "HTTP/1.1 200 OK\r\n" |
| 293 "Backoff: 3600\r\n" | 353 "Backoff: 3600\r\n" |
| 294 "Content-Length: 9\r\n\r\n"), | 354 "Content-Length: 9\r\n\r\n"), |
| 295 MockRead("test.html")}; | 355 MockRead("test.html")}; |
| 296 | 356 |
| 297 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK); | 357 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK); |
| 298 ssl_socket_data_provider.SetNextProto(kProtoHTTP11); | 358 ssl_socket_data_provider.SetNextProto(kProtoHTTP11); |
| 299 ssl_socket_data_provider.cert = | 359 ssl_socket_data_provider.cert = |
| 300 ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der"); | 360 ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 327 request2->Start(); | 387 request2->Start(); |
| 328 ASSERT_TRUE(request2->is_pending()); | 388 ASSERT_TRUE(request2->is_pending()); |
| 329 base::RunLoop().Run(); | 389 base::RunLoop().Run(); |
| 330 | 390 |
| 331 EXPECT_FALSE(request2->status().is_success()); | 391 EXPECT_FALSE(request2->status().is_success()); |
| 332 EXPECT_EQ(ERR_TEMPORARY_BACKOFF, request2->status().error()); | 392 EXPECT_EQ(ERR_TEMPORARY_BACKOFF, request2->status().error()); |
| 333 EXPECT_EQ(0, delegate2.received_before_network_start_count()); | 393 EXPECT_EQ(0, delegate2.received_before_network_start_count()); |
| 334 } | 394 } |
| 335 | 395 |
| 336 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeaderNotSecure) { | 396 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeaderNotSecure) { |
| 337 MockWrite writes[] = {MockWrite( | 397 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 338 "GET / HTTP/1.1\r\n" | |
| 339 "Host: www.example.com\r\n" | |
| 340 "Connection: keep-alive\r\n" | |
| 341 "User-Agent:\r\n" | |
| 342 "Accept-Encoding: gzip, deflate\r\n" | |
| 343 "Accept-Language: en-us,fr\r\n\r\n")}; | |
| 344 MockRead reads[] = {MockRead( | 398 MockRead reads[] = {MockRead( |
| 345 "HTTP/1.1 200 OK\r\n" | 399 "HTTP/1.1 200 OK\r\n" |
| 346 "Backoff: 3600\r\n" | 400 "Backoff: 3600\r\n" |
| 347 "Content-Length: 9\r\n\r\n"), | 401 "Content-Length: 9\r\n\r\n"), |
| 348 MockRead("test.html")}; | 402 MockRead("test.html")}; |
| 349 | 403 |
| 350 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 404 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 351 arraysize(writes)); | 405 arraysize(writes)); |
| 352 socket_factory_.AddSocketDataProvider(&socket_data); | 406 socket_factory_.AddSocketDataProvider(&socket_data); |
| 353 | 407 |
| 354 TestDelegate delegate; | 408 TestDelegate delegate; |
| 355 scoped_ptr<URLRequest> request = | 409 scoped_ptr<URLRequest> request = |
| 356 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, | 410 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 357 &delegate).Pass(); | 411 &delegate).Pass(); |
| 358 | 412 |
| 359 request->Start(); | 413 request->Start(); |
| 360 ASSERT_TRUE(request->is_pending()); | 414 ASSERT_TRUE(request->is_pending()); |
| 361 base::RunLoop().Run(); | 415 base::RunLoop().Run(); |
| 362 | 416 |
| 363 EXPECT_TRUE(request->status().is_success()); | 417 EXPECT_TRUE(request->status().is_success()); |
| 364 EXPECT_EQ("test.html", delegate.data_received()); | 418 EXPECT_EQ("test.html", delegate.data_received()); |
| 365 EXPECT_EQ(1, delegate.received_before_network_start_count()); | 419 EXPECT_EQ(1, delegate.received_before_network_start_count()); |
| 366 // Backoff logic does not apply to plain HTTP request. | 420 // Backoff logic does not apply to plain HTTP request. |
| 367 EXPECT_EQ(0, manager_.GetNumberOfEntriesForTests()); | 421 EXPECT_EQ(0, manager_.GetNumberOfEntriesForTests()); |
| 368 } | 422 } |
| 369 | 423 |
| 370 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeaderCachedResponse) { | 424 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeaderCachedResponse) { |
| 371 MockWrite writes[] = {MockWrite( | 425 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 372 "GET / HTTP/1.1\r\n" | |
| 373 "Host: www.example.com\r\n" | |
| 374 "Connection: keep-alive\r\n" | |
| 375 "User-Agent:\r\n" | |
| 376 "Accept-Encoding: gzip, deflate\r\n" | |
| 377 "Accept-Language: en-us,fr\r\n\r\n")}; | |
| 378 MockRead reads[] = {MockRead( | 426 MockRead reads[] = {MockRead( |
| 379 "HTTP/1.1 200 OK\r\n" | 427 "HTTP/1.1 200 OK\r\n" |
| 380 "Backoff: 3600\r\n" | 428 "Backoff: 3600\r\n" |
| 381 "Cache-Control: max-age=120\r\n" | 429 "Cache-Control: max-age=120\r\n" |
| 382 "Content-Length: 9\r\n\r\n"), | 430 "Content-Length: 9\r\n\r\n"), |
| 383 MockRead("test.html")}; | 431 MockRead("test.html")}; |
| 384 | 432 |
| 385 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK); | 433 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK); |
| 386 ssl_socket_data_provider.SetNextProto(kProtoHTTP11); | 434 ssl_socket_data_provider.SetNextProto(kProtoHTTP11); |
| 387 ssl_socket_data_provider.cert = | 435 ssl_socket_data_provider.cert = |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 req_->SetLoadFlags(LOAD_DISABLE_CACHE); | 713 req_->SetLoadFlags(LOAD_DISABLE_CACHE); |
| 666 job->Start(); | 714 job->Start(); |
| 667 base::RunLoop().RunUntilIdle(); | 715 base::RunLoop().RunUntilIdle(); |
| 668 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 716 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
| 669 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 717 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 670 } | 718 } |
| 671 | 719 |
| 672 } // namespace | 720 } // namespace |
| 673 | 721 |
| 674 } // namespace net | 722 } // namespace net |
| OLD | NEW |