Index: chrome/browser/media_galleries/media_scan_manager_unittest.cc |
diff --git a/chrome/browser/media_galleries/media_scan_manager_unittest.cc b/chrome/browser/media_galleries/media_scan_manager_unittest.cc |
index 5ab0c4ef241fc0186eedb29279d0bcbf7753b638..e0fc250f89f6d3d9dcf349d4475627364b868ddc 100644 |
--- a/chrome/browser/media_galleries/media_scan_manager_unittest.cc |
+++ b/chrome/browser/media_galleries/media_scan_manager_unittest.cc |
@@ -230,7 +230,7 @@ class MediaScanManagerTest : public MediaScanManagerObserver, |
EXPECT_EQ(video_count, pref_info->second.video_count); |
} |
- // MediaScanMangerObserver implementation. |
+ // MediaScanManagerObserver implementation. |
virtual void OnScanFinished( |
const std::string& extension_id, |
int gallery_count, |
@@ -242,6 +242,15 @@ class MediaScanManagerTest : public MediaScanManagerObserver, |
EXPECT_EQ(expected_file_counts_.video_count, file_counts.video_count); |
} |
+ protected: |
+ // So derived tests can access ...::FindContainerScanResults(). |
+ MediaFolderFinder::MediaFolderFinderResults FindContainerScanResults( |
+ const MediaFolderFinder::MediaFolderFinderResults& found_folders, |
+ const std::vector<base::FilePath>& sensitive_locations) { |
+ return MediaScanManager::FindContainerScanResults(found_folders, |
+ sensitive_locations); |
+ } |
+ |
private: |
void OnFindFoldersStarted( |
MediaFolderFinder::MediaFolderFinderResultsCallback callback) { |
@@ -306,6 +315,160 @@ TEST_F(MediaScanManagerTest, SingleResult) { |
EXPECT_EQ(galleries_before + 1, gallery_count()); |
} |
+// Generally test that it includes directories with sufficient density |
+// and excludes others. |
+// |
+// A/ - NOT included |
+// A/B/ * |
vandebo (ex-Chrome)
2014/05/30 20:30:24
* = container result? Please note.
Kevin Bailey
2014/06/01 21:12:40
Done.
|
+// A/B/C/files |
+// A/D/ - NOT included |
+// A/D/E/files |
+// A/D/F/files |
+// A/D/G/files |
+// A/D/H/ |
+// A/H/ * |
+// A/H/I/files |
+// A/H/J/files |
+TEST_F(MediaScanManagerTest, MergeRedundant) { |
+ base::FilePath path; |
+ MediaFolderFinder::MediaFolderFinderResults found_folders; |
+ std::vector<base::FilePath> sensitive_locations; |
+ std::vector<base::FilePath> expected_folders; |
+ MediaGalleryScanResult file_counts; |
+ file_counts.audio_count = 1; |
+ file_counts.image_count = 2; |
+ file_counts.video_count = 3; |
+ MakeTestFolder("A", &path); |
+ MakeTestFolder("A/B", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/B/C", &path); |
+ found_folders[path] = file_counts; |
+ // Not dense enough. |
+ MakeTestFolder("A/D", &path); |
+ MakeTestFolder("A/D/E", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/D/F", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/D/G", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/D/H", &path); |
+ // Dense enough to be reported. |
+ MakeTestFolder("A/H", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/H/I", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/H/J", &path); |
+ found_folders[path] = file_counts; |
+ MediaFolderFinder::MediaFolderFinderResults results = |
+ FindContainerScanResults(found_folders, sensitive_locations); |
+ EXPECT_EQ(expected_folders.size(), results.size()); |
+ for (std::vector<base::FilePath>::const_iterator it = |
+ expected_folders.begin(); |
+ it != expected_folders.end(); ++it) { |
+ EXPECT_TRUE(results.find(*it) != results.end()); |
+ } |
+} |
+ |
+// Make sure intermediates are included. |
+// |
+// A/ * |
+// A/B1/ * |
+// A/B1/B2/files |
+// A/C1/ * |
+// A/C1/C2/files |
+TEST_F(MediaScanManagerTest, MergeRedundant2) { |
+ base::FilePath path; |
+ MediaFolderFinder::MediaFolderFinderResults found_folders; |
+ std::vector<base::FilePath> sensitive_locations; |
+ std::vector<base::FilePath> expected_folders; |
+ MediaGalleryScanResult file_counts; |
+ file_counts.audio_count = 1; |
+ file_counts.image_count = 2; |
+ file_counts.video_count = 3; |
+ MakeTestFolder("A", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/B1", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/B1/B2", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/C1", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/C1/C2", &path); |
+ found_folders[path] = file_counts; |
+ // Make "home dir" not dense enough. |
+ MakeTestFolder("D", &path); |
+ MediaFolderFinder::MediaFolderFinderResults results = |
+ FindContainerScanResults(found_folders, sensitive_locations); |
+ EXPECT_EQ(expected_folders.size(), results.size()); |
+ for (std::vector<base::FilePath>::const_iterator it = |
+ expected_folders.begin(); |
+ it != expected_folders.end(); ++it) { |
+ EXPECT_TRUE(results.find(*it) != results.end()); |
+ } |
+} |
+ |
+// Make sure that sensistive directories are pruned. |
+// |
+// A/ - NOT included |
+// A/B/ - sensitive |
+// A/C/ * |
+// A/C/G/files |
+// A/C/H/files |
+// A/D/ * |
+// A/D/I/files |
+// A/D/J/files |
+// A/E/ * |
+// A/E/K/files |
+// A/E/L/files |
+// A/F/ * |
+// A/F/M/files |
+// A/F/N/files |
+TEST_F(MediaScanManagerTest, MergeRedundantWithSensitive) { |
+ base::FilePath path; |
+ MediaFolderFinder::MediaFolderFinderResults found_folders; |
+ std::vector<base::FilePath> sensitive_locations; |
+ std::vector<base::FilePath> expected_folders; |
+ MediaGalleryScanResult file_counts; |
+ file_counts.audio_count = 1; |
+ file_counts.image_count = 2; |
+ file_counts.video_count = 3; |
+ MakeTestFolder("A", &path); |
+ MakeTestFolder("A/B", &path); |
+ sensitive_locations.push_back(path); |
+ MakeTestFolder("A/C", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/C/G", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/C/H", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/D", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/D/I", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/D/J", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/E", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/E/K", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/E/L", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/F", &path); |
+ expected_folders.push_back(path); |
+ MakeTestFolder("A/F/M", &path); |
+ found_folders[path] = file_counts; |
+ MakeTestFolder("A/F/N", &path); |
+ found_folders[path] = file_counts; |
+ MediaFolderFinder::MediaFolderFinderResults results = |
+ FindContainerScanResults(found_folders, sensitive_locations); |
+ EXPECT_EQ(expected_folders.size(), results.size()); |
+ for (std::vector<base::FilePath>::const_iterator it = |
+ expected_folders.begin(); |
+ it != expected_folders.end(); ++it) { |
+ EXPECT_TRUE(results.find(*it) != results.end()); |
+ } |
+} |
+ |
TEST_F(MediaScanManagerTest, Containers) { |
MediaGalleryScanResult file_counts; |
file_counts.audio_count = 1; |