| 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 <stdint.h> |
| 6 |
| 5 #include <vector> | 7 #include <vector> |
| 6 | 8 |
| 7 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 10 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 11 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 12 #include "content/browser/fileapi/mock_file_change_observer.h" | 15 #include "content/browser/fileapi/mock_file_change_observer.h" |
| 13 #include "content/browser/quota/mock_quota_manager.h" | 16 #include "content/browser/quota/mock_quota_manager.h" |
| 14 #include "content/public/test/mock_blob_url_request_context.h" | 17 #include "content/public/test/mock_blob_url_request_context.h" |
| 15 #include "content/public/test/test_file_system_backend.h" | 18 #include "content/public/test/test_file_system_backend.h" |
| 16 #include "content/public/test/test_file_system_context.h" | 19 #include "content/public/test/test_file_system_context.h" |
| 17 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 90 } |
| 88 | 91 |
| 89 void TearDown() override { | 92 void TearDown() override { |
| 90 quota_manager_ = NULL; | 93 quota_manager_ = NULL; |
| 91 file_system_context_ = NULL; | 94 file_system_context_ = NULL; |
| 92 base::RunLoop().RunUntilIdle(); | 95 base::RunLoop().RunUntilIdle(); |
| 93 } | 96 } |
| 94 | 97 |
| 95 base::File::Error status() const { return status_; } | 98 base::File::Error status() const { return status_; } |
| 96 base::File::Error cancel_status() const { return cancel_status_; } | 99 base::File::Error cancel_status() const { return cancel_status_; } |
| 97 void add_bytes_written(int64 bytes, bool complete) { | 100 void add_bytes_written(int64_t bytes, bool complete) { |
| 98 bytes_written_ += bytes; | 101 bytes_written_ += bytes; |
| 99 EXPECT_FALSE(complete_); | 102 EXPECT_FALSE(complete_); |
| 100 complete_ = complete; | 103 complete_ = complete; |
| 101 } | 104 } |
| 102 int64 bytes_written() const { return bytes_written_; } | 105 int64_t bytes_written() const { return bytes_written_; } |
| 103 bool complete() const { return complete_; } | 106 bool complete() const { return complete_; } |
| 104 | 107 |
| 105 protected: | 108 protected: |
| 106 const storage::ChangeObserverList& change_observers() const { | 109 const storage::ChangeObserverList& change_observers() const { |
| 107 return change_observers_; | 110 return change_observers_; |
| 108 } | 111 } |
| 109 | 112 |
| 110 storage::MockFileChangeObserver* change_observer() { | 113 storage::MockFileChangeObserver* change_observer() { |
| 111 return &change_observer_; | 114 return &change_observer_; |
| 112 } | 115 } |
| 113 | 116 |
| 114 FileSystemURL URLForPath(const base::FilePath& path) const { | 117 FileSystemURL URLForPath(const base::FilePath& path) const { |
| 115 return file_system_context_->CreateCrackedFileSystemURL( | 118 return file_system_context_->CreateCrackedFileSystemURL( |
| 116 kOrigin, kFileSystemType, path); | 119 kOrigin, kFileSystemType, path); |
| 117 } | 120 } |
| 118 | 121 |
| 119 // Callback function for recording test results. | 122 // Callback function for recording test results. |
| 120 FileSystemOperation::WriteCallback RecordWriteCallback() { | 123 FileSystemOperation::WriteCallback RecordWriteCallback() { |
| 121 return base::Bind(&FileSystemOperationImplWriteTest::DidWrite, | 124 return base::Bind(&FileSystemOperationImplWriteTest::DidWrite, |
| 122 weak_factory_.GetWeakPtr()); | 125 weak_factory_.GetWeakPtr()); |
| 123 } | 126 } |
| 124 | 127 |
| 125 FileSystemOperation::StatusCallback RecordCancelCallback() { | 128 FileSystemOperation::StatusCallback RecordCancelCallback() { |
| 126 return base::Bind(&FileSystemOperationImplWriteTest::DidCancel, | 129 return base::Bind(&FileSystemOperationImplWriteTest::DidCancel, |
| 127 weak_factory_.GetWeakPtr()); | 130 weak_factory_.GetWeakPtr()); |
| 128 } | 131 } |
| 129 | 132 |
| 130 void DidWrite(base::File::Error status, int64 bytes, bool complete) { | 133 void DidWrite(base::File::Error status, int64_t bytes, bool complete) { |
| 131 if (status == base::File::FILE_OK) { | 134 if (status == base::File::FILE_OK) { |
| 132 add_bytes_written(bytes, complete); | 135 add_bytes_written(bytes, complete); |
| 133 if (complete) | 136 if (complete) |
| 134 base::MessageLoop::current()->QuitWhenIdle(); | 137 base::MessageLoop::current()->QuitWhenIdle(); |
| 135 } else { | 138 } else { |
| 136 EXPECT_FALSE(complete_); | 139 EXPECT_FALSE(complete_); |
| 137 EXPECT_EQ(status_, base::File::FILE_OK); | 140 EXPECT_EQ(status_, base::File::FILE_OK); |
| 138 complete_ = true; | 141 complete_ = true; |
| 139 status_ = status; | 142 status_ = status; |
| 140 if (base::MessageLoop::current()->is_running()) | 143 if (base::MessageLoop::current()->is_running()) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 154 scoped_refptr<MockQuotaManager> quota_manager_; | 157 scoped_refptr<MockQuotaManager> quota_manager_; |
| 155 | 158 |
| 156 base::MessageLoopForIO loop_; | 159 base::MessageLoopForIO loop_; |
| 157 | 160 |
| 158 base::ScopedTempDir dir_; | 161 base::ScopedTempDir dir_; |
| 159 base::FilePath virtual_path_; | 162 base::FilePath virtual_path_; |
| 160 | 163 |
| 161 // For post-operation status. | 164 // For post-operation status. |
| 162 base::File::Error status_; | 165 base::File::Error status_; |
| 163 base::File::Error cancel_status_; | 166 base::File::Error cancel_status_; |
| 164 int64 bytes_written_; | 167 int64_t bytes_written_; |
| 165 bool complete_; | 168 bool complete_; |
| 166 | 169 |
| 167 scoped_ptr<MockBlobURLRequestContext> url_request_context_; | 170 scoped_ptr<MockBlobURLRequestContext> url_request_context_; |
| 168 | 171 |
| 169 storage::MockFileChangeObserver change_observer_; | 172 storage::MockFileChangeObserver change_observer_; |
| 170 storage::ChangeObserverList change_observers_; | 173 storage::ChangeObserverList change_observers_; |
| 171 | 174 |
| 172 base::WeakPtrFactory<FileSystemOperationImplWriteTest> weak_factory_; | 175 base::WeakPtrFactory<FileSystemOperationImplWriteTest> weak_factory_; |
| 173 | 176 |
| 174 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplWriteTest); | 177 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplWriteTest); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 EXPECT_EQ(base::File::FILE_ERROR_ABORT, status()); | 324 EXPECT_EQ(base::File::FILE_ERROR_ABORT, status()); |
| 322 EXPECT_EQ(base::File::FILE_OK, cancel_status()); | 325 EXPECT_EQ(base::File::FILE_OK, cancel_status()); |
| 323 EXPECT_TRUE(complete()); | 326 EXPECT_TRUE(complete()); |
| 324 | 327 |
| 325 EXPECT_EQ(0, change_observer()->get_and_reset_modify_file_count()); | 328 EXPECT_EQ(0, change_observer()->get_and_reset_modify_file_count()); |
| 326 } | 329 } |
| 327 | 330 |
| 328 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. | 331 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. |
| 329 | 332 |
| 330 } // namespace content | 333 } // namespace content |
| OLD | NEW |