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

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

Issue 2467833002: Implement redirect handling on MojoAsyncResourceHandler (Closed)
Patch Set: fix Created 4 years, 1 month 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 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/mojo_async_resource_handler.h" 5 #include "content/browser/loader/mojo_async_resource_handler.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 written += io_buffer_size; 846 written += io_buffer_size;
847 bool defer = false; 847 bool defer = false;
848 ASSERT_TRUE(handler_->OnReadCompleted(io_buffer_size, &defer)); 848 ASSERT_TRUE(handler_->OnReadCompleted(io_buffer_size, &defer));
849 if (defer) 849 if (defer)
850 break; 850 break;
851 } 851 }
852 852
853 url_loader_client_.RunUntilResponseBodyArrived(); 853 url_loader_client_.RunUntilResponseBodyArrived();
854 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 854 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
855 handler_->ResetBeginWriteExpectation(); 855 handler_->ResetBeginWriteExpectation();
856 handler_->ResumeForTesting(); 856 handler_->OnWritableForTesting();
857 857
858 std::string actual; 858 std::string actual;
859 while (actual.size() < written) { 859 while (actual.size() < written) {
860 char buf[16]; 860 char buf[16];
861 uint32_t read_size = sizeof(buf); 861 uint32_t read_size = sizeof(buf);
862 MojoResult result = 862 MojoResult result =
863 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, 863 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size,
864 MOJO_READ_DATA_FLAG_NONE); 864 MOJO_READ_DATA_FLAG_NONE);
865 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); 865 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT);
866 if (result == MOJO_RESULT_OK) 866 if (result == MOJO_RESULT_OK)
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 if (result == MOJO_RESULT_FAILED_PRECONDITION) 1085 if (result == MOJO_RESULT_FAILED_PRECONDITION)
1086 break; 1086 break;
1087 base::RunLoop().RunUntilIdle(); 1087 base::RunLoop().RunUntilIdle();
1088 DCHECK(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK); 1088 DCHECK(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK);
1089 } 1089 }
1090 1090
1091 base::RunLoop().RunUntilIdle(); 1091 base::RunLoop().RunUntilIdle();
1092 EXPECT_EQ(0, resource_controller_.num_resume_calls()); 1092 EXPECT_EQ(0, resource_controller_.num_resume_calls());
1093 } 1093 }
1094 1094
1095 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, RedirectHandling) {
1096 bool defer = false;
1097
1098 ASSERT_TRUE(handler_->OnWillStart(request_->url(), &defer));
1099 ASSERT_FALSE(defer);
1100 scoped_refptr<ResourceResponse> response = new ResourceResponse();
1101 net::RedirectInfo redirect_info;
1102 redirect_info.status_code = 301;
1103 ASSERT_TRUE(
1104 handler_->OnRequestRedirected(redirect_info, response.get(), &defer));
1105 ASSERT_TRUE(defer);
1106
1107 ASSERT_FALSE(url_loader_client_.has_received_response());
1108 ASSERT_FALSE(url_loader_client_.has_received_redirect());
1109 url_loader_client_.RunUntilRedirectReceived();
1110
1111 ASSERT_FALSE(url_loader_client_.has_received_response());
1112 ASSERT_TRUE(url_loader_client_.has_received_redirect());
mmenke 2016/11/10 21:42:41 Check that there was only one received redirect ca
yhirano 2016/11/11 09:47:04 Done in TestResourceClient.
1113 EXPECT_EQ(301, url_loader_client_.redirect_info().status_code);
1114
1115 EXPECT_EQ(0, resource_controller_.num_resume_calls());
1116 handler_->FollowRedirect();
1117 EXPECT_EQ(1, resource_controller_.num_resume_calls());
mmenke 2016/11/10 21:42:41 Let's continue this request to completion. Otherw
yhirano 2016/11/11 09:47:04 Done.
1118 }
1119
1095 // Typically ResourceHandler methods are called in this order. 1120 // Typically ResourceHandler methods are called in this order.
1096 TEST_P( 1121 TEST_P(
1097 MojoAsyncResourceHandlerWithAllocationSizeTest, 1122 MojoAsyncResourceHandlerWithAllocationSizeTest,
1098 OnWillStartThenOnResponseStartedThenOnWillReadThenOnReadCompletedThenOnRespo nseCompleted) { 1123 OnWillStartThenOnResponseStartedThenOnWillReadThenOnReadCompletedThenOnRespo nseCompleted) {
1099 rdh_delegate_.set_num_on_response_started_calls_expectation(1); 1124 rdh_delegate_.set_num_on_response_started_calls_expectation(1);
1100 bool defer = false; 1125 bool defer = false;
1101 1126
1102 ASSERT_TRUE(handler_->OnWillStart(request_->url(), &defer)); 1127 ASSERT_TRUE(handler_->OnWillStart(request_->url(), &defer));
1103 ASSERT_FALSE(defer); 1128 ASSERT_FALSE(defer);
1104 scoped_refptr<ResourceResponse> response = new ResourceResponse(); 1129 scoped_refptr<ResourceResponse> response = new ResourceResponse();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 } 1234 }
1210 } 1235 }
1211 EXPECT_EQ("B", body); 1236 EXPECT_EQ("B", body);
1212 } 1237 }
1213 1238
1214 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 1239 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
1215 MojoAsyncResourceHandlerWithAllocationSizeTest, 1240 MojoAsyncResourceHandlerWithAllocationSizeTest,
1216 ::testing::Values(8, 32 * 2014)); 1241 ::testing::Values(8, 32 * 2014));
1217 } // namespace 1242 } // namespace
1218 } // namespace content 1243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698