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 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 TestURLLoaderClient::TestURLLoaderClient() : binding_(this) {} | 13 TestURLLoaderClient::TestURLLoaderClient() : binding_(this) {} |
14 TestURLLoaderClient::~TestURLLoaderClient() {} | 14 TestURLLoaderClient::~TestURLLoaderClient() {} |
15 | 15 |
16 void TestURLLoaderClient::OnReceiveResponse( | 16 void TestURLLoaderClient::OnReceiveResponse( |
17 const ResourceResponseHead& response_head, | 17 const ResourceResponseHead& response_head, |
18 mojom::DownloadedTempFileAssociatedPtrInfo downloaded_file) { | 18 mojom::DownloadedTempFilePtr downloaded_file) { |
19 EXPECT_FALSE(has_received_response_); | 19 EXPECT_FALSE(has_received_response_); |
20 EXPECT_FALSE(has_received_cached_metadata_); | 20 EXPECT_FALSE(has_received_cached_metadata_); |
21 EXPECT_FALSE(has_received_completion_); | 21 EXPECT_FALSE(has_received_completion_); |
22 has_received_response_ = true; | 22 has_received_response_ = true; |
23 response_head_ = response_head; | 23 response_head_ = response_head; |
24 if (quit_closure_for_on_receive_response_) | 24 if (quit_closure_for_on_receive_response_) |
25 quit_closure_for_on_receive_response_.Run(); | 25 quit_closure_for_on_receive_response_.Run(); |
26 } | 26 } |
27 | 27 |
28 void TestURLLoaderClient::OnReceiveRedirect( | 28 void TestURLLoaderClient::OnReceiveRedirect( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 has_received_completion_ = true; | 101 has_received_completion_ = true; |
102 completion_status_ = status; | 102 completion_status_ = status; |
103 if (quit_closure_for_on_complete_) | 103 if (quit_closure_for_on_complete_) |
104 quit_closure_for_on_complete_.Run(); | 104 quit_closure_for_on_complete_.Run(); |
105 } | 105 } |
106 | 106 |
107 void TestURLLoaderClient::ClearHasReceivedRedirect() { | 107 void TestURLLoaderClient::ClearHasReceivedRedirect() { |
108 has_received_redirect_ = false; | 108 has_received_redirect_ = false; |
109 } | 109 } |
110 | 110 |
111 mojom::URLLoaderClientAssociatedPtrInfo | 111 mojom::URLLoaderClientPtr TestURLLoaderClient::CreateInterfacePtr() { |
112 TestURLLoaderClient::CreateRemoteAssociatedPtrInfo() { | 112 mojom::URLLoaderClientPtr client_ptr; |
113 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info; | 113 binding_.Bind(&client_ptr); |
114 binding_.Bind(&client_ptr_info); | 114 return client_ptr; |
115 return client_ptr_info; | |
116 } | 115 } |
117 | 116 |
118 void TestURLLoaderClient::Unbind() { | 117 void TestURLLoaderClient::Unbind() { |
119 binding_.Unbind(); | 118 binding_.Unbind(); |
120 response_body_.reset(); | 119 response_body_.reset(); |
121 } | 120 } |
122 | 121 |
123 void TestURLLoaderClient::RunUntilResponseReceived() { | 122 void TestURLLoaderClient::RunUntilResponseReceived() { |
124 if (has_received_response_) | 123 if (has_received_response_) |
125 return; | 124 return; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 void TestURLLoaderClient::RunUntilComplete() { | 167 void TestURLLoaderClient::RunUntilComplete() { |
169 if (has_received_completion_) | 168 if (has_received_completion_) |
170 return; | 169 return; |
171 base::RunLoop run_loop; | 170 base::RunLoop run_loop; |
172 quit_closure_for_on_complete_ = run_loop.QuitClosure(); | 171 quit_closure_for_on_complete_ = run_loop.QuitClosure(); |
173 run_loop.Run(); | 172 run_loop.Run(); |
174 quit_closure_for_on_complete_.Reset(); | 173 quit_closure_for_on_complete_.Reset(); |
175 } | 174 } |
176 | 175 |
177 } // namespace content | 176 } // namespace content |
OLD | NEW |