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/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "content/public/test/test_file_system_context.h" | 14 #include "content/public/test/test_file_system_context.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
17 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
18 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
19 #include "net/url_request/url_request_job.h" | 19 #include "net/url_request/url_request_job.h" |
20 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
21 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 #include "webkit/browser/fileapi/async_file_test_helper.h" | 23 #include "webkit/browser/fileapi/async_file_test_helper.h" |
24 #include "webkit/browser/fileapi/file_system_context.h" | 24 #include "webkit/browser/fileapi/file_system_context.h" |
25 #include "webkit/browser/fileapi/file_system_quota_util.h" | 25 #include "webkit/browser/fileapi/file_system_quota_util.h" |
26 #include "webkit/browser/fileapi/file_writer_delegate.h" | 26 #include "webkit/browser/fileapi/file_writer_delegate.h" |
27 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" | 27 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" |
28 | 28 |
29 namespace fileapi { | 29 using fileapi::AsyncFileTestHelper; |
| 30 using fileapi::FileSystemURL; |
| 31 using fileapi::FileWriterDelegate; |
| 32 |
| 33 namespace content { |
30 | 34 |
31 namespace { | 35 namespace { |
32 | 36 |
33 const GURL kOrigin("http://example.com"); | 37 const GURL kOrigin("http://example.com"); |
34 const FileSystemType kFileSystemType = kFileSystemTypeTest; | 38 const fileapi::FileSystemType kFileSystemType = fileapi::kFileSystemTypeTest; |
35 | 39 |
36 const char kData[] = "The quick brown fox jumps over the lazy dog.\n"; | 40 const char kData[] = "The quick brown fox jumps over the lazy dog.\n"; |
37 const int kDataSize = ARRAYSIZE_UNSAFE(kData) - 1; | 41 const int kDataSize = ARRAYSIZE_UNSAFE(kData) - 1; |
38 | 42 |
39 class Result { | 43 class Result { |
40 public: | 44 public: |
41 Result() | 45 Result() |
42 : status_(base::PLATFORM_FILE_OK), | 46 : status_(base::PLATFORM_FILE_OK), |
43 bytes_written_(0), | 47 bytes_written_(0), |
44 write_status_(FileWriterDelegate::SUCCESS_IO_PENDING) {} | 48 write_status_(FileWriterDelegate::SUCCESS_IO_PENDING) {} |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 106 |
103 FileSystemURL GetFileSystemURL(const char* file_name) const { | 107 FileSystemURL GetFileSystemURL(const char* file_name) const { |
104 return file_system_context_->CreateCrackedFileSystemURL( | 108 return file_system_context_->CreateCrackedFileSystemURL( |
105 kOrigin, kFileSystemType, base::FilePath().FromUTF8Unsafe(file_name)); | 109 kOrigin, kFileSystemType, base::FilePath().FromUTF8Unsafe(file_name)); |
106 } | 110 } |
107 | 111 |
108 FileWriterDelegate* CreateWriterDelegate( | 112 FileWriterDelegate* CreateWriterDelegate( |
109 const char* test_file_path, | 113 const char* test_file_path, |
110 int64 offset, | 114 int64 offset, |
111 int64 allowed_growth) { | 115 int64 allowed_growth) { |
112 SandboxFileStreamWriter* writer = new SandboxFileStreamWriter( | 116 fileapi::SandboxFileStreamWriter* writer = |
113 file_system_context_.get(), | 117 new fileapi::SandboxFileStreamWriter( |
114 GetFileSystemURL(test_file_path), | 118 file_system_context_.get(), |
115 offset, | 119 GetFileSystemURL(test_file_path), |
116 *file_system_context_->GetUpdateObservers(kFileSystemType)); | 120 offset, |
| 121 *file_system_context_->GetUpdateObservers(kFileSystemType)); |
117 writer->set_default_quota(allowed_growth); | 122 writer->set_default_quota(allowed_growth); |
118 return new FileWriterDelegate(scoped_ptr<FileStreamWriter>(writer)); | 123 return new FileWriterDelegate( |
| 124 scoped_ptr<fileapi::FileStreamWriter>(writer)); |
119 } | 125 } |
120 | 126 |
121 FileWriterDelegate::DelegateWriteCallback GetWriteCallback(Result* result) { | 127 FileWriterDelegate::DelegateWriteCallback GetWriteCallback(Result* result) { |
122 return base::Bind(&Result::DidWrite, base::Unretained(result)); | 128 return base::Bind(&Result::DidWrite, base::Unretained(result)); |
123 } | 129 } |
124 | 130 |
125 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, | 131 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, |
126 // and creates a new FileWriterDelegate for the file. | 132 // and creates a new FileWriterDelegate for the file. |
127 void PrepareForWrite(const char* test_file_path, | 133 void PrepareForWrite(const char* test_file_path, |
128 const GURL& blob_url, | 134 const GURL& blob_url, |
129 int64 offset, | 135 int64 offset, |
130 int64 allowed_growth) { | 136 int64 allowed_growth) { |
131 file_writer_delegate_.reset( | 137 file_writer_delegate_.reset( |
132 CreateWriterDelegate(test_file_path, offset, allowed_growth)); | 138 CreateWriterDelegate(test_file_path, offset, allowed_growth)); |
133 request_ = empty_context_.CreateRequest( | 139 request_ = empty_context_.CreateRequest( |
134 blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get()); | 140 blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get()); |
135 } | 141 } |
136 | 142 |
137 static net::URLRequest::ProtocolFactory Factory; | 143 static net::URLRequest::ProtocolFactory Factory; |
138 | 144 |
139 // This should be alive until the very end of this instance. | 145 // This should be alive until the very end of this instance. |
140 base::MessageLoopForIO loop_; | 146 base::MessageLoopForIO loop_; |
141 | 147 |
142 scoped_refptr<FileSystemContext> file_system_context_; | 148 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
143 | 149 |
144 net::URLRequestContext empty_context_; | 150 net::URLRequestContext empty_context_; |
145 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 151 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
146 scoped_ptr<net::URLRequest> request_; | 152 scoped_ptr<net::URLRequest> request_; |
147 | 153 |
148 base::ScopedTempDir dir_; | 154 base::ScopedTempDir dir_; |
149 | 155 |
150 static const char* content_; | 156 static const char* content_; |
151 }; | 157 }; |
152 | 158 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 ASSERT_EQ(FileWriterDelegate::ERROR_WRITE_STARTED, result.write_status()); | 451 ASSERT_EQ(FileWriterDelegate::ERROR_WRITE_STARTED, result.write_status()); |
446 file_writer_delegate_.reset(); | 452 file_writer_delegate_.reset(); |
447 | 453 |
448 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); | 454 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); |
449 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); | 455 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); |
450 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); | 456 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); |
451 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result.status()); | 457 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result.status()); |
452 } | 458 } |
453 } | 459 } |
454 | 460 |
455 } // namespace fileapi | 461 } // namespace content |
OLD | NEW |