| 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 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/test/mock_special_storage_policy.h" | 22 #include "content/public/test/mock_special_storage_policy.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 24 #include "content/public/test/test_file_system_options.h" | 24 #include "content/public/test/test_file_system_options.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "webkit/browser/fileapi/async_file_util.h" | 26 #include "webkit/browser/fileapi/async_file_util.h" |
| 27 #include "webkit/browser/fileapi/external_mount_points.h" | 27 #include "webkit/browser/fileapi/external_mount_points.h" |
| 28 #include "webkit/browser/fileapi/file_system_context.h" | 28 #include "webkit/browser/fileapi/file_system_context.h" |
| 29 #include "webkit/browser/fileapi/file_system_operation_context.h" | 29 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 30 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 30 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 31 | 31 |
| 32 using fileapi::FileSystemOperationContext; | 32 using storage::FileSystemOperationContext; |
| 33 using fileapi::FileSystemOperation; | 33 using storage::FileSystemOperation; |
| 34 using fileapi::FileSystemURL; | 34 using storage::FileSystemURL; |
| 35 | 35 |
| 36 namespace itunes { | 36 namespace itunes { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 void ReadDirectoryTestHelperCallback( | 40 void ReadDirectoryTestHelperCallback( |
| 41 base::RunLoop* run_loop, | 41 base::RunLoop* run_loop, |
| 42 FileSystemOperation::FileEntryList* contents, | 42 FileSystemOperation::FileEntryList* contents, |
| 43 bool* completed, base::File::Error error, | 43 bool* completed, base::File::Error error, |
| 44 const FileSystemOperation::FileEntryList& file_list, | 44 const FileSystemOperation::FileEntryList& file_list, |
| 45 bool has_more) { | 45 bool has_more) { |
| 46 DCHECK(!*completed); | 46 DCHECK(!*completed); |
| 47 *completed = (!has_more && error == base::File::FILE_OK); | 47 *completed = (!has_more && error == base::File::FILE_OK); |
| 48 *contents = file_list; | 48 *contents = file_list; |
| 49 run_loop->Quit(); | 49 run_loop->Quit(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void ReadDirectoryTestHelper(fileapi::FileSystemOperationRunner* runner, | 52 void ReadDirectoryTestHelper(storage::FileSystemOperationRunner* runner, |
| 53 const FileSystemURL& url, | 53 const FileSystemURL& url, |
| 54 FileSystemOperation::FileEntryList* contents, | 54 FileSystemOperation::FileEntryList* contents, |
| 55 bool* completed) { | 55 bool* completed) { |
| 56 DCHECK(contents); | 56 DCHECK(contents); |
| 57 DCHECK(completed); | 57 DCHECK(completed); |
| 58 base::RunLoop run_loop; | 58 base::RunLoop run_loop; |
| 59 runner->ReadDirectory( | 59 runner->ReadDirectory( |
| 60 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, | 60 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, |
| 61 completed)); | 61 completed)); |
| 62 run_loop.Run(); | 62 run_loop.Run(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 class TestMediaFileSystemBackend : public MediaFileSystemBackend { | 114 class TestMediaFileSystemBackend : public MediaFileSystemBackend { |
| 115 public: | 115 public: |
| 116 TestMediaFileSystemBackend(const base::FilePath& profile_path, | 116 TestMediaFileSystemBackend(const base::FilePath& profile_path, |
| 117 ITunesFileUtil* itunes_file_util) | 117 ITunesFileUtil* itunes_file_util) |
| 118 : MediaFileSystemBackend( | 118 : MediaFileSystemBackend( |
| 119 profile_path, | 119 profile_path, |
| 120 MediaFileSystemBackend::MediaTaskRunner().get()), | 120 MediaFileSystemBackend::MediaTaskRunner().get()), |
| 121 test_file_util_(itunes_file_util) {} | 121 test_file_util_(itunes_file_util) {} |
| 122 | 122 |
| 123 virtual fileapi::AsyncFileUtil* | 123 virtual storage::AsyncFileUtil* GetAsyncFileUtil( |
| 124 GetAsyncFileUtil(fileapi::FileSystemType type) OVERRIDE { | 124 storage::FileSystemType type) OVERRIDE { |
| 125 if (type != fileapi::kFileSystemTypeItunes) | 125 if (type != storage::kFileSystemTypeItunes) |
| 126 return NULL; | 126 return NULL; |
| 127 | 127 |
| 128 return test_file_util_.get(); | 128 return test_file_util_.get(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 private: | 131 private: |
| 132 scoped_ptr<fileapi::AsyncFileUtil> test_file_util_; | 132 scoped_ptr<storage::AsyncFileUtil> test_file_util_; |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 class ItunesFileUtilTest : public testing::Test { | 135 class ItunesFileUtilTest : public testing::Test { |
| 136 public: | 136 public: |
| 137 ItunesFileUtilTest() | 137 ItunesFileUtilTest() |
| 138 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 138 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 139 } | 139 } |
| 140 virtual ~ItunesFileUtilTest() {} | 140 virtual ~ItunesFileUtilTest() {} |
| 141 | 141 |
| 142 void SetUpDataProvider() { | 142 void SetUpDataProvider() { |
| 143 ASSERT_TRUE(fake_library_dir_.CreateUniqueTempDir()); | 143 ASSERT_TRUE(fake_library_dir_.CreateUniqueTempDir()); |
| 144 ASSERT_EQ( | 144 ASSERT_EQ( |
| 145 0, | 145 0, |
| 146 base::WriteFile( | 146 base::WriteFile( |
| 147 fake_library_dir_.path().AppendASCII(kITunesLibraryXML), | 147 fake_library_dir_.path().AppendASCII(kITunesLibraryXML), |
| 148 NULL, | 148 NULL, |
| 149 0)); | 149 0)); |
| 150 | 150 |
| 151 itunes_data_provider_.reset( | 151 itunes_data_provider_.reset( |
| 152 new TestITunesDataProvider(fake_library_dir_.path())); | 152 new TestITunesDataProvider(fake_library_dir_.path())); |
| 153 } | 153 } |
| 154 | 154 |
| 155 virtual void SetUp() OVERRIDE { | 155 virtual void SetUp() OVERRIDE { |
| 156 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 156 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 157 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); | 157 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); |
| 158 | 158 |
| 159 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 159 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = |
| 160 new content::MockSpecialStoragePolicy(); | 160 new content::MockSpecialStoragePolicy(); |
| 161 | 161 |
| 162 // Initialize fake ItunesDataProvider on media task runner thread. | 162 // Initialize fake ItunesDataProvider on media task runner thread. |
| 163 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 163 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 164 FROM_HERE, | 164 FROM_HERE, |
| 165 base::Bind(&ItunesFileUtilTest::SetUpDataProvider, | 165 base::Bind(&ItunesFileUtilTest::SetUpDataProvider, |
| 166 base::Unretained(this))); | 166 base::Unretained(this))); |
| 167 base::WaitableEvent event(true, false /* initially_signalled */); | 167 base::WaitableEvent event(true, false /* initially_signalled */); |
| 168 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 168 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 169 FROM_HERE, | 169 FROM_HERE, |
| 170 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 170 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 171 event.Wait(); | 171 event.Wait(); |
| 172 | 172 |
| 173 media_path_filter_.reset(new MediaPathFilter()); | 173 media_path_filter_.reset(new MediaPathFilter()); |
| 174 ScopedVector<fileapi::FileSystemBackend> additional_providers; | 174 ScopedVector<storage::FileSystemBackend> additional_providers; |
| 175 additional_providers.push_back(new TestMediaFileSystemBackend( | 175 additional_providers.push_back(new TestMediaFileSystemBackend( |
| 176 profile_dir_.path(), | 176 profile_dir_.path(), |
| 177 new TestITunesFileUtil(media_path_filter_.get(), | 177 new TestITunesFileUtil(media_path_filter_.get(), |
| 178 itunes_data_provider_.get()))); | 178 itunes_data_provider_.get()))); |
| 179 | 179 |
| 180 file_system_context_ = new fileapi::FileSystemContext( | 180 file_system_context_ = new storage::FileSystemContext( |
| 181 base::MessageLoopProxy::current().get(), | 181 base::MessageLoopProxy::current().get(), |
| 182 base::MessageLoopProxy::current().get(), | 182 base::MessageLoopProxy::current().get(), |
| 183 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 183 storage::ExternalMountPoints::CreateRefCounted().get(), |
| 184 storage_policy.get(), | 184 storage_policy.get(), |
| 185 NULL, | 185 NULL, |
| 186 additional_providers.Pass(), | 186 additional_providers.Pass(), |
| 187 std::vector<fileapi::URLRequestAutoMountHandler>(), | 187 std::vector<storage::URLRequestAutoMountHandler>(), |
| 188 profile_dir_.path(), | 188 profile_dir_.path(), |
| 189 content::CreateAllowFileAccessOptions()); | 189 content::CreateAllowFileAccessOptions()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 protected: | 192 protected: |
| 193 void TestNonexistentFolder(const std::string& path_append) { | 193 void TestNonexistentFolder(const std::string& path_append) { |
| 194 FileSystemOperation::FileEntryList contents; | 194 FileSystemOperation::FileEntryList contents; |
| 195 FileSystemURL url = CreateURL(path_append); | 195 FileSystemURL url = CreateURL(path_append); |
| 196 bool completed = false; | 196 bool completed = false; |
| 197 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 197 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 198 | 198 |
| 199 ASSERT_FALSE(completed); | 199 ASSERT_FALSE(completed); |
| 200 } | 200 } |
| 201 | 201 |
| 202 FileSystemURL CreateURL(const std::string& path) const { | 202 FileSystemURL CreateURL(const std::string& path) const { |
| 203 base::FilePath virtual_path = | 203 base::FilePath virtual_path = |
| 204 ImportedMediaGalleryRegistry::GetInstance()->ImportedRoot(); | 204 ImportedMediaGalleryRegistry::GetInstance()->ImportedRoot(); |
| 205 virtual_path = virtual_path.AppendASCII("itunes"); | 205 virtual_path = virtual_path.AppendASCII("itunes"); |
| 206 virtual_path = virtual_path.AppendASCII(path); | 206 virtual_path = virtual_path.AppendASCII(path); |
| 207 return file_system_context_->CreateCrackedFileSystemURL( | 207 return file_system_context_->CreateCrackedFileSystemURL( |
| 208 GURL("http://www.example.com"), fileapi::kFileSystemTypeItunes, | 208 GURL("http://www.example.com"), |
| 209 storage::kFileSystemTypeItunes, |
| 209 virtual_path); | 210 virtual_path); |
| 210 } | 211 } |
| 211 | 212 |
| 212 fileapi::FileSystemOperationRunner* operation_runner() const { | 213 storage::FileSystemOperationRunner* operation_runner() const { |
| 213 return file_system_context_->operation_runner(); | 214 return file_system_context_->operation_runner(); |
| 214 } | 215 } |
| 215 | 216 |
| 216 scoped_refptr<fileapi::FileSystemContext> file_system_context() const { | 217 scoped_refptr<storage::FileSystemContext> file_system_context() const { |
| 217 return file_system_context_; | 218 return file_system_context_; |
| 218 } | 219 } |
| 219 | 220 |
| 220 TestITunesDataProvider* data_provider() const { | 221 TestITunesDataProvider* data_provider() const { |
| 221 return itunes_data_provider_.get(); | 222 return itunes_data_provider_.get(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 private: | 225 private: |
| 225 base::MessageLoop message_loop_; | 226 base::MessageLoop message_loop_; |
| 226 content::TestBrowserThread io_thread_; | 227 content::TestBrowserThread io_thread_; |
| 227 | 228 |
| 228 base::ScopedTempDir profile_dir_; | 229 base::ScopedTempDir profile_dir_; |
| 229 base::ScopedTempDir fake_library_dir_; | 230 base::ScopedTempDir fake_library_dir_; |
| 230 | 231 |
| 231 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 232 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 232 scoped_ptr<MediaPathFilter> media_path_filter_; | 233 scoped_ptr<MediaPathFilter> media_path_filter_; |
| 233 scoped_ptr<TestITunesDataProvider> itunes_data_provider_; | 234 scoped_ptr<TestITunesDataProvider> itunes_data_provider_; |
| 234 | 235 |
| 235 DISALLOW_COPY_AND_ASSIGN(ItunesFileUtilTest); | 236 DISALLOW_COPY_AND_ASSIGN(ItunesFileUtilTest); |
| 236 }; | 237 }; |
| 237 | 238 |
| 238 TEST_F(ItunesFileUtilTest, RootContents) { | 239 TEST_F(ItunesFileUtilTest, RootContents) { |
| 239 FileSystemOperation::FileEntryList contents; | 240 FileSystemOperation::FileEntryList contents; |
| 240 FileSystemURL url = CreateURL(""); | 241 FileSystemURL url = CreateURL(""); |
| 241 bool completed = false; | 242 bool completed = false; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 completed = false; | 343 completed = false; |
| 343 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 344 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 344 ASSERT_TRUE(completed); | 345 ASSERT_TRUE(completed); |
| 345 ASSERT_EQ(1u, contents.size()); | 346 ASSERT_EQ(1u, contents.size()); |
| 346 EXPECT_FALSE(contents.front().is_directory); | 347 EXPECT_FALSE(contents.front().is_directory); |
| 347 EXPECT_EQ(base::FilePath().AppendASCII("baz.ogg").value(), | 348 EXPECT_EQ(base::FilePath().AppendASCII("baz.ogg").value(), |
| 348 contents.front().name); | 349 contents.front().name); |
| 349 } | 350 } |
| 350 | 351 |
| 351 } // namespace itunes | 352 } // namespace itunes |
| OLD | NEW |