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

Side by Side Diff: content/browser/loader/intercepting_resource_handler_unittest.cc

Issue 2557433005: Revert of Fix a pair of ResourceLoader cancellation/error bugs. (Closed)
Patch Set: 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 | « no previous file | content/browser/loader/resource_loader.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/loader/intercepting_resource_handler.h" 5 #include "content/browser/loader/intercepting_resource_handler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 true, // is_main_frame 226 true, // is_main_frame
227 false, // parent_is_main_frame 227 false, // parent_is_main_frame
228 true, // allow_download 228 true, // allow_download
229 true, // is_async 229 true, // is_async
230 false); // is_using_lofi 230 false); // is_using_lofi
231 231
232 net::URLRequestStatus old_handler_status; 232 net::URLRequestStatus old_handler_status;
233 std::string old_handler_body; 233 std::string old_handler_body;
234 std::unique_ptr<TestResourceHandler> old_handler_scoped( 234 std::unique_ptr<TestResourceHandler> old_handler_scoped(
235 new TestResourceHandler(&old_handler_status, &old_handler_body)); 235 new TestResourceHandler(&old_handler_status, &old_handler_body));
236 // When sending a payload to the old ResourceHandler, the
237 // InterceptingResourceHandler doesn't send a final EOF read.
238 // TODO(mmenke): Should it? Or can we just get rid of that 0-byte read
239 // entirely?
240 old_handler_scoped->set_expect_eof_read(false);
241 TestResourceHandler* old_handler = old_handler_scoped.get(); 236 TestResourceHandler* old_handler = old_handler_scoped.get();
242 scoped_refptr<net::IOBuffer> old_buffer = old_handler->buffer(); 237 scoped_refptr<net::IOBuffer> old_buffer = old_handler->buffer();
243 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( 238 std::unique_ptr<InterceptingResourceHandler> intercepting_handler(
244 new InterceptingResourceHandler(std::move(old_handler_scoped), 239 new InterceptingResourceHandler(std::move(old_handler_scoped),
245 request.get())); 240 request.get()));
246 241
247 scoped_refptr<ResourceResponse> response(new ResourceResponse); 242 scoped_refptr<ResourceResponse> response(new ResourceResponse);
248 243
249 // Simulate the MimeSniffingResourceHandler buffering the data. 244 // Simulate the MimeSniffingResourceHandler buffering the data.
250 scoped_refptr<net::IOBuffer> read_buffer; 245 scoped_refptr<net::IOBuffer> read_buffer;
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 true, // is_async 593 true, // is_async
599 false); // is_using_lofi 594 false); // is_using_lofi
600 595
601 std::unique_ptr<TestResourceController> resource_controller = 596 std::unique_ptr<TestResourceController> resource_controller =
602 base::MakeUnique<TestResourceController>(); 597 base::MakeUnique<TestResourceController>();
603 net::URLRequestStatus old_handler_status = {net::URLRequestStatus::IO_PENDING, 598 net::URLRequestStatus old_handler_status = {net::URLRequestStatus::IO_PENDING,
604 0}; 599 0};
605 std::string old_handler_body; 600 std::string old_handler_body;
606 std::unique_ptr<TestResourceHandler> old_handler( 601 std::unique_ptr<TestResourceHandler> old_handler(
607 new TestResourceHandler(&old_handler_status, &old_handler_body)); 602 new TestResourceHandler(&old_handler_status, &old_handler_body));
608 // When sending a payload to the old ResourceHandler, the
609 // InterceptingResourceHandler doesn't send a final EOF read.
610 // TODO(mmenke): Should it? Or can we just get rid of that 0-byte read
611 // entirely?
612 old_handler->set_expect_eof_read(false);
613 old_handler->SetBufferSize(10); 603 old_handler->SetBufferSize(10);
614 old_handler->set_defer_on_read_completed(true); 604 old_handler->set_defer_on_read_completed(true);
615 605
616 scoped_refptr<net::IOBuffer> old_buffer = old_handler.get()->buffer(); 606 scoped_refptr<net::IOBuffer> old_buffer = old_handler.get()->buffer();
617 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( 607 std::unique_ptr<InterceptingResourceHandler> intercepting_handler(
618 new InterceptingResourceHandler(std::move(old_handler), request.get())); 608 new InterceptingResourceHandler(std::move(old_handler), request.get()));
619 intercepting_handler->SetController(resource_controller.get()); 609 intercepting_handler->SetController(resource_controller.get());
620 610
621 scoped_refptr<ResourceResponse> response(new ResourceResponse); 611 scoped_refptr<ResourceResponse> response(new ResourceResponse);
622 612
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 EXPECT_EQ("T", new_handler_body); 680 EXPECT_EQ("T", new_handler_body);
691 681
692 intercepting_handler->Resume(); 682 intercepting_handler->Resume();
693 EXPECT_EQ(2, resource_controller->resume_calls()); 683 EXPECT_EQ(2, resource_controller->resume_calls());
694 EXPECT_EQ(kPayload, old_handler_body); 684 EXPECT_EQ(kPayload, old_handler_body);
695 EXPECT_EQ(kData, new_handler_body); 685 EXPECT_EQ(kData, new_handler_body);
696 686
697 EXPECT_EQ(old_handler_status.status(), net::URLRequestStatus::SUCCESS); 687 EXPECT_EQ(old_handler_status.status(), net::URLRequestStatus::SUCCESS);
698 EXPECT_EQ(new_handler_status.status(), net::URLRequestStatus::IO_PENDING); 688 EXPECT_EQ(new_handler_status.status(), net::URLRequestStatus::IO_PENDING);
699 689
700 // Final EOF byte is read.
701 ASSERT_TRUE(intercepting_handler->OnReadCompleted(0, &defer));
702 ASSERT_FALSE(defer);
703
704 defer = false; 690 defer = false;
705 intercepting_handler->OnResponseCompleted({net::URLRequestStatus::SUCCESS, 0}, 691 intercepting_handler->OnResponseCompleted({net::URLRequestStatus::SUCCESS, 0},
706 &defer); 692 &defer);
707 ASSERT_TRUE(defer); 693 ASSERT_TRUE(defer);
708 EXPECT_EQ(old_handler_status.status(), net::URLRequestStatus::SUCCESS); 694 EXPECT_EQ(old_handler_status.status(), net::URLRequestStatus::SUCCESS);
709 EXPECT_EQ(new_handler_status.status(), net::URLRequestStatus::SUCCESS); 695 EXPECT_EQ(new_handler_status.status(), net::URLRequestStatus::SUCCESS);
710 } 696 }
711 697
712 // Test cancellation where there is only the old handler in an 698 // Test cancellation where there is only the old handler in an
713 // InterceptingResourceHandler. 699 // InterceptingResourceHandler.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 true, // is_async 753 true, // is_async
768 false); // is_using_lofi 754 false); // is_using_lofi
769 755
770 std::unique_ptr<TestResourceController> resource_controller = 756 std::unique_ptr<TestResourceController> resource_controller =
771 base::MakeUnique<TestResourceController>(); 757 base::MakeUnique<TestResourceController>();
772 net::URLRequestStatus old_handler_status = {net::URLRequestStatus::IO_PENDING, 758 net::URLRequestStatus old_handler_status = {net::URLRequestStatus::IO_PENDING,
773 0}; 759 0};
774 std::string old_handler_body; 760 std::string old_handler_body;
775 std::unique_ptr<TestResourceHandler> old_handler( 761 std::unique_ptr<TestResourceHandler> old_handler(
776 new TestResourceHandler(&old_handler_status, &old_handler_body)); 762 new TestResourceHandler(&old_handler_status, &old_handler_body));
777 // When sending a payload to the old ResourceHandler, the
778 // InterceptingResourceHandler doesn't send a final EOF read.
779 // TODO(mmenke): Should it? Or can we just get rid of that 0-byte read
780 // entirely?
781 old_handler->set_expect_eof_read(false);
782 763
783 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( 764 std::unique_ptr<InterceptingResourceHandler> intercepting_handler(
784 new InterceptingResourceHandler(std::move(old_handler), request.get())); 765 new InterceptingResourceHandler(std::move(old_handler), request.get()));
785 intercepting_handler->SetController(resource_controller.get()); 766 intercepting_handler->SetController(resource_controller.get());
786 767
787 scoped_refptr<ResourceResponse> response(new ResourceResponse); 768 scoped_refptr<ResourceResponse> response(new ResourceResponse);
788 769
789 // Simulate the MimeSniffingResourceHandler buffering the data. 770 // Simulate the MimeSniffingResourceHandler buffering the data.
790 scoped_refptr<net::IOBuffer> read_buffer; 771 scoped_refptr<net::IOBuffer> read_buffer;
791 int buf_size = 0; 772 int buf_size = 0;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 {net::URLRequestStatus::CANCELED, net::ERR_FAILED}, &defer); 879 {net::URLRequestStatus::CANCELED, net::ERR_FAILED}, &defer);
899 ASSERT_TRUE(defer); 880 ASSERT_TRUE(defer);
900 EXPECT_EQ(0, resource_controller->resume_calls()); 881 EXPECT_EQ(0, resource_controller->resume_calls());
901 EXPECT_EQ(net::URLRequestStatus::CANCELED, old_handler_status.status()); 882 EXPECT_EQ(net::URLRequestStatus::CANCELED, old_handler_status.status());
902 EXPECT_EQ(net::URLRequestStatus::CANCELED, new_handler_status.status()); 883 EXPECT_EQ(net::URLRequestStatus::CANCELED, new_handler_status.status());
903 } 884 }
904 885
905 } // namespace 886 } // namespace
906 887
907 } // namespace content 888 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/resource_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698