| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <stack> | 8 #include <stack> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 base::Bind( | 225 base::Bind( |
| 226 &SetValueAndCallClosure<bool>, run_loop.QuitClosure(), &success)); | 226 &SetValueAndCallClosure<bool>, run_loop.QuitClosure(), &success)); |
| 227 run_loop.Run(); | 227 run_loop.Run(); |
| 228 EXPECT_TRUE(success); | 228 EXPECT_TRUE(success); |
| 229 EXPECT_EQ(normalized_path, result_path); | 229 EXPECT_EQ(normalized_path, result_path); |
| 230 return tracker.file_id(); | 230 return tracker.file_id(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 SyncStatusCode RegisterApp(const std::string& app_id) { | 233 SyncStatusCode RegisterApp(const std::string& app_id) { |
| 234 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); | 234 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); |
| 235 if (!ContainsKey(file_systems_, app_id)) { | 235 if (!base::ContainsKey(file_systems_, app_id)) { |
| 236 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem( | 236 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem( |
| 237 origin, in_memory_env_.get(), | 237 origin, in_memory_env_.get(), |
| 238 io_task_runner_.get(), file_task_runner_.get()); | 238 io_task_runner_.get(), file_task_runner_.get()); |
| 239 file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED); | 239 file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED); |
| 240 | 240 |
| 241 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 241 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 242 base::RunLoop run_loop; | 242 base::RunLoop run_loop; |
| 243 local_sync_service_->MaybeInitializeFileSystemContext( | 243 local_sync_service_->MaybeInitializeFileSystemContext( |
| 244 origin, file_system->file_system_context(), | 244 origin, file_system->file_system_context(), |
| 245 base::Bind(&SetValueAndCallClosure<SyncStatusCode>, | 245 base::Bind(&SetValueAndCallClosure<SyncStatusCode>, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 259 remote_sync_service_->RegisterOrigin( | 259 remote_sync_service_->RegisterOrigin( |
| 260 origin, | 260 origin, |
| 261 base::Bind(&SetValueAndCallClosure<SyncStatusCode>, | 261 base::Bind(&SetValueAndCallClosure<SyncStatusCode>, |
| 262 run_loop.QuitClosure(), &status)); | 262 run_loop.QuitClosure(), &status)); |
| 263 run_loop.Run(); | 263 run_loop.Run(); |
| 264 return status; | 264 return status; |
| 265 } | 265 } |
| 266 | 266 |
| 267 void AddLocalFolder(const std::string& app_id, | 267 void AddLocalFolder(const std::string& app_id, |
| 268 const base::FilePath::StringType& path) { | 268 const base::FilePath::StringType& path) { |
| 269 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); | 269 ASSERT_TRUE(base::ContainsKey(file_systems_, app_id)); |
| 270 EXPECT_EQ(base::File::FILE_OK, | 270 EXPECT_EQ(base::File::FILE_OK, |
| 271 file_systems_[app_id]->CreateDirectory( | 271 file_systems_[app_id]->CreateDirectory( |
| 272 CreateURL(app_id, path))); | 272 CreateURL(app_id, path))); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void AddOrUpdateLocalFile(const std::string& app_id, | 275 void AddOrUpdateLocalFile(const std::string& app_id, |
| 276 const base::FilePath::StringType& path, | 276 const base::FilePath::StringType& path, |
| 277 const std::string& content) { | 277 const std::string& content) { |
| 278 storage::FileSystemURL url(CreateURL(app_id, path)); | 278 storage::FileSystemURL url(CreateURL(app_id, path)); |
| 279 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); | 279 ASSERT_TRUE(base::ContainsKey(file_systems_, app_id)); |
| 280 EXPECT_EQ(base::File::FILE_OK, file_systems_[app_id]->CreateFile(url)); | 280 EXPECT_EQ(base::File::FILE_OK, file_systems_[app_id]->CreateFile(url)); |
| 281 int64_t bytes_written = file_systems_[app_id]->WriteString(url, content); | 281 int64_t bytes_written = file_systems_[app_id]->WriteString(url, content); |
| 282 EXPECT_EQ(static_cast<int64_t>(content.size()), bytes_written); | 282 EXPECT_EQ(static_cast<int64_t>(content.size()), bytes_written); |
| 283 base::RunLoop().RunUntilIdle(); | 283 base::RunLoop().RunUntilIdle(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void UpdateLocalFile(const std::string& app_id, | 286 void UpdateLocalFile(const std::string& app_id, |
| 287 const base::FilePath::StringType& path, | 287 const base::FilePath::StringType& path, |
| 288 const std::string& content) { | 288 const std::string& content) { |
| 289 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); | 289 ASSERT_TRUE(base::ContainsKey(file_systems_, app_id)); |
| 290 int64_t bytes_written = | 290 int64_t bytes_written = |
| 291 file_systems_[app_id]->WriteString(CreateURL(app_id, path), content); | 291 file_systems_[app_id]->WriteString(CreateURL(app_id, path), content); |
| 292 EXPECT_EQ(static_cast<int64_t>(content.size()), bytes_written); | 292 EXPECT_EQ(static_cast<int64_t>(content.size()), bytes_written); |
| 293 base::RunLoop().RunUntilIdle(); | 293 base::RunLoop().RunUntilIdle(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void RemoveLocal(const std::string& app_id, | 296 void RemoveLocal(const std::string& app_id, |
| 297 const base::FilePath::StringType& path) { | 297 const base::FilePath::StringType& path) { |
| 298 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); | 298 ASSERT_TRUE(base::ContainsKey(file_systems_, app_id)); |
| 299 EXPECT_EQ(base::File::FILE_OK, | 299 EXPECT_EQ(base::File::FILE_OK, |
| 300 file_systems_[app_id]->Remove( | 300 file_systems_[app_id]->Remove( |
| 301 CreateURL(app_id, path), | 301 CreateURL(app_id, path), |
| 302 true /* recursive */)); | 302 true /* recursive */)); |
| 303 base::RunLoop().RunUntilIdle(); | 303 base::RunLoop().RunUntilIdle(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 SyncStatusCode ProcessLocalChange() { | 306 SyncStatusCode ProcessLocalChange() { |
| 307 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 307 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 308 storage::FileSystemURL url; | 308 storage::FileSystemURL url; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 ScopedVector<google_apis::FileResource> remote_entries; | 417 ScopedVector<google_apis::FileResource> remote_entries; |
| 418 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 418 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
| 419 fake_drive_service_helper_->ListFilesInFolder( | 419 fake_drive_service_helper_->ListFilesInFolder( |
| 420 sync_root_folder_id, &remote_entries)); | 420 sync_root_folder_id, &remote_entries)); |
| 421 std::map<std::string, const google_apis::FileResource*> app_root_by_title; | 421 std::map<std::string, const google_apis::FileResource*> app_root_by_title; |
| 422 for (ScopedVector<google_apis::FileResource>::iterator itr = | 422 for (ScopedVector<google_apis::FileResource>::iterator itr = |
| 423 remote_entries.begin(); | 423 remote_entries.begin(); |
| 424 itr != remote_entries.end(); | 424 itr != remote_entries.end(); |
| 425 ++itr) { | 425 ++itr) { |
| 426 const google_apis::FileResource& remote_entry = **itr; | 426 const google_apis::FileResource& remote_entry = **itr; |
| 427 EXPECT_FALSE(ContainsKey(app_root_by_title, remote_entry.title())); | 427 EXPECT_FALSE(base::ContainsKey(app_root_by_title, remote_entry.title())); |
| 428 app_root_by_title[remote_entry.title()] = *itr; | 428 app_root_by_title[remote_entry.title()] = *itr; |
| 429 } | 429 } |
| 430 | 430 |
| 431 for (std::map<std::string, CannedSyncableFileSystem*>::const_iterator itr = | 431 for (std::map<std::string, CannedSyncableFileSystem*>::const_iterator itr = |
| 432 file_systems_.begin(); | 432 file_systems_.begin(); |
| 433 itr != file_systems_.end(); ++itr) { | 433 itr != file_systems_.end(); ++itr) { |
| 434 const std::string& app_id = itr->first; | 434 const std::string& app_id = itr->first; |
| 435 SCOPED_TRACE(testing::Message() << "Verifying app: " << app_id); | 435 SCOPED_TRACE(testing::Message() << "Verifying app: " << app_id); |
| 436 CannedSyncableFileSystem* file_system = itr->second; | 436 CannedSyncableFileSystem* file_system = itr->second; |
| 437 ASSERT_TRUE(ContainsKey(app_root_by_title, app_id)); | 437 ASSERT_TRUE(base::ContainsKey(app_root_by_title, app_id)); |
| 438 VerifyConsistencyForFolder( | 438 VerifyConsistencyForFolder( |
| 439 app_id, base::FilePath(), | 439 app_id, base::FilePath(), |
| 440 app_root_by_title[app_id]->file_id(), | 440 app_root_by_title[app_id]->file_id(), |
| 441 file_system); | 441 file_system); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 | 444 |
| 445 void VerifyConsistencyForFolder(const std::string& app_id, | 445 void VerifyConsistencyForFolder(const std::string& app_id, |
| 446 const base::FilePath& path, | 446 const base::FilePath& path, |
| 447 const std::string& folder_id, | 447 const std::string& folder_id, |
| 448 CannedSyncableFileSystem* file_system) { | 448 CannedSyncableFileSystem* file_system) { |
| 449 SCOPED_TRACE(testing::Message() << "Verifying folder: " << path.value()); | 449 SCOPED_TRACE(testing::Message() << "Verifying folder: " << path.value()); |
| 450 | 450 |
| 451 ScopedVector<google_apis::FileResource> remote_entries; | 451 ScopedVector<google_apis::FileResource> remote_entries; |
| 452 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 452 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
| 453 fake_drive_service_helper_->ListFilesInFolder( | 453 fake_drive_service_helper_->ListFilesInFolder( |
| 454 folder_id, &remote_entries)); | 454 folder_id, &remote_entries)); |
| 455 std::map<std::string, const google_apis::FileResource*> | 455 std::map<std::string, const google_apis::FileResource*> |
| 456 remote_entry_by_title; | 456 remote_entry_by_title; |
| 457 for (size_t i = 0; i < remote_entries.size(); ++i) { | 457 for (size_t i = 0; i < remote_entries.size(); ++i) { |
| 458 google_apis::FileResource* remote_entry = remote_entries[i]; | 458 google_apis::FileResource* remote_entry = remote_entries[i]; |
| 459 EXPECT_FALSE(ContainsKey(remote_entry_by_title, remote_entry->title())) | 459 EXPECT_FALSE( |
| 460 base::ContainsKey(remote_entry_by_title, remote_entry->title())) |
| 460 << "title: " << remote_entry->title(); | 461 << "title: " << remote_entry->title(); |
| 461 remote_entry_by_title[remote_entry->title()] = remote_entry; | 462 remote_entry_by_title[remote_entry->title()] = remote_entry; |
| 462 } | 463 } |
| 463 | 464 |
| 464 storage::FileSystemURL url(CreateURL(app_id, path)); | 465 storage::FileSystemURL url(CreateURL(app_id, path)); |
| 465 FileEntryList local_entries; | 466 FileEntryList local_entries; |
| 466 EXPECT_EQ(base::File::FILE_OK, | 467 EXPECT_EQ(base::File::FILE_OK, |
| 467 file_system->ReadDirectory(url, &local_entries)); | 468 file_system->ReadDirectory(url, &local_entries)); |
| 468 for (FileEntryList::iterator itr = local_entries.begin(); | 469 for (FileEntryList::iterator itr = local_entries.begin(); |
| 469 itr != local_entries.end(); | 470 itr != local_entries.end(); |
| 470 ++itr) { | 471 ++itr) { |
| 471 const storage::DirectoryEntry& local_entry = *itr; | 472 const storage::DirectoryEntry& local_entry = *itr; |
| 472 storage::FileSystemURL entry_url( | 473 storage::FileSystemURL entry_url( |
| 473 CreateURL(app_id, path.Append(local_entry.name))); | 474 CreateURL(app_id, path.Append(local_entry.name))); |
| 474 std::string title = | 475 std::string title = |
| 475 storage::VirtualPath::BaseName(entry_url.path()).AsUTF8Unsafe(); | 476 storage::VirtualPath::BaseName(entry_url.path()).AsUTF8Unsafe(); |
| 476 SCOPED_TRACE(testing::Message() << "Verifying entry: " << title); | 477 SCOPED_TRACE(testing::Message() << "Verifying entry: " << title); |
| 477 | 478 |
| 478 ASSERT_TRUE(ContainsKey(remote_entry_by_title, title)); | 479 ASSERT_TRUE(base::ContainsKey(remote_entry_by_title, title)); |
| 479 const google_apis::FileResource& remote_entry = | 480 const google_apis::FileResource& remote_entry = |
| 480 *remote_entry_by_title[title]; | 481 *remote_entry_by_title[title]; |
| 481 if (local_entry.is_directory) { | 482 if (local_entry.is_directory) { |
| 482 ASSERT_TRUE(remote_entry.IsDirectory()); | 483 ASSERT_TRUE(remote_entry.IsDirectory()); |
| 483 VerifyConsistencyForFolder(app_id, entry_url.path(), | 484 VerifyConsistencyForFolder(app_id, entry_url.path(), |
| 484 remote_entry.file_id(), | 485 remote_entry.file_id(), |
| 485 file_system); | 486 file_system); |
| 486 } else { | 487 } else { |
| 487 ASSERT_FALSE(remote_entry.IsDirectory()); | 488 ASSERT_FALSE(remote_entry.IsDirectory()); |
| 488 VerifyConsistencyForFile(app_id, entry_url.path(), | 489 VerifyConsistencyForFile(app_id, entry_url.path(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 505 fake_drive_service_helper_->ReadFile(file_id, &file_content)); | 506 fake_drive_service_helper_->ReadFile(file_id, &file_content)); |
| 506 EXPECT_EQ(base::File::FILE_OK, | 507 EXPECT_EQ(base::File::FILE_OK, |
| 507 file_system->VerifyFile(url, file_content)); | 508 file_system->VerifyFile(url, file_content)); |
| 508 } | 509 } |
| 509 | 510 |
| 510 size_t CountApp() { | 511 size_t CountApp() { |
| 511 return file_systems_.size(); | 512 return file_systems_.size(); |
| 512 } | 513 } |
| 513 | 514 |
| 514 size_t CountLocalFile(const std::string& app_id) { | 515 size_t CountLocalFile(const std::string& app_id) { |
| 515 if (!ContainsKey(file_systems_, app_id)) | 516 if (!base::ContainsKey(file_systems_, app_id)) |
| 516 return 0; | 517 return 0; |
| 517 | 518 |
| 518 CannedSyncableFileSystem* file_system = file_systems_[app_id]; | 519 CannedSyncableFileSystem* file_system = file_systems_[app_id]; |
| 519 std::stack<base::FilePath> folders; | 520 std::stack<base::FilePath> folders; |
| 520 folders.push(base::FilePath()); // root folder | 521 folders.push(base::FilePath()); // root folder |
| 521 | 522 |
| 522 size_t result = 1; | 523 size_t result = 1; |
| 523 while (!folders.empty()) { | 524 while (!folders.empty()) { |
| 524 storage::FileSystemURL url(CreateURL(app_id, folders.top())); | 525 storage::FileSystemURL url(CreateURL(app_id, folders.top())); |
| 525 folders.pop(); | 526 folders.pop(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 537 | 538 |
| 538 return result; | 539 return result; |
| 539 } | 540 } |
| 540 | 541 |
| 541 void VerifyLocalFile(const std::string& app_id, | 542 void VerifyLocalFile(const std::string& app_id, |
| 542 const base::FilePath::StringType& path, | 543 const base::FilePath::StringType& path, |
| 543 const std::string& content) { | 544 const std::string& content) { |
| 544 SCOPED_TRACE(testing::Message() << "Verifying local file: " | 545 SCOPED_TRACE(testing::Message() << "Verifying local file: " |
| 545 << "app_id = " << app_id | 546 << "app_id = " << app_id |
| 546 << ", path = " << path); | 547 << ", path = " << path); |
| 547 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); | 548 ASSERT_TRUE(base::ContainsKey(file_systems_, app_id)); |
| 548 EXPECT_EQ(base::File::FILE_OK, | 549 EXPECT_EQ(base::File::FILE_OK, |
| 549 file_systems_[app_id]->VerifyFile( | 550 file_systems_[app_id]->VerifyFile( |
| 550 CreateURL(app_id, path), content)); | 551 CreateURL(app_id, path), content)); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void VerifyLocalFolder(const std::string& app_id, | 554 void VerifyLocalFolder(const std::string& app_id, |
| 554 const base::FilePath::StringType& path) { | 555 const base::FilePath::StringType& path) { |
| 555 SCOPED_TRACE(testing::Message() << "Verifying local file: " | 556 SCOPED_TRACE(testing::Message() << "Verifying local file: " |
| 556 << "app_id = " << app_id | 557 << "app_id = " << app_id |
| 557 << ", path = " << path); | 558 << ", path = " << path); |
| 558 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); | 559 ASSERT_TRUE(base::ContainsKey(file_systems_, app_id)); |
| 559 EXPECT_EQ(base::File::FILE_OK, | 560 EXPECT_EQ(base::File::FILE_OK, |
| 560 file_systems_[app_id]->DirectoryExists(CreateURL(app_id, path))); | 561 file_systems_[app_id]->DirectoryExists(CreateURL(app_id, path))); |
| 561 } | 562 } |
| 562 | 563 |
| 563 size_t CountMetadata() { | 564 size_t CountMetadata() { |
| 564 size_t count = 0; | 565 size_t count = 0; |
| 565 base::RunLoop run_loop; | 566 base::RunLoop run_loop; |
| 566 PostTaskAndReplyWithResult( | 567 PostTaskAndReplyWithResult( |
| 567 worker_task_runner_.get(), | 568 worker_task_runner_.get(), |
| 568 FROM_HERE, | 569 FROM_HERE, |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 | 1724 |
| 1724 EXPECT_EQ(1u, CountApp()); | 1725 EXPECT_EQ(1u, CountApp()); |
| 1725 EXPECT_EQ(1u, CountLocalFile(app_id)); | 1726 EXPECT_EQ(1u, CountLocalFile(app_id)); |
| 1726 | 1727 |
| 1727 EXPECT_EQ(2u, CountMetadata()); | 1728 EXPECT_EQ(2u, CountMetadata()); |
| 1728 EXPECT_EQ(2u, CountTracker()); | 1729 EXPECT_EQ(2u, CountTracker()); |
| 1729 } | 1730 } |
| 1730 | 1731 |
| 1731 } // namespace drive_backend | 1732 } // namespace drive_backend |
| 1732 } // namespace sync_file_system | 1733 } // namespace sync_file_system |
| OLD | NEW |