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

Side by Side Diff: content/child/test_request_peer.cc

Issue 2597873002: Move URLLoaderClientImpl to a separate file (Closed)
Patch Set: fix Created 4 years 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/child/test_request_peer.h ('k') | content/child/url_loader_client_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/child/test_request_peer.h"
6
7 #include "content/child/resource_dispatcher.h"
8 #include "net/url_request/redirect_info.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12
13 TestRequestPeer::TestRequestPeer(ResourceDispatcher* dispatcher,
14 Context* context)
15 : dispatcher_(dispatcher), context_(context) {}
16
17 TestRequestPeer::~TestRequestPeer() = default;
18
19 void TestRequestPeer::OnUploadProgress(uint64_t position, uint64_t size) {
20 EXPECT_FALSE(context_->complete);
21 }
22
23 bool TestRequestPeer::OnReceivedRedirect(const net::RedirectInfo& redirect_info,
24 const ResourceResponseInfo& info) {
25 EXPECT_FALSE(context_->cancelled);
26 EXPECT_FALSE(context_->complete);
27 ++context_->seen_redirects;
28 if (context_->defer_on_redirect)
29 dispatcher_->SetDefersLoading(context_->request_id, true);
30 return context_->follow_redirects;
31 }
32
33 void TestRequestPeer::OnReceivedResponse(const ResourceResponseInfo& info) {
34 EXPECT_FALSE(context_->cancelled);
35 EXPECT_FALSE(context_->received_response);
36 EXPECT_FALSE(context_->complete);
37 context_->received_response = true;
38 if (context_->cancel_on_receive_response) {
39 dispatcher_->Cancel(context_->request_id);
40 context_->cancelled = true;
41 }
42 }
43
44 void TestRequestPeer::OnDownloadedData(int len, int encoded_data_length) {
45 EXPECT_TRUE(context_->received_response);
46 EXPECT_FALSE(context_->cancelled);
47 EXPECT_FALSE(context_->complete);
48 context_->total_downloaded_data_length += len;
49 context_->total_encoded_data_length += encoded_data_length;
50 }
51
52 void TestRequestPeer::OnReceivedData(std::unique_ptr<ReceivedData> data) {
53 if (context_->cancelled)
54 return;
55 EXPECT_TRUE(context_->received_response);
56 EXPECT_FALSE(context_->complete);
57 context_->data.append(data->payload(), data->length());
58
59 if (context_->cancel_on_receive_data) {
60 dispatcher_->Cancel(context_->request_id);
61 context_->cancelled = true;
62 }
63 }
64
65 void TestRequestPeer::OnTransferSizeUpdated(int transfer_size_diff) {
66 EXPECT_TRUE(context_->received_response);
67 EXPECT_FALSE(context_->complete);
68 if (context_->cancelled)
69 return;
70 context_->total_encoded_data_length += transfer_size_diff;
71 }
72
73 void TestRequestPeer::OnCompletedRequest(int error_code,
74 bool was_ignored_by_handler,
75 bool stale_copy_in_cache,
76 const base::TimeTicks& completion_time,
77 int64_t total_transfer_size,
78 int64_t encoded_body_size) {
79 if (context_->cancelled)
80 return;
81 EXPECT_TRUE(context_->received_response);
82 EXPECT_FALSE(context_->complete);
83 context_->complete = true;
84 }
85
86 TestRequestPeer::Context::Context() = default;
87 TestRequestPeer::Context::~Context() = default;
88
89 } // namespace content
OLDNEW
« no previous file with comments | « content/child/test_request_peer.h ('k') | content/child/url_loader_client_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698