| 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/test_url_loader_client.h" | 5 #include "content/browser/loader/test_url_loader_client.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 quit_closure_for_on_receive_cached_metadata_.Run(); | 66 quit_closure_for_on_receive_cached_metadata_.Run(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void TestURLLoaderClient::OnTransferSizeUpdated(int32_t transfer_size_diff) { | 69 void TestURLLoaderClient::OnTransferSizeUpdated(int32_t transfer_size_diff) { |
| 70 EXPECT_TRUE(has_received_response_); | 70 EXPECT_TRUE(has_received_response_); |
| 71 EXPECT_FALSE(has_received_completion_); | 71 EXPECT_FALSE(has_received_completion_); |
| 72 EXPECT_GT(transfer_size_diff, 0); | 72 EXPECT_GT(transfer_size_diff, 0); |
| 73 body_transfer_size_ += transfer_size_diff; | 73 body_transfer_size_ += transfer_size_diff; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void TestURLLoaderClient::OnUploadProgress(int64_t current_position, | 76 void TestURLLoaderClient::OnUploadProgress( |
| 77 int64_t total_size, | 77 int64_t current_position, |
| 78 const base::Closure& ack_callback) { | 78 int64_t total_size, |
| 79 OnUploadProgressCallback ack_callback) { |
| 79 EXPECT_TRUE(ack_callback); | 80 EXPECT_TRUE(ack_callback); |
| 80 EXPECT_FALSE(has_received_response_); | 81 EXPECT_FALSE(has_received_response_); |
| 81 EXPECT_FALSE(has_received_completion_); | 82 EXPECT_FALSE(has_received_completion_); |
| 82 EXPECT_LT(0, current_position); | 83 EXPECT_LT(0, current_position); |
| 83 EXPECT_LE(current_position, total_size); | 84 EXPECT_LE(current_position, total_size); |
| 84 | 85 |
| 85 has_received_upload_progress_ = true; | 86 has_received_upload_progress_ = true; |
| 86 current_upload_position_ = current_position; | 87 current_upload_position_ = current_position; |
| 87 total_upload_size_ = total_size; | 88 total_upload_size_ = total_size; |
| 88 ack_callback.Run(); | 89 std::move(ack_callback).Run(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void TestURLLoaderClient::OnStartLoadingResponseBody( | 92 void TestURLLoaderClient::OnStartLoadingResponseBody( |
| 92 mojo::ScopedDataPipeConsumerHandle body) { | 93 mojo::ScopedDataPipeConsumerHandle body) { |
| 93 EXPECT_TRUE(has_received_response_); | 94 EXPECT_TRUE(has_received_response_); |
| 94 EXPECT_FALSE(has_received_completion_); | 95 EXPECT_FALSE(has_received_completion_); |
| 95 response_body_ = std::move(body); | 96 response_body_ = std::move(body); |
| 96 if (quit_closure_for_on_start_loading_response_body_) | 97 if (quit_closure_for_on_start_loading_response_body_) |
| 97 quit_closure_for_on_start_loading_response_body_.Run(); | 98 quit_closure_for_on_start_loading_response_body_.Run(); |
| 98 } | 99 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void TestURLLoaderClient::RunUntilComplete() { | 170 void TestURLLoaderClient::RunUntilComplete() { |
| 170 if (has_received_completion_) | 171 if (has_received_completion_) |
| 171 return; | 172 return; |
| 172 base::RunLoop run_loop; | 173 base::RunLoop run_loop; |
| 173 quit_closure_for_on_complete_ = run_loop.QuitClosure(); | 174 quit_closure_for_on_complete_ = run_loop.QuitClosure(); |
| 174 run_loop.Run(); | 175 run_loop.Run(); |
| 175 quit_closure_for_on_complete_.Reset(); | 176 quit_closure_for_on_complete_.Reset(); |
| 176 } | 177 } |
| 177 | 178 |
| 178 } // namespace content | 179 } // namespace content |
| OLD | NEW |