| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/media_galleries/fileapi/picasa_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/picasa_file_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 base::StringPrintf("hello%05d.txt", i)); | 93 base::StringPrintf("hello%05d.txt", i)); |
| 94 if (base::WriteFile(path, NULL, 0) == -1) | 94 if (base::WriteFile(path, NULL, 0) == -1) |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 | 97 |
| 98 return true; | 98 return true; |
| 99 } | 99 } |
| 100 | 100 |
| 101 double GetVariantTimestamp() const { | 101 double GetVariantTimestamp() const { |
| 102 DCHECK(!folder_dir_.path().empty()); | 102 DCHECK(!folder_dir_.path().empty()); |
| 103 base::Time variant_epoch = base::Time::FromLocalExploded( | 103 base::Time variant_epoch; |
| 104 picasa::kPmpVariantTimeEpoch); | 104 EXPECT_TRUE(base::Time::FromLocalExploded(picasa::kPmpVariantTimeEpoch, |
| 105 &variant_epoch)); |
| 105 | 106 |
| 106 int64_t microseconds_since_epoch = | 107 int64_t microseconds_since_epoch = |
| 107 (folder_info_.timestamp - variant_epoch).InMicroseconds(); | 108 (folder_info_.timestamp - variant_epoch).InMicroseconds(); |
| 108 | 109 |
| 109 return static_cast<double>(microseconds_since_epoch) / | 110 return static_cast<double>(microseconds_since_epoch) / |
| 110 base::Time::kMicrosecondsPerDay; | 111 base::Time::kMicrosecondsPerDay; |
| 111 } | 112 } |
| 112 | 113 |
| 113 const std::set<std::string>& image_filenames() const { | 114 const std::set<std::string>& image_filenames() const { |
| 114 DCHECK(!folder_dir_.path().empty()); | 115 DCHECK(!folder_dir_.path().empty()); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 381 |
| 381 scoped_refptr<storage::FileSystemContext> file_system_context_; | 382 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 382 std::unique_ptr<PicasaDataProvider> picasa_data_provider_; | 383 std::unique_ptr<PicasaDataProvider> picasa_data_provider_; |
| 383 std::unique_ptr<MediaPathFilter> media_path_filter_; | 384 std::unique_ptr<MediaPathFilter> media_path_filter_; |
| 384 | 385 |
| 385 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); | 386 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); |
| 386 }; | 387 }; |
| 387 | 388 |
| 388 TEST_F(PicasaFileUtilTest, DateFormat) { | 389 TEST_F(PicasaFileUtilTest, DateFormat) { |
| 389 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; | 390 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; |
| 390 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); | 391 base::Time shortmonth; |
| 392 EXPECT_TRUE(base::Time::FromLocalExploded(exploded_shortmonth, &shortmonth)); |
| 391 | 393 |
| 392 base::Time::Exploded exploded_shortday = { 2013, 11, 0, 3, 0, 0, 0, 0 }; | 394 base::Time::Exploded exploded_shortday = { 2013, 11, 0, 3, 0, 0, 0, 0 }; |
| 393 base::Time shortday = base::Time::FromLocalExploded(exploded_shortday); | 395 base::Time shortday; |
| 396 EXPECT_TRUE(base::Time::FromLocalExploded(exploded_shortday, &shortday)); |
| 394 | 397 |
| 395 EXPECT_EQ("2013-04-16", DateToPathString(shortmonth)); | 398 EXPECT_EQ("2013-04-16", DateToPathString(shortmonth)); |
| 396 EXPECT_EQ("2013-11-03", DateToPathString(shortday)); | 399 EXPECT_EQ("2013-11-03", DateToPathString(shortday)); |
| 397 } | 400 } |
| 398 | 401 |
| 399 TEST_F(PicasaFileUtilTest, NameDeduplication) { | 402 TEST_F(PicasaFileUtilTest, NameDeduplication) { |
| 400 ScopedVector<TestFolder> test_folders; | 403 ScopedVector<TestFolder> test_folders; |
| 401 std::vector<std::string> expected_names; | 404 std::vector<std::string> expected_names; |
| 402 | 405 |
| 403 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); | 406 base::Time test_date; |
| 407 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 404 base::Time test_date_2 = test_date - base::TimeDelta::FromDays(1); | 408 base::Time test_date_2 = test_date - base::TimeDelta::FromDays(1); |
| 405 | 409 |
| 406 std::string test_date_string = DateToPathString(test_date); | 410 std::string test_date_string = DateToPathString(test_date); |
| 407 std::string test_date_2_string = DateToPathString(test_date_2); | 411 std::string test_date_2_string = DateToPathString(test_date_2); |
| 408 | 412 |
| 409 test_folders.push_back( | 413 test_folders.push_back( |
| 410 new TestFolder("diff_date", test_date_2, "uuid3", 0, 0)); | 414 new TestFolder("diff_date", test_date_2, "uuid3", 0, 0)); |
| 411 expected_names.push_back("diff_date " + test_date_2_string); | 415 expected_names.push_back("diff_date " + test_date_2_string); |
| 412 | 416 |
| 413 test_folders.push_back( | 417 test_folders.push_back( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 ScopedVector<TestFolder> empty_folders_list; | 469 ScopedVector<TestFolder> empty_folders_list; |
| 466 SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap()); | 470 SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 467 | 471 |
| 468 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo"); | 472 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo"); |
| 469 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar"); | 473 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar"); |
| 470 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar/baz"); | 474 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar/baz"); |
| 471 } | 475 } |
| 472 | 476 |
| 473 TEST_F(PicasaFileUtilTest, FolderContentsTrivial) { | 477 TEST_F(PicasaFileUtilTest, FolderContentsTrivial) { |
| 474 ScopedVector<TestFolder> test_folders; | 478 ScopedVector<TestFolder> test_folders; |
| 475 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); | 479 base::Time test_date; |
| 480 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 476 | 481 |
| 477 test_folders.push_back( | 482 test_folders.push_back( |
| 478 new TestFolder("folder-1-empty", test_date, "uid-empty", 0, 0)); | 483 new TestFolder("folder-1-empty", test_date, "uid-empty", 0, 0)); |
| 479 test_folders.push_back( | 484 test_folders.push_back( |
| 480 new TestFolder("folder-2-images", test_date, "uid-images", 5, 0)); | 485 new TestFolder("folder-2-images", test_date, "uid-images", 5, 0)); |
| 481 test_folders.push_back( | 486 test_folders.push_back( |
| 482 new TestFolder("folder-3-nonimages", test_date, "uid-nonimages", 0, 5)); | 487 new TestFolder("folder-3-nonimages", test_date, "uid-nonimages", 0, 5)); |
| 483 test_folders.push_back( | 488 test_folders.push_back( |
| 484 new TestFolder("folder-4-both", test_date, "uid-both", 5, 5)); | 489 new TestFolder("folder-4-both", test_date, "uid-both", 5, 5)); |
| 485 | 490 |
| 486 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); | 491 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 487 VerifyFolderDirectoryList(test_folders); | 492 VerifyFolderDirectoryList(test_folders); |
| 488 } | 493 } |
| 489 | 494 |
| 490 TEST_F(PicasaFileUtilTest, FolderWithManyFiles) { | 495 TEST_F(PicasaFileUtilTest, FolderWithManyFiles) { |
| 491 ScopedVector<TestFolder> test_folders; | 496 ScopedVector<TestFolder> test_folders; |
| 492 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); | 497 base::Time test_date; |
| 498 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 493 | 499 |
| 494 test_folders.push_back( | 500 test_folders.push_back( |
| 495 new TestFolder("folder-many-files", test_date, "uid-both", 50, 50)); | 501 new TestFolder("folder-many-files", test_date, "uid-both", 50, 50)); |
| 496 | 502 |
| 497 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); | 503 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 498 VerifyFolderDirectoryList(test_folders); | 504 VerifyFolderDirectoryList(test_folders); |
| 499 } | 505 } |
| 500 | 506 |
| 501 TEST_F(PicasaFileUtilTest, ManyFolders) { | 507 TEST_F(PicasaFileUtilTest, ManyFolders) { |
| 502 ScopedVector<TestFolder> test_folders; | 508 ScopedVector<TestFolder> test_folders; |
| 503 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); | 509 base::Time test_date; |
| 510 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 504 | 511 |
| 505 for (unsigned int i = 0; i < 50; ++i) { | 512 for (unsigned int i = 0; i < 50; ++i) { |
| 506 base::Time date = test_date - base::TimeDelta::FromDays(i); | 513 base::Time date = test_date - base::TimeDelta::FromDays(i); |
| 507 | 514 |
| 508 test_folders.push_back( | 515 test_folders.push_back( |
| 509 new TestFolder(base::StringPrintf("folder-%05d", i), | 516 new TestFolder(base::StringPrintf("folder-%05d", i), |
| 510 date, | 517 date, |
| 511 base::StringPrintf("uid%05d", i), i % 5, i % 3)); | 518 base::StringPrintf("uid%05d", i), i % 5, i % 3)); |
| 512 } | 519 } |
| 513 | 520 |
| 514 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); | 521 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 515 VerifyFolderDirectoryList(test_folders); | 522 VerifyFolderDirectoryList(test_folders); |
| 516 } | 523 } |
| 517 | 524 |
| 518 TEST_F(PicasaFileUtilTest, AlbumExistence) { | 525 TEST_F(PicasaFileUtilTest, AlbumExistence) { |
| 519 ScopedVector<TestFolder> test_folders; | 526 ScopedVector<TestFolder> test_folders; |
| 520 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); | 527 base::Time test_date; |
| 528 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 521 | 529 |
| 522 std::vector<AlbumInfo> albums; | 530 std::vector<AlbumInfo> albums; |
| 523 AlbumInfo info; | 531 AlbumInfo info; |
| 524 info.name = "albumname"; | 532 info.name = "albumname"; |
| 525 info.uid = "albumuid"; | 533 info.uid = "albumuid"; |
| 526 info.timestamp = test_date; | 534 info.timestamp = test_date; |
| 527 albums.push_back(info); | 535 albums.push_back(info); |
| 528 | 536 |
| 529 AlbumImagesMap albums_images; | 537 AlbumImagesMap albums_images; |
| 530 albums_images[info.uid] = AlbumImages(); | 538 albums_images[info.uid] = AlbumImages(); |
| 531 | 539 |
| 532 SetupFolders(&test_folders, albums, albums_images); | 540 SetupFolders(&test_folders, albums, albums_images); |
| 533 | 541 |
| 534 TestEmptyDirectory(std::string(kPicasaDirAlbums) + "/albumname 2013-04-16"); | 542 TestEmptyDirectory(std::string(kPicasaDirAlbums) + "/albumname 2013-04-16"); |
| 535 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + | 543 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + |
| 536 "/albumname 2013-04-16/toodeep"); | 544 "/albumname 2013-04-16/toodeep"); |
| 537 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + "/wrongname"); | 545 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + "/wrongname"); |
| 538 } | 546 } |
| 539 | 547 |
| 540 TEST_F(PicasaFileUtilTest, AlbumContents) { | 548 TEST_F(PicasaFileUtilTest, AlbumContents) { |
| 541 ScopedVector<TestFolder> test_folders; | 549 ScopedVector<TestFolder> test_folders; |
| 542 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); | 550 base::Time test_date; |
| 551 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 543 | 552 |
| 544 std::vector<AlbumInfo> albums; | 553 std::vector<AlbumInfo> albums; |
| 545 AlbumInfo info; | 554 AlbumInfo info; |
| 546 info.name = "albumname"; | 555 info.name = "albumname"; |
| 547 info.uid = "albumuid"; | 556 info.uid = "albumuid"; |
| 548 info.timestamp = test_date; | 557 info.timestamp = test_date; |
| 549 albums.push_back(info); | 558 albums.push_back(info); |
| 550 | 559 |
| 551 base::ScopedTempDir temp_dir; | 560 base::ScopedTempDir temp_dir; |
| 552 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 561 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 operation_runner()->CreateSnapshotFile( | 593 operation_runner()->CreateSnapshotFile( |
| 585 CreateURL(std::string(kPicasaDirAlbums) + | 594 CreateURL(std::string(kPicasaDirAlbums) + |
| 586 "/albumname 2013-04-16/mapped_name.jpg"), | 595 "/albumname 2013-04-16/mapped_name.jpg"), |
| 587 snapshot_callback); | 596 snapshot_callback); |
| 588 loop.Run(); | 597 loop.Run(); |
| 589 EXPECT_EQ(base::File::FILE_OK, error); | 598 EXPECT_EQ(base::File::FILE_OK, error); |
| 590 EXPECT_EQ(image_path, platform_path_result); | 599 EXPECT_EQ(image_path, platform_path_result); |
| 591 } | 600 } |
| 592 | 601 |
| 593 } // namespace picasa | 602 } // namespace picasa |
| OLD | NEW |