OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 public: | 168 public: |
169 FileWriterDelegateTestJob(net::URLRequest* request, | 169 FileWriterDelegateTestJob(net::URLRequest* request, |
170 net::NetworkDelegate* network_delegate, | 170 net::NetworkDelegate* network_delegate, |
171 const std::string& content) | 171 const std::string& content) |
172 : net::URLRequestJob(request, network_delegate), | 172 : net::URLRequestJob(request, network_delegate), |
173 content_(content), | 173 content_(content), |
174 remaining_bytes_(content.length()), | 174 remaining_bytes_(content.length()), |
175 cursor_(0) { | 175 cursor_(0) { |
176 } | 176 } |
177 | 177 |
178 virtual void Start() override { | 178 void Start() override { |
179 base::MessageLoop::current()->PostTask( | 179 base::MessageLoop::current()->PostTask( |
180 FROM_HERE, | 180 FROM_HERE, |
181 base::Bind(&FileWriterDelegateTestJob::NotifyHeadersComplete, this)); | 181 base::Bind(&FileWriterDelegateTestJob::NotifyHeadersComplete, this)); |
182 } | 182 } |
183 | 183 |
184 virtual bool ReadRawData(net::IOBuffer* buf, | 184 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override { |
185 int buf_size, | |
186 int *bytes_read) override { | |
187 if (remaining_bytes_ < buf_size) | 185 if (remaining_bytes_ < buf_size) |
188 buf_size = static_cast<int>(remaining_bytes_); | 186 buf_size = static_cast<int>(remaining_bytes_); |
189 | 187 |
190 for (int i = 0; i < buf_size; ++i) | 188 for (int i = 0; i < buf_size; ++i) |
191 buf->data()[i] = content_[cursor_++]; | 189 buf->data()[i] = content_[cursor_++]; |
192 remaining_bytes_ -= buf_size; | 190 remaining_bytes_ -= buf_size; |
193 | 191 |
194 SetStatus(net::URLRequestStatus()); | 192 SetStatus(net::URLRequestStatus()); |
195 *bytes_read = buf_size; | 193 *bytes_read = buf_size; |
196 return true; | 194 return true; |
197 } | 195 } |
198 | 196 |
199 virtual int GetResponseCode() const override { | 197 int GetResponseCode() const override { return 200; } |
200 return 200; | |
201 } | |
202 | 198 |
203 protected: | 199 protected: |
204 virtual ~FileWriterDelegateTestJob() {} | 200 ~FileWriterDelegateTestJob() override {} |
205 | 201 |
206 private: | 202 private: |
207 std::string content_; | 203 std::string content_; |
208 int remaining_bytes_; | 204 int remaining_bytes_; |
209 int cursor_; | 205 int cursor_; |
210 }; | 206 }; |
211 | 207 |
212 class BlobURLRequestJobFactory : public net::URLRequestJobFactory { | 208 class BlobURLRequestJobFactory : public net::URLRequestJobFactory { |
213 public: | 209 public: |
214 explicit BlobURLRequestJobFactory(const char** content_data) | 210 explicit BlobURLRequestJobFactory(const char** content_data) |
215 : content_data_(content_data) { | 211 : content_data_(content_data) { |
216 } | 212 } |
217 | 213 |
218 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | 214 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( |
219 const std::string& scheme, | 215 const std::string& scheme, |
220 net::URLRequest* request, | 216 net::URLRequest* request, |
221 net::NetworkDelegate* network_delegate) const override { | 217 net::NetworkDelegate* network_delegate) const override { |
222 return new FileWriterDelegateTestJob( | 218 return new FileWriterDelegateTestJob( |
223 request, network_delegate, *content_data_); | 219 request, network_delegate, *content_data_); |
224 } | 220 } |
225 | 221 |
226 virtual bool IsHandledProtocol(const std::string& scheme) const override { | 222 bool IsHandledProtocol(const std::string& scheme) const override { |
227 return scheme == "blob"; | 223 return scheme == "blob"; |
228 } | 224 } |
229 | 225 |
230 virtual bool IsHandledURL(const GURL& url) const override { | 226 bool IsHandledURL(const GURL& url) const override { |
231 return url.SchemeIs("blob"); | 227 return url.SchemeIs("blob"); |
232 } | 228 } |
233 | 229 |
234 virtual bool IsSafeRedirectTarget(const GURL& location) const override { | 230 bool IsSafeRedirectTarget(const GURL& location) const override { |
235 return true; | 231 return true; |
236 } | 232 } |
237 | 233 |
238 private: | 234 private: |
239 const char** content_data_; | 235 const char** content_data_; |
240 | 236 |
241 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJobFactory); | 237 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJobFactory); |
242 }; | 238 }; |
243 | 239 |
244 } // namespace (anonymous) | 240 } // namespace (anonymous) |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 file_writer_delegate_.reset(); | 473 file_writer_delegate_.reset(); |
478 | 474 |
479 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); | 475 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); |
480 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); | 476 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); |
481 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); | 477 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); |
482 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); | 478 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); |
483 } | 479 } |
484 } | 480 } |
485 | 481 |
486 } // namespace content | 482 } // namespace content |
OLD | NEW |