| 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 "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" | 16 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" |
| 17 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" | 17 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
| 18 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 18 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
| 19 #include "chrome/browser/sync_file_system/sync_status_code.h" | 19 #include "chrome/browser/sync_file_system/sync_status_code.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 "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
| 24 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
| 23 #include "webkit/browser/fileapi/file_system_context.h" | 25 #include "webkit/browser/fileapi/file_system_context.h" |
| 24 #include "webkit/browser/quota/quota_manager.h" | 26 #include "webkit/browser/quota/quota_manager.h" |
| 25 | 27 |
| 26 using fileapi::FileSystemContext; | 28 using fileapi::FileSystemContext; |
| 27 using fileapi::FileSystemURL; | 29 using fileapi::FileSystemURL; |
| 28 using fileapi::FileSystemURLSet; | 30 using fileapi::FileSystemURLSet; |
| 29 using content::MockBlobURLRequestContext; | 31 using content::MockBlobURLRequestContext; |
| 30 using content::ScopedTextBlob; | 32 using content::ScopedTextBlob; |
| 31 | 33 |
| 32 namespace sync_file_system { | 34 namespace sync_file_system { |
| 33 | 35 |
| 34 class LocalFileChangeTrackerTest : public testing::Test { | 36 class LocalFileChangeTrackerTest : public testing::Test { |
| 35 public: | 37 public: |
| 36 LocalFileChangeTrackerTest() | 38 LocalFileChangeTrackerTest() |
| 37 : file_system_(GURL("http://example.com"), | 39 : in_memory_env_(leveldb::NewMemEnv(leveldb::Env::Default())), |
| 40 file_system_(GURL("http://example.com"), |
| 41 in_memory_env_.get(), |
| 38 base::MessageLoopProxy::current().get(), | 42 base::MessageLoopProxy::current().get(), |
| 39 base::MessageLoopProxy::current().get()) {} | 43 base::MessageLoopProxy::current().get()) {} |
| 40 | 44 |
| 41 virtual void SetUp() OVERRIDE { | 45 virtual void SetUp() OVERRIDE { |
| 42 file_system_.SetUp(); | 46 file_system_.SetUp(); |
| 43 | 47 |
| 44 sync_context_ = | 48 sync_context_ = |
| 45 new LocalFileSyncContext(base::FilePath(), | 49 new LocalFileSyncContext(base::FilePath(), |
| 50 in_memory_env_.get(), |
| 46 base::MessageLoopProxy::current().get(), | 51 base::MessageLoopProxy::current().get(), |
| 47 base::MessageLoopProxy::current().get()); | 52 base::MessageLoopProxy::current().get()); |
| 48 ASSERT_EQ( | 53 ASSERT_EQ( |
| 49 sync_file_system::SYNC_STATUS_OK, | 54 sync_file_system::SYNC_STATUS_OK, |
| 50 file_system_.MaybeInitializeFileSystemContext(sync_context_.get())); | 55 file_system_.MaybeInitializeFileSystemContext(sync_context_.get())); |
| 51 } | 56 } |
| 52 | 57 |
| 53 virtual void TearDown() OVERRIDE { | 58 virtual void TearDown() OVERRIDE { |
| 54 if (sync_context_.get()) | 59 if (sync_context_.get()) |
| 55 sync_context_->ShutdownOnUIThread(); | 60 sync_context_->ShutdownOnUIThread(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void RestoreChangesFromTrackerDB() { | 104 void RestoreChangesFromTrackerDB() { |
| 100 change_tracker()->CollectLastDirtyChanges(file_system_context()); | 105 change_tracker()->CollectLastDirtyChanges(file_system_context()); |
| 101 } | 106 } |
| 102 | 107 |
| 103 void GetAllChangedURLs(fileapi::FileSystemURLSet* urls) { | 108 void GetAllChangedURLs(fileapi::FileSystemURLSet* urls) { |
| 104 change_tracker()->GetAllChangedURLs(urls); | 109 change_tracker()->GetAllChangedURLs(urls); |
| 105 } | 110 } |
| 106 | 111 |
| 107 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; | 112 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; |
| 108 base::MessageLoopForIO message_loop_; | 113 base::MessageLoopForIO message_loop_; |
| 114 scoped_ptr<leveldb::Env> in_memory_env_; |
| 109 CannedSyncableFileSystem file_system_; | 115 CannedSyncableFileSystem file_system_; |
| 110 | 116 |
| 111 private: | 117 private: |
| 112 scoped_refptr<LocalFileSyncContext> sync_context_; | 118 scoped_refptr<LocalFileSyncContext> sync_context_; |
| 113 | 119 |
| 114 DISALLOW_COPY_AND_ASSIGN(LocalFileChangeTrackerTest); | 120 DISALLOW_COPY_AND_ASSIGN(LocalFileChangeTrackerTest); |
| 115 }; | 121 }; |
| 116 | 122 |
| 117 TEST_F(LocalFileChangeTrackerTest, GetChanges) { | 123 TEST_F(LocalFileChangeTrackerTest, GetChanges) { |
| 118 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem()); | 124 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem()); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 | 677 |
| 672 // Make sure they're gone from the database too. | 678 // Make sure they're gone from the database too. |
| 673 DropChangesInTracker(); | 679 DropChangesInTracker(); |
| 674 RestoreChangesFromTrackerDB(); | 680 RestoreChangesFromTrackerDB(); |
| 675 | 681 |
| 676 GetAllChangedURLs(&urls); | 682 GetAllChangedURLs(&urls); |
| 677 EXPECT_TRUE(urls.empty()); | 683 EXPECT_TRUE(urls.empty()); |
| 678 } | 684 } |
| 679 | 685 |
| 680 } // namespace sync_file_system | 686 } // namespace sync_file_system |
| OLD | NEW |