Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 1124813003: [chrome/browser/chromeos/drive] Avoid use of MessageLoopProxy by use of TTRH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/prefs/testing_pref_service.h" 15 #include "base/prefs/testing_pref_service.h"
17 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h"
18 #include "base/thread_task_runner_handle.h"
18 #include "chrome/browser/chromeos/drive/change_list_loader.h" 19 #include "chrome/browser/chromeos/drive/change_list_loader.h"
19 #include "chrome/browser/chromeos/drive/drive.pb.h" 20 #include "chrome/browser/chromeos/drive/drive.pb.h"
20 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 21 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
21 #include "chrome/browser/chromeos/drive/file_change.h" 22 #include "chrome/browser/chromeos/drive/file_change.h"
22 #include "chrome/browser/chromeos/drive/file_system_observer.h" 23 #include "chrome/browser/chromeos/drive/file_system_observer.h"
23 #include "chrome/browser/chromeos/drive/file_system_util.h" 24 #include "chrome/browser/chromeos/drive/file_system_util.h"
24 #include "chrome/browser/chromeos/drive/job_scheduler.h" 25 #include "chrome/browser/chromeos/drive/job_scheduler.h"
25 #include "chrome/browser/chromeos/drive/sync_client.h" 26 #include "chrome/browser/chromeos/drive/sync_client.h"
26 #include "chrome/browser/chromeos/drive/test_util.h" 27 #include "chrome/browser/chromeos/drive/test_util.h"
27 #include "chrome/browser/drive/drive_api_util.h" 28 #include "chrome/browser/drive/drive_api_util.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 100 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
100 pref_service_.reset(new TestingPrefServiceSimple); 101 pref_service_.reset(new TestingPrefServiceSimple);
101 test_util::RegisterDrivePrefs(pref_service_->registry()); 102 test_util::RegisterDrivePrefs(pref_service_->registry());
102 103
103 logger_.reset(new EventLogger); 104 logger_.reset(new EventLogger);
104 fake_drive_service_.reset(new FakeDriveService); 105 fake_drive_service_.reset(new FakeDriveService);
105 test_util::SetUpTestEntries(fake_drive_service_.get()); 106 test_util::SetUpTestEntries(fake_drive_service_.get());
106 107
107 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); 108 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
108 109
109 scheduler_.reset(new JobScheduler(pref_service_.get(), 110 scheduler_.reset(new JobScheduler(pref_service_.get(), logger_.get(),
110 logger_.get(),
111 fake_drive_service_.get(), 111 fake_drive_service_.get(),
112 base::MessageLoopProxy::current().get())); 112 base::ThreadTaskRunnerHandle::Get()));
113 113
114 mock_directory_observer_.reset(new MockDirectoryChangeObserver); 114 mock_directory_observer_.reset(new MockDirectoryChangeObserver);
115 115
116 SetUpResourceMetadataAndFileSystem(); 116 SetUpResourceMetadataAndFileSystem();
117 } 117 }
118 118
119 void SetUpResourceMetadataAndFileSystem() { 119 void SetUpResourceMetadataAndFileSystem() {
120 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta"); 120 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta");
121 ASSERT_TRUE(base::CreateDirectory(metadata_dir)); 121 ASSERT_TRUE(base::CreateDirectory(metadata_dir));
122 metadata_storage_.reset(new internal::ResourceMetadataStorage( 122 metadata_storage_.reset(new internal::ResourceMetadataStorage(
123 metadata_dir, base::MessageLoopProxy::current().get())); 123 metadata_dir, base::ThreadTaskRunnerHandle::Get()));
124 ASSERT_TRUE(metadata_storage_->Initialize()); 124 ASSERT_TRUE(metadata_storage_->Initialize());
125 125
126 const base::FilePath cache_dir = temp_dir_.path().AppendASCII("files"); 126 const base::FilePath cache_dir = temp_dir_.path().AppendASCII("files");
127 ASSERT_TRUE(base::CreateDirectory(cache_dir)); 127 ASSERT_TRUE(base::CreateDirectory(cache_dir));
128 cache_.reset(new internal::FileCache( 128 cache_.reset(new internal::FileCache(metadata_storage_.get(), cache_dir,
129 metadata_storage_.get(), 129 base::ThreadTaskRunnerHandle::Get(),
130 cache_dir, 130 fake_free_disk_space_getter_.get()));
131 base::MessageLoopProxy::current().get(),
132 fake_free_disk_space_getter_.get()));
133 ASSERT_TRUE(cache_->Initialize()); 131 ASSERT_TRUE(cache_->Initialize());
134 132
135 resource_metadata_.reset(new internal::ResourceMetadata( 133 resource_metadata_.reset(
136 metadata_storage_.get(), cache_.get(), 134 new internal::ResourceMetadata(metadata_storage_.get(), cache_.get(),
137 base::MessageLoopProxy::current())); 135 base::ThreadTaskRunnerHandle::Get()));
138 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize()); 136 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize());
139 137
140 const base::FilePath temp_file_dir = temp_dir_.path().AppendASCII("tmp"); 138 const base::FilePath temp_file_dir = temp_dir_.path().AppendASCII("tmp");
141 ASSERT_TRUE(base::CreateDirectory(temp_file_dir)); 139 ASSERT_TRUE(base::CreateDirectory(temp_file_dir));
142 file_system_.reset(new FileSystem( 140 file_system_.reset(
143 pref_service_.get(), 141 new FileSystem(pref_service_.get(), logger_.get(), cache_.get(),
144 logger_.get(), 142 scheduler_.get(), resource_metadata_.get(),
145 cache_.get(), 143 base::ThreadTaskRunnerHandle::Get(), temp_file_dir));
146 scheduler_.get(),
147 resource_metadata_.get(),
148 base::MessageLoopProxy::current().get(),
149 temp_file_dir));
150 file_system_->AddObserver(mock_directory_observer_.get()); 144 file_system_->AddObserver(mock_directory_observer_.get());
151 145
152 // Disable delaying so that the sync starts immediately. 146 // Disable delaying so that the sync starts immediately.
153 file_system_->sync_client_for_testing()->set_delay_for_testing( 147 file_system_->sync_client_for_testing()->set_delay_for_testing(
154 base::TimeDelta::FromSeconds(0)); 148 base::TimeDelta::FromSeconds(0));
155 } 149 }
156 150
157 // Loads the full resource list via FakeDriveService. 151 // Loads the full resource list via FakeDriveService.
158 bool LoadFullResourceList() { 152 bool LoadFullResourceList() {
159 FileError error = FILE_ERROR_FAILED; 153 FileError error = FILE_ERROR_FAILED;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // drive/root/Dir1/SubDir2/File3. If |use_up_to_date_timestamp| is true, sets 209 // drive/root/Dir1/SubDir2/File3. If |use_up_to_date_timestamp| is true, sets
216 // the changestamp to that of FakeDriveService, indicating the cache is 210 // the changestamp to that of FakeDriveService, indicating the cache is
217 // holding the latest file system info. 211 // holding the latest file system info.
218 void SetUpTestFileSystem(SetUpTestFileSystemParam param) { 212 void SetUpTestFileSystem(SetUpTestFileSystemParam param) {
219 // Destroy the existing resource metadata to close DB. 213 // Destroy the existing resource metadata to close DB.
220 resource_metadata_.reset(); 214 resource_metadata_.reset();
221 215
222 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta"); 216 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta");
223 ASSERT_TRUE(base::CreateDirectory(metadata_dir)); 217 ASSERT_TRUE(base::CreateDirectory(metadata_dir));
224 scoped_ptr<internal::ResourceMetadataStorage, 218 scoped_ptr<internal::ResourceMetadataStorage,
225 test_util::DestroyHelperForTests> metadata_storage( 219 test_util::DestroyHelperForTests>
226 new internal::ResourceMetadataStorage( 220 metadata_storage(new internal::ResourceMetadataStorage(
227 metadata_dir, base::MessageLoopProxy::current().get())); 221 metadata_dir, base::ThreadTaskRunnerHandle::Get()));
228 222
229 const base::FilePath cache_dir = temp_dir_.path().AppendASCII("files"); 223 const base::FilePath cache_dir = temp_dir_.path().AppendASCII("files");
230 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache( 224 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache(
231 new internal::FileCache(metadata_storage.get(), 225 new internal::FileCache(metadata_storage.get(), cache_dir,
232 cache_dir, 226 base::ThreadTaskRunnerHandle::Get(),
233 base::MessageLoopProxy::current().get(),
234 fake_free_disk_space_getter_.get())); 227 fake_free_disk_space_getter_.get()));
235 228
236 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 229 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
237 resource_metadata(new internal::ResourceMetadata( 230 resource_metadata(new internal::ResourceMetadata(
238 metadata_storage_.get(), cache.get(), 231 metadata_storage_.get(), cache.get(),
239 base::MessageLoopProxy::current())); 232 base::ThreadTaskRunnerHandle::Get()));
240 233
241 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->Initialize()); 234 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->Initialize());
242 235
243 const int64 changestamp = param == USE_SERVER_TIMESTAMP ? 236 const int64 changestamp = param == USE_SERVER_TIMESTAMP ?
244 fake_drive_service_->about_resource().largest_change_id() : 1; 237 fake_drive_service_->about_resource().largest_change_id() : 1;
245 ASSERT_EQ(FILE_ERROR_OK, 238 ASSERT_EQ(FILE_ERROR_OK,
246 resource_metadata->SetLargestChangestamp(changestamp)); 239 resource_metadata->SetLargestChangestamp(changestamp));
247 240
248 // drive/root 241 // drive/root
249 ResourceEntry root; 242 ResourceEntry root;
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 google_apis::test_util::CreateCopyResultCallback(&available)); 1043 google_apis::test_util::CreateCopyResultCallback(&available));
1051 content::RunAllBlockingPoolTasksUntilIdle(); 1044 content::RunAllBlockingPoolTasksUntilIdle();
1052 ASSERT_FALSE(available); 1045 ASSERT_FALSE(available);
1053 1046
1054 entry = GetResourceEntrySync(file_in_root); 1047 entry = GetResourceEntrySync(file_in_root);
1055 ASSERT_TRUE(entry); 1048 ASSERT_TRUE(entry);
1056 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present()); 1049 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present());
1057 } 1050 }
1058 1051
1059 } // namespace drive 1052 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698