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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" |
11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 19 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
19 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 20 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
20 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" | 21 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 DCHECK(completed); | 145 DCHECK(completed); |
145 base::RunLoop run_loop; | 146 base::RunLoop run_loop; |
146 runner->ReadDirectory( | 147 runner->ReadDirectory( |
147 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, | 148 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, |
148 completed)); | 149 completed)); |
149 run_loop.Run(); | 150 run_loop.Run(); |
150 } | 151 } |
151 | 152 |
152 } // namespace | 153 } // namespace |
153 | 154 |
154 class TestPicasaDataProvider : public PicasaDataProvider { | |
155 public: | |
156 TestPicasaDataProvider() | |
157 : PicasaDataProvider(base::FilePath(FILE_PATH_LITERAL("Fake"))), | |
158 initialized_(false) { | |
159 } | |
160 | |
161 virtual ~TestPicasaDataProvider() {} | |
162 | |
163 virtual void RefreshData(const base::Closure& ready_callback) OVERRIDE { | |
164 DCHECK(initialized_); | |
165 ready_callback.Run(); | |
166 } | |
167 | |
168 void Init(const std::vector<AlbumInfo>& albums, | |
169 const std::vector<AlbumInfo>& folders) { | |
170 UniquifyNames(albums, &album_map_); | |
171 UniquifyNames(folders, &folder_map_); | |
172 initialized_ = true; | |
173 } | |
174 | |
175 private: | |
176 bool initialized_; | |
177 }; | |
178 | |
179 class TestPicasaFileUtil : public PicasaFileUtil { | 155 class TestPicasaFileUtil : public PicasaFileUtil { |
180 public: | 156 public: |
181 TestPicasaFileUtil(chrome::MediaPathFilter* media_path_filter, | 157 TestPicasaFileUtil(chrome::MediaPathFilter* media_path_filter, |
182 PicasaDataProvider* data_provider) | 158 PicasaDataProvider* data_provider) |
183 : PicasaFileUtil(media_path_filter), | 159 : PicasaFileUtil(media_path_filter), |
184 data_provider_(data_provider) { | 160 data_provider_(data_provider) { |
185 } | 161 } |
186 virtual ~TestPicasaFileUtil() {} | 162 virtual ~TestPicasaFileUtil() {} |
187 private: | 163 private: |
188 virtual PicasaDataProvider* GetDataProvider() OVERRIDE { | 164 virtual PicasaDataProvider* GetDataProvider() OVERRIDE { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 196 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
221 } | 197 } |
222 virtual ~PicasaFileUtilTest() {} | 198 virtual ~PicasaFileUtilTest() {} |
223 | 199 |
224 virtual void SetUp() OVERRIDE { | 200 virtual void SetUp() OVERRIDE { |
225 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 201 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
226 | 202 |
227 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 203 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
228 new quota::MockSpecialStoragePolicy(); | 204 new quota::MockSpecialStoragePolicy(); |
229 | 205 |
| 206 picasa_data_provider_.reset(new PicasaDataProvider(base::FilePath())); |
230 media_path_filter_.reset(new chrome::MediaPathFilter()); | 207 media_path_filter_.reset(new chrome::MediaPathFilter()); |
231 picasa_data_provider_.reset(new TestPicasaDataProvider()); | |
232 | 208 |
233 ScopedVector<fileapi::FileSystemBackend> additional_providers; | 209 ScopedVector<fileapi::FileSystemBackend> additional_providers; |
234 additional_providers.push_back(new TestMediaFileSystemBackend( | 210 additional_providers.push_back(new TestMediaFileSystemBackend( |
235 profile_dir_.path(), | 211 profile_dir_.path(), |
236 new TestPicasaFileUtil(media_path_filter_.get(), | 212 new TestPicasaFileUtil(media_path_filter_.get(), |
237 picasa_data_provider_.get()))); | 213 picasa_data_provider_.get()))); |
238 | 214 |
239 file_system_context_ = new fileapi::FileSystemContext( | 215 file_system_context_ = new fileapi::FileSystemContext( |
240 base::MessageLoopProxy::current().get(), | 216 base::MessageLoopProxy::current().get(), |
241 base::MessageLoopProxy::current().get(), | 217 base::MessageLoopProxy::current().get(), |
242 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 218 fileapi::ExternalMountPoints::CreateRefCounted().get(), |
243 storage_policy.get(), | 219 storage_policy.get(), |
244 NULL, | 220 NULL, |
245 additional_providers.Pass(), | 221 additional_providers.Pass(), |
246 profile_dir_.path(), | 222 profile_dir_.path(), |
247 fileapi::CreateAllowFileAccessOptions()); | 223 fileapi::CreateAllowFileAccessOptions()); |
248 } | 224 } |
249 | 225 |
250 protected: | 226 protected: |
| 227 void SetupDataProvider(PicasaDataProvider* picasa_data_provider, |
| 228 const std::vector<AlbumInfo>& albums, |
| 229 const std::vector<AlbumInfo>& folders) { |
| 230 PicasaDataProvider::UniquifyNames(albums, |
| 231 &picasa_data_provider->album_map_); |
| 232 PicasaDataProvider::UniquifyNames(folders, |
| 233 &picasa_data_provider->folder_map_); |
| 234 picasa_data_provider->state_ = |
| 235 PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE; |
| 236 } |
| 237 |
251 // |test_folders| must be in alphabetical order for easy verification | 238 // |test_folders| must be in alphabetical order for easy verification |
252 void SetupFolders(ScopedVector<TestFolder>* test_folders) { | 239 void SetupFolders(ScopedVector<TestFolder>* test_folders) { |
253 std::vector<AlbumInfo> folders; | 240 std::vector<AlbumInfo> folders; |
254 for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); | 241 for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); |
255 it != test_folders->end(); ++it) { | 242 it != test_folders->end(); ++it) { |
256 TestFolder* test_folder = *it; | 243 TestFolder* test_folder = *it; |
257 ASSERT_TRUE(test_folder->Init()); | 244 ASSERT_TRUE(test_folder->Init()); |
258 folders.push_back(test_folder->folder_info()); | 245 folders.push_back(test_folder->folder_info()); |
259 } | 246 } |
260 picasa_data_provider_->Init(std::vector<AlbumInfo>(), folders); | 247 |
| 248 SetupDataProvider( |
| 249 picasa_data_provider_.get(), std::vector<AlbumInfo>(), folders); |
261 } | 250 } |
262 | 251 |
263 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { | 252 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { |
264 FileSystemOperation::FileEntryList contents; | 253 FileSystemOperation::FileEntryList contents; |
265 FileSystemURL url = CreateURL(kPicasaDirFolders); | 254 FileSystemURL url = CreateURL(kPicasaDirFolders); |
266 bool completed = false; | 255 bool completed = false; |
267 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 256 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
268 | 257 |
269 ASSERT_TRUE(completed); | 258 ASSERT_TRUE(completed); |
270 ASSERT_EQ(test_folders.size(), contents.size()); | 259 ASSERT_EQ(test_folders.size(), contents.size()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return file_system_context_; | 319 return file_system_context_; |
331 } | 320 } |
332 | 321 |
333 private: | 322 private: |
334 base::MessageLoop message_loop_; | 323 base::MessageLoop message_loop_; |
335 content::TestBrowserThread io_thread_; | 324 content::TestBrowserThread io_thread_; |
336 | 325 |
337 base::ScopedTempDir profile_dir_; | 326 base::ScopedTempDir profile_dir_; |
338 | 327 |
339 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 328 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 329 scoped_ptr<PicasaDataProvider> picasa_data_provider_; |
340 scoped_ptr<chrome::MediaPathFilter> media_path_filter_; | 330 scoped_ptr<chrome::MediaPathFilter> media_path_filter_; |
341 scoped_ptr<TestPicasaDataProvider> picasa_data_provider_; | |
342 | 331 |
343 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); | 332 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); |
344 }; | 333 }; |
345 | 334 |
346 TEST_F(PicasaFileUtilTest, DateFormat) { | 335 TEST_F(PicasaFileUtilTest, DateFormat) { |
347 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; | 336 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; |
348 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); | 337 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); |
349 | 338 |
350 base::Time::Exploded exploded_shortday = { 2013, 11, 0, 3, 0, 0, 0, 0 }; | 339 base::Time::Exploded exploded_shortday = { 2013, 11, 0, 3, 0, 0, 0, 0 }; |
351 base::Time shortday = base::Time::FromLocalExploded(exploded_shortday); | 340 base::Time shortday = base::Time::FromLocalExploded(exploded_shortday); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 new TestFolder(base::StringPrintf("folder-%05d", i), | 462 new TestFolder(base::StringPrintf("folder-%05d", i), |
474 date, | 463 date, |
475 base::StringPrintf("uid%05d", i), i % 5, i % 3)); | 464 base::StringPrintf("uid%05d", i), i % 5, i % 3)); |
476 } | 465 } |
477 | 466 |
478 SetupFolders(&test_folders); | 467 SetupFolders(&test_folders); |
479 VerifyFolderDirectoryList(test_folders); | 468 VerifyFolderDirectoryList(test_folders); |
480 } | 469 } |
481 | 470 |
482 } // namespace picasa | 471 } // namespace picasa |
OLD | NEW |