Chromium Code Reviews| 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 <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 5531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5542 base::RunLoop().Run(); | 5542 base::RunLoop().Run(); |
| 5543 | 5543 |
| 5544 std::string value; | 5544 std::string value; |
| 5545 const HttpRequestHeaders& headers = req->extra_request_headers(); | 5545 const HttpRequestHeaders& headers = req->extra_request_headers(); |
| 5546 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); | 5546 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); |
| 5547 EXPECT_FALSE(req->is_pending()); | 5547 EXPECT_FALSE(req->is_pending()); |
| 5548 EXPECT_FALSE(req->is_redirecting()); | 5548 EXPECT_FALSE(req->is_redirecting()); |
| 5549 EXPECT_EQ("None", d.data_received()); | 5549 EXPECT_EQ("None", d.data_received()); |
| 5550 } | 5550 } |
| 5551 | 5551 |
| 5552 TEST_F(URLRequestTestHTTP, CancelTest) { | 5552 TEST_F(URLRequestTestHTTP, CancelAfterStart) { |
| 5553 TestDelegate d; | 5553 TestDelegate d; |
| 5554 { | 5554 { |
| 5555 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5555 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5556 GURL("http://www.google.com/"), DEFAULT_PRIORITY, &d)); | 5556 GURL("http://www.google.com/"), DEFAULT_PRIORITY, &d)); |
| 5557 | 5557 |
| 5558 r->Start(); | 5558 r->Start(); |
| 5559 EXPECT_TRUE(r->is_pending()); | 5559 EXPECT_TRUE(r->is_pending()); |
| 5560 | 5560 |
| 5561 r->Cancel(); | 5561 r->Cancel(); |
| 5562 | 5562 |
| 5563 base::RunLoop().Run(); | 5563 base::RunLoop().Run(); |
| 5564 | 5564 |
| 5565 // We expect to receive OnResponseStarted even though the request has been | 5565 // We expect to receive OnResponseStarted even though the request has been |
| 5566 // cancelled. | 5566 // cancelled. |
| 5567 EXPECT_EQ(1, d.response_started_count()); | 5567 EXPECT_EQ(1, d.response_started_count()); |
| 5568 EXPECT_EQ(0, d.bytes_received()); | 5568 EXPECT_EQ(0, d.bytes_received()); |
| 5569 EXPECT_FALSE(d.received_data_before_response()); | 5569 EXPECT_FALSE(d.received_data_before_response()); |
| 5570 } | 5570 } |
| 5571 } | 5571 } |
| 5572 | 5572 |
| 5573 TEST_F(URLRequestTestHTTP, CancelTest2) { | 5573 TEST_F(URLRequestTestHTTP, CancelInResponseStarted) { |
| 5574 ASSERT_TRUE(http_test_server()->Start()); | 5574 ASSERT_TRUE(http_test_server()->Start()); |
| 5575 | 5575 |
| 5576 TestDelegate d; | 5576 TestDelegate d; |
| 5577 { | 5577 { |
| 5578 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5578 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5579 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 5579 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 5580 | 5580 |
| 5581 d.set_cancel_in_response_started(true); | 5581 d.set_cancel_in_response_started(true); |
| 5582 | 5582 |
| 5583 r->Start(); | 5583 r->Start(); |
| 5584 EXPECT_TRUE(r->is_pending()); | 5584 EXPECT_TRUE(r->is_pending()); |
| 5585 | 5585 |
| 5586 base::RunLoop().Run(); | 5586 base::RunLoop().Run(); |
| 5587 | 5587 |
| 5588 EXPECT_EQ(1, d.response_started_count()); | 5588 EXPECT_EQ(1, d.response_started_count()); |
| 5589 EXPECT_EQ(0, d.bytes_received()); | 5589 EXPECT_EQ(0, d.bytes_received()); |
| 5590 EXPECT_FALSE(d.received_data_before_response()); | 5590 EXPECT_FALSE(d.received_data_before_response()); |
| 5591 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 5591 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 5592 } | 5592 } |
| 5593 } | 5593 } |
| 5594 | 5594 |
| 5595 TEST_F(URLRequestTestHTTP, CancelTest3) { | 5595 TEST_F(URLRequestTestHTTP, CancelOnDataReceived) { |
| 5596 ASSERT_TRUE(http_test_server()->Start()); | 5596 ASSERT_TRUE(http_test_server()->Start()); |
| 5597 | 5597 |
| 5598 TestDelegate d; | 5598 TestDelegate d; |
| 5599 { | 5599 { |
| 5600 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5600 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5601 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | |
| 5602 | |
| 5603 d.set_cancel_in_received_data(true); | |
| 5604 | |
| 5605 r->Start(); | |
| 5606 EXPECT_TRUE(r->is_pending()); | |
| 5607 | |
| 5608 base::RunLoop().Run(); | |
| 5609 | |
| 5610 EXPECT_EQ(1, d.response_started_count()); | |
| 5611 EXPECT_NE(0, d.received_bytes_count()); | |
| 5612 // There is no guarantee about how much data was received | |
| 5613 // before the cancel was issued. It could have been 0 bytes, | |
| 5614 // or it could have been all the bytes. | |
| 5615 // EXPECT_EQ(0, d.bytes_received()); | |
| 5616 EXPECT_FALSE(d.received_data_before_response()); | |
| 5617 EXPECT_EQ(ERR_ABORTED, d.request_status()); | |
| 5618 } | |
| 5619 } | |
| 5620 | |
| 5621 TEST_F(URLRequestTestHTTP, CancelDuringEofRead) { | |
| 5622 ASSERT_TRUE(http_test_server()->Start()); | |
| 5623 | |
| 5624 TestDelegate d; | |
| 5625 { | |
| 5626 // This returns an empty response (With headers). | |
| 5627 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | |
| 5601 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 5628 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
|
mmenke
2016/12/02 15:20:08
Note that before the switch to the embedded test s
| |
| 5602 | 5629 |
| 5603 d.set_cancel_in_received_data(true); | 5630 d.set_cancel_in_received_data(true); |
| 5604 | 5631 |
| 5605 r->Start(); | 5632 r->Start(); |
| 5606 EXPECT_TRUE(r->is_pending()); | 5633 EXPECT_TRUE(r->is_pending()); |
| 5607 | 5634 |
| 5608 base::RunLoop().Run(); | 5635 base::RunLoop().Run(); |
| 5609 | 5636 |
| 5610 EXPECT_EQ(1, d.response_started_count()); | 5637 EXPECT_EQ(1, d.response_started_count()); |
| 5638 EXPECT_EQ(0, d.received_bytes_count()); | |
| 5611 // There is no guarantee about how much data was received | 5639 // There is no guarantee about how much data was received |
| 5612 // before the cancel was issued. It could have been 0 bytes, | 5640 // before the cancel was issued. It could have been 0 bytes, |
| 5613 // or it could have been all the bytes. | 5641 // or it could have been all the bytes. |
| 5614 // EXPECT_EQ(0, d.bytes_received()); | 5642 // EXPECT_EQ(0, d.bytes_received()); |
| 5615 EXPECT_FALSE(d.received_data_before_response()); | 5643 EXPECT_FALSE(d.received_data_before_response()); |
| 5616 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 5644 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 5617 } | 5645 } |
| 5618 } | 5646 } |
| 5619 | 5647 |
| 5620 TEST_F(URLRequestTestHTTP, CancelTest4) { | 5648 TEST_F(URLRequestTestHTTP, CancelByDestroyingAfterStart) { |
| 5621 ASSERT_TRUE(http_test_server()->Start()); | 5649 ASSERT_TRUE(http_test_server()->Start()); |
| 5622 | 5650 |
| 5623 TestDelegate d; | 5651 TestDelegate d; |
| 5624 { | 5652 { |
| 5625 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5653 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5626 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 5654 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 5627 | 5655 |
| 5628 r->Start(); | 5656 r->Start(); |
| 5629 EXPECT_TRUE(r->is_pending()); | 5657 EXPECT_TRUE(r->is_pending()); |
| 5630 | 5658 |
| 5631 // The request will be implicitly canceled when it is destroyed. The | 5659 // The request will be implicitly canceled when it is destroyed. The |
| 5632 // test delegate must not post a quit message when this happens because | 5660 // test delegate must not post a quit message when this happens because |
| 5633 // this test doesn't actually have a message loop. The quit message would | 5661 // this test doesn't actually have a message loop. The quit message would |
| 5634 // get put on this thread's message queue and the next test would exit | 5662 // get put on this thread's message queue and the next test would exit |
| 5635 // early, causing problems. | 5663 // early, causing problems. |
| 5636 d.set_quit_on_complete(false); | 5664 d.set_quit_on_complete(false); |
| 5637 } | 5665 } |
| 5638 // expect things to just cleanup properly. | 5666 // expect things to just cleanup properly. |
| 5639 | 5667 |
| 5640 // we won't actually get a received response here because we've never run the | 5668 // we won't actually get a received response here because we've never run the |
| 5641 // message loop | 5669 // message loop |
| 5642 EXPECT_FALSE(d.received_data_before_response()); | 5670 EXPECT_FALSE(d.received_data_before_response()); |
| 5643 EXPECT_EQ(0, d.bytes_received()); | 5671 EXPECT_EQ(0, d.bytes_received()); |
| 5644 } | 5672 } |
| 5645 | 5673 |
| 5646 TEST_F(URLRequestTestHTTP, CancelTest5) { | 5674 TEST_F(URLRequestTestHTTP, CancelWhileReadingFromCache) { |
| 5647 ASSERT_TRUE(http_test_server()->Start()); | 5675 ASSERT_TRUE(http_test_server()->Start()); |
| 5648 | 5676 |
| 5649 // populate cache | 5677 // populate cache |
| 5650 { | 5678 { |
| 5651 TestDelegate d; | 5679 TestDelegate d; |
| 5652 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5680 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5653 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); | 5681 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); |
| 5654 r->Start(); | 5682 r->Start(); |
| 5655 base::RunLoop().Run(); | 5683 base::RunLoop().Run(); |
| 5656 EXPECT_EQ(OK, d.request_status()); | 5684 EXPECT_EQ(OK, d.request_status()); |
| (...skipping 4905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10562 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10590 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 10563 | 10591 |
| 10564 req->Start(); | 10592 req->Start(); |
| 10565 req->Cancel(); | 10593 req->Cancel(); |
| 10566 base::RunLoop().RunUntilIdle(); | 10594 base::RunLoop().RunUntilIdle(); |
| 10567 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 10595 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 10568 EXPECT_EQ(0, d.received_redirect_count()); | 10596 EXPECT_EQ(0, d.received_redirect_count()); |
| 10569 } | 10597 } |
| 10570 | 10598 |
| 10571 } // namespace net | 10599 } // namespace net |
| OLD | NEW |