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 |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/stl_util.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
16 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" | 17 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" |
17 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
h" | 18 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
h" |
18 #include "chrome/browser/sync_file_system/drive_backend/fake_drive_service_helpe
r.h" | 19 #include "chrome/browser/sync_file_system/drive_backend/fake_drive_service_helpe
r.h" |
19 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 20 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
20 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" | 21 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" |
21 #include "chrome/browser/sync_file_system/drive_backend/sync_engine.h" | 22 #include "chrome/browser/sync_file_system/drive_backend/sync_engine.h" |
22 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" | 23 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" |
23 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" | 24 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" |
24 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" | 25 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 std::string sync_root_folder_id; | 406 std::string sync_root_folder_id; |
406 google_apis::DriveApiErrorCode error = | 407 google_apis::DriveApiErrorCode error = |
407 fake_drive_service_helper_->GetSyncRootFolderID(&sync_root_folder_id); | 408 fake_drive_service_helper_->GetSyncRootFolderID(&sync_root_folder_id); |
408 if (sync_root_folder_id.empty()) { | 409 if (sync_root_folder_id.empty()) { |
409 EXPECT_EQ(google_apis::HTTP_NOT_FOUND, error); | 410 EXPECT_EQ(google_apis::HTTP_NOT_FOUND, error); |
410 EXPECT_TRUE(file_systems_.empty()); | 411 EXPECT_TRUE(file_systems_.empty()); |
411 return; | 412 return; |
412 } | 413 } |
413 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); | 414 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); |
414 | 415 |
415 ScopedVector<google_apis::FileResource> remote_entries; | 416 std::vector<std::unique_ptr<google_apis::FileResource>> remote_entries; |
416 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 417 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
417 fake_drive_service_helper_->ListFilesInFolder( | 418 fake_drive_service_helper_->ListFilesInFolder( |
418 sync_root_folder_id, &remote_entries)); | 419 sync_root_folder_id, &remote_entries)); |
419 std::map<std::string, const google_apis::FileResource*> app_root_by_title; | 420 std::map<std::string, const google_apis::FileResource*> app_root_by_title; |
420 for (ScopedVector<google_apis::FileResource>::iterator itr = | 421 for (const auto& remote_entry : remote_entries) { |
421 remote_entries.begin(); | 422 EXPECT_FALSE(base::ContainsKey(app_root_by_title, remote_entry->title())); |
422 itr != remote_entries.end(); | 423 app_root_by_title[remote_entry->title()] = remote_entry.get(); |
423 ++itr) { | |
424 const google_apis::FileResource& remote_entry = **itr; | |
425 EXPECT_FALSE(base::ContainsKey(app_root_by_title, remote_entry.title())); | |
426 app_root_by_title[remote_entry.title()] = *itr; | |
427 } | 424 } |
428 | 425 |
429 for (std::map<std::string, CannedSyncableFileSystem*>::const_iterator itr = | 426 for (std::map<std::string, CannedSyncableFileSystem*>::const_iterator itr = |
430 file_systems_.begin(); | 427 file_systems_.begin(); |
431 itr != file_systems_.end(); ++itr) { | 428 itr != file_systems_.end(); ++itr) { |
432 const std::string& app_id = itr->first; | 429 const std::string& app_id = itr->first; |
433 SCOPED_TRACE(testing::Message() << "Verifying app: " << app_id); | 430 SCOPED_TRACE(testing::Message() << "Verifying app: " << app_id); |
434 CannedSyncableFileSystem* file_system = itr->second; | 431 CannedSyncableFileSystem* file_system = itr->second; |
435 ASSERT_TRUE(base::ContainsKey(app_root_by_title, app_id)); | 432 ASSERT_TRUE(base::ContainsKey(app_root_by_title, app_id)); |
436 VerifyConsistencyForFolder( | 433 VerifyConsistencyForFolder( |
437 app_id, base::FilePath(), | 434 app_id, base::FilePath(), |
438 app_root_by_title[app_id]->file_id(), | 435 app_root_by_title[app_id]->file_id(), |
439 file_system); | 436 file_system); |
440 } | 437 } |
441 } | 438 } |
442 | 439 |
443 void VerifyConsistencyForFolder(const std::string& app_id, | 440 void VerifyConsistencyForFolder(const std::string& app_id, |
444 const base::FilePath& path, | 441 const base::FilePath& path, |
445 const std::string& folder_id, | 442 const std::string& folder_id, |
446 CannedSyncableFileSystem* file_system) { | 443 CannedSyncableFileSystem* file_system) { |
447 SCOPED_TRACE(testing::Message() << "Verifying folder: " << path.value()); | 444 SCOPED_TRACE(testing::Message() << "Verifying folder: " << path.value()); |
448 | 445 |
449 ScopedVector<google_apis::FileResource> remote_entries; | 446 std::vector<std::unique_ptr<google_apis::FileResource>> remote_entries; |
450 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 447 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
451 fake_drive_service_helper_->ListFilesInFolder( | 448 fake_drive_service_helper_->ListFilesInFolder( |
452 folder_id, &remote_entries)); | 449 folder_id, &remote_entries)); |
453 std::map<std::string, const google_apis::FileResource*> | 450 std::map<std::string, const google_apis::FileResource*> |
454 remote_entry_by_title; | 451 remote_entry_by_title; |
455 for (size_t i = 0; i < remote_entries.size(); ++i) { | 452 for (size_t i = 0; i < remote_entries.size(); ++i) { |
456 google_apis::FileResource* remote_entry = remote_entries[i]; | 453 google_apis::FileResource* remote_entry = remote_entries[i].get(); |
457 EXPECT_FALSE( | 454 EXPECT_FALSE( |
458 base::ContainsKey(remote_entry_by_title, remote_entry->title())) | 455 base::ContainsKey(remote_entry_by_title, remote_entry->title())) |
459 << "title: " << remote_entry->title(); | 456 << "title: " << remote_entry->title(); |
460 remote_entry_by_title[remote_entry->title()] = remote_entry; | 457 remote_entry_by_title[remote_entry->title()] = remote_entry; |
461 } | 458 } |
462 | 459 |
463 storage::FileSystemURL url(CreateURL(app_id, path)); | 460 storage::FileSystemURL url(CreateURL(app_id, path)); |
464 FileEntryList local_entries; | 461 FileEntryList local_entries; |
465 EXPECT_EQ(base::File::FILE_OK, | 462 EXPECT_EQ(base::File::FILE_OK, |
466 file_system->ReadDirectory(url, &local_entries)); | 463 file_system->ReadDirectory(url, &local_entries)); |
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 | 1719 |
1723 EXPECT_EQ(1u, CountApp()); | 1720 EXPECT_EQ(1u, CountApp()); |
1724 EXPECT_EQ(1u, CountLocalFile(app_id)); | 1721 EXPECT_EQ(1u, CountLocalFile(app_id)); |
1725 | 1722 |
1726 EXPECT_EQ(2u, CountMetadata()); | 1723 EXPECT_EQ(2u, CountMetadata()); |
1727 EXPECT_EQ(2u, CountTracker()); | 1724 EXPECT_EQ(2u, CountTracker()); |
1728 } | 1725 } |
1729 | 1726 |
1730 } // namespace drive_backend | 1727 } // namespace drive_backend |
1731 } // namespace sync_file_system | 1728 } // namespace sync_file_system |
OLD | NEW |