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/drive/drive_sync_client.h" | 5 #include "chrome/browser/chromeos/drive/drive_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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 virtual void SetUp() OVERRIDE { | 74 virtual void SetUp() OVERRIDE { |
75 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier); | 75 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier); |
76 | 76 |
77 // Create a temporary directory. | 77 // Create a temporary directory. |
78 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 78 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
79 | 79 |
80 // Initialize the cache. | 80 // Initialize the cache. |
81 scoped_refptr<base::SequencedWorkerPool> pool = | 81 scoped_refptr<base::SequencedWorkerPool> pool = |
82 content::BrowserThread::GetBlockingPool(); | 82 content::BrowserThread::GetBlockingPool(); |
83 cache_ = new DriveCache( | 83 cache_.reset(new DriveCache( |
84 temp_dir_.path(), | 84 temp_dir_.path(), |
85 pool->GetSequencedTaskRunner(pool->GetSequenceToken()), | 85 pool->GetSequencedTaskRunner(pool->GetSequenceToken()), |
86 NULL /* free_disk_space_getter */); | 86 NULL /* free_disk_space_getter */)); |
87 bool cache_initialization_success = false; | 87 bool cache_initialization_success = false; |
88 cache_->RequestInitialize( | 88 cache_->RequestInitialize( |
89 base::Bind(&test_util::CopyResultFromInitializeCacheCallback, | 89 base::Bind(&test_util::CopyResultFromInitializeCacheCallback, |
90 &cache_initialization_success)); | 90 &cache_initialization_success)); |
91 google_apis::test_util::RunBlockingPoolTask(); | 91 google_apis::test_util::RunBlockingPoolTask(); |
92 ASSERT_TRUE(cache_initialization_success); | 92 ASSERT_TRUE(cache_initialization_success); |
93 SetUpCache(); | 93 SetUpCache(); |
94 | 94 |
95 // Initialize the sync client. | 95 // Initialize the sync client. |
96 sync_client_.reset(new DriveSyncClient(profile_.get(), | 96 sync_client_.reset(new DriveSyncClient(profile_.get(), |
97 mock_file_system_.get(), | 97 mock_file_system_.get(), |
98 cache_)); | 98 cache_.get())); |
99 | 99 |
100 EXPECT_CALL(*mock_file_system_, AddObserver(sync_client_.get())).Times(1); | 100 EXPECT_CALL(*mock_file_system_, AddObserver(sync_client_.get())).Times(1); |
101 EXPECT_CALL(*mock_file_system_, | 101 EXPECT_CALL(*mock_file_system_, |
102 RemoveObserver(sync_client_.get())).Times(1); | 102 RemoveObserver(sync_client_.get())).Times(1); |
103 | 103 |
104 // Disable delaying so that DoSyncLoop() starts immediately. | 104 // Disable delaying so that DoSyncLoop() starts immediately. |
105 sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0)); | 105 sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0)); |
106 sync_client_->Initialize(); | 106 sync_client_->Initialize(); |
107 } | 107 } |
108 | 108 |
109 virtual void TearDown() OVERRIDE { | 109 virtual void TearDown() OVERRIDE { |
110 // The sync client should be deleted before NetworkLibrary, as the sync | 110 // The sync client should be deleted before NetworkLibrary, as the sync |
111 // client registers itself as observer of NetworkLibrary. | 111 // client registers itself as observer of NetworkLibrary. |
112 sync_client_.reset(); | 112 sync_client_.reset(); |
113 test_util::DeleteDriveCache(cache_); | 113 cache_.reset(); |
114 mock_network_change_notifier_.reset(); | 114 mock_network_change_notifier_.reset(); |
115 } | 115 } |
116 | 116 |
117 // Sets up cache for tests. | 117 // Sets up cache for tests. |
118 void SetUpCache() { | 118 void SetUpCache() { |
119 // Prepare a temp file. | 119 // Prepare a temp file. |
120 base::FilePath temp_file; | 120 base::FilePath temp_file; |
121 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), | 121 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), |
122 &temp_file)); | 122 &temp_file)); |
123 const std::string content = "hello"; | 123 const std::string content = "hello"; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 sync_client_->AddResourceIdForTesting(DriveSyncClient::UPLOAD, | 247 sync_client_->AddResourceIdForTesting(DriveSyncClient::UPLOAD, |
248 resource_id); | 248 resource_id); |
249 } | 249 } |
250 | 250 |
251 protected: | 251 protected: |
252 MessageLoopForUI message_loop_; | 252 MessageLoopForUI message_loop_; |
253 content::TestBrowserThread ui_thread_; | 253 content::TestBrowserThread ui_thread_; |
254 base::ScopedTempDir temp_dir_; | 254 base::ScopedTempDir temp_dir_; |
255 scoped_ptr<TestingProfile> profile_; | 255 scoped_ptr<TestingProfile> profile_; |
256 scoped_ptr<StrictMock<MockDriveFileSystem> > mock_file_system_; | 256 scoped_ptr<StrictMock<MockDriveFileSystem> > mock_file_system_; |
257 DriveCache* cache_; | 257 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_; |
258 scoped_ptr<DriveSyncClient> sync_client_; | 258 scoped_ptr<DriveSyncClient> sync_client_; |
259 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; | 259 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; |
260 }; | 260 }; |
261 | 261 |
262 TEST_F(DriveSyncClientTest, StartInitialScan) { | 262 TEST_F(DriveSyncClientTest, StartInitialScan) { |
263 // Start processing the files in the backlog. This will collect the | 263 // Start processing the files in the backlog. This will collect the |
264 // resource IDs of these files. | 264 // resource IDs of these files. |
265 sync_client_->StartProcessingBacklog(); | 265 sync_client_->StartProcessingBacklog(); |
266 | 266 |
267 // Check the contents of the queue for fetching. | 267 // Check the contents of the queue for fetching. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // Start checking the existing pinned files. This will collect the resource | 329 // Start checking the existing pinned files. This will collect the resource |
330 // IDs of pinned files, with stale local cache files. | 330 // IDs of pinned files, with stale local cache files. |
331 sync_client_->StartCheckingExistingPinnedFiles(); | 331 sync_client_->StartCheckingExistingPinnedFiles(); |
332 | 332 |
333 SetExpectationForGetFileByResourceId("resource_id_fetched"); | 333 SetExpectationForGetFileByResourceId("resource_id_fetched"); |
334 | 334 |
335 google_apis::test_util::RunBlockingPoolTask(); | 335 google_apis::test_util::RunBlockingPoolTask(); |
336 } | 336 } |
337 | 337 |
338 } // namespace drive | 338 } // namespace drive |
OLD | NEW |