| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/gdata/gdata_sync_client.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 mock_network_library_ = new chromeos::MockNetworkLibrary; | 72 mock_network_library_ = new chromeos::MockNetworkLibrary; |
| 73 chromeos::CrosLibrary::Get()->GetTestApi()->SetNetworkLibrary( | 73 chromeos::CrosLibrary::Get()->GetTestApi()->SetNetworkLibrary( |
| 74 mock_network_library_, true); | 74 mock_network_library_, true); |
| 75 | 75 |
| 76 // Create a temporary directory. | 76 // Create a temporary directory. |
| 77 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 77 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 78 | 78 |
| 79 // Initialize the sync client. | 79 // Initialize the sync client. |
| 80 scoped_refptr<base::SequencedWorkerPool> pool = | 80 scoped_refptr<base::SequencedWorkerPool> pool = |
| 81 content::BrowserThread::GetBlockingPool(); | 81 content::BrowserThread::GetBlockingPool(); |
| 82 cache_ = GDataCache::CreateGDataCacheOnUIThread( | 82 cache_ = DriveCache::CreateDriveCacheOnUIThread( |
| 83 temp_dir_.path(), | 83 temp_dir_.path(), |
| 84 pool->GetSequencedTaskRunner(pool->GetSequenceToken())); | 84 pool->GetSequencedTaskRunner(pool->GetSequenceToken())); |
| 85 sync_client_.reset(new GDataSyncClient(profile_.get(), | 85 sync_client_.reset(new GDataSyncClient(profile_.get(), |
| 86 mock_file_system_.get(), | 86 mock_file_system_.get(), |
| 87 cache_)); | 87 cache_)); |
| 88 | 88 |
| 89 EXPECT_CALL(*mock_network_library_, AddNetworkManagerObserver( | 89 EXPECT_CALL(*mock_network_library_, AddNetworkManagerObserver( |
| 90 sync_client_.get())).Times(1); | 90 sync_client_.get())).Times(1); |
| 91 EXPECT_CALL(*mock_network_library_, RemoveNetworkManagerObserver( | 91 EXPECT_CALL(*mock_network_library_, RemoveNetworkManagerObserver( |
| 92 sync_client_.get())).Times(1); | 92 sync_client_.get())).Times(1); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 .Times(AnyNumber()) | 152 .Times(AnyNumber()) |
| 153 .WillRepeatedly((Return(active_network_.get()))); | 153 .WillRepeatedly((Return(active_network_.get()))); |
| 154 chromeos::Network::TestApi(active_network_.get()).SetDisconnected(); | 154 chromeos::Network::TestApi(active_network_.get()).SetDisconnected(); |
| 155 sync_client_->OnNetworkManagerChanged(mock_network_library_); | 155 sync_client_->OnNetworkManagerChanged(mock_network_library_); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Sets up test files in the temporary directory. | 158 // Sets up test files in the temporary directory. |
| 159 void SetUpTestFiles() { | 159 void SetUpTestFiles() { |
| 160 // Create a directory in the temporary directory for pinned symlinks. | 160 // Create a directory in the temporary directory for pinned symlinks. |
| 161 const FilePath pinned_dir = | 161 const FilePath pinned_dir = |
| 162 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_PINNED); | 162 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_PINNED); |
| 163 ASSERT_TRUE(file_util::CreateDirectory(pinned_dir)); | 163 ASSERT_TRUE(file_util::CreateDirectory(pinned_dir)); |
| 164 // Create a directory in the temporary directory for persistent files. | 164 // Create a directory in the temporary directory for persistent files. |
| 165 const FilePath persistent_dir = | 165 const FilePath persistent_dir = |
| 166 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_PERSISTENT); | 166 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_PERSISTENT); |
| 167 ASSERT_TRUE(file_util::CreateDirectory(persistent_dir)); | 167 ASSERT_TRUE(file_util::CreateDirectory(persistent_dir)); |
| 168 // Create a directory in the temporary directory for outgoing symlinks. | 168 // Create a directory in the temporary directory for outgoing symlinks. |
| 169 const FilePath outgoing_dir = | 169 const FilePath outgoing_dir = |
| 170 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_OUTGOING); | 170 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_OUTGOING); |
| 171 ASSERT_TRUE(file_util::CreateDirectory(outgoing_dir)); | 171 ASSERT_TRUE(file_util::CreateDirectory(outgoing_dir)); |
| 172 | 172 |
| 173 // Create a symlink in the pinned directory to /dev/null. | 173 // Create a symlink in the pinned directory to /dev/null. |
| 174 // We'll collect this resource ID as a file to be fetched. | 174 // We'll collect this resource ID as a file to be fetched. |
| 175 ASSERT_TRUE( | 175 ASSERT_TRUE( |
| 176 file_util::CreateSymbolicLink( | 176 file_util::CreateSymbolicLink( |
| 177 FilePath::FromUTF8Unsafe("/dev/null"), | 177 FilePath::FromUTF8Unsafe("/dev/null"), |
| 178 pinned_dir.AppendASCII("resource_id_not_fetched_foo"))); | 178 pinned_dir.AppendASCII("resource_id_not_fetched_foo"))); |
| 179 // Create some more. | 179 // Create some more. |
| 180 ASSERT_TRUE( | 180 ASSERT_TRUE( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 resource_id); | 277 resource_id); |
| 278 } | 278 } |
| 279 | 279 |
| 280 protected: | 280 protected: |
| 281 MessageLoopForUI message_loop_; | 281 MessageLoopForUI message_loop_; |
| 282 content::TestBrowserThread ui_thread_; | 282 content::TestBrowserThread ui_thread_; |
| 283 content::TestBrowserThread io_thread_; | 283 content::TestBrowserThread io_thread_; |
| 284 ScopedTempDir temp_dir_; | 284 ScopedTempDir temp_dir_; |
| 285 scoped_ptr<TestingProfile> profile_; | 285 scoped_ptr<TestingProfile> profile_; |
| 286 scoped_ptr<StrictMock<MockGDataFileSystem> > mock_file_system_; | 286 scoped_ptr<StrictMock<MockGDataFileSystem> > mock_file_system_; |
| 287 GDataCache* cache_; | 287 DriveCache* cache_; |
| 288 scoped_ptr<GDataSyncClient> sync_client_; | 288 scoped_ptr<GDataSyncClient> sync_client_; |
| 289 chromeos::MockNetworkLibrary* mock_network_library_; | 289 chromeos::MockNetworkLibrary* mock_network_library_; |
| 290 scoped_ptr<chromeos::Network> active_network_; | 290 scoped_ptr<chromeos::Network> active_network_; |
| 291 }; | 291 }; |
| 292 | 292 |
| 293 TEST_F(GDataSyncClientTest, StartInitialScan) { | 293 TEST_F(GDataSyncClientTest, StartInitialScan) { |
| 294 SetUpTestFiles(); | 294 SetUpTestFiles(); |
| 295 // Connect to no network, so the sync loop won't spin. | 295 // Connect to no network, so the sync loop won't spin. |
| 296 ConnectToNone(); | 296 ConnectToNone(); |
| 297 | 297 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 ASSERT_EQ(1U, resource_ids.size()); | 565 ASSERT_EQ(1U, resource_ids.size()); |
| 566 EXPECT_EQ("resource_id_fetched", resource_ids[0]); | 566 EXPECT_EQ("resource_id_fetched", resource_ids[0]); |
| 567 // resource_id_dirty is not collected in the queue. | 567 // resource_id_dirty is not collected in the queue. |
| 568 | 568 |
| 569 // Check the contents of the queue for uploading. | 569 // Check the contents of the queue for uploading. |
| 570 resource_ids = GetResourceIdsToBeUploaded(); | 570 resource_ids = GetResourceIdsToBeUploaded(); |
| 571 ASSERT_TRUE(resource_ids.empty()); | 571 ASSERT_TRUE(resource_ids.empty()); |
| 572 } | 572 } |
| 573 | 573 |
| 574 } // namespace gdata | 574 } // namespace gdata |
| OLD | NEW |