Chromium Code Reviews| 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_path_; |
| 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 fake_auto_add_dir_path_ = fake_auto_add_dir_.GetPath(); | |
| 93 } else { | 94 } else { |
| 94 ASSERT_TRUE(fake_auto_add_dir_.Delete()); | 95 ASSERT_TRUE(fake_auto_add_dir_.Delete()); |
| 96 fake_auto_add_dir_path_.clear(); | |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 private: | 100 private: |
| 101 base::FilePath fake_auto_add_dir_path_; | |
|
vabr (Chromium)
2016/09/14 16:22:17
Before: ScopedTempDir needed to trust the code cal
Reilly Grant (use Gerrit)
2016/09/14 18:06:19
You could add an ASSERT_FALSE(fake_auto_add_dir_pa
vabr (Chromium)
2016/09/14 20:14:39
The trouble is that it can actually be empty: Itun
| |
| 99 base::ScopedTempDir fake_auto_add_dir_; | 102 base::ScopedTempDir fake_auto_add_dir_; |
| 100 }; | 103 }; |
| 101 | 104 |
| 102 class TestITunesFileUtil : public ITunesFileUtil { | 105 class TestITunesFileUtil : public ITunesFileUtil { |
| 103 public: | 106 public: |
| 104 explicit TestITunesFileUtil(MediaPathFilter* media_path_filter, | 107 explicit TestITunesFileUtil(MediaPathFilter* media_path_filter, |
| 105 ITunesDataProvider* data_provider) | 108 ITunesDataProvider* data_provider) |
| 106 : ITunesFileUtil(media_path_filter), | 109 : ITunesFileUtil(media_path_filter), |
| 107 data_provider_(data_provider) { | 110 data_provider_(data_provider) { |
| 108 } | 111 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 136 }; | 139 }; |
| 137 | 140 |
| 138 class ItunesFileUtilTest : public testing::Test { | 141 class ItunesFileUtilTest : public testing::Test { |
| 139 public: | 142 public: |
| 140 ItunesFileUtilTest() | 143 ItunesFileUtilTest() |
| 141 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 144 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 142 } | 145 } |
| 143 | 146 |
| 144 void SetUpDataProvider() { | 147 void SetUpDataProvider() { |
| 145 ASSERT_TRUE(fake_library_dir_.CreateUniqueTempDir()); | 148 ASSERT_TRUE(fake_library_dir_.CreateUniqueTempDir()); |
| 146 ASSERT_EQ( | 149 ASSERT_EQ(0, base::WriteFile( |
| 147 0, | 150 fake_library_dir_.GetPath().AppendASCII(kITunesLibraryXML), |
| 148 base::WriteFile( | 151 NULL, 0)); |
| 149 fake_library_dir_.path().AppendASCII(kITunesLibraryXML), | |
| 150 NULL, | |
| 151 0)); | |
| 152 | 152 |
| 153 itunes_data_provider_.reset( | 153 itunes_data_provider_.reset( |
| 154 new TestITunesDataProvider(fake_library_dir_.path())); | 154 new TestITunesDataProvider(fake_library_dir_.GetPath())); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void SetUp() override { | 157 void SetUp() override { |
| 158 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 158 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 159 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); | 159 ImportedMediaGalleryRegistry::GetInstance()->Initialize(); |
| 160 | 160 |
| 161 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = | 161 scoped_refptr<storage::SpecialStoragePolicy> storage_policy = |
| 162 new content::MockSpecialStoragePolicy(); | 162 new content::MockSpecialStoragePolicy(); |
| 163 | 163 |
| 164 // Initialize fake ItunesDataProvider on media task runner thread. | 164 // Initialize fake ItunesDataProvider on media task runner thread. |
| 165 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 165 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 166 FROM_HERE, | 166 FROM_HERE, |
| 167 base::Bind(&ItunesFileUtilTest::SetUpDataProvider, | 167 base::Bind(&ItunesFileUtilTest::SetUpDataProvider, |
| 168 base::Unretained(this))); | 168 base::Unretained(this))); |
| 169 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, | 169 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
| 170 base::WaitableEvent::InitialState::NOT_SIGNALED); | 170 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 171 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 171 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 172 FROM_HERE, | 172 FROM_HERE, |
| 173 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 173 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 174 event.Wait(); | 174 event.Wait(); |
| 175 | 175 |
| 176 media_path_filter_.reset(new MediaPathFilter()); | 176 media_path_filter_.reset(new MediaPathFilter()); |
| 177 ScopedVector<storage::FileSystemBackend> additional_providers; | 177 ScopedVector<storage::FileSystemBackend> additional_providers; |
| 178 additional_providers.push_back(new TestMediaFileSystemBackend( | 178 additional_providers.push_back(new TestMediaFileSystemBackend( |
| 179 profile_dir_.path(), | 179 profile_dir_.GetPath(), |
| 180 new TestITunesFileUtil(media_path_filter_.get(), | 180 new TestITunesFileUtil(media_path_filter_.get(), |
| 181 itunes_data_provider_.get()))); | 181 itunes_data_provider_.get()))); |
| 182 | 182 |
| 183 file_system_context_ = new storage::FileSystemContext( | 183 file_system_context_ = new storage::FileSystemContext( |
| 184 base::ThreadTaskRunnerHandle::Get().get(), | 184 base::ThreadTaskRunnerHandle::Get().get(), |
| 185 base::ThreadTaskRunnerHandle::Get().get(), | 185 base::ThreadTaskRunnerHandle::Get().get(), |
| 186 storage::ExternalMountPoints::CreateRefCounted().get(), | 186 storage::ExternalMountPoints::CreateRefCounted().get(), |
| 187 storage_policy.get(), NULL, std::move(additional_providers), | 187 storage_policy.get(), NULL, std::move(additional_providers), |
| 188 std::vector<storage::URLRequestAutoMountHandler>(), profile_dir_.path(), | 188 std::vector<storage::URLRequestAutoMountHandler>(), |
| 189 content::CreateAllowFileAccessOptions()); | 189 profile_dir_.GetPath(), 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); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 completed = false; | 343 completed = false; |
| 344 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 344 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
| 345 ASSERT_TRUE(completed); | 345 ASSERT_TRUE(completed); |
| 346 ASSERT_EQ(1u, contents.size()); | 346 ASSERT_EQ(1u, contents.size()); |
| 347 EXPECT_FALSE(contents.front().is_directory); | 347 EXPECT_FALSE(contents.front().is_directory); |
| 348 EXPECT_EQ(base::FilePath().AppendASCII("baz.ogg").value(), | 348 EXPECT_EQ(base::FilePath().AppendASCII("baz.ogg").value(), |
| 349 contents.front().name); | 349 contents.front().name); |
| 350 } | 350 } |
| 351 | 351 |
| 352 } // namespace itunes | 352 } // namespace itunes |
| OLD | NEW |