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