Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/browser/media_galleries/media_scan_manager_unittest.cc

Issue 285433004: Have FindContainerScanResults() find broader media container directories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit tests (and fixes they found) Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 TEST_F(MediaScanManagerTest, MergeRedundant) {
vandebo (ex-Chrome) 2014/05/27 19:07:16 This is a fine test, but doesn't test the new func
Kevin Bailey 2014/05/27 21:04:36 Added test that duplicates this. Passes. Did you
vandebo (ex-Chrome) 2014/05/28 00:36:59 Oops, yes, I meant what you typed. This is the mot
Kevin Bailey 2014/05/28 15:05:36 I lowered the requirement to a single reference bu
319 base::FilePath path;
320 MediaFolderFinder::MediaFolderFinderResults found_folders;
321 std::vector<base::FilePath> sensitive_locations;
322 std::vector<base::FilePath> expected_folders;
323 MediaGalleryScanResult file_counts;
324 file_counts.audio_count = 1;
325 file_counts.image_count = 2;
326 file_counts.video_count = 3;
327 MakeTestFolder("A", &path);
328 // Not enough to be considered.
329 MakeTestFolder("A/B", &path);
330 MakeTestFolder("A/B/C", &path);
331 found_folders[path] = file_counts;
332 // Enough but not dense enough.
333 MakeTestFolder("A/D", &path);
334 MakeTestFolder("A/D/E", &path);
335 found_folders[path] = file_counts;
336 MakeTestFolder("A/D/F", &path);
337 found_folders[path] = file_counts;
338 MakeTestFolder("A/D/G", &path);
339 found_folders[path] = file_counts;
340 MakeTestFolder("A/D/H", &path);
341 // Enough to be reported.
342 MakeTestFolder("A/H", &path);
343 expected_folders.push_back(path);
344 MakeTestFolder("A/H/I", &path);
345 found_folders[path] = file_counts;
346 MakeTestFolder("A/H/J", &path);
347 found_folders[path] = file_counts;
348 MediaFolderFinder::MediaFolderFinderResults results =
349 FindContainerScanResults(found_folders, sensitive_locations);
350 EXPECT_EQ((unsigned)1, results.size());
351 for (std::vector<base::FilePath>::const_iterator it =
352 expected_folders.begin();
353 it != expected_folders.end(); ++it) {
354 EXPECT_TRUE(results.find(*it) != results.end());
355 }
356 }
357
358 TEST_F(MediaScanManagerTest, MergeRedundantWithSensitive) {
359 base::FilePath path;
360 MediaFolderFinder::MediaFolderFinderResults found_folders;
361 std::vector<base::FilePath> sensitive_locations;
362 std::vector<base::FilePath> expected_folders;
363 MediaGalleryScanResult file_counts;
364 file_counts.audio_count = 1;
365 file_counts.image_count = 2;
366 file_counts.video_count = 3;
367 MakeTestFolder("A", &path);
368 MakeTestFolder("A/B", &path);
369 sensitive_locations.push_back(path);
370 MakeTestFolder("A/C", &path);
371 expected_folders.push_back(path);
372 MakeTestFolder("A/C/G", &path);
373 found_folders[path] = file_counts;
374 MakeTestFolder("A/C/H", &path);
375 found_folders[path] = file_counts;
376 MakeTestFolder("A/D", &path);
377 expected_folders.push_back(path);
378 MakeTestFolder("A/D/I", &path);
379 found_folders[path] = file_counts;
380 MakeTestFolder("A/D/J", &path);
381 found_folders[path] = file_counts;
382 MakeTestFolder("A/E", &path);
383 expected_folders.push_back(path);
384 MakeTestFolder("A/E/K", &path);
385 found_folders[path] = file_counts;
386 MakeTestFolder("A/E/L", &path);
387 found_folders[path] = file_counts;
388 MakeTestFolder("A/F", &path);
389 expected_folders.push_back(path);
390 MakeTestFolder("A/F/M", &path);
391 found_folders[path] = file_counts;
392 MakeTestFolder("A/F/N", &path);
393 found_folders[path] = file_counts;
394 MediaFolderFinder::MediaFolderFinderResults results =
395 FindContainerScanResults(found_folders, sensitive_locations);
396 EXPECT_EQ((unsigned)4, results.size());
397 for (std::vector<base::FilePath>::const_iterator it =
398 expected_folders.begin();
399 it != expected_folders.end(); ++it) {
400 EXPECT_TRUE(results.find(*it) != results.end());
401 }
402 }
403
309 TEST_F(MediaScanManagerTest, Containers) { 404 TEST_F(MediaScanManagerTest, Containers) {
310 MediaGalleryScanResult file_counts; 405 MediaGalleryScanResult file_counts;
311 file_counts.audio_count = 1; 406 file_counts.audio_count = 1;
312 base::FilePath path; 407 base::FilePath path;
313 std::set<base::FilePath> expected_galleries; 408 std::set<base::FilePath> expected_galleries;
314 std::set<base::FilePath> bad_galleries; 409 std::set<base::FilePath> bad_galleries;
315 MediaFolderFinder::MediaFolderFinderResults found_folders; 410 MediaFolderFinder::MediaFolderFinderResults found_folders;
316 size_t galleries_before = gallery_count(); 411 size_t galleries_before = gallery_count();
317 412
318 // Should manifest as a gallery in result1. 413 // Should manifest as a gallery in result1.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 file_counts.audio_count *= kGalleriesAdded; 610 file_counts.audio_count *= kGalleriesAdded;
516 file_counts.image_count *= kGalleriesAdded; 611 file_counts.image_count *= kGalleriesAdded;
517 file_counts.video_count *= kGalleriesAdded; 612 file_counts.video_count *= kGalleriesAdded;
518 SetExpectedScanResults(kGalleriesAdded, file_counts); 613 SetExpectedScanResults(kGalleriesAdded, file_counts);
519 StartScan(); 614 StartScan();
520 615
521 base::RunLoop().RunUntilIdle(); 616 base::RunLoop().RunUntilIdle();
522 EXPECT_EQ(1, FindFolderDestroyCount()); 617 EXPECT_EQ(1, FindFolderDestroyCount());
523 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); 618 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count());
524 } 619 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698