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(); ++it) { |
| 367 EXPECT_TRUE(results.find(*it) != results.end()); |
| 368 } |
| 369 } |
| 370 |
| 371 // Make sure intermediates are included. |
| 372 // |
| 373 // A/ - included in results |
| 374 // A/B1/ - NOT included |
| 375 // A/B1/B2/files |
| 376 // A/C1/ - NOT included |
| 377 // A/C1/C2/files |
| 378 TEST_F(MediaScanManagerTest, MergeRedundant2) { |
| 379 base::FilePath path; |
| 380 MediaFolderFinder::MediaFolderFinderResults found_folders; |
| 381 std::vector<base::FilePath> sensitive_locations; |
| 382 std::vector<base::FilePath> expected_folders; |
| 383 MediaGalleryScanResult file_counts; |
| 384 file_counts.audio_count = 1; |
| 385 file_counts.image_count = 2; |
| 386 file_counts.video_count = 3; |
| 387 MakeTestFolder("A", &path); |
| 388 expected_folders.push_back(path); |
| 389 MakeTestFolder("A/B1", &path); |
| 390 MakeTestFolder("A/B1/B2", &path); |
| 391 found_folders[path] = file_counts; |
| 392 MakeTestFolder("A/C1", &path); |
| 393 MakeTestFolder("A/C1/C2", &path); |
| 394 found_folders[path] = file_counts; |
| 395 // Make "home dir" not dense enough. |
| 396 MakeTestFolder("D", &path); |
| 397 MediaFolderFinder::MediaFolderFinderResults results = |
| 398 FindContainerScanResults(found_folders, sensitive_locations); |
| 399 EXPECT_EQ(expected_folders.size(), results.size()); |
| 400 for (std::vector<base::FilePath>::const_iterator it = |
| 401 expected_folders.begin(); |
| 402 it != expected_folders.end(); ++it) { |
| 403 EXPECT_TRUE(results.find(*it) != results.end()); |
| 404 } |
| 405 } |
| 406 |
| 407 // Make sure "A/" only gets a count of 1, from "A/D/", |
| 408 // not 2 from "A/D/H/" and "A/D/I/". |
| 409 // |
| 410 // A/ - NOT included |
| 411 // A/D/ - included in results |
| 412 // A/D/E/files |
| 413 // A/D/F/files |
| 414 // A/D/G/files |
| 415 // A/D/H/files |
| 416 // A/D/I/ - NOT included |
| 417 // A/D/I/J/files |
| 418 TEST_F(MediaScanManagerTest, MergeRedundant3) { |
| 419 base::FilePath path; |
| 420 MediaFolderFinder::MediaFolderFinderResults found_folders; |
| 421 std::vector<base::FilePath> sensitive_locations; |
| 422 std::vector<base::FilePath> expected_folders; |
| 423 MediaGalleryScanResult file_counts; |
| 424 file_counts.audio_count = 1; |
| 425 file_counts.image_count = 2; |
| 426 file_counts.video_count = 3; |
| 427 MakeTestFolder("A", &path); |
| 428 MakeTestFolder("A/D", &path); |
| 429 expected_folders.push_back(path); |
| 430 MakeTestFolder("A/D/E", &path); |
| 431 found_folders[path] = file_counts; |
| 432 MakeTestFolder("A/D/F", &path); |
| 433 found_folders[path] = file_counts; |
| 434 MakeTestFolder("A/D/G", &path); |
| 435 found_folders[path] = file_counts; |
| 436 MakeTestFolder("A/D/H", &path); |
| 437 found_folders[path] = file_counts; |
| 438 MakeTestFolder("A/D/I", &path); |
| 439 MakeTestFolder("A/D/I/J", &path); |
| 440 found_folders[path] = file_counts; |
| 441 MediaFolderFinder::MediaFolderFinderResults results = |
| 442 FindContainerScanResults(found_folders, sensitive_locations); |
| 443 EXPECT_EQ(expected_folders.size(), results.size()); |
| 444 for (std::vector<base::FilePath>::const_iterator it = |
| 445 expected_folders.begin(); |
| 446 it != expected_folders.end(); ++it) { |
| 447 EXPECT_TRUE(results.find(*it) != results.end()); |
| 448 } |
| 449 } |
| 450 |
| 451 // Make sure that sensistive directories are pruned. |
| 452 // |
| 453 // A/ - NOT included |
| 454 // A/B/ - sensitive |
| 455 // A/C/ - included in results |
| 456 // A/C/G/files |
| 457 // A/C/H/files |
| 458 // A/D/ - included in results |
| 459 // A/D/I/files |
| 460 // A/D/J/files |
| 461 // A/E/ - included in results |
| 462 // A/E/K/files |
| 463 // A/E/L/files |
| 464 // A/F/ - included in results |
| 465 // A/F/M/files |
| 466 // A/F/N/files |
| 467 TEST_F(MediaScanManagerTest, MergeRedundantWithSensitive) { |
| 468 base::FilePath path; |
| 469 MediaFolderFinder::MediaFolderFinderResults found_folders; |
| 470 std::vector<base::FilePath> sensitive_locations; |
| 471 std::vector<base::FilePath> expected_folders; |
| 472 MediaGalleryScanResult file_counts; |
| 473 file_counts.audio_count = 1; |
| 474 file_counts.image_count = 2; |
| 475 file_counts.video_count = 3; |
| 476 MakeTestFolder("A", &path); |
| 477 MakeTestFolder("A/B", &path); |
| 478 sensitive_locations.push_back(path); |
| 479 MakeTestFolder("A/C", &path); |
| 480 expected_folders.push_back(path); |
| 481 MakeTestFolder("A/C/G", &path); |
| 482 found_folders[path] = file_counts; |
| 483 MakeTestFolder("A/C/H", &path); |
| 484 found_folders[path] = file_counts; |
| 485 MakeTestFolder("A/D", &path); |
| 486 expected_folders.push_back(path); |
| 487 MakeTestFolder("A/D/I", &path); |
| 488 found_folders[path] = file_counts; |
| 489 MakeTestFolder("A/D/J", &path); |
| 490 found_folders[path] = file_counts; |
| 491 MakeTestFolder("A/E", &path); |
| 492 expected_folders.push_back(path); |
| 493 MakeTestFolder("A/E/K", &path); |
| 494 found_folders[path] = file_counts; |
| 495 MakeTestFolder("A/E/L", &path); |
| 496 found_folders[path] = file_counts; |
| 497 MakeTestFolder("A/F", &path); |
| 498 expected_folders.push_back(path); |
| 499 MakeTestFolder("A/F/M", &path); |
| 500 found_folders[path] = file_counts; |
| 501 MakeTestFolder("A/F/N", &path); |
| 502 found_folders[path] = file_counts; |
| 503 MediaFolderFinder::MediaFolderFinderResults results = |
| 504 FindContainerScanResults(found_folders, sensitive_locations); |
| 505 EXPECT_EQ(expected_folders.size(), results.size()); |
| 506 for (std::vector<base::FilePath>::const_iterator it = |
| 507 expected_folders.begin(); |
| 508 it != expected_folders.end(); ++it) { |
| 509 EXPECT_TRUE(results.find(*it) != results.end()); |
| 510 } |
| 511 } |
| 512 |
309 TEST_F(MediaScanManagerTest, Containers) { | 513 TEST_F(MediaScanManagerTest, Containers) { |
310 MediaGalleryScanResult file_counts; | 514 MediaGalleryScanResult file_counts; |
311 file_counts.audio_count = 1; | 515 file_counts.audio_count = 1; |
312 base::FilePath path; | 516 base::FilePath path; |
313 std::set<base::FilePath> expected_galleries; | 517 std::set<base::FilePath> expected_galleries; |
314 std::set<base::FilePath> bad_galleries; | 518 std::set<base::FilePath> bad_galleries; |
315 MediaFolderFinder::MediaFolderFinderResults found_folders; | 519 MediaFolderFinder::MediaFolderFinderResults found_folders; |
316 size_t galleries_before = gallery_count(); | 520 size_t galleries_before = gallery_count(); |
317 | 521 |
318 // Should manifest as a gallery in result1. | 522 // 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; | 719 file_counts.audio_count *= kGalleriesAdded; |
516 file_counts.image_count *= kGalleriesAdded; | 720 file_counts.image_count *= kGalleriesAdded; |
517 file_counts.video_count *= kGalleriesAdded; | 721 file_counts.video_count *= kGalleriesAdded; |
518 SetExpectedScanResults(kGalleriesAdded, file_counts); | 722 SetExpectedScanResults(kGalleriesAdded, file_counts); |
519 StartScan(); | 723 StartScan(); |
520 | 724 |
521 base::RunLoop().RunUntilIdle(); | 725 base::RunLoop().RunUntilIdle(); |
522 EXPECT_EQ(1, FindFolderDestroyCount()); | 726 EXPECT_EQ(1, FindFolderDestroyCount()); |
523 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); | 727 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); |
524 } | 728 } |
OLD | NEW |