Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 2542843006: ResourceLoader: Fix a bunch of double-cancellation/double-error notification cases. (Closed)
Patch Set: Fix merge Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | remoting/host/token_validator_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 EXPECT_FALSE(d.received_data_before_response());
5613 EXPECT_EQ(ERR_ABORTED, d.request_status());
5614 }
5615 }
5616
5617 TEST_F(URLRequestTestHTTP, CancelDuringEofRead) {
5618 ASSERT_TRUE(http_test_server()->Start());
5619
5620 TestDelegate d;
5621 {
5622 // This returns an empty response (With headers).
5623 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
5601 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); 5624 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d));
5602 5625
5603 d.set_cancel_in_received_data(true); 5626 d.set_cancel_in_received_data(true);
5604 5627
5605 r->Start(); 5628 r->Start();
5606 EXPECT_TRUE(r->is_pending()); 5629 EXPECT_TRUE(r->is_pending());
5607 5630
5608 base::RunLoop().Run(); 5631 base::RunLoop().Run();
5609 5632
5610 EXPECT_EQ(1, d.response_started_count()); 5633 EXPECT_EQ(1, d.response_started_count());
5611 // There is no guarantee about how much data was received 5634 EXPECT_EQ(0, d.received_bytes_count());
5612 // before the cancel was issued. It could have been 0 bytes,
5613 // or it could have been all the bytes.
5614 // EXPECT_EQ(0, d.bytes_received());
5615 EXPECT_FALSE(d.received_data_before_response()); 5635 EXPECT_FALSE(d.received_data_before_response());
5616 EXPECT_EQ(ERR_ABORTED, d.request_status()); 5636 EXPECT_EQ(ERR_ABORTED, d.request_status());
5617 } 5637 }
5618 } 5638 }
5619 5639
5620 TEST_F(URLRequestTestHTTP, CancelTest4) { 5640 TEST_F(URLRequestTestHTTP, CancelByDestroyingAfterStart) {
5621 ASSERT_TRUE(http_test_server()->Start()); 5641 ASSERT_TRUE(http_test_server()->Start());
5622 5642
5623 TestDelegate d; 5643 TestDelegate d;
5624 { 5644 {
5625 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 5645 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
5626 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); 5646 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d));
5627 5647
5628 r->Start(); 5648 r->Start();
5629 EXPECT_TRUE(r->is_pending()); 5649 EXPECT_TRUE(r->is_pending());
5630 5650
5631 // The request will be implicitly canceled when it is destroyed. The 5651 // The request will be implicitly canceled when it is destroyed. The
5632 // test delegate must not post a quit message when this happens because 5652 // 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 5653 // 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 5654 // get put on this thread's message queue and the next test would exit
5635 // early, causing problems. 5655 // early, causing problems.
5636 d.set_quit_on_complete(false); 5656 d.set_quit_on_complete(false);
5637 } 5657 }
5638 // expect things to just cleanup properly. 5658 // expect things to just cleanup properly.
5639 5659
5640 // we won't actually get a received response here because we've never run the 5660 // we won't actually get a received response here because we've never run the
5641 // message loop 5661 // message loop
5642 EXPECT_FALSE(d.received_data_before_response()); 5662 EXPECT_FALSE(d.received_data_before_response());
5643 EXPECT_EQ(0, d.bytes_received()); 5663 EXPECT_EQ(0, d.bytes_received());
5644 } 5664 }
5645 5665
5646 TEST_F(URLRequestTestHTTP, CancelTest5) { 5666 TEST_F(URLRequestTestHTTP, CancelWhileReadingFromCache) {
5647 ASSERT_TRUE(http_test_server()->Start()); 5667 ASSERT_TRUE(http_test_server()->Start());
5648 5668
5649 // populate cache 5669 // populate cache
5650 { 5670 {
5651 TestDelegate d; 5671 TestDelegate d;
5652 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 5672 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
5653 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); 5673 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d));
5654 r->Start(); 5674 r->Start();
5655 base::RunLoop().Run(); 5675 base::RunLoop().Run();
5656 EXPECT_EQ(OK, d.request_status()); 5676 EXPECT_EQ(OK, d.request_status());
(...skipping 4957 matching lines...) Expand 10 before | Expand all | Expand 10 after
10614 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10634 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10615 10635
10616 req->Start(); 10636 req->Start();
10617 req->Cancel(); 10637 req->Cancel();
10618 base::RunLoop().RunUntilIdle(); 10638 base::RunLoop().RunUntilIdle();
10619 EXPECT_EQ(ERR_ABORTED, d.request_status()); 10639 EXPECT_EQ(ERR_ABORTED, d.request_status());
10620 EXPECT_EQ(0, d.received_redirect_count()); 10640 EXPECT_EQ(0, d.received_redirect_count());
10621 } 10641 }
10622 10642
10623 } // namespace net 10643 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | remoting/host/token_validator_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698