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