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

Side by Side Diff: content/browser/fileapi/file_writer_delegate_unittest.cc

Issue 1410643007: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Comments Created 5 years, 1 month 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
OLDNEW
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"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/numerics/safe_conversions.h"
davidben 2015/11/03 22:50:05 Unused?
xunjieli 2015/11/04 01:26:51 Done.
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "content/public/test/async_file_test_helper.h" 17 #include "content/public/test/async_file_test_helper.h"
17 #include "content/public/test/test_file_system_context.h" 18 #include "content/public/test/test_file_system_context.h"
18 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
19 #include "net/base/request_priority.h" 20 #include "net/base/request_priority.h"
20 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
21 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
22 #include "net/url_request/url_request_job.h" 23 #include "net/url_request/url_request_job.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 remaining_bytes_(content.length()), 178 remaining_bytes_(content.length()),
178 cursor_(0) { 179 cursor_(0) {
179 } 180 }
180 181
181 void Start() override { 182 void Start() override {
182 base::ThreadTaskRunnerHandle::Get()->PostTask( 183 base::ThreadTaskRunnerHandle::Get()->PostTask(
183 FROM_HERE, 184 FROM_HERE,
184 base::Bind(&FileWriterDelegateTestJob::NotifyHeadersComplete, this)); 185 base::Bind(&FileWriterDelegateTestJob::NotifyHeadersComplete, this));
185 } 186 }
186 187
187 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override { 188 int ReadRawData(net::IOBuffer* buf, int buf_size) override {
188 if (remaining_bytes_ < buf_size) 189 if (remaining_bytes_ < buf_size)
189 buf_size = static_cast<int>(remaining_bytes_); 190 buf_size = static_cast<int>(remaining_bytes_);
davidben 2015/11/03 22:50:05 [Existing issue, but the static_cast<int> doesn't
xunjieli 2015/11/04 01:26:51 Done.
190 191
191 for (int i = 0; i < buf_size; ++i) 192 for (int i = 0; i < buf_size; ++i)
192 buf->data()[i] = content_[cursor_++]; 193 buf->data()[i] = content_[cursor_++];
193 remaining_bytes_ -= buf_size; 194 remaining_bytes_ -= buf_size;
194 195
195 SetStatus(net::URLRequestStatus()); 196 return buf_size;
196 *bytes_read = buf_size;
197 return true;
198 } 197 }
199 198
200 int GetResponseCode() const override { return 200; } 199 int GetResponseCode() const override { return 200; }
201 200
202 protected: 201 protected:
203 ~FileWriterDelegateTestJob() override {} 202 ~FileWriterDelegateTestJob() override {}
204 203
205 private: 204 private:
206 std::string content_; 205 std::string content_;
207 int remaining_bytes_; 206 int remaining_bytes_;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 file_writer_delegate_.reset(); 488 file_writer_delegate_.reset();
490 489
491 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); 490 EXPECT_EQ(pre_write_usage + allowed_growth, usage());
492 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); 491 EXPECT_EQ(GetFileSizeOnDisk("test"), usage());
493 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); 492 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written());
494 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); 493 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status());
495 } 494 }
496 } 495 }
497 496
498 } // namespace content 497 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698