| OLD | NEW |
| 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/resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 417 |
| 418 // Cannot refresh root. | 418 // Cannot refresh root. |
| 419 dir_entry.Clear(); | 419 dir_entry.Clear(); |
| 420 dir_entry.set_local_id(util::kDriveGrandRootLocalId); | 420 dir_entry.set_local_id(util::kDriveGrandRootLocalId); |
| 421 dir_entry.set_title("new-root-name"); | 421 dir_entry.set_title("new-root-name"); |
| 422 dir_entry.set_parent_local_id(dir3_id); | 422 dir_entry.set_parent_local_id(dir3_id); |
| 423 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, | 423 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, |
| 424 resource_metadata_->RefreshEntry(dir_entry)); | 424 resource_metadata_->RefreshEntry(dir_entry)); |
| 425 } | 425 } |
| 426 | 426 |
| 427 TEST_F(ResourceMetadataTest, RefreshEntry_ResourceIDCheck) { |
| 428 // Get an entry with a non-empty resource ID. |
| 429 ResourceEntry entry; |
| 430 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath( |
| 431 base::FilePath::FromUTF8Unsafe("drive/root/dir1"), &entry)); |
| 432 EXPECT_FALSE(entry.resource_id().empty()); |
| 433 |
| 434 // Add a new entry with an empty resource ID. |
| 435 ResourceEntry new_entry; |
| 436 new_entry.set_parent_local_id(entry.local_id()); |
| 437 new_entry.set_title("new entry"); |
| 438 std::string local_id; |
| 439 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(new_entry, &local_id)); |
| 440 |
| 441 // Try to refresh the new entry with a used resource ID. |
| 442 new_entry.set_local_id(local_id); |
| 443 new_entry.set_resource_id(entry.resource_id()); |
| 444 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, |
| 445 resource_metadata_->RefreshEntry(new_entry)); |
| 446 } |
| 447 |
| 427 TEST_F(ResourceMetadataTest, GetSubDirectoriesRecursively) { | 448 TEST_F(ResourceMetadataTest, GetSubDirectoriesRecursively) { |
| 428 std::set<base::FilePath> sub_directories; | 449 std::set<base::FilePath> sub_directories; |
| 429 | 450 |
| 430 // file9: not a directory, so no children. | 451 // file9: not a directory, so no children. |
| 431 std::string local_id; | 452 std::string local_id; |
| 432 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath( | 453 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath( |
| 433 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"), &local_id)); | 454 base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"), &local_id)); |
| 434 resource_metadata_->GetSubDirectoriesRecursively(local_id, &sub_directories); | 455 resource_metadata_->GetSubDirectoriesRecursively(local_id, &sub_directories); |
| 435 EXPECT_TRUE(sub_directories.empty()); | 456 EXPECT_TRUE(sub_directories.empty()); |
| 436 | 457 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 759 |
| 739 // The "trash" directory should be empty. | 760 // The "trash" directory should be empty. |
| 740 ASSERT_EQ(FILE_ERROR_OK, | 761 ASSERT_EQ(FILE_ERROR_OK, |
| 741 resource_metadata_->ReadDirectoryByPath( | 762 resource_metadata_->ReadDirectoryByPath( |
| 742 base::FilePath::FromUTF8Unsafe("drive/trash"), &entries)); | 763 base::FilePath::FromUTF8Unsafe("drive/trash"), &entries)); |
| 743 EXPECT_TRUE(entries.empty()); | 764 EXPECT_TRUE(entries.empty()); |
| 744 } | 765 } |
| 745 | 766 |
| 746 } // namespace internal | 767 } // namespace internal |
| 747 } // namespace drive | 768 } // namespace drive |
| OLD | NEW |