| 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 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "chrome/browser/media_galleries/fileapi/async_file_util_test_helper.h" |
| 14 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" | 15 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" |
| 15 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 16 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
| 16 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_album_table_reade
r.h" | 17 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_album_table_reade
r.h" |
| 17 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" | 18 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" |
| 18 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" | 19 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" |
| 19 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_constants.h" | 20 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_constants.h" |
| 20 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_test_helper.h" | 21 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_test_helper.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "webkit/browser/fileapi/async_file_util_adapter.h" | 23 #include "webkit/browser/fileapi/async_file_util_adapter.h" |
| 23 #include "webkit/browser/fileapi/external_mount_points.h" | 24 #include "webkit/browser/fileapi/external_mount_points.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 140 } |
| 140 | 141 |
| 141 scoped_ptr<PicasaDataProvider> data_provider_; | 142 scoped_ptr<PicasaDataProvider> data_provider_; |
| 142 }; | 143 }; |
| 143 | 144 |
| 144 class TestMediaFileSystemMountPointProvider | 145 class TestMediaFileSystemMountPointProvider |
| 145 : public chrome::MediaFileSystemMountPointProvider { | 146 : public chrome::MediaFileSystemMountPointProvider { |
| 146 public: | 147 public: |
| 147 TestMediaFileSystemMountPointProvider( | 148 TestMediaFileSystemMountPointProvider( |
| 148 const base::FilePath& profile_path, | 149 const base::FilePath& profile_path, |
| 149 scoped_ptr<PicasaFileUtil> picasa_file_util) | 150 PicasaFileUtil* picasa_file_util) |
| 150 : chrome::MediaFileSystemMountPointProvider(profile_path), | 151 : chrome::MediaFileSystemMountPointProvider(profile_path), |
| 151 test_file_util_(new fileapi::AsyncFileUtilAdapter( | 152 test_file_util_(picasa_file_util) { |
| 152 picasa_file_util.release())) { | |
| 153 } | 153 } |
| 154 | 154 |
| 155 virtual fileapi::AsyncFileUtil* | 155 virtual fileapi::AsyncFileUtil* |
| 156 GetAsyncFileUtil(fileapi::FileSystemType type) OVERRIDE { | 156 GetAsyncFileUtil(fileapi::FileSystemType type) OVERRIDE { |
| 157 if (type != fileapi::kFileSystemTypePicasa) | 157 if (type != fileapi::kFileSystemTypePicasa) |
| 158 return NULL; | 158 return NULL; |
| 159 | 159 |
| 160 return test_file_util_.get(); | 160 return test_file_util_.get(); |
| 161 } | 161 } |
| 162 | 162 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 179 public: | 179 public: |
| 180 PicasaFileUtilTest() {} | 180 PicasaFileUtilTest() {} |
| 181 virtual ~PicasaFileUtilTest() {} | 181 virtual ~PicasaFileUtilTest() {} |
| 182 | 182 |
| 183 virtual void SetUp() OVERRIDE { | 183 virtual void SetUp() OVERRIDE { |
| 184 test_helper_.reset(new PmpTestHelper(kPicasaAlbumTableName)); | 184 test_helper_.reset(new PmpTestHelper(kPicasaAlbumTableName)); |
| 185 ASSERT_TRUE(test_helper_->Init()); | 185 ASSERT_TRUE(test_helper_->Init()); |
| 186 | 186 |
| 187 scoped_ptr<PicasaDataProvider> data_provider( | 187 scoped_ptr<PicasaDataProvider> data_provider( |
| 188 new PicasaDataProvider(test_helper_->GetTempDirPath())); | 188 new PicasaDataProvider(test_helper_->GetTempDirPath())); |
| 189 scoped_ptr<PicasaFileUtil> file_util(new TestPicasaFileUtil( | |
| 190 data_provider.Pass())); | |
| 191 | 189 |
| 192 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 190 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 193 | 191 |
| 194 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 192 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
| 195 new quota::MockSpecialStoragePolicy(); | 193 new quota::MockSpecialStoragePolicy(); |
| 196 | 194 |
| 197 ScopedVector<fileapi::FileSystemMountPointProvider> additional_providers; | 195 ScopedVector<fileapi::FileSystemMountPointProvider> additional_providers; |
| 198 additional_providers.push_back( | 196 additional_providers.push_back(new TestMediaFileSystemMountPointProvider( |
| 199 new TestMediaFileSystemMountPointProvider(profile_dir_.path(), | 197 profile_dir_.path(), |
| 200 file_util.Pass())); | 198 new TestPicasaFileUtil(data_provider.Pass()))); |
| 201 | 199 |
| 202 file_system_context_ = new fileapi::FileSystemContext( | 200 file_system_context_ = new fileapi::FileSystemContext( |
| 203 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), | 201 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), |
| 204 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 202 fileapi::ExternalMountPoints::CreateRefCounted().get(), |
| 205 storage_policy, | 203 storage_policy, |
| 206 NULL, | 204 NULL, |
| 207 additional_providers.Pass(), | 205 additional_providers.Pass(), |
| 208 profile_dir_.path(), | 206 profile_dir_.path(), |
| 209 fileapi::CreateAllowFileAccessOptions()); | 207 fileapi::CreateAllowFileAccessOptions()); |
| 210 } | 208 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 378 |
| 381 scoped_ptr<chrome::MediaPathFilter> media_path_filter( | 379 scoped_ptr<chrome::MediaPathFilter> media_path_filter( |
| 382 new chrome::MediaPathFilter()); | 380 new chrome::MediaPathFilter()); |
| 383 | 381 |
| 384 operation_context->SetUserValue( | 382 operation_context->SetUserValue( |
| 385 chrome::MediaFileSystemMountPointProvider::kMediaPathFilterKey, | 383 chrome::MediaFileSystemMountPointProvider::kMediaPathFilterKey, |
| 386 media_path_filter.get()); | 384 media_path_filter.get()); |
| 387 | 385 |
| 388 scoped_ptr<PicasaDataProvider> data_provider( | 386 scoped_ptr<PicasaDataProvider> data_provider( |
| 389 new TestPicasaDataProvider(std::vector<AlbumInfo>(), folders)); | 387 new TestPicasaDataProvider(std::vector<AlbumInfo>(), folders)); |
| 390 TestPicasaFileUtil file_util(data_provider.Pass()); | 388 chrome::AsyncFileUtilTestHelper test_file_util( |
| 389 new TestPicasaFileUtil(data_provider.Pass())); |
| 391 | 390 |
| 392 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enumerator = | 391 fileapi::AsyncFileUtil::EntryList file_list; |
| 393 file_util.CreateFileEnumerator(operation_context.get(), | 392 bool has_more = false; |
| 394 CreateURL("folders")); | 393 base::PlatformFileError error = test_file_util.ReadDirectorySync( |
| 394 operation_context.get(), |
| 395 CreateURL(kPicasaDirFolders), |
| 396 &file_list, |
| 397 &has_more); |
| 398 ASSERT_EQ(error, base::PLATFORM_FILE_OK); |
| 395 | 399 |
| 396 for (unsigned int i = 0; i < expected_names.size(); ++i) { | 400 for (size_t i = 0; i < file_list.size(); ++i) { |
| 397 base::FilePath path = file_enumerator->Next(); | 401 ASSERT_FALSE(file_list[i].name.empty()); |
| 398 | 402 EXPECT_EQ(expected_names[i], |
| 399 ASSERT_TRUE(!path.empty()); | 403 base::FilePath(file_list[i].name).AsUTF8Unsafe()); |
| 400 EXPECT_EQ(expected_names[i], path.BaseName().AsUTF8Unsafe()); | 404 EXPECT_EQ(folders[i].timestamp, file_list[i].last_modified_time); |
| 401 EXPECT_EQ(folders[i].timestamp, file_enumerator->LastModifiedTime()); | 405 EXPECT_TRUE(file_list[i].is_directory); |
| 402 EXPECT_TRUE(file_enumerator->IsDirectory()); | |
| 403 } | 406 } |
| 404 } | 407 } |
| 405 | 408 |
| 406 TEST_F(PicasaFileUtilTest, RootFolders) { | 409 TEST_F(PicasaFileUtilTest, RootFolders) { |
| 407 FileSystemOperation::FileEntryList contents; | 410 FileSystemOperation::FileEntryList contents; |
| 408 FileSystemURL url = CreateURL(""); | 411 FileSystemURL url = CreateURL(""); |
| 409 bool completed = false; | 412 bool completed = false; |
| 410 NewOperation(url)->ReadDirectory( | 413 NewOperation(url)->ReadDirectory( |
| 411 url, base::Bind(&DidReadDirectory, &contents, &completed)); | 414 url, base::Bind(&DidReadDirectory, &contents, &completed)); |
| 412 base::MessageLoop::current()->RunUntilIdle(); | 415 base::MessageLoop::current()->RunUntilIdle(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 new TestFolder(base::StringPrintf("folder-%05d", i), | 477 new TestFolder(base::StringPrintf("folder-%05d", i), |
| 475 date, | 478 date, |
| 476 base::StringPrintf("uid%05d", i), i % 5, i % 3)); | 479 base::StringPrintf("uid%05d", i), i % 5, i % 3)); |
| 477 } | 480 } |
| 478 | 481 |
| 479 SetupFolders(&test_folders); | 482 SetupFolders(&test_folders); |
| 480 VerifyFolderDirectoryList(test_folders); | 483 VerifyFolderDirectoryList(test_folders); |
| 481 } | 484 } |
| 482 | 485 |
| 483 } // namespace chrome | 486 } // namespace chrome |
| OLD | NEW |