Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 EXPECT_TRUE(false); | 223 EXPECT_TRUE(false); |
| 224 return; | 224 return; |
| 225 } | 225 } |
| 226 MediaGalleriesPrefInfoMap::const_iterator pref_info = | 226 MediaGalleriesPrefInfoMap::const_iterator pref_info = |
| 227 known_galleries().find(pref_id); | 227 known_galleries().find(pref_id); |
| 228 EXPECT_EQ(audio_count, pref_info->second.audio_count); | 228 EXPECT_EQ(audio_count, pref_info->second.audio_count); |
| 229 EXPECT_EQ(image_count, pref_info->second.image_count); | 229 EXPECT_EQ(image_count, pref_info->second.image_count); |
| 230 EXPECT_EQ(video_count, pref_info->second.video_count); | 230 EXPECT_EQ(video_count, pref_info->second.video_count); |
| 231 } | 231 } |
| 232 | 232 |
| 233 // MediaScanMangerObserver implementation. | 233 // MediaScanManagerObserver implementation. |
| 234 virtual void OnScanFinished( | 234 virtual void OnScanFinished( |
| 235 const std::string& extension_id, | 235 const std::string& extension_id, |
| 236 int gallery_count, | 236 int gallery_count, |
| 237 const MediaGalleryScanResult& file_counts) OVERRIDE { | 237 const MediaGalleryScanResult& file_counts) OVERRIDE { |
| 238 EXPECT_EQ(extension_->id(), extension_id); | 238 EXPECT_EQ(extension_->id(), extension_id); |
| 239 EXPECT_EQ(expected_gallery_count_, gallery_count); | 239 EXPECT_EQ(expected_gallery_count_, gallery_count); |
| 240 EXPECT_EQ(expected_file_counts_.audio_count, file_counts.audio_count); | 240 EXPECT_EQ(expected_file_counts_.audio_count, file_counts.audio_count); |
| 241 EXPECT_EQ(expected_file_counts_.image_count, file_counts.image_count); | 241 EXPECT_EQ(expected_file_counts_.image_count, file_counts.image_count); |
| 242 EXPECT_EQ(expected_file_counts_.video_count, file_counts.video_count); | 242 EXPECT_EQ(expected_file_counts_.video_count, file_counts.video_count); |
| 243 } | 243 } |
| 244 | 244 |
| 245 protected: | |
| 246 // So derived tests can access ...::FindContainerScanResults(). | |
| 247 MediaFolderFinder::MediaFolderFinderResults FindContainerScanResults( | |
| 248 const MediaFolderFinder::MediaFolderFinderResults& found_folders, | |
| 249 const std::vector<base::FilePath>& sensitive_locations) { | |
| 250 return MediaScanManager::FindContainerScanResults(found_folders, | |
| 251 sensitive_locations); | |
| 252 } | |
| 253 | |
| 245 private: | 254 private: |
| 246 void OnFindFoldersStarted( | 255 void OnFindFoldersStarted( |
| 247 MediaFolderFinder::MediaFolderFinderResultsCallback callback) { | 256 MediaFolderFinder::MediaFolderFinderResultsCallback callback) { |
| 248 find_folders_start_count_++; | 257 find_folders_start_count_++; |
| 249 callback.Run(find_folders_success_, find_folders_results_); | 258 callback.Run(find_folders_success_, find_folders_results_); |
| 250 } | 259 } |
| 251 | 260 |
| 252 void OnFindFoldersDestroyed() { | 261 void OnFindFoldersDestroyed() { |
| 253 find_folders_destroy_count_++; | 262 find_folders_destroy_count_++; |
| 254 } | 263 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 SetFindFoldersResults(true, found_folders); | 308 SetFindFoldersResults(true, found_folders); |
| 300 | 309 |
| 301 SetExpectedScanResults(1 /*gallery_count*/, file_counts); | 310 SetExpectedScanResults(1 /*gallery_count*/, file_counts); |
| 302 StartScan(); | 311 StartScan(); |
| 303 | 312 |
| 304 base::RunLoop().RunUntilIdle(); | 313 base::RunLoop().RunUntilIdle(); |
| 305 EXPECT_EQ(1, FindFolderDestroyCount()); | 314 EXPECT_EQ(1, FindFolderDestroyCount()); |
| 306 EXPECT_EQ(galleries_before + 1, gallery_count()); | 315 EXPECT_EQ(galleries_before + 1, gallery_count()); |
| 307 } | 316 } |
| 308 | 317 |
| 318 // Generally test that it includes directories with sufficient density | |
| 319 // and excludes others. | |
| 320 // | |
| 321 // A/ - NOT included | |
| 322 // A/B/ * | |
|
vandebo (ex-Chrome)
2014/05/30 20:30:24
* = container result? Please note.
Kevin Bailey
2014/06/01 21:12:40
Done.
| |
| 323 // A/B/C/files | |
| 324 // A/D/ - NOT included | |
| 325 // A/D/E/files | |
| 326 // A/D/F/files | |
| 327 // A/D/G/files | |
| 328 // A/D/H/ | |
| 329 // A/H/ * | |
| 330 // A/H/I/files | |
| 331 // A/H/J/files | |
| 332 TEST_F(MediaScanManagerTest, MergeRedundant) { | |
| 333 base::FilePath path; | |
| 334 MediaFolderFinder::MediaFolderFinderResults found_folders; | |
| 335 std::vector<base::FilePath> sensitive_locations; | |
| 336 std::vector<base::FilePath> expected_folders; | |
| 337 MediaGalleryScanResult file_counts; | |
| 338 file_counts.audio_count = 1; | |
| 339 file_counts.image_count = 2; | |
| 340 file_counts.video_count = 3; | |
| 341 MakeTestFolder("A", &path); | |
| 342 MakeTestFolder("A/B", &path); | |
| 343 expected_folders.push_back(path); | |
| 344 MakeTestFolder("A/B/C", &path); | |
| 345 found_folders[path] = file_counts; | |
| 346 // Not dense enough. | |
| 347 MakeTestFolder("A/D", &path); | |
| 348 MakeTestFolder("A/D/E", &path); | |
| 349 found_folders[path] = file_counts; | |
| 350 MakeTestFolder("A/D/F", &path); | |
| 351 found_folders[path] = file_counts; | |
| 352 MakeTestFolder("A/D/G", &path); | |
| 353 found_folders[path] = file_counts; | |
| 354 MakeTestFolder("A/D/H", &path); | |
| 355 // Dense enough to be reported. | |
| 356 MakeTestFolder("A/H", &path); | |
| 357 expected_folders.push_back(path); | |
| 358 MakeTestFolder("A/H/I", &path); | |
| 359 found_folders[path] = file_counts; | |
| 360 MakeTestFolder("A/H/J", &path); | |
| 361 found_folders[path] = file_counts; | |
| 362 MediaFolderFinder::MediaFolderFinderResults results = | |
| 363 FindContainerScanResults(found_folders, sensitive_locations); | |
| 364 EXPECT_EQ(expected_folders.size(), results.size()); | |
| 365 for (std::vector<base::FilePath>::const_iterator it = | |
| 366 expected_folders.begin(); | |
| 367 it != expected_folders.end(); ++it) { | |
| 368 EXPECT_TRUE(results.find(*it) != results.end()); | |
| 369 } | |
| 370 } | |
| 371 | |
| 372 // Make sure intermediates are included. | |
| 373 // | |
| 374 // A/ * | |
| 375 // A/B1/ * | |
| 376 // A/B1/B2/files | |
| 377 // A/C1/ * | |
| 378 // A/C1/C2/files | |
| 379 TEST_F(MediaScanManagerTest, MergeRedundant2) { | |
| 380 base::FilePath path; | |
| 381 MediaFolderFinder::MediaFolderFinderResults found_folders; | |
| 382 std::vector<base::FilePath> sensitive_locations; | |
| 383 std::vector<base::FilePath> expected_folders; | |
| 384 MediaGalleryScanResult file_counts; | |
| 385 file_counts.audio_count = 1; | |
| 386 file_counts.image_count = 2; | |
| 387 file_counts.video_count = 3; | |
| 388 MakeTestFolder("A", &path); | |
| 389 expected_folders.push_back(path); | |
| 390 MakeTestFolder("A/B1", &path); | |
| 391 expected_folders.push_back(path); | |
| 392 MakeTestFolder("A/B1/B2", &path); | |
| 393 found_folders[path] = file_counts; | |
| 394 MakeTestFolder("A/C1", &path); | |
| 395 expected_folders.push_back(path); | |
| 396 MakeTestFolder("A/C1/C2", &path); | |
| 397 found_folders[path] = file_counts; | |
| 398 // Make "home dir" not dense enough. | |
| 399 MakeTestFolder("D", &path); | |
| 400 MediaFolderFinder::MediaFolderFinderResults results = | |
| 401 FindContainerScanResults(found_folders, sensitive_locations); | |
| 402 EXPECT_EQ(expected_folders.size(), results.size()); | |
| 403 for (std::vector<base::FilePath>::const_iterator it = | |
| 404 expected_folders.begin(); | |
| 405 it != expected_folders.end(); ++it) { | |
| 406 EXPECT_TRUE(results.find(*it) != results.end()); | |
| 407 } | |
| 408 } | |
| 409 | |
| 410 // Make sure that sensistive directories are pruned. | |
| 411 // | |
| 412 // A/ - NOT included | |
| 413 // A/B/ - sensitive | |
| 414 // A/C/ * | |
| 415 // A/C/G/files | |
| 416 // A/C/H/files | |
| 417 // A/D/ * | |
| 418 // A/D/I/files | |
| 419 // A/D/J/files | |
| 420 // A/E/ * | |
| 421 // A/E/K/files | |
| 422 // A/E/L/files | |
| 423 // A/F/ * | |
| 424 // A/F/M/files | |
| 425 // A/F/N/files | |
| 426 TEST_F(MediaScanManagerTest, MergeRedundantWithSensitive) { | |
| 427 base::FilePath path; | |
| 428 MediaFolderFinder::MediaFolderFinderResults found_folders; | |
| 429 std::vector<base::FilePath> sensitive_locations; | |
| 430 std::vector<base::FilePath> expected_folders; | |
| 431 MediaGalleryScanResult file_counts; | |
| 432 file_counts.audio_count = 1; | |
| 433 file_counts.image_count = 2; | |
| 434 file_counts.video_count = 3; | |
| 435 MakeTestFolder("A", &path); | |
| 436 MakeTestFolder("A/B", &path); | |
| 437 sensitive_locations.push_back(path); | |
| 438 MakeTestFolder("A/C", &path); | |
| 439 expected_folders.push_back(path); | |
| 440 MakeTestFolder("A/C/G", &path); | |
| 441 found_folders[path] = file_counts; | |
| 442 MakeTestFolder("A/C/H", &path); | |
| 443 found_folders[path] = file_counts; | |
| 444 MakeTestFolder("A/D", &path); | |
| 445 expected_folders.push_back(path); | |
| 446 MakeTestFolder("A/D/I", &path); | |
| 447 found_folders[path] = file_counts; | |
| 448 MakeTestFolder("A/D/J", &path); | |
| 449 found_folders[path] = file_counts; | |
| 450 MakeTestFolder("A/E", &path); | |
| 451 expected_folders.push_back(path); | |
| 452 MakeTestFolder("A/E/K", &path); | |
| 453 found_folders[path] = file_counts; | |
| 454 MakeTestFolder("A/E/L", &path); | |
| 455 found_folders[path] = file_counts; | |
| 456 MakeTestFolder("A/F", &path); | |
| 457 expected_folders.push_back(path); | |
| 458 MakeTestFolder("A/F/M", &path); | |
| 459 found_folders[path] = file_counts; | |
| 460 MakeTestFolder("A/F/N", &path); | |
| 461 found_folders[path] = file_counts; | |
| 462 MediaFolderFinder::MediaFolderFinderResults results = | |
| 463 FindContainerScanResults(found_folders, sensitive_locations); | |
| 464 EXPECT_EQ(expected_folders.size(), results.size()); | |
| 465 for (std::vector<base::FilePath>::const_iterator it = | |
| 466 expected_folders.begin(); | |
| 467 it != expected_folders.end(); ++it) { | |
| 468 EXPECT_TRUE(results.find(*it) != results.end()); | |
| 469 } | |
| 470 } | |
| 471 | |
| 309 TEST_F(MediaScanManagerTest, Containers) { | 472 TEST_F(MediaScanManagerTest, Containers) { |
| 310 MediaGalleryScanResult file_counts; | 473 MediaGalleryScanResult file_counts; |
| 311 file_counts.audio_count = 1; | 474 file_counts.audio_count = 1; |
| 312 base::FilePath path; | 475 base::FilePath path; |
| 313 std::set<base::FilePath> expected_galleries; | 476 std::set<base::FilePath> expected_galleries; |
| 314 std::set<base::FilePath> bad_galleries; | 477 std::set<base::FilePath> bad_galleries; |
| 315 MediaFolderFinder::MediaFolderFinderResults found_folders; | 478 MediaFolderFinder::MediaFolderFinderResults found_folders; |
| 316 size_t galleries_before = gallery_count(); | 479 size_t galleries_before = gallery_count(); |
| 317 | 480 |
| 318 // Should manifest as a gallery in result1. | 481 // Should manifest as a gallery in result1. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 file_counts.audio_count *= kGalleriesAdded; | 678 file_counts.audio_count *= kGalleriesAdded; |
| 516 file_counts.image_count *= kGalleriesAdded; | 679 file_counts.image_count *= kGalleriesAdded; |
| 517 file_counts.video_count *= kGalleriesAdded; | 680 file_counts.video_count *= kGalleriesAdded; |
| 518 SetExpectedScanResults(kGalleriesAdded, file_counts); | 681 SetExpectedScanResults(kGalleriesAdded, file_counts); |
| 519 StartScan(); | 682 StartScan(); |
| 520 | 683 |
| 521 base::RunLoop().RunUntilIdle(); | 684 base::RunLoop().RunUntilIdle(); |
| 522 EXPECT_EQ(1, FindFolderDestroyCount()); | 685 EXPECT_EQ(1, FindFolderDestroyCount()); |
| 523 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); | 686 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); |
| 524 } | 687 } |
| OLD | NEW |