| OLD | NEW |
| 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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 written += io_buffer_size; | 832 written += io_buffer_size; |
| 833 bool defer = false; | 833 bool defer = false; |
| 834 ASSERT_TRUE(handler_->OnReadCompleted(io_buffer_size, &defer)); | 834 ASSERT_TRUE(handler_->OnReadCompleted(io_buffer_size, &defer)); |
| 835 if (defer) | 835 if (defer) |
| 836 break; | 836 break; |
| 837 } | 837 } |
| 838 | 838 |
| 839 url_loader_client_.RunUntilResponseBodyArrived(); | 839 url_loader_client_.RunUntilResponseBodyArrived(); |
| 840 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); | 840 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); |
| 841 handler_->ResetBeginWriteExpectation(); | 841 handler_->ResetBeginWriteExpectation(); |
| 842 handler_->ResumeForTesting(); | 842 handler_->OnWritableForTesting(); |
| 843 | 843 |
| 844 std::string actual; | 844 std::string actual; |
| 845 while (actual.size() < written) { | 845 while (actual.size() < written) { |
| 846 char buf[16]; | 846 char buf[16]; |
| 847 uint32_t read_size = sizeof(buf); | 847 uint32_t read_size = sizeof(buf); |
| 848 MojoResult result = | 848 MojoResult result = |
| 849 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, | 849 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, |
| 850 MOJO_READ_DATA_FLAG_NONE); | 850 MOJO_READ_DATA_FLAG_NONE); |
| 851 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); | 851 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); |
| 852 if (result == MOJO_RESULT_OK) | 852 if (result == MOJO_RESULT_OK) |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 if (result == MOJO_RESULT_FAILED_PRECONDITION) | 1071 if (result == MOJO_RESULT_FAILED_PRECONDITION) |
| 1072 break; | 1072 break; |
| 1073 base::RunLoop().RunUntilIdle(); | 1073 base::RunLoop().RunUntilIdle(); |
| 1074 DCHECK(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK); | 1074 DCHECK(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK); |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 base::RunLoop().RunUntilIdle(); | 1077 base::RunLoop().RunUntilIdle(); |
| 1078 EXPECT_EQ(0, resource_controller_.num_resume_calls()); | 1078 EXPECT_EQ(0, resource_controller_.num_resume_calls()); |
| 1079 } | 1079 } |
| 1080 | 1080 |
| 1081 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, RedirectHandling) { |
| 1082 rdh_delegate_.set_num_on_response_started_calls_expectation(1); |
| 1083 bool defer = false; |
| 1084 |
| 1085 ASSERT_TRUE(handler_->OnWillStart(request_->url(), &defer)); |
| 1086 ASSERT_FALSE(defer); |
| 1087 scoped_refptr<ResourceResponse> response = new ResourceResponse(); |
| 1088 net::RedirectInfo redirect_info; |
| 1089 redirect_info.status_code = 301; |
| 1090 ASSERT_TRUE( |
| 1091 handler_->OnRequestRedirected(redirect_info, response.get(), &defer)); |
| 1092 ASSERT_TRUE(defer); |
| 1093 |
| 1094 ASSERT_FALSE(url_loader_client_.has_received_response()); |
| 1095 ASSERT_FALSE(url_loader_client_.has_received_redirect()); |
| 1096 url_loader_client_.RunUntilRedirectReceived(); |
| 1097 |
| 1098 ASSERT_FALSE(url_loader_client_.has_received_response()); |
| 1099 ASSERT_TRUE(url_loader_client_.has_received_redirect()); |
| 1100 EXPECT_EQ(301, url_loader_client_.redirect_info().status_code); |
| 1101 |
| 1102 EXPECT_EQ(0, resource_controller_.num_resume_calls()); |
| 1103 handler_->FollowRedirect(); |
| 1104 EXPECT_EQ(1, resource_controller_.num_resume_calls()); |
| 1105 |
| 1106 defer = false; |
| 1107 ASSERT_TRUE(handler_->OnResponseStarted(response.get(), &defer)); |
| 1108 ASSERT_FALSE(defer); |
| 1109 |
| 1110 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, net::OK); |
| 1111 handler_->OnResponseCompleted(status, &defer); |
| 1112 ASSERT_FALSE(defer); |
| 1113 |
| 1114 ASSERT_FALSE(url_loader_client_.has_received_completion()); |
| 1115 url_loader_client_.RunUntilComplete(); |
| 1116 |
| 1117 ASSERT_TRUE(url_loader_client_.has_received_response()); |
| 1118 ASSERT_TRUE(url_loader_client_.has_received_completion()); |
| 1119 EXPECT_EQ(net::OK, url_loader_client_.completion_status().error_code); |
| 1120 } |
| 1121 |
| 1081 // Typically ResourceHandler methods are called in this order. | 1122 // Typically ResourceHandler methods are called in this order. |
| 1082 TEST_P( | 1123 TEST_P( |
| 1083 MojoAsyncResourceHandlerWithAllocationSizeTest, | 1124 MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1084 OnWillStartThenOnResponseStartedThenOnWillReadThenOnReadCompletedThenOnRespo
nseCompleted) { | 1125 OnWillStartThenOnResponseStartedThenOnWillReadThenOnReadCompletedThenOnRespo
nseCompleted) { |
| 1085 rdh_delegate_.set_num_on_response_started_calls_expectation(1); | 1126 rdh_delegate_.set_num_on_response_started_calls_expectation(1); |
| 1086 bool defer = false; | 1127 bool defer = false; |
| 1087 | 1128 |
| 1088 ASSERT_TRUE(handler_->OnWillStart(request_->url(), &defer)); | 1129 ASSERT_TRUE(handler_->OnWillStart(request_->url(), &defer)); |
| 1089 ASSERT_FALSE(defer); | 1130 ASSERT_FALSE(defer); |
| 1090 scoped_refptr<ResourceResponse> response = new ResourceResponse(); | 1131 scoped_refptr<ResourceResponse> response = new ResourceResponse(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 } | 1236 } |
| 1196 } | 1237 } |
| 1197 EXPECT_EQ("B", body); | 1238 EXPECT_EQ("B", body); |
| 1198 } | 1239 } |
| 1199 | 1240 |
| 1200 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1241 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1201 MojoAsyncResourceHandlerWithAllocationSizeTest, | 1242 MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1202 ::testing::Values(8, 32 * 2014)); | 1243 ::testing::Values(8, 32 * 2014)); |
| 1203 } // namespace | 1244 } // namespace |
| 1204 } // namespace content | 1245 } // namespace content |
| OLD | NEW |