| 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(PmpTestHelper* test_helper, | |
| 27 base::FilePath test_folder_1_path, | |
| 28 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 void SetupFoldersAndDataProvider() { | |
| 285 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | |
| 286 ASSERT_TRUE(test_folder_1_.CreateUniqueTempDir()); | |
| 287 ASSERT_TRUE(test_folder_2_.CreateUniqueTempDir()); | |
| 288 ASSERT_TRUE(database_dir_.CreateUniqueTempDir()); | |
| 289 ASSERT_TRUE(test_helper_.Init()); | |
| 290 picasa_data_provider_.reset(new TestPicasaDataProvider( | |
| 291 test_helper_.GetDatabaseDirPath())); | |
| 292 } | |
| 293 | |
| 294 virtual void StartTestOnMediaTaskRunner() { | |
| 295 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | |
| 296 | |
| 297 data_provider()->MoveTempFilesToDatabase(); | |
| 298 | |
| 299 data_provider()->RefreshData( | |
| 300 RequestedDataType(), | |
| 301 base::Bind(&PicasaDataProviderTest::VerifyRefreshResults, | |
| 302 base::Unretained(this))); | |
| 303 } | |
| 304 | |
| 305 void DestructDataProviderThenQuit() { | |
| 306 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | |
| 307 picasa_data_provider_.reset(); | |
| 308 content::BrowserThread::PostTask( | |
| 309 content::BrowserThread::UI, FROM_HERE, quit_closure_); | |
| 310 } | |
| 311 | |
| 312 base::ScopedTempDir test_folder_1_; | |
| 313 base::ScopedTempDir test_folder_2_; | |
| 314 base::ScopedTempDir database_dir_; | |
| 315 | |
| 316 PmpTestHelper test_helper_; | |
| 317 scoped_ptr<TestPicasaDataProvider> picasa_data_provider_; | |
| 318 | |
| 319 base::Closure quit_closure_; | |
| 320 | |
| 321 DISALLOW_COPY_AND_ASSIGN(PicasaDataProviderTest); | |
| 322 }; | |
| 323 | |
| 324 class PicasaDataProviderNoDatabaseGetListTest : public PicasaDataProviderTest { | |
| 325 protected: | |
| 326 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { | |
| 327 return PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA; | |
| 328 } | |
| 329 virtual void VerifyRefreshResults(bool parse_success) OVERRIDE { | |
| 330 EXPECT_FALSE(parse_success); | |
| 331 TestDone(); | |
| 332 } | |
| 333 }; | |
| 334 | |
| 335 IN_PROC_BROWSER_TEST_F(PicasaDataProviderNoDatabaseGetListTest, | |
| 336 NoDatabaseGetList) { | |
| 337 RunTest(); | |
| 338 } | |
| 339 | |
| 340 class PicasaDataProviderNoDatabaseGetAlbumsImagesTest | |
| 341 : public PicasaDataProviderTest { | |
| 342 protected: | |
| 343 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { | |
| 344 return PicasaDataProvider::ALBUMS_IMAGES_DATA; | |
| 345 } | |
| 346 virtual void VerifyRefreshResults(bool parse_success) OVERRIDE { | |
| 347 EXPECT_FALSE(parse_success); | |
| 348 TestDone(); | |
| 349 } | |
| 350 }; | |
| 351 | |
| 352 IN_PROC_BROWSER_TEST_F(PicasaDataProviderNoDatabaseGetAlbumsImagesTest, | |
| 353 NoDatabaseGetAlbumsImages) { | |
| 354 RunTest(); | |
| 355 } | |
| 356 | |
| 357 class PicasaDataProviderGetListTest : public PicasaDataProviderTest { | |
| 358 protected: | |
| 359 virtual void InitializeTestData() OVERRIDE { | |
| 360 WriteTestAlbumTable( | |
| 361 test_helper(), test_folder_1_path(), test_folder_2_path()); | |
| 362 } | |
| 363 | |
| 364 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { | |
| 365 return PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA; | |
| 366 } | |
| 367 | |
| 368 virtual void VerifyRefreshResults(bool parse_success) OVERRIDE { | |
| 369 ASSERT_TRUE(parse_success); | |
| 370 VerifyAlbumTable( | |
| 371 data_provider(), test_folder_1_path(), test_folder_2_path()); | |
| 372 TestDone(); | |
| 373 } | |
| 374 }; | |
| 375 | |
| 376 IN_PROC_BROWSER_TEST_F(PicasaDataProviderGetListTest, GetListTest) { | |
| 377 RunTest(); | |
| 378 } | |
| 379 | |
| 380 class PicasaDataProviderGetAlbumsImagesTest : public PicasaDataProviderTest { | |
| 381 protected: | |
| 382 virtual void InitializeTestData() OVERRIDE { | |
| 383 WriteTestAlbumTable( | |
| 384 test_helper(), test_folder_1_path(), test_folder_2_path()); | |
| 385 WriteAlbumsImagesIndex(test_folder_1_path(), test_folder_2_path()); | |
| 386 } | |
| 387 | |
| 388 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { | |
| 389 return PicasaDataProvider::ALBUMS_IMAGES_DATA; | |
| 390 } | |
| 391 | |
| 392 virtual void VerifyRefreshResults(bool parse_success) OVERRIDE { | |
| 393 ASSERT_TRUE(parse_success); | |
| 394 VerifyAlbumTable( | |
| 395 data_provider(), test_folder_1_path(), test_folder_2_path()); | |
| 396 VerifyAlbumsImagesIndex( | |
| 397 data_provider(), test_folder_1_path(), test_folder_2_path()); | |
| 398 TestDone(); | |
| 399 } | |
| 400 }; | |
| 401 | |
| 402 IN_PROC_BROWSER_TEST_F(PicasaDataProviderGetAlbumsImagesTest, | |
| 403 GetAlbumsImagesTest) { | |
| 404 RunTest(); | |
| 405 } | |
| 406 | |
| 407 class PicasaDataProviderMultipleMixedCallbacksTest | |
| 408 : public PicasaDataProviderTest { | |
| 409 public: | |
| 410 PicasaDataProviderMultipleMixedCallbacksTest() | |
| 411 : list_callbacks_called_(0), albums_images_callbacks_called_(0) {} | |
| 412 | |
| 413 virtual void InitializeTestData() OVERRIDE { | |
| 414 WriteTestAlbumTable( | |
| 415 test_helper(), test_folder_1_path(), test_folder_2_path()); | |
| 416 WriteAlbumsImagesIndex(test_folder_1_path(), test_folder_2_path()); | |
| 417 } | |
| 418 | |
| 419 virtual PicasaDataProvider::DataType RequestedDataType() const OVERRIDE { | |
| 420 return PicasaDataProvider::ALBUMS_IMAGES_DATA; | |
| 421 } | |
| 422 | |
| 423 protected: | |
| 424 virtual void ListCallback(int expected_list_callbacks_called, | |
| 425 bool parse_success) { | |
| 426 ASSERT_TRUE(parse_success); | |
| 427 ASSERT_EQ(expected_list_callbacks_called, ++list_callbacks_called_); | |
| 428 VerifyAlbumTable( | |
| 429 data_provider(), test_folder_1_path(), test_folder_2_path()); | |
| 430 CheckTestDone(); | |
| 431 } | |
| 432 | |
| 433 virtual void AlbumsImagesCallback(int expected_albums_images_callbacks_called, | |
| 434 bool parse_success) { | |
| 435 ASSERT_TRUE(parse_success); | |
| 436 ASSERT_EQ(expected_albums_images_callbacks_called, | |
| 437 ++albums_images_callbacks_called_); | |
| 438 VerifyAlbumsImagesIndex( | |
| 439 data_provider(), test_folder_1_path(), test_folder_2_path()); | |
| 440 CheckTestDone(); | |
| 441 } | |
| 442 | |
| 443 private: | |
| 444 void CheckTestDone() { | |
| 445 ASSERT_LE(list_callbacks_called_, 2); | |
| 446 ASSERT_LE(albums_images_callbacks_called_, 2); | |
| 447 if (list_callbacks_called_ == 2 && albums_images_callbacks_called_ == 2) | |
| 448 TestDone(); | |
| 449 } | |
| 450 | |
| 451 virtual void StartTestOnMediaTaskRunner() OVERRIDE { | |
| 452 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | |
| 453 | |
| 454 data_provider()->MoveTempFilesToDatabase(); | |
| 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 void StartTestOnMediaTaskRunner() OVERRIDE { | |
| 509 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | |
| 510 | |
| 511 // Refresh before moving album table to database dir, guaranteeing failure. | |
| 512 data_provider()->RefreshData( | |
| 513 RequestedDataType(), | |
| 514 base::Bind( | |
| 515 &PicasaDataProviderFileWatcherInvalidateTest::ListCallback, | |
| 516 base::Unretained(this))); | |
| 517 } | |
| 518 }; | |
| 519 | |
| 520 IN_PROC_BROWSER_TEST_F(PicasaDataProviderFileWatcherInvalidateTest, | |
| 521 FileWatcherInvalidateTest) { | |
| 522 RunTest(); | |
| 523 } | |
| 524 | |
| 525 class PicasaDataProviderInvalidateInflightTableReaderTest | |
| 526 : public PicasaDataProviderGetListTest { | |
| 527 private: | |
| 528 virtual void StartTestOnMediaTaskRunner() OVERRIDE { | |
| 529 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | |
| 530 | |
| 531 // Refresh before the database files have been moved into the database. | |
| 532 // This is guaranteed to fail to read the album table. | |
| 533 data_provider()->RefreshData( | |
| 534 RequestedDataType(), | |
| 535 base::Bind(&PicasaDataProviderInvalidateInflightTableReaderTest:: | |
| 536 VerifyRefreshResults, | |
| 537 base::Unretained(this))); | |
| 538 | |
| 539 // Now move table into database and invalidate the inflight table reader. | |
| 540 data_provider()->MoveTempFilesToDatabase(); | |
| 541 data_provider()->InvalidateData(); | |
| 542 | |
| 543 // VerifyRefreshResults callback should receive correct results now. | |
| 544 } | |
| 545 }; | |
| 546 | |
| 547 IN_PROC_BROWSER_TEST_F(PicasaDataProviderInvalidateInflightTableReaderTest, | |
| 548 InvalidateInflightTableReaderTest) { | |
| 549 RunTest(); | |
| 550 } | |
| 551 | |
| 552 class PicasaDataProviderInvalidateInflightAlbumsIndexerTest | |
| 553 : public PicasaDataProviderGetAlbumsImagesTest { | |
| 554 protected: | |
| 555 virtual void ListCallback(bool parse_success) { | |
| 556 ASSERT_TRUE(parse_success); | |
| 557 | |
| 558 // Empty the album maps to guarantee that the first utility process will | |
| 559 // fail to get the correct albums-images index. | |
| 560 data_provider()->SetAlbumMapsForTesting(AlbumMap(), AlbumMap()); | |
| 561 data_provider()->RefreshData( | |
| 562 PicasaDataProvider::ALBUMS_IMAGES_DATA, | |
| 563 base::Bind(&PicasaDataProviderInvalidateInflightAlbumsIndexerTest:: | |
| 564 VerifyRefreshResults, | |
| 565 base::Unretained(this))); | |
| 566 | |
| 567 // Now invalidate all the data. The album maps will be re-read. | |
| 568 data_provider()->InvalidateData(); | |
| 569 | |
| 570 // VerifyRefreshResults callback should receive correct results now. | |
| 571 } | |
| 572 | |
| 573 private: | |
| 574 virtual void StartTestOnMediaTaskRunner() OVERRIDE { | |
| 575 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | |
| 576 | |
| 577 data_provider()->MoveTempFilesToDatabase(); | |
| 578 | |
| 579 data_provider()->RefreshData( | |
| 580 PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA, | |
| 581 base::Bind(&PicasaDataProviderInvalidateInflightAlbumsIndexerTest:: | |
| 582 ListCallback, | |
| 583 base::Unretained(this))); | |
| 584 } | |
| 585 }; | |
| 586 | |
| 587 IN_PROC_BROWSER_TEST_F(PicasaDataProviderInvalidateInflightAlbumsIndexerTest, | |
| 588 InvalidateInflightAlbumsIndexerTest) { | |
| 589 RunTest(); | |
| 590 } | |
| 591 | |
| 592 } // namespace picasa | |
| OLD | NEW |