Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: content/browser/loader/test_url_loader_client.cc

Issue 2951293002: NetworkService: Destroy URLLoaders when a NetworkContext is destroyed. (Closed)
Patch Set: Response to comment, change why destruction is safe Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/loader/test_url_loader_client.h ('k') | content/network/network_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 const base::Optional<net::SSLInfo>& ssl_info, 18 const base::Optional<net::SSLInfo>& ssl_info,
19 mojom::DownloadedTempFilePtr downloaded_file) { 19 mojom::DownloadedTempFilePtr downloaded_file) {
20 EXPECT_FALSE(has_received_response_); 20 EXPECT_FALSE(has_received_response_);
21 EXPECT_FALSE(has_received_cached_metadata_); 21 EXPECT_FALSE(has_received_cached_metadata_);
22 EXPECT_FALSE(has_received_completion_); 22 EXPECT_FALSE(has_received_completion_);
23 has_received_response_ = true; 23 has_received_response_ = true;
24 response_head_ = response_head; 24 response_head_ = response_head;
25 ssl_info_ = ssl_info; 25 ssl_info_ = ssl_info;
26 if (quit_closure_for_on_receive_response_) 26 if (quit_closure_for_on_receive_response_)
27 quit_closure_for_on_receive_response_.Run(); 27 quit_closure_for_on_receive_response_.Run();
28 binding_.set_connection_error_handler(base::Bind(
29 &TestURLLoaderClient::OnConnectionError, base::Unretained(this)));
28 } 30 }
29 31
30 void TestURLLoaderClient::OnReceiveRedirect( 32 void TestURLLoaderClient::OnReceiveRedirect(
31 const net::RedirectInfo& redirect_info, 33 const net::RedirectInfo& redirect_info,
32 const ResourceResponseHead& response_head) { 34 const ResourceResponseHead& response_head) {
33 EXPECT_FALSE(has_received_cached_metadata_); 35 EXPECT_FALSE(has_received_cached_metadata_);
34 EXPECT_FALSE(response_body_.is_valid()); 36 EXPECT_FALSE(response_body_.is_valid());
35 EXPECT_FALSE(has_received_response_); 37 EXPECT_FALSE(has_received_response_);
36 // Use ClearHasReceivedRedirect to accept more redirects. 38 // Use ClearHasReceivedRedirect to accept more redirects.
37 EXPECT_FALSE(has_received_redirect_); 39 EXPECT_FALSE(has_received_redirect_);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 171
170 void TestURLLoaderClient::RunUntilComplete() { 172 void TestURLLoaderClient::RunUntilComplete() {
171 if (has_received_completion_) 173 if (has_received_completion_)
172 return; 174 return;
173 base::RunLoop run_loop; 175 base::RunLoop run_loop;
174 quit_closure_for_on_complete_ = run_loop.QuitClosure(); 176 quit_closure_for_on_complete_ = run_loop.QuitClosure();
175 run_loop.Run(); 177 run_loop.Run();
176 quit_closure_for_on_complete_.Reset(); 178 quit_closure_for_on_complete_.Reset();
177 } 179 }
178 180
181 void TestURLLoaderClient::RunUntilConnectionError() {
182 if (has_received_connection_error_)
183 return;
184 base::RunLoop run_loop;
185 quit_closure_for_on_connection_error_ = run_loop.QuitClosure();
186 run_loop.Run();
187 quit_closure_for_on_connection_error_.Reset();
188 }
189
190 void TestURLLoaderClient::OnConnectionError() {
191 has_received_connection_error_ = true;
192 if (quit_closure_for_on_connection_error_)
193 quit_closure_for_on_connection_error_.Run();
194 }
195
179 } // namespace content 196 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/test_url_loader_client.h ('k') | content/network/network_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698