| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "content/browser/fileapi/mock_file_change_observer.h" | 12 #include "content/browser/fileapi/mock_file_change_observer.h" |
| 13 #include "content/browser/quota/mock_quota_manager.h" | 13 #include "content/browser/quota/mock_quota_manager.h" |
| 14 #include "content/public/test/mock_blob_url_request_context.h" | 14 #include "content/public/test/mock_blob_url_request_context.h" |
| 15 #include "content/public/test/test_file_system_backend.h" | 15 #include "content/public/test/test_file_system_backend.h" |
| 16 #include "content/public/test/test_file_system_context.h" | 16 #include "content/public/test/test_file_system_context.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_job_factory_impl.h" | 20 #include "net/url_request/url_request_job_factory_impl.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 #include "webkit/browser/blob/blob_storage_context.h" | 23 #include "storage/browser/blob/blob_storage_context.h" |
| 24 #include "webkit/browser/blob/blob_url_request_job.h" | 24 #include "storage/browser/blob/blob_url_request_job.h" |
| 25 #include "webkit/browser/fileapi/file_system_context.h" | 25 #include "storage/browser/fileapi/file_system_context.h" |
| 26 #include "webkit/browser/fileapi/file_system_file_util.h" | 26 #include "storage/browser/fileapi/file_system_file_util.h" |
| 27 #include "webkit/browser/fileapi/file_system_operation_context.h" | 27 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 28 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 28 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 29 #include "webkit/browser/fileapi/local_file_util.h" | 29 #include "storage/browser/fileapi/local_file_util.h" |
| 30 #include "webkit/common/blob/blob_data.h" | 30 #include "storage/common/blob/blob_data.h" |
| 31 #include "webkit/common/fileapi/file_system_util.h" | 31 #include "storage/common/fileapi/file_system_util.h" |
| 32 | 32 |
| 33 using fileapi::FileSystemOperation; | 33 using storage::FileSystemOperation; |
| 34 using fileapi::FileSystemOperationRunner; | 34 using storage::FileSystemOperationRunner; |
| 35 using fileapi::FileSystemURL; | 35 using storage::FileSystemURL; |
| 36 using content::MockBlobURLRequestContext; | 36 using content::MockBlobURLRequestContext; |
| 37 using content::ScopedTextBlob; | 37 using content::ScopedTextBlob; |
| 38 | 38 |
| 39 namespace content { | 39 namespace content { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 const GURL kOrigin("http://example.com"); | 43 const GURL kOrigin("http://example.com"); |
| 44 const fileapi::FileSystemType kFileSystemType = fileapi::kFileSystemTypeTest; | 44 const storage::FileSystemType kFileSystemType = storage::kFileSystemTypeTest; |
| 45 | 45 |
| 46 void AssertStatusEq(base::File::Error expected, | 46 void AssertStatusEq(base::File::Error expected, |
| 47 base::File::Error actual) { | 47 base::File::Error actual) { |
| 48 ASSERT_EQ(expected, actual); | 48 ASSERT_EQ(expected, actual); |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 class FileSystemOperationImplWriteTest | 53 class FileSystemOperationImplWriteTest |
| 54 : public testing::Test { | 54 : public testing::Test { |
| 55 public: | 55 public: |
| 56 FileSystemOperationImplWriteTest() | 56 FileSystemOperationImplWriteTest() |
| 57 : status_(base::File::FILE_OK), | 57 : status_(base::File::FILE_OK), |
| 58 cancel_status_(base::File::FILE_ERROR_FAILED), | 58 cancel_status_(base::File::FILE_ERROR_FAILED), |
| 59 bytes_written_(0), | 59 bytes_written_(0), |
| 60 complete_(false), | 60 complete_(false), |
| 61 weak_factory_(this) { | 61 weak_factory_(this) { |
| 62 change_observers_ = fileapi::MockFileChangeObserver::CreateList( | 62 change_observers_ = |
| 63 &change_observer_); | 63 storage::MockFileChangeObserver::CreateList(&change_observer_); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual void SetUp() { | 66 virtual void SetUp() { |
| 67 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 67 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
| 68 | 68 |
| 69 quota_manager_ = | 69 quota_manager_ = |
| 70 new MockQuotaManager(false /* is_incognito */, | 70 new MockQuotaManager(false /* is_incognito */, |
| 71 dir_.path(), | 71 dir_.path(), |
| 72 base::MessageLoopProxy::current().get(), | 72 base::MessageLoopProxy::current().get(), |
| 73 base::MessageLoopProxy::current().get(), | 73 base::MessageLoopProxy::current().get(), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 98 base::File::Error cancel_status() const { return cancel_status_; } | 98 base::File::Error cancel_status() const { return cancel_status_; } |
| 99 void add_bytes_written(int64 bytes, bool complete) { | 99 void add_bytes_written(int64 bytes, bool complete) { |
| 100 bytes_written_ += bytes; | 100 bytes_written_ += bytes; |
| 101 EXPECT_FALSE(complete_); | 101 EXPECT_FALSE(complete_); |
| 102 complete_ = complete; | 102 complete_ = complete; |
| 103 } | 103 } |
| 104 int64 bytes_written() const { return bytes_written_; } | 104 int64 bytes_written() const { return bytes_written_; } |
| 105 bool complete() const { return complete_; } | 105 bool complete() const { return complete_; } |
| 106 | 106 |
| 107 protected: | 107 protected: |
| 108 const fileapi::ChangeObserverList& change_observers() const { | 108 const storage::ChangeObserverList& change_observers() const { |
| 109 return change_observers_; | 109 return change_observers_; |
| 110 } | 110 } |
| 111 | 111 |
| 112 fileapi::MockFileChangeObserver* change_observer() { | 112 storage::MockFileChangeObserver* change_observer() { |
| 113 return &change_observer_; | 113 return &change_observer_; |
| 114 } | 114 } |
| 115 | 115 |
| 116 FileSystemURL URLForPath(const base::FilePath& path) const { | 116 FileSystemURL URLForPath(const base::FilePath& path) const { |
| 117 return file_system_context_->CreateCrackedFileSystemURL( | 117 return file_system_context_->CreateCrackedFileSystemURL( |
| 118 kOrigin, kFileSystemType, path); | 118 kOrigin, kFileSystemType, path); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Callback function for recording test results. | 121 // Callback function for recording test results. |
| 122 FileSystemOperation::WriteCallback RecordWriteCallback() { | 122 FileSystemOperation::WriteCallback RecordWriteCallback() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 145 } | 145 } |
| 146 | 146 |
| 147 void DidCancel(base::File::Error status) { | 147 void DidCancel(base::File::Error status) { |
| 148 cancel_status_ = status; | 148 cancel_status_ = status; |
| 149 } | 149 } |
| 150 | 150 |
| 151 const MockBlobURLRequestContext& url_request_context() const { | 151 const MockBlobURLRequestContext& url_request_context() const { |
| 152 return *url_request_context_; | 152 return *url_request_context_; |
| 153 } | 153 } |
| 154 | 154 |
| 155 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 155 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 156 scoped_refptr<MockQuotaManager> quota_manager_; | 156 scoped_refptr<MockQuotaManager> quota_manager_; |
| 157 | 157 |
| 158 base::MessageLoopForIO loop_; | 158 base::MessageLoopForIO loop_; |
| 159 | 159 |
| 160 base::ScopedTempDir dir_; | 160 base::ScopedTempDir dir_; |
| 161 base::FilePath virtual_path_; | 161 base::FilePath virtual_path_; |
| 162 | 162 |
| 163 // For post-operation status. | 163 // For post-operation status. |
| 164 base::File::Error status_; | 164 base::File::Error status_; |
| 165 base::File::Error cancel_status_; | 165 base::File::Error cancel_status_; |
| 166 int64 bytes_written_; | 166 int64 bytes_written_; |
| 167 bool complete_; | 167 bool complete_; |
| 168 | 168 |
| 169 scoped_ptr<MockBlobURLRequestContext> url_request_context_; | 169 scoped_ptr<MockBlobURLRequestContext> url_request_context_; |
| 170 | 170 |
| 171 fileapi::MockFileChangeObserver change_observer_; | 171 storage::MockFileChangeObserver change_observer_; |
| 172 fileapi::ChangeObserverList change_observers_; | 172 storage::ChangeObserverList change_observers_; |
| 173 | 173 |
| 174 base::WeakPtrFactory<FileSystemOperationImplWriteTest> weak_factory_; | 174 base::WeakPtrFactory<FileSystemOperationImplWriteTest> weak_factory_; |
| 175 | 175 |
| 176 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplWriteTest); | 176 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplWriteTest); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 TEST_F(FileSystemOperationImplWriteTest, TestWriteSuccess) { | 179 TEST_F(FileSystemOperationImplWriteTest, TestWriteSuccess) { |
| 180 ScopedTextBlob blob(url_request_context(), | 180 ScopedTextBlob blob(url_request_context(), |
| 181 "blob-id:success", | 181 "blob-id:success", |
| 182 "Hello, world!\n"); | 182 "Hello, world!\n"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 202 | 202 |
| 203 EXPECT_EQ(0, bytes_written()); | 203 EXPECT_EQ(0, bytes_written()); |
| 204 EXPECT_EQ(base::File::FILE_OK, status()); | 204 EXPECT_EQ(base::File::FILE_OK, status()); |
| 205 EXPECT_TRUE(complete()); | 205 EXPECT_TRUE(complete()); |
| 206 | 206 |
| 207 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 207 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 | 210 |
| 211 TEST_F(FileSystemOperationImplWriteTest, TestWriteInvalidBlobUrl) { | 211 TEST_F(FileSystemOperationImplWriteTest, TestWriteInvalidBlobUrl) { |
| 212 scoped_ptr<webkit_blob::BlobDataHandle> null_handle; | 212 scoped_ptr<storage::BlobDataHandle> null_handle; |
| 213 file_system_context_->operation_runner()->Write( | 213 file_system_context_->operation_runner()->Write( |
| 214 &url_request_context(), URLForPath(virtual_path_), | 214 &url_request_context(), URLForPath(virtual_path_), |
| 215 null_handle.Pass(), 0, RecordWriteCallback()); | 215 null_handle.Pass(), 0, RecordWriteCallback()); |
| 216 base::MessageLoop::current()->Run(); | 216 base::MessageLoop::current()->Run(); |
| 217 | 217 |
| 218 EXPECT_EQ(0, bytes_written()); | 218 EXPECT_EQ(0, bytes_written()); |
| 219 EXPECT_EQ(base::File::FILE_ERROR_FAILED, status()); | 219 EXPECT_EQ(base::File::FILE_ERROR_FAILED, status()); |
| 220 EXPECT_TRUE(complete()); | 220 EXPECT_TRUE(complete()); |
| 221 | 221 |
| 222 EXPECT_EQ(0, change_observer()->get_and_reset_modify_file_count()); | 222 EXPECT_EQ(0, change_observer()->get_and_reset_modify_file_count()); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 EXPECT_EQ(base::File::FILE_ERROR_ABORT, status()); | 323 EXPECT_EQ(base::File::FILE_ERROR_ABORT, status()); |
| 324 EXPECT_EQ(base::File::FILE_OK, cancel_status()); | 324 EXPECT_EQ(base::File::FILE_OK, cancel_status()); |
| 325 EXPECT_TRUE(complete()); | 325 EXPECT_TRUE(complete()); |
| 326 | 326 |
| 327 EXPECT_EQ(0, change_observer()->get_and_reset_modify_file_count()); | 327 EXPECT_EQ(0, change_observer()->get_and_reset_modify_file_count()); |
| 328 } | 328 } |
| 329 | 329 |
| 330 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. | 330 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. |
| 331 | 331 |
| 332 } // namespace content | 332 } // namespace content |
| OLD | NEW |