| 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" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/location.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" |
| 14 #include "content/public/test/async_file_test_helper.h" | 16 #include "content/public/test/async_file_test_helper.h" |
| 15 #include "content/public/test/test_file_system_context.h" | 17 #include "content/public/test/test_file_system_context.h" |
| 16 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 17 #include "net/base/request_priority.h" | 19 #include "net/base/request_priority.h" |
| 18 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 20 #include "net/url_request/url_request_job.h" | 22 #include "net/url_request/url_request_job.h" |
| 21 #include "net/url_request/url_request_job_factory.h" | 23 #include "net/url_request/url_request_job_factory.h" |
| 22 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
| 23 #include "storage/browser/fileapi/file_system_context.h" | 25 #include "storage/browser/fileapi/file_system_context.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 void TearDown() override; | 91 void TearDown() override; |
| 90 | 92 |
| 91 int64 usage() { | 93 int64 usage() { |
| 92 return file_system_context_->GetQuotaUtil(kFileSystemType) | 94 return file_system_context_->GetQuotaUtil(kFileSystemType) |
| 93 ->GetOriginUsageOnFileTaskRunner( | 95 ->GetOriginUsageOnFileTaskRunner( |
| 94 file_system_context_.get(), kOrigin, kFileSystemType); | 96 file_system_context_.get(), kOrigin, kFileSystemType); |
| 95 } | 97 } |
| 96 | 98 |
| 97 int64 GetFileSizeOnDisk(const char* test_file_path) { | 99 int64 GetFileSizeOnDisk(const char* test_file_path) { |
| 98 // There might be in-flight flush/write. | 100 // There might be in-flight flush/write. |
| 99 base::MessageLoop::current()->PostTask( | 101 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 100 FROM_HERE, base::Bind(&base::DoNothing)); | 102 base::Bind(&base::DoNothing)); |
| 101 base::RunLoop().RunUntilIdle(); | 103 base::RunLoop().RunUntilIdle(); |
| 102 | 104 |
| 103 FileSystemURL url = GetFileSystemURL(test_file_path); | 105 FileSystemURL url = GetFileSystemURL(test_file_path); |
| 104 base::File::Info file_info; | 106 base::File::Info file_info; |
| 105 EXPECT_EQ(base::File::FILE_OK, | 107 EXPECT_EQ(base::File::FILE_OK, |
| 106 AsyncFileTestHelper::GetMetadata( | 108 AsyncFileTestHelper::GetMetadata( |
| 107 file_system_context_.get(), url, &file_info)); | 109 file_system_context_.get(), url, &file_info)); |
| 108 return file_info.size; | 110 return file_info.size; |
| 109 } | 111 } |
| 110 | 112 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 FileWriterDelegateTestJob(net::URLRequest* request, | 172 FileWriterDelegateTestJob(net::URLRequest* request, |
| 171 net::NetworkDelegate* network_delegate, | 173 net::NetworkDelegate* network_delegate, |
| 172 const std::string& content) | 174 const std::string& content) |
| 173 : net::URLRequestJob(request, network_delegate), | 175 : net::URLRequestJob(request, network_delegate), |
| 174 content_(content), | 176 content_(content), |
| 175 remaining_bytes_(content.length()), | 177 remaining_bytes_(content.length()), |
| 176 cursor_(0) { | 178 cursor_(0) { |
| 177 } | 179 } |
| 178 | 180 |
| 179 void Start() override { | 181 void Start() override { |
| 180 base::MessageLoop::current()->PostTask( | 182 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 181 FROM_HERE, | 183 FROM_HERE, |
| 182 base::Bind(&FileWriterDelegateTestJob::NotifyHeadersComplete, this)); | 184 base::Bind(&FileWriterDelegateTestJob::NotifyHeadersComplete, this)); |
| 183 } | 185 } |
| 184 | 186 |
| 185 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override { | 187 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override { |
| 186 if (remaining_bytes_ < buf_size) | 188 if (remaining_bytes_ < buf_size) |
| 187 buf_size = static_cast<int>(remaining_bytes_); | 189 buf_size = static_cast<int>(remaining_bytes_); |
| 188 | 190 |
| 189 for (int i = 0; i < buf_size; ++i) | 191 for (int i = 0; i < buf_size; ++i) |
| 190 buf->data()[i] = content_[cursor_++]; | 192 buf->data()[i] = content_[cursor_++]; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 file_writer_delegate_.reset(); | 489 file_writer_delegate_.reset(); |
| 488 | 490 |
| 489 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); | 491 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); |
| 490 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); | 492 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); |
| 491 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); | 493 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); |
| 492 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); | 494 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); |
| 493 } | 495 } |
| 494 } | 496 } |
| 495 | 497 |
| 496 } // namespace content | 498 } // namespace content |
| OLD | NEW |