Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / utility / media_galleries / picasa_albums_indexer_unittest.cc
blob83ab66f57a741ae375c5d37776fbc72b9b33e71f
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
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "chrome/common/media_galleries/picasa_types.h"
7 #include "chrome/utility/media_galleries/picasa_albums_indexer.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace picasa {
12 namespace {
14 const char test_ini_string[] =
15 "[.album:e66fb059001aabcc69b262b7009fad90]\n"
16 "name=CustomAlbum1\n"
17 "token=e66fb059001aabcc69b262b7009fad90\n"
18 "date=2013-03-15T14:53:21-07:00\n"
19 "[InBoth.jpg]\n"
20 "albums=e66fb059001aabcc69b262b7009fad90,18cb2df48aaa98e1c276b45cfcd81c95\n"
21 "[.album:18cb2df48aaa98e1c276b45cfcd81c95]\n"
22 "name=CustomAlbum2\n"
23 "token=18cb2df48aaa98e1c276b45cfcd81c95\n"
24 "date=2013-04-01T16:37:34-07:00\n"
25 "[InFirst.jpg]\n"
26 "albums=e66fb059001aabcc69b262b7009fad90\n"
27 "[InSecond.jpg]\n"
28 "albums=18cb2df48aaa98e1c276b45cfcd81c95\n";
30 TEST(PicasaAlbumsIndexerTest, ValidCase) {
31 std::set<std::string> valid_album_uuids;
32 valid_album_uuids.insert("e66fb059001aabcc69b262b7009fad90");
33 valid_album_uuids.insert("18cb2df48aaa98e1c276b45cfcd81c95");
34 PicasaAlbumsIndexer indexer(valid_album_uuids);
36 std::vector<FolderINIContents> folders_inis;
37 FolderINIContents folder_ini;
38 folder_ini.folder_path = base::FilePath(FILE_PATH_LITERAL("/foo/baz"));
39 folder_ini.ini_contents = test_ini_string;
40 folders_inis.push_back(folder_ini);
41 indexer.ParseFolderINI(folders_inis);
43 const AlbumImagesMap& albums_images = indexer.albums_images();
44 AlbumImagesMap::const_iterator it;
46 it = albums_images.find("e66fb059001aabcc69b262b7009fad90");
47 ASSERT_NE(albums_images.end(), it);
48 EXPECT_EQ(2u, it->second.size());
49 EXPECT_EQ(1u, it->second.count("InBoth.jpg"));
50 EXPECT_EQ(1u, it->second.count("InFirst.jpg"));
52 it = albums_images.find("18cb2df48aaa98e1c276b45cfcd81c95");
53 ASSERT_NE(albums_images.end(), it);
54 EXPECT_EQ(2u, it->second.size());
55 EXPECT_EQ(1u, it->second.count("InBoth.jpg"));
56 EXPECT_EQ(1u, it->second.count("InSecond.jpg"));
59 TEST(PicasaAlbumsIndexerTest, DedupeNames) {
60 std::set<std::string> valid_album_uuids;
61 valid_album_uuids.insert("e66fb059001aabcc69b262b7009fad90");
62 valid_album_uuids.insert("18cb2df48aaa98e1c276b45cfcd81c95");
63 PicasaAlbumsIndexer indexer(valid_album_uuids);
65 std::vector<FolderINIContents> folders_inis;
66 FolderINIContents folder_ini;
67 folder_ini.folder_path = base::FilePath(FILE_PATH_LITERAL("/foo/baz"));
68 folder_ini.ini_contents = test_ini_string;
69 folders_inis.push_back(folder_ini);
71 // Add a second folder with just a duplicate InFirst.jpg.
72 folder_ini.folder_path = base::FilePath(FILE_PATH_LITERAL("/foo/second"));
73 folder_ini.ini_contents =
74 "[.album:e66fb059001aabcc69b262b7009fad90]\n"
75 "name=CustomAlbum1\n"
76 "token=e66fb059001aabcc69b262b7009fad90\n"
77 "date=2013-03-15T14:53:21-07:00\n"
78 "[InFirst.jpg]\n"
79 "albums=e66fb059001aabcc69b262b7009fad90\n";
80 folders_inis.push_back(folder_ini);
82 // Add a third folder with just a duplicate InFirst.jpg and InSecond.jpg.
83 folder_ini.folder_path = base::FilePath(FILE_PATH_LITERAL("/foo/third"));
84 folder_ini.ini_contents =
85 "[.album:e66fb059001aabcc69b262b7009fad90]\n"
86 "name=CustomAlbum1\n"
87 "token=e66fb059001aabcc69b262b7009fad90\n"
88 "date=2013-03-15T14:53:21-07:00\n"
89 "[.album:18cb2df48aaa98e1c276b45cfcd81c95]\n"
90 "name=CustomAlbum2\n"
91 "token=18cb2df48aaa98e1c276b45cfcd81c95\n"
92 "date=2013-04-01T16:37:34-07:00\n"
93 "[InFirst.jpg]\n"
94 "albums=e66fb059001aabcc69b262b7009fad90\n"
95 "[InSecond.jpg]\n"
96 "albums=18cb2df48aaa98e1c276b45cfcd81c95\n";
97 folders_inis.push_back(folder_ini);
99 indexer.ParseFolderINI(folders_inis);
101 const AlbumImagesMap& albums_images = indexer.albums_images();
102 AlbumImagesMap::const_iterator it;
104 it = albums_images.find("e66fb059001aabcc69b262b7009fad90");
105 ASSERT_NE(albums_images.end(), it);
106 EXPECT_EQ(4u, it->second.size());
107 EXPECT_EQ(1u, it->second.count("InBoth.jpg"));
108 EXPECT_EQ(1u, it->second.count("InFirst.jpg"));
109 EXPECT_EQ(1u, it->second.count("InFirst (1).jpg"));
110 EXPECT_EQ(1u, it->second.count("InFirst (2).jpg"));
112 it = albums_images.find("18cb2df48aaa98e1c276b45cfcd81c95");
113 ASSERT_NE(albums_images.end(), it);
114 EXPECT_EQ(3u, it->second.size());
115 EXPECT_EQ(1u, it->second.count("InBoth.jpg"));
116 EXPECT_EQ(1u, it->second.count("InSecond.jpg"));
117 EXPECT_EQ(1u, it->second.count("InSecond (1).jpg"));
120 TEST(PicasaAlbumsIndexerTest, EdgeCases) {
121 std::set<std::string> valid_album_uuids;
122 valid_album_uuids.insert("album-uuid-with-no-images");
123 valid_album_uuids.insert("18cb2df48aaa98e1c276b45cfcd81c95");
124 PicasaAlbumsIndexer indexer(valid_album_uuids);
126 std::vector<FolderINIContents> folders_inis;
127 FolderINIContents folder_ini;
128 folder_ini.folder_path = base::FilePath(FILE_PATH_LITERAL("/foo/baz"));
129 folder_ini.ini_contents = test_ini_string;
130 folders_inis.push_back(folder_ini);
131 indexer.ParseFolderINI(folders_inis);
133 const AlbumImagesMap& albums_images = indexer.albums_images();
134 AlbumImagesMap::const_iterator it;
136 // UUID that exists in INI that isn't in |valid_album_uuids|.
137 EXPECT_EQ(albums_images.end(),
138 albums_images.find("e66fb059001aabcc69b262b7009fad90"));
140 // UUID that exists in INI and |valid_album_uuids| but no images.
141 it = albums_images.find("album-uuid-with-no-images");
142 EXPECT_NE(albums_images.end(), it);
143 EXPECT_EQ(0u, it->second.size());
145 // Should still parse normal albums correctly.
146 it = albums_images.find("18cb2df48aaa98e1c276b45cfcd81c95");
147 EXPECT_NE(albums_images.end(), it);
148 EXPECT_EQ(2u, it->second.size());
149 EXPECT_EQ(1u, it->second.count("InBoth.jpg"));
150 EXPECT_EQ(1u, it->second.count("InSecond.jpg"));
153 } // namespace
155 } // namespace picasa