| 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 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" | 13 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" |
| 14 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 14 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
| 15 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" | 15 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
| 16 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" | 16 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" |
| 17 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 17 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
| 18 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" | 18 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" |
| 19 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" | 19 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" |
| 20 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 20 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
| 21 #include "content/public/test/mock_blob_url_request_context.h" | 21 #include "content/public/test/mock_blob_url_request_context.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
| 25 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
| 24 #include "webkit/browser/fileapi/file_system_context.h" | 26 #include "webkit/browser/fileapi/file_system_context.h" |
| 25 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 27 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 26 | 28 |
| 27 using fileapi::FileSystemOperation; | 29 using fileapi::FileSystemOperation; |
| 28 using fileapi::FileSystemURL; | 30 using fileapi::FileSystemURL; |
| 29 using content::MockBlobURLRequestContext; | 31 using content::MockBlobURLRequestContext; |
| 30 using content::ScopedTextBlob; | 32 using content::ScopedTextBlob; |
| 31 using base::File; | 33 using base::File; |
| 32 | 34 |
| 33 namespace sync_file_system { | 35 namespace sync_file_system { |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 const std::string kParent = "foo"; | 38 const std::string kParent = "foo"; |
| 37 const std::string kFile = "foo/file"; | 39 const std::string kFile = "foo/file"; |
| 38 const std::string kDir = "foo/dir"; | 40 const std::string kDir = "foo/dir"; |
| 39 const std::string kChild = "foo/dir/bar"; | 41 const std::string kChild = "foo/dir/bar"; |
| 40 const std::string kOther = "bar"; | 42 const std::string kOther = "bar"; |
| 41 } // namespace | 43 } // namespace |
| 42 | 44 |
| 43 class SyncableFileOperationRunnerTest : public testing::Test { | 45 class SyncableFileOperationRunnerTest : public testing::Test { |
| 44 protected: | 46 protected: |
| 45 typedef FileSystemOperation::StatusCallback StatusCallback; | 47 typedef FileSystemOperation::StatusCallback StatusCallback; |
| 46 | 48 |
| 47 // Use the current thread as IO thread so that we can directly call | 49 // Use the current thread as IO thread so that we can directly call |
| 48 // operations in the tests. | 50 // operations in the tests. |
| 49 SyncableFileOperationRunnerTest() | 51 SyncableFileOperationRunnerTest() |
| 50 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 52 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 53 in_memory_env_(leveldb::NewMemEnv(leveldb::Env::Default())), |
| 51 file_system_(GURL("http://example.com"), | 54 file_system_(GURL("http://example.com"), |
| 55 in_memory_env_.get(), |
| 52 base::MessageLoopProxy::current().get(), | 56 base::MessageLoopProxy::current().get(), |
| 53 base::MessageLoopProxy::current().get()), | 57 base::MessageLoopProxy::current().get()), |
| 54 callback_count_(0), | 58 callback_count_(0), |
| 55 write_status_(File::FILE_ERROR_FAILED), | 59 write_status_(File::FILE_ERROR_FAILED), |
| 56 write_bytes_(0), | 60 write_bytes_(0), |
| 57 write_complete_(false), | 61 write_complete_(false), |
| 58 url_request_context_(file_system_.file_system_context()), | 62 url_request_context_(file_system_.file_system_context()), |
| 59 weak_factory_(this) {} | 63 weak_factory_(this) {} |
| 60 | 64 |
| 61 virtual void SetUp() OVERRIDE { | 65 virtual void SetUp() OVERRIDE { |
| 62 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 66 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
| 67 |
| 63 file_system_.SetUp(); | 68 file_system_.SetUp(); |
| 64 sync_context_ = new LocalFileSyncContext( | 69 sync_context_ = new LocalFileSyncContext( |
| 65 dir_.path(), | 70 dir_.path(), |
| 71 in_memory_env_.get(), |
| 66 base::MessageLoopProxy::current().get(), | 72 base::MessageLoopProxy::current().get(), |
| 67 base::MessageLoopProxy::current().get()); | 73 base::MessageLoopProxy::current().get()); |
| 68 ASSERT_EQ( | 74 ASSERT_EQ( |
| 69 SYNC_STATUS_OK, | 75 SYNC_STATUS_OK, |
| 70 file_system_.MaybeInitializeFileSystemContext(sync_context_.get())); | 76 file_system_.MaybeInitializeFileSystemContext(sync_context_.get())); |
| 71 | 77 |
| 72 ASSERT_EQ(File::FILE_OK, file_system_.OpenFileSystem()); | 78 ASSERT_EQ(File::FILE_OK, file_system_.OpenFileSystem()); |
| 73 ASSERT_EQ(File::FILE_OK, | 79 ASSERT_EQ(File::FILE_OK, |
| 74 file_system_.CreateDirectory(URL(kParent))); | 80 file_system_.CreateDirectory(URL(kParent))); |
| 75 } | 81 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 SCOPED_TRACE(testing::Message() << location.ToString()); | 130 SCOPED_TRACE(testing::Message() << location.ToString()); |
| 125 EXPECT_EQ(expect, status); | 131 EXPECT_EQ(expect, status); |
| 126 ++callback_count_; | 132 ++callback_count_; |
| 127 } | 133 } |
| 128 | 134 |
| 129 bool CreateTempFile(base::FilePath* path) { | 135 bool CreateTempFile(base::FilePath* path) { |
| 130 return base::CreateTemporaryFileInDir(dir_.path(), path); | 136 return base::CreateTemporaryFileInDir(dir_.path(), path); |
| 131 } | 137 } |
| 132 | 138 |
| 133 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; | 139 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; |
| 140 content::TestBrowserThreadBundle thread_bundle_; |
| 141 |
| 134 base::ScopedTempDir dir_; | 142 base::ScopedTempDir dir_; |
| 143 scoped_ptr<leveldb::Env> in_memory_env_; |
| 135 | 144 |
| 136 content::TestBrowserThreadBundle thread_bundle_; | |
| 137 CannedSyncableFileSystem file_system_; | 145 CannedSyncableFileSystem file_system_; |
| 138 scoped_refptr<LocalFileSyncContext> sync_context_; | 146 scoped_refptr<LocalFileSyncContext> sync_context_; |
| 139 | 147 |
| 140 int callback_count_; | 148 int callback_count_; |
| 141 File::Error write_status_; | 149 File::Error write_status_; |
| 142 size_t write_bytes_; | 150 size_t write_bytes_; |
| 143 bool write_complete_; | 151 bool write_complete_; |
| 144 | 152 |
| 145 MockBlobURLRequestContext url_request_context_; | 153 MockBlobURLRequestContext url_request_context_; |
| 146 | 154 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 file_system_.operation_runner()->Truncate( | 400 file_system_.operation_runner()->Truncate( |
| 393 URL(kFile), 10, | 401 URL(kFile), 10, |
| 394 ExpectStatus(FROM_HERE, File::FILE_OK)); | 402 ExpectStatus(FROM_HERE, File::FILE_OK)); |
| 395 file_system_.operation_runner()->Cancel( | 403 file_system_.operation_runner()->Cancel( |
| 396 id, ExpectStatus(FROM_HERE, File::FILE_ERROR_INVALID_OPERATION)); | 404 id, ExpectStatus(FROM_HERE, File::FILE_ERROR_INVALID_OPERATION)); |
| 397 base::MessageLoop::current()->RunUntilIdle(); | 405 base::MessageLoop::current()->RunUntilIdle(); |
| 398 EXPECT_EQ(2, callback_count_); | 406 EXPECT_EQ(2, callback_count_); |
| 399 } | 407 } |
| 400 | 408 |
| 401 } // namespace sync_file_system | 409 } // namespace sync_file_system |
| OLD | NEW |