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/picasa_data_provider.h" | 5 #include "chrome/browser/media_galleries/fileapi/picasa_data_provider.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (!file_watch_request_returned_) { | 114 if (!file_watch_request_returned_) { |
115 file_watch_started_callbacks_.push_back(ready_callback); | 115 file_watch_started_callbacks_.push_back(ready_callback); |
116 return; | 116 return; |
117 } | 117 } |
118 ready_callback.Run(temp_dir_watcher_.get() != NULL); | 118 ready_callback.Run(temp_dir_watcher_.get() != NULL); |
119 } | 119 } |
120 | 120 |
121 // Simulates the actual writing process of moving all the database files | 121 // Simulates the actual writing process of moving all the database files |
122 // from the temporary directory to the database directory in a loop. | 122 // from the temporary directory to the database directory in a loop. |
123 void MoveTempFilesToDatabase() { | 123 void MoveTempFilesToDatabase() { |
124 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 124 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
125 | 125 |
126 base::FileEnumerator file_enumerator( | 126 base::FileEnumerator file_enumerator( |
127 database_path_.DirName().AppendASCII(kPicasaTempDirName), | 127 database_path_.DirName().AppendASCII(kPicasaTempDirName), |
128 false /* recursive */, | 128 false /* recursive */, |
129 base::FileEnumerator::FILES); | 129 base::FileEnumerator::FILES); |
130 | 130 |
131 for (base::FilePath src_path = file_enumerator.Next(); !src_path.empty(); | 131 for (base::FilePath src_path = file_enumerator.Next(); !src_path.empty(); |
132 src_path = file_enumerator.Next()) { | 132 src_path = file_enumerator.Next()) { |
133 ASSERT_TRUE( | 133 ASSERT_TRUE( |
134 base::Move(src_path, database_path_.Append(src_path.BaseName()))); | 134 base::Move(src_path, database_path_.Append(src_path.BaseName()))); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 FROM_HERE, | 202 FROM_HERE, |
203 base::Bind(&PicasaDataProviderTest::StartTestOnMediaTaskRunner, | 203 base::Bind(&PicasaDataProviderTest::StartTestOnMediaTaskRunner, |
204 base::Unretained(this))); | 204 base::Unretained(this))); |
205 loop.Run(); | 205 loop.Run(); |
206 } | 206 } |
207 | 207 |
208 virtual PicasaDataProvider::DataType RequestedDataType() const = 0; | 208 virtual PicasaDataProvider::DataType RequestedDataType() const = 0; |
209 | 209 |
210 // Start the test. The data provider is refreshed before calling StartTest | 210 // Start the test. The data provider is refreshed before calling StartTest |
211 // and the result of the refresh is passed in. | 211 // and the result of the refresh is passed in. |
212 virtual void VerifyRefreshResults(bool parse_success) {}; | 212 virtual void VerifyRefreshResults(bool parse_success) {} |
213 | 213 |
214 void TestDone() { | 214 void TestDone() { |
215 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 215 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
216 | 216 |
217 // The data provider must be destructed on the MediaTaskRunner. This is done | 217 // The data provider must be destructed on the MediaTaskRunner. This is done |
218 // in a posted task rather than directly because TestDone is called by | 218 // in a posted task rather than directly because TestDone is called by |
219 // PicasaDataProvider. The callee should not destroy the caller. | 219 // PicasaDataProvider. The callee should not destroy the caller. |
220 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 220 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
221 FROM_HERE, | 221 FROM_HERE, |
222 base::Bind(&PicasaDataProviderTest::DestructDataProviderThenQuit, | 222 base::Bind(&PicasaDataProviderTest::DestructDataProviderThenQuit, |
223 base::Unretained(this))); | 223 base::Unretained(this))); |
224 } | 224 } |
225 | 225 |
226 const base::FilePath& test_folder_1_path() { return test_folder_1_.path(); } | 226 const base::FilePath& test_folder_1_path() { return test_folder_1_.path(); } |
227 const base::FilePath& test_folder_2_path() { return test_folder_2_.path(); } | 227 const base::FilePath& test_folder_2_path() { return test_folder_2_.path(); } |
228 | 228 |
229 TestPicasaDataProvider* data_provider() const { | 229 TestPicasaDataProvider* data_provider() const { |
230 return picasa_data_provider_.get(); | 230 return picasa_data_provider_.get(); |
231 } | 231 } |
232 | 232 |
233 const base::FilePath GetTempDirPath() const { | 233 const base::FilePath GetTempDirPath() const { |
234 return picasa_root_dir_.path().AppendASCII(kPicasaTempDirName); | 234 return picasa_root_dir_.path().AppendASCII(kPicasaTempDirName); |
235 } | 235 } |
236 | 236 |
237 virtual base::FilePath GetColumnFileDestination() const { | 237 virtual base::FilePath GetColumnFileDestination() const { |
238 return picasa_root_dir_.path().AppendASCII(kPicasaDatabaseDirName); | 238 return picasa_root_dir_.path().AppendASCII(kPicasaDatabaseDirName); |
239 } | 239 } |
240 | 240 |
241 private: | 241 private: |
242 void SetupFoldersAndDataProvider() { | 242 void SetupFoldersAndDataProvider() { |
243 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 243 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
244 ASSERT_TRUE(test_folder_1_.CreateUniqueTempDir()); | 244 ASSERT_TRUE(test_folder_1_.CreateUniqueTempDir()); |
245 ASSERT_TRUE(test_folder_2_.CreateUniqueTempDir()); | 245 ASSERT_TRUE(test_folder_2_.CreateUniqueTempDir()); |
246 ASSERT_TRUE(picasa_root_dir_.CreateUniqueTempDir()); | 246 ASSERT_TRUE(picasa_root_dir_.CreateUniqueTempDir()); |
247 ASSERT_TRUE(base::CreateDirectory( | 247 ASSERT_TRUE(base::CreateDirectory( |
248 picasa_root_dir_.path().AppendASCII(kPicasaDatabaseDirName))); | 248 picasa_root_dir_.path().AppendASCII(kPicasaDatabaseDirName))); |
249 ASSERT_TRUE(base::CreateDirectory( | 249 ASSERT_TRUE(base::CreateDirectory( |
250 picasa_root_dir_.path().AppendASCII(kPicasaTempDirName))); | 250 picasa_root_dir_.path().AppendASCII(kPicasaTempDirName))); |
251 | 251 |
252 picasa_data_provider_.reset(new TestPicasaDataProvider( | 252 picasa_data_provider_.reset(new TestPicasaDataProvider( |
253 picasa_root_dir_.path().AppendASCII(kPicasaDatabaseDirName))); | 253 picasa_root_dir_.path().AppendASCII(kPicasaDatabaseDirName))); |
254 } | 254 } |
255 | 255 |
256 virtual void StartTestOnMediaTaskRunner() { | 256 virtual void StartTestOnMediaTaskRunner() { |
257 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 257 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
258 | 258 |
259 data_provider()->RefreshData( | 259 data_provider()->RefreshData( |
260 RequestedDataType(), | 260 RequestedDataType(), |
261 base::Bind(&PicasaDataProviderTest::VerifyRefreshResults, | 261 base::Bind(&PicasaDataProviderTest::VerifyRefreshResults, |
262 base::Unretained(this))); | 262 base::Unretained(this))); |
263 } | 263 } |
264 | 264 |
265 void DestructDataProviderThenQuit() { | 265 void DestructDataProviderThenQuit() { |
266 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 266 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
267 picasa_data_provider_.reset(); | 267 picasa_data_provider_.reset(); |
268 content::BrowserThread::PostTask( | 268 content::BrowserThread::PostTask( |
269 content::BrowserThread::UI, FROM_HERE, quit_closure_); | 269 content::BrowserThread::UI, FROM_HERE, quit_closure_); |
270 } | 270 } |
271 | 271 |
272 base::ScopedTempDir test_folder_1_; | 272 base::ScopedTempDir test_folder_1_; |
273 base::ScopedTempDir test_folder_2_; | 273 base::ScopedTempDir test_folder_2_; |
274 base::ScopedTempDir picasa_root_dir_; | 274 base::ScopedTempDir picasa_root_dir_; |
275 | 275 |
276 std::unique_ptr<TestPicasaDataProvider> picasa_data_provider_; | 276 std::unique_ptr<TestPicasaDataProvider> picasa_data_provider_; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 401 |
402 private: | 402 private: |
403 void CheckTestDone() { | 403 void CheckTestDone() { |
404 ASSERT_LE(list_callbacks_called_, 2); | 404 ASSERT_LE(list_callbacks_called_, 2); |
405 ASSERT_LE(albums_images_callbacks_called_, 2); | 405 ASSERT_LE(albums_images_callbacks_called_, 2); |
406 if (list_callbacks_called_ == 2 && albums_images_callbacks_called_ == 2) | 406 if (list_callbacks_called_ == 2 && albums_images_callbacks_called_ == 2) |
407 TestDone(); | 407 TestDone(); |
408 } | 408 } |
409 | 409 |
410 void StartTestOnMediaTaskRunner() override { | 410 void StartTestOnMediaTaskRunner() override { |
411 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 411 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
412 | 412 |
413 data_provider()->RefreshData( | 413 data_provider()->RefreshData( |
414 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, | 414 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, |
415 base::Bind(&PicasaDataProviderMultipleMixedCallbacksTest::ListCallback, | 415 base::Bind(&PicasaDataProviderMultipleMixedCallbacksTest::ListCallback, |
416 base::Unretained(this), | 416 base::Unretained(this), |
417 1)); | 417 1)); |
418 data_provider()->RefreshData( | 418 data_provider()->RefreshData( |
419 PicasaDataProvider::ALBUMS_IMAGES_DATA, | 419 PicasaDataProvider::ALBUMS_IMAGES_DATA, |
420 base::Bind( | 420 base::Bind( |
421 &PicasaDataProviderMultipleMixedCallbacksTest::AlbumsImagesCallback, | 421 &PicasaDataProviderMultipleMixedCallbacksTest::AlbumsImagesCallback, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 468 |
469 data_provider()->MoveTempFilesToDatabase(); | 469 data_provider()->MoveTempFilesToDatabase(); |
470 } | 470 } |
471 | 471 |
472 base::FilePath GetColumnFileDestination() const override { | 472 base::FilePath GetColumnFileDestination() const override { |
473 return GetTempDirPath(); | 473 return GetTempDirPath(); |
474 } | 474 } |
475 | 475 |
476 private: | 476 private: |
477 void StartTestOnMediaTaskRunner() override { | 477 void StartTestOnMediaTaskRunner() override { |
478 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 478 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
479 | 479 |
480 // Refresh before moving album table to database dir, guaranteeing failure. | 480 // Refresh before moving album table to database dir, guaranteeing failure. |
481 data_provider()->RefreshData( | 481 data_provider()->RefreshData( |
482 RequestedDataType(), | 482 RequestedDataType(), |
483 base::Bind( | 483 base::Bind( |
484 &PicasaDataProviderFileWatcherInvalidateTest::ListCallback, | 484 &PicasaDataProviderFileWatcherInvalidateTest::ListCallback, |
485 base::Unretained(this))); | 485 base::Unretained(this))); |
486 } | 486 } |
487 }; | 487 }; |
488 | 488 |
489 IN_PROC_BROWSER_TEST_F(PicasaDataProviderFileWatcherInvalidateTest, | 489 IN_PROC_BROWSER_TEST_F(PicasaDataProviderFileWatcherInvalidateTest, |
490 FileWatcherInvalidateTest) { | 490 FileWatcherInvalidateTest) { |
491 RunTest(); | 491 RunTest(); |
492 } | 492 } |
493 | 493 |
494 class PicasaDataProviderInvalidateInflightTableReaderTest | 494 class PicasaDataProviderInvalidateInflightTableReaderTest |
495 : public PicasaDataProviderGetListTest { | 495 : public PicasaDataProviderGetListTest { |
496 protected: | 496 protected: |
497 // Don't write the database files until later. | 497 // Don't write the database files until later. |
498 void InitializeTestData() override {} | 498 void InitializeTestData() override {} |
499 | 499 |
500 private: | 500 private: |
501 void StartTestOnMediaTaskRunner() override { | 501 void StartTestOnMediaTaskRunner() override { |
502 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 502 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
503 | 503 |
504 // Refresh before the database files have been written. | 504 // Refresh before the database files have been written. |
505 // This is guaranteed to fail to read the album table. | 505 // This is guaranteed to fail to read the album table. |
506 data_provider()->RefreshData( | 506 data_provider()->RefreshData( |
507 RequestedDataType(), | 507 RequestedDataType(), |
508 base::Bind(&PicasaDataProviderInvalidateInflightTableReaderTest:: | 508 base::Bind(&PicasaDataProviderInvalidateInflightTableReaderTest:: |
509 VerifyRefreshResults, | 509 VerifyRefreshResults, |
510 base::Unretained(this))); | 510 base::Unretained(this))); |
511 | 511 |
512 // Now write the album table and invalidate the inflight table reader. | 512 // Now write the album table and invalidate the inflight table reader. |
(...skipping 25 matching lines...) Expand all Loading... |
538 base::Unretained(this))); | 538 base::Unretained(this))); |
539 | 539 |
540 // Now invalidate all the data. The album maps will be re-read. | 540 // Now invalidate all the data. The album maps will be re-read. |
541 data_provider()->InvalidateData(); | 541 data_provider()->InvalidateData(); |
542 | 542 |
543 // VerifyRefreshResults callback should receive correct results now. | 543 // VerifyRefreshResults callback should receive correct results now. |
544 } | 544 } |
545 | 545 |
546 private: | 546 private: |
547 void StartTestOnMediaTaskRunner() override { | 547 void StartTestOnMediaTaskRunner() override { |
548 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 548 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
549 | 549 |
550 data_provider()->RefreshData( | 550 data_provider()->RefreshData( |
551 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, | 551 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, |
552 base::Bind(&PicasaDataProviderInvalidateInflightAlbumsIndexerTest:: | 552 base::Bind(&PicasaDataProviderInvalidateInflightAlbumsIndexerTest:: |
553 ListCallback, | 553 ListCallback, |
554 base::Unretained(this))); | 554 base::Unretained(this))); |
555 } | 555 } |
556 }; | 556 }; |
557 | 557 |
558 IN_PROC_BROWSER_TEST_F(PicasaDataProviderInvalidateInflightAlbumsIndexerTest, | 558 IN_PROC_BROWSER_TEST_F(PicasaDataProviderInvalidateInflightAlbumsIndexerTest, |
559 InvalidateInflightAlbumsIndexerTest) { | 559 InvalidateInflightAlbumsIndexerTest) { |
560 RunTest(); | 560 RunTest(); |
561 } | 561 } |
562 | 562 |
563 } // namespace picasa | 563 } // namespace picasa |
OLD | NEW |