| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif | 10 #endif |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 r.set_method(method.c_str()); | 217 r.set_method(method.c_str()); |
| 218 | 218 |
| 219 r.AppendBytesToUpload(uploadBytes, kMsgSize); | 219 r.AppendBytesToUpload(uploadBytes, kMsgSize); |
| 220 | 220 |
| 221 r.Start(); | 221 r.Start(); |
| 222 EXPECT_TRUE(r.is_pending()); | 222 EXPECT_TRUE(r.is_pending()); |
| 223 | 223 |
| 224 MessageLoop::current()->Run(); | 224 MessageLoop::current()->Run(); |
| 225 | 225 |
| 226 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 226 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
| 227 (int) r.status().status() << ", os error: " << r.status().os_error(); | 227 (int) r.status().status() << ", os error: " << r.status().error(); |
| 228 | 228 |
| 229 EXPECT_FALSE(d.received_data_before_response()); | 229 EXPECT_FALSE(d.received_data_before_response()); |
| 230 EXPECT_EQ(uploadBytes, d.data_received()); | 230 EXPECT_EQ(uploadBytes, d.data_received()); |
| 231 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize), 0); | 231 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize), 0); |
| 232 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); | 232 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); |
| 233 } | 233 } |
| 234 delete[] uploadBytes; | 234 delete[] uploadBytes; |
| 235 } | 235 } |
| 236 | 236 |
| 237 void AddChunksToUpload(TestURLRequest* r) { | 237 void AddChunksToUpload(TestURLRequest* r) { |
| 238 r->AppendChunkToUpload("a", 1, false); | 238 r->AppendChunkToUpload("a", 1, false); |
| 239 r->AppendChunkToUpload("bcd", 3, false); | 239 r->AppendChunkToUpload("bcd", 3, false); |
| 240 r->AppendChunkToUpload("this is a longer chunk than before.", 35, false); | 240 r->AppendChunkToUpload("this is a longer chunk than before.", 35, false); |
| 241 r->AppendChunkToUpload("\r\n\r\n", 4, false); | 241 r->AppendChunkToUpload("\r\n\r\n", 4, false); |
| 242 r->AppendChunkToUpload("0", 1, false); | 242 r->AppendChunkToUpload("0", 1, false); |
| 243 r->AppendChunkToUpload("2323", 4, true); | 243 r->AppendChunkToUpload("2323", 4, true); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void VerifyReceivedDataMatchesChunks(TestURLRequest* r, TestDelegate* d) { | 246 void VerifyReceivedDataMatchesChunks(TestURLRequest* r, TestDelegate* d) { |
| 247 // This should match the chunks sent by AddChunksToUpload(). | 247 // This should match the chunks sent by AddChunksToUpload(). |
| 248 const char* expected_data = | 248 const char* expected_data = |
| 249 "abcdthis is a longer chunk than before.\r\n\r\n02323"; | 249 "abcdthis is a longer chunk than before.\r\n\r\n02323"; |
| 250 | 250 |
| 251 ASSERT_EQ(1, d->response_started_count()) << "request failed: " << | 251 ASSERT_EQ(1, d->response_started_count()) << "request failed: " << |
| 252 (int) r->status().status() << ", os error: " << r->status().os_error(); | 252 (int) r->status().status() << ", os error: " << r->status().error(); |
| 253 | 253 |
| 254 EXPECT_FALSE(d->received_data_before_response()); | 254 EXPECT_FALSE(d->received_data_before_response()); |
| 255 | 255 |
| 256 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received())); | 256 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received())); |
| 257 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data, | 257 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data, |
| 258 strlen(expected_data))); | 258 strlen(expected_data))); |
| 259 } | 259 } |
| 260 | 260 |
| 261 TestServer test_server_; | 261 TestServer test_server_; |
| 262 }; | 262 }; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 277 TestDelegate d; | 277 TestDelegate d; |
| 278 { | 278 { |
| 279 URLRequest r(GURL("https://www.redirect.com/"), &d); | 279 URLRequest r(GURL("https://www.redirect.com/"), &d); |
| 280 r.set_context(context); | 280 r.set_context(context); |
| 281 r.Start(); | 281 r.Start(); |
| 282 EXPECT_TRUE(r.is_pending()); | 282 EXPECT_TRUE(r.is_pending()); |
| 283 | 283 |
| 284 MessageLoop::current()->Run(); | 284 MessageLoop::current()->Run(); |
| 285 | 285 |
| 286 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 286 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 287 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 287 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 288 EXPECT_EQ(1, d.response_started_count()); | 288 EXPECT_EQ(1, d.response_started_count()); |
| 289 // We should not have followed the redirect. | 289 // We should not have followed the redirect. |
| 290 EXPECT_EQ(0, d.received_redirect_count()); | 290 EXPECT_EQ(0, d.received_redirect_count()); |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 | 293 |
| 294 // This is the same as the previous test, but checks that the network delegate | 294 // This is the same as the previous test, but checks that the network delegate |
| 295 // registers the error. | 295 // registers the error. |
| 296 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 296 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
| 297 ASSERT_TRUE(test_server_.Start()); | 297 ASSERT_TRUE(test_server_.Start()); |
| 298 | 298 |
| 299 TestNetworkDelegate network_delegate; // must outlive URLRequest | 299 TestNetworkDelegate network_delegate; // must outlive URLRequest |
| 300 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 300 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
| 301 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 301 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 302 context->set_network_delegate(&network_delegate); | 302 context->set_network_delegate(&network_delegate); |
| 303 context->Init(); | 303 context->Init(); |
| 304 | 304 |
| 305 TestDelegate d; | 305 TestDelegate d; |
| 306 { | 306 { |
| 307 URLRequest r(GURL("https://www.redirect.com/"), &d); | 307 URLRequest r(GURL("https://www.redirect.com/"), &d); |
| 308 r.set_context(context); | 308 r.set_context(context); |
| 309 r.Start(); | 309 r.Start(); |
| 310 EXPECT_TRUE(r.is_pending()); | 310 EXPECT_TRUE(r.is_pending()); |
| 311 | 311 |
| 312 MessageLoop::current()->Run(); | 312 MessageLoop::current()->Run(); |
| 313 | 313 |
| 314 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 314 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 315 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 315 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 316 EXPECT_EQ(1, d.response_started_count()); | 316 EXPECT_EQ(1, d.response_started_count()); |
| 317 // We should not have followed the redirect. | 317 // We should not have followed the redirect. |
| 318 EXPECT_EQ(0, d.received_redirect_count()); | 318 EXPECT_EQ(0, d.received_redirect_count()); |
| 319 | 319 |
| 320 EXPECT_EQ(1, network_delegate.error_count()); | 320 EXPECT_EQ(1, network_delegate.error_count()); |
| 321 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_os_error()); | 321 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Tests that the network delegate can block and cancel a request. | 325 // Tests that the network delegate can block and cancel a request. |
| 326 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { | 326 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { |
| 327 ASSERT_TRUE(test_server_.Start()); | 327 ASSERT_TRUE(test_server_.Start()); |
| 328 | 328 |
| 329 TestDelegate d; | 329 TestDelegate d; |
| 330 BlockingNetworkDelegate network_delegate; | 330 BlockingNetworkDelegate network_delegate; |
| 331 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); | 331 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); |
| 332 | 332 |
| 333 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 333 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
| 334 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 334 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 335 context->set_network_delegate(&network_delegate); | 335 context->set_network_delegate(&network_delegate); |
| 336 context->Init(); | 336 context->Init(); |
| 337 | 337 |
| 338 { | 338 { |
| 339 TestURLRequest r(test_server_.GetURL(""), &d); | 339 TestURLRequest r(test_server_.GetURL(""), &d); |
| 340 r.set_context(context); | 340 r.set_context(context); |
| 341 | 341 |
| 342 r.Start(); | 342 r.Start(); |
| 343 MessageLoop::current()->Run(); | 343 MessageLoop::current()->Run(); |
| 344 | 344 |
| 345 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 345 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 346 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().os_error()); | 346 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
| 347 EXPECT_EQ(1, network_delegate.created_requests()); | 347 EXPECT_EQ(1, network_delegate.created_requests()); |
| 348 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 348 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 349 } | 349 } |
| 350 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 350 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 351 } | 351 } |
| 352 | 352 |
| 353 // Tests that the network delegate can cancel a request synchronously. | 353 // Tests that the network delegate can cancel a request synchronously. |
| 354 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { | 354 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { |
| 355 ASSERT_TRUE(test_server_.Start()); | 355 ASSERT_TRUE(test_server_.Start()); |
| 356 | 356 |
| 357 TestDelegate d; | 357 TestDelegate d; |
| 358 BlockingNetworkDelegate network_delegate; | 358 BlockingNetworkDelegate network_delegate; |
| 359 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 359 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
| 360 | 360 |
| 361 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 361 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
| 362 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 362 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 363 context->set_network_delegate(&network_delegate); | 363 context->set_network_delegate(&network_delegate); |
| 364 context->Init(); | 364 context->Init(); |
| 365 | 365 |
| 366 { | 366 { |
| 367 TestURLRequest r(test_server_.GetURL(""), &d); | 367 TestURLRequest r(test_server_.GetURL(""), &d); |
| 368 r.set_context(context); | 368 r.set_context(context); |
| 369 | 369 |
| 370 r.Start(); | 370 r.Start(); |
| 371 MessageLoop::current()->Run(); | 371 MessageLoop::current()->Run(); |
| 372 | 372 |
| 373 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 373 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 374 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().os_error()); | 374 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
| 375 EXPECT_EQ(1, network_delegate.created_requests()); | 375 EXPECT_EQ(1, network_delegate.created_requests()); |
| 376 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 376 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 377 } | 377 } |
| 378 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 378 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 379 } | 379 } |
| 380 | 380 |
| 381 // Tests that the network delegate can block and redirect a request to a new | 381 // Tests that the network delegate can block and redirect a request to a new |
| 382 // URL. | 382 // URL. |
| 383 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { | 383 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { |
| 384 ASSERT_TRUE(test_server_.Start()); | 384 ASSERT_TRUE(test_server_.Start()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 395 | 395 |
| 396 { | 396 { |
| 397 GURL original_url(test_server_.GetURL("empty.html")); | 397 GURL original_url(test_server_.GetURL("empty.html")); |
| 398 TestURLRequest r(original_url, &d); | 398 TestURLRequest r(original_url, &d); |
| 399 r.set_context(context); | 399 r.set_context(context); |
| 400 | 400 |
| 401 r.Start(); | 401 r.Start(); |
| 402 MessageLoop::current()->Run(); | 402 MessageLoop::current()->Run(); |
| 403 | 403 |
| 404 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 404 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 405 EXPECT_EQ(0, r.status().os_error()); | 405 EXPECT_EQ(0, r.status().error()); |
| 406 EXPECT_EQ(redirect_url, r.url()); | 406 EXPECT_EQ(redirect_url, r.url()); |
| 407 EXPECT_EQ(original_url, r.original_url()); | 407 EXPECT_EQ(original_url, r.original_url()); |
| 408 EXPECT_EQ(2U, r.url_chain().size()); | 408 EXPECT_EQ(2U, r.url_chain().size()); |
| 409 EXPECT_EQ(1, network_delegate.created_requests()); | 409 EXPECT_EQ(1, network_delegate.created_requests()); |
| 410 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 410 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 411 } | 411 } |
| 412 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 412 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // In this unit test, we're using the HTTPTestServer as a proxy server and | 415 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| (...skipping 12 matching lines...) Expand all Loading... |
| 428 { | 428 { |
| 429 URLRequest r(GURL("https://www.server-auth.com/"), &d); | 429 URLRequest r(GURL("https://www.server-auth.com/"), &d); |
| 430 r.set_context(context); | 430 r.set_context(context); |
| 431 | 431 |
| 432 r.Start(); | 432 r.Start(); |
| 433 EXPECT_TRUE(r.is_pending()); | 433 EXPECT_TRUE(r.is_pending()); |
| 434 | 434 |
| 435 MessageLoop::current()->Run(); | 435 MessageLoop::current()->Run(); |
| 436 | 436 |
| 437 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 437 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 438 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 438 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 | 441 |
| 442 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 442 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
| 443 ASSERT_TRUE(test_server_.Start()); | 443 ASSERT_TRUE(test_server_.Start()); |
| 444 | 444 |
| 445 TestDelegate d; | 445 TestDelegate d; |
| 446 { | 446 { |
| 447 TestURLRequest r(test_server_.GetURL(""), &d); | 447 TestURLRequest r(test_server_.GetURL(""), &d); |
| 448 r.set_context(default_context_); | 448 r.set_context(default_context_); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 r.set_context(context); | 521 r.set_context(context); |
| 522 r.Start(); | 522 r.Start(); |
| 523 EXPECT_TRUE(r.is_pending()); | 523 EXPECT_TRUE(r.is_pending()); |
| 524 | 524 |
| 525 MessageLoop::current()->Run(); | 525 MessageLoop::current()->Run(); |
| 526 | 526 |
| 527 EXPECT_EQ(1, d.response_started_count()); | 527 EXPECT_EQ(1, d.response_started_count()); |
| 528 EXPECT_FALSE(d.received_data_before_response()); | 528 EXPECT_FALSE(d.received_data_before_response()); |
| 529 VLOG(1) << " Received " << d.bytes_received() << " bytes" | 529 VLOG(1) << " Received " << d.bytes_received() << " bytes" |
| 530 << " status = " << r.status().status() | 530 << " status = " << r.status().status() |
| 531 << " os_error = " << r.status().os_error(); | 531 << " error = " << r.status().error(); |
| 532 if (test_expect_success[i]) { | 532 if (test_expect_success[i]) { |
| 533 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()) | 533 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()) |
| 534 << " Parameter = \"" << test_file << "\""; | 534 << " Parameter = \"" << test_file << "\""; |
| 535 } else { | 535 } else { |
| 536 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 536 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 537 EXPECT_EQ(-100, r.status().os_error()) | 537 EXPECT_EQ(-100, r.status().error()) |
| 538 << " Parameter = \"" << test_file << "\""; | 538 << " Parameter = \"" << test_file << "\""; |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 | 543 |
| 544 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { | 544 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { |
| 545 ASSERT_TRUE(test_server_.Start()); | 545 ASSERT_TRUE(test_server_.Start()); |
| 546 | 546 |
| 547 TestServer https_test_server( | 547 TestServer https_test_server( |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 TestURLRequest r(test_server_.GetURL("echo"), &d); | 897 TestURLRequest r(test_server_.GetURL("echo"), &d); |
| 898 r.set_context(default_context_); | 898 r.set_context(default_context_); |
| 899 r.set_method("POST"); | 899 r.set_method("POST"); |
| 900 | 900 |
| 901 r.Start(); | 901 r.Start(); |
| 902 EXPECT_TRUE(r.is_pending()); | 902 EXPECT_TRUE(r.is_pending()); |
| 903 | 903 |
| 904 MessageLoop::current()->Run(); | 904 MessageLoop::current()->Run(); |
| 905 | 905 |
| 906 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 906 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
| 907 (int) r.status().status() << ", os error: " << r.status().os_error(); | 907 (int) r.status().status() << ", error: " << r.status().error(); |
| 908 | 908 |
| 909 EXPECT_FALSE(d.received_data_before_response()); | 909 EXPECT_FALSE(d.received_data_before_response()); |
| 910 EXPECT_TRUE(d.data_received().empty()); | 910 EXPECT_TRUE(d.data_received().empty()); |
| 911 } | 911 } |
| 912 } | 912 } |
| 913 | 913 |
| 914 TEST_F(URLRequestTestHTTP, PostFileTest) { | 914 TEST_F(URLRequestTestHTTP, PostFileTest) { |
| 915 ASSERT_TRUE(test_server_.Start()); | 915 ASSERT_TRUE(test_server_.Start()); |
| 916 | 916 |
| 917 TestDelegate d; | 917 TestDelegate d; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 944 int64 longsize; | 944 int64 longsize; |
| 945 ASSERT_EQ(true, file_util::GetFileSize(path, &longsize)); | 945 ASSERT_EQ(true, file_util::GetFileSize(path, &longsize)); |
| 946 int size = static_cast<int>(longsize); | 946 int size = static_cast<int>(longsize); |
| 947 scoped_array<char> buf(new char[size]); | 947 scoped_array<char> buf(new char[size]); |
| 948 | 948 |
| 949 int size_read = static_cast<int>(file_util::ReadFile(path, | 949 int size_read = static_cast<int>(file_util::ReadFile(path, |
| 950 buf.get(), size)); | 950 buf.get(), size)); |
| 951 ASSERT_EQ(size, size_read); | 951 ASSERT_EQ(size, size_read); |
| 952 | 952 |
| 953 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 953 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
| 954 (int) r.status().status() << ", os error: " << r.status().os_error(); | 954 (int) r.status().status() << ", error: " << r.status().error(); |
| 955 | 955 |
| 956 EXPECT_FALSE(d.received_data_before_response()); | 956 EXPECT_FALSE(d.received_data_before_response()); |
| 957 | 957 |
| 958 ASSERT_EQ(size, d.bytes_received()); | 958 ASSERT_EQ(size, d.bytes_received()); |
| 959 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); | 959 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); |
| 960 } | 960 } |
| 961 } | 961 } |
| 962 | 962 |
| 963 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 963 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
| 964 ASSERT_TRUE(test_server_.Start()); | 964 ASSERT_TRUE(test_server_.Start()); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 ASSERT_TRUE(test_server_.Start()); | 1406 ASSERT_TRUE(test_server_.Start()); |
| 1407 | 1407 |
| 1408 TestDelegate d; | 1408 TestDelegate d; |
| 1409 TestURLRequest req(test_server_.GetURL( | 1409 TestURLRequest req(test_server_.GetURL( |
| 1410 "files/redirect-to-file.html"), &d); | 1410 "files/redirect-to-file.html"), &d); |
| 1411 req.set_context(default_context_); | 1411 req.set_context(default_context_); |
| 1412 req.Start(); | 1412 req.Start(); |
| 1413 MessageLoop::current()->Run(); | 1413 MessageLoop::current()->Run(); |
| 1414 | 1414 |
| 1415 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 1415 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 1416 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().os_error()); | 1416 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 1419 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
| 1420 ASSERT_TRUE(test_server_.Start()); | 1420 ASSERT_TRUE(test_server_.Start()); |
| 1421 | 1421 |
| 1422 TestDelegate d; | 1422 TestDelegate d; |
| 1423 TestURLRequest req(test_server_.GetURL( | 1423 TestURLRequest req(test_server_.GetURL( |
| 1424 "files/redirect-to-invalid-url.html"), &d); | 1424 "files/redirect-to-invalid-url.html"), &d); |
| 1425 req.set_context(default_context_); | 1425 req.set_context(default_context_); |
| 1426 req.Start(); | 1426 req.Start(); |
| 1427 MessageLoop::current()->Run(); | 1427 MessageLoop::current()->Run(); |
| 1428 | 1428 |
| 1429 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 1429 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 1430 EXPECT_EQ(ERR_INVALID_URL, req.status().os_error()); | 1430 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); |
| 1431 } | 1431 } |
| 1432 | 1432 |
| 1433 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 1433 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
| 1434 ASSERT_TRUE(test_server_.Start()); | 1434 ASSERT_TRUE(test_server_.Start()); |
| 1435 | 1435 |
| 1436 TestDelegate d; | 1436 TestDelegate d; |
| 1437 TestURLRequest req(test_server_.GetURL("echoheader?Referer"), &d); | 1437 TestURLRequest req(test_server_.GetURL("echoheader?Referer"), &d); |
| 1438 req.set_context(default_context_); | 1438 req.set_context(default_context_); |
| 1439 req.set_referrer("http://user:pass@foo.com/"); | 1439 req.set_referrer("http://user:pass@foo.com/"); |
| 1440 req.Start(); | 1440 req.Start(); |
| (...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2603 TestURLRequest req(GURL("http://example.com"), &d); | 2603 TestURLRequest req(GURL("http://example.com"), &d); |
| 2604 req.set_context(context); | 2604 req.set_context(context); |
| 2605 req.set_method("GET"); | 2605 req.set_method("GET"); |
| 2606 | 2606 |
| 2607 req.Start(); | 2607 req.Start(); |
| 2608 MessageLoop::current()->Run(); | 2608 MessageLoop::current()->Run(); |
| 2609 | 2609 |
| 2610 // Check we see a failed request. | 2610 // Check we see a failed request. |
| 2611 EXPECT_FALSE(req.status().is_success()); | 2611 EXPECT_FALSE(req.status().is_success()); |
| 2612 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 2612 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 2613 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().os_error()); | 2613 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); |
| 2614 | 2614 |
| 2615 EXPECT_EQ(1, network_delegate.error_count()); | 2615 EXPECT_EQ(1, network_delegate.error_count()); |
| 2616 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_os_error()); | 2616 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); |
| 2617 EXPECT_EQ(1, network_delegate.completed_requests()); | 2617 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 2618 } | 2618 } |
| 2619 | 2619 |
| 2620 // Check that it is impossible to change the referrer in the extra headers of | 2620 // Check that it is impossible to change the referrer in the extra headers of |
| 2621 // an URLRequest. | 2621 // an URLRequest. |
| 2622 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 2622 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
| 2623 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); | 2623 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 2624 ASSERT_TRUE(test_server.Start()); | 2624 ASSERT_TRUE(test_server.Start()); |
| 2625 | 2625 |
| 2626 // If extra headers contain referer and the request contains a referer, | 2626 // If extra headers contain referer and the request contains a referer, |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3168 req.SetExtraRequestHeaders(headers); | 3168 req.SetExtraRequestHeaders(headers); |
| 3169 req.Start(); | 3169 req.Start(); |
| 3170 MessageLoop::current()->Run(); | 3170 MessageLoop::current()->Run(); |
| 3171 // If the net tests are being run with ChromeFrame then we need to allow for | 3171 // If the net tests are being run with ChromeFrame then we need to allow for |
| 3172 // the 'chromeframe' suffix which is added to the user agent before the | 3172 // the 'chromeframe' suffix which is added to the user agent before the |
| 3173 // closing parentheses. | 3173 // closing parentheses. |
| 3174 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3174 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 3175 } | 3175 } |
| 3176 | 3176 |
| 3177 } // namespace net | 3177 } // namespace net |
| OLD | NEW |