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 "components/drive/chromeos/resource_metadata.h" | 5 #include "components/drive/chromeos/resource_metadata.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 namespace drive { | 26 namespace drive { |
27 namespace internal { | 27 namespace internal { |
28 namespace { | 28 namespace { |
29 | 29 |
30 // The changestamp of the resource metadata used in | 30 // The changestamp of the resource metadata used in |
31 // ResourceMetadataTest. | 31 // ResourceMetadataTest. |
32 const int64_t kTestChangestamp = 100; | 32 const int64_t kTestChangestamp = 100; |
33 | 33 |
| 34 const char kTeamDriveId[] = "TEAM_DRIVE_ID"; |
| 35 const char kTeamDriveName[] = "Name of a Team Drive"; |
| 36 const char kTeamDriveName2[] = "New Name of a Team Drive"; |
| 37 |
34 // Returns the sorted base names from |entries|. | 38 // Returns the sorted base names from |entries|. |
35 std::vector<std::string> GetSortedBaseNames( | 39 std::vector<std::string> GetSortedBaseNames( |
36 const ResourceEntryVector& entries) { | 40 const ResourceEntryVector& entries) { |
37 std::vector<std::string> base_names; | 41 std::vector<std::string> base_names; |
38 for (size_t i = 0; i < entries.size(); ++i) | 42 for (size_t i = 0; i < entries.size(); ++i) |
39 base_names.push_back(entries[i].base_name()); | 43 base_names.push_back(entries[i].base_name()); |
40 std::sort(base_names.begin(), base_names.end()); | 44 std::sort(base_names.begin(), base_names.end()); |
41 | 45 |
42 return base_names; | 46 return base_names; |
43 } | 47 } |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 dir3_local_id, &entry)); | 519 dir3_local_id, &entry)); |
516 | 520 |
517 // Remove unknown local_id using RemoveEntry. | 521 // Remove unknown local_id using RemoveEntry. |
518 EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->RemoveEntry("foo")); | 522 EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->RemoveEntry("foo")); |
519 | 523 |
520 // Try removing root. This should fail. | 524 // Try removing root. This should fail. |
521 EXPECT_EQ(FILE_ERROR_ACCESS_DENIED, resource_metadata_->RemoveEntry( | 525 EXPECT_EQ(FILE_ERROR_ACCESS_DENIED, resource_metadata_->RemoveEntry( |
522 util::kDriveGrandRootLocalId)); | 526 util::kDriveGrandRootLocalId)); |
523 } | 527 } |
524 | 528 |
| 529 TEST_F(ResourceMetadataTest, AddTeamDrive) { |
| 530 ResourceEntry entry; |
| 531 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 532 resource_metadata_->GetResourceEntryById(kTeamDriveId, &entry)); |
| 533 EXPECT_EQ(FILE_ERROR_OK, |
| 534 resource_metadata_->AddTeamDrive(kTeamDriveId, kTeamDriveName)); |
| 535 EXPECT_EQ(FILE_ERROR_OK, |
| 536 resource_metadata_->GetResourceEntryById(kTeamDriveId, &entry)); |
| 537 EXPECT_EQ(kTeamDriveName, entry.base_name()); |
| 538 } |
| 539 |
| 540 TEST_F(ResourceMetadataTest, RefreshTeamDrive) { |
| 541 ResourceEntry entry; |
| 542 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 543 resource_metadata_->GetResourceEntryById(kTeamDriveId, &entry)); |
| 544 EXPECT_EQ(FILE_ERROR_OK, |
| 545 resource_metadata_->AddTeamDrive(kTeamDriveId, kTeamDriveName)); |
| 546 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->RefreshTeamDrive( |
| 547 kTeamDriveId, kTeamDriveName2)); |
| 548 EXPECT_EQ(FILE_ERROR_OK, |
| 549 resource_metadata_->GetResourceEntryById(kTeamDriveId, &entry)); |
| 550 EXPECT_EQ(kTeamDriveName2, entry.base_name()); |
| 551 } |
| 552 |
525 TEST_F(ResourceMetadataTest, GetResourceEntryById_RootDirectory) { | 553 TEST_F(ResourceMetadataTest, GetResourceEntryById_RootDirectory) { |
526 // Look up the root directory by its ID. | 554 // Look up the root directory by its ID. |
527 ResourceEntry entry; | 555 ResourceEntry entry; |
528 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById( | 556 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById( |
529 util::kDriveGrandRootLocalId, &entry)); | 557 util::kDriveGrandRootLocalId, &entry)); |
530 EXPECT_EQ("drive", entry.base_name()); | 558 EXPECT_EQ("drive", entry.base_name()); |
531 } | 559 } |
532 | 560 |
533 TEST_F(ResourceMetadataTest, GetResourceEntryById) { | 561 TEST_F(ResourceMetadataTest, GetResourceEntryById) { |
534 // Get file4 by path. | 562 // Get file4 by path. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 | 731 |
704 // The "trash" directory should be empty. | 732 // The "trash" directory should be empty. |
705 ASSERT_EQ(FILE_ERROR_OK, | 733 ASSERT_EQ(FILE_ERROR_OK, |
706 resource_metadata_->ReadDirectoryByPath( | 734 resource_metadata_->ReadDirectoryByPath( |
707 base::FilePath::FromUTF8Unsafe("drive/trash"), &entries)); | 735 base::FilePath::FromUTF8Unsafe("drive/trash"), &entries)); |
708 EXPECT_TRUE(entries.empty()); | 736 EXPECT_TRUE(entries.empty()); |
709 } | 737 } |
710 | 738 |
711 } // namespace internal | 739 } // namespace internal |
712 } // namespace drive | 740 } // namespace drive |
OLD | NEW |