Index: chrome/browser/media_galleries/fileapi/picasa/picasa_file_util_unittest.cc |
diff --git a/chrome/browser/media_galleries/fileapi/picasa/picasa_file_util_unittest.cc b/chrome/browser/media_galleries/fileapi/picasa/picasa_file_util_unittest.cc |
index 67f1d43cd7325e8765a073128a2c1294842eb30d..618c49ba361d10bfb1a08a0644518b10f17a41d4 100644 |
--- a/chrome/browser/media_galleries/fileapi/picasa/picasa_file_util_unittest.cc |
+++ b/chrome/browser/media_galleries/fileapi/picasa/picasa_file_util_unittest.cc |
@@ -47,6 +47,12 @@ namespace { |
base::Time::Exploded test_date_exploded = { 2013, 4, 0, 16, 0, 0, 0, 0 }; |
+// Defined up here because used by TestFolder. |
Greg Billock
2013/08/21 17:13:17
can omit comment
tommycli
2013/08/21 21:37:06
Done.
|
+bool WriteJPEGHeader(const base::FilePath& path) { |
+ const char kJpegHeader[] = "\xFF\xD8\xFF"; // Per HTML5 specification. |
+ return file_util::WriteFile(path, kJpegHeader, arraysize(kJpegHeader)) != -1; |
+} |
+ |
class TestFolder { |
public: |
TestFolder(const std::string& name, const base::Time& timestamp, |
@@ -66,14 +72,13 @@ class TestFolder { |
folder_info_ = AlbumInfo(name_, timestamp_, uid_, folder_dir_.path()); |
- const char kJpegHeader[] = "\xFF\xD8\xFF"; // Per HTML5 specification. |
for (unsigned int i = 0; i < image_files_; ++i) { |
std::string image_filename = base::StringPrintf("img%05d.jpg", i); |
image_filenames_.insert(image_filename); |
base::FilePath path = folder_dir_.path().AppendASCII(image_filename); |
- if (file_util::WriteFile(path, kJpegHeader, arraysize(kJpegHeader)) == -1) |
+ if (!WriteJPEGHeader(path)) |
return false; |
} |
@@ -250,19 +255,10 @@ class PicasaFileUtilTest : public testing::Test { |
event->Signal(); |
} |
- void SetupDataProvider(PicasaDataProvider* picasa_data_provider, |
- const std::vector<AlbumInfo>& albums, |
- const std::vector<AlbumInfo>& folders) { |
- PicasaDataProvider::UniquifyNames(albums, |
- &picasa_data_provider->album_map_); |
- PicasaDataProvider::UniquifyNames(folders, |
- &picasa_data_provider->folder_map_); |
- picasa_data_provider->state_ = |
- PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE; |
- } |
- |
// |test_folders| must be in alphabetical order for easy verification |
- void SetupFolders(ScopedVector<TestFolder>* test_folders) { |
+ void SetupFolders(ScopedVector<TestFolder>* test_folders, |
+ const std::vector<AlbumInfo>& albums, |
+ const AlbumImagesMap& albums_images) { |
std::vector<AlbumInfo> folders; |
for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); |
it != test_folders->end(); ++it) { |
@@ -271,8 +267,13 @@ class PicasaFileUtilTest : public testing::Test { |
folders.push_back(test_folder->folder_info()); |
} |
- SetupDataProvider( |
- picasa_data_provider_.get(), std::vector<AlbumInfo>(), folders); |
+ PicasaDataProvider::UniquifyNames(albums, |
+ &picasa_data_provider_->album_map_); |
+ PicasaDataProvider::UniquifyNames(folders, |
+ &picasa_data_provider_->folder_map_); |
+ picasa_data_provider_->albums_images_ = albums_images; |
+ picasa_data_provider_->state_ = |
+ PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE; |
} |
void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { |
@@ -321,16 +322,25 @@ class PicasaFileUtilTest : public testing::Test { |
return PicasaDataProvider::DateToPathString(time); |
} |
- void TestNonexistentFolder(const std::string& path_append) { |
+ void TestNonexistentDirectory(const std::string& path) { |
FileSystemOperation::FileEntryList contents; |
- FileSystemURL url = CreateURL( |
- std::string(kPicasaDirFolders) + path_append); |
+ FileSystemURL url = CreateURL(path); |
bool completed = false; |
ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
ASSERT_FALSE(completed); |
} |
+ void TestEmptyDirectory(const std::string& path) { |
+ FileSystemOperation::FileEntryList contents; |
+ FileSystemURL url = CreateURL(path); |
+ bool completed = false; |
+ ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
+ |
+ ASSERT_TRUE(completed); |
+ EXPECT_EQ(0u, contents.size()); |
+ } |
+ |
FileSystemURL CreateURL(const std::string& virtual_path) const { |
return file_system_context_->CreateCrackedFileSystemURL( |
GURL("http://www.example.com"), fileapi::kFileSystemTypePicasa, |
@@ -399,7 +409,7 @@ TEST_F(PicasaFileUtilTest, NameDeduplication) { |
new TestFolder("unique_name", test_date, "uuid1", 0, 0)); |
expected_names.push_back("unique_name " + test_date_string); |
- SetupFolders(&test_folders); |
+ SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
FileSystemOperation::FileEntryList contents; |
FileSystemURL url = CreateURL(kPicasaDirFolders); |
@@ -418,7 +428,7 @@ TEST_F(PicasaFileUtilTest, NameDeduplication) { |
TEST_F(PicasaFileUtilTest, RootFolders) { |
ScopedVector<TestFolder> empty_folders_list; |
- SetupFolders(&empty_folders_list); |
+ SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap()); |
FileSystemOperation::FileEntryList contents; |
FileSystemURL url = CreateURL(""); |
@@ -440,11 +450,11 @@ TEST_F(PicasaFileUtilTest, RootFolders) { |
TEST_F(PicasaFileUtilTest, NonexistentFolder) { |
ScopedVector<TestFolder> empty_folders_list; |
- SetupFolders(&empty_folders_list); |
+ SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap()); |
- TestNonexistentFolder("/foo"); |
- TestNonexistentFolder("/foo/bar"); |
- TestNonexistentFolder("/foo/bar/baz"); |
+ TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo"); |
+ TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar"); |
+ TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar/baz"); |
} |
TEST_F(PicasaFileUtilTest, FolderContentsTrivial) { |
@@ -460,7 +470,7 @@ TEST_F(PicasaFileUtilTest, FolderContentsTrivial) { |
test_folders.push_back( |
new TestFolder("folder-4-both", test_date, "uid-both", 5, 5)); |
- SetupFolders(&test_folders); |
+ SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
VerifyFolderDirectoryList(test_folders); |
} |
@@ -471,7 +481,7 @@ TEST_F(PicasaFileUtilTest, FolderWithManyFiles) { |
test_folders.push_back( |
new TestFolder("folder-many-files", test_date, "uid-both", 500, 500)); |
- SetupFolders(&test_folders); |
+ SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
VerifyFolderDirectoryList(test_folders); |
} |
@@ -490,8 +500,66 @@ TEST_F(PicasaFileUtilTest, ManyFolders) { |
base::StringPrintf("uid%05d", i), i % 5, i % 3)); |
} |
- SetupFolders(&test_folders); |
+ SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
VerifyFolderDirectoryList(test_folders); |
} |
+TEST_F(PicasaFileUtilTest, AlbumExistence) { |
+ ScopedVector<TestFolder> test_folders; |
+ base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); |
+ |
+ std::vector<AlbumInfo> albums; |
+ AlbumInfo info; |
+ info.name = "albumname"; |
+ info.uid = "albumuid"; |
+ info.timestamp = test_date; |
+ albums.push_back(info); |
+ |
+ AlbumImagesMap albums_images; |
+ albums_images[info.uid] = AlbumImages(); |
+ |
+ SetupFolders(&test_folders, albums, albums_images); |
+ |
+ TestEmptyDirectory(std::string(kPicasaDirAlbums) + "/albumname 2013-04-16"); |
+ TestNonexistentDirectory(std::string(kPicasaDirAlbums) + |
+ "/albumname 2013-04-16/toodeep"); |
+ TestNonexistentDirectory(std::string(kPicasaDirAlbums) + "/wrongname"); |
+} |
+ |
+TEST_F(PicasaFileUtilTest, AlbumContents) { |
+ ScopedVector<TestFolder> test_folders; |
+ base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); |
+ |
+ std::vector<AlbumInfo> albums; |
+ AlbumInfo info; |
+ info.name = "albumname"; |
+ info.uid = "albumuid"; |
+ info.timestamp = test_date; |
+ albums.push_back(info); |
+ |
+ base::ScopedTempDir temp_dir; |
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
+ |
+ base::FilePath image_path = temp_dir.path().AppendASCII("img.jpg"); |
+ ASSERT_TRUE(WriteJPEGHeader(image_path)); |
+ |
+ AlbumImagesMap albums_images; |
+ albums_images[info.uid] = AlbumImages(); |
+ albums_images[info.uid]["mapped_name.jpg"] = image_path; |
+ |
+ SetupFolders(&test_folders, albums, albums_images); |
+ |
+ FileSystemOperation::FileEntryList contents; |
+ FileSystemURL url = |
+ CreateURL(std::string(kPicasaDirAlbums) + "/albumname 2013-04-16"); |
+ bool completed = false; |
+ ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
+ |
+ ASSERT_TRUE(completed); |
+ EXPECT_EQ(1u, contents.size()); |
+ EXPECT_EQ("mapped_name.jpg", |
+ base::FilePath(contents.begin()->name).AsUTF8Unsafe()); |
+ EXPECT_FALSE(contents.begin()->is_directory); |
Greg Billock
2013/08/21 17:13:17
Need to check the actual on-disk filename you get
tommycli
2013/08/21 21:37:06
I can't easily access that information. The file u
Greg Billock
2013/08/21 21:41:23
Is there a way to prove we can read it? Get the fi
tommycli
2013/08/21 22:19:26
Seems like creating a snapshot file is a way to ve
|
+} |
+ |
} // namespace picasa |