| 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 <map> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/test/mock_special_storage_policy.h" | 23 #include "content/public/test/mock_special_storage_policy.h" |
| 24 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread.h" |
| 25 #include "content/public/test/test_file_system_options.h" | 25 #include "content/public/test/test_file_system_options.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "webkit/browser/fileapi/async_file_util.h" | 27 #include "webkit/browser/fileapi/async_file_util.h" |
| 28 #include "webkit/browser/fileapi/external_mount_points.h" | 28 #include "webkit/browser/fileapi/external_mount_points.h" |
| 29 #include "webkit/browser/fileapi/file_system_context.h" | 29 #include "webkit/browser/fileapi/file_system_context.h" |
| 30 #include "webkit/browser/fileapi/file_system_operation_context.h" | 30 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 31 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 31 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 32 | 32 |
| 33 using fileapi::FileSystemOperationContext; | 33 using storage::FileSystemOperationContext; |
| 34 using fileapi::FileSystemOperation; | 34 using storage::FileSystemOperation; |
| 35 using fileapi::FileSystemURL; | 35 using storage::FileSystemURL; |
| 36 | 36 |
| 37 namespace iphoto { | 37 namespace iphoto { |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 void ReadDirectoryTestHelperCallback( | 41 void ReadDirectoryTestHelperCallback( |
| 42 base::RunLoop* run_loop, | 42 base::RunLoop* run_loop, |
| 43 FileSystemOperation::FileEntryList* contents, | 43 FileSystemOperation::FileEntryList* contents, |
| 44 bool* completed, | 44 bool* completed, |
| 45 base::File::Error error, | 45 base::File::Error error, |
| 46 const FileSystemOperation::FileEntryList& file_list, | 46 const FileSystemOperation::FileEntryList& file_list, |
| 47 bool has_more) { | 47 bool has_more) { |
| 48 DCHECK(!*completed); | 48 DCHECK(!*completed); |
| 49 *completed = !has_more && error == base::File::FILE_OK; | 49 *completed = !has_more && error == base::File::FILE_OK; |
| 50 *contents = file_list; | 50 *contents = file_list; |
| 51 run_loop->Quit(); | 51 run_loop->Quit(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ReadDirectoryTestHelper(fileapi::FileSystemOperationRunner* runner, | 54 void ReadDirectoryTestHelper(storage::FileSystemOperationRunner* runner, |
| 55 const FileSystemURL& url, | 55 const FileSystemURL& url, |
| 56 FileSystemOperation::FileEntryList* contents, | 56 FileSystemOperation::FileEntryList* contents, |
| 57 bool* completed) { | 57 bool* completed) { |
| 58 DCHECK(contents); | 58 DCHECK(contents); |
| 59 DCHECK(completed); | 59 DCHECK(completed); |
| 60 base::RunLoop run_loop; | 60 base::RunLoop run_loop; |
| 61 runner->ReadDirectory( | 61 runner->ReadDirectory( |
| 62 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, | 62 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, |
| 63 completed)); | 63 completed)); |
| 64 run_loop.Run(); | 64 run_loop.Run(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 class TestMediaFileSystemBackend : public MediaFileSystemBackend { | 140 class TestMediaFileSystemBackend : public MediaFileSystemBackend { |
| 141 public: | 141 public: |
| 142 TestMediaFileSystemBackend(const base::FilePath& profile_path, | 142 TestMediaFileSystemBackend(const base::FilePath& profile_path, |
| 143 IPhotoFileUtil* iphoto_file_util) | 143 IPhotoFileUtil* iphoto_file_util) |
| 144 : MediaFileSystemBackend( | 144 : MediaFileSystemBackend( |
| 145 profile_path, | 145 profile_path, |
| 146 MediaFileSystemBackend::MediaTaskRunner().get()), | 146 MediaFileSystemBackend::MediaTaskRunner().get()), |
| 147 test_file_util_(iphoto_file_util) {} | 147 test_file_util_(iphoto_file_util) {} |
| 148 | 148 |
| 149 virtual fileapi::AsyncFileUtil* | 149 virtual storage::AsyncFileUtil* GetAsyncFileUtil( |
| 150 GetAsyncFileUtil(fileapi::FileSystemType type) OVERRIDE { | 150 storage::FileSystemType type) OVERRIDE { |
| 151 if (type != fileapi::kFileSystemTypeIphoto) | 151 if (type != storage::kFileSystemTypeIphoto) |
| 152 return NULL; | 152 return NULL; |
| 153 | 153 |
| 154 return test_file_util_.get(); | 154 return test_file_util_.get(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 private: | 157 private: |
| 158 scoped_ptr<fileapi::AsyncFileUtil> test_file_util_; | 158 scoped_ptr<storage::AsyncFileUtil> test_file_util_; |
| 159 }; | 159 }; |
| 160 | 160 |
| 161 class IPhotoFileUtilTest : public testing::Test { | 161 class IPhotoFileUtilTest : public testing::Test { |
| 162 public: | 162 public: |
| 163 IPhotoFileUtilTest() | 163 IPhotoFileUtilTest() |
| 164 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 164 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 165 } | 165 } |
| 166 virtual ~IPhotoFileUtilTest() {} | 166 virtual ~IPhotoFileUtilTest() {} |
| 167 | 167 |
| 168 void SetUpDataProvider() { | 168 void SetUpDataProvider() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 181 0)); | 181 0)); |
| 182 | 182 |
| 183 iphoto_data_provider_.reset( | 183 iphoto_data_provider_.reset( |
| 184 new TestIPhotoDataProvider(fake_library_dir_.path())); | 184 new TestIPhotoDataProvider(fake_library_dir_.path())); |
| 185 } | 185 } |
| 186 | 186 |
| 187 virtual void SetUp() OVERRIDE { | 187 virtual void SetUp() OVERRIDE { |
| 188 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 188 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 189 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); | 189 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); |
| 190 | 190 |
| 191 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 191 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = |
| 192 new content::MockSpecialStoragePolicy(); | 192 new content::MockSpecialStoragePolicy(); |
| 193 | 193 |
| 194 // Initialize fake IPhotoDataProvider on media task runner thread. | 194 // Initialize fake IPhotoDataProvider on media task runner thread. |
| 195 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 195 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 196 FROM_HERE, | 196 FROM_HERE, |
| 197 base::Bind(&IPhotoFileUtilTest::SetUpDataProvider, | 197 base::Bind(&IPhotoFileUtilTest::SetUpDataProvider, |
| 198 base::Unretained(this))); | 198 base::Unretained(this))); |
| 199 base::WaitableEvent event(true, false /* initially_signalled */); | 199 base::WaitableEvent event(true, false /* initially_signalled */); |
| 200 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 200 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 201 FROM_HERE, | 201 FROM_HERE, |
| 202 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 202 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 203 event.Wait(); | 203 event.Wait(); |
| 204 | 204 |
| 205 media_path_filter_.reset(new MediaPathFilter()); | 205 media_path_filter_.reset(new MediaPathFilter()); |
| 206 ScopedVector<fileapi::FileSystemBackend> additional_providers; | 206 ScopedVector<storage::FileSystemBackend> additional_providers; |
| 207 additional_providers.push_back(new TestMediaFileSystemBackend( | 207 additional_providers.push_back(new TestMediaFileSystemBackend( |
| 208 profile_dir_.path(), | 208 profile_dir_.path(), |
| 209 new TestIPhotoFileUtil(media_path_filter_.get(), | 209 new TestIPhotoFileUtil(media_path_filter_.get(), |
| 210 iphoto_data_provider_.get()))); | 210 iphoto_data_provider_.get()))); |
| 211 | 211 |
| 212 file_system_context_ = new fileapi::FileSystemContext( | 212 file_system_context_ = new storage::FileSystemContext( |
| 213 base::MessageLoopProxy::current().get(), | 213 base::MessageLoopProxy::current().get(), |
| 214 base::MessageLoopProxy::current().get(), | 214 base::MessageLoopProxy::current().get(), |
| 215 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 215 storage::ExternalMountPoints::CreateRefCounted().get(), |
| 216 storage_policy.get(), | 216 storage_policy.get(), |
| 217 NULL, | 217 NULL, |
| 218 additional_providers.Pass(), | 218 additional_providers.Pass(), |
| 219 std::vector<fileapi::URLRequestAutoMountHandler>(), | 219 std::vector<storage::URLRequestAutoMountHandler>(), |
| 220 profile_dir_.path(), | 220 profile_dir_.path(), |
| 221 content::CreateAllowFileAccessOptions()); | 221 content::CreateAllowFileAccessOptions()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 protected: | 224 protected: |
| 225 void TestNonexistentFolder(const std::string& path_append) { | 225 void TestNonexistentFolder(const std::string& path_append) { |
| 226 FileSystemOperation::FileEntryList contents; | 226 FileSystemOperation::FileEntryList contents; |
| 227 FileSystemURL url = CreateURL(path_append); | 227 FileSystemURL url = CreateURL(path_append); |
| 228 bool completed = false; | 228 bool completed = false; |
| 229 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 229 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 230 | 230 |
| 231 ASSERT_FALSE(completed); | 231 ASSERT_FALSE(completed); |
| 232 } | 232 } |
| 233 | 233 |
| 234 FileSystemURL CreateURL(const std::string& path) const { | 234 FileSystemURL CreateURL(const std::string& path) const { |
| 235 base::FilePath virtual_path = | 235 base::FilePath virtual_path = |
| 236 ImportedMediaGalleryRegistry::GetInstance()->ImportedRoot(); | 236 ImportedMediaGalleryRegistry::GetInstance()->ImportedRoot(); |
| 237 virtual_path = virtual_path.AppendASCII("iphoto"); | 237 virtual_path = virtual_path.AppendASCII("iphoto"); |
| 238 virtual_path = virtual_path.AppendASCII(path); | 238 virtual_path = virtual_path.AppendASCII(path); |
| 239 return file_system_context_->CreateCrackedFileSystemURL( | 239 return file_system_context_->CreateCrackedFileSystemURL( |
| 240 GURL("http://www.example.com"), fileapi::kFileSystemTypeIphoto, | 240 GURL("http://www.example.com"), |
| 241 storage::kFileSystemTypeIphoto, |
| 241 virtual_path); | 242 virtual_path); |
| 242 } | 243 } |
| 243 | 244 |
| 244 fileapi::FileSystemOperationRunner* operation_runner() const { | 245 storage::FileSystemOperationRunner* operation_runner() const { |
| 245 return file_system_context_->operation_runner(); | 246 return file_system_context_->operation_runner(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 scoped_refptr<fileapi::FileSystemContext> file_system_context() const { | 249 scoped_refptr<storage::FileSystemContext> file_system_context() const { |
| 249 return file_system_context_; | 250 return file_system_context_; |
| 250 } | 251 } |
| 251 | 252 |
| 252 TestIPhotoDataProvider* data_provider() const { | 253 TestIPhotoDataProvider* data_provider() const { |
| 253 return iphoto_data_provider_.get(); | 254 return iphoto_data_provider_.get(); |
| 254 } | 255 } |
| 255 | 256 |
| 256 private: | 257 private: |
| 257 base::MessageLoop message_loop_; | 258 base::MessageLoop message_loop_; |
| 258 content::TestBrowserThread io_thread_; | 259 content::TestBrowserThread io_thread_; |
| 259 | 260 |
| 260 base::ScopedTempDir profile_dir_; | 261 base::ScopedTempDir profile_dir_; |
| 261 base::ScopedTempDir fake_library_dir_; | 262 base::ScopedTempDir fake_library_dir_; |
| 262 | 263 |
| 263 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 264 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 264 scoped_ptr<MediaPathFilter> media_path_filter_; | 265 scoped_ptr<MediaPathFilter> media_path_filter_; |
| 265 scoped_ptr<TestIPhotoDataProvider> iphoto_data_provider_; | 266 scoped_ptr<TestIPhotoDataProvider> iphoto_data_provider_; |
| 266 | 267 |
| 267 DISALLOW_COPY_AND_ASSIGN(IPhotoFileUtilTest); | 268 DISALLOW_COPY_AND_ASSIGN(IPhotoFileUtilTest); |
| 268 }; | 269 }; |
| 269 | 270 |
| 270 TEST_F(IPhotoFileUtilTest, RootContents) { | 271 TEST_F(IPhotoFileUtilTest, RootContents) { |
| 271 FileSystemOperation::FileEntryList contents; | 272 FileSystemOperation::FileEntryList contents; |
| 272 FileSystemURL url = CreateURL(""); | 273 FileSystemURL url = CreateURL(""); |
| 273 bool completed = false; | 274 bool completed = false; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 completed = false; | 345 completed = false; |
| 345 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 346 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 346 ASSERT_TRUE(completed); | 347 ASSERT_TRUE(completed); |
| 347 ASSERT_EQ(1u, contents.size()); | 348 ASSERT_EQ(1u, contents.size()); |
| 348 | 349 |
| 349 EXPECT_FALSE(contents.front().is_directory); | 350 EXPECT_FALSE(contents.front().is_directory); |
| 350 EXPECT_EQ("a.jpg", contents.front().name); | 351 EXPECT_EQ("a.jpg", contents.front().name); |
| 351 } | 352 } |
| 352 | 353 |
| 353 } // namespace iphoto | 354 } // namespace iphoto |
| OLD | NEW |