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

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

Issue 2542843006: ResourceLoader: Fix a bunch of double-cancellation/double-error notification cases. (Closed)
Patch Set: Move comment 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
OLDNEW
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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 EXPECT_EQ(1, did_finish_loading_); 917 EXPECT_EQ(1, did_finish_loading_);
918 EXPECT_EQ(1, raw_ptr_resource_handler_->on_read_completed_called()); 918 EXPECT_EQ(1, raw_ptr_resource_handler_->on_read_completed_called());
919 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_eof()); 919 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_eof());
920 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called()); 920 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called());
921 921
922 EXPECT_EQ(net::ERR_ABORTED, 922 EXPECT_EQ(net::ERR_ABORTED,
923 raw_ptr_resource_handler_->final_status().error()); 923 raw_ptr_resource_handler_->final_status().error());
924 EXPECT_LT(0u, raw_ptr_resource_handler_->body().size()); 924 EXPECT_LT(0u, raw_ptr_resource_handler_->body().size());
925 } 925 }
926 926
927 // This test is broken because ResourceLoader assumes when 927 TEST_F(ResourceLoaderTest, SyncCancelOnReceivedEof) {
928 // URLRequest::was_pending() is false, canceling the request will not result in
929 // a completion notification. This isn't the case - whether or not there's a
930 // notification depends on whether URLRequestJob::NotifyDone() has been invoked
931 // yet - something the URLRequest doesn't even know about, itself. As a result,
932 // the ResourceLoader is notified of cancellation twice.
933 // TODO(mmenke): Fix this.
934 TEST_F(ResourceLoaderTest, DISABLED_SyncCancelOnReceivedEof) {
935 raw_ptr_resource_handler_->set_on_on_read_eof_result(false); 928 raw_ptr_resource_handler_->set_on_on_read_eof_result(false);
936 929
937 loader_->StartRequest(); 930 loader_->StartRequest();
938 raw_ptr_resource_handler_->WaitUntilResponseComplete(); 931 raw_ptr_resource_handler_->WaitUntilResponseComplete();
939 base::RunLoop().RunUntilIdle(); 932 base::RunLoop().RunUntilIdle();
940 EXPECT_EQ(1, did_receive_response_); 933 EXPECT_EQ(1, did_receive_response_);
941 EXPECT_EQ(1, did_finish_loading_); 934 EXPECT_EQ(1, did_finish_loading_);
942 EXPECT_EQ(1, raw_ptr_resource_handler_->on_read_eof()); 935 EXPECT_EQ(1, raw_ptr_resource_handler_->on_read_eof());
943 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called()); 936 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called());
944 937
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1010
1018 EXPECT_EQ(net::ERR_FAILED, raw_ptr_resource_handler_->final_status().error()); 1011 EXPECT_EQ(net::ERR_FAILED, raw_ptr_resource_handler_->final_status().error());
1019 EXPECT_LT(0u, raw_ptr_resource_handler_->body().size()); 1012 EXPECT_LT(0u, raw_ptr_resource_handler_->body().size());
1020 } 1013 }
1021 1014
1022 TEST_F(ResourceLoaderTest, AsyncCancelOnReceivedEof) { 1015 TEST_F(ResourceLoaderTest, AsyncCancelOnReceivedEof) {
1023 raw_ptr_resource_handler_->set_defer_on_read_eof(true); 1016 raw_ptr_resource_handler_->set_defer_on_read_eof(true);
1024 1017
1025 loader_->StartRequest(); 1018 loader_->StartRequest();
1026 raw_ptr_resource_handler_->WaitUntilDeferred(); 1019 raw_ptr_resource_handler_->WaitUntilDeferred();
1027 // Have to spin the message loop for the test to pass - see comment on sync
1028 // version of this test for explanation.
1029 // TODO(mmenke): Remove this line once that's fixed.
1030 base::RunLoop().RunUntilIdle();
1031 raw_ptr_resource_handler_->CancelWithError(net::ERR_FAILED); 1020 raw_ptr_resource_handler_->CancelWithError(net::ERR_FAILED);
1032 base::RunLoop().RunUntilIdle(); 1021 base::RunLoop().RunUntilIdle();
1033 EXPECT_EQ(1, did_receive_response_); 1022 EXPECT_EQ(1, did_receive_response_);
1034 EXPECT_EQ(1, did_finish_loading_); 1023 EXPECT_EQ(1, did_finish_loading_);
1035 EXPECT_EQ(1, raw_ptr_resource_handler_->on_read_eof()); 1024 EXPECT_EQ(1, raw_ptr_resource_handler_->on_read_eof());
1036 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called()); 1025 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called());
1037 1026
1038 EXPECT_EQ(net::ERR_FAILED, raw_ptr_resource_handler_->final_status().error()); 1027 EXPECT_EQ(net::ERR_FAILED, raw_ptr_resource_handler_->final_status().error());
1039 EXPECT_EQ(test_data(), raw_ptr_resource_handler_->body()); 1028 EXPECT_EQ(test_data(), raw_ptr_resource_handler_->body());
1040 } 1029 }
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 1426
1438 // Tests that the effective connection type is not set on non-main frame 1427 // Tests that the effective connection type is not set on non-main frame
1439 // requests. 1428 // requests.
1440 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) { 1429 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) {
1441 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false, 1430 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false,
1442 net::EFFECTIVE_CONNECTION_TYPE_3G, 1431 net::EFFECTIVE_CONNECTION_TYPE_3G,
1443 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); 1432 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1444 } 1433 }
1445 1434
1446 } // namespace content 1435 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698