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 <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById_RootDirectory) { | 247 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById_RootDirectory) { |
248 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> | 248 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> |
249 resource_metadata(new ResourceMetadata(temp_dir_.path(), | 249 resource_metadata(new ResourceMetadata(temp_dir_.path(), |
250 blocking_task_runner_)); | 250 blocking_task_runner_)); |
251 FileError error = FILE_ERROR_FAILED; | 251 FileError error = FILE_ERROR_FAILED; |
252 resource_metadata->Initialize( | 252 resource_metadata->Initialize( |
253 google_apis::test_util::CreateCopyResultCallback(&error)); | 253 google_apis::test_util::CreateCopyResultCallback(&error)); |
254 google_apis::test_util::RunBlockingPoolTask(); | 254 google_apis::test_util::RunBlockingPoolTask(); |
255 ASSERT_EQ(FILE_ERROR_OK, error); | 255 ASSERT_EQ(FILE_ERROR_OK, error); |
256 | 256 |
257 base::FilePath drive_file_path; | |
258 scoped_ptr<ResourceEntry> entry; | 257 scoped_ptr<ResourceEntry> entry; |
259 | 258 |
260 // Look up the root directory by its resource ID. | 259 // Look up the root directory by its resource ID. |
261 resource_metadata->GetResourceEntryByIdOnUIThread( | 260 resource_metadata->GetResourceEntryByIdOnUIThread( |
262 util::kDriveGrandRootSpecialResourceId, | 261 util::kDriveGrandRootSpecialResourceId, |
263 google_apis::test_util::CreateCopyResultCallback( | 262 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
264 &error, &drive_file_path, &entry)); | |
265 google_apis::test_util::RunBlockingPoolTask(); | 263 google_apis::test_util::RunBlockingPoolTask(); |
266 EXPECT_EQ(FILE_ERROR_OK, error); | 264 EXPECT_EQ(FILE_ERROR_OK, error); |
267 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), drive_file_path); | |
268 ASSERT_TRUE(entry.get()); | 265 ASSERT_TRUE(entry.get()); |
269 EXPECT_EQ("drive", entry->base_name()); | 266 EXPECT_EQ("drive", entry->base_name()); |
270 } | 267 } |
271 | 268 |
272 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById) { | 269 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryById) { |
273 // Confirm that an existing file is found. | 270 // Confirm that an existing file is found. |
274 FileError error = FILE_ERROR_FAILED; | 271 FileError error = FILE_ERROR_FAILED; |
275 base::FilePath drive_file_path; | |
276 scoped_ptr<ResourceEntry> entry; | 272 scoped_ptr<ResourceEntry> entry; |
277 resource_metadata_->GetResourceEntryByIdOnUIThread( | 273 resource_metadata_->GetResourceEntryByIdOnUIThread( |
278 "resource_id:file4", | 274 "resource_id:file4", |
279 google_apis::test_util::CreateCopyResultCallback( | 275 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
280 &error, &drive_file_path, &entry)); | |
281 google_apis::test_util::RunBlockingPoolTask(); | 276 google_apis::test_util::RunBlockingPoolTask(); |
282 EXPECT_EQ(FILE_ERROR_OK, error); | 277 EXPECT_EQ(FILE_ERROR_OK, error); |
283 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"), | |
284 drive_file_path); | |
285 ASSERT_TRUE(entry.get()); | 278 ASSERT_TRUE(entry.get()); |
286 EXPECT_EQ("file4", entry->base_name()); | 279 EXPECT_EQ("file4", entry->base_name()); |
287 | 280 |
288 // Confirm that a non existing file is not found. | 281 // Confirm that a non existing file is not found. |
289 error = FILE_ERROR_FAILED; | 282 error = FILE_ERROR_FAILED; |
290 entry.reset(); | 283 entry.reset(); |
291 resource_metadata_->GetResourceEntryByIdOnUIThread( | 284 resource_metadata_->GetResourceEntryByIdOnUIThread( |
292 "file:non_existing", | 285 "file:non_existing", |
293 google_apis::test_util::CreateCopyResultCallback( | 286 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
294 &error, &drive_file_path, &entry)); | |
295 google_apis::test_util::RunBlockingPoolTask(); | 287 google_apis::test_util::RunBlockingPoolTask(); |
296 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 288 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
297 EXPECT_FALSE(entry.get()); | 289 EXPECT_FALSE(entry.get()); |
298 } | 290 } |
299 | 291 |
300 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryByPath) { | 292 TEST_F(ResourceMetadataTestOnUIThread, GetResourceEntryByPath) { |
301 // Confirm that an existing file is found. | 293 // Confirm that an existing file is found. |
302 FileError error = FILE_ERROR_FAILED; | 294 FileError error = FILE_ERROR_FAILED; |
303 scoped_ptr<ResourceEntry> entry; | 295 scoped_ptr<ResourceEntry> entry; |
304 resource_metadata_->GetResourceEntryByPathOnUIThread( | 296 resource_metadata_->GetResourceEntryByPathOnUIThread( |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // The second entry should not be found. | 434 // The second entry should not be found. |
443 EXPECT_EQ(FILE_ERROR_NOT_FOUND, pair_result->second.error); | 435 EXPECT_EQ(FILE_ERROR_NOT_FOUND, pair_result->second.error); |
444 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/non_existent"), | 436 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/non_existent"), |
445 pair_result->second.path); | 437 pair_result->second.path); |
446 ASSERT_FALSE(pair_result->second.entry.get()); | 438 ASSERT_FALSE(pair_result->second.entry.get()); |
447 } | 439 } |
448 | 440 |
449 TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) { | 441 TEST_F(ResourceMetadataTestOnUIThread, RemoveEntry) { |
450 // Make sure file9 is found. | 442 // Make sure file9 is found. |
451 FileError error = FILE_ERROR_FAILED; | 443 FileError error = FILE_ERROR_FAILED; |
452 base::FilePath drive_file_path; | |
453 const std::string file9_resource_id = "resource_id:file9"; | 444 const std::string file9_resource_id = "resource_id:file9"; |
454 scoped_ptr<ResourceEntry> entry; | 445 scoped_ptr<ResourceEntry> entry; |
455 resource_metadata_->GetResourceEntryByIdOnUIThread( | 446 resource_metadata_->GetResourceEntryByIdOnUIThread( |
456 file9_resource_id, | 447 file9_resource_id, |
457 google_apis::test_util::CreateCopyResultCallback( | 448 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
458 &error, &drive_file_path, &entry)); | |
459 google_apis::test_util::RunBlockingPoolTask(); | 449 google_apis::test_util::RunBlockingPoolTask(); |
460 EXPECT_EQ(FILE_ERROR_OK, error); | 450 EXPECT_EQ(FILE_ERROR_OK, error); |
461 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"), | |
462 drive_file_path); | |
463 ASSERT_TRUE(entry.get()); | 451 ASSERT_TRUE(entry.get()); |
464 EXPECT_EQ("file9", entry->base_name()); | 452 EXPECT_EQ("file9", entry->base_name()); |
465 | 453 |
466 // Remove file9 using RemoveEntry. | 454 // Remove file9 using RemoveEntry. |
| 455 base::FilePath drive_file_path; |
467 resource_metadata_->RemoveEntryOnUIThread( | 456 resource_metadata_->RemoveEntryOnUIThread( |
468 file9_resource_id, | 457 file9_resource_id, |
469 google_apis::test_util::CreateCopyResultCallback( | 458 google_apis::test_util::CreateCopyResultCallback( |
470 &error, &drive_file_path)); | 459 &error, &drive_file_path)); |
471 google_apis::test_util::RunBlockingPoolTask(); | 460 google_apis::test_util::RunBlockingPoolTask(); |
472 EXPECT_EQ(FILE_ERROR_OK, error); | 461 EXPECT_EQ(FILE_ERROR_OK, error); |
473 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"), | 462 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"), |
474 drive_file_path); | 463 drive_file_path); |
475 | 464 |
476 // file9 should no longer exist. | 465 // file9 should no longer exist. |
477 resource_metadata_->GetResourceEntryByIdOnUIThread( | 466 resource_metadata_->GetResourceEntryByIdOnUIThread( |
478 file9_resource_id, | 467 file9_resource_id, |
479 google_apis::test_util::CreateCopyResultCallback( | 468 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
480 &error, &drive_file_path, &entry)); | |
481 google_apis::test_util::RunBlockingPoolTask(); | 469 google_apis::test_util::RunBlockingPoolTask(); |
482 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 470 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
483 EXPECT_FALSE(entry.get()); | 471 EXPECT_FALSE(entry.get()); |
484 | 472 |
485 // Look for dir3. | 473 // Look for dir3. |
486 const std::string dir3_resource_id = "resource_id:dir3"; | 474 const std::string dir3_resource_id = "resource_id:dir3"; |
487 resource_metadata_->GetResourceEntryByIdOnUIThread( | 475 resource_metadata_->GetResourceEntryByIdOnUIThread( |
488 dir3_resource_id, | 476 dir3_resource_id, |
489 google_apis::test_util::CreateCopyResultCallback( | 477 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
490 &error, &drive_file_path, &entry)); | |
491 google_apis::test_util::RunBlockingPoolTask(); | 478 google_apis::test_util::RunBlockingPoolTask(); |
492 EXPECT_EQ(FILE_ERROR_OK, error); | 479 EXPECT_EQ(FILE_ERROR_OK, error); |
493 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"), | |
494 drive_file_path); | |
495 ASSERT_TRUE(entry.get()); | 480 ASSERT_TRUE(entry.get()); |
496 EXPECT_EQ("dir3", entry->base_name()); | 481 EXPECT_EQ("dir3", entry->base_name()); |
497 | 482 |
498 // Remove dir3 using RemoveEntry. | 483 // Remove dir3 using RemoveEntry. |
499 resource_metadata_->RemoveEntryOnUIThread( | 484 resource_metadata_->RemoveEntryOnUIThread( |
500 dir3_resource_id, | 485 dir3_resource_id, |
501 google_apis::test_util::CreateCopyResultCallback( | 486 google_apis::test_util::CreateCopyResultCallback( |
502 &error, &drive_file_path)); | 487 &error, &drive_file_path)); |
503 google_apis::test_util::RunBlockingPoolTask(); | 488 google_apis::test_util::RunBlockingPoolTask(); |
504 EXPECT_EQ(FILE_ERROR_OK, error); | 489 EXPECT_EQ(FILE_ERROR_OK, error); |
505 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1"), drive_file_path); | 490 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1"), drive_file_path); |
506 | 491 |
507 // dir3 should no longer exist. | 492 // dir3 should no longer exist. |
508 resource_metadata_->GetResourceEntryByIdOnUIThread( | 493 resource_metadata_->GetResourceEntryByIdOnUIThread( |
509 dir3_resource_id, | 494 dir3_resource_id, |
510 google_apis::test_util::CreateCopyResultCallback( | 495 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
511 &error, &drive_file_path, &entry)); | |
512 google_apis::test_util::RunBlockingPoolTask(); | 496 google_apis::test_util::RunBlockingPoolTask(); |
513 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 497 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
514 EXPECT_FALSE(entry.get()); | 498 EXPECT_FALSE(entry.get()); |
515 | 499 |
516 // Remove unknown resource_id using RemoveEntry. | 500 // Remove unknown resource_id using RemoveEntry. |
517 resource_metadata_->RemoveEntryOnUIThread( | 501 resource_metadata_->RemoveEntryOnUIThread( |
518 "foo", | 502 "foo", |
519 google_apis::test_util::CreateCopyResultCallback( | 503 google_apis::test_util::CreateCopyResultCallback( |
520 &error, &drive_file_path)); | 504 &error, &drive_file_path)); |
521 google_apis::test_util::RunBlockingPoolTask(); | 505 google_apis::test_util::RunBlockingPoolTask(); |
(...skipping 20 matching lines...) Expand all Loading... |
542 google_apis::test_util::CreateCopyResultCallback( | 526 google_apis::test_util::CreateCopyResultCallback( |
543 &error, &drive_file_path)); | 527 &error, &drive_file_path)); |
544 google_apis::test_util::RunBlockingPoolTask(); | 528 google_apis::test_util::RunBlockingPoolTask(); |
545 EXPECT_EQ(FILE_ERROR_OK, error); | 529 EXPECT_EQ(FILE_ERROR_OK, error); |
546 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"), | 530 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"), |
547 drive_file_path); | 531 drive_file_path); |
548 | 532 |
549 // Look up the entry by its resource id and make sure it really moved. | 533 // Look up the entry by its resource id and make sure it really moved. |
550 resource_metadata_->GetResourceEntryByIdOnUIThread( | 534 resource_metadata_->GetResourceEntryByIdOnUIThread( |
551 "resource_id:file8", | 535 "resource_id:file8", |
552 google_apis::test_util::CreateCopyResultCallback( | 536 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
553 &error, &drive_file_path, &entry)); | |
554 google_apis::test_util::RunBlockingPoolTask(); | 537 google_apis::test_util::RunBlockingPoolTask(); |
555 EXPECT_EQ(FILE_ERROR_OK, error); | 538 EXPECT_EQ(FILE_ERROR_OK, error); |
556 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir1/file8"), | |
557 drive_file_path); | |
558 | 539 |
559 // Move non-existent file to drive/dir1. This should fail. | 540 // Move non-existent file to drive/dir1. This should fail. |
560 resource_metadata_->MoveEntryToDirectoryOnUIThread( | 541 resource_metadata_->MoveEntryToDirectoryOnUIThread( |
561 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"), | 542 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"), |
562 base::FilePath::FromUTF8Unsafe("drive/root/dir1"), | 543 base::FilePath::FromUTF8Unsafe("drive/root/dir1"), |
563 google_apis::test_util::CreateCopyResultCallback( | 544 google_apis::test_util::CreateCopyResultCallback( |
564 &error, &drive_file_path)); | 545 &error, &drive_file_path)); |
565 google_apis::test_util::RunBlockingPoolTask(); | 546 google_apis::test_util::RunBlockingPoolTask(); |
566 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 547 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
567 EXPECT_EQ(base::FilePath(), drive_file_path); | 548 EXPECT_EQ(base::FilePath(), drive_file_path); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 google_apis::test_util::CreateCopyResultCallback( | 585 google_apis::test_util::CreateCopyResultCallback( |
605 &error, &drive_file_path)); | 586 &error, &drive_file_path)); |
606 google_apis::test_util::RunBlockingPoolTask(); | 587 google_apis::test_util::RunBlockingPoolTask(); |
607 EXPECT_EQ(FILE_ERROR_OK, error); | 588 EXPECT_EQ(FILE_ERROR_OK, error); |
608 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"), | 589 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"), |
609 drive_file_path); | 590 drive_file_path); |
610 | 591 |
611 // Make sure file is still ok. | 592 // Make sure file is still ok. |
612 resource_metadata_->GetResourceEntryByIdOnUIThread( | 593 resource_metadata_->GetResourceEntryByIdOnUIThread( |
613 "resource_id:file8", | 594 "resource_id:file8", |
614 google_apis::test_util::CreateCopyResultCallback( | 595 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
615 &error, &drive_file_path, &entry)); | |
616 google_apis::test_util::RunBlockingPoolTask(); | 596 google_apis::test_util::RunBlockingPoolTask(); |
617 EXPECT_EQ(FILE_ERROR_OK, error); | 597 EXPECT_EQ(FILE_ERROR_OK, error); |
618 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"), | |
619 drive_file_path); | |
620 } | 598 } |
621 | 599 |
622 TEST_F(ResourceMetadataTestOnUIThread, RenameEntry) { | 600 TEST_F(ResourceMetadataTestOnUIThread, RenameEntry) { |
623 FileError error = FILE_ERROR_FAILED; | 601 FileError error = FILE_ERROR_FAILED; |
624 base::FilePath drive_file_path; | 602 base::FilePath drive_file_path; |
625 scoped_ptr<ResourceEntry> entry; | 603 scoped_ptr<ResourceEntry> entry; |
626 | 604 |
627 // Rename file8 to file11. | 605 // Rename file8 to file11. |
628 resource_metadata_->RenameEntryOnUIThread( | 606 resource_metadata_->RenameEntryOnUIThread( |
629 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"), | 607 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file8"), |
630 "file11", | 608 "file11", |
631 google_apis::test_util::CreateCopyResultCallback( | 609 google_apis::test_util::CreateCopyResultCallback( |
632 &error, &drive_file_path)); | 610 &error, &drive_file_path)); |
633 google_apis::test_util::RunBlockingPoolTask(); | 611 google_apis::test_util::RunBlockingPoolTask(); |
634 EXPECT_EQ(FILE_ERROR_OK, error); | 612 EXPECT_EQ(FILE_ERROR_OK, error); |
635 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"), | 613 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"), |
636 drive_file_path); | 614 drive_file_path); |
637 | 615 |
638 // Lookup the file by resource id to make sure the file actually got renamed. | 616 // Lookup the file by resource id to make sure the file actually got renamed. |
639 resource_metadata_->GetResourceEntryByIdOnUIThread( | 617 resource_metadata_->GetResourceEntryByIdOnUIThread( |
640 "resource_id:file8", | 618 "resource_id:file8", |
641 google_apis::test_util::CreateCopyResultCallback( | 619 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
642 &error, &drive_file_path, &entry)); | |
643 google_apis::test_util::RunBlockingPoolTask(); | 620 google_apis::test_util::RunBlockingPoolTask(); |
644 EXPECT_EQ(FILE_ERROR_OK, error); | 621 EXPECT_EQ(FILE_ERROR_OK, error); |
645 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"), | |
646 drive_file_path); | |
647 | 622 |
648 // Rename to file7 to force a duplicate name. | 623 // Rename to file7 to force a duplicate name. |
649 resource_metadata_->RenameEntryOnUIThread( | 624 resource_metadata_->RenameEntryOnUIThread( |
650 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"), | 625 base::FilePath::FromUTF8Unsafe("drive/root/dir2/file11"), |
651 "file7", | 626 "file7", |
652 google_apis::test_util::CreateCopyResultCallback( | 627 google_apis::test_util::CreateCopyResultCallback( |
653 &error, &drive_file_path)); | 628 &error, &drive_file_path)); |
654 google_apis::test_util::RunBlockingPoolTask(); | 629 google_apis::test_util::RunBlockingPoolTask(); |
655 EXPECT_EQ(FILE_ERROR_OK, error); | 630 EXPECT_EQ(FILE_ERROR_OK, error); |
656 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file7 (2)"), | 631 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/root/dir2/file7 (2)"), |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 else | 1190 else |
1216 ++directory_count; | 1191 ++directory_count; |
1217 } | 1192 } |
1218 | 1193 |
1219 EXPECT_EQ(7, file_count); | 1194 EXPECT_EQ(7, file_count); |
1220 EXPECT_EQ(6, directory_count); | 1195 EXPECT_EQ(6, directory_count); |
1221 } | 1196 } |
1222 | 1197 |
1223 } // namespace internal | 1198 } // namespace internal |
1224 } // namespace drive | 1199 } // namespace drive |
OLD | NEW |