| 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 <memory> |
| 10 #include <set> | 11 #include <set> |
| 11 #include <string> | 12 #include <string> |
| 12 #include <utility> | 13 #include <utility> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 16 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 17 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
| 18 #include "base/files/scoped_temp_dir.h" | 19 #include "base/files/scoped_temp_dir.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/ptr_util.h" |
| 20 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
| 21 #include "base/memory/scoped_vector.h" | |
| 22 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 23 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
| 24 #include "base/single_thread_task_runner.h" | 25 #include "base/single_thread_task_runner.h" |
| 25 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| 28 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 29 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 29 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 30 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
| 30 #include "chrome/browser/media_galleries/fileapi/picasa_data_provider.h" | 31 #include "chrome/browser/media_galleries/fileapi/picasa_data_provider.h" |
| 31 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 32 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); | 238 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); |
| 238 | 239 |
| 239 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = | 240 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = |
| 240 new content::MockSpecialStoragePolicy(); | 241 new content::MockSpecialStoragePolicy(); |
| 241 | 242 |
| 242 SynchronouslyRunOnMediaTaskRunner(base::Bind( | 243 SynchronouslyRunOnMediaTaskRunner(base::Bind( |
| 243 &PicasaFileUtilTest::SetUpOnMediaTaskRunner, base::Unretained(this))); | 244 &PicasaFileUtilTest::SetUpOnMediaTaskRunner, base::Unretained(this))); |
| 244 | 245 |
| 245 media_path_filter_.reset(new MediaPathFilter()); | 246 media_path_filter_.reset(new MediaPathFilter()); |
| 246 | 247 |
| 247 ScopedVector<storage::FileSystemBackend> additional_providers; | 248 std::vector<std::unique_ptr<storage::FileSystemBackend>> |
| 248 additional_providers.push_back(new TestMediaFileSystemBackend( | 249 additional_providers; |
| 250 additional_providers.push_back(base::MakeUnique<TestMediaFileSystemBackend>( |
| 249 profile_dir_.GetPath(), | 251 profile_dir_.GetPath(), |
| 250 new TestPicasaFileUtil(media_path_filter_.get(), | 252 new TestPicasaFileUtil(media_path_filter_.get(), |
| 251 picasa_data_provider_.get()))); | 253 picasa_data_provider_.get()))); |
| 252 | 254 |
| 253 file_system_context_ = new storage::FileSystemContext( | 255 file_system_context_ = new storage::FileSystemContext( |
| 254 base::ThreadTaskRunnerHandle::Get().get(), | 256 base::ThreadTaskRunnerHandle::Get().get(), |
| 255 base::ThreadTaskRunnerHandle::Get().get(), | 257 base::ThreadTaskRunnerHandle::Get().get(), |
| 256 storage::ExternalMountPoints::CreateRefCounted().get(), | 258 storage::ExternalMountPoints::CreateRefCounted().get(), |
| 257 storage_policy.get(), NULL, std::move(additional_providers), | 259 storage_policy.get(), NULL, std::move(additional_providers), |
| 258 std::vector<storage::URLRequestAutoMountHandler>(), | 260 std::vector<storage::URLRequestAutoMountHandler>(), |
| 259 profile_dir_.GetPath(), content::CreateAllowFileAccessOptions()); | 261 profile_dir_.GetPath(), content::CreateAllowFileAccessOptions()); |
| 260 } | 262 } |
| 261 | 263 |
| 262 void TearDown() override { | 264 void TearDown() override { |
| 263 SynchronouslyRunOnMediaTaskRunner( | 265 SynchronouslyRunOnMediaTaskRunner( |
| 264 base::Bind(&PicasaFileUtilTest::TearDownOnMediaTaskRunner, | 266 base::Bind(&PicasaFileUtilTest::TearDownOnMediaTaskRunner, |
| 265 base::Unretained(this))); | 267 base::Unretained(this))); |
| 266 } | 268 } |
| 267 | 269 |
| 268 protected: | 270 protected: |
| 269 void SetUpOnMediaTaskRunner() { | 271 void SetUpOnMediaTaskRunner() { |
| 270 picasa_data_provider_.reset(new PicasaDataProvider(base::FilePath())); | 272 picasa_data_provider_.reset(new PicasaDataProvider(base::FilePath())); |
| 271 } | 273 } |
| 272 | 274 |
| 273 void TearDownOnMediaTaskRunner() { | 275 void TearDownOnMediaTaskRunner() { |
| 274 picasa_data_provider_.reset(); | 276 picasa_data_provider_.reset(); |
| 275 } | 277 } |
| 276 | 278 |
| 277 // |test_folders| must be in alphabetical order for easy verification | 279 // |test_folders| must be in alphabetical order for easy verification |
| 278 void SetupFolders(ScopedVector<TestFolder>* test_folders, | 280 void SetupFolders(std::vector<std::unique_ptr<TestFolder>>* test_folders, |
| 279 const std::vector<AlbumInfo>& albums, | 281 const std::vector<AlbumInfo>& albums, |
| 280 const AlbumImagesMap& albums_images) { | 282 const AlbumImagesMap& albums_images) { |
| 281 std::vector<AlbumInfo> folders; | 283 std::vector<AlbumInfo> folders; |
| 282 for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); | 284 for (const auto& test_folder : *test_folders) { |
| 283 it != test_folders->end(); ++it) { | |
| 284 TestFolder* test_folder = *it; | |
| 285 ASSERT_TRUE(test_folder->Init()); | 285 ASSERT_TRUE(test_folder->Init()); |
| 286 folders.push_back(test_folder->folder_info()); | 286 folders.push_back(test_folder->folder_info()); |
| 287 } | 287 } |
| 288 | 288 |
| 289 PicasaDataProvider::UniquifyNames(albums, | 289 PicasaDataProvider::UniquifyNames(albums, |
| 290 &picasa_data_provider_->album_map_); | 290 &picasa_data_provider_->album_map_); |
| 291 PicasaDataProvider::UniquifyNames(folders, | 291 PicasaDataProvider::UniquifyNames(folders, |
| 292 &picasa_data_provider_->folder_map_); | 292 &picasa_data_provider_->folder_map_); |
| 293 picasa_data_provider_->albums_images_ = albums_images; | 293 picasa_data_provider_->albums_images_ = albums_images; |
| 294 picasa_data_provider_->state_ = | 294 picasa_data_provider_->state_ = |
| 295 PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE; | 295 PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE; |
| 296 } | 296 } |
| 297 | 297 |
| 298 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { | 298 void VerifyFolderDirectoryList( |
| 299 const std::vector<std::unique_ptr<TestFolder>>& test_folders) { |
| 299 FileSystemOperation::FileEntryList contents; | 300 FileSystemOperation::FileEntryList contents; |
| 300 FileSystemURL url = CreateURL(kPicasaDirFolders); | 301 FileSystemURL url = CreateURL(kPicasaDirFolders); |
| 301 bool completed = false; | 302 bool completed = false; |
| 302 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 303 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 303 | 304 |
| 304 ASSERT_TRUE(completed); | 305 ASSERT_TRUE(completed); |
| 305 ASSERT_EQ(test_folders.size(), contents.size()); | 306 ASSERT_EQ(test_folders.size(), contents.size()); |
| 306 | 307 |
| 307 for (size_t i = 0; i < contents.size(); ++i) { | 308 for (size_t i = 0; i < contents.size(); ++i) { |
| 308 EXPECT_TRUE(contents[i].is_directory); | 309 EXPECT_TRUE(contents[i].is_directory); |
| 309 | 310 |
| 310 FileSystemOperation::FileEntryList folder_contents; | 311 FileSystemOperation::FileEntryList folder_contents; |
| 311 FileSystemURL folder_url = CreateURL( | 312 FileSystemURL folder_url = CreateURL( |
| 312 std::string(kPicasaDirFolders) + "/" + | 313 std::string(kPicasaDirFolders) + "/" + |
| 313 base::FilePath(contents[i].name).AsUTF8Unsafe()); | 314 base::FilePath(contents[i].name).AsUTF8Unsafe()); |
| 314 bool folder_read_completed = false; | 315 bool folder_read_completed = false; |
| 315 ReadDirectoryTestHelper(operation_runner(), folder_url, &folder_contents, | 316 ReadDirectoryTestHelper(operation_runner(), folder_url, &folder_contents, |
| 316 &folder_read_completed); | 317 &folder_read_completed); |
| 317 | 318 |
| 318 EXPECT_TRUE(folder_read_completed); | 319 EXPECT_TRUE(folder_read_completed); |
| 319 | 320 |
| 320 const std::set<std::string>& image_filenames = | 321 const std::set<std::string>& image_filenames = |
| 321 test_folders[i]->image_filenames(); | 322 test_folders[i]->image_filenames(); |
| 322 | 323 |
| 323 EXPECT_EQ(image_filenames.size(), folder_contents.size()); | 324 EXPECT_EQ(image_filenames.size(), folder_contents.size()); |
| 324 | 325 |
| 325 for (FileSystemOperation::FileEntryList::const_iterator file_it = | 326 for (auto file_it = folder_contents.begin(); |
| 326 folder_contents.begin(); file_it != folder_contents.end(); | 327 file_it != folder_contents.end(); ++file_it) { |
| 327 ++file_it) { | |
| 328 EXPECT_EQ(1u, image_filenames.count( | 328 EXPECT_EQ(1u, image_filenames.count( |
| 329 base::FilePath(file_it->name).AsUTF8Unsafe())); | 329 base::FilePath(file_it->name).AsUTF8Unsafe())); |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 std::string DateToPathString(const base::Time& time) { | 334 std::string DateToPathString(const base::Time& time) { |
| 335 return PicasaDataProvider::DateToPathString(time); | 335 return PicasaDataProvider::DateToPathString(time); |
| 336 } | 336 } |
| 337 | 337 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 393 |
| 394 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 }; |
| 395 base::Time shortday; | 395 base::Time shortday; |
| 396 EXPECT_TRUE(base::Time::FromLocalExploded(exploded_shortday, &shortday)); | 396 EXPECT_TRUE(base::Time::FromLocalExploded(exploded_shortday, &shortday)); |
| 397 | 397 |
| 398 EXPECT_EQ("2013-04-16", DateToPathString(shortmonth)); | 398 EXPECT_EQ("2013-04-16", DateToPathString(shortmonth)); |
| 399 EXPECT_EQ("2013-11-03", DateToPathString(shortday)); | 399 EXPECT_EQ("2013-11-03", DateToPathString(shortday)); |
| 400 } | 400 } |
| 401 | 401 |
| 402 TEST_F(PicasaFileUtilTest, NameDeduplication) { | 402 TEST_F(PicasaFileUtilTest, NameDeduplication) { |
| 403 ScopedVector<TestFolder> test_folders; | 403 std::vector<std::unique_ptr<TestFolder>> test_folders; |
| 404 std::vector<std::string> expected_names; | 404 std::vector<std::string> expected_names; |
| 405 | 405 |
| 406 base::Time test_date; | 406 base::Time test_date; |
| 407 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); | 407 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 408 base::Time test_date_2 = test_date - base::TimeDelta::FromDays(1); | 408 base::Time test_date_2 = test_date - base::TimeDelta::FromDays(1); |
| 409 | 409 |
| 410 std::string test_date_string = DateToPathString(test_date); | 410 std::string test_date_string = DateToPathString(test_date); |
| 411 std::string test_date_2_string = DateToPathString(test_date_2); | 411 std::string test_date_2_string = DateToPathString(test_date_2); |
| 412 | 412 |
| 413 test_folders.push_back( | 413 test_folders.push_back( |
| 414 new TestFolder("diff_date", test_date_2, "uuid3", 0, 0)); | 414 base::MakeUnique<TestFolder>("diff_date", test_date_2, "uuid3", 0, 0)); |
| 415 expected_names.push_back("diff_date " + test_date_2_string); | 415 expected_names.push_back("diff_date " + test_date_2_string); |
| 416 | 416 |
| 417 test_folders.push_back( | 417 test_folders.push_back( |
| 418 new TestFolder("diff_date", test_date, "uuid2", 0, 0)); | 418 base::MakeUnique<TestFolder>("diff_date", test_date, "uuid2", 0, 0)); |
| 419 expected_names.push_back("diff_date " + test_date_string); | 419 expected_names.push_back("diff_date " + test_date_string); |
| 420 | 420 |
| 421 test_folders.push_back( | 421 test_folders.push_back( |
| 422 new TestFolder("duplicate", test_date, "uuid4", 0, 0)); | 422 base::MakeUnique<TestFolder>("duplicate", test_date, "uuid4", 0, 0)); |
| 423 expected_names.push_back("duplicate " + test_date_string + " (1)"); | 423 expected_names.push_back("duplicate " + test_date_string + " (1)"); |
| 424 | 424 |
| 425 test_folders.push_back( | 425 test_folders.push_back( |
| 426 new TestFolder("duplicate", test_date, "uuid5", 0, 0)); | 426 base::MakeUnique<TestFolder>("duplicate", test_date, "uuid5", 0, 0)); |
| 427 expected_names.push_back("duplicate " + test_date_string + " (2)"); | 427 expected_names.push_back("duplicate " + test_date_string + " (2)"); |
| 428 | 428 |
| 429 test_folders.push_back( | 429 test_folders.push_back( |
| 430 new TestFolder("unique_name", test_date, "uuid1", 0, 0)); | 430 base::MakeUnique<TestFolder>("unique_name", test_date, "uuid1", 0, 0)); |
| 431 expected_names.push_back("unique_name " + test_date_string); | 431 expected_names.push_back("unique_name " + test_date_string); |
| 432 | 432 |
| 433 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); | 433 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 434 | 434 |
| 435 FileSystemOperation::FileEntryList contents; | 435 FileSystemOperation::FileEntryList contents; |
| 436 FileSystemURL url = CreateURL(kPicasaDirFolders); | 436 FileSystemURL url = CreateURL(kPicasaDirFolders); |
| 437 bool completed = false; | 437 bool completed = false; |
| 438 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 438 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 439 | 439 |
| 440 ASSERT_TRUE(completed); | 440 ASSERT_TRUE(completed); |
| 441 ASSERT_EQ(expected_names.size(), contents.size()); | 441 ASSERT_EQ(expected_names.size(), contents.size()); |
| 442 for (size_t i = 0; i < contents.size(); ++i) { | 442 for (size_t i = 0; i < contents.size(); ++i) { |
| 443 EXPECT_EQ(expected_names[i], | 443 EXPECT_EQ(expected_names[i], |
| 444 base::FilePath(contents[i].name).AsUTF8Unsafe()); | 444 base::FilePath(contents[i].name).AsUTF8Unsafe()); |
| 445 EXPECT_TRUE(contents[i].is_directory); | 445 EXPECT_TRUE(contents[i].is_directory); |
| 446 } | 446 } |
| 447 } | 447 } |
| 448 | 448 |
| 449 TEST_F(PicasaFileUtilTest, RootFolders) { | 449 TEST_F(PicasaFileUtilTest, RootFolders) { |
| 450 ScopedVector<TestFolder> empty_folders_list; | 450 std::vector<std::unique_ptr<TestFolder>> empty_folders_list; |
| 451 SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap()); | 451 SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 452 | 452 |
| 453 FileSystemOperation::FileEntryList contents; | 453 FileSystemOperation::FileEntryList contents; |
| 454 FileSystemURL url = CreateURL(""); | 454 FileSystemURL url = CreateURL(""); |
| 455 bool completed = false; | 455 bool completed = false; |
| 456 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 456 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 457 | 457 |
| 458 ASSERT_TRUE(completed); | 458 ASSERT_TRUE(completed); |
| 459 ASSERT_EQ(2u, contents.size()); | 459 ASSERT_EQ(2u, contents.size()); |
| 460 | 460 |
| 461 EXPECT_TRUE(contents.front().is_directory); | 461 EXPECT_TRUE(contents.front().is_directory); |
| 462 EXPECT_TRUE(contents.back().is_directory); | 462 EXPECT_TRUE(contents.back().is_directory); |
| 463 | 463 |
| 464 EXPECT_EQ(FILE_PATH_LITERAL("albums"), contents.front().name); | 464 EXPECT_EQ(FILE_PATH_LITERAL("albums"), contents.front().name); |
| 465 EXPECT_EQ(FILE_PATH_LITERAL("folders"), contents.back().name); | 465 EXPECT_EQ(FILE_PATH_LITERAL("folders"), contents.back().name); |
| 466 } | 466 } |
| 467 | 467 |
| 468 TEST_F(PicasaFileUtilTest, NonexistentFolder) { | 468 TEST_F(PicasaFileUtilTest, NonexistentFolder) { |
| 469 ScopedVector<TestFolder> empty_folders_list; | 469 std::vector<std::unique_ptr<TestFolder>> empty_folders_list; |
| 470 SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap()); | 470 SetupFolders(&empty_folders_list, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 471 | 471 |
| 472 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo"); | 472 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo"); |
| 473 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar"); | 473 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar"); |
| 474 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar/baz"); | 474 TestNonexistentDirectory(std::string(kPicasaDirFolders) + "/foo/bar/baz"); |
| 475 } | 475 } |
| 476 | 476 |
| 477 TEST_F(PicasaFileUtilTest, FolderContentsTrivial) { | 477 TEST_F(PicasaFileUtilTest, FolderContentsTrivial) { |
| 478 ScopedVector<TestFolder> test_folders; | 478 std::vector<std::unique_ptr<TestFolder>> test_folders; |
| 479 base::Time test_date; | 479 base::Time test_date; |
| 480 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); | 480 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 481 | 481 |
| 482 test_folders.push_back( | 482 test_folders.push_back(base::MakeUnique<TestFolder>( |
| 483 new TestFolder("folder-1-empty", test_date, "uid-empty", 0, 0)); | 483 "folder-1-empty", test_date, "uid-empty", 0, 0)); |
| 484 test_folders.push_back( | 484 test_folders.push_back(base::MakeUnique<TestFolder>( |
| 485 new TestFolder("folder-2-images", test_date, "uid-images", 5, 0)); | 485 "folder-2-images", test_date, "uid-images", 5, 0)); |
| 486 test_folders.push_back( | 486 test_folders.push_back(base::MakeUnique<TestFolder>( |
| 487 new TestFolder("folder-3-nonimages", test_date, "uid-nonimages", 0, 5)); | 487 "folder-3-nonimages", test_date, "uid-nonimages", 0, 5)); |
| 488 test_folders.push_back( | 488 test_folders.push_back(base::MakeUnique<TestFolder>( |
| 489 new TestFolder("folder-4-both", test_date, "uid-both", 5, 5)); | 489 "folder-4-both", test_date, "uid-both", 5, 5)); |
| 490 | 490 |
| 491 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); | 491 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 492 VerifyFolderDirectoryList(test_folders); | 492 VerifyFolderDirectoryList(test_folders); |
| 493 } | 493 } |
| 494 | 494 |
| 495 TEST_F(PicasaFileUtilTest, FolderWithManyFiles) { | 495 TEST_F(PicasaFileUtilTest, FolderWithManyFiles) { |
| 496 ScopedVector<TestFolder> test_folders; | 496 std::vector<std::unique_ptr<TestFolder>> test_folders; |
| 497 base::Time test_date; | 497 base::Time test_date; |
| 498 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); | 498 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 499 | 499 |
| 500 test_folders.push_back( | 500 test_folders.push_back(base::MakeUnique<TestFolder>( |
| 501 new TestFolder("folder-many-files", test_date, "uid-both", 50, 50)); | 501 "folder-many-files", test_date, "uid-both", 50, 50)); |
| 502 | 502 |
| 503 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); | 503 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 504 VerifyFolderDirectoryList(test_folders); | 504 VerifyFolderDirectoryList(test_folders); |
| 505 } | 505 } |
| 506 | 506 |
| 507 TEST_F(PicasaFileUtilTest, ManyFolders) { | 507 TEST_F(PicasaFileUtilTest, ManyFolders) { |
| 508 ScopedVector<TestFolder> test_folders; | 508 std::vector<std::unique_ptr<TestFolder>> test_folders; |
| 509 base::Time test_date; | 509 base::Time test_date; |
| 510 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); | 510 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 511 | 511 |
| 512 for (unsigned int i = 0; i < 50; ++i) { | 512 for (unsigned int i = 0; i < 50; ++i) { |
| 513 base::Time date = test_date - base::TimeDelta::FromDays(i); | 513 base::Time date = test_date - base::TimeDelta::FromDays(i); |
| 514 | 514 |
| 515 test_folders.push_back( | 515 test_folders.push_back(base::MakeUnique<TestFolder>( |
| 516 new TestFolder(base::StringPrintf("folder-%05d", i), | 516 base::StringPrintf("folder-%05d", i), date, |
| 517 date, | 517 base::StringPrintf("uid%05d", i), i % 5, i % 3)); |
| 518 base::StringPrintf("uid%05d", i), i % 5, i % 3)); | |
| 519 } | 518 } |
| 520 | 519 |
| 521 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); | 520 SetupFolders(&test_folders, std::vector<AlbumInfo>(), AlbumImagesMap()); |
| 522 VerifyFolderDirectoryList(test_folders); | 521 VerifyFolderDirectoryList(test_folders); |
| 523 } | 522 } |
| 524 | 523 |
| 525 TEST_F(PicasaFileUtilTest, AlbumExistence) { | 524 TEST_F(PicasaFileUtilTest, AlbumExistence) { |
| 526 ScopedVector<TestFolder> test_folders; | 525 std::vector<std::unique_ptr<TestFolder>> test_folders; |
| 527 base::Time test_date; | 526 base::Time test_date; |
| 528 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); | 527 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 529 | 528 |
| 530 std::vector<AlbumInfo> albums; | 529 std::vector<AlbumInfo> albums; |
| 531 AlbumInfo info; | 530 AlbumInfo info; |
| 532 info.name = "albumname"; | 531 info.name = "albumname"; |
| 533 info.uid = "albumuid"; | 532 info.uid = "albumuid"; |
| 534 info.timestamp = test_date; | 533 info.timestamp = test_date; |
| 535 albums.push_back(info); | 534 albums.push_back(info); |
| 536 | 535 |
| 537 AlbumImagesMap albums_images; | 536 AlbumImagesMap albums_images; |
| 538 albums_images[info.uid] = AlbumImages(); | 537 albums_images[info.uid] = AlbumImages(); |
| 539 | 538 |
| 540 SetupFolders(&test_folders, albums, albums_images); | 539 SetupFolders(&test_folders, albums, albums_images); |
| 541 | 540 |
| 542 TestEmptyDirectory(std::string(kPicasaDirAlbums) + "/albumname 2013-04-16"); | 541 TestEmptyDirectory(std::string(kPicasaDirAlbums) + "/albumname 2013-04-16"); |
| 543 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + | 542 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + |
| 544 "/albumname 2013-04-16/toodeep"); | 543 "/albumname 2013-04-16/toodeep"); |
| 545 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + "/wrongname"); | 544 TestNonexistentDirectory(std::string(kPicasaDirAlbums) + "/wrongname"); |
| 546 } | 545 } |
| 547 | 546 |
| 548 TEST_F(PicasaFileUtilTest, AlbumContents) { | 547 TEST_F(PicasaFileUtilTest, AlbumContents) { |
| 549 ScopedVector<TestFolder> test_folders; | 548 std::vector<std::unique_ptr<TestFolder>> test_folders; |
| 550 base::Time test_date; | 549 base::Time test_date; |
| 551 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); | 550 EXPECT_TRUE(base::Time::FromLocalExploded(test_date_exploded, &test_date)); |
| 552 | 551 |
| 553 std::vector<AlbumInfo> albums; | 552 std::vector<AlbumInfo> albums; |
| 554 AlbumInfo info; | 553 AlbumInfo info; |
| 555 info.name = "albumname"; | 554 info.name = "albumname"; |
| 556 info.uid = "albumuid"; | 555 info.uid = "albumuid"; |
| 557 info.timestamp = test_date; | 556 info.timestamp = test_date; |
| 558 albums.push_back(info); | 557 albums.push_back(info); |
| 559 | 558 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 operation_runner()->CreateSnapshotFile( | 592 operation_runner()->CreateSnapshotFile( |
| 594 CreateURL(std::string(kPicasaDirAlbums) + | 593 CreateURL(std::string(kPicasaDirAlbums) + |
| 595 "/albumname 2013-04-16/mapped_name.jpg"), | 594 "/albumname 2013-04-16/mapped_name.jpg"), |
| 596 snapshot_callback); | 595 snapshot_callback); |
| 597 loop.Run(); | 596 loop.Run(); |
| 598 EXPECT_EQ(base::File::FILE_OK, error); | 597 EXPECT_EQ(base::File::FILE_OK, error); |
| 599 EXPECT_EQ(image_path, platform_path_result); | 598 EXPECT_EQ(image_path, platform_path_result); |
| 600 } | 599 } |
| 601 | 600 |
| 602 } // namespace picasa | 601 } // namespace picasa |
| OLD | NEW |