OLD | NEW |
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 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) | 5 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) |
6 // rather than as part of test_shell_tests because they rely on being able | 6 // rather than as part of test_shell_tests because they rely on being able |
7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses | 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses |
8 // TYPE_UI, which URLRequest doesn't allow. | 8 // TYPE_UI, which URLRequest doesn't allow. |
9 // | 9 // |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 remaining_bytes_(content.length()), | 151 remaining_bytes_(content.length()), |
152 cursor_(0) { | 152 cursor_(0) { |
153 } | 153 } |
154 | 154 |
155 virtual void Start() OVERRIDE { | 155 virtual void Start() OVERRIDE { |
156 MessageLoop::current()->PostTask( | 156 MessageLoop::current()->PostTask( |
157 FROM_HERE, | 157 FROM_HERE, |
158 base::Bind(&FileWriterDelegateTestJob::NotifyHeadersComplete, this)); | 158 base::Bind(&FileWriterDelegateTestJob::NotifyHeadersComplete, this)); |
159 } | 159 } |
160 | 160 |
161 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read) | 161 virtual bool ReadRawData(net::IOBuffer* buf, |
162 OVERRIDE { | 162 int buf_size, |
| 163 int *bytes_read) OVERRIDE { |
163 if (remaining_bytes_ < buf_size) | 164 if (remaining_bytes_ < buf_size) |
164 buf_size = static_cast<int>(remaining_bytes_); | 165 buf_size = static_cast<int>(remaining_bytes_); |
165 | 166 |
166 for (int i = 0; i < buf_size; ++i) | 167 for (int i = 0; i < buf_size; ++i) |
167 buf->data()[i] = content_[cursor_++]; | 168 buf->data()[i] = content_[cursor_++]; |
168 remaining_bytes_ -= buf_size; | 169 remaining_bytes_ -= buf_size; |
169 | 170 |
170 SetStatus(net::URLRequestStatus()); | 171 SetStatus(net::URLRequestStatus()); |
171 *bytes_read = buf_size; | 172 *bytes_read = buf_size; |
172 return true; | 173 return true; |
173 } | 174 } |
174 | 175 |
175 virtual int GetResponseCode() const OVERRIDE { | 176 virtual int GetResponseCode() const OVERRIDE { |
176 return 200; | 177 return 200; |
177 } | 178 } |
178 | 179 |
| 180 protected: |
| 181 virtual ~FileWriterDelegateTestJob() {} |
| 182 |
179 private: | 183 private: |
180 std::string content_; | 184 std::string content_; |
181 int remaining_bytes_; | 185 int remaining_bytes_; |
182 int cursor_; | 186 int cursor_; |
183 }; | 187 }; |
184 | 188 |
185 } // namespace (anonymous) | 189 } // namespace (anonymous) |
186 | 190 |
187 // static | 191 // static |
188 net::URLRequestJob* FileWriterDelegateTest::Factory( | 192 net::URLRequestJob* FileWriterDelegateTest::Factory( |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status()); | 429 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status()); |
426 EXPECT_TRUE(result_->complete()); | 430 EXPECT_TRUE(result_->complete()); |
427 } | 431 } |
428 | 432 |
429 class FileWriterDelegateUnlimitedTest : public FileWriterDelegateTest { | 433 class FileWriterDelegateUnlimitedTest : public FileWriterDelegateTest { |
430 protected: | 434 protected: |
431 virtual void SetUpTestHelper(const FilePath& path) OVERRIDE; | 435 virtual void SetUpTestHelper(const FilePath& path) OVERRIDE; |
432 }; | 436 }; |
433 | 437 |
434 } // namespace fileapi | 438 } // namespace fileapi |
OLD | NEW |