| 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 10 matching lines...) Expand all Loading... |
| 21 #include "net/url_request/url_request_job_factory.h" | 21 #include "net/url_request/url_request_job_factory.h" |
| 22 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
| 23 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
| 24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 #include "webkit/browser/fileapi/file_system_context.h" | 25 #include "webkit/browser/fileapi/file_system_context.h" |
| 26 #include "webkit/browser/fileapi/file_system_quota_util.h" | 26 #include "webkit/browser/fileapi/file_system_quota_util.h" |
| 27 #include "webkit/browser/fileapi/file_writer_delegate.h" | 27 #include "webkit/browser/fileapi/file_writer_delegate.h" |
| 28 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" | 28 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" |
| 29 | 29 |
| 30 using content::AsyncFileTestHelper; | 30 using content::AsyncFileTestHelper; |
| 31 using fileapi::FileSystemURL; | 31 using storage::FileSystemURL; |
| 32 using fileapi::FileWriterDelegate; | 32 using storage::FileWriterDelegate; |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const GURL kOrigin("http://example.com"); | 38 const GURL kOrigin("http://example.com"); |
| 39 const fileapi::FileSystemType kFileSystemType = fileapi::kFileSystemTypeTest; | 39 const storage::FileSystemType kFileSystemType = storage::kFileSystemTypeTest; |
| 40 | 40 |
| 41 const char kData[] = "The quick brown fox jumps over the lazy dog.\n"; | 41 const char kData[] = "The quick brown fox jumps over the lazy dog.\n"; |
| 42 const int kDataSize = ARRAYSIZE_UNSAFE(kData) - 1; | 42 const int kDataSize = ARRAYSIZE_UNSAFE(kData) - 1; |
| 43 | 43 |
| 44 class Result { | 44 class Result { |
| 45 public: | 45 public: |
| 46 Result() | 46 Result() |
| 47 : status_(base::File::FILE_OK), | 47 : status_(base::File::FILE_OK), |
| 48 bytes_written_(0), | 48 bytes_written_(0), |
| 49 write_status_(FileWriterDelegate::SUCCESS_IO_PENDING) {} | 49 write_status_(FileWriterDelegate::SUCCESS_IO_PENDING) {} |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 FileSystemURL GetFileSystemURL(const char* file_name) const { | 110 FileSystemURL GetFileSystemURL(const char* file_name) const { |
| 111 return file_system_context_->CreateCrackedFileSystemURL( | 111 return file_system_context_->CreateCrackedFileSystemURL( |
| 112 kOrigin, kFileSystemType, base::FilePath().FromUTF8Unsafe(file_name)); | 112 kOrigin, kFileSystemType, base::FilePath().FromUTF8Unsafe(file_name)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 FileWriterDelegate* CreateWriterDelegate( | 115 FileWriterDelegate* CreateWriterDelegate( |
| 116 const char* test_file_path, | 116 const char* test_file_path, |
| 117 int64 offset, | 117 int64 offset, |
| 118 int64 allowed_growth) { | 118 int64 allowed_growth) { |
| 119 fileapi::SandboxFileStreamWriter* writer = | 119 storage::SandboxFileStreamWriter* writer = |
| 120 new fileapi::SandboxFileStreamWriter( | 120 new storage::SandboxFileStreamWriter( |
| 121 file_system_context_.get(), | 121 file_system_context_.get(), |
| 122 GetFileSystemURL(test_file_path), | 122 GetFileSystemURL(test_file_path), |
| 123 offset, | 123 offset, |
| 124 *file_system_context_->GetUpdateObservers(kFileSystemType)); | 124 *file_system_context_->GetUpdateObservers(kFileSystemType)); |
| 125 writer->set_default_quota(allowed_growth); | 125 writer->set_default_quota(allowed_growth); |
| 126 return new FileWriterDelegate( | 126 return new FileWriterDelegate(scoped_ptr<storage::FileStreamWriter>(writer), |
| 127 scoped_ptr<fileapi::FileStreamWriter>(writer), | 127 FileWriterDelegate::FLUSH_ON_COMPLETION); |
| 128 FileWriterDelegate::FLUSH_ON_COMPLETION); | |
| 129 } | 128 } |
| 130 | 129 |
| 131 FileWriterDelegate::DelegateWriteCallback GetWriteCallback(Result* result) { | 130 FileWriterDelegate::DelegateWriteCallback GetWriteCallback(Result* result) { |
| 132 return base::Bind(&Result::DidWrite, base::Unretained(result)); | 131 return base::Bind(&Result::DidWrite, base::Unretained(result)); |
| 133 } | 132 } |
| 134 | 133 |
| 135 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, | 134 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, |
| 136 // and creates a new FileWriterDelegate for the file. | 135 // and creates a new FileWriterDelegate for the file. |
| 137 void PrepareForWrite(const char* test_file_path, | 136 void PrepareForWrite(const char* test_file_path, |
| 138 const GURL& blob_url, | 137 const GURL& blob_url, |
| 139 int64 offset, | 138 int64 offset, |
| 140 int64 allowed_growth) { | 139 int64 allowed_growth) { |
| 141 file_writer_delegate_.reset( | 140 file_writer_delegate_.reset( |
| 142 CreateWriterDelegate(test_file_path, offset, allowed_growth)); | 141 CreateWriterDelegate(test_file_path, offset, allowed_growth)); |
| 143 request_ = empty_context_.CreateRequest( | 142 request_ = empty_context_.CreateRequest( |
| 144 blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get(), NULL); | 143 blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get(), NULL); |
| 145 } | 144 } |
| 146 | 145 |
| 147 // This should be alive until the very end of this instance. | 146 // This should be alive until the very end of this instance. |
| 148 base::MessageLoopForIO loop_; | 147 base::MessageLoopForIO loop_; |
| 149 | 148 |
| 150 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 149 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 151 | 150 |
| 152 net::URLRequestContext empty_context_; | 151 net::URLRequestContext empty_context_; |
| 153 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 152 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 154 scoped_ptr<net::URLRequest> request_; | 153 scoped_ptr<net::URLRequest> request_; |
| 155 scoped_ptr<BlobURLRequestJobFactory> job_factory_; | 154 scoped_ptr<BlobURLRequestJobFactory> job_factory_; |
| 156 | 155 |
| 157 base::ScopedTempDir dir_; | 156 base::ScopedTempDir dir_; |
| 158 | 157 |
| 159 static const char* content_; | 158 static const char* content_; |
| 160 }; | 159 }; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 file_writer_delegate_.reset(); | 477 file_writer_delegate_.reset(); |
| 479 | 478 |
| 480 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); | 479 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); |
| 481 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); | 480 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); |
| 482 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); | 481 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); |
| 483 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); | 482 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); |
| 484 } | 483 } |
| 485 } | 484 } |
| 486 | 485 |
| 487 } // namespace content | 486 } // namespace content |
| OLD | NEW |