Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/browser/media_galleries/fileapi/picasa/picasa_file_util_unittest.cc

Issue 22912008: Media Galleries API Picasa: Make PicasaFileUtil support album contents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_path.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/message_loop/message_loop_proxy.h" 16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/platform_file.h"
16 #include "base/run_loop.h" 18 #include "base/run_loop.h"
17 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
18 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
19 #include "base/time/time.h" 21 #include "base/time/time.h"
20 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" 22 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
21 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" 23 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h"
22 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" 24 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h"
23 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" 25 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h"
24 #include "chrome/common/media_galleries/picasa_types.h" 26 #include "chrome/common/media_galleries/picasa_types.h"
25 #include "chrome/common/media_galleries/pmp_constants.h" 27 #include "chrome/common/media_galleries/pmp_constants.h"
26 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
27 #include "content/public/test/test_browser_thread.h" 29 #include "content/public/test/test_browser_thread.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 #include "webkit/browser/fileapi/async_file_util_adapter.h" 31 #include "webkit/browser/fileapi/async_file_util_adapter.h"
30 #include "webkit/browser/fileapi/external_mount_points.h" 32 #include "webkit/browser/fileapi/external_mount_points.h"
31 #include "webkit/browser/fileapi/file_system_context.h" 33 #include "webkit/browser/fileapi/file_system_context.h"
32 #include "webkit/browser/fileapi/file_system_file_util.h" 34 #include "webkit/browser/fileapi/file_system_file_util.h"
33 #include "webkit/browser/fileapi/file_system_operation_context.h" 35 #include "webkit/browser/fileapi/file_system_operation_context.h"
34 #include "webkit/browser/fileapi/file_system_operation_runner.h" 36 #include "webkit/browser/fileapi/file_system_operation_runner.h"
35 #include "webkit/browser/fileapi/isolated_context.h" 37 #include "webkit/browser/fileapi/isolated_context.h"
36 #include "webkit/browser/fileapi/mock_file_system_options.h" 38 #include "webkit/browser/fileapi/mock_file_system_options.h"
37 #include "webkit/browser/quota/mock_special_storage_policy.h" 39 #include "webkit/browser/quota/mock_special_storage_policy.h"
40 #include "webkit/common/blob/shareable_file_reference.h"
38 41
39 using fileapi::FileSystemFileUtil; 42 using fileapi::FileSystemFileUtil;
40 using fileapi::FileSystemOperationContext; 43 using fileapi::FileSystemOperationContext;
41 using fileapi::FileSystemOperation; 44 using fileapi::FileSystemOperation;
42 using fileapi::FileSystemURL; 45 using fileapi::FileSystemURL;
43 46
44 namespace picasa { 47 namespace picasa {
45 48
46 namespace { 49 namespace {
47 50
48 base::Time::Exploded test_date_exploded = { 2013, 4, 0, 16, 0, 0, 0, 0 }; 51 base::Time::Exploded test_date_exploded = { 2013, 4, 0, 16, 0, 0, 0, 0 };
49 52
53 bool WriteJPEGHeader(const base::FilePath& path) {
54 const char kJpegHeader[] = "\xFF\xD8\xFF"; // Per HTML5 specification.
55 return file_util::WriteFile(path, kJpegHeader, arraysize(kJpegHeader)) != -1;
56 }
57
50 class TestFolder { 58 class TestFolder {
51 public: 59 public:
52 TestFolder(const std::string& name, const base::Time& timestamp, 60 TestFolder(const std::string& name, const base::Time& timestamp,
53 const std::string& uid, unsigned int image_files, 61 const std::string& uid, unsigned int image_files,
54 unsigned int non_image_files) 62 unsigned int non_image_files)
55 : name_(name), 63 : name_(name),
56 timestamp_(timestamp), 64 timestamp_(timestamp),
57 uid_(uid), 65 uid_(uid),
58 image_files_(image_files), 66 image_files_(image_files),
59 non_image_files_(non_image_files), 67 non_image_files_(non_image_files),
60 folder_info_("", base::Time(), "", base::FilePath()) { 68 folder_info_("", base::Time(), "", base::FilePath()) {
61 } 69 }
62 70
63 bool Init() { 71 bool Init() {
64 if (!folder_dir_.CreateUniqueTempDir()) 72 if (!folder_dir_.CreateUniqueTempDir())
65 return false; 73 return false;
66 74
67 folder_info_ = AlbumInfo(name_, timestamp_, uid_, folder_dir_.path()); 75 folder_info_ = AlbumInfo(name_, timestamp_, uid_, folder_dir_.path());
68 76
69 const char kJpegHeader[] = "\xFF\xD8\xFF"; // Per HTML5 specification.
70 for (unsigned int i = 0; i < image_files_; ++i) { 77 for (unsigned int i = 0; i < image_files_; ++i) {
71 std::string image_filename = base::StringPrintf("img%05d.jpg", i); 78 std::string image_filename = base::StringPrintf("img%05d.jpg", i);
72 image_filenames_.insert(image_filename); 79 image_filenames_.insert(image_filename);
73 80
74 base::FilePath path = folder_dir_.path().AppendASCII(image_filename); 81 base::FilePath path = folder_dir_.path().AppendASCII(image_filename);
75 82
76 if (file_util::WriteFile(path, kJpegHeader, arraysize(kJpegHeader)) == -1) 83 if (!WriteJPEGHeader(path))
77 return false; 84 return false;
78 } 85 }
79 86
80 for (unsigned int i = 0; i < non_image_files_; ++i) { 87 for (unsigned int i = 0; i < non_image_files_; ++i) {
81 base::FilePath path = folder_dir_.path().AppendASCII( 88 base::FilePath path = folder_dir_.path().AppendASCII(
82 base::StringPrintf("hello%05d.txt", i)); 89 base::StringPrintf("hello%05d.txt", i));
83 if (file_util::WriteFile(path, NULL, 0) == -1) 90 if (file_util::WriteFile(path, NULL, 0) == -1)
84 return false; 91 return false;
85 } 92 }
86 93
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 bool* completed) { 151 bool* completed) {
145 DCHECK(contents); 152 DCHECK(contents);
146 DCHECK(completed); 153 DCHECK(completed);
147 base::RunLoop run_loop; 154 base::RunLoop run_loop;
148 runner->ReadDirectory( 155 runner->ReadDirectory(
149 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, 156 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents,
150 completed)); 157 completed));
151 run_loop.Run(); 158 run_loop.Run();
152 } 159 }
153 160
161 void CreateSnapshotFileTestHelperCallback(
162 base::RunLoop* run_loop,
163 base::PlatformFileError* error,
164 base::FilePath* platform_path_result,
165 base::PlatformFileError result,
166 const base::PlatformFileInfo& file_info,
167 const base::FilePath& platform_path,
168 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
169 DCHECK(run_loop);
170 DCHECK(error);
171 DCHECK(platform_path_result);
172
173 *error = result;
174 *platform_path_result = platform_path;
175 run_loop->Quit();
176 }
177
154 } // namespace 178 } // namespace
155 179
156 class TestPicasaFileUtil : public PicasaFileUtil { 180 class TestPicasaFileUtil : public PicasaFileUtil {
157 public: 181 public:
158 TestPicasaFileUtil(chrome::MediaPathFilter* media_path_filter, 182 TestPicasaFileUtil(chrome::MediaPathFilter* media_path_filter,
159 PicasaDataProvider* data_provider) 183 PicasaDataProvider* data_provider)
160 : PicasaFileUtil(media_path_filter), 184 : PicasaFileUtil(media_path_filter),
161 data_provider_(data_provider) { 185 data_provider_(data_provider) {
162 } 186 }
163 virtual ~TestPicasaFileUtil() {} 187 virtual ~TestPicasaFileUtil() {}
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void SetUpOnMediaTaskRunner(base::WaitableEvent* event) { 269 void SetUpOnMediaTaskRunner(base::WaitableEvent* event) {
246 picasa_data_provider_.reset(new PicasaDataProvider(base::FilePath())); 270 picasa_data_provider_.reset(new PicasaDataProvider(base::FilePath()));
247 event->Signal(); 271 event->Signal();
248 } 272 }
249 273
250 void TearDownOnMediaTaskRunner(base::WaitableEvent* event) { 274 void TearDownOnMediaTaskRunner(base::WaitableEvent* event) {
251 picasa_data_provider_.reset(); 275 picasa_data_provider_.reset();
252 event->Signal(); 276 event->Signal();
253 } 277 }
254 278
255 void SetupDataProvider(PicasaDataProvider* picasa_data_provider,
256 const std::vector<AlbumInfo>& albums,
257 const std::vector<AlbumInfo>& folders) {
258 PicasaDataProvider::UniquifyNames(albums,
259 &picasa_data_provider->album_map_);
260 PicasaDataProvider::UniquifyNames(folders,
261 &picasa_data_provider->folder_map_);
262 picasa_data_provider->state_ =
263 PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE;
264 }
265
266 // |test_folders| must be in alphabetical order for easy verification 279 // |test_folders| must be in alphabetical order for easy verification
267 void SetupFolders(ScopedVector<TestFolder>* test_folders) { 280 void SetupFolders(ScopedVector<TestFolder>* test_folders,
281 const std::vector<AlbumInfo>& albums,
282 const AlbumImagesMap& albums_images) {
268 std::vector<AlbumInfo> folders; 283 std::vector<AlbumInfo> folders;
269 for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); 284 for (ScopedVector<TestFolder>::iterator it = test_folders->begin();
270 it != test_folders->end(); ++it) { 285 it != test_folders->end(); ++it) {
271 TestFolder* test_folder = *it; 286 TestFolder* test_folder = *it;
272 ASSERT_TRUE(test_folder->Init()); 287 ASSERT_TRUE(test_folder->Init());
273 folders.push_back(test_folder->folder_info()); 288 folders.push_back(test_folder->folder_info());
274 } 289 }
275 290
276 SetupDataProvider( 291 PicasaDataProvider::UniquifyNames(albums,
277 picasa_data_provider_.get(), std::vector<AlbumInfo>(), folders); 292 &picasa_data_provider_->album_map_);
293 PicasaDataProvider::UniquifyNames(folders,
294 &picasa_data_provider_->folder_map_);
295 picasa_data_provider_->albums_images_ = albums_images;
296 picasa_data_provider_->state_ =
297 PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE;
278 } 298 }
279 299
280 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { 300 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) {
281 FileSystemOperation::FileEntryList contents; 301 FileSystemOperation::FileEntryList contents;
282 FileSystemURL url = CreateURL(kPicasaDirFolders); 302 FileSystemURL url = CreateURL(kPicasaDirFolders);
283 bool completed = false; 303 bool completed = false;
284 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); 304 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed);
285 305
286 ASSERT_TRUE(completed); 306 ASSERT_TRUE(completed);
287 ASSERT_EQ(test_folders.size(), contents.size()); 307 ASSERT_EQ(test_folders.size(), contents.size());
(...skipping 28 matching lines...) Expand all
316 EXPECT_EQ(1u, image_filenames.count( 336 EXPECT_EQ(1u, image_filenames.count(
317 base::FilePath(file_it->name).AsUTF8Unsafe())); 337 base::FilePath(file_it->name).AsUTF8Unsafe()));
318 } 338 }
319 } 339 }
320 } 340 }
321 341
322 std::string DateToPathString(const base::Time& time) { 342 std::string DateToPathString(const base::Time& time) {
323 return PicasaDataProvider::DateToPathString(time); 343 return PicasaDataProvider::DateToPathString(time);
324 } 344 }
325 345
326 void TestNonexistentFolder(const std::string& path_append) { 346 void TestNonexistentDirectory(const std::string& path) {
327 FileSystemOperation::FileEntryList contents; 347 FileSystemOperation::FileEntryList contents;
328 FileSystemURL url = CreateURL( 348 FileSystemURL url = CreateURL(path);
329 std::string(kPicasaDirFolders) + path_append);
330 bool completed = false; 349 bool completed = false;
331 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); 350 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed);
332 351
333 ASSERT_FALSE(completed); 352 ASSERT_FALSE(completed);
334 } 353 }
335 354
355 void TestEmptyDirectory(const std::string& path) {
356 FileSystemOperation::FileEntryList contents;
357 FileSystemURL url = CreateURL(path);
358 bool completed = false;
359 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed);
360
361 ASSERT_TRUE(completed);
362 EXPECT_EQ(0u, contents.size());
363 }
364
336 FileSystemURL CreateURL(const std::string& virtual_path) const { 365 FileSystemURL CreateURL(const std::string& virtual_path) const {
337 return file_system_context_->CreateCrackedFileSystemURL( 366 return file_system_context_->CreateCrackedFileSystemURL(
338 GURL("http://www.example.com"), fileapi::kFileSystemTypePicasa, 367 GURL("http://www.example.com"), fileapi::kFileSystemTypePicasa,
339 base::FilePath::FromUTF8Unsafe(virtual_path)); 368 base::FilePath::FromUTF8Unsafe(virtual_path));
340 } 369 }
341 370
342 fileapi::FileSystemOperationRunner* operation_runner() const { 371 fileapi::FileSystemOperationRunner* operation_runner() const {
343 return file_system_context_->operation_runner(); 372 return file_system_context_->operation_runner();
344 } 373 }
345 374
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 expected_names.push_back("duplicate " + test_date_string + " (1)"); 423 expected_names.push_back("duplicate " + test_date_string + " (1)");
395 424
396 test_folders.push_back( 425 test_folders.push_back(
397 new TestFolder("duplicate", test_date, "uuid5", 0, 0)); 426 new TestFolder("duplicate", test_date, "uuid5", 0, 0));
398 expected_names.push_back("duplicate " + test_date_string + " (2)"); 427 expected_names.push_back("duplicate " + test_date_string + " (2)");
399 428
400 test_folders.push_back( 429 test_folders.push_back(
401 new TestFolder("unique_name", test_date, "uuid1", 0, 0)); 430 new TestFolder("unique_name", test_date, "uuid1", 0, 0));
402 expected_names.push_back("unique_name " + test_date_string); 431 expected_names.push_back("unique_name " + test_date_string);
403 432
404 SetupFolders(&test_folders); 433 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap());
405 434
406 FileSystemOperation::FileEntryList contents; 435 FileSystemOperation::FileEntryList contents;
407 FileSystemURL url = CreateURL(kPicasaDirFolders); 436 FileSystemURL url = CreateURL(kPicasaDirFolders);
408 bool completed = false; 437 bool completed = false;
409 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); 438 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed);
410 439
411 ASSERT_TRUE(completed); 440 ASSERT_TRUE(completed);
412 ASSERT_EQ(expected_names.size(), contents.size()); 441 ASSERT_EQ(expected_names.size(), contents.size());
413 for (size_t i = 0; i < contents.size(); ++i) { 442 for (size_t i = 0; i < contents.size(); ++i) {
414 EXPECT_EQ(expected_names[i], 443 EXPECT_EQ(expected_names[i],
415 base::FilePath(contents[i].name).AsUTF8Unsafe()); 444 base::FilePath(contents[i].name).AsUTF8Unsafe());
416 EXPECT_EQ(test_folders[i]->timestamp(), contents[i].last_modified_time); 445 EXPECT_EQ(test_folders[i]->timestamp(), contents[i].last_modified_time);
417 EXPECT_TRUE(contents[i].is_directory); 446 EXPECT_TRUE(contents[i].is_directory);
418 } 447 }
419 } 448 }
420 449
421 TEST_F(PicasaFileUtilTest, RootFolders) { 450 TEST_F(PicasaFileUtilTest, RootFolders) {
422 ScopedVector<TestFolder> empty_folders_list; 451 ScopedVector<TestFolder> empty_folders_list;
423 SetupFolders(&empty_folders_list); 452 SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap());
424 453
425 FileSystemOperation::FileEntryList contents; 454 FileSystemOperation::FileEntryList contents;
426 FileSystemURL url = CreateURL(""); 455 FileSystemURL url = CreateURL("");
427 bool completed = false; 456 bool completed = false;
428 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); 457 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed);
429 458
430 ASSERT_TRUE(completed); 459 ASSERT_TRUE(completed);
431 ASSERT_EQ(2u, contents.size()); 460 ASSERT_EQ(2u, contents.size());
432 461
433 EXPECT_TRUE(contents.front().is_directory); 462 EXPECT_TRUE(contents.front().is_directory);
434 EXPECT_TRUE(contents.back().is_directory); 463 EXPECT_TRUE(contents.back().is_directory);
435 464
436 EXPECT_EQ(0, contents.front().size); 465 EXPECT_EQ(0, contents.front().size);
437 EXPECT_EQ(0, contents.back().size); 466 EXPECT_EQ(0, contents.back().size);
438 467
439 EXPECT_EQ(FILE_PATH_LITERAL("albums"), contents.front().name); 468 EXPECT_EQ(FILE_PATH_LITERAL("albums"), contents.front().name);
440 EXPECT_EQ(FILE_PATH_LITERAL("folders"), contents.back().name); 469 EXPECT_EQ(FILE_PATH_LITERAL("folders"), contents.back().name);
441 } 470 }
442 471
443 TEST_F(PicasaFileUtilTest, NonexistentFolder) { 472 TEST_F(PicasaFileUtilTest, NonexistentFolder) {
444 ScopedVector<TestFolder> empty_folders_list; 473 ScopedVector<TestFolder> empty_folders_list;
445 SetupFolders(&empty_folders_list); 474 SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap());
446 475
447 TestNonexistentFolder("/foo"); 476 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo");
448 TestNonexistentFolder("/foo/bar"); 477 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar");
449 TestNonexistentFolder("/foo/bar/baz"); 478 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar/baz");
450 } 479 }
451 480
452 TEST_F(PicasaFileUtilTest, FolderContentsTrivial) { 481 TEST_F(PicasaFileUtilTest, FolderContentsTrivial) {
453 ScopedVector<TestFolder> test_folders; 482 ScopedVector<TestFolder> test_folders;
454 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); 483 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded);
455 484
456 test_folders.push_back( 485 test_folders.push_back(
457 new TestFolder("folder-1-empty", test_date, "uid-empty", 0, 0)); 486 new TestFolder("folder-1-empty", test_date, "uid-empty", 0, 0));
458 test_folders.push_back( 487 test_folders.push_back(
459 new TestFolder("folder-2-images", test_date, "uid-images", 5, 0)); 488 new TestFolder("folder-2-images", test_date, "uid-images", 5, 0));
460 test_folders.push_back( 489 test_folders.push_back(
461 new TestFolder("folder-3-nonimages", test_date, "uid-nonimages", 0, 5)); 490 new TestFolder("folder-3-nonimages", test_date, "uid-nonimages", 0, 5));
462 test_folders.push_back( 491 test_folders.push_back(
463 new TestFolder("folder-4-both", test_date, "uid-both", 5, 5)); 492 new TestFolder("folder-4-both", test_date, "uid-both", 5, 5));
464 493
465 SetupFolders(&test_folders); 494 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap());
466 VerifyFolderDirectoryList(test_folders); 495 VerifyFolderDirectoryList(test_folders);
467 } 496 }
468 497
469 TEST_F(PicasaFileUtilTest, FolderWithManyFiles) { 498 TEST_F(PicasaFileUtilTest, FolderWithManyFiles) {
470 ScopedVector<TestFolder> test_folders; 499 ScopedVector<TestFolder> test_folders;
471 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); 500 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded);
472 501
473 test_folders.push_back( 502 test_folders.push_back(
474 new TestFolder("folder-many-files", test_date, "uid-both", 500, 500)); 503 new TestFolder("folder-many-files", test_date, "uid-both", 500, 500));
475 504
476 SetupFolders(&test_folders); 505 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap());
477 VerifyFolderDirectoryList(test_folders); 506 VerifyFolderDirectoryList(test_folders);
478 } 507 }
479 508
480 TEST_F(PicasaFileUtilTest, ManyFolders) { 509 TEST_F(PicasaFileUtilTest, ManyFolders) {
481 ScopedVector<TestFolder> test_folders; 510 ScopedVector<TestFolder> test_folders;
482 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded); 511 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded);
483 512
484 // TODO(tommycli): Turn number of test folders back up to 50 (or more) once 513 // TODO(tommycli): Turn number of test folders back up to 50 (or more) once
485 // https://codereview.chromium.org/15479003/ lands. 514 // https://codereview.chromium.org/15479003/ lands.
486 for (unsigned int i = 0; i < 25; ++i) { 515 for (unsigned int i = 0; i < 25; ++i) {
487 base::Time date = test_date - base::TimeDelta::FromDays(i); 516 base::Time date = test_date - base::TimeDelta::FromDays(i);
488 517
489 test_folders.push_back( 518 test_folders.push_back(
490 new TestFolder(base::StringPrintf("folder-%05d", i), 519 new TestFolder(base::StringPrintf("folder-%05d", i),
491 date, 520 date,
492 base::StringPrintf("uid%05d", i), i % 5, i % 3)); 521 base::StringPrintf("uid%05d", i), i % 5, i % 3));
493 } 522 }
494 523
495 SetupFolders(&test_folders); 524 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap());
496 VerifyFolderDirectoryList(test_folders); 525 VerifyFolderDirectoryList(test_folders);
497 } 526 }
498 527
528 TEST_F(PicasaFileUtilTest, AlbumExistence) {
529 ScopedVector<TestFolder> test_folders;
530 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded);
531
532 std::vector<AlbumInfo> albums;
533 AlbumInfo info;
534 info.name = "albumname";
535 info.uid = "albumuid";
536 info.timestamp = test_date;
537 albums.push_back(info);
538
539 AlbumImagesMap albums_images;
540 albums_images[info.uid] = AlbumImages();
541
542 SetupFolders(&test_folders, albums, albums_images);
543
544 TestEmptyDirectory(std::string(kPicasaDirAlbums) + "/albumname 2013-04-16");
545 TestNonexistentDirectory(std::string(kPicasaDirAlbums) +
546 "/albumname 2013-04-16/toodeep");
547 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + "/wrongname");
548 }
549
550 TEST_F(PicasaFileUtilTest, AlbumContents) {
551 ScopedVector<TestFolder> test_folders;
552 base::Time test_date = base::Time::FromLocalExploded(test_date_exploded);
553
554 std::vector<AlbumInfo> albums;
555 AlbumInfo info;
556 info.name = "albumname";
557 info.uid = "albumuid";
558 info.timestamp = test_date;
559 albums.push_back(info);
560
561 base::ScopedTempDir temp_dir;
562 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
563
564 base::FilePath image_path = temp_dir.path().AppendASCII("img.jpg");
565 ASSERT_TRUE(WriteJPEGHeader(image_path));
566
567 AlbumImagesMap albums_images;
568 albums_images[info.uid] = AlbumImages();
569 albums_images[info.uid]["mapped_name.jpg"] = image_path;
570
571 SetupFolders(&test_folders, albums, albums_images);
572
573 FileSystemOperation::FileEntryList contents;
574 FileSystemURL url =
575 CreateURL(std::string(kPicasaDirAlbums) + "/albumname 2013-04-16");
576 bool completed = false;
577 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed);
578
579 ASSERT_TRUE(completed);
580 EXPECT_EQ(1u, contents.size());
581 EXPECT_EQ("mapped_name.jpg",
582 base::FilePath(contents.begin()->name).AsUTF8Unsafe());
583 EXPECT_FALSE(contents.begin()->is_directory);
584
585 // Create a snapshot file to verify the file path.
586 base::RunLoop loop;
587 base::PlatformFileError error;
588 base::FilePath platform_path_result;
589 fileapi::FileSystemOperationRunner::SnapshotFileCallback snapshot_callback =
590 base::Bind(&CreateSnapshotFileTestHelperCallback,
591 &loop,
592 &error,
593 &platform_path_result);
594 operation_runner()->CreateSnapshotFile(
595 CreateURL(std::string(kPicasaDirAlbums) +
596 "/albumname 2013-04-16/mapped_name.jpg"),
597 snapshot_callback);
598 loop.Run();
599 EXPECT_EQ(base::PLATFORM_FILE_OK, error);
600 EXPECT_EQ(image_path, platform_path_result);
601 }
602
499 } // namespace picasa 603 } // namespace picasa
OLDNEW
« no previous file with comments | « chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698