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

Side by Side Diff: net/http/http_response_body_drainer_unittest.cc

Issue 1884943003: HttpStreamParser: Don't reuse sockets which receive unparsed data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: oops Created 4 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 | « net/http/http_response_body_drainer.cc ('k') | net/http/http_stream_parser.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/http/http_response_body_drainer.h" 5 #include "net/http/http_response_body_drainer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cstring> 9 #include <cstring>
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 public: 72 public:
73 MockHttpStream(CloseResultWaiter* result_waiter) 73 MockHttpStream(CloseResultWaiter* result_waiter)
74 : result_waiter_(result_waiter), 74 : result_waiter_(result_waiter),
75 buf_len_(0), 75 buf_len_(0),
76 closed_(false), 76 closed_(false),
77 stall_reads_forever_(false), 77 stall_reads_forever_(false),
78 num_chunks_(0), 78 num_chunks_(0),
79 is_sync_(false), 79 is_sync_(false),
80 is_last_chunk_zero_size_(false), 80 is_last_chunk_zero_size_(false),
81 is_complete_(false), 81 is_complete_(false),
82 can_reuse_connection_(true),
82 weak_factory_(this) {} 83 weak_factory_(this) {}
83 ~MockHttpStream() override {} 84 ~MockHttpStream() override {}
84 85
85 // HttpStream implementation. 86 // HttpStream implementation.
86 int InitializeStream(const HttpRequestInfo* request_info, 87 int InitializeStream(const HttpRequestInfo* request_info,
87 RequestPriority priority, 88 RequestPriority priority,
88 const BoundNetLog& net_log, 89 const BoundNetLog& net_log,
89 const CompletionCallback& callback) override { 90 const CompletionCallback& callback) override {
90 return ERR_UNEXPECTED; 91 return ERR_UNEXPECTED;
91 } 92 }
92 int SendRequest(const HttpRequestHeaders& request_headers, 93 int SendRequest(const HttpRequestHeaders& request_headers,
93 HttpResponseInfo* response, 94 HttpResponseInfo* response,
94 const CompletionCallback& callback) override { 95 const CompletionCallback& callback) override {
95 return ERR_UNEXPECTED; 96 return ERR_UNEXPECTED;
96 } 97 }
97 UploadProgress GetUploadProgress() const override { return UploadProgress(); } 98 UploadProgress GetUploadProgress() const override { return UploadProgress(); }
98 int ReadResponseHeaders(const CompletionCallback& callback) override { 99 int ReadResponseHeaders(const CompletionCallback& callback) override {
99 return ERR_UNEXPECTED; 100 return ERR_UNEXPECTED;
100 } 101 }
101 102
102 bool IsConnectionReused() const override { return false; } 103 bool IsConnectionReused() const override { return false; }
103 void SetConnectionReused() override {} 104 void SetConnectionReused() override {}
104 bool CanReuseConnection() const override { return false; } 105 bool CanReuseConnection() const override { return can_reuse_connection_; }
105 int64_t GetTotalReceivedBytes() const override { return 0; } 106 int64_t GetTotalReceivedBytes() const override { return 0; }
106 int64_t GetTotalSentBytes() const override { return 0; } 107 int64_t GetTotalSentBytes() const override { return 0; }
107 void GetSSLInfo(SSLInfo* ssl_info) override {} 108 void GetSSLInfo(SSLInfo* ssl_info) override {}
108 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {} 109 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {}
109 bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } 110 bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; }
110 Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, 111 Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key,
111 std::vector<uint8_t>* out) override { 112 std::vector<uint8_t>* out) override {
112 ADD_FAILURE(); 113 ADD_FAILURE();
113 return ERR_NOT_IMPLEMENTED; 114 return ERR_NOT_IMPLEMENTED;
114 } 115 }
(...skipping 24 matching lines...) Expand all
139 140
140 // Methods to tweak/observer mock behavior: 141 // Methods to tweak/observer mock behavior:
141 void set_stall_reads_forever() { stall_reads_forever_ = true; } 142 void set_stall_reads_forever() { stall_reads_forever_ = true; }
142 143
143 void set_num_chunks(int num_chunks) { num_chunks_ = num_chunks; } 144 void set_num_chunks(int num_chunks) { num_chunks_ = num_chunks; }
144 145
145 void set_sync() { is_sync_ = true; } 146 void set_sync() { is_sync_ = true; }
146 147
147 void set_is_last_chunk_zero_size() { is_last_chunk_zero_size_ = true; } 148 void set_is_last_chunk_zero_size() { is_last_chunk_zero_size_ = true; }
148 149
150 // Sets result value of CanReuseConnection. Defaults to true.
151 void set_can_reuse_connection(bool can_reuse_connection) {
152 can_reuse_connection_ = can_reuse_connection;
153 }
154
149 private: 155 private:
150 int ReadResponseBodyImpl(IOBuffer* buf, int buf_len); 156 int ReadResponseBodyImpl(IOBuffer* buf, int buf_len);
151 void CompleteRead(); 157 void CompleteRead();
152 158
153 bool closed() const { return closed_; } 159 bool closed() const { return closed_; }
154 160
155 CloseResultWaiter* const result_waiter_; 161 CloseResultWaiter* const result_waiter_;
156 scoped_refptr<IOBuffer> user_buf_; 162 scoped_refptr<IOBuffer> user_buf_;
157 CompletionCallback callback_; 163 CompletionCallback callback_;
158 int buf_len_; 164 int buf_len_;
159 bool closed_; 165 bool closed_;
160 bool stall_reads_forever_; 166 bool stall_reads_forever_;
161 int num_chunks_; 167 int num_chunks_;
162 bool is_sync_; 168 bool is_sync_;
163 bool is_last_chunk_zero_size_; 169 bool is_last_chunk_zero_size_;
164 bool is_complete_; 170 bool is_complete_;
171 bool can_reuse_connection_;
172
165 base::WeakPtrFactory<MockHttpStream> weak_factory_; 173 base::WeakPtrFactory<MockHttpStream> weak_factory_;
174
175 DISALLOW_COPY_AND_ASSIGN(MockHttpStream);
166 }; 176 };
167 177
168 int MockHttpStream::ReadResponseBody(IOBuffer* buf, 178 int MockHttpStream::ReadResponseBody(IOBuffer* buf,
169 int buf_len, 179 int buf_len,
170 const CompletionCallback& callback) { 180 const CompletionCallback& callback) {
171 CHECK(!callback.is_null()); 181 CHECK(!callback.is_null());
172 CHECK(callback_.is_null()); 182 CHECK(callback_.is_null());
173 CHECK(buf); 183 CHECK(buf);
174 184
175 if (stall_reads_forever_) 185 if (stall_reads_forever_)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 TEST_F(HttpResponseBodyDrainerTest, DrainBodyTooLarge) { 318 TEST_F(HttpResponseBodyDrainerTest, DrainBodyTooLarge) {
309 int too_many_chunks = 319 int too_many_chunks =
310 HttpResponseBodyDrainer::kDrainBodyBufferSize / kMagicChunkSize; 320 HttpResponseBodyDrainer::kDrainBodyBufferSize / kMagicChunkSize;
311 too_many_chunks += 1; // Now it's too large. 321 too_many_chunks += 1; // Now it's too large.
312 322
313 mock_stream_->set_num_chunks(too_many_chunks); 323 mock_stream_->set_num_chunks(too_many_chunks);
314 drainer_->Start(session_.get()); 324 drainer_->Start(session_.get());
315 EXPECT_TRUE(result_waiter_.WaitForResult()); 325 EXPECT_TRUE(result_waiter_.WaitForResult());
316 } 326 }
317 327
328 TEST_F(HttpResponseBodyDrainerTest, DrainBodyCantReuse) {
329 mock_stream_->set_num_chunks(1);
330 mock_stream_->set_can_reuse_connection(false);
331 drainer_->Start(session_.get());
332 EXPECT_TRUE(result_waiter_.WaitForResult());
333 }
334
318 } // namespace 335 } // namespace
319 336
320 } // namespace net 337 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_response_body_drainer.cc ('k') | net/http/http_stream_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698