| 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/drive_resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // See drive.proto for the difference between the two URLs. | 27 // See drive.proto for the difference between the two URLs. |
| 28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; | 28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; |
| 29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; | 29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; |
| 30 | 30 |
| 31 // Callback for DriveResourceMetadata::InitFromDB. | 31 // Callback for DriveResourceMetadata::InitFromDB. |
| 32 void InitFromDBCallback(DriveFileError expected_error, | 32 void InitFromDBCallback(DriveFileError expected_error, |
| 33 DriveFileError actual_error) { | 33 DriveFileError actual_error) { |
| 34 EXPECT_EQ(expected_error, actual_error); | 34 EXPECT_EQ(expected_error, actual_error); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void OnGetChangedDirectories(std::set<FilePath>* out_changed_directories, |
| 38 const std::set<FilePath>& in_changed_directories) { |
| 39 *out_changed_directories = in_changed_directories; |
| 40 } |
| 41 |
| 37 } // namespace | 42 } // namespace |
| 38 | 43 |
| 39 class DriveResourceMetadataTest : public testing::Test { | 44 class DriveResourceMetadataTest : public testing::Test { |
| 40 public: | 45 public: |
| 41 DriveResourceMetadataTest(); | 46 DriveResourceMetadataTest(); |
| 42 | 47 |
| 43 protected: | 48 protected: |
| 49 DriveEntryProto CreateDriveEntryProto(int sequence_id, |
| 50 bool is_directory, |
| 51 const std::string& parent_resource_id); |
| 52 |
| 44 DriveResourceMetadata resource_metadata_; | 53 DriveResourceMetadata resource_metadata_; |
| 45 | 54 |
| 46 private: | 55 private: |
| 47 // Creates the following files/directories | 56 // Creates the following files/directories |
| 48 // drive/dir1/ | 57 // drive/dir1/ |
| 49 // drive/dir2/ | 58 // drive/dir2/ |
| 50 // drive/dir1/dir3/ | 59 // drive/dir1/dir3/ |
| 51 // drive/dir1/file4 | 60 // drive/dir1/file4 |
| 52 // drive/dir1/file5 | 61 // drive/dir1/file5 |
| 53 // drive/dir2/file6 | 62 // drive/dir2/file6 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 AddFile(dir1, sequence_id++); | 95 AddFile(dir1, sequence_id++); |
| 87 | 96 |
| 88 AddFile(dir2, sequence_id++); | 97 AddFile(dir2, sequence_id++); |
| 89 AddFile(dir2, sequence_id++); | 98 AddFile(dir2, sequence_id++); |
| 90 AddFile(dir2, sequence_id++); | 99 AddFile(dir2, sequence_id++); |
| 91 | 100 |
| 92 AddFile(dir3, sequence_id++); | 101 AddFile(dir3, sequence_id++); |
| 93 AddFile(dir3, sequence_id++); | 102 AddFile(dir3, sequence_id++); |
| 94 } | 103 } |
| 95 | 104 |
| 105 DriveEntryProto DriveResourceMetadataTest::CreateDriveEntryProto( |
| 106 int sequence_id, |
| 107 bool is_directory, |
| 108 const std::string& parent_resource_id) { |
| 109 DriveEntryProto entry_proto; |
| 110 const std::string sequence_id_str = base::IntToString(sequence_id); |
| 111 const std::string title = (is_directory ? "dir" : "file") + |
| 112 sequence_id_str; |
| 113 const std::string resource_id = "resource_id:" + title; |
| 114 entry_proto.set_title(title); |
| 115 entry_proto.set_resource_id(resource_id); |
| 116 entry_proto.set_parent_resource_id(parent_resource_id); |
| 117 |
| 118 PlatformFileInfoProto* file_info = entry_proto.mutable_file_info(); |
| 119 file_info->set_is_directory(is_directory); |
| 120 |
| 121 if (!is_directory) { |
| 122 DriveFileSpecificInfo* file_specific_info = |
| 123 entry_proto.mutable_file_specific_info(); |
| 124 file_info->set_size(sequence_id * 1024); |
| 125 file_specific_info->set_file_md5(std::string("md5:") + title); |
| 126 } |
| 127 return entry_proto; |
| 128 } |
| 129 |
| 96 DriveDirectory* DriveResourceMetadataTest::AddDirectory(DriveDirectory* parent, | 130 DriveDirectory* DriveResourceMetadataTest::AddDirectory(DriveDirectory* parent, |
| 97 int sequence_id) { | 131 int sequence_id) { |
| 98 scoped_ptr<DriveDirectory> dir = resource_metadata_.CreateDriveDirectory(); | 132 scoped_ptr<DriveDirectory> dir = resource_metadata_.CreateDriveDirectory(); |
| 99 const std::string dir_name = "dir" + base::IntToString(sequence_id); | 133 const std::string dir_name = "dir" + base::IntToString(sequence_id); |
| 100 const std::string resource_id = std::string("dir_resource_id:") + dir_name; | 134 const std::string resource_id = std::string("resource_id:") + dir_name; |
| 101 dir->set_title(dir_name); | 135 dir->set_title(dir_name); |
| 102 dir->set_resource_id(resource_id); | 136 dir->set_resource_id(resource_id); |
| 103 | 137 |
| 104 parent->AddEntry(dir.get()); | 138 parent->AddEntry(dir.get()); |
| 105 | 139 |
| 106 return dir.release(); | 140 return dir.release(); |
| 107 } | 141 } |
| 108 | 142 |
| 109 DriveFile* DriveResourceMetadataTest::AddFile(DriveDirectory* parent, | 143 DriveFile* DriveResourceMetadataTest::AddFile(DriveDirectory* parent, |
| 110 int sequence_id) { | 144 int sequence_id) { |
| 111 scoped_ptr<DriveFile> file = resource_metadata_.CreateDriveFile(); | 145 scoped_ptr<DriveFile> file = resource_metadata_.CreateDriveFile(); |
| 112 const std::string title = "file" + base::IntToString(sequence_id); | 146 const std::string title = "file" + base::IntToString(sequence_id); |
| 113 const std::string resource_id = std::string("file_resource_id:") + title; | 147 const std::string resource_id = std::string("resource_id:") + title; |
| 114 file->set_title(title); | 148 file->set_title(title); |
| 115 file->set_resource_id(resource_id); | 149 file->set_resource_id(resource_id); |
| 116 file->set_file_md5(std::string("file_md5:") + title); | 150 file->set_file_md5(std::string("md5:") + title); |
| 117 | 151 |
| 118 parent->AddEntry(file.get()); | 152 parent->AddEntry(file.get()); |
| 119 | 153 |
| 120 return file.release(); | 154 return file.release(); |
| 121 } | 155 } |
| 122 | 156 |
| 123 TEST_F(DriveResourceMetadataTest, VersionCheck) { | 157 TEST_F(DriveResourceMetadataTest, VersionCheck) { |
| 124 // Set up the root directory. | 158 // Set up the root directory. |
| 125 DriveRootDirectoryProto proto; | 159 DriveRootDirectoryProto proto; |
| 126 DriveEntryProto* mutable_entry = | 160 DriveEntryProto* mutable_entry = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 204 |
| 171 EXPECT_EQ(kWAPIRootDirectoryResourceId, entry->resource_id()); | 205 EXPECT_EQ(kWAPIRootDirectoryResourceId, entry->resource_id()); |
| 172 } | 206 } |
| 173 | 207 |
| 174 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId) { | 208 TEST_F(DriveResourceMetadataTest, GetEntryInfoByResourceId) { |
| 175 // Confirm that an existing file is found. | 209 // Confirm that an existing file is found. |
| 176 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 210 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 177 FilePath drive_file_path; | 211 FilePath drive_file_path; |
| 178 scoped_ptr<DriveEntryProto> entry_proto; | 212 scoped_ptr<DriveEntryProto> entry_proto; |
| 179 resource_metadata_.GetEntryInfoByResourceId( | 213 resource_metadata_.GetEntryInfoByResourceId( |
| 180 "file_resource_id:file4", | 214 "resource_id:file4", |
| 181 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, | 215 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 182 &error, &drive_file_path, &entry_proto)); | 216 &error, &drive_file_path, &entry_proto)); |
| 183 google_apis::test_util::RunBlockingPoolTask(); | 217 google_apis::test_util::RunBlockingPoolTask(); |
| 184 EXPECT_EQ(DRIVE_FILE_OK, error); | 218 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 185 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path); | 219 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path); |
| 186 ASSERT_TRUE(entry_proto.get()); | 220 ASSERT_TRUE(entry_proto.get()); |
| 187 EXPECT_EQ("file4", entry_proto->base_name()); | 221 EXPECT_EQ("file4", entry_proto->base_name()); |
| 188 | 222 |
| 189 // Confirm that a non existing file is not found. | 223 // Confirm that a non existing file is not found. |
| 190 error = DRIVE_FILE_ERROR_FAILED; | 224 error = DRIVE_FILE_ERROR_FAILED; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 google_apis::test_util::RunBlockingPoolTask(); | 408 google_apis::test_util::RunBlockingPoolTask(); |
| 375 EXPECT_EQ(DRIVE_FILE_OK, error); | 409 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 376 ASSERT_TRUE(entries.get()); | 410 ASSERT_TRUE(entries.get()); |
| 377 ASSERT_EQ(3U, entries->size()); | 411 ASSERT_EQ(3U, entries->size()); |
| 378 } | 412 } |
| 379 | 413 |
| 380 TEST_F(DriveResourceMetadataTest, RemoveEntryFromParent) { | 414 TEST_F(DriveResourceMetadataTest, RemoveEntryFromParent) { |
| 381 // Make sure file9 is found. | 415 // Make sure file9 is found. |
| 382 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 416 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 383 FilePath drive_file_path; | 417 FilePath drive_file_path; |
| 384 const std::string file9_resource_id = "file_resource_id:file9"; | 418 const std::string file9_resource_id = "resource_id:file9"; |
| 385 scoped_ptr<DriveEntryProto> entry_proto; | 419 scoped_ptr<DriveEntryProto> entry_proto; |
| 386 resource_metadata_.GetEntryInfoByResourceId( | 420 resource_metadata_.GetEntryInfoByResourceId( |
| 387 file9_resource_id, | 421 file9_resource_id, |
| 388 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, | 422 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 389 &error, &drive_file_path, &entry_proto)); | 423 &error, &drive_file_path, &entry_proto)); |
| 390 google_apis::test_util::RunBlockingPoolTask(); | 424 google_apis::test_util::RunBlockingPoolTask(); |
| 391 EXPECT_EQ(DRIVE_FILE_OK, error); | 425 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 392 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"), drive_file_path); | 426 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"), drive_file_path); |
| 393 ASSERT_TRUE(entry_proto.get()); | 427 ASSERT_TRUE(entry_proto.get()); |
| 394 EXPECT_EQ("file9", entry_proto->base_name()); | 428 EXPECT_EQ("file9", entry_proto->base_name()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 405 // file9 should no longer exist. | 439 // file9 should no longer exist. |
| 406 resource_metadata_.GetEntryInfoByResourceId( | 440 resource_metadata_.GetEntryInfoByResourceId( |
| 407 file9_resource_id, | 441 file9_resource_id, |
| 408 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, | 442 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 409 &error, &drive_file_path, &entry_proto)); | 443 &error, &drive_file_path, &entry_proto)); |
| 410 google_apis::test_util::RunBlockingPoolTask(); | 444 google_apis::test_util::RunBlockingPoolTask(); |
| 411 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 445 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 412 EXPECT_FALSE(entry_proto.get()); | 446 EXPECT_FALSE(entry_proto.get()); |
| 413 | 447 |
| 414 // Look for dir3. | 448 // Look for dir3. |
| 415 const std::string dir3_resource_id = "dir_resource_id:dir3"; | 449 const std::string dir3_resource_id = "resource_id:dir3"; |
| 416 resource_metadata_.GetEntryInfoByResourceId( | 450 resource_metadata_.GetEntryInfoByResourceId( |
| 417 dir3_resource_id, | 451 dir3_resource_id, |
| 418 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, | 452 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 419 &error, &drive_file_path, &entry_proto)); | 453 &error, &drive_file_path, &entry_proto)); |
| 420 google_apis::test_util::RunBlockingPoolTask(); | 454 google_apis::test_util::RunBlockingPoolTask(); |
| 421 EXPECT_EQ(DRIVE_FILE_OK, error); | 455 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 422 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3"), drive_file_path); | 456 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3"), drive_file_path); |
| 423 ASSERT_TRUE(entry_proto.get()); | 457 ASSERT_TRUE(entry_proto.get()); |
| 424 EXPECT_EQ("dir3", entry_proto->base_name()); | 458 EXPECT_EQ("dir3", entry_proto->base_name()); |
| 425 | 459 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 FilePath::FromUTF8Unsafe("drive/dir2/file8"), | 502 FilePath::FromUTF8Unsafe("drive/dir2/file8"), |
| 469 FilePath::FromUTF8Unsafe("drive/dir1"), | 503 FilePath::FromUTF8Unsafe("drive/dir1"), |
| 470 base::Bind(&test_util::CopyResultsFromFileMoveCallback, | 504 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 471 &error, &drive_file_path)); | 505 &error, &drive_file_path)); |
| 472 google_apis::test_util::RunBlockingPoolTask(); | 506 google_apis::test_util::RunBlockingPoolTask(); |
| 473 EXPECT_EQ(DRIVE_FILE_OK, error); | 507 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 474 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file8"), drive_file_path); | 508 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file8"), drive_file_path); |
| 475 | 509 |
| 476 // Look up the entry by its resource id and make sure it really moved. | 510 // Look up the entry by its resource id and make sure it really moved. |
| 477 resource_metadata_.GetEntryInfoByResourceId( | 511 resource_metadata_.GetEntryInfoByResourceId( |
| 478 "file_resource_id:file8", | 512 "resource_id:file8", |
| 479 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, | 513 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 480 &error, &drive_file_path, &entry_proto)); | 514 &error, &drive_file_path, &entry_proto)); |
| 481 google_apis::test_util::RunBlockingPoolTask(); | 515 google_apis::test_util::RunBlockingPoolTask(); |
| 482 EXPECT_EQ(DRIVE_FILE_OK, error); | 516 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 483 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file8"), drive_file_path); | 517 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file8"), drive_file_path); |
| 484 | 518 |
| 485 // Move non-existent file to drive/dir1. This should fail. | 519 // Move non-existent file to drive/dir1. This should fail. |
| 486 resource_metadata_.MoveEntryToDirectory( | 520 resource_metadata_.MoveEntryToDirectory( |
| 487 FilePath::FromUTF8Unsafe("drive/dir2/file8"), | 521 FilePath::FromUTF8Unsafe("drive/dir2/file8"), |
| 488 FilePath::FromUTF8Unsafe("drive/dir1"), | 522 FilePath::FromUTF8Unsafe("drive/dir1"), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 FilePath::FromUTF8Unsafe("drive/file8"), | 561 FilePath::FromUTF8Unsafe("drive/file8"), |
| 528 FilePath::FromUTF8Unsafe("drive/dir2"), | 562 FilePath::FromUTF8Unsafe("drive/dir2"), |
| 529 base::Bind(&test_util::CopyResultsFromFileMoveCallback, | 563 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 530 &error, &drive_file_path)); | 564 &error, &drive_file_path)); |
| 531 google_apis::test_util::RunBlockingPoolTask(); | 565 google_apis::test_util::RunBlockingPoolTask(); |
| 532 EXPECT_EQ(DRIVE_FILE_OK, error); | 566 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 533 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file8"), drive_file_path); | 567 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file8"), drive_file_path); |
| 534 | 568 |
| 535 // Make sure file is still ok. | 569 // Make sure file is still ok. |
| 536 resource_metadata_.GetEntryInfoByResourceId( | 570 resource_metadata_.GetEntryInfoByResourceId( |
| 537 "file_resource_id:file8", | 571 "resource_id:file8", |
| 538 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, | 572 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 539 &error, &drive_file_path, &entry_proto)); | 573 &error, &drive_file_path, &entry_proto)); |
| 540 google_apis::test_util::RunBlockingPoolTask(); | 574 google_apis::test_util::RunBlockingPoolTask(); |
| 541 EXPECT_EQ(DRIVE_FILE_OK, error); | 575 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 542 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file8"), drive_file_path); | 576 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file8"), drive_file_path); |
| 543 } | 577 } |
| 544 | 578 |
| 545 TEST_F(DriveResourceMetadataTest, RenameEntry) { | 579 TEST_F(DriveResourceMetadataTest, RenameEntry) { |
| 546 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 580 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 547 FilePath drive_file_path; | 581 FilePath drive_file_path; |
| 548 scoped_ptr<DriveEntryProto> entry_proto; | 582 scoped_ptr<DriveEntryProto> entry_proto; |
| 549 | 583 |
| 550 // Rename file8 to file11. | 584 // Rename file8 to file11. |
| 551 resource_metadata_.RenameEntry( | 585 resource_metadata_.RenameEntry( |
| 552 FilePath::FromUTF8Unsafe("drive/dir2/file8"), | 586 FilePath::FromUTF8Unsafe("drive/dir2/file8"), |
| 553 "file11", | 587 "file11", |
| 554 base::Bind(&test_util::CopyResultsFromFileMoveCallback, | 588 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 555 &error, &drive_file_path)); | 589 &error, &drive_file_path)); |
| 556 google_apis::test_util::RunBlockingPoolTask(); | 590 google_apis::test_util::RunBlockingPoolTask(); |
| 557 EXPECT_EQ(DRIVE_FILE_OK, error); | 591 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 558 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file11"), drive_file_path); | 592 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file11"), drive_file_path); |
| 559 | 593 |
| 560 // Lookup the file by resource id to make sure the file actually got renamed. | 594 // Lookup the file by resource id to make sure the file actually got renamed. |
| 561 resource_metadata_.GetEntryInfoByResourceId( | 595 resource_metadata_.GetEntryInfoByResourceId( |
| 562 "file_resource_id:file8", | 596 "resource_id:file8", |
| 563 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, | 597 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 564 &error, &drive_file_path, &entry_proto)); | 598 &error, &drive_file_path, &entry_proto)); |
| 565 google_apis::test_util::RunBlockingPoolTask(); | 599 google_apis::test_util::RunBlockingPoolTask(); |
| 566 EXPECT_EQ(DRIVE_FILE_OK, error); | 600 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 567 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file11"), drive_file_path); | 601 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2/file11"), drive_file_path); |
| 568 | 602 |
| 569 // Rename to file7 to force a duplicate name. | 603 // Rename to file7 to force a duplicate name. |
| 570 resource_metadata_.RenameEntry( | 604 resource_metadata_.RenameEntry( |
| 571 FilePath::FromUTF8Unsafe("drive/dir2/file11"), | 605 FilePath::FromUTF8Unsafe("drive/dir2/file11"), |
| 572 "file7", | 606 "file7", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 590 resource_metadata_.RenameEntry( | 624 resource_metadata_.RenameEntry( |
| 591 FilePath::FromUTF8Unsafe("drive/dir2/file11"), | 625 FilePath::FromUTF8Unsafe("drive/dir2/file11"), |
| 592 "file11", | 626 "file11", |
| 593 base::Bind(&test_util::CopyResultsFromFileMoveCallback, | 627 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 594 &error, &drive_file_path)); | 628 &error, &drive_file_path)); |
| 595 google_apis::test_util::RunBlockingPoolTask(); | 629 google_apis::test_util::RunBlockingPoolTask(); |
| 596 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); | 630 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 597 EXPECT_EQ(FilePath(), drive_file_path); | 631 EXPECT_EQ(FilePath(), drive_file_path); |
| 598 } | 632 } |
| 599 | 633 |
| 634 TEST_F(DriveResourceMetadataTest, RefreshEntryProto) { |
| 635 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 636 FilePath drive_file_path; |
| 637 scoped_ptr<DriveEntryProto> entry_proto; |
| 638 |
| 639 // Get file9. |
| 640 resource_metadata_.GetEntryInfoByPath( |
| 641 FilePath::FromUTF8Unsafe("drive/dir1/dir3/file9"), |
| 642 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
| 643 &error, &entry_proto)); |
| 644 google_apis::test_util::RunBlockingPoolTask(); |
| 645 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 646 ASSERT_TRUE(entry_proto.get()); |
| 647 EXPECT_EQ("file9", entry_proto->base_name()); |
| 648 ASSERT_TRUE(entry_proto->has_file_specific_info()); |
| 649 EXPECT_EQ("md5:file9", entry_proto->file_specific_info().file_md5()); |
| 650 |
| 651 // Rename it and change the file size. |
| 652 DriveEntryProto file_entry_proto(*entry_proto); |
| 653 const std::string updated_md5("md5:updated"); |
| 654 file_entry_proto.mutable_file_specific_info()->set_file_md5(updated_md5); |
| 655 file_entry_proto.set_title("file100"); |
| 656 entry_proto.reset(); |
| 657 resource_metadata_.RefreshEntryProto( |
| 658 file_entry_proto, |
| 659 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 660 &error, &drive_file_path, &entry_proto)); |
| 661 google_apis::test_util::RunBlockingPoolTask(); |
| 662 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 663 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100"), |
| 664 drive_file_path); |
| 665 ASSERT_TRUE(entry_proto.get()); |
| 666 EXPECT_EQ("file100", entry_proto->base_name()); |
| 667 ASSERT_TRUE(entry_proto->has_file_specific_info()); |
| 668 EXPECT_EQ(updated_md5, entry_proto->file_specific_info().file_md5()); |
| 669 |
| 670 // Make sure we get the same thing from GetEntryInfoByPath. |
| 671 entry_proto.reset(); |
| 672 resource_metadata_.GetEntryInfoByPath( |
| 673 FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100"), |
| 674 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
| 675 &error, &entry_proto)); |
| 676 google_apis::test_util::RunBlockingPoolTask(); |
| 677 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 678 ASSERT_TRUE(entry_proto.get()); |
| 679 EXPECT_EQ("file100", entry_proto->base_name()); |
| 680 ASSERT_TRUE(entry_proto->has_file_specific_info()); |
| 681 EXPECT_EQ(updated_md5, entry_proto->file_specific_info().file_md5()); |
| 682 |
| 683 // Get dir2. |
| 684 entry_proto.reset(); |
| 685 resource_metadata_.GetEntryInfoByPath( |
| 686 FilePath::FromUTF8Unsafe("drive/dir2"), |
| 687 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
| 688 &error, &entry_proto)); |
| 689 google_apis::test_util::RunBlockingPoolTask(); |
| 690 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 691 ASSERT_TRUE(entry_proto.get()); |
| 692 EXPECT_EQ("dir2", entry_proto->base_name()); |
| 693 ASSERT_TRUE(entry_proto->file_info().is_directory()); |
| 694 |
| 695 // Change the name to dir100 and change the parent to drive/dir1/dir3. |
| 696 DriveEntryProto dir_entry_proto(*entry_proto); |
| 697 dir_entry_proto.set_title("dir100"); |
| 698 dir_entry_proto.set_parent_resource_id("resource_id:dir3"); |
| 699 entry_proto.reset(); |
| 700 resource_metadata_.RefreshEntryProto( |
| 701 dir_entry_proto, |
| 702 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
| 703 &error, &drive_file_path, &entry_proto)); |
| 704 google_apis::test_util::RunBlockingPoolTask(); |
| 705 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 706 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/dir100"), |
| 707 drive_file_path); |
| 708 ASSERT_TRUE(entry_proto.get()); |
| 709 EXPECT_EQ("dir100", entry_proto->base_name()); |
| 710 EXPECT_TRUE(entry_proto->file_info().is_directory()); |
| 711 EXPECT_EQ("resource_id:dir2", entry_proto->resource_id()); |
| 712 |
| 713 // Make sure the children have moved over. Test file6. |
| 714 entry_proto.reset(); |
| 715 resource_metadata_.GetEntryInfoByPath( |
| 716 FilePath::FromUTF8Unsafe("drive/dir1/dir3/dir100/file6"), |
| 717 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
| 718 &error, &entry_proto)); |
| 719 google_apis::test_util::RunBlockingPoolTask(); |
| 720 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 721 ASSERT_TRUE(entry_proto.get()); |
| 722 EXPECT_EQ("file6", entry_proto->base_name()); |
| 723 |
| 724 // Make sure dir2 no longer exists. |
| 725 resource_metadata_.GetEntryInfoByPath( |
| 726 FilePath::FromUTF8Unsafe("drive/dir2"), |
| 727 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
| 728 &error, &entry_proto)); |
| 729 google_apis::test_util::RunBlockingPoolTask(); |
| 730 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 731 EXPECT_FALSE(entry_proto.get()); |
| 732 } |
| 733 |
| 734 TEST_F(DriveResourceMetadataTest, AddEntryToParent) { |
| 735 int sequence_id = 100; |
| 736 DriveEntryProto file_entry_proto = CreateDriveEntryProto( |
| 737 sequence_id++, false, "resource_id:dir3"); |
| 738 |
| 739 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 740 FilePath drive_file_path; |
| 741 |
| 742 // Add to dir3. |
| 743 resource_metadata_.AddEntryToParent( |
| 744 file_entry_proto, |
| 745 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 746 &error, &drive_file_path)); |
| 747 google_apis::test_util::RunBlockingPoolTask(); |
| 748 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 749 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir3/file100"), |
| 750 drive_file_path); |
| 751 |
| 752 // Adds to root when parent resource id is not specified. |
| 753 DriveEntryProto file_entry_proto2 = CreateDriveEntryProto( |
| 754 sequence_id++, false, ""); |
| 755 |
| 756 resource_metadata_.AddEntryToParent( |
| 757 file_entry_proto2, |
| 758 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 759 &error, &drive_file_path)); |
| 760 google_apis::test_util::RunBlockingPoolTask(); |
| 761 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 762 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/file101"), drive_file_path); |
| 763 |
| 764 // Add a directory. |
| 765 DriveEntryProto dir_entry_proto = CreateDriveEntryProto( |
| 766 sequence_id++, true, "resource_id:dir1"); |
| 767 |
| 768 resource_metadata_.AddEntryToParent( |
| 769 dir_entry_proto, |
| 770 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 771 &error, &drive_file_path)); |
| 772 google_apis::test_util::RunBlockingPoolTask(); |
| 773 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 774 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/dir102"), drive_file_path); |
| 775 |
| 776 // Add to an invalid parent. |
| 777 DriveEntryProto file_entry_proto3 = CreateDriveEntryProto( |
| 778 sequence_id++, false, "resource_id:invalid"); |
| 779 |
| 780 resource_metadata_.AddEntryToParent( |
| 781 file_entry_proto3, |
| 782 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 783 &error, &drive_file_path)); |
| 784 google_apis::test_util::RunBlockingPoolTask(); |
| 785 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); |
| 786 } |
| 787 |
| 788 TEST_F(DriveResourceMetadataTest, GetChangedDirectories) { |
| 789 std::set<FilePath> changed_directories; |
| 790 |
| 791 // file9: only drive/dir1/dir3 is affected. |
| 792 resource_metadata_.GetChangedDirectories("resource_id:file9", |
| 793 base::Bind(&OnGetChangedDirectories, &changed_directories)); |
| 794 google_apis::test_util::RunBlockingPoolTask(); |
| 795 EXPECT_EQ(1u, changed_directories.size()); |
| 796 EXPECT_EQ(1u, changed_directories.count( |
| 797 FilePath::FromUTF8Unsafe("drive/dir1/dir3"))); |
| 798 |
| 799 // dir2: root and dir2 are affected. |
| 800 resource_metadata_.GetChangedDirectories("resource_id:dir2", |
| 801 base::Bind(&OnGetChangedDirectories, &changed_directories)); |
| 802 google_apis::test_util::RunBlockingPoolTask(); |
| 803 EXPECT_EQ(2u, changed_directories.size()); |
| 804 EXPECT_EQ(1u, changed_directories.count( |
| 805 FilePath::FromUTF8Unsafe("drive"))); |
| 806 EXPECT_EQ(1u, changed_directories.count( |
| 807 FilePath::FromUTF8Unsafe("drive/dir2"))); |
| 808 |
| 809 // dir1: root, dir1, and dir3 are affected. |
| 810 resource_metadata_.GetChangedDirectories("resource_id:dir1", |
| 811 base::Bind(&OnGetChangedDirectories, &changed_directories)); |
| 812 google_apis::test_util::RunBlockingPoolTask(); |
| 813 EXPECT_EQ(3u, changed_directories.size()); |
| 814 EXPECT_EQ(1u, changed_directories.count( |
| 815 FilePath::FromUTF8Unsafe("drive"))); |
| 816 EXPECT_EQ(1u, changed_directories.count( |
| 817 FilePath::FromUTF8Unsafe("drive/dir1"))); |
| 818 EXPECT_EQ(1u, changed_directories.count( |
| 819 FilePath::FromUTF8Unsafe("drive/dir1/dir3"))); |
| 820 } |
| 821 |
| 600 TEST_F(DriveResourceMetadataTest, TakeOverEntries) { | 822 TEST_F(DriveResourceMetadataTest, TakeOverEntries) { |
| 601 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 823 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 602 FilePath drive_file_path; | 824 FilePath drive_file_path; |
| 603 scoped_ptr<DriveEntryProto> entry_proto; | 825 scoped_ptr<DriveEntryProto> entry_proto; |
| 604 | 826 |
| 605 // Move files from dir1 to dir2. | 827 // Move files from dir1 to dir2. |
| 606 resource_metadata_.TakeOverEntries( | 828 resource_metadata_.TakeOverEntries( |
| 607 "dir_resource_id:dir1", | 829 "resource_id:dir1", |
| 608 "dir_resource_id:dir2", | 830 "resource_id:dir2", |
| 609 base::Bind(&test_util::CopyResultsFromFileMoveCallback, | 831 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
| 610 &error, &drive_file_path)); | 832 &error, &drive_file_path)); |
| 611 google_apis::test_util::RunBlockingPoolTask(); | 833 google_apis::test_util::RunBlockingPoolTask(); |
| 612 EXPECT_EQ(DRIVE_FILE_OK, error); | 834 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 613 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2"), drive_file_path); | 835 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir2"), drive_file_path); |
| 614 | 836 |
| 615 // Check if the file move worked. file6 should now be in drive/dir2. | 837 // Check if the file move worked. file6 should now be in drive/dir2. |
| 616 resource_metadata_.GetEntryInfoByPath( | 838 resource_metadata_.GetEntryInfoByPath( |
| 617 FilePath::FromUTF8Unsafe("drive/dir2/file6"), | 839 FilePath::FromUTF8Unsafe("drive/dir2/file6"), |
| 618 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, | 840 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 648 FilePath::FromUTF8Unsafe("drive/dir2"), | 870 FilePath::FromUTF8Unsafe("drive/dir2"), |
| 649 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | 871 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, |
| 650 &error, &entries)); | 872 &error, &entries)); |
| 651 google_apis::test_util::RunBlockingPoolTask(); | 873 google_apis::test_util::RunBlockingPoolTask(); |
| 652 EXPECT_EQ(DRIVE_FILE_OK, error); | 874 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 653 ASSERT_TRUE(entries.get()); | 875 ASSERT_TRUE(entries.get()); |
| 654 ASSERT_EQ(6U, entries->size()); | 876 ASSERT_EQ(6U, entries->size()); |
| 655 } | 877 } |
| 656 | 878 |
| 657 } // namespace drive | 879 } // namespace drive |
| OLD | NEW |