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

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

Issue 120303003: [StorageMonitor] Move gallery name generation to StorageInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 6 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // MediaGalleriesPreferences unit tests. 5 // MediaGalleriesPreferences unit tests.
6 6
7 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 7 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 false, 0, 0, 0, 2); 287 false, 0, 0, 0, 2);
288 } 288 }
289 289
290 MediaGalleryPrefId AddFixedGalleryWithExepectation( 290 MediaGalleryPrefId AddFixedGalleryWithExepectation(
291 const std::string& path_name, const std::string& name, 291 const std::string& path_name, const std::string& name,
292 MediaGalleryPrefInfo::Type type) { 292 MediaGalleryPrefInfo::Type type) {
293 base::FilePath path = MakeMediaGalleriesTestingPath(path_name); 293 base::FilePath path = MakeMediaGalleriesTestingPath(path_name);
294 StorageInfo info; 294 StorageInfo info;
295 base::FilePath relative_path; 295 base::FilePath relative_path;
296 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 296 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
297 info.set_name(ASCIIToUTF16(name)); 297 base::string16 gallery_name = base::ASCIIToUTF16(name);
298 MediaGalleryPrefId id = AddGalleryWithNameV2(info.device_id(), info.name(), 298 MediaGalleryPrefId id = AddGalleryWithNameV2(info.device_id(), gallery_name,
299 relative_path, type); 299 relative_path, type);
300 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 300 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
301 type); 301 type);
302 Verify(); 302 Verify();
303 return id; 303 return id;
304 } 304 }
305 305
306 bool UpdateDeviceIDForSingletonType(const std::string& device_id) { 306 bool UpdateDeviceIDForSingletonType(const std::string& device_id) {
307 return gallery_prefs()->UpdateDeviceIDForSingletonType(device_id); 307 return gallery_prefs()->UpdateDeviceIDForSingletonType(device_id);
308 } 308 }
309 309
310 scoped_refptr<extensions::Extension> all_permission_extension; 310 scoped_refptr<extensions::Extension> all_permission_extension;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 TEST_F(MediaGalleriesPreferencesTest, GalleryManagement) { 342 TEST_F(MediaGalleriesPreferencesTest, GalleryManagement) {
343 MediaGalleryPrefId auto_id, user_added_id, scan_id, id; 343 MediaGalleryPrefId auto_id, user_added_id, scan_id, id;
344 base::FilePath path; 344 base::FilePath path;
345 base::FilePath relative_path; 345 base::FilePath relative_path;
346 Verify(); 346 Verify();
347 347
348 // Add a new auto detected gallery. 348 // Add a new auto detected gallery.
349 path = MakeMediaGalleriesTestingPath("new_auto"); 349 path = MakeMediaGalleriesTestingPath("new_auto");
350 StorageInfo info; 350 StorageInfo info;
351 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 351 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
352 info.set_name(ASCIIToUTF16("NewAutoGallery")); 352 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
353 id = AddGalleryWithNameV2(info.device_id(), info.name(), 353 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
354 relative_path, MediaGalleryPrefInfo::kAutoDetected); 354 MediaGalleryPrefInfo::kAutoDetected);
355 EXPECT_EQ(default_galleries_count() + 1UL, id); 355 EXPECT_EQ(default_galleries_count() + 1UL, id);
356 auto_id = id; 356 auto_id = id;
357 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 357 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
358 MediaGalleryPrefInfo::kAutoDetected); 358 MediaGalleryPrefInfo::kAutoDetected);
359 Verify(); 359 Verify();
360 360
361 // Add it as other types, nothing should happen. 361 // Add it as other types, nothing should happen.
362 id = AddGalleryWithNameV2(info.device_id(), info.name(), 362 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
363 relative_path, MediaGalleryPrefInfo::kUserAdded); 363 MediaGalleryPrefInfo::kUserAdded);
364 EXPECT_EQ(auto_id, id); 364 EXPECT_EQ(auto_id, id);
365 Verify(); 365 Verify();
366 id = AddGalleryWithNameV2(info.device_id(), info.name(), 366 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
367 relative_path, MediaGalleryPrefInfo::kAutoDetected); 367 MediaGalleryPrefInfo::kAutoDetected);
368 EXPECT_EQ(auto_id, id); 368 EXPECT_EQ(auto_id, id);
369 Verify(); 369 Verify();
370 id = AddGalleryWithNameV2(info.device_id(), info.name(), 370 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
371 relative_path, MediaGalleryPrefInfo::kScanResult); 371 MediaGalleryPrefInfo::kScanResult);
372 EXPECT_EQ(auto_id, id); 372 EXPECT_EQ(auto_id, id);
373 373
374 // Add a new user added gallery. 374 // Add a new user added gallery.
375 path = MakeMediaGalleriesTestingPath("new_user"); 375 path = MakeMediaGalleriesTestingPath("new_user");
376 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 376 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
377 info.set_name(ASCIIToUTF16("NewUserGallery")); 377 gallery_name = base::ASCIIToUTF16("NewUserGallery");
378 id = AddGalleryWithNameV2(info.device_id(), info.name(), 378 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
379 relative_path, MediaGalleryPrefInfo::kUserAdded); 379 MediaGalleryPrefInfo::kUserAdded);
380 EXPECT_EQ(default_galleries_count() + 2UL, id); 380 EXPECT_EQ(default_galleries_count() + 2UL, id);
381 user_added_id = id; 381 user_added_id = id;
382 const std::string user_added_device_id = info.device_id(); 382 const std::string user_added_device_id = info.device_id();
383 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 383 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
384 MediaGalleryPrefInfo::kUserAdded); 384 MediaGalleryPrefInfo::kUserAdded);
385 Verify(); 385 Verify();
386 386
387 // Add it as other types, nothing should happen. 387 // Add it as other types, nothing should happen.
388 id = AddGalleryWithNameV2(info.device_id(), info.name(), 388 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
389 relative_path, MediaGalleryPrefInfo::kUserAdded); 389 MediaGalleryPrefInfo::kUserAdded);
390 EXPECT_EQ(user_added_id, id); 390 EXPECT_EQ(user_added_id, id);
391 Verify(); 391 Verify();
392 id = AddGalleryWithNameV2(info.device_id(), info.name(), 392 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
393 relative_path, MediaGalleryPrefInfo::kAutoDetected); 393 MediaGalleryPrefInfo::kAutoDetected);
394 EXPECT_EQ(user_added_id, id); 394 EXPECT_EQ(user_added_id, id);
395 Verify(); 395 Verify();
396 id = AddGalleryWithNameV2(info.device_id(), info.name(), 396 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
397 relative_path, MediaGalleryPrefInfo::kScanResult); 397 MediaGalleryPrefInfo::kScanResult);
398 EXPECT_EQ(user_added_id, id); 398 EXPECT_EQ(user_added_id, id);
399 Verify(); 399 Verify();
400 400
401 // Add a new scan result gallery. 401 // Add a new scan result gallery.
402 path = MakeMediaGalleriesTestingPath("new_scan"); 402 path = MakeMediaGalleriesTestingPath("new_scan");
403 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 403 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
404 info.set_name(ASCIIToUTF16("NewScanGallery")); 404 gallery_name = base::ASCIIToUTF16("NewScanGallery");
405 id = AddGalleryWithNameV2(info.device_id(), info.name(), 405 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
406 relative_path, MediaGalleryPrefInfo::kScanResult); 406 MediaGalleryPrefInfo::kScanResult);
407 EXPECT_EQ(default_galleries_count() + 3UL, id); 407 EXPECT_EQ(default_galleries_count() + 3UL, id);
408 scan_id = id; 408 scan_id = id;
409 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 409 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
410 MediaGalleryPrefInfo::kScanResult); 410 MediaGalleryPrefInfo::kScanResult);
411 Verify(); 411 Verify();
412 412
413 // Add it as other types, nothing should happen. 413 // Add it as other types, nothing should happen.
414 id = AddGalleryWithNameV2(info.device_id(), info.name(), 414 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
415 relative_path, MediaGalleryPrefInfo::kUserAdded); 415 MediaGalleryPrefInfo::kUserAdded);
416 EXPECT_EQ(scan_id, id); 416 EXPECT_EQ(scan_id, id);
417 Verify(); 417 Verify();
418 id = AddGalleryWithNameV2(info.device_id(), info.name(), 418 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
419 relative_path, MediaGalleryPrefInfo::kAutoDetected); 419 MediaGalleryPrefInfo::kAutoDetected);
420 EXPECT_EQ(scan_id, id); 420 EXPECT_EQ(scan_id, id);
421 Verify(); 421 Verify();
422 id = AddGalleryWithNameV2(info.device_id(), info.name(), 422 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
423 relative_path, MediaGalleryPrefInfo::kScanResult); 423 MediaGalleryPrefInfo::kScanResult);
424 EXPECT_EQ(scan_id, id); 424 EXPECT_EQ(scan_id, id);
425 Verify(); 425 Verify();
426 426
427 // Lookup some galleries. 427 // Lookup some galleries.
428 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 428 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(
429 MakeMediaGalleriesTestingPath("new_auto"), NULL)); 429 MakeMediaGalleriesTestingPath("new_auto"), NULL));
430 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 430 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(
431 MakeMediaGalleriesTestingPath("new_user"), NULL)); 431 MakeMediaGalleriesTestingPath("new_user"), NULL));
432 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 432 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(
433 MakeMediaGalleriesTestingPath("new_scan"), NULL)); 433 MakeMediaGalleriesTestingPath("new_scan"), NULL));
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 MediaGalleryPrefId id, metadata_id; 596 MediaGalleryPrefId id, metadata_id;
597 base::FilePath path; 597 base::FilePath path;
598 StorageInfo info; 598 StorageInfo info;
599 base::FilePath relative_path; 599 base::FilePath relative_path;
600 base::Time now = base::Time::Now(); 600 base::Time now = base::Time::Now();
601 Verify(); 601 Verify();
602 602
603 // Add an auto detected gallery in the prefs version 0 format. 603 // Add an auto detected gallery in the prefs version 0 format.
604 path = MakeMediaGalleriesTestingPath("new_auto"); 604 path = MakeMediaGalleriesTestingPath("new_auto");
605 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 605 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
606 info.set_name(ASCIIToUTF16("NewAutoGallery")); 606 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
607 id = AddGalleryWithNameV0(info.device_id(), info.name(), 607 id = AddGalleryWithNameV0(info.device_id(), gallery_name, relative_path,
608 relative_path, false /*auto*/); 608 false /*auto*/);
609 EXPECT_EQ(default_galleries_count() + 1UL, id); 609 EXPECT_EQ(default_galleries_count() + 1UL, id);
610 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 610 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
611 MediaGalleryPrefInfo::kAutoDetected); 611 MediaGalleryPrefInfo::kAutoDetected);
612 Verify(); 612 Verify();
613 613
614 metadata_id = gallery_prefs()->AddGallery(info.device_id(), 614 metadata_id = gallery_prefs()->AddGallery(info.device_id(),
615 relative_path, 615 relative_path,
616 MediaGalleryPrefInfo::kAutoDetected, 616 MediaGalleryPrefInfo::kAutoDetected,
617 ASCIIToUTF16("volume label"), 617 ASCIIToUTF16("volume label"),
618 ASCIIToUTF16("vendor name"), 618 ASCIIToUTF16("vendor name"),
619 ASCIIToUTF16("model name"), 619 ASCIIToUTF16("model name"),
620 1000000ULL, now, 0, 0, 0); 620 1000000ULL, now, 0, 0, 0);
(...skipping 12 matching lines...) Expand all
633 TEST_F(MediaGalleriesPreferencesTest, AutoAddedBlackListing) { 633 TEST_F(MediaGalleriesPreferencesTest, AutoAddedBlackListing) {
634 MediaGalleryPrefId auto_id, id; 634 MediaGalleryPrefId auto_id, id;
635 base::FilePath path; 635 base::FilePath path;
636 StorageInfo info; 636 StorageInfo info;
637 base::FilePath relative_path; 637 base::FilePath relative_path;
638 Verify(); 638 Verify();
639 639
640 // Add a new auto detect gallery to test with. 640 // Add a new auto detect gallery to test with.
641 path = MakeMediaGalleriesTestingPath("new_auto"); 641 path = MakeMediaGalleriesTestingPath("new_auto");
642 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 642 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
643 info.set_name(ASCIIToUTF16("NewAutoGallery")); 643 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
644 id = AddGalleryWithNameV1(info.device_id(), info.name(), 644 id = AddGalleryWithNameV1(info.device_id(), gallery_name,
645 relative_path, false /*auto*/); 645 relative_path, false /*auto*/);
646 EXPECT_EQ(default_galleries_count() + 1UL, id); 646 EXPECT_EQ(default_galleries_count() + 1UL, id);
647 auto_id = id; 647 auto_id = id;
648 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 648 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
649 MediaGalleryPrefInfo::kAutoDetected); 649 MediaGalleryPrefInfo::kAutoDetected);
650 Verify(); 650 Verify();
651 651
652 // Remove an auto added gallery (i.e. make it blacklisted). 652 // Remove an auto added gallery (i.e. make it blacklisted).
653 gallery_prefs()->ForgetGalleryById(auto_id); 653 gallery_prefs()->ForgetGalleryById(auto_id);
654 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 654 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed;
655 expected_galleries_for_all.erase(auto_id); 655 expected_galleries_for_all.erase(auto_id);
656 Verify(); 656 Verify();
657 657
658 // Try adding the gallery again automatically and it should be a no-op. 658 // Try adding the gallery again automatically and it should be a no-op.
659 id = AddGalleryWithNameV1(info.device_id(), info.name(), 659 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
660 relative_path, false /*auto*/); 660 false /*auto*/);
661 EXPECT_EQ(auto_id, id); 661 EXPECT_EQ(auto_id, id);
662 Verify(); 662 Verify();
663 663
664 // Add the gallery again as a user action. 664 // Add the gallery again as a user action.
665 id = gallery_prefs()->AddGalleryByPath(path, 665 id = gallery_prefs()->AddGalleryByPath(path,
666 MediaGalleryPrefInfo::kUserAdded); 666 MediaGalleryPrefInfo::kUserAdded);
667 EXPECT_EQ(auto_id, id); 667 EXPECT_EQ(auto_id, id);
668 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 668 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
669 MediaGalleryPrefInfo::kAutoDetected); 669 MediaGalleryPrefInfo::kAutoDetected);
670 Verify(); 670 Verify();
671 } 671 }
672 672
673 // Whenever a "ScanResult" gallery is removed, it is moved to a black listed 673 // Whenever a "ScanResult" gallery is removed, it is moved to a black listed
674 // state. When the gallery is added again, the black listed state is updated 674 // state. When the gallery is added again, the black listed state is updated
675 // back to the "ScanResult" type. 675 // back to the "ScanResult" type.
676 TEST_F(MediaGalleriesPreferencesTest, ScanResultBlackListing) { 676 TEST_F(MediaGalleriesPreferencesTest, ScanResultBlackListing) {
677 MediaGalleryPrefId scan_id, id; 677 MediaGalleryPrefId scan_id, id;
678 base::FilePath path; 678 base::FilePath path;
679 StorageInfo info; 679 StorageInfo info;
680 base::FilePath relative_path; 680 base::FilePath relative_path;
681 Verify(); 681 Verify();
682 682
683 // Add a new scan result gallery to test with. 683 // Add a new scan result gallery to test with.
684 path = MakeMediaGalleriesTestingPath("new_scan"); 684 path = MakeMediaGalleriesTestingPath("new_scan");
685 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 685 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
686 info.set_name(ASCIIToUTF16("NewScanGallery")); 686 base::string16 gallery_name = base::ASCIIToUTF16("NewScanGallery");
687 id = AddGalleryWithNameV2(info.device_id(), info.name(), 687 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
688 relative_path, MediaGalleryPrefInfo::kScanResult); 688 MediaGalleryPrefInfo::kScanResult);
689 EXPECT_EQ(default_galleries_count() + 1UL, id); 689 EXPECT_EQ(default_galleries_count() + 1UL, id);
690 scan_id = id; 690 scan_id = id;
691 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 691 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
692 MediaGalleryPrefInfo::kScanResult); 692 MediaGalleryPrefInfo::kScanResult);
693 Verify(); 693 Verify();
694 694
695 // Remove a scan result gallery (i.e. make it blacklisted). 695 // Remove a scan result gallery (i.e. make it blacklisted).
696 gallery_prefs()->ForgetGalleryById(scan_id); 696 gallery_prefs()->ForgetGalleryById(scan_id);
697 expected_galleries_[scan_id].type = MediaGalleryPrefInfo::kRemovedScan; 697 expected_galleries_[scan_id].type = MediaGalleryPrefInfo::kRemovedScan;
698 expected_galleries_for_all.erase(scan_id); 698 expected_galleries_for_all.erase(scan_id);
699 Verify(); 699 Verify();
700 700
701 // Try adding the gallery again as a scan result it should be a no-op. 701 // Try adding the gallery again as a scan result it should be a no-op.
702 id = AddGalleryWithNameV2(info.device_id(), info.name(), 702 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
703 relative_path, MediaGalleryPrefInfo::kScanResult); 703 MediaGalleryPrefInfo::kScanResult);
704 EXPECT_EQ(scan_id, id); 704 EXPECT_EQ(scan_id, id);
705 Verify(); 705 Verify();
706 706
707 // Add the gallery again as a user action. 707 // Add the gallery again as a user action.
708 id = gallery_prefs()->AddGalleryByPath(path, 708 id = gallery_prefs()->AddGalleryByPath(path,
709 MediaGalleryPrefInfo::kUserAdded); 709 MediaGalleryPrefInfo::kUserAdded);
710 EXPECT_EQ(scan_id, id); 710 EXPECT_EQ(scan_id, id);
711 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 711 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
712 MediaGalleryPrefInfo::kUserAdded); 712 MediaGalleryPrefInfo::kUserAdded);
713 Verify(); 713 Verify();
714 } 714 }
715 715
716 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryNameV2) { 716 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryNameV2) {
717 // Add a new auto detect gallery to test with. 717 // Add a new auto detect gallery to test with.
718 base::FilePath path = MakeMediaGalleriesTestingPath("new_auto"); 718 base::FilePath path = MakeMediaGalleriesTestingPath("new_auto");
719 StorageInfo info; 719 StorageInfo info;
720 base::FilePath relative_path; 720 base::FilePath relative_path;
721 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 721 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
722 info.set_name(ASCIIToUTF16("NewAutoGallery")); 722 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
723 MediaGalleryPrefId id = 723 MediaGalleryPrefId id =
724 AddGalleryWithNameV2(info.device_id(), info.name(), 724 AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
725 relative_path, MediaGalleryPrefInfo::kAutoDetected); 725 MediaGalleryPrefInfo::kAutoDetected);
726 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 726 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
727 MediaGalleryPrefInfo::kAutoDetected); 727 MediaGalleryPrefInfo::kAutoDetected);
728 Verify(); 728 Verify();
729 729
730 // Won't override the name -- don't change any expectation. 730 // Won't override the name -- don't change any expectation.
731 info.set_name(base::string16()); 731 gallery_name = base::string16();
732 AddGalleryWithNameV2(info.device_id(), info.name(), relative_path, 732 AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
733 MediaGalleryPrefInfo::kAutoDetected); 733 MediaGalleryPrefInfo::kAutoDetected);
734 Verify(); 734 Verify();
735 735
736 info.set_name(ASCIIToUTF16("NewName")); 736 gallery_name = base::ASCIIToUTF16("NewName");
737 id = AddGalleryWithNameV2(info.device_id(), info.name(), 737 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
738 relative_path, MediaGalleryPrefInfo::kAutoDetected); 738 MediaGalleryPrefInfo::kAutoDetected);
739 // Note: will really just update the existing expectation. 739 // Note: will really just update the existing expectation.
740 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 740 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
741 MediaGalleryPrefInfo::kAutoDetected); 741 MediaGalleryPrefInfo::kAutoDetected);
742 Verify(); 742 Verify();
743 } 743 }
744 744
745 TEST_F(MediaGalleriesPreferencesTest, GalleryPermissions) { 745 TEST_F(MediaGalleriesPreferencesTest, GalleryPermissions) {
746 MediaGalleryPrefId auto_id, user_added_id, to_blacklist_id, scan_id, 746 MediaGalleryPrefId auto_id, user_added_id, to_blacklist_id, scan_id,
747 to_scan_remove_id, id; 747 to_scan_remove_id, id;
748 base::FilePath path; 748 base::FilePath path;
749 StorageInfo info; 749 StorageInfo info;
750 base::FilePath relative_path; 750 base::FilePath relative_path;
751 Verify(); 751 Verify();
752 752
753 // Add some galleries to test with. 753 // Add some galleries to test with.
754 path = MakeMediaGalleriesTestingPath("new_user"); 754 path = MakeMediaGalleriesTestingPath("new_user");
755 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 755 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
756 info.set_name(ASCIIToUTF16("NewUserGallery")); 756 base::string16 gallery_name = base::ASCIIToUTF16("NewUserGallery");
757 id = AddGalleryWithNameV1(info.device_id(), info.name(), 757 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
758 relative_path, true /*user*/); 758 true /*user*/);
759 EXPECT_EQ(default_galleries_count() + 1UL, id); 759 EXPECT_EQ(default_galleries_count() + 1UL, id);
760 user_added_id = id; 760 user_added_id = id;
761 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 761 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
762 MediaGalleryPrefInfo::kUserAdded); 762 MediaGalleryPrefInfo::kUserAdded);
763 Verify(); 763 Verify();
764 764
765 path = MakeMediaGalleriesTestingPath("new_auto"); 765 path = MakeMediaGalleriesTestingPath("new_auto");
766 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 766 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
767 info.set_name(ASCIIToUTF16("NewAutoGallery")); 767 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
768 id = AddGalleryWithNameV1(info.device_id(), info.name(), 768 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
769 relative_path, false /*auto*/); 769 false /*auto*/);
770 EXPECT_EQ(default_galleries_count() + 2UL, id); 770 EXPECT_EQ(default_galleries_count() + 2UL, id);
771 auto_id = id; 771 auto_id = id;
772 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 772 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
773 MediaGalleryPrefInfo::kAutoDetected); 773 MediaGalleryPrefInfo::kAutoDetected);
774 Verify(); 774 Verify();
775 775
776 path = MakeMediaGalleriesTestingPath("to_blacklist"); 776 path = MakeMediaGalleriesTestingPath("to_blacklist");
777 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 777 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
778 info.set_name(ASCIIToUTF16("ToBlacklistGallery")); 778 gallery_name = base::ASCIIToUTF16("ToBlacklistGallery");
779 id = AddGalleryWithNameV1(info.device_id(), info.name(), 779 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
780 relative_path, false /*auto*/); 780 false /*auto*/);
781 EXPECT_EQ(default_galleries_count() + 3UL, id); 781 EXPECT_EQ(default_galleries_count() + 3UL, id);
782 to_blacklist_id = id; 782 to_blacklist_id = id;
783 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 783 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
784 MediaGalleryPrefInfo::kAutoDetected); 784 MediaGalleryPrefInfo::kAutoDetected);
785 Verify(); 785 Verify();
786 786
787 path = MakeMediaGalleriesTestingPath("new_scan"); 787 path = MakeMediaGalleriesTestingPath("new_scan");
788 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 788 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
789 info.set_name(ASCIIToUTF16("NewScanGallery")); 789 gallery_name = base::ASCIIToUTF16("NewScanGallery");
790 id = AddGalleryWithNameV2(info.device_id(), info.name(), 790 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
791 relative_path, MediaGalleryPrefInfo::kScanResult); 791 MediaGalleryPrefInfo::kScanResult);
792 EXPECT_EQ(default_galleries_count() + 4UL, id); 792 EXPECT_EQ(default_galleries_count() + 4UL, id);
793 scan_id = id; 793 scan_id = id;
794 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 794 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
795 MediaGalleryPrefInfo::kScanResult); 795 MediaGalleryPrefInfo::kScanResult);
796 Verify(); 796 Verify();
797 797
798 path = MakeMediaGalleriesTestingPath("to_scan_remove"); 798 path = MakeMediaGalleriesTestingPath("to_scan_remove");
799 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 799 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
800 info.set_name(ASCIIToUTF16("ToScanRemoveGallery")); 800 gallery_name = base::ASCIIToUTF16("ToScanRemoveGallery");
801 id = AddGalleryWithNameV2(info.device_id(), info.name(), 801 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
802 relative_path, MediaGalleryPrefInfo::kScanResult); 802 MediaGalleryPrefInfo::kScanResult);
803 EXPECT_EQ(default_galleries_count() + 5UL, id); 803 EXPECT_EQ(default_galleries_count() + 5UL, id);
804 to_scan_remove_id = id; 804 to_scan_remove_id = id;
805 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 805 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
806 MediaGalleryPrefInfo::kScanResult); 806 MediaGalleryPrefInfo::kScanResult);
807 Verify(); 807 Verify();
808 808
809 // Remove permission for all galleries from the all-permission extension. 809 // Remove permission for all galleries from the all-permission extension.
810 gallery_prefs()->SetGalleryPermissionForExtension( 810 gallery_prefs()->SetGalleryPermissionForExtension(
811 *all_permission_extension.get(), auto_id, false); 811 *all_permission_extension.get(), auto_id, false);
812 expected_galleries_for_all.erase(auto_id); 812 expected_galleries_for_all.erase(auto_id);
813 Verify(); 813 Verify();
814 814
815 gallery_prefs()->SetGalleryPermissionForExtension( 815 gallery_prefs()->SetGalleryPermissionForExtension(
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryDetails) { 926 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryDetails) {
927 MediaGalleryPrefId auto_id, id; 927 MediaGalleryPrefId auto_id, id;
928 base::FilePath path; 928 base::FilePath path;
929 StorageInfo info; 929 StorageInfo info;
930 base::FilePath relative_path; 930 base::FilePath relative_path;
931 Verify(); 931 Verify();
932 932
933 // Add a new auto detect gallery to test with. 933 // Add a new auto detect gallery to test with.
934 path = MakeMediaGalleriesTestingPath("new_auto"); 934 path = MakeMediaGalleriesTestingPath("new_auto");
935 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 935 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
936 info.set_name(ASCIIToUTF16("NewAutoGallery")); 936 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
937 id = AddGalleryWithNameV1(info.device_id(), info.name(), 937 id = AddGalleryWithNameV1(info.device_id(), gallery_name,
938 relative_path, false /*auto*/); 938 relative_path, false /*auto*/);
939 EXPECT_EQ(default_galleries_count() + 1UL, id); 939 EXPECT_EQ(default_galleries_count() + 1UL, id);
940 auto_id = id; 940 auto_id = id;
941 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 941 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
942 MediaGalleryPrefInfo::kAutoDetected); 942 MediaGalleryPrefInfo::kAutoDetected);
943 Verify(); 943 Verify();
944 944
945 // Update the device name and add the gallery again. 945 // Update the device name and add the gallery again.
946 info.set_name(ASCIIToUTF16("AutoGallery2")); 946 gallery_name = base::ASCIIToUTF16("AutoGallery2");
947 id = AddGalleryWithNameV1(info.device_id(), info.name(), 947 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
948 relative_path, false /*auto*/); 948 false /*auto*/);
949 EXPECT_EQ(auto_id, id); 949 EXPECT_EQ(auto_id, id);
950 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 950 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
951 MediaGalleryPrefInfo::kAutoDetected); 951 MediaGalleryPrefInfo::kAutoDetected);
952 Verify(); 952 Verify();
953 } 953 }
954 954
955 TEST_F(MediaGalleriesPreferencesTest, MultipleGalleriesPerDevices) { 955 TEST_F(MediaGalleriesPreferencesTest, MultipleGalleriesPerDevices) {
956 base::FilePath path; 956 base::FilePath path;
957 StorageInfo info; 957 StorageInfo info;
958 base::FilePath relative_path; 958 base::FilePath relative_path;
959 Verify(); 959 Verify();
960 960
961 // Add a regular gallery 961 // Add a regular gallery
962 path = MakeMediaGalleriesTestingPath("new_user"); 962 path = MakeMediaGalleriesTestingPath("new_user");
963 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 963 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
964 info.set_name(ASCIIToUTF16("NewUserGallery")); 964 base::string16 gallery_name = base::ASCIIToUTF16("NewUserGallery");
965 MediaGalleryPrefId user_added_id = 965 MediaGalleryPrefId user_added_id =
966 AddGalleryWithNameV1(info.device_id(), info.name(), 966 AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
967 relative_path, true /*user*/); 967 true /*user*/);
968 EXPECT_EQ(default_galleries_count() + 1UL, user_added_id); 968 EXPECT_EQ(default_galleries_count() + 1UL, user_added_id);
969 AddGalleryExpectation(user_added_id, info.name(), info.device_id(), 969 AddGalleryExpectation(user_added_id, gallery_name, info.device_id(),
970 relative_path, MediaGalleryPrefInfo::kUserAdded); 970 relative_path, MediaGalleryPrefInfo::kUserAdded);
971 Verify(); 971 Verify();
972 972
973 // Find it by device id and fail to find something related. 973 // Find it by device id and fail to find something related.
974 MediaGalleryPrefIdSet pref_id_set; 974 MediaGalleryPrefIdSet pref_id_set;
975 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id()); 975 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id());
976 EXPECT_EQ(1U, pref_id_set.size()); 976 EXPECT_EQ(1U, pref_id_set.size());
977 EXPECT_TRUE(pref_id_set.find(user_added_id) != pref_id_set.end()); 977 EXPECT_TRUE(pref_id_set.find(user_added_id) != pref_id_set.end());
978 978
979 MediaStorageUtil::GetDeviceInfoFromPath( 979 MediaStorageUtil::GetDeviceInfoFromPath(
980 MakeMediaGalleriesTestingPath("new_user/foo"), &info, &relative_path); 980 MakeMediaGalleriesTestingPath("new_user/foo"), &info, &relative_path);
981 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id()); 981 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id());
982 EXPECT_EQ(0U, pref_id_set.size()); 982 EXPECT_EQ(0U, pref_id_set.size());
983 983
984 // Add some galleries on the same device. 984 // Add some galleries on the same device.
985 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device1")); 985 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device1"));
986 info.set_name(ASCIIToUTF16("Device1Path1")); 986 gallery_name = base::ASCIIToUTF16("Device1Path1");
987 std::string device_id = "path:device1"; 987 std::string device_id = "path:device1";
988 MediaGalleryPrefId dev1_path1_id = AddGalleryWithNameV1( 988 MediaGalleryPrefId dev1_path1_id = AddGalleryWithNameV1(
989 device_id, info.name(), relative_path, true /*user*/); 989 device_id, gallery_name, relative_path, true /*user*/);
990 EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id); 990 EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id);
991 AddGalleryExpectation(dev1_path1_id, info.name(), device_id, relative_path, 991 AddGalleryExpectation(dev1_path1_id, gallery_name, device_id, relative_path,
992 MediaGalleryPrefInfo::kUserAdded); 992 MediaGalleryPrefInfo::kUserAdded);
993 Verify(); 993 Verify();
994 994
995 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device1")); 995 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device1"));
996 info.set_name(ASCIIToUTF16("Device1Path2")); 996 gallery_name = base::ASCIIToUTF16("Device1Path2");
997 MediaGalleryPrefId dev1_path2_id = AddGalleryWithNameV1( 997 MediaGalleryPrefId dev1_path2_id = AddGalleryWithNameV1(
998 device_id, info.name(), relative_path, true /*user*/); 998 device_id, gallery_name, relative_path, true /*user*/);
999 EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id); 999 EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id);
1000 AddGalleryExpectation(dev1_path2_id, info.name(), device_id, relative_path, 1000 AddGalleryExpectation(dev1_path2_id, gallery_name, device_id, relative_path,
1001 MediaGalleryPrefInfo::kUserAdded); 1001 MediaGalleryPrefInfo::kUserAdded);
1002 Verify(); 1002 Verify();
1003 1003
1004 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device2")); 1004 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device2"));
1005 info.set_name(ASCIIToUTF16("Device2Path1")); 1005 gallery_name = base::ASCIIToUTF16("Device2Path1");
1006 device_id = "path:device2"; 1006 device_id = "path:device2";
1007 MediaGalleryPrefId dev2_path1_id = AddGalleryWithNameV1( 1007 MediaGalleryPrefId dev2_path1_id = AddGalleryWithNameV1(
1008 device_id, info.name(), relative_path, true /*user*/); 1008 device_id, gallery_name, relative_path, true /*user*/);
1009 EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id); 1009 EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id);
1010 AddGalleryExpectation(dev2_path1_id, info.name(), device_id, relative_path, 1010 AddGalleryExpectation(dev2_path1_id, gallery_name, device_id, relative_path,
1011 MediaGalleryPrefInfo::kUserAdded); 1011 MediaGalleryPrefInfo::kUserAdded);
1012 Verify(); 1012 Verify();
1013 1013
1014 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device2")); 1014 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device2"));
1015 info.set_name(ASCIIToUTF16("Device2Path2")); 1015 gallery_name = base::ASCIIToUTF16("Device2Path2");
1016 MediaGalleryPrefId dev2_path2_id = AddGalleryWithNameV1( 1016 MediaGalleryPrefId dev2_path2_id = AddGalleryWithNameV1(
1017 device_id, info.name(), relative_path, true /*user*/); 1017 device_id, gallery_name, relative_path, true /*user*/);
1018 EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id); 1018 EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id);
1019 AddGalleryExpectation(dev2_path2_id, info.name(), device_id, relative_path, 1019 AddGalleryExpectation(dev2_path2_id, gallery_name, device_id, relative_path,
1020 MediaGalleryPrefInfo::kUserAdded); 1020 MediaGalleryPrefInfo::kUserAdded);
1021 Verify(); 1021 Verify();
1022 1022
1023 // Check that adding one of them again works as expected. 1023 // Check that adding one of them again works as expected.
1024 MediaGalleryPrefId id = AddGalleryWithNameV1( 1024 MediaGalleryPrefId id = AddGalleryWithNameV1(
1025 device_id, info.name(), relative_path, true /*user*/); 1025 device_id, gallery_name, relative_path, true /*user*/);
1026 EXPECT_EQ(dev2_path2_id, id); 1026 EXPECT_EQ(dev2_path2_id, id);
1027 Verify(); 1027 Verify();
1028 } 1028 }
1029 1029
1030 TEST_F(MediaGalleriesPreferencesTest, GalleryChangeObserver) { 1030 TEST_F(MediaGalleriesPreferencesTest, GalleryChangeObserver) {
1031 // Start with one observer. 1031 // Start with one observer.
1032 MockGalleryChangeObserver observer1(gallery_prefs()); 1032 MockGalleryChangeObserver observer1(gallery_prefs());
1033 gallery_prefs()->AddGalleryChangeObserver(&observer1); 1033 gallery_prefs()->AddGalleryChangeObserver(&observer1);
1034 1034
1035 // Add a new auto detected gallery. 1035 // Add a new auto detected gallery.
1036 base::FilePath path = MakeMediaGalleriesTestingPath("new_auto"); 1036 base::FilePath path = MakeMediaGalleriesTestingPath("new_auto");
1037 StorageInfo info; 1037 StorageInfo info;
1038 base::FilePath relative_path; 1038 base::FilePath relative_path;
1039 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 1039 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
1040 info.set_name(ASCIIToUTF16("NewAutoGallery")); 1040 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
1041 MediaGalleryPrefId auto_id = AddGalleryWithNameV1( 1041 MediaGalleryPrefId auto_id = AddGalleryWithNameV1(
1042 info.device_id(), info.name(), relative_path, false /*auto*/); 1042 info.device_id(), gallery_name, relative_path, false /*auto*/);
1043 EXPECT_EQ(default_galleries_count() + 1UL, auto_id); 1043 EXPECT_EQ(default_galleries_count() + 1UL, auto_id);
1044 AddGalleryExpectation(auto_id, info.name(), info.device_id(), 1044 AddGalleryExpectation(auto_id, gallery_name, info.device_id(),
1045 relative_path, MediaGalleryPrefInfo::kAutoDetected); 1045 relative_path, MediaGalleryPrefInfo::kAutoDetected);
1046 EXPECT_EQ(1, observer1.notifications()); 1046 EXPECT_EQ(1, observer1.notifications());
1047 1047
1048 // Add a second observer. 1048 // Add a second observer.
1049 MockGalleryChangeObserver observer2(gallery_prefs()); 1049 MockGalleryChangeObserver observer2(gallery_prefs());
1050 gallery_prefs()->AddGalleryChangeObserver(&observer2); 1050 gallery_prefs()->AddGalleryChangeObserver(&observer2);
1051 1051
1052 // Add a new user added gallery. 1052 // Add a new user added gallery.
1053 path = MakeMediaGalleriesTestingPath("new_user"); 1053 path = MakeMediaGalleriesTestingPath("new_user");
1054 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 1054 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
1055 info.set_name(ASCIIToUTF16("NewUserGallery")); 1055 gallery_name = base::ASCIIToUTF16("NewUserGallery");
1056 MediaGalleryPrefId user_added_id = 1056 MediaGalleryPrefId user_added_id =
1057 AddGalleryWithNameV1(info.device_id(), info.name(), 1057 AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
1058 relative_path, true /*user*/); 1058 true /*user*/);
1059 AddGalleryExpectation(user_added_id, info.name(), info.device_id(), 1059 AddGalleryExpectation(user_added_id, gallery_name, info.device_id(),
1060 relative_path, MediaGalleryPrefInfo::kUserAdded); 1060 relative_path, MediaGalleryPrefInfo::kUserAdded);
1061 EXPECT_EQ(default_galleries_count() + 2UL, user_added_id); 1061 EXPECT_EQ(default_galleries_count() + 2UL, user_added_id);
1062 EXPECT_EQ(2, observer1.notifications()); 1062 EXPECT_EQ(2, observer1.notifications());
1063 EXPECT_EQ(1, observer2.notifications()); 1063 EXPECT_EQ(1, observer2.notifications());
1064 1064
1065 // Remove the first observer. 1065 // Remove the first observer.
1066 gallery_prefs()->RemoveGalleryChangeObserver(&observer1); 1066 gallery_prefs()->RemoveGalleryChangeObserver(&observer1);
1067 1067
1068 // Remove an auto added gallery (i.e. make it blacklisted). 1068 // Remove an auto added gallery (i.e. make it blacklisted).
1069 gallery_prefs()->ForgetGalleryById(auto_id); 1069 gallery_prefs()->ForgetGalleryById(auto_id);
(...skipping 15 matching lines...) Expand all
1085 TEST_F(MediaGalleriesPreferencesTest, UpdateSingletonDeviceIdType) { 1085 TEST_F(MediaGalleriesPreferencesTest, UpdateSingletonDeviceIdType) {
1086 MediaGalleryPrefId id; 1086 MediaGalleryPrefId id;
1087 base::FilePath path; 1087 base::FilePath path;
1088 StorageInfo info; 1088 StorageInfo info;
1089 base::FilePath relative_path; 1089 base::FilePath relative_path;
1090 Verify(); 1090 Verify();
1091 1091
1092 // Add a new auto detect gallery to test with. 1092 // Add a new auto detect gallery to test with.
1093 path = MakeMediaGalleriesTestingPath("new_auto"); 1093 path = MakeMediaGalleriesTestingPath("new_auto");
1094 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 1094 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
1095 info.set_name(ASCIIToUTF16("NewAutoGallery")); 1095 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
1096 info.set_device_id(StorageInfo::MakeDeviceId(StorageInfo::ITUNES, 1096 info.set_device_id(StorageInfo::MakeDeviceId(StorageInfo::ITUNES,
1097 path.AsUTF8Unsafe())); 1097 path.AsUTF8Unsafe()));
1098 id = AddGalleryWithNameV2(info.device_id(), info.name(), relative_path, 1098 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
1099 MediaGalleryPrefInfo::kAutoDetected); 1099 MediaGalleryPrefInfo::kAutoDetected);
1100 EXPECT_EQ(default_galleries_count() + 1UL, id); 1100 EXPECT_EQ(default_galleries_count() + 1UL, id);
1101 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 1101 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
1102 MediaGalleryPrefInfo::kAutoDetected); 1102 MediaGalleryPrefInfo::kAutoDetected);
1103 Verify(); 1103 Verify();
1104 1104
1105 // Update the device id. 1105 // Update the device id.
1106 MockGalleryChangeObserver observer(gallery_prefs()); 1106 MockGalleryChangeObserver observer(gallery_prefs());
1107 gallery_prefs()->AddGalleryChangeObserver(&observer); 1107 gallery_prefs()->AddGalleryChangeObserver(&observer);
1108 1108
1109 path = MakeMediaGalleriesTestingPath("updated_path"); 1109 path = MakeMediaGalleriesTestingPath("updated_path");
1110 std::string updated_device_id = 1110 std::string updated_device_id =
1111 StorageInfo::MakeDeviceId(StorageInfo::ITUNES, path.AsUTF8Unsafe()); 1111 StorageInfo::MakeDeviceId(StorageInfo::ITUNES, path.AsUTF8Unsafe());
1112 EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id)); 1112 EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id));
1113 AddGalleryExpectation(id, info.name(), updated_device_id, relative_path, 1113 AddGalleryExpectation(id, gallery_name, updated_device_id, relative_path,
1114 MediaGalleryPrefInfo::kAutoDetected); 1114 MediaGalleryPrefInfo::kAutoDetected);
1115 expected_device_map[info.device_id()].erase(id); 1115 expected_device_map[info.device_id()].erase(id);
1116 expected_device_map[updated_device_id].insert(id); 1116 expected_device_map[updated_device_id].insert(id);
1117 Verify(); 1117 Verify();
1118 EXPECT_EQ(1, observer.notifications()); 1118 EXPECT_EQ(1, observer.notifications());
1119 1119
1120 // No gallery for type. 1120 // No gallery for type.
1121 std::string new_device_id = 1121 std::string new_device_id =
1122 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe()); 1122 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe());
1123 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id)); 1123 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 info.volume_label = base::string16(); 1220 info.volume_label = base::string16();
1221 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName()); 1221 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName());
1222 1222
1223 info.device_id = StorageInfo::MakeDeviceId( 1223 info.device_id = StorageInfo::MakeDeviceId(
1224 StorageInfo::FIXED_MASS_STORAGE, "unique"); 1224 StorageInfo::FIXED_MASS_STORAGE, "unique");
1225 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(), 1225 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(),
1226 base::UTF16ToUTF8(info.GetGalleryTooltip())); 1226 base::UTF16ToUTF8(info.GetGalleryTooltip()));
1227 1227
1228 TestStorageMonitor::Destroy(); 1228 TestStorageMonitor::Destroy();
1229 } 1229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698