| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 void TestURLLoaderClient::OnDataDownloaded(int64_t data_length, | 39 void TestURLLoaderClient::OnDataDownloaded(int64_t data_length, |
| 40 int64_t encoded_data_length) { | 40 int64_t encoded_data_length) { |
| 41 has_data_downloaded_ = true; | 41 has_data_downloaded_ = true; |
| 42 download_data_length_ += data_length; | 42 download_data_length_ += data_length; |
| 43 encoded_download_data_length_ += encoded_data_length; | 43 encoded_download_data_length_ += encoded_data_length; |
| 44 if (quit_closure_for_on_data_downloaded_) | 44 if (quit_closure_for_on_data_downloaded_) |
| 45 quit_closure_for_on_data_downloaded_.Run(); | 45 quit_closure_for_on_data_downloaded_.Run(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void TestURLLoaderClient::OnReceiveCachedMetadata( |
| 49 const std::vector<uint8_t>& data) { |
| 50 EXPECT_FALSE(has_received_cached_metadata_); |
| 51 EXPECT_TRUE(has_received_response_); |
| 52 EXPECT_FALSE(has_received_completion_); |
| 53 has_received_cached_metadata_ = true; |
| 54 cached_metadata_ = |
| 55 std::string(reinterpret_cast<const char*>(data.data()), data.size()); |
| 56 if (quit_closure_for_on_receive_cached_metadata_) |
| 57 quit_closure_for_on_receive_cached_metadata_.Run(); |
| 58 } |
| 59 |
| 48 void TestURLLoaderClient::OnTransferSizeUpdated(int32_t transfer_size_diff) { | 60 void TestURLLoaderClient::OnTransferSizeUpdated(int32_t transfer_size_diff) { |
| 49 EXPECT_GT(transfer_size_diff, 0); | 61 EXPECT_GT(transfer_size_diff, 0); |
| 50 body_transfer_size_ += transfer_size_diff; | 62 body_transfer_size_ += transfer_size_diff; |
| 51 } | 63 } |
| 52 | 64 |
| 53 void TestURLLoaderClient::OnStartLoadingResponseBody( | 65 void TestURLLoaderClient::OnStartLoadingResponseBody( |
| 54 mojo::ScopedDataPipeConsumerHandle body) { | 66 mojo::ScopedDataPipeConsumerHandle body) { |
| 55 response_body_ = std::move(body); | 67 response_body_ = std::move(body); |
| 56 if (quit_closure_for_on_start_loading_response_body_) | 68 if (quit_closure_for_on_start_loading_response_body_) |
| 57 quit_closure_for_on_start_loading_response_body_.Run(); | 69 quit_closure_for_on_start_loading_response_body_.Run(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 binding_.Bind(&client_ptr_info, associated_group); | 88 binding_.Bind(&client_ptr_info, associated_group); |
| 77 return client_ptr_info; | 89 return client_ptr_info; |
| 78 } | 90 } |
| 79 | 91 |
| 80 void TestURLLoaderClient::Unbind() { | 92 void TestURLLoaderClient::Unbind() { |
| 81 binding_.Unbind(); | 93 binding_.Unbind(); |
| 82 response_body_.reset(); | 94 response_body_.reset(); |
| 83 } | 95 } |
| 84 | 96 |
| 85 void TestURLLoaderClient::RunUntilResponseReceived() { | 97 void TestURLLoaderClient::RunUntilResponseReceived() { |
| 98 if (has_received_response_) |
| 99 return; |
| 86 base::RunLoop run_loop; | 100 base::RunLoop run_loop; |
| 87 quit_closure_for_on_receive_response_ = run_loop.QuitClosure(); | 101 quit_closure_for_on_receive_response_ = run_loop.QuitClosure(); |
| 88 run_loop.Run(); | 102 run_loop.Run(); |
| 89 quit_closure_for_on_receive_response_.Reset(); | 103 quit_closure_for_on_receive_response_.Reset(); |
| 90 } | 104 } |
| 91 | 105 |
| 92 void TestURLLoaderClient::RunUntilRedirectReceived() { | 106 void TestURLLoaderClient::RunUntilRedirectReceived() { |
| 107 if (has_received_redirect_) |
| 108 return; |
| 93 base::RunLoop run_loop; | 109 base::RunLoop run_loop; |
| 94 quit_closure_for_on_receive_redirect_ = run_loop.QuitClosure(); | 110 quit_closure_for_on_receive_redirect_ = run_loop.QuitClosure(); |
| 95 run_loop.Run(); | 111 run_loop.Run(); |
| 96 quit_closure_for_on_receive_redirect_.Reset(); | 112 quit_closure_for_on_receive_redirect_.Reset(); |
| 97 } | 113 } |
| 98 | 114 |
| 99 void TestURLLoaderClient::RunUntilDataDownloaded() { | 115 void TestURLLoaderClient::RunUntilDataDownloaded() { |
| 116 if (has_data_downloaded_) |
| 117 return; |
| 100 base::RunLoop run_loop; | 118 base::RunLoop run_loop; |
| 101 quit_closure_for_on_data_downloaded_ = run_loop.QuitClosure(); | 119 quit_closure_for_on_data_downloaded_ = run_loop.QuitClosure(); |
| 102 run_loop.Run(); | 120 run_loop.Run(); |
| 103 quit_closure_for_on_data_downloaded_.Reset(); | 121 quit_closure_for_on_data_downloaded_.Reset(); |
| 104 } | 122 } |
| 105 | 123 |
| 124 void TestURLLoaderClient::RunUntilCachedMetadataReceived() { |
| 125 if (has_received_cached_metadata_) |
| 126 return; |
| 127 base::RunLoop run_loop; |
| 128 quit_closure_for_on_receive_cached_metadata_ = run_loop.QuitClosure(); |
| 129 run_loop.Run(); |
| 130 quit_closure_for_on_receive_cached_metadata_.Reset(); |
| 131 } |
| 132 |
| 106 void TestURLLoaderClient::RunUntilResponseBodyArrived() { | 133 void TestURLLoaderClient::RunUntilResponseBodyArrived() { |
| 107 if (response_body_.is_valid()) | 134 if (response_body_.is_valid()) |
| 108 return; | 135 return; |
| 109 base::RunLoop run_loop; | 136 base::RunLoop run_loop; |
| 110 quit_closure_for_on_start_loading_response_body_ = run_loop.QuitClosure(); | 137 quit_closure_for_on_start_loading_response_body_ = run_loop.QuitClosure(); |
| 111 run_loop.Run(); | 138 run_loop.Run(); |
| 112 quit_closure_for_on_start_loading_response_body_.Reset(); | 139 quit_closure_for_on_start_loading_response_body_.Reset(); |
| 113 } | 140 } |
| 114 | 141 |
| 115 void TestURLLoaderClient::RunUntilComplete() { | 142 void TestURLLoaderClient::RunUntilComplete() { |
| 116 if (has_received_completion_) | 143 if (has_received_completion_) |
| 117 return; | 144 return; |
| 118 base::RunLoop run_loop; | 145 base::RunLoop run_loop; |
| 119 quit_closure_for_on_complete_ = run_loop.QuitClosure(); | 146 quit_closure_for_on_complete_ = run_loop.QuitClosure(); |
| 120 run_loop.Run(); | 147 run_loop.Run(); |
| 121 quit_closure_for_on_complete_.Reset(); | 148 quit_closure_for_on_complete_.Reset(); |
| 122 } | 149 } |
| 123 | 150 |
| 124 } // namespace content | 151 } // namespace content |
| OLD | NEW |