| 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/itunes_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/itunes_file_util.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 EXPECT_TRUE(fake_auto_add_dir_.CreateUniqueTempDir()); | 76 EXPECT_TRUE(fake_auto_add_dir_.CreateUniqueTempDir()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 ~TestITunesDataProvider() override {} | 79 ~TestITunesDataProvider() override {} |
| 80 | 80 |
| 81 void RefreshData(const ReadyCallback& ready_callback) override { | 81 void RefreshData(const ReadyCallback& ready_callback) override { |
| 82 ready_callback.Run(true /* success */); | 82 ready_callback.Run(true /* success */); |
| 83 } | 83 } |
| 84 | 84 |
| 85 const base::FilePath& auto_add_path() const override { | 85 const base::FilePath& auto_add_path() const override { |
| 86 return fake_auto_add_dir_.path(); | 86 return fake_auto_add_dir_.GetPath(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void SetProvideAutoAddDir(bool provide_auto_add_dir) { | 89 void SetProvideAutoAddDir(bool provide_auto_add_dir) { |
| 90 if (provide_auto_add_dir) { | 90 if (provide_auto_add_dir) { |
| 91 if (!fake_auto_add_dir_.IsValid()) | 91 if (!fake_auto_add_dir_.IsValid()) |
| 92 ASSERT_TRUE(fake_auto_add_dir_.CreateUniqueTempDir()); | 92 ASSERT_TRUE(fake_auto_add_dir_.CreateUniqueTempDir()); |
| 93 } else { | 93 } else { |
| 94 ASSERT_TRUE(fake_auto_add_dir_.Delete()); | 94 ASSERT_TRUE(fake_auto_add_dir_.Delete()); |
| 95 } | 95 } |
| 96 } | 96 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 class ItunesFileUtilTest : public testing::Test { | 138 class ItunesFileUtilTest : public testing::Test { |
| 139 public: | 139 public: |
| 140 ItunesFileUtilTest() | 140 ItunesFileUtilTest() |
| 141 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 141 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 142 } | 142 } |
| 143 | 143 |
| 144 void SetUpDataProvider() { | 144 void SetUpDataProvider() { |
| 145 ASSERT_TRUE(fake_library_dir_.CreateUniqueTempDir()); | 145 ASSERT_TRUE(fake_library_dir_.CreateUniqueTempDir()); |
| 146 ASSERT_EQ( | 146 ASSERT_EQ(0, base::WriteFile( |
| 147 0, | 147 fake_library_dir_.GetPath().AppendASCII(kITunesLibraryXML), |
| 148 base::WriteFile( | 148 NULL, 0)); |
| 149 fake_library_dir_.path().AppendASCII(kITunesLibraryXML), | |
| 150 NULL, | |
| 151 0)); | |
| 152 | 149 |
| 153 itunes_data_provider_.reset( | 150 itunes_data_provider_.reset( |
| 154 new TestITunesDataProvider(fake_library_dir_.path())); | 151 new TestITunesDataProvider(fake_library_dir_.GetPath())); |
| 155 } | 152 } |
| 156 | 153 |
| 157 void SetUp() override { | 154 void SetUp() override { |
| 158 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 155 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 159 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); | 156 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); |
| 160 | 157 |
| 161 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = | 158 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = |
| 162 new content::MockSpecialStoragePolicy(); | 159 new content::MockSpecialStoragePolicy(); |
| 163 | 160 |
| 164 // Initialize fake ItunesDataProvider on media task runner thread. | 161 // Initialize fake ItunesDataProvider on media task runner thread. |
| 165 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 162 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 166 FROM_HERE, | 163 FROM_HERE, |
| 167 base::Bind(&ItunesFileUtilTest::SetUpDataProvider, | 164 base::Bind(&ItunesFileUtilTest::SetUpDataProvider, |
| 168 base::Unretained(this))); | 165 base::Unretained(this))); |
| 169 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, | 166 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
| 170 base::WaitableEvent::InitialState::NOT_SIGNALED); | 167 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 171 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 168 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 172 FROM_HERE, | 169 FROM_HERE, |
| 173 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 170 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 174 event.Wait(); | 171 event.Wait(); |
| 175 | 172 |
| 176 media_path_filter_.reset(new MediaPathFilter()); | 173 media_path_filter_.reset(new MediaPathFilter()); |
| 177 ScopedVector<storage::FileSystemBackend> additional_providers; | 174 ScopedVector<storage::FileSystemBackend> additional_providers; |
| 178 additional_providers.push_back(new TestMediaFileSystemBackend( | 175 additional_providers.push_back(new TestMediaFileSystemBackend( |
| 179 profile_dir_.path(), | 176 profile_dir_.GetPath(), |
| 180 new TestITunesFileUtil(media_path_filter_.get(), | 177 new TestITunesFileUtil(media_path_filter_.get(), |
| 181 itunes_data_provider_.get()))); | 178 itunes_data_provider_.get()))); |
| 182 | 179 |
| 183 file_system_context_ = new storage::FileSystemContext( | 180 file_system_context_ = new storage::FileSystemContext( |
| 184 base::ThreadTaskRunnerHandle::Get().get(), | 181 base::ThreadTaskRunnerHandle::Get().get(), |
| 185 base::ThreadTaskRunnerHandle::Get().get(), | 182 base::ThreadTaskRunnerHandle::Get().get(), |
| 186 storage::ExternalMountPoints::CreateRefCounted().get(), | 183 storage::ExternalMountPoints::CreateRefCounted().get(), |
| 187 storage_policy.get(), NULL, std::move(additional_providers), | 184 storage_policy.get(), NULL, std::move(additional_providers), |
| 188 std::vector<storage::URLRequestAutoMountHandler>(), profile_dir_.path(), | 185 std::vector<storage::URLRequestAutoMountHandler>(), |
| 189 content::CreateAllowFileAccessOptions()); | 186 profile_dir_.GetPath(), content::CreateAllowFileAccessOptions()); |
| 190 } | 187 } |
| 191 | 188 |
| 192 protected: | 189 protected: |
| 193 void TestNonexistentFolder(const std::string& path_append) { | 190 void TestNonexistentFolder(const std::string& path_append) { |
| 194 FileSystemOperation::FileEntryList contents; | 191 FileSystemOperation::FileEntryList contents; |
| 195 FileSystemURL url = CreateURL(path_append); | 192 FileSystemURL url = CreateURL(path_append); |
| 196 bool completed = false; | 193 bool completed = false; |
| 197 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 194 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 198 | 195 |
| 199 ASSERT_FALSE(completed); | 196 ASSERT_FALSE(completed); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 completed = false; | 340 completed = false; |
| 344 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 341 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 345 ASSERT_TRUE(completed); | 342 ASSERT_TRUE(completed); |
| 346 ASSERT_EQ(1u, contents.size()); | 343 ASSERT_EQ(1u, contents.size()); |
| 347 EXPECT_FALSE(contents.front().is_directory); | 344 EXPECT_FALSE(contents.front().is_directory); |
| 348 EXPECT_EQ(base::FilePath().AppendASCII("baz.ogg").value(), | 345 EXPECT_EQ(base::FilePath().AppendASCII("baz.ogg").value(), |
| 349 contents.front().name); | 346 contents.front().name); |
| 350 } | 347 } |
| 351 | 348 |
| 352 } // namespace itunes | 349 } // namespace itunes |
| OLD | NEW |