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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/drive_backend_sync_unittest.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/browser/drive/drive_uploader.h" 10 #include "chrome/browser/drive/drive_uploader.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 137 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
138 local_sync_service_->MaybeInitializeFileSystemContext( 138 local_sync_service_->MaybeInitializeFileSystemContext(
139 origin, file_system->file_system_context(), 139 origin, file_system->file_system_context(),
140 CreateResultReceiver(&status)); 140 CreateResultReceiver(&status));
141 base::RunLoop().RunUntilIdle(); 141 base::RunLoop().RunUntilIdle();
142 EXPECT_EQ(SYNC_STATUS_OK, status); 142 EXPECT_EQ(SYNC_STATUS_OK, status);
143 143
144 file_system->backend()->sync_context()-> 144 file_system->backend()->sync_context()->
145 set_mock_notify_changes_duration_in_sec(0); 145 set_mock_notify_changes_duration_in_sec(0);
146 146
147 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system->OpenFileSystem()); 147 EXPECT_EQ(base::File::FILE_OK, file_system->OpenFileSystem());
148 file_systems_[app_id] = file_system; 148 file_systems_[app_id] = file_system;
149 } 149 }
150 150
151 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 151 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
152 remote_sync_service_->RegisterOrigin(origin, CreateResultReceiver(&status)); 152 remote_sync_service_->RegisterOrigin(origin, CreateResultReceiver(&status));
153 base::RunLoop().RunUntilIdle(); 153 base::RunLoop().RunUntilIdle();
154 return status; 154 return status;
155 } 155 }
156 156
157 void AddLocalFolder(const std::string& app_id, 157 void AddLocalFolder(const std::string& app_id,
158 const base::FilePath::StringType& path) { 158 const base::FilePath::StringType& path) {
159 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 159 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
160 EXPECT_EQ(base::PLATFORM_FILE_OK, 160 EXPECT_EQ(base::File::FILE_OK,
161 file_systems_[app_id]->CreateDirectory( 161 file_systems_[app_id]->CreateDirectory(
162 CreateURL(app_id, path))); 162 CreateURL(app_id, path)));
163 } 163 }
164 164
165 void AddOrUpdateLocalFile(const std::string& app_id, 165 void AddOrUpdateLocalFile(const std::string& app_id,
166 const base::FilePath::StringType& path, 166 const base::FilePath::StringType& path,
167 const std::string& content) { 167 const std::string& content) {
168 fileapi::FileSystemURL url(CreateURL(app_id, path)); 168 fileapi::FileSystemURL url(CreateURL(app_id, path));
169 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 169 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
170 EXPECT_EQ(base::PLATFORM_FILE_OK, file_systems_[app_id]->CreateFile(url)); 170 EXPECT_EQ(base::File::FILE_OK, file_systems_[app_id]->CreateFile(url));
171 int64 bytes_written = file_systems_[app_id]->WriteString(url, content); 171 int64 bytes_written = file_systems_[app_id]->WriteString(url, content);
172 EXPECT_EQ(static_cast<int64>(content.size()), bytes_written); 172 EXPECT_EQ(static_cast<int64>(content.size()), bytes_written);
173 base::RunLoop().RunUntilIdle(); 173 base::RunLoop().RunUntilIdle();
174 } 174 }
175 175
176 void UpdateLocalFile(const std::string& app_id, 176 void UpdateLocalFile(const std::string& app_id,
177 const base::FilePath::StringType& path, 177 const base::FilePath::StringType& path,
178 const std::string& content) { 178 const std::string& content) {
179 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 179 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
180 int64 bytes_written = file_systems_[app_id]->WriteString( 180 int64 bytes_written = file_systems_[app_id]->WriteString(
181 CreateURL(app_id, path), content); 181 CreateURL(app_id, path), content);
182 EXPECT_EQ(static_cast<int64>(content.size()), bytes_written); 182 EXPECT_EQ(static_cast<int64>(content.size()), bytes_written);
183 base::RunLoop().RunUntilIdle(); 183 base::RunLoop().RunUntilIdle();
184 } 184 }
185 185
186 void RemoveLocal(const std::string& app_id, 186 void RemoveLocal(const std::string& app_id,
187 const base::FilePath::StringType& path) { 187 const base::FilePath::StringType& path) {
188 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 188 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
189 EXPECT_EQ(base::PLATFORM_FILE_OK, 189 EXPECT_EQ(base::File::FILE_OK,
190 file_systems_[app_id]->Remove( 190 file_systems_[app_id]->Remove(
191 CreateURL(app_id, path), 191 CreateURL(app_id, path),
192 true /* recursive */)); 192 true /* recursive */));
193 base::RunLoop().RunUntilIdle(); 193 base::RunLoop().RunUntilIdle();
194 } 194 }
195 195
196 SyncStatusCode ProcessLocalChange() { 196 SyncStatusCode ProcessLocalChange() {
197 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 197 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
198 fileapi::FileSystemURL url; 198 fileapi::FileSystemURL url;
199 local_sync_service_->ProcessLocalChange( 199 local_sync_service_->ProcessLocalChange(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 remote_entries.begin(); 294 remote_entries.begin();
295 itr != remote_entries.end(); 295 itr != remote_entries.end();
296 ++itr) { 296 ++itr) {
297 const google_apis::ResourceEntry& remote_entry = **itr; 297 const google_apis::ResourceEntry& remote_entry = **itr;
298 EXPECT_FALSE(ContainsKey(remote_entry_by_title, remote_entry.title())); 298 EXPECT_FALSE(ContainsKey(remote_entry_by_title, remote_entry.title()));
299 remote_entry_by_title[remote_entry.title()] = *itr; 299 remote_entry_by_title[remote_entry.title()] = *itr;
300 } 300 }
301 301
302 fileapi::FileSystemURL url(CreateURL(app_id, path)); 302 fileapi::FileSystemURL url(CreateURL(app_id, path));
303 CannedSyncableFileSystem::FileEntryList local_entries; 303 CannedSyncableFileSystem::FileEntryList local_entries;
304 EXPECT_EQ(base::PLATFORM_FILE_OK, 304 EXPECT_EQ(base::File::FILE_OK,
305 file_system->ReadDirectory(url, &local_entries)); 305 file_system->ReadDirectory(url, &local_entries));
306 for (CannedSyncableFileSystem::FileEntryList::iterator itr = 306 for (CannedSyncableFileSystem::FileEntryList::iterator itr =
307 local_entries.begin(); 307 local_entries.begin();
308 itr != local_entries.end(); 308 itr != local_entries.end();
309 ++itr) { 309 ++itr) {
310 const fileapi::DirectoryEntry& local_entry = *itr; 310 const fileapi::DirectoryEntry& local_entry = *itr;
311 fileapi::FileSystemURL entry_url( 311 fileapi::FileSystemURL entry_url(
312 CreateURL(app_id, path.Append(local_entry.name))); 312 CreateURL(app_id, path.Append(local_entry.name)));
313 std::string title = entry_url.path().AsUTF8Unsafe(); 313 std::string title = entry_url.path().AsUTF8Unsafe();
314 ASSERT_TRUE(ContainsKey(remote_entry_by_title, title)); 314 ASSERT_TRUE(ContainsKey(remote_entry_by_title, title));
(...skipping 17 matching lines...) Expand all
332 } 332 }
333 333
334 void VerifyConsistencyForFile(const std::string& app_id, 334 void VerifyConsistencyForFile(const std::string& app_id,
335 const base::FilePath& path, 335 const base::FilePath& path,
336 const std::string& file_id, 336 const std::string& file_id,
337 CannedSyncableFileSystem* file_system) { 337 CannedSyncableFileSystem* file_system) {
338 fileapi::FileSystemURL url(CreateURL(app_id, path)); 338 fileapi::FileSystemURL url(CreateURL(app_id, path));
339 std::string file_content; 339 std::string file_content;
340 EXPECT_EQ(google_apis::HTTP_SUCCESS, 340 EXPECT_EQ(google_apis::HTTP_SUCCESS,
341 fake_drive_service_helper_->ReadFile(file_id, &file_content)); 341 fake_drive_service_helper_->ReadFile(file_id, &file_content));
342 EXPECT_EQ(base::PLATFORM_FILE_OK, 342 EXPECT_EQ(base::File::FILE_OK,
343 file_system->VerifyFile(url, file_content)); 343 file_system->VerifyFile(url, file_content));
344 } 344 }
345 345
346 drive::FakeDriveService* fake_drive_service() { 346 drive::FakeDriveService* fake_drive_service() {
347 return static_cast<drive::FakeDriveService*>( 347 return static_cast<drive::FakeDriveService*>(
348 remote_sync_service_->GetDriveService()); 348 remote_sync_service_->GetDriveService());
349 } 349 }
350 350
351 drive::DriveUploaderInterface* drive_uploader() { 351 drive::DriveUploaderInterface* drive_uploader() {
352 return remote_sync_service_->GetDriveUploader(); 352 return remote_sync_service_->GetDriveUploader();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 EXPECT_TRUE(GetFileIDByPath(app_id, base::FilePath(path), &file_id)); 473 EXPECT_TRUE(GetFileIDByPath(app_id, base::FilePath(path), &file_id));
474 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 474 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
475 fake_drive_service_helper()->DeleteResource(file_id)); 475 fake_drive_service_helper()->DeleteResource(file_id));
476 476
477 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 477 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
478 VerifyConsistency(); 478 VerifyConsistency();
479 } 479 }
480 480
481 } // namespace drive_backend 481 } // namespace drive_backend
482 } // namespace sync_file_system 482 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698