OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/file_util.h" |
| 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" |
| 11 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 12 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" |
| 13 #include "chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.h" |
| 14 #include "chrome/common/media_galleries/picasa_types.h" |
| 15 #include "chrome/common/media_galleries/pmp_test_helper.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "content/public/test/test_browser_thread.h" |
| 18 |
| 19 using chrome::MediaFileSystemBackend; |
| 20 |
| 21 namespace picasa { |
| 22 |
| 23 namespace { |
| 24 |
| 25 void WriteTestAlbumTable(PmpTestHelper* test_helper, |
| 26 base::FilePath test_folder_1_path, |
| 27 base::FilePath test_folder_2_path) { |
| 28 std::vector<uint32> category_vector; |
| 29 category_vector.push_back(kAlbumCategoryFolder); |
| 30 category_vector.push_back(kAlbumCategoryInvalid); |
| 31 category_vector.push_back(kAlbumCategoryAlbum); |
| 32 category_vector.push_back(kAlbumCategoryFolder); |
| 33 category_vector.push_back(kAlbumCategoryAlbum); |
| 34 |
| 35 std::vector<double> date_vector; |
| 36 date_vector.push_back(0.0); |
| 37 date_vector.push_back(0.0); |
| 38 date_vector.push_back(0.0); |
| 39 date_vector.push_back(0.0); |
| 40 date_vector.push_back(0.0); |
| 41 |
| 42 std::vector<std::string> filename_vector; |
| 43 filename_vector.push_back(test_folder_1_path.AsUTF8Unsafe()); |
| 44 filename_vector.push_back(""); |
| 45 filename_vector.push_back(""); |
| 46 filename_vector.push_back(test_folder_2_path.AsUTF8Unsafe()); |
| 47 filename_vector.push_back(""); |
| 48 |
| 49 std::vector<std::string> name_vector; |
| 50 name_vector.push_back(test_folder_1_path.BaseName().AsUTF8Unsafe()); |
| 51 name_vector.push_back(""); |
| 52 name_vector.push_back("Album 1 Name"); |
| 53 name_vector.push_back(test_folder_2_path.BaseName().AsUTF8Unsafe()); |
| 54 name_vector.push_back("Album 2 Name"); |
| 55 |
| 56 std::vector<std::string> token_vector; |
| 57 token_vector.push_back(""); |
| 58 token_vector.push_back(""); |
| 59 token_vector.push_back(std::string(kAlbumTokenPrefix) + "uid3"); |
| 60 token_vector.push_back(""); |
| 61 token_vector.push_back(std::string(kAlbumTokenPrefix) + "uid5"); |
| 62 |
| 63 std::vector<std::string> uid_vector; |
| 64 uid_vector.push_back("uid1"); |
| 65 uid_vector.push_back("uid2"); |
| 66 uid_vector.push_back("uid3"); |
| 67 uid_vector.push_back("uid4"); |
| 68 uid_vector.push_back("uid5"); |
| 69 |
| 70 ASSERT_TRUE(test_helper->WriteColumnFileFromVector( |
| 71 "category", PMP_TYPE_UINT32, category_vector)); |
| 72 ASSERT_TRUE(test_helper->WriteColumnFileFromVector( |
| 73 "date", PMP_TYPE_DOUBLE64, date_vector)); |
| 74 ASSERT_TRUE(test_helper->WriteColumnFileFromVector( |
| 75 "filename", PMP_TYPE_STRING, filename_vector)); |
| 76 ASSERT_TRUE(test_helper->WriteColumnFileFromVector( |
| 77 "name", PMP_TYPE_STRING, name_vector)); |
| 78 ASSERT_TRUE(test_helper->WriteColumnFileFromVector( |
| 79 "token", PMP_TYPE_STRING, token_vector)); |
| 80 ASSERT_TRUE(test_helper->WriteColumnFileFromVector( |
| 81 "uid", PMP_TYPE_STRING, uid_vector)); |
| 82 } |
| 83 |
| 84 void WriteAlbumsImagesIndex(const base::FilePath& test_folder_1_path, |
| 85 const base::FilePath& test_folder_2_path) { |
| 86 const char folder_1_test_ini[] = |
| 87 "[InBoth.jpg]\n" |
| 88 "albums=uid3,uid5\n" |
| 89 "[InSecondAlbumOnly.jpg]\n" |
| 90 "albums=uid5\n"; |
| 91 ASSERT_TRUE( |
| 92 file_util::WriteFile(test_folder_1_path.AppendASCII(kPicasaINIFilename), |
| 93 folder_1_test_ini, |
| 94 arraysize(folder_1_test_ini))); |
| 95 |
| 96 const char folder_2_test_ini[] = |
| 97 "[InFirstAlbumOnly.jpg]\n" |
| 98 "albums=uid3\n"; |
| 99 ASSERT_TRUE( |
| 100 file_util::WriteFile(test_folder_2_path.AppendASCII(kPicasaINIFilename), |
| 101 folder_2_test_ini, |
| 102 arraysize(folder_2_test_ini))); |
| 103 } |
| 104 |
| 105 void VerifyAlbumTable(PicasaDataProvider* data_provider, |
| 106 base::FilePath test_folder_1_path, |
| 107 base::FilePath test_folder_2_path) { |
| 108 scoped_ptr<AlbumMap> folders = data_provider->GetFolders(); |
| 109 ASSERT_TRUE(folders.get()); |
| 110 EXPECT_EQ(2u, folders->size()); |
| 111 |
| 112 AlbumMap::const_iterator folder_1 = folders->find( |
| 113 test_folder_1_path.BaseName().AsUTF8Unsafe() + " 1899-12-30"); |
| 114 EXPECT_NE(folders->end(), folder_1); |
| 115 EXPECT_EQ(test_folder_1_path.BaseName().AsUTF8Unsafe(), |
| 116 folder_1->second.name); |
| 117 EXPECT_EQ(test_folder_1_path, folder_1->second.path); |
| 118 EXPECT_EQ("uid1", folder_1->second.uid); |
| 119 |
| 120 AlbumMap::const_iterator folder_2 = folders->find( |
| 121 test_folder_2_path.BaseName().AsUTF8Unsafe() + " 1899-12-30"); |
| 122 EXPECT_NE(folders->end(), folder_2); |
| 123 EXPECT_EQ(test_folder_2_path.BaseName().AsUTF8Unsafe(), |
| 124 folder_2->second.name); |
| 125 EXPECT_EQ(test_folder_2_path, folder_2->second.path); |
| 126 EXPECT_EQ("uid4", folder_2->second.uid); |
| 127 |
| 128 scoped_ptr<AlbumMap> albums = data_provider->GetAlbums(); |
| 129 ASSERT_TRUE(albums.get()); |
| 130 EXPECT_EQ(2u, albums->size()); |
| 131 |
| 132 AlbumMap::const_iterator album_1 = albums->find("Album 1 Name 1899-12-30"); |
| 133 EXPECT_NE(albums->end(), album_1); |
| 134 EXPECT_EQ("Album 1 Name", album_1->second.name); |
| 135 EXPECT_EQ(base::FilePath(), album_1->second.path); |
| 136 EXPECT_EQ("uid3", album_1->second.uid); |
| 137 |
| 138 AlbumMap::const_iterator album_2 = albums->find("Album 2 Name 1899-12-30"); |
| 139 EXPECT_NE(albums->end(), album_2); |
| 140 EXPECT_EQ("Album 2 Name", album_2->second.name); |
| 141 EXPECT_EQ(base::FilePath(), album_2->second.path); |
| 142 EXPECT_EQ("uid5", album_2->second.uid); |
| 143 } |
| 144 |
| 145 void VerifyAlbumsImagesIndex(PicasaDataProvider* data_provider, |
| 146 base::FilePath test_folder_1_path, |
| 147 base::FilePath test_folder_2_path) { |
| 148 base::PlatformFileError error; |
| 149 scoped_ptr<AlbumImages> album_1_images = |
| 150 data_provider->FindAlbumImages("uid3", &error); |
| 151 ASSERT_TRUE(album_1_images); |
| 152 EXPECT_EQ(base::PLATFORM_FILE_OK, error); |
| 153 EXPECT_EQ(2u, album_1_images->size()); |
| 154 EXPECT_NE(album_1_images->end(), album_1_images->find("InBoth.jpg")); |
| 155 EXPECT_EQ(test_folder_1_path.AppendASCII("InBoth.jpg"), |
| 156 (*album_1_images)["InBoth.jpg"]); |
| 157 EXPECT_NE(album_1_images->end(), |
| 158 album_1_images->find("InFirstAlbumOnly.jpg")); |
| 159 EXPECT_EQ(test_folder_2_path.AppendASCII("InFirstAlbumOnly.jpg"), |
| 160 (*album_1_images)["InFirstAlbumOnly.jpg"]); |
| 161 |
| 162 scoped_ptr<AlbumImages> album_2_images = |
| 163 data_provider->FindAlbumImages("uid5", &error); |
| 164 ASSERT_TRUE(album_2_images); |
| 165 EXPECT_EQ(base::PLATFORM_FILE_OK, error); |
| 166 EXPECT_EQ(2u, album_2_images->size()); |
| 167 EXPECT_NE(album_2_images->end(), album_2_images->find("InBoth.jpg")); |
| 168 EXPECT_EQ(test_folder_1_path.AppendASCII("InBoth.jpg"), |
| 169 (*album_2_images)["InBoth.jpg"]); |
| 170 EXPECT_NE(album_2_images->end(), |
| 171 album_2_images->find("InSecondAlbumOnly.jpg")); |
| 172 EXPECT_EQ(test_folder_1_path.AppendASCII("InSecondAlbumOnly.jpg"), |
| 173 (*album_2_images)["InSecondAlbumOnly.jpg"]); |
| 174 } |
| 175 |
| 176 } // namespace |
| 177 |
| 178 class PicasaDataProviderTest : public InProcessBrowserTest { |
| 179 public: |
| 180 PicasaDataProviderTest() : test_helper_(kPicasaAlbumTableName) {} |
| 181 virtual ~PicasaDataProviderTest() {} |
| 182 |
| 183 protected: |
| 184 // Runs on the MediaTaskRunner and designed to be overridden by subclasses. |
| 185 virtual void InitializeTestData() {} |
| 186 |
| 187 void RunTest() { |
| 188 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 189 base::RunLoop loop; |
| 190 quit_closure_ = loop.QuitClosure(); |
| 191 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 192 FROM_HERE, |
| 193 base::Bind(&PicasaDataProviderTest::SetupFoldersAndDataProvider, |
| 194 base::Unretained(this))); |
| 195 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 196 FROM_HERE, |
| 197 base::Bind(&PicasaDataProviderTest::InitializeTestData, |
| 198 base::Unretained(this))); |
| 199 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 200 FROM_HERE, |
| 201 base::Bind(&PicasaDataProviderTest::StartTestOnMediaTaskRunner, |
| 202 base::Unretained(this))); |
| 203 loop.Run(); |
| 204 } |
| 205 |
| 206 virtual PicasaDataProvider::DataType RequestedDataType() const = 0; |
| 207 |
| 208 // Start the test. The data provider is refreshed before calling StartTest |
| 209 // and the result of the refresh is passed in. |
| 210 virtual void VerifyRefreshResults(bool parse_success) {}; |
| 211 |
| 212 void TestDone() { |
| 213 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 214 |
| 215 // The data provider must be destructed on the MediaTaskRunner. This is done |
| 216 // in a posted task rather than directly because TestDone is called by |
| 217 // PicasaDataProvider. The callee should not destroy the caller. |
| 218 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 219 FROM_HERE, |
| 220 base::Bind(&PicasaDataProviderTest::DestructDataProviderThenQuit, |
| 221 base::Unretained(this))); |
| 222 } |
| 223 |
| 224 const base::FilePath& test_folder_1_path() { return test_folder_1_.path(); } |
| 225 const base::FilePath& test_folder_2_path() { return test_folder_2_.path(); } |
| 226 |
| 227 PmpTestHelper* test_helper() { return &test_helper_; } |
| 228 |
| 229 PicasaDataProvider* data_provider() const { |
| 230 return picasa_data_provider_.get(); |
| 231 } |
| 232 |
| 233 private: |
| 234 void SetupFoldersAndDataProvider() { |
| 235 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 236 ASSERT_TRUE(test_folder_1_.CreateUniqueTempDir()); |
| 237 ASSERT_TRUE(test_folder_2_.CreateUniqueTempDir()); |
| 238 ASSERT_TRUE(test_helper_.Init()); |
| 239 picasa_data_provider_.reset( |
| 240 new PicasaDataProvider(test_helper_.GetTempDirPath())); |
| 241 } |
| 242 |
| 243 virtual void StartTestOnMediaTaskRunner() { |
| 244 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 245 |
| 246 data_provider()->RefreshData( |
| 247 RequestedDataType(), |
| 248 base::Bind(&PicasaDataProviderTest::VerifyRefreshResults, |
| 249 base::Unretained(this))); |
| 250 } |
| 251 |
| 252 void DestructDataProviderThenQuit() { |
| 253 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 254 picasa_data_provider_.reset(); |
| 255 content::BrowserThread::PostTask( |
| 256 content::BrowserThread::UI, FROM_HERE, quit_closure_); |
| 257 } |
| 258 |
| 259 base::ScopedTempDir test_folder_1_; |
| 260 base::ScopedTempDir test_folder_2_; |
| 261 |
| 262 PmpTestHelper test_helper_; |
| 263 scoped_ptr<PicasaDataProvider> picasa_data_provider_; |
| 264 |
| 265 base::Closure quit_closure_; |
| 266 |
| 267 DISALLOW_COPY_AND_ASSIGN(PicasaDataProviderTest); |
| 268 }; |
| 269 |
| 270 class PicasaDataProviderNoDatabaseGetListTest : public PicasaDataProviderTest { |
| 271 protected: |
| 272 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { |
| 273 return PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA; |
| 274 } |
| 275 virtual void VerifyRefreshResults(bool parse_success) OVERRIDE { |
| 276 EXPECT_FALSE(parse_success); |
| 277 TestDone(); |
| 278 } |
| 279 }; |
| 280 |
| 281 IN_PROC_BROWSER_TEST_F(PicasaDataProviderNoDatabaseGetListTest, |
| 282 NoDatabaseGetList) { |
| 283 RunTest(); |
| 284 } |
| 285 |
| 286 class PicasaDataProviderNoDatabaseGetAlbumsImagesTest |
| 287 : public PicasaDataProviderTest { |
| 288 protected: |
| 289 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { |
| 290 return PicasaDataProvider::ALBUMS_IMAGES_DATA; |
| 291 } |
| 292 virtual void VerifyRefreshResults(bool parse_success) OVERRIDE { |
| 293 EXPECT_FALSE(parse_success); |
| 294 TestDone(); |
| 295 } |
| 296 }; |
| 297 |
| 298 IN_PROC_BROWSER_TEST_F(PicasaDataProviderNoDatabaseGetAlbumsImagesTest, |
| 299 NoDatabaseGetAlbumsImages) { |
| 300 RunTest(); |
| 301 } |
| 302 |
| 303 class PicasaDataProviderGetListTest : public PicasaDataProviderTest { |
| 304 protected: |
| 305 virtual void InitializeTestData() OVERRIDE { |
| 306 WriteTestAlbumTable( |
| 307 test_helper(), test_folder_1_path(), test_folder_2_path()); |
| 308 } |
| 309 |
| 310 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { |
| 311 return PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA; |
| 312 } |
| 313 |
| 314 virtual void VerifyRefreshResults(bool parse_success) OVERRIDE { |
| 315 ASSERT_TRUE(parse_success); |
| 316 VerifyAlbumTable( |
| 317 data_provider(), test_folder_1_path(), test_folder_2_path()); |
| 318 TestDone(); |
| 319 } |
| 320 }; |
| 321 |
| 322 IN_PROC_BROWSER_TEST_F(PicasaDataProviderGetListTest, GetListTest) { |
| 323 RunTest(); |
| 324 } |
| 325 |
| 326 class PicasaDataProviderGetAlbumsImagesTest : public PicasaDataProviderTest { |
| 327 protected: |
| 328 virtual void InitializeTestData() OVERRIDE { |
| 329 WriteTestAlbumTable( |
| 330 test_helper(), test_folder_1_path(), test_folder_2_path()); |
| 331 WriteAlbumsImagesIndex(test_folder_1_path(), test_folder_2_path()); |
| 332 } |
| 333 |
| 334 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { |
| 335 return PicasaDataProvider::ALBUMS_IMAGES_DATA; |
| 336 } |
| 337 |
| 338 virtual void VerifyRefreshResults(bool parse_success) OVERRIDE { |
| 339 ASSERT_TRUE(parse_success); |
| 340 VerifyAlbumTable( |
| 341 data_provider(), test_folder_1_path(), test_folder_2_path()); |
| 342 VerifyAlbumsImagesIndex( |
| 343 data_provider(), test_folder_1_path(), test_folder_2_path()); |
| 344 TestDone(); |
| 345 } |
| 346 }; |
| 347 |
| 348 IN_PROC_BROWSER_TEST_F(PicasaDataProviderGetAlbumsImagesTest, |
| 349 GetAlbumsImagesTest) { |
| 350 RunTest(); |
| 351 } |
| 352 |
| 353 class PicasaDataProviderMultipleMixedCallbacksTest |
| 354 : public PicasaDataProviderTest { |
| 355 public: |
| 356 PicasaDataProviderMultipleMixedCallbacksTest() |
| 357 : list_callbacks_called_(0), albums_images_callbacks_called_(0) {} |
| 358 |
| 359 virtual void InitializeTestData() OVERRIDE { |
| 360 WriteTestAlbumTable( |
| 361 test_helper(), test_folder_1_path(), test_folder_2_path()); |
| 362 WriteAlbumsImagesIndex(test_folder_1_path(), test_folder_2_path()); |
| 363 } |
| 364 |
| 365 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { |
| 366 return PicasaDataProvider::ALBUMS_IMAGES_DATA; |
| 367 } |
| 368 |
| 369 protected: |
| 370 virtual void ListCallback(int expected_list_callbacks_called, |
| 371 bool parse_success) { |
| 372 ASSERT_TRUE(parse_success); |
| 373 ASSERT_EQ(expected_list_callbacks_called, ++list_callbacks_called_); |
| 374 VerifyAlbumTable( |
| 375 data_provider(), test_folder_1_path(), test_folder_2_path()); |
| 376 CheckTestDone(); |
| 377 } |
| 378 |
| 379 virtual void AlbumsImagesCallback(int expected_albums_images_callbacks_called, |
| 380 bool parse_success) { |
| 381 ASSERT_TRUE(parse_success); |
| 382 ASSERT_EQ(expected_albums_images_callbacks_called, |
| 383 ++albums_images_callbacks_called_); |
| 384 VerifyAlbumsImagesIndex( |
| 385 data_provider(), test_folder_1_path(), test_folder_2_path()); |
| 386 CheckTestDone(); |
| 387 } |
| 388 |
| 389 private: |
| 390 void CheckTestDone() { |
| 391 ASSERT_LE(list_callbacks_called_, 2); |
| 392 ASSERT_LE(albums_images_callbacks_called_, 2); |
| 393 if (list_callbacks_called_ == 2 && albums_images_callbacks_called_ == 2) |
| 394 TestDone(); |
| 395 } |
| 396 |
| 397 virtual void StartTestOnMediaTaskRunner() OVERRIDE { |
| 398 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 399 |
| 400 data_provider()->RefreshData( |
| 401 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, |
| 402 base::Bind(&PicasaDataProviderMultipleMixedCallbacksTest::ListCallback, |
| 403 base::Unretained(this), |
| 404 1)); |
| 405 data_provider()->RefreshData( |
| 406 PicasaDataProvider::ALBUMS_IMAGES_DATA, |
| 407 base::Bind( |
| 408 &PicasaDataProviderMultipleMixedCallbacksTest::AlbumsImagesCallback, |
| 409 base::Unretained(this), |
| 410 1)); |
| 411 data_provider()->RefreshData( |
| 412 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, |
| 413 base::Bind(&PicasaDataProviderMultipleMixedCallbacksTest::ListCallback, |
| 414 base::Unretained(this), |
| 415 2)); |
| 416 data_provider()->RefreshData( |
| 417 PicasaDataProvider::ALBUMS_IMAGES_DATA, |
| 418 base::Bind( |
| 419 &PicasaDataProviderMultipleMixedCallbacksTest::AlbumsImagesCallback, |
| 420 base::Unretained(this), |
| 421 2)); |
| 422 } |
| 423 |
| 424 int list_callbacks_called_; |
| 425 int albums_images_callbacks_called_; |
| 426 }; |
| 427 |
| 428 IN_PROC_BROWSER_TEST_F(PicasaDataProviderMultipleMixedCallbacksTest, |
| 429 MultipleMixedCallbacks) { |
| 430 RunTest(); |
| 431 } |
| 432 |
| 433 class PicasaDataProviderInvalidateSimpleTest : public PicasaDataProviderTest { |
| 434 protected: |
| 435 virtual void FirstListCallback(bool parse_success) { |
| 436 ASSERT_FALSE(parse_success); |
| 437 WriteTestAlbumTable( |
| 438 test_helper(), test_folder_1_path(), test_folder_2_path()); |
| 439 |
| 440 // TODO(tommycli): Remove this line once database is under file watch. |
| 441 data_provider()->InvalidateData(); |
| 442 |
| 443 // Have to post this, otherwise this will run the callback immediately. |
| 444 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 445 FROM_HERE, |
| 446 base::Bind( |
| 447 &PicasaDataProvider::RefreshData, |
| 448 base::Unretained(data_provider()), |
| 449 RequestedDataType(), |
| 450 base::Bind( |
| 451 &PicasaDataProviderInvalidateSimpleTest::SecondListCallback, |
| 452 base::Unretained(this)))); |
| 453 } |
| 454 |
| 455 virtual void SecondListCallback(bool parse_success) { |
| 456 ASSERT_TRUE(parse_success); |
| 457 VerifyAlbumTable( |
| 458 data_provider(), test_folder_1_path(), test_folder_2_path()); |
| 459 TestDone(); |
| 460 } |
| 461 |
| 462 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { |
| 463 return PicasaDataProvider::ALBUMS_IMAGES_DATA; |
| 464 } |
| 465 |
| 466 private: |
| 467 virtual void StartTestOnMediaTaskRunner() OVERRIDE { |
| 468 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 469 |
| 470 data_provider()->RefreshData( |
| 471 RequestedDataType(), |
| 472 base::Bind(&PicasaDataProviderInvalidateSimpleTest::FirstListCallback, |
| 473 base::Unretained(this))); |
| 474 } |
| 475 }; |
| 476 |
| 477 IN_PROC_BROWSER_TEST_F(PicasaDataProviderInvalidateSimpleTest, |
| 478 InvalidateSimpleTest) { |
| 479 RunTest(); |
| 480 } |
| 481 |
| 482 class PicasaDataProviderInvalidateInflightTableReaderTest |
| 483 : public PicasaDataProviderGetListTest { |
| 484 private: |
| 485 virtual void StartTestOnMediaTaskRunner() OVERRIDE { |
| 486 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 487 |
| 488 // Temporarily empty the database path to guarantee that the first utility |
| 489 // process will fail to read the database. |
| 490 data_provider()->SetDatabasePathForTesting(base::FilePath()); |
| 491 data_provider()->RefreshData( |
| 492 RequestedDataType(), |
| 493 base::Bind(&PicasaDataProviderInvalidateInflightTableReaderTest:: |
| 494 VerifyRefreshResults, |
| 495 base::Unretained(this))); |
| 496 |
| 497 // Now restore the database path and invalidate the inflight table reader. |
| 498 data_provider()->SetDatabasePathForTesting(test_helper()->GetTempDirPath()); |
| 499 data_provider()->InvalidateData(); |
| 500 |
| 501 // VerifyRefreshResults callback should receive correct results now. |
| 502 } |
| 503 }; |
| 504 |
| 505 IN_PROC_BROWSER_TEST_F(PicasaDataProviderInvalidateInflightTableReaderTest, |
| 506 InvalidateInflightTableReaderTest) { |
| 507 RunTest(); |
| 508 } |
| 509 |
| 510 class PicasaDataProviderInvalidateInflightAlbumsIndexerTest |
| 511 : public PicasaDataProviderGetAlbumsImagesTest { |
| 512 protected: |
| 513 virtual void ListCallback(bool parse_success) { |
| 514 ASSERT_TRUE(parse_success); |
| 515 |
| 516 // Empty the album maps to guarantee that the first utility process will |
| 517 // give incorrect results. |
| 518 data_provider()->SetAlbumMapsForTesting(AlbumMap(), AlbumMap()); |
| 519 data_provider()->RefreshData( |
| 520 PicasaDataProvider::ALBUMS_IMAGES_DATA, |
| 521 base::Bind(&PicasaDataProviderInvalidateInflightAlbumsIndexerTest:: |
| 522 VerifyRefreshResults, |
| 523 base::Unretained(this))); |
| 524 |
| 525 // Now invalidate all the data. The album maps will be re-read. |
| 526 data_provider()->InvalidateData(); |
| 527 |
| 528 // VerifyRefreshResults callback should receive correct results now. |
| 529 } |
| 530 |
| 531 private: |
| 532 virtual void StartTestOnMediaTaskRunner() OVERRIDE { |
| 533 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 534 |
| 535 data_provider()->RefreshData( |
| 536 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, |
| 537 base::Bind(&PicasaDataProviderInvalidateInflightAlbumsIndexerTest:: |
| 538 ListCallback, |
| 539 base::Unretained(this))); |
| 540 } |
| 541 }; |
| 542 |
| 543 IN_PROC_BROWSER_TEST_F(PicasaDataProviderInvalidateInflightAlbumsIndexerTest, |
| 544 InvalidateInflightAlbumsIndexerTest) { |
| 545 RunTest(); |
| 546 } |
| 547 |
| 548 } // namespace picasa |
OLD | NEW |