| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "webkit/browser/fileapi/file_system_context.h" | 23 #include "webkit/browser/fileapi/file_system_context.h" |
| 24 #include "webkit/browser/fileapi/file_system_file_util.h" | 24 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 25 #include "webkit/browser/fileapi/file_system_operation_context.h" | 25 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 26 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 26 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 27 #include "webkit/browser/fileapi/local_file_util.h" | 27 #include "webkit/browser/fileapi/local_file_util.h" |
| 28 #include "webkit/browser/fileapi/mock_file_change_observer.h" | 28 #include "webkit/browser/fileapi/mock_file_change_observer.h" |
| 29 #include "webkit/browser/quota/mock_quota_manager.h" | 29 #include "webkit/browser/quota/mock_quota_manager.h" |
| 30 #include "webkit/common/blob/blob_data.h" | 30 #include "webkit/common/blob/blob_data.h" |
| 31 #include "webkit/common/fileapi/file_system_util.h" | 31 #include "webkit/common/fileapi/file_system_util.h" |
| 32 | 32 |
| 33 using fileapi::FileSystemOperation; |
| 34 using fileapi::FileSystemOperationRunner; |
| 35 using fileapi::FileSystemURL; |
| 33 using webkit_blob::MockBlobURLRequestContext; | 36 using webkit_blob::MockBlobURLRequestContext; |
| 34 using webkit_blob::ScopedTextBlob; | 37 using webkit_blob::ScopedTextBlob; |
| 35 | 38 |
| 36 namespace fileapi { | 39 namespace content { |
| 37 | 40 |
| 38 namespace { | 41 namespace { |
| 39 | 42 |
| 40 const GURL kOrigin("http://example.com"); | 43 const GURL kOrigin("http://example.com"); |
| 41 const FileSystemType kFileSystemType = kFileSystemTypeTest; | 44 const fileapi::FileSystemType kFileSystemType = fileapi::kFileSystemTypeTest; |
| 42 | 45 |
| 43 void AssertStatusEq(base::PlatformFileError expected, | 46 void AssertStatusEq(base::PlatformFileError expected, |
| 44 base::PlatformFileError actual) { | 47 base::PlatformFileError actual) { |
| 45 ASSERT_EQ(expected, actual); | 48 ASSERT_EQ(expected, actual); |
| 46 } | 49 } |
| 47 | 50 |
| 48 } // namespace | 51 } // namespace |
| 49 | 52 |
| 50 class FileSystemOperationImplWriteTest | 53 class FileSystemOperationImplWriteTest |
| 51 : public testing::Test { | 54 : public testing::Test { |
| 52 public: | 55 public: |
| 53 FileSystemOperationImplWriteTest() | 56 FileSystemOperationImplWriteTest() |
| 54 : status_(base::PLATFORM_FILE_OK), | 57 : status_(base::PLATFORM_FILE_OK), |
| 55 cancel_status_(base::PLATFORM_FILE_ERROR_FAILED), | 58 cancel_status_(base::PLATFORM_FILE_ERROR_FAILED), |
| 56 bytes_written_(0), | 59 bytes_written_(0), |
| 57 complete_(false), | 60 complete_(false), |
| 58 weak_factory_(this) { | 61 weak_factory_(this) { |
| 59 change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); | 62 change_observers_ = fileapi::MockFileChangeObserver::CreateList( |
| 63 &change_observer_); |
| 60 } | 64 } |
| 61 | 65 |
| 62 virtual void SetUp() { | 66 virtual void SetUp() { |
| 63 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 67 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
| 64 | 68 |
| 65 quota_manager_ = | 69 quota_manager_ = |
| 66 new quota::MockQuotaManager(false /* is_incognito */, | 70 new quota::MockQuotaManager(false /* is_incognito */, |
| 67 dir_.path(), | 71 dir_.path(), |
| 68 base::MessageLoopProxy::current().get(), | 72 base::MessageLoopProxy::current().get(), |
| 69 base::MessageLoopProxy::current().get(), | 73 base::MessageLoopProxy::current().get(), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 94 base::PlatformFileError cancel_status() const { return cancel_status_; } | 98 base::PlatformFileError cancel_status() const { return cancel_status_; } |
| 95 void add_bytes_written(int64 bytes, bool complete) { | 99 void add_bytes_written(int64 bytes, bool complete) { |
| 96 bytes_written_ += bytes; | 100 bytes_written_ += bytes; |
| 97 EXPECT_FALSE(complete_); | 101 EXPECT_FALSE(complete_); |
| 98 complete_ = complete; | 102 complete_ = complete; |
| 99 } | 103 } |
| 100 int64 bytes_written() const { return bytes_written_; } | 104 int64 bytes_written() const { return bytes_written_; } |
| 101 bool complete() const { return complete_; } | 105 bool complete() const { return complete_; } |
| 102 | 106 |
| 103 protected: | 107 protected: |
| 104 const ChangeObserverList& change_observers() const { | 108 const fileapi::ChangeObserverList& change_observers() const { |
| 105 return change_observers_; | 109 return change_observers_; |
| 106 } | 110 } |
| 107 | 111 |
| 108 MockFileChangeObserver* change_observer() { | 112 fileapi::MockFileChangeObserver* change_observer() { |
| 109 return &change_observer_; | 113 return &change_observer_; |
| 110 } | 114 } |
| 111 | 115 |
| 112 FileSystemURL URLForPath(const base::FilePath& path) const { | 116 FileSystemURL URLForPath(const base::FilePath& path) const { |
| 113 return file_system_context_->CreateCrackedFileSystemURL( | 117 return file_system_context_->CreateCrackedFileSystemURL( |
| 114 kOrigin, kFileSystemType, path); | 118 kOrigin, kFileSystemType, path); |
| 115 } | 119 } |
| 116 | 120 |
| 117 // Callback function for recording test results. | 121 // Callback function for recording test results. |
| 118 FileSystemOperation::WriteCallback RecordWriteCallback() { | 122 FileSystemOperation::WriteCallback RecordWriteCallback() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 141 } | 145 } |
| 142 | 146 |
| 143 void DidCancel(base::PlatformFileError status) { | 147 void DidCancel(base::PlatformFileError status) { |
| 144 cancel_status_ = status; | 148 cancel_status_ = status; |
| 145 } | 149 } |
| 146 | 150 |
| 147 const MockBlobURLRequestContext& url_request_context() const { | 151 const MockBlobURLRequestContext& url_request_context() const { |
| 148 return *url_request_context_; | 152 return *url_request_context_; |
| 149 } | 153 } |
| 150 | 154 |
| 151 scoped_refptr<FileSystemContext> file_system_context_; | 155 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 152 scoped_refptr<quota::MockQuotaManager> quota_manager_; | 156 scoped_refptr<quota::MockQuotaManager> quota_manager_; |
| 153 | 157 |
| 154 base::MessageLoopForIO loop_; | 158 base::MessageLoopForIO loop_; |
| 155 | 159 |
| 156 base::ScopedTempDir dir_; | 160 base::ScopedTempDir dir_; |
| 157 base::FilePath virtual_path_; | 161 base::FilePath virtual_path_; |
| 158 | 162 |
| 159 // For post-operation status. | 163 // For post-operation status. |
| 160 base::PlatformFileError status_; | 164 base::PlatformFileError status_; |
| 161 base::PlatformFileError cancel_status_; | 165 base::PlatformFileError cancel_status_; |
| 162 int64 bytes_written_; | 166 int64 bytes_written_; |
| 163 bool complete_; | 167 bool complete_; |
| 164 | 168 |
| 165 scoped_ptr<MockBlobURLRequestContext> url_request_context_; | 169 scoped_ptr<MockBlobURLRequestContext> url_request_context_; |
| 166 | 170 |
| 167 MockFileChangeObserver change_observer_; | 171 fileapi::MockFileChangeObserver change_observer_; |
| 168 ChangeObserverList change_observers_; | 172 fileapi::ChangeObserverList change_observers_; |
| 169 | 173 |
| 170 base::WeakPtrFactory<FileSystemOperationImplWriteTest> weak_factory_; | 174 base::WeakPtrFactory<FileSystemOperationImplWriteTest> weak_factory_; |
| 171 | 175 |
| 172 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplWriteTest); | 176 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplWriteTest); |
| 173 }; | 177 }; |
| 174 | 178 |
| 175 TEST_F(FileSystemOperationImplWriteTest, TestWriteSuccess) { | 179 TEST_F(FileSystemOperationImplWriteTest, TestWriteSuccess) { |
| 176 ScopedTextBlob blob(url_request_context(), | 180 ScopedTextBlob blob(url_request_context(), |
| 177 "blob-id:success", | 181 "blob-id:success", |
| 178 "Hello, world!\n"); | 182 "Hello, world!\n"); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 EXPECT_EQ(0, bytes_written()); | 322 EXPECT_EQ(0, bytes_written()); |
| 319 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); | 323 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); |
| 320 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); | 324 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); |
| 321 EXPECT_TRUE(complete()); | 325 EXPECT_TRUE(complete()); |
| 322 | 326 |
| 323 EXPECT_EQ(0, change_observer()->get_and_reset_modify_file_count()); | 327 EXPECT_EQ(0, change_observer()->get_and_reset_modify_file_count()); |
| 324 } | 328 } |
| 325 | 329 |
| 326 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. | 330 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. |
| 327 | 331 |
| 328 } // namespace fileapi | 332 } // namespace content |
| OLD | NEW |