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_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/file_path.h" | |
11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 19 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
19 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 20 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
20 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" | 21 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 bool* completed) { | 143 bool* completed) { |
143 DCHECK(contents); | 144 DCHECK(contents); |
144 DCHECK(completed); | 145 DCHECK(completed); |
145 base::RunLoop run_loop; | 146 base::RunLoop run_loop; |
146 runner->ReadDirectory( | 147 runner->ReadDirectory( |
147 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, | 148 url, base::Bind(&ReadDirectoryTestHelperCallback, &run_loop, contents, |
148 completed)); | 149 completed)); |
149 run_loop.Run(); | 150 run_loop.Run(); |
150 } | 151 } |
151 | 152 |
153 void SynchronouslyRunOnMediaTaskRunner(const base::Closure& closure) { | |
154 base::RunLoop loop; | |
155 chrome::MediaFileSystemBackend::MediaTaskRunner()->PostTaskAndReply( | |
156 FROM_HERE, | |
157 closure, | |
158 base::Bind(&base::RunLoop::Quit, base::Unretained(&loop))); | |
vandebo (ex-Chrome)
2013/08/27 04:29:04
loop::QuitClosure()
tommycli
2013/08/27 18:39:18
Done.
| |
159 loop.Run(); | |
160 } | |
161 | |
152 } // namespace | 162 } // namespace |
153 | 163 |
154 class TestPicasaDataProvider : public PicasaDataProvider { | |
155 public: | |
156 TestPicasaDataProvider() | |
157 : PicasaDataProvider(base::FilePath(FILE_PATH_LITERAL("Fake"))), | |
158 initialized_(false) { | |
159 } | |
160 | |
161 virtual ~TestPicasaDataProvider() {} | |
162 | |
163 virtual void RefreshData(const base::Closure& ready_callback) OVERRIDE { | |
164 DCHECK(initialized_); | |
165 ready_callback.Run(); | |
166 } | |
167 | |
168 void Init(const std::vector<AlbumInfo>& albums, | |
169 const std::vector<AlbumInfo>& folders) { | |
170 UniquifyNames(albums, &album_map_); | |
171 UniquifyNames(folders, &folder_map_); | |
172 initialized_ = true; | |
173 } | |
174 | |
175 private: | |
176 bool initialized_; | |
177 }; | |
178 | |
179 class TestPicasaFileUtil : public PicasaFileUtil { | 164 class TestPicasaFileUtil : public PicasaFileUtil { |
180 public: | 165 public: |
181 TestPicasaFileUtil(chrome::MediaPathFilter* media_path_filter, | 166 TestPicasaFileUtil(chrome::MediaPathFilter* media_path_filter, |
182 PicasaDataProvider* data_provider) | 167 PicasaDataProvider* data_provider) |
183 : PicasaFileUtil(media_path_filter), | 168 : PicasaFileUtil(media_path_filter), |
184 data_provider_(data_provider) { | 169 data_provider_(data_provider) { |
185 } | 170 } |
186 virtual ~TestPicasaFileUtil() {} | 171 virtual ~TestPicasaFileUtil() {} |
187 private: | 172 private: |
188 virtual PicasaDataProvider* GetDataProvider() OVERRIDE { | 173 virtual PicasaDataProvider* GetDataProvider() OVERRIDE { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 : io_thread_(content::BrowserThread::IO, &message_loop_) { | 205 : io_thread_(content::BrowserThread::IO, &message_loop_) { |
221 } | 206 } |
222 virtual ~PicasaFileUtilTest() {} | 207 virtual ~PicasaFileUtilTest() {} |
223 | 208 |
224 virtual void SetUp() OVERRIDE { | 209 virtual void SetUp() OVERRIDE { |
225 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 210 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
226 | 211 |
227 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 212 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
228 new quota::MockSpecialStoragePolicy(); | 213 new quota::MockSpecialStoragePolicy(); |
229 | 214 |
215 SynchronouslyRunOnMediaTaskRunner(base::Bind( | |
216 &PicasaFileUtilTest::SetUpOnMediaTaskRunner, base::Unretained(this))); | |
217 | |
230 media_path_filter_.reset(new chrome::MediaPathFilter()); | 218 media_path_filter_.reset(new chrome::MediaPathFilter()); |
231 picasa_data_provider_.reset(new TestPicasaDataProvider()); | |
232 | 219 |
233 ScopedVector<fileapi::FileSystemBackend> additional_providers; | 220 ScopedVector<fileapi::FileSystemBackend> additional_providers; |
234 additional_providers.push_back(new TestMediaFileSystemBackend( | 221 additional_providers.push_back(new TestMediaFileSystemBackend( |
235 profile_dir_.path(), | 222 profile_dir_.path(), |
236 new TestPicasaFileUtil(media_path_filter_.get(), | 223 new TestPicasaFileUtil(media_path_filter_.get(), |
237 picasa_data_provider_.get()))); | 224 picasa_data_provider_.get()))); |
238 | 225 |
239 file_system_context_ = new fileapi::FileSystemContext( | 226 file_system_context_ = new fileapi::FileSystemContext( |
240 base::MessageLoopProxy::current().get(), | 227 base::MessageLoopProxy::current().get(), |
241 base::MessageLoopProxy::current().get(), | 228 base::MessageLoopProxy::current().get(), |
242 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 229 fileapi::ExternalMountPoints::CreateRefCounted().get(), |
243 storage_policy.get(), | 230 storage_policy.get(), |
244 NULL, | 231 NULL, |
245 additional_providers.Pass(), | 232 additional_providers.Pass(), |
246 profile_dir_.path(), | 233 profile_dir_.path(), |
247 fileapi::CreateAllowFileAccessOptions()); | 234 fileapi::CreateAllowFileAccessOptions()); |
248 } | 235 } |
249 | 236 |
237 virtual void TearDown() OVERRIDE { | |
238 SynchronouslyRunOnMediaTaskRunner( | |
239 base::Bind(&PicasaFileUtilTest::TearDownOnMediaTaskRunner, | |
240 base::Unretained(this))); | |
241 } | |
242 | |
250 protected: | 243 protected: |
244 void SetUpOnMediaTaskRunner() { | |
245 picasa_data_provider_.reset(new PicasaDataProvider(base::FilePath())); | |
246 } | |
247 | |
248 void TearDownOnMediaTaskRunner() { | |
249 picasa_data_provider_.reset(); | |
250 } | |
251 | |
252 void SetupDataProvider(PicasaDataProvider* picasa_data_provider, | |
253 const std::vector<AlbumInfo>& albums, | |
254 const std::vector<AlbumInfo>& folders) { | |
255 PicasaDataProvider::UniquifyNames(albums, | |
256 &picasa_data_provider->album_map_); | |
257 PicasaDataProvider::UniquifyNames(folders, | |
258 &picasa_data_provider->folder_map_); | |
259 picasa_data_provider->state_ = | |
260 PicasaDataProvider::ALBUMS_IMAGES_FRESH_STATE; | |
261 } | |
262 | |
251 // |test_folders| must be in alphabetical order for easy verification | 263 // |test_folders| must be in alphabetical order for easy verification |
252 void SetupFolders(ScopedVector<TestFolder>* test_folders) { | 264 void SetupFolders(ScopedVector<TestFolder>* test_folders) { |
253 std::vector<AlbumInfo> folders; | 265 std::vector<AlbumInfo> folders; |
254 for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); | 266 for (ScopedVector<TestFolder>::iterator it = test_folders->begin(); |
255 it != test_folders->end(); ++it) { | 267 it != test_folders->end(); ++it) { |
256 TestFolder* test_folder = *it; | 268 TestFolder* test_folder = *it; |
257 ASSERT_TRUE(test_folder->Init()); | 269 ASSERT_TRUE(test_folder->Init()); |
258 folders.push_back(test_folder->folder_info()); | 270 folders.push_back(test_folder->folder_info()); |
259 } | 271 } |
260 picasa_data_provider_->Init(std::vector<AlbumInfo>(), folders); | 272 |
273 SetupDataProvider( | |
274 picasa_data_provider_.get(), std::vector<AlbumInfo>(), folders); | |
261 } | 275 } |
262 | 276 |
263 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { | 277 void VerifyFolderDirectoryList(const ScopedVector<TestFolder>& test_folders) { |
264 FileSystemOperation::FileEntryList contents; | 278 FileSystemOperation::FileEntryList contents; |
265 FileSystemURL url = CreateURL(kPicasaDirFolders); | 279 FileSystemURL url = CreateURL(kPicasaDirFolders); |
266 bool completed = false; | 280 bool completed = false; |
267 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); | 281 ReadDirectoryTestHelper(operation_runner(), url, &contents, &completed); |
268 | 282 |
269 ASSERT_TRUE(completed); | 283 ASSERT_TRUE(completed); |
270 ASSERT_EQ(test_folders.size(), contents.size()); | 284 ASSERT_EQ(test_folders.size(), contents.size()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 return file_system_context_; | 344 return file_system_context_; |
331 } | 345 } |
332 | 346 |
333 private: | 347 private: |
334 base::MessageLoop message_loop_; | 348 base::MessageLoop message_loop_; |
335 content::TestBrowserThread io_thread_; | 349 content::TestBrowserThread io_thread_; |
336 | 350 |
337 base::ScopedTempDir profile_dir_; | 351 base::ScopedTempDir profile_dir_; |
338 | 352 |
339 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 353 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
354 scoped_ptr<PicasaDataProvider> picasa_data_provider_; | |
340 scoped_ptr<chrome::MediaPathFilter> media_path_filter_; | 355 scoped_ptr<chrome::MediaPathFilter> media_path_filter_; |
341 scoped_ptr<TestPicasaDataProvider> picasa_data_provider_; | |
342 | 356 |
343 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); | 357 DISALLOW_COPY_AND_ASSIGN(PicasaFileUtilTest); |
344 }; | 358 }; |
345 | 359 |
346 TEST_F(PicasaFileUtilTest, DateFormat) { | 360 TEST_F(PicasaFileUtilTest, DateFormat) { |
347 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; | 361 base::Time::Exploded exploded_shortmonth = { 2013, 4, 0, 16, 0, 0, 0, 0 }; |
348 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); | 362 base::Time shortmonth = base::Time::FromLocalExploded(exploded_shortmonth); |
349 | 363 |
350 base::Time::Exploded exploded_shortday = { 2013, 11, 0, 3, 0, 0, 0, 0 }; | 364 base::Time::Exploded exploded_shortday = { 2013, 11, 0, 3, 0, 0, 0, 0 }; |
351 base::Time shortday = base::Time::FromLocalExploded(exploded_shortday); | 365 base::Time shortday = base::Time::FromLocalExploded(exploded_shortday); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 new TestFolder(base::StringPrintf("folder-%05d", i), | 487 new TestFolder(base::StringPrintf("folder-%05d", i), |
474 date, | 488 date, |
475 base::StringPrintf("uid%05d", i), i % 5, i % 3)); | 489 base::StringPrintf("uid%05d", i), i % 5, i % 3)); |
476 } | 490 } |
477 | 491 |
478 SetupFolders(&test_folders); | 492 SetupFolders(&test_folders); |
479 VerifyFolderDirectoryList(test_folders); | 493 VerifyFolderDirectoryList(test_folders); |
480 } | 494 } |
481 | 495 |
482 } // namespace picasa | 496 } // namespace picasa |
OLD | NEW |