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/ - NOT included |
| 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/ - included in results |
| 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 MakeTestFolder("A/B/C", &path); |
| 344 found_folders[path] = file_counts; |
| 345 // Not dense enough. |
| 346 MakeTestFolder("A/D", &path); |
| 347 MakeTestFolder("A/D/E", &path); |
| 348 found_folders[path] = file_counts; |
| 349 MakeTestFolder("A/D/F", &path); |
| 350 found_folders[path] = file_counts; |
| 351 MakeTestFolder("A/D/G", &path); |
| 352 found_folders[path] = file_counts; |
| 353 MakeTestFolder("A/D/H", &path); |
| 354 // Dense enough to be reported. |
| 355 MakeTestFolder("A/H", &path); |
| 356 expected_folders.push_back(path); |
| 357 MakeTestFolder("A/H/I", &path); |
| 358 found_folders[path] = file_counts; |
| 359 MakeTestFolder("A/H/J", &path); |
| 360 found_folders[path] = file_counts; |
| 361 MediaFolderFinder::MediaFolderFinderResults results = |
| 362 FindContainerScanResults(found_folders, sensitive_locations); |
| 363 EXPECT_EQ(expected_folders.size(), results.size()); |
| 364 for (std::vector<base::FilePath>::const_iterator it = |
| 365 expected_folders.begin(); |
| 366 it != expected_folders.end(); |
| 367 ++it) { |
| 368 EXPECT_TRUE(results.find(*it) != results.end()); |
| 369 } |
| 370 } |
| 371 |
| 372 // Make sure intermediates are not included. |
| 373 // |
| 374 // A/ - included in results |
| 375 // A/B1/ - NOT included |
| 376 // A/B1/B2/files |
| 377 // A/C1/ - NOT included |
| 378 // A/C1/C2/files |
| 379 TEST_F(MediaScanManagerTest, MergeRedundantNoIntermediates) { |
| 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 MakeTestFolder("A/B1/B2", &path); |
| 392 found_folders[path] = file_counts; |
| 393 MakeTestFolder("A/C1", &path); |
| 394 MakeTestFolder("A/C1/C2", &path); |
| 395 found_folders[path] = file_counts; |
| 396 // Make "home dir" not dense enough. |
| 397 MakeTestFolder("D", &path); |
| 398 MediaFolderFinder::MediaFolderFinderResults results = |
| 399 FindContainerScanResults(found_folders, sensitive_locations); |
| 400 EXPECT_EQ(expected_folders.size(), results.size()); |
| 401 for (std::vector<base::FilePath>::const_iterator it = |
| 402 expected_folders.begin(); |
| 403 it != expected_folders.end(); |
| 404 ++it) { |
| 405 EXPECT_TRUE(results.find(*it) != results.end()); |
| 406 } |
| 407 } |
| 408 |
| 409 // Make sure "A/" only gets a count of 1, from "A/D/", |
| 410 // not 2 from "A/D/H/" and "A/D/I/". |
| 411 // |
| 412 // A/ - NOT included |
| 413 // A/D/ - included in results |
| 414 // A/D/E/files |
| 415 // A/D/F/files |
| 416 // A/D/G/files |
| 417 // A/D/H/files |
| 418 // A/D/I/ - NOT included |
| 419 // A/D/I/J/files |
| 420 TEST_F(MediaScanManagerTest, MergeRedundantVerifyNoOvercount) { |
| 421 base::FilePath path; |
| 422 MediaFolderFinder::MediaFolderFinderResults found_folders; |
| 423 std::vector<base::FilePath> sensitive_locations; |
| 424 std::vector<base::FilePath> expected_folders; |
| 425 MediaGalleryScanResult file_counts; |
| 426 file_counts.audio_count = 1; |
| 427 file_counts.image_count = 2; |
| 428 file_counts.video_count = 3; |
| 429 MakeTestFolder("A", &path); |
| 430 MakeTestFolder("A/D", &path); |
| 431 expected_folders.push_back(path); |
| 432 MakeTestFolder("A/D/E", &path); |
| 433 found_folders[path] = file_counts; |
| 434 MakeTestFolder("A/D/F", &path); |
| 435 found_folders[path] = file_counts; |
| 436 MakeTestFolder("A/D/G", &path); |
| 437 found_folders[path] = file_counts; |
| 438 MakeTestFolder("A/D/H", &path); |
| 439 found_folders[path] = file_counts; |
| 440 MakeTestFolder("A/D/I", &path); |
| 441 MakeTestFolder("A/D/I/J", &path); |
| 442 found_folders[path] = file_counts; |
| 443 MediaFolderFinder::MediaFolderFinderResults results = |
| 444 FindContainerScanResults(found_folders, sensitive_locations); |
| 445 EXPECT_EQ(expected_folders.size(), results.size()); |
| 446 for (std::vector<base::FilePath>::const_iterator it = |
| 447 expected_folders.begin(); |
| 448 it != expected_folders.end(); |
| 449 ++it) { |
| 450 EXPECT_TRUE(results.find(*it) != results.end()); |
| 451 } |
| 452 } |
| 453 |
| 454 // Make sure that sensistive directories are pruned. |
| 455 // |
| 456 // A/ - NOT included |
| 457 // A/B/ - sensitive |
| 458 // A/C/ - included in results |
| 459 // A/C/G/files |
| 460 // A/C/H/files |
| 461 // A/D/ - included in results |
| 462 // A/D/I/files |
| 463 // A/D/J/files |
| 464 // A/E/ - included in results |
| 465 // A/E/K/files |
| 466 // A/E/L/files |
| 467 // A/F/ - included in results |
| 468 // A/F/M/files |
| 469 // A/F/N/files |
| 470 TEST_F(MediaScanManagerTest, MergeRedundantWithSensitive) { |
| 471 base::FilePath path; |
| 472 MediaFolderFinder::MediaFolderFinderResults found_folders; |
| 473 std::vector<base::FilePath> sensitive_locations; |
| 474 std::vector<base::FilePath> expected_folders; |
| 475 MediaGalleryScanResult file_counts; |
| 476 file_counts.audio_count = 1; |
| 477 file_counts.image_count = 2; |
| 478 file_counts.video_count = 3; |
| 479 MakeTestFolder("A", &path); |
| 480 MakeTestFolder("A/B", &path); |
| 481 sensitive_locations.push_back(path); |
| 482 MakeTestFolder("A/C", &path); |
| 483 expected_folders.push_back(path); |
| 484 MakeTestFolder("A/C/G", &path); |
| 485 found_folders[path] = file_counts; |
| 486 MakeTestFolder("A/C/H", &path); |
| 487 found_folders[path] = file_counts; |
| 488 MakeTestFolder("A/D", &path); |
| 489 expected_folders.push_back(path); |
| 490 MakeTestFolder("A/D/I", &path); |
| 491 found_folders[path] = file_counts; |
| 492 MakeTestFolder("A/D/J", &path); |
| 493 found_folders[path] = file_counts; |
| 494 MakeTestFolder("A/E", &path); |
| 495 expected_folders.push_back(path); |
| 496 MakeTestFolder("A/E/K", &path); |
| 497 found_folders[path] = file_counts; |
| 498 MakeTestFolder("A/E/L", &path); |
| 499 found_folders[path] = file_counts; |
| 500 MakeTestFolder("A/F", &path); |
| 501 expected_folders.push_back(path); |
| 502 MakeTestFolder("A/F/M", &path); |
| 503 found_folders[path] = file_counts; |
| 504 MakeTestFolder("A/F/N", &path); |
| 505 found_folders[path] = file_counts; |
| 506 MediaFolderFinder::MediaFolderFinderResults results = |
| 507 FindContainerScanResults(found_folders, sensitive_locations); |
| 508 EXPECT_EQ(expected_folders.size(), results.size()); |
| 509 for (std::vector<base::FilePath>::const_iterator it = |
| 510 expected_folders.begin(); |
| 511 it != expected_folders.end(); |
| 512 ++it) { |
| 513 EXPECT_TRUE(results.find(*it) != results.end()); |
| 514 } |
| 515 } |
| 516 |
309 TEST_F(MediaScanManagerTest, Containers) { | 517 TEST_F(MediaScanManagerTest, Containers) { |
310 MediaGalleryScanResult file_counts; | 518 MediaGalleryScanResult file_counts; |
311 file_counts.audio_count = 1; | 519 file_counts.audio_count = 1; |
312 base::FilePath path; | 520 base::FilePath path; |
313 std::set<base::FilePath> expected_galleries; | 521 std::set<base::FilePath> expected_galleries; |
314 std::set<base::FilePath> bad_galleries; | 522 std::set<base::FilePath> bad_galleries; |
315 MediaFolderFinder::MediaFolderFinderResults found_folders; | 523 MediaFolderFinder::MediaFolderFinderResults found_folders; |
316 size_t galleries_before = gallery_count(); | 524 size_t galleries_before = gallery_count(); |
317 | 525 |
318 // Should manifest as a gallery in result1. | 526 // Should manifest as a gallery in result1. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 file_counts.image_count = 0; | 623 file_counts.image_count = 0; |
416 file_counts.video_count = 7; | 624 file_counts.video_count = 7; |
417 base::FilePath path; | 625 base::FilePath path; |
418 MakeTestFolder("uscan", &path); | 626 MakeTestFolder("uscan", &path); |
419 found_folders[path] = file_counts; | 627 found_folders[path] = file_counts; |
420 | 628 |
421 file_counts.video_count = 11; | 629 file_counts.video_count = 11; |
422 MakeTestFolder("gscan/dir1", &path); | 630 MakeTestFolder("gscan/dir1", &path); |
423 found_folders[path] = file_counts; | 631 found_folders[path] = file_counts; |
424 | 632 |
| 633 MakeTestFolder("junk", &path); |
| 634 |
425 SetFindFoldersResults(true, found_folders); | 635 SetFindFoldersResults(true, found_folders); |
426 file_counts.video_count = 7; | 636 file_counts.video_count = 7; |
427 SetExpectedScanResults(1 /*gallery_count*/, file_counts); | 637 SetExpectedScanResults(1 /*gallery_count*/, file_counts); |
428 StartScan(); | 638 StartScan(); |
429 | 639 |
430 base::RunLoop().RunUntilIdle(); | 640 base::RunLoop().RunUntilIdle(); |
431 EXPECT_EQ(2, FindFolderDestroyCount()); | 641 EXPECT_EQ(2, FindFolderDestroyCount()); |
432 EXPECT_EQ(galleries_before + 2, gallery_count()); | 642 EXPECT_EQ(galleries_before + 2, gallery_count()); |
433 CheckFileCounts(granted_scan, 0, 0, 11); | 643 CheckFileCounts(granted_scan, 0, 0, 11); |
434 // The new scan result should be one more than it's previous id. | 644 // The new scan result should be one more than it's previous id. |
(...skipping 20 matching lines...) Expand all Loading... |
455 MediaGalleryScanResult file_counts; | 665 MediaGalleryScanResult file_counts; |
456 file_counts.audio_count = 4; | 666 file_counts.audio_count = 4; |
457 base::FilePath path; | 667 base::FilePath path; |
458 MakeTestFolder("auto/dir1", &path); | 668 MakeTestFolder("auto/dir1", &path); |
459 found_folders[path] = file_counts; | 669 found_folders[path] = file_counts; |
460 | 670 |
461 file_counts.audio_count = 6; | 671 file_counts.audio_count = 6; |
462 MakeTestFolder("scan", &path); | 672 MakeTestFolder("scan", &path); |
463 found_folders[path] = file_counts; | 673 found_folders[path] = file_counts; |
464 | 674 |
| 675 MakeTestFolder("junk", &path); |
| 676 |
465 file_counts.audio_count = 5; | 677 file_counts.audio_count = 5; |
466 MakeTestFolder("user/dir2", &path); | 678 MakeTestFolder("user/dir2", &path); |
467 found_folders[path] = file_counts; | 679 found_folders[path] = file_counts; |
468 | 680 |
469 SetFindFoldersResults(true, found_folders); | 681 SetFindFoldersResults(true, found_folders); |
470 | 682 |
471 file_counts.audio_count = 0; | 683 file_counts.audio_count = 0; |
472 SetExpectedScanResults(0 /*gallery_count*/, file_counts); | 684 SetExpectedScanResults(0 /*gallery_count*/, file_counts); |
473 StartScan(); | 685 StartScan(); |
474 | 686 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 file_counts.audio_count *= kGalleriesAdded; | 727 file_counts.audio_count *= kGalleriesAdded; |
516 file_counts.image_count *= kGalleriesAdded; | 728 file_counts.image_count *= kGalleriesAdded; |
517 file_counts.video_count *= kGalleriesAdded; | 729 file_counts.video_count *= kGalleriesAdded; |
518 SetExpectedScanResults(kGalleriesAdded, file_counts); | 730 SetExpectedScanResults(kGalleriesAdded, file_counts); |
519 StartScan(); | 731 StartScan(); |
520 | 732 |
521 base::RunLoop().RunUntilIdle(); | 733 base::RunLoop().RunUntilIdle(); |
522 EXPECT_EQ(1, FindFolderDestroyCount()); | 734 EXPECT_EQ(1, FindFolderDestroyCount()); |
523 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); | 735 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); |
524 } | 736 } |
OLD | NEW |