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