| 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 | 10 |
| 10 namespace content { | 11 namespace content { |
| 11 | 12 |
| 12 TestURLLoaderClient::TestURLLoaderClient() : binding_(this) {} | 13 TestURLLoaderClient::TestURLLoaderClient() : binding_(this) {} |
| 13 TestURLLoaderClient::~TestURLLoaderClient() {} | 14 TestURLLoaderClient::~TestURLLoaderClient() {} |
| 14 | 15 |
| 15 void TestURLLoaderClient::OnReceiveResponse( | 16 void TestURLLoaderClient::OnReceiveResponse( |
| 16 const ResourceResponseHead& response_head) { | 17 const ResourceResponseHead& response_head) { |
| 17 has_received_response_ = true; | 18 has_received_response_ = true; |
| 18 response_head_ = response_head; | 19 response_head_ = response_head; |
| 19 if (quit_closure_for_on_received_response_) | 20 if (quit_closure_for_on_receive_response_) |
| 20 quit_closure_for_on_received_response_.Run(); | 21 quit_closure_for_on_receive_response_.Run(); |
| 22 } |
| 23 |
| 24 void TestURLLoaderClient::OnReceiveRedirect( |
| 25 const net::RedirectInfo& redirect_info, |
| 26 const ResourceResponseHead& response_head) { |
| 27 EXPECT_FALSE(response_body_.is_valid()); |
| 28 EXPECT_FALSE(has_received_response_); |
| 29 has_received_redirect_ = true; |
| 30 redirect_info_ = redirect_info; |
| 31 response_head_ = response_head; |
| 32 if (quit_closure_for_on_receive_redirect_) |
| 33 quit_closure_for_on_receive_redirect_.Run(); |
| 21 } | 34 } |
| 22 | 35 |
| 23 void TestURLLoaderClient::OnDataDownloaded(int64_t data_length, | 36 void TestURLLoaderClient::OnDataDownloaded(int64_t data_length, |
| 24 int64_t encoded_data_length) { | 37 int64_t encoded_data_length) { |
| 25 has_data_downloaded_ = true; | 38 has_data_downloaded_ = true; |
| 26 download_data_length_ += data_length; | 39 download_data_length_ += data_length; |
| 27 encoded_download_data_length_ += encoded_data_length; | 40 encoded_download_data_length_ += encoded_data_length; |
| 28 if (quit_closure_for_on_data_downloaded_) | 41 if (quit_closure_for_on_data_downloaded_) |
| 29 quit_closure_for_on_data_downloaded_.Run(); | 42 quit_closure_for_on_data_downloaded_.Run(); |
| 30 } | 43 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 52 return client_ptr_info; | 65 return client_ptr_info; |
| 53 } | 66 } |
| 54 | 67 |
| 55 void TestURLLoaderClient::Unbind() { | 68 void TestURLLoaderClient::Unbind() { |
| 56 binding_.Unbind(); | 69 binding_.Unbind(); |
| 57 response_body_.reset(); | 70 response_body_.reset(); |
| 58 } | 71 } |
| 59 | 72 |
| 60 void TestURLLoaderClient::RunUntilResponseReceived() { | 73 void TestURLLoaderClient::RunUntilResponseReceived() { |
| 61 base::RunLoop run_loop; | 74 base::RunLoop run_loop; |
| 62 quit_closure_for_on_received_response_ = run_loop.QuitClosure(); | 75 quit_closure_for_on_receive_response_ = run_loop.QuitClosure(); |
| 63 run_loop.Run(); | 76 run_loop.Run(); |
| 64 quit_closure_for_on_received_response_.Reset(); | 77 quit_closure_for_on_receive_response_.Reset(); |
| 78 } |
| 79 |
| 80 void TestURLLoaderClient::RunUntilRedirectReceived() { |
| 81 base::RunLoop run_loop; |
| 82 quit_closure_for_on_receive_redirect_ = run_loop.QuitClosure(); |
| 83 run_loop.Run(); |
| 84 quit_closure_for_on_receive_redirect_.Reset(); |
| 65 } | 85 } |
| 66 | 86 |
| 67 void TestURLLoaderClient::RunUntilDataDownloaded() { | 87 void TestURLLoaderClient::RunUntilDataDownloaded() { |
| 68 base::RunLoop run_loop; | 88 base::RunLoop run_loop; |
| 69 quit_closure_for_on_data_downloaded_ = run_loop.QuitClosure(); | 89 quit_closure_for_on_data_downloaded_ = run_loop.QuitClosure(); |
| 70 run_loop.Run(); | 90 run_loop.Run(); |
| 71 quit_closure_for_on_data_downloaded_.Reset(); | 91 quit_closure_for_on_data_downloaded_.Reset(); |
| 72 } | 92 } |
| 73 | 93 |
| 74 void TestURLLoaderClient::RunUntilResponseBodyArrived() { | 94 void TestURLLoaderClient::RunUntilResponseBodyArrived() { |
| 75 if (response_body_.is_valid()) | 95 if (response_body_.is_valid()) |
| 76 return; | 96 return; |
| 77 base::RunLoop run_loop; | 97 base::RunLoop run_loop; |
| 78 quit_closure_for_on_start_loading_response_body_ = run_loop.QuitClosure(); | 98 quit_closure_for_on_start_loading_response_body_ = run_loop.QuitClosure(); |
| 79 run_loop.Run(); | 99 run_loop.Run(); |
| 80 quit_closure_for_on_start_loading_response_body_.Reset(); | 100 quit_closure_for_on_start_loading_response_body_.Reset(); |
| 81 } | 101 } |
| 82 | 102 |
| 83 void TestURLLoaderClient::RunUntilComplete() { | 103 void TestURLLoaderClient::RunUntilComplete() { |
| 84 if (has_received_completion_) | 104 if (has_received_completion_) |
| 85 return; | 105 return; |
| 86 base::RunLoop run_loop; | 106 base::RunLoop run_loop; |
| 87 quit_closure_for_on_complete_ = run_loop.QuitClosure(); | 107 quit_closure_for_on_complete_ = run_loop.QuitClosure(); |
| 88 run_loop.Run(); | 108 run_loop.Run(); |
| 89 quit_closure_for_on_complete_.Reset(); | 109 quit_closure_for_on_complete_.Reset(); |
| 90 } | 110 } |
| 91 | 111 |
| 92 } // namespace content | 112 } // namespace content |
| OLD | NEW |