| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <stack> | 6 #include <stack> |
| 7 | 7 |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 std::string sync_root_folder_id; | 404 std::string sync_root_folder_id; |
| 405 google_apis::GDataErrorCode error = | 405 google_apis::GDataErrorCode error = |
| 406 fake_drive_service_helper_->GetSyncRootFolderID(&sync_root_folder_id); | 406 fake_drive_service_helper_->GetSyncRootFolderID(&sync_root_folder_id); |
| 407 if (sync_root_folder_id.empty()) { | 407 if (sync_root_folder_id.empty()) { |
| 408 EXPECT_EQ(google_apis::HTTP_NOT_FOUND, error); | 408 EXPECT_EQ(google_apis::HTTP_NOT_FOUND, error); |
| 409 EXPECT_TRUE(file_systems_.empty()); | 409 EXPECT_TRUE(file_systems_.empty()); |
| 410 return; | 410 return; |
| 411 } | 411 } |
| 412 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); | 412 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); |
| 413 | 413 |
| 414 ScopedVector<google_apis::ResourceEntry> remote_entries; | 414 ScopedVector<google_apis::FileResource> remote_entries; |
| 415 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 415 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
| 416 fake_drive_service_helper_->ListFilesInFolder( | 416 fake_drive_service_helper_->ListFilesInFolder( |
| 417 sync_root_folder_id, &remote_entries)); | 417 sync_root_folder_id, &remote_entries)); |
| 418 std::map<std::string, const google_apis::ResourceEntry*> app_root_by_title; | 418 std::map<std::string, const google_apis::FileResource*> app_root_by_title; |
| 419 for (ScopedVector<google_apis::ResourceEntry>::iterator itr = | 419 for (ScopedVector<google_apis::FileResource>::iterator itr = |
| 420 remote_entries.begin(); | 420 remote_entries.begin(); |
| 421 itr != remote_entries.end(); | 421 itr != remote_entries.end(); |
| 422 ++itr) { | 422 ++itr) { |
| 423 const google_apis::ResourceEntry& remote_entry = **itr; | 423 const google_apis::FileResource& remote_entry = **itr; |
| 424 EXPECT_FALSE(ContainsKey(app_root_by_title, remote_entry.title())); | 424 EXPECT_FALSE(ContainsKey(app_root_by_title, remote_entry.title())); |
| 425 app_root_by_title[remote_entry.title()] = *itr; | 425 app_root_by_title[remote_entry.title()] = *itr; |
| 426 } | 426 } |
| 427 | 427 |
| 428 for (std::map<std::string, CannedSyncableFileSystem*>::const_iterator itr = | 428 for (std::map<std::string, CannedSyncableFileSystem*>::const_iterator itr = |
| 429 file_systems_.begin(); | 429 file_systems_.begin(); |
| 430 itr != file_systems_.end(); ++itr) { | 430 itr != file_systems_.end(); ++itr) { |
| 431 const std::string& app_id = itr->first; | 431 const std::string& app_id = itr->first; |
| 432 SCOPED_TRACE(testing::Message() << "Verifying app: " << app_id); | 432 SCOPED_TRACE(testing::Message() << "Verifying app: " << app_id); |
| 433 CannedSyncableFileSystem* file_system = itr->second; | 433 CannedSyncableFileSystem* file_system = itr->second; |
| 434 ASSERT_TRUE(ContainsKey(app_root_by_title, app_id)); | 434 ASSERT_TRUE(ContainsKey(app_root_by_title, app_id)); |
| 435 VerifyConsistencyForFolder( | 435 VerifyConsistencyForFolder( |
| 436 app_id, base::FilePath(), | 436 app_id, base::FilePath(), |
| 437 app_root_by_title[app_id]->resource_id(), | 437 app_root_by_title[app_id]->file_id(), |
| 438 file_system); | 438 file_system); |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 | 441 |
| 442 void VerifyConsistencyForFolder(const std::string& app_id, | 442 void VerifyConsistencyForFolder(const std::string& app_id, |
| 443 const base::FilePath& path, | 443 const base::FilePath& path, |
| 444 const std::string& folder_id, | 444 const std::string& folder_id, |
| 445 CannedSyncableFileSystem* file_system) { | 445 CannedSyncableFileSystem* file_system) { |
| 446 SCOPED_TRACE(testing::Message() << "Verifying folder: " << path.value()); | 446 SCOPED_TRACE(testing::Message() << "Verifying folder: " << path.value()); |
| 447 | 447 |
| 448 ScopedVector<google_apis::ResourceEntry> remote_entries; | 448 ScopedVector<google_apis::FileResource> remote_entries; |
| 449 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 449 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
| 450 fake_drive_service_helper_->ListFilesInFolder( | 450 fake_drive_service_helper_->ListFilesInFolder( |
| 451 folder_id, &remote_entries)); | 451 folder_id, &remote_entries)); |
| 452 std::map<std::string, const google_apis::ResourceEntry*> | 452 std::map<std::string, const google_apis::FileResource*> |
| 453 remote_entry_by_title; | 453 remote_entry_by_title; |
| 454 for (size_t i = 0; i < remote_entries.size(); ++i) { | 454 for (size_t i = 0; i < remote_entries.size(); ++i) { |
| 455 google_apis::ResourceEntry* remote_entry = remote_entries[i]; | 455 google_apis::FileResource* remote_entry = remote_entries[i]; |
| 456 EXPECT_FALSE(ContainsKey(remote_entry_by_title, remote_entry->title())) | 456 EXPECT_FALSE(ContainsKey(remote_entry_by_title, remote_entry->title())) |
| 457 << "title: " << remote_entry->title(); | 457 << "title: " << remote_entry->title(); |
| 458 remote_entry_by_title[remote_entry->title()] = remote_entry; | 458 remote_entry_by_title[remote_entry->title()] = remote_entry; |
| 459 } | 459 } |
| 460 | 460 |
| 461 storage::FileSystemURL url(CreateURL(app_id, path)); | 461 storage::FileSystemURL url(CreateURL(app_id, path)); |
| 462 FileEntryList local_entries; | 462 FileEntryList local_entries; |
| 463 EXPECT_EQ(base::File::FILE_OK, | 463 EXPECT_EQ(base::File::FILE_OK, |
| 464 file_system->ReadDirectory(url, &local_entries)); | 464 file_system->ReadDirectory(url, &local_entries)); |
| 465 for (FileEntryList::iterator itr = local_entries.begin(); | 465 for (FileEntryList::iterator itr = local_entries.begin(); |
| 466 itr != local_entries.end(); | 466 itr != local_entries.end(); |
| 467 ++itr) { | 467 ++itr) { |
| 468 const storage::DirectoryEntry& local_entry = *itr; | 468 const storage::DirectoryEntry& local_entry = *itr; |
| 469 storage::FileSystemURL entry_url( | 469 storage::FileSystemURL entry_url( |
| 470 CreateURL(app_id, path.Append(local_entry.name))); | 470 CreateURL(app_id, path.Append(local_entry.name))); |
| 471 std::string title = | 471 std::string title = |
| 472 storage::VirtualPath::BaseName(entry_url.path()).AsUTF8Unsafe(); | 472 storage::VirtualPath::BaseName(entry_url.path()).AsUTF8Unsafe(); |
| 473 SCOPED_TRACE(testing::Message() << "Verifying entry: " << title); | 473 SCOPED_TRACE(testing::Message() << "Verifying entry: " << title); |
| 474 | 474 |
| 475 ASSERT_TRUE(ContainsKey(remote_entry_by_title, title)); | 475 ASSERT_TRUE(ContainsKey(remote_entry_by_title, title)); |
| 476 const google_apis::ResourceEntry& remote_entry = | 476 const google_apis::FileResource& remote_entry = |
| 477 *remote_entry_by_title[title]; | 477 *remote_entry_by_title[title]; |
| 478 if (local_entry.is_directory) { | 478 if (local_entry.is_directory) { |
| 479 ASSERT_TRUE(remote_entry.is_folder()); | 479 ASSERT_TRUE(remote_entry.IsDirectory()); |
| 480 VerifyConsistencyForFolder(app_id, entry_url.path(), | 480 VerifyConsistencyForFolder(app_id, entry_url.path(), |
| 481 remote_entry.resource_id(), | 481 remote_entry.file_id(), |
| 482 file_system); | 482 file_system); |
| 483 } else { | 483 } else { |
| 484 ASSERT_TRUE(remote_entry.is_file()); | 484 ASSERT_FALSE(remote_entry.IsDirectory()); |
| 485 VerifyConsistencyForFile(app_id, entry_url.path(), | 485 VerifyConsistencyForFile(app_id, entry_url.path(), |
| 486 remote_entry.resource_id(), | 486 remote_entry.file_id(), |
| 487 file_system); | 487 file_system); |
| 488 } | 488 } |
| 489 remote_entry_by_title.erase(title); | 489 remote_entry_by_title.erase(title); |
| 490 } | 490 } |
| 491 | 491 |
| 492 EXPECT_TRUE(remote_entry_by_title.empty()); | 492 EXPECT_TRUE(remote_entry_by_title.empty()); |
| 493 } | 493 } |
| 494 | 494 |
| 495 void VerifyConsistencyForFile(const std::string& app_id, | 495 void VerifyConsistencyForFile(const std::string& app_id, |
| 496 const base::FilePath& path, | 496 const base::FilePath& path, |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 | 1720 |
| 1721 EXPECT_EQ(1u, CountApp()); | 1721 EXPECT_EQ(1u, CountApp()); |
| 1722 EXPECT_EQ(1u, CountLocalFile(app_id)); | 1722 EXPECT_EQ(1u, CountLocalFile(app_id)); |
| 1723 | 1723 |
| 1724 EXPECT_EQ(2u, CountMetadata()); | 1724 EXPECT_EQ(2u, CountMetadata()); |
| 1725 EXPECT_EQ(2u, CountTracker()); | 1725 EXPECT_EQ(2u, CountTracker()); |
| 1726 } | 1726 } |
| 1727 | 1727 |
| 1728 } // namespace drive_backend | 1728 } // namespace drive_backend |
| 1729 } // namespace sync_file_system | 1729 } // namespace sync_file_system |
| OLD | NEW |