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 TEST_F(MediaScanManagerTest, MergeRedundant) { | |
|
vandebo (ex-Chrome)
2014/05/28 21:01:06
nit: for all of these tests, a comment laying out
Kevin Bailey
2014/05/29 00:36:41
Done. Should look better.
| |
| 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 MakeTestFolder("A/B", &path); | |
| 329 expected_folders.push_back(path); | |
| 330 MakeTestFolder("A/B/C", &path); | |
| 331 found_folders[path] = file_counts; | |
| 332 // 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 // Dense 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(expected_folders.size(), 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, MergeRedundant2) { | |
| 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 expected_folders.push_back(path); | |
| 369 MakeTestFolder("A/B1", &path); | |
| 370 expected_folders.push_back(path); | |
| 371 MakeTestFolder("A/B1/B2", &path); | |
| 372 found_folders[path] = file_counts; | |
| 373 MakeTestFolder("A/C1", &path); | |
| 374 expected_folders.push_back(path); | |
| 375 MakeTestFolder("A/C1/C2", &path); | |
| 376 found_folders[path] = file_counts; | |
| 377 // Make "home dir" not dense enough. | |
| 378 MakeTestFolder("D", &path); | |
|
vandebo (ex-Chrome)
2014/05/28 21:01:06
So I can see both sides of the story on this one,
Kevin Bailey
2014/05/29 00:36:41
I could change the behavior of the final loop - co
vandebo (ex-Chrome)
2014/05/30 20:30:24
In general, I think intermediates should be passed
Kevin Bailey
2014/06/01 21:12:40
I *could* add another loop to *include* parents wi
| |
| 379 MediaFolderFinder::MediaFolderFinderResults results = | |
| 380 FindContainerScanResults(found_folders, sensitive_locations); | |
| 381 EXPECT_EQ(expected_folders.size(), results.size()); | |
| 382 for (std::vector<base::FilePath>::const_iterator it = | |
| 383 expected_folders.begin(); | |
| 384 it != expected_folders.end(); ++it) { | |
| 385 EXPECT_TRUE(results.find(*it) != results.end()); | |
| 386 } | |
| 387 } | |
| 388 | |
| 389 TEST_F(MediaScanManagerTest, MergeRedundantWithSensitive) { | |
| 390 base::FilePath path; | |
| 391 MediaFolderFinder::MediaFolderFinderResults found_folders; | |
| 392 std::vector<base::FilePath> sensitive_locations; | |
| 393 std::vector<base::FilePath> expected_folders; | |
| 394 MediaGalleryScanResult file_counts; | |
| 395 file_counts.audio_count = 1; | |
| 396 file_counts.image_count = 2; | |
| 397 file_counts.video_count = 3; | |
| 398 MakeTestFolder("A", &path); | |
| 399 MakeTestFolder("A/B", &path); | |
| 400 sensitive_locations.push_back(path); | |
| 401 MakeTestFolder("A/C", &path); | |
| 402 expected_folders.push_back(path); | |
| 403 MakeTestFolder("A/C/G", &path); | |
| 404 found_folders[path] = file_counts; | |
| 405 MakeTestFolder("A/C/H", &path); | |
| 406 found_folders[path] = file_counts; | |
| 407 MakeTestFolder("A/D", &path); | |
| 408 expected_folders.push_back(path); | |
| 409 MakeTestFolder("A/D/I", &path); | |
| 410 found_folders[path] = file_counts; | |
| 411 MakeTestFolder("A/D/J", &path); | |
| 412 found_folders[path] = file_counts; | |
| 413 MakeTestFolder("A/E", &path); | |
| 414 expected_folders.push_back(path); | |
| 415 MakeTestFolder("A/E/K", &path); | |
| 416 found_folders[path] = file_counts; | |
| 417 MakeTestFolder("A/E/L", &path); | |
| 418 found_folders[path] = file_counts; | |
| 419 MakeTestFolder("A/F", &path); | |
| 420 expected_folders.push_back(path); | |
| 421 MakeTestFolder("A/F/M", &path); | |
| 422 found_folders[path] = file_counts; | |
| 423 MakeTestFolder("A/F/N", &path); | |
| 424 found_folders[path] = file_counts; | |
| 425 MediaFolderFinder::MediaFolderFinderResults results = | |
| 426 FindContainerScanResults(found_folders, sensitive_locations); | |
| 427 EXPECT_EQ(expected_folders.size(), results.size()); | |
| 428 for (std::vector<base::FilePath>::const_iterator it = | |
| 429 expected_folders.begin(); | |
| 430 it != expected_folders.end(); ++it) { | |
| 431 EXPECT_TRUE(results.find(*it) != results.end()); | |
| 432 } | |
| 433 } | |
| 434 | |
| 309 TEST_F(MediaScanManagerTest, Containers) { | 435 TEST_F(MediaScanManagerTest, Containers) { |
| 310 MediaGalleryScanResult file_counts; | 436 MediaGalleryScanResult file_counts; |
| 311 file_counts.audio_count = 1; | 437 file_counts.audio_count = 1; |
| 312 base::FilePath path; | 438 base::FilePath path; |
| 313 std::set<base::FilePath> expected_galleries; | 439 std::set<base::FilePath> expected_galleries; |
| 314 std::set<base::FilePath> bad_galleries; | 440 std::set<base::FilePath> bad_galleries; |
| 315 MediaFolderFinder::MediaFolderFinderResults found_folders; | 441 MediaFolderFinder::MediaFolderFinderResults found_folders; |
| 316 size_t galleries_before = gallery_count(); | 442 size_t galleries_before = gallery_count(); |
| 317 | 443 |
| 318 // Should manifest as a gallery in result1. | 444 // 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; | 641 file_counts.audio_count *= kGalleriesAdded; |
| 516 file_counts.image_count *= kGalleriesAdded; | 642 file_counts.image_count *= kGalleriesAdded; |
| 517 file_counts.video_count *= kGalleriesAdded; | 643 file_counts.video_count *= kGalleriesAdded; |
| 518 SetExpectedScanResults(kGalleriesAdded, file_counts); | 644 SetExpectedScanResults(kGalleriesAdded, file_counts); |
| 519 StartScan(); | 645 StartScan(); |
| 520 | 646 |
| 521 base::RunLoop().RunUntilIdle(); | 647 base::RunLoop().RunUntilIdle(); |
| 522 EXPECT_EQ(1, FindFolderDestroyCount()); | 648 EXPECT_EQ(1, FindFolderDestroyCount()); |
| 523 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); | 649 EXPECT_EQ(galleries_before + kGalleriesAdded, gallery_count()); |
| 524 } | 650 } |
| OLD | NEW |