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

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

Issue 19489006: Media Galleries: Move gallery name generation back to StorageMonitor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 7 years, 4 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 | Annotate | Revision Log
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 167
168 MediaGalleriesPreferences* gallery_prefs() { 168 MediaGalleriesPreferences* gallery_prefs() {
169 return gallery_prefs_.get(); 169 return gallery_prefs_.get();
170 } 170 }
171 171
172 uint64 default_galleries_count() { 172 uint64 default_galleries_count() {
173 return default_galleries_count_; 173 return default_galleries_count_;
174 } 174 }
175 175
176 void AddGalleryExpectation(MediaGalleryPrefId id, string16 display_name, 176 void AddGalleryExpectation(MediaGalleryPrefId id,
177 const string16& display_name,
177 std::string device_id, 178 std::string device_id,
178 base::FilePath relative_path, 179 base::FilePath relative_path,
179 MediaGalleryPrefInfo::Type type) { 180 MediaGalleryPrefInfo::Type type) {
180 expected_galleries_[id].pref_id = id; 181 expected_galleries_[id].pref_id = id;
181 expected_galleries_[id].display_name = display_name; 182 expected_galleries_[id].display_name = display_name;
182 expected_galleries_[id].device_id = device_id; 183 expected_galleries_[id].device_id = device_id;
183 expected_galleries_[id].path = relative_path.NormalizePathSeparators(); 184 expected_galleries_[id].path = relative_path.NormalizePathSeparators();
184 expected_galleries_[id].type = type; 185 expected_galleries_[id].type = type;
185 186
186 if (type == MediaGalleryPrefInfo::kAutoDetected) 187 if (type == MediaGalleryPrefInfo::kAutoDetected)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 TEST_F(MediaGalleriesPreferencesTest, GalleryManagement) { 264 TEST_F(MediaGalleriesPreferencesTest, GalleryManagement) {
264 MediaGalleryPrefId auto_id, user_added_id, id; 265 MediaGalleryPrefId auto_id, user_added_id, id;
265 base::FilePath path; 266 base::FilePath path;
266 base::FilePath relative_path; 267 base::FilePath relative_path;
267 Verify(); 268 Verify();
268 269
269 // Add a new auto detected gallery. 270 // Add a new auto detected gallery.
270 path = MakePath("new_auto"); 271 path = MakePath("new_auto");
271 StorageInfo info; 272 StorageInfo info;
272 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 273 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
273 info.set_name(ASCIIToUTF16("NewAutoGallery")); 274 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
274 id = AddGalleryWithNameV1(info.device_id(), info.name(), 275 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
275 relative_path, false /*auto*/); 276 false /*auto*/);
276 EXPECT_EQ(default_galleries_count() + 1UL, id); 277 EXPECT_EQ(default_galleries_count() + 1UL, id);
277 auto_id = id; 278 auto_id = id;
278 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 279 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
279 MediaGalleryPrefInfo::kAutoDetected); 280 MediaGalleryPrefInfo::kAutoDetected);
280 Verify(); 281 Verify();
281 282
282 // Add it again (as user), nothing should happen. 283 // Add it again (as user), nothing should happen.
283 id = AddGalleryWithNameV1(info.device_id(), info.name(), 284 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
284 relative_path, true /*auto*/); 285 true /*auto*/);
285 EXPECT_EQ(auto_id, id); 286 EXPECT_EQ(auto_id, id);
286 Verify(); 287 Verify();
287 288
288 // Add a new user added gallery. 289 // Add a new user added gallery.
289 path = MakePath("new_user"); 290 path = MakePath("new_user");
290 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 291 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
291 info.set_name(ASCIIToUTF16("NewUserGallery")); 292 gallery_name = base::ASCIIToUTF16("NewUserGallery");
292 id = AddGalleryWithNameV1(info.device_id(), info.name(), 293 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
293 relative_path, true /*user*/); 294 true /*user*/);
294 EXPECT_EQ(default_galleries_count() + 2UL, id); 295 EXPECT_EQ(default_galleries_count() + 2UL, id);
295 user_added_id = id; 296 user_added_id = id;
296 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 297 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
297 MediaGalleryPrefInfo::kUserAdded); 298 MediaGalleryPrefInfo::kUserAdded);
298 Verify(); 299 Verify();
299 300
300 // Lookup some galleries. 301 // Lookup some galleries.
301 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"), NULL)); 302 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"), NULL));
302 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_user"), NULL)); 303 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_user"), NULL));
303 EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(MakePath("other"), NULL)); 304 EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(MakePath("other"), NULL));
304 305
305 // Check that we always get the gallery info. 306 // Check that we always get the gallery info.
306 MediaGalleryPrefInfo gallery_info; 307 MediaGalleryPrefInfo gallery_info;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 MediaGalleryPrefId id, metadata_id; 377 MediaGalleryPrefId id, metadata_id;
377 base::FilePath path; 378 base::FilePath path;
378 StorageInfo info; 379 StorageInfo info;
379 base::FilePath relative_path; 380 base::FilePath relative_path;
380 base::Time now = base::Time::Now(); 381 base::Time now = base::Time::Now();
381 Verify(); 382 Verify();
382 383
383 // Add an auto detected gallery in the prefs version 0 format. 384 // Add an auto detected gallery in the prefs version 0 format.
384 path = MakePath("new_auto"); 385 path = MakePath("new_auto");
385 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 386 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
386 info.set_name(ASCIIToUTF16("NewAutoGallery")); 387 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
387 id = AddGalleryWithNameV0(info.device_id(), info.name(), 388 id = AddGalleryWithNameV0(info.device_id(), gallery_name, relative_path,
388 relative_path, false /*auto*/); 389 false /*auto*/);
389 EXPECT_EQ(default_galleries_count() + 1UL, id); 390 EXPECT_EQ(default_galleries_count() + 1UL, id);
390 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 391 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
391 MediaGalleryPrefInfo::kAutoDetected); 392 MediaGalleryPrefInfo::kAutoDetected);
392 Verify(); 393 Verify();
393 394
394 metadata_id = gallery_prefs()->AddGallery(info.device_id(), 395 metadata_id = gallery_prefs()->AddGallery(info.device_id(),
395 relative_path, 396 relative_path,
396 false /*auto*/, 397 false /*auto*/,
397 ASCIIToUTF16("volume label"), 398 ASCIIToUTF16("volume label"),
398 ASCIIToUTF16("vendor name"), 399 ASCIIToUTF16("vendor name"),
399 ASCIIToUTF16("model name"), 400 ASCIIToUTF16("model name"),
400 1000000ULL, now); 401 1000000ULL, now);
(...skipping 15 matching lines...) Expand all
416 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryType) { 417 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryType) {
417 MediaGalleryPrefId auto_id, id; 418 MediaGalleryPrefId auto_id, id;
418 base::FilePath path; 419 base::FilePath path;
419 StorageInfo info; 420 StorageInfo info;
420 base::FilePath relative_path; 421 base::FilePath relative_path;
421 Verify(); 422 Verify();
422 423
423 // Add a new auto detect gallery to test with. 424 // Add a new auto detect gallery to test with.
424 path = MakePath("new_auto"); 425 path = MakePath("new_auto");
425 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 426 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
426 info.set_name(ASCIIToUTF16("NewAutoGallery")); 427 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
427 id = AddGalleryWithNameV1(info.device_id(), info.name(), 428 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
428 relative_path, false /*auto*/); 429 false /*auto*/);
429 EXPECT_EQ(default_galleries_count() + 1UL, id); 430 EXPECT_EQ(default_galleries_count() + 1UL, id);
430 auto_id = id; 431 auto_id = id;
431 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 432 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
432 MediaGalleryPrefInfo::kAutoDetected); 433 MediaGalleryPrefInfo::kAutoDetected);
433 Verify(); 434 Verify();
434 435
435 // Remove an auto added gallery (i.e. make it blacklisted). 436 // Remove an auto added gallery (i.e. make it blacklisted).
436 gallery_prefs()->ForgetGalleryById(auto_id); 437 gallery_prefs()->ForgetGalleryById(auto_id);
437 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 438 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed;
438 expected_galleries_for_all.erase(auto_id); 439 expected_galleries_for_all.erase(auto_id);
439 Verify(); 440 Verify();
440 441
441 // Add the gallery again as a user action. 442 // Add the gallery again as a user action.
442 id = gallery_prefs()->AddGalleryByPath(path); 443 id = gallery_prefs()->AddGalleryByPath(path);
443 EXPECT_EQ(auto_id, id); 444 EXPECT_EQ(auto_id, id);
444 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 445 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
445 MediaGalleryPrefInfo::kAutoDetected); 446 MediaGalleryPrefInfo::kAutoDetected);
446 Verify(); 447 Verify();
447 448
448 // Remove an auto added gallery (i.e. make it blacklisted). 449 // Remove an auto added gallery (i.e. make it blacklisted).
449 gallery_prefs()->ForgetGalleryById(auto_id); 450 gallery_prefs()->ForgetGalleryById(auto_id);
450 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 451 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed;
451 expected_galleries_for_all.erase(auto_id); 452 expected_galleries_for_all.erase(auto_id);
452 Verify(); 453 Verify();
453 454
454 // Try adding the gallery again automatically and it should be a no-op. 455 // Try adding the gallery again automatically and it should be a no-op.
455 id = AddGalleryWithNameV1(info.device_id(), info.name(), 456 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
456 relative_path, false /*auto*/); 457 false /*auto*/);
457 EXPECT_EQ(auto_id, id); 458 EXPECT_EQ(auto_id, id);
458 Verify(); 459 Verify();
459 } 460 }
460 461
461 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryNameV2) { 462 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryNameV2) {
462 // Add a new auto detect gallery to test with. 463 // Add a new auto detect gallery to test with.
463 base::FilePath path = MakePath("new_auto"); 464 base::FilePath path = MakePath("new_auto");
464 StorageInfo info; 465 StorageInfo info;
465 base::FilePath relative_path; 466 base::FilePath relative_path;
466 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 467 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
467 info.set_name(ASCIIToUTF16("NewAutoGallery")); 468 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
468 MediaGalleryPrefId id = 469 MediaGalleryPrefId id = AddGalleryWithNameV2(info.device_id(), gallery_name,
469 AddGalleryWithNameV2(info.device_id(), info.name(), 470 relative_path, false /*auto*/);
470 relative_path, false /*auto*/); 471 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
471 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
472 MediaGalleryPrefInfo::kAutoDetected); 472 MediaGalleryPrefInfo::kAutoDetected);
473 Verify(); 473 Verify();
474 474
475 // Won't override the name -- don't change any expectation. 475 // Won't override the name -- don't change any expectation.
476 info.set_name(string16()); 476 gallery_name = base::string16();
477 AddGalleryWithNameV2(info.device_id(), info.name(), relative_path, false); 477 AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, false);
478 Verify(); 478 Verify();
479 479
480 info.set_name(ASCIIToUTF16("NewName")); 480 gallery_name = base::ASCIIToUTF16("NewName");
481 id = AddGalleryWithNameV2(info.device_id(), info.name(), 481 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
482 relative_path, false); 482 false);
483 // Note: will really just update the existing expectation. 483 // Note: will really just update the existing expectation.
484 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 484 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
485 MediaGalleryPrefInfo::kAutoDetected); 485 MediaGalleryPrefInfo::kAutoDetected);
486 Verify(); 486 Verify();
487 } 487 }
488 488
489 TEST_F(MediaGalleriesPreferencesTest, GalleryPermissions) { 489 TEST_F(MediaGalleriesPreferencesTest, GalleryPermissions) {
490 MediaGalleryPrefId auto_id, user_added_id, to_blacklist_id, id; 490 MediaGalleryPrefId auto_id, user_added_id, to_blacklist_id, id;
491 base::FilePath path; 491 base::FilePath path;
492 StorageInfo info; 492 StorageInfo info;
493 base::FilePath relative_path; 493 base::FilePath relative_path;
494 Verify(); 494 Verify();
495 495
496 // Add some galleries to test with. 496 // Add some galleries to test with.
497 path = MakePath("new_user"); 497 path = MakePath("new_user");
498 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 498 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
499 info.set_name(ASCIIToUTF16("NewUserGallery")); 499 base::string16 gallery_name = base::ASCIIToUTF16("NewUserGallery");
500 id = AddGalleryWithNameV1(info.device_id(), info.name(), 500 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
501 relative_path, true /*user*/); 501 true /*user*/);
502 EXPECT_EQ(default_galleries_count() + 1UL, id); 502 EXPECT_EQ(default_galleries_count() + 1UL, id);
503 user_added_id = id; 503 user_added_id = id;
504 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 504 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
505 MediaGalleryPrefInfo::kUserAdded); 505 MediaGalleryPrefInfo::kUserAdded);
506 Verify(); 506 Verify();
507 507
508 path = MakePath("new_auto"); 508 path = MakePath("new_auto");
509 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 509 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
510 info.set_name(ASCIIToUTF16("NewAutoGallery")); 510 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
511 id = AddGalleryWithNameV1(info.device_id(), info.name(), 511 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
512 relative_path, false /*auto*/); 512 false /*auto*/);
513 EXPECT_EQ(default_galleries_count() + 2UL, id); 513 EXPECT_EQ(default_galleries_count() + 2UL, id);
514 auto_id = id; 514 auto_id = id;
515 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 515 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
516 MediaGalleryPrefInfo::kAutoDetected); 516 MediaGalleryPrefInfo::kAutoDetected);
517 Verify(); 517 Verify();
518 518
519 path = MakePath("to_blacklist"); 519 path = MakePath("to_blacklist");
520 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 520 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
521 info.set_name(ASCIIToUTF16("ToBlacklistGallery")); 521 gallery_name = base::ASCIIToUTF16("ToBlacklistGallery");
522 id = AddGalleryWithNameV1(info.device_id(), info.name(), 522 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
523 relative_path, false /*auto*/); 523 false /*auto*/);
524 EXPECT_EQ(default_galleries_count() + 3UL, id); 524 EXPECT_EQ(default_galleries_count() + 3UL, id);
525 to_blacklist_id = id; 525 to_blacklist_id = id;
526 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 526 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
527 MediaGalleryPrefInfo::kAutoDetected); 527 MediaGalleryPrefInfo::kAutoDetected);
528 Verify(); 528 Verify();
529 529
530 // Remove permission for all galleries from the all-permission extension. 530 // Remove permission for all galleries from the all-permission extension.
531 gallery_prefs()->SetGalleryPermissionForExtension( 531 gallery_prefs()->SetGalleryPermissionForExtension(
532 *all_permission_extension.get(), auto_id, false); 532 *all_permission_extension.get(), auto_id, false);
533 expected_galleries_for_all.erase(auto_id); 533 expected_galleries_for_all.erase(auto_id);
534 Verify(); 534 Verify();
535 535
536 gallery_prefs()->SetGalleryPermissionForExtension( 536 gallery_prefs()->SetGalleryPermissionForExtension(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryDetails) { 607 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryDetails) {
608 MediaGalleryPrefId auto_id, id; 608 MediaGalleryPrefId auto_id, id;
609 base::FilePath path; 609 base::FilePath path;
610 StorageInfo info; 610 StorageInfo info;
611 base::FilePath relative_path; 611 base::FilePath relative_path;
612 Verify(); 612 Verify();
613 613
614 // Add a new auto detect gallery to test with. 614 // Add a new auto detect gallery to test with.
615 path = MakePath("new_auto"); 615 path = MakePath("new_auto");
616 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 616 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
617 info.set_name(ASCIIToUTF16("NewAutoGallery")); 617 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
618 id = AddGalleryWithNameV1(info.device_id(), info.name(), 618 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
619 relative_path, false /*auto*/); 619 false /*auto*/);
620 EXPECT_EQ(default_galleries_count() + 1UL, id); 620 EXPECT_EQ(default_galleries_count() + 1UL, id);
621 auto_id = id; 621 auto_id = id;
622 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 622 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
623 MediaGalleryPrefInfo::kAutoDetected); 623 MediaGalleryPrefInfo::kAutoDetected);
624 Verify(); 624 Verify();
625 625
626 // Update the device name and add the gallery again. 626 // Update the device name and add the gallery again.
627 info.set_name(ASCIIToUTF16("AutoGallery2")); 627 gallery_name = base::ASCIIToUTF16("AutoGallery2");
628 id = AddGalleryWithNameV1(info.device_id(), info.name(), 628 id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
629 relative_path, false /*auto*/); 629 false /*auto*/);
630 EXPECT_EQ(auto_id, id); 630 EXPECT_EQ(auto_id, id);
631 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 631 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
632 MediaGalleryPrefInfo::kAutoDetected); 632 MediaGalleryPrefInfo::kAutoDetected);
633 Verify(); 633 Verify();
634 } 634 }
635 635
636 TEST_F(MediaGalleriesPreferencesTest, MultipleGalleriesPerDevices) { 636 TEST_F(MediaGalleriesPreferencesTest, MultipleGalleriesPerDevices) {
637 base::FilePath path; 637 base::FilePath path;
638 StorageInfo info; 638 StorageInfo info;
639 base::FilePath relative_path; 639 base::FilePath relative_path;
640 Verify(); 640 Verify();
641 641
642 // Add a regular gallery 642 // Add a regular gallery
643 path = MakePath("new_user"); 643 path = MakePath("new_user");
644 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 644 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
645 info.set_name(ASCIIToUTF16("NewUserGallery")); 645 base::string16 gallery_name = base::ASCIIToUTF16("NewUserGallery");
646 MediaGalleryPrefId user_added_id = 646 MediaGalleryPrefId user_added_id = AddGalleryWithNameV1(
647 AddGalleryWithNameV1(info.device_id(), info.name(), 647 info.device_id(), gallery_name, relative_path, true /*user*/);
648 relative_path, true /*user*/);
649 EXPECT_EQ(default_galleries_count() + 1UL, user_added_id); 648 EXPECT_EQ(default_galleries_count() + 1UL, user_added_id);
650 AddGalleryExpectation(user_added_id, info.name(), info.device_id(), 649 AddGalleryExpectation(user_added_id, gallery_name, info.device_id(),
651 relative_path, MediaGalleryPrefInfo::kUserAdded); 650 relative_path, MediaGalleryPrefInfo::kUserAdded);
652 Verify(); 651 Verify();
653 652
654 // Find it by device id and fail to find something related. 653 // Find it by device id and fail to find something related.
655 MediaGalleryPrefIdSet pref_id_set; 654 MediaGalleryPrefIdSet pref_id_set;
656 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id()); 655 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id());
657 EXPECT_EQ(1U, pref_id_set.size()); 656 EXPECT_EQ(1U, pref_id_set.size());
658 EXPECT_TRUE(pref_id_set.find(user_added_id) != pref_id_set.end()); 657 EXPECT_TRUE(pref_id_set.find(user_added_id) != pref_id_set.end());
659 658
660 MediaStorageUtil::GetDeviceInfoFromPath(MakePath("new_user/foo"), &info, 659 MediaStorageUtil::GetDeviceInfoFromPath(MakePath("new_user/foo"), &info,
661 &relative_path); 660 &relative_path);
662 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id()); 661 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id());
663 EXPECT_EQ(0U, pref_id_set.size()); 662 EXPECT_EQ(0U, pref_id_set.size());
664 663
665 // Add some galleries on the same device. 664 // Add some galleries on the same device.
666 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device1")); 665 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device1"));
667 info.set_name(ASCIIToUTF16("Device1Path1")); 666 gallery_name = base::ASCIIToUTF16("Device1Path1");
668 std::string device_id = "path:device1"; 667 std::string device_id = "path:device1";
669 MediaGalleryPrefId dev1_path1_id = AddGalleryWithNameV1( 668 MediaGalleryPrefId dev1_path1_id = AddGalleryWithNameV1(
670 device_id, info.name(), relative_path, true /*user*/); 669 device_id, gallery_name, relative_path, true /*user*/);
671 EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id); 670 EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id);
672 AddGalleryExpectation(dev1_path1_id, info.name(), device_id, relative_path, 671 AddGalleryExpectation(dev1_path1_id, gallery_name, device_id, relative_path,
673 MediaGalleryPrefInfo::kUserAdded); 672 MediaGalleryPrefInfo::kUserAdded);
674 Verify(); 673 Verify();
675 674
676 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device1")); 675 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device1"));
677 info.set_name(ASCIIToUTF16("Device1Path2")); 676 gallery_name = base::ASCIIToUTF16("Device1Path2");
678 MediaGalleryPrefId dev1_path2_id = AddGalleryWithNameV1( 677 MediaGalleryPrefId dev1_path2_id = AddGalleryWithNameV1(
679 device_id, info.name(), relative_path, true /*user*/); 678 device_id, gallery_name, relative_path, true /*user*/);
680 EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id); 679 EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id);
681 AddGalleryExpectation(dev1_path2_id, info.name(), device_id, relative_path, 680 AddGalleryExpectation(dev1_path2_id, gallery_name, device_id, relative_path,
682 MediaGalleryPrefInfo::kUserAdded); 681 MediaGalleryPrefInfo::kUserAdded);
683 Verify(); 682 Verify();
684 683
685 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device2")); 684 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device2"));
686 info.set_name(ASCIIToUTF16("Device2Path1")); 685 gallery_name = base::ASCIIToUTF16("Device2Path1");
687 device_id = "path:device2"; 686 device_id = "path:device2";
688 MediaGalleryPrefId dev2_path1_id = AddGalleryWithNameV1( 687 MediaGalleryPrefId dev2_path1_id = AddGalleryWithNameV1(
689 device_id, info.name(), relative_path, true /*user*/); 688 device_id, gallery_name, relative_path, true /*user*/);
690 EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id); 689 EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id);
691 AddGalleryExpectation(dev2_path1_id, info.name(), device_id, relative_path, 690 AddGalleryExpectation(dev2_path1_id, gallery_name, device_id, relative_path,
692 MediaGalleryPrefInfo::kUserAdded); 691 MediaGalleryPrefInfo::kUserAdded);
693 Verify(); 692 Verify();
694 693
695 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device2")); 694 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device2"));
696 info.set_name(ASCIIToUTF16("Device2Path2")); 695 gallery_name = base::ASCIIToUTF16("Device2Path2");
697 MediaGalleryPrefId dev2_path2_id = AddGalleryWithNameV1( 696 MediaGalleryPrefId dev2_path2_id = AddGalleryWithNameV1(
698 device_id, info.name(), relative_path, true /*user*/); 697 device_id, gallery_name, relative_path, true /*user*/);
699 EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id); 698 EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id);
700 AddGalleryExpectation(dev2_path2_id, info.name(), device_id, relative_path, 699 AddGalleryExpectation(dev2_path2_id, gallery_name, device_id, relative_path,
701 MediaGalleryPrefInfo::kUserAdded); 700 MediaGalleryPrefInfo::kUserAdded);
702 Verify(); 701 Verify();
703 702
704 // Check that adding one of them again works as expected. 703 // Check that adding one of them again works as expected.
705 MediaGalleryPrefId id = AddGalleryWithNameV1( 704 MediaGalleryPrefId id = AddGalleryWithNameV1(
706 device_id, info.name(), relative_path, true /*user*/); 705 device_id, gallery_name, relative_path, true /*user*/);
707 EXPECT_EQ(dev2_path2_id, id); 706 EXPECT_EQ(dev2_path2_id, id);
708 Verify(); 707 Verify();
709 } 708 }
710 709
711 TEST_F(MediaGalleriesPreferencesTest, GalleryChangeObserver) { 710 TEST_F(MediaGalleriesPreferencesTest, GalleryChangeObserver) {
712 // Start with one observer. 711 // Start with one observer.
713 MockGalleryChangeObserver observer1(gallery_prefs()); 712 MockGalleryChangeObserver observer1(gallery_prefs());
714 gallery_prefs()->AddGalleryChangeObserver(&observer1); 713 gallery_prefs()->AddGalleryChangeObserver(&observer1);
715 714
716 // Add a new auto detected gallery. 715 // Add a new auto detected gallery.
717 base::FilePath path = MakePath("new_auto"); 716 base::FilePath path = MakePath("new_auto");
718 StorageInfo info; 717 StorageInfo info;
719 base::FilePath relative_path; 718 base::FilePath relative_path;
720 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 719 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
721 info.set_name(ASCIIToUTF16("NewAutoGallery")); 720 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
722 MediaGalleryPrefId auto_id = AddGalleryWithNameV1( 721 MediaGalleryPrefId auto_id = AddGalleryWithNameV1(
723 info.device_id(), info.name(), relative_path, false /*auto*/); 722 info.device_id(), gallery_name, relative_path, false /*auto*/);
724 EXPECT_EQ(default_galleries_count() + 1UL, auto_id); 723 EXPECT_EQ(default_galleries_count() + 1UL, auto_id);
725 AddGalleryExpectation(auto_id, info.name(), info.device_id(), 724 AddGalleryExpectation(auto_id, gallery_name, info.device_id(),
726 relative_path, MediaGalleryPrefInfo::kAutoDetected); 725 relative_path, MediaGalleryPrefInfo::kAutoDetected);
727 EXPECT_EQ(1, observer1.notifications()); 726 EXPECT_EQ(1, observer1.notifications());
728 727
729 // Add a second observer. 728 // Add a second observer.
730 MockGalleryChangeObserver observer2(gallery_prefs()); 729 MockGalleryChangeObserver observer2(gallery_prefs());
731 gallery_prefs()->AddGalleryChangeObserver(&observer2); 730 gallery_prefs()->AddGalleryChangeObserver(&observer2);
732 731
733 // Add a new user added gallery. 732 // Add a new user added gallery.
734 path = MakePath("new_user"); 733 path = MakePath("new_user");
735 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 734 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
736 info.set_name(ASCIIToUTF16("NewUserGallery")); 735 gallery_name = base::ASCIIToUTF16("NewUserGallery");
737 MediaGalleryPrefId user_added_id = 736 MediaGalleryPrefId user_added_id = AddGalleryWithNameV1(
738 AddGalleryWithNameV1(info.device_id(), info.name(), 737 info.device_id(), gallery_name, relative_path, true /*user*/);
739 relative_path, true /*user*/); 738 AddGalleryExpectation(user_added_id, gallery_name, info.device_id(),
740 AddGalleryExpectation(user_added_id, info.name(), info.device_id(),
741 relative_path, MediaGalleryPrefInfo::kUserAdded); 739 relative_path, MediaGalleryPrefInfo::kUserAdded);
742 EXPECT_EQ(default_galleries_count() + 2UL, user_added_id); 740 EXPECT_EQ(default_galleries_count() + 2UL, user_added_id);
743 EXPECT_EQ(2, observer1.notifications()); 741 EXPECT_EQ(2, observer1.notifications());
744 EXPECT_EQ(1, observer2.notifications()); 742 EXPECT_EQ(1, observer2.notifications());
745 743
746 // Remove the first observer. 744 // Remove the first observer.
747 gallery_prefs()->RemoveGalleryChangeObserver(&observer1); 745 gallery_prefs()->RemoveGalleryChangeObserver(&observer1);
748 746
749 // Remove an auto added gallery (i.e. make it blacklisted). 747 // Remove an auto added gallery (i.e. make it blacklisted).
750 gallery_prefs()->ForgetGalleryById(auto_id); 748 gallery_prefs()->ForgetGalleryById(auto_id);
(...skipping 15 matching lines...) Expand all
766 TEST_F(MediaGalleriesPreferencesTest, UpdateSingletonDeviceIdType) { 764 TEST_F(MediaGalleriesPreferencesTest, UpdateSingletonDeviceIdType) {
767 MediaGalleryPrefId id; 765 MediaGalleryPrefId id;
768 base::FilePath path; 766 base::FilePath path;
769 StorageInfo info; 767 StorageInfo info;
770 base::FilePath relative_path; 768 base::FilePath relative_path;
771 Verify(); 769 Verify();
772 770
773 // Add a new auto detect gallery to test with. 771 // Add a new auto detect gallery to test with.
774 path = MakePath("new_auto"); 772 path = MakePath("new_auto");
775 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 773 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
776 info.set_name(ASCIIToUTF16("NewAutoGallery")); 774 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
777 info.set_device_id(StorageInfo::MakeDeviceId(StorageInfo::ITUNES, 775 info.set_device_id(StorageInfo::MakeDeviceId(StorageInfo::ITUNES,
778 path.AsUTF8Unsafe())); 776 path.AsUTF8Unsafe()));
779 id = AddGalleryWithNameV2(info.device_id(), info.name(), relative_path, 777 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
780 false /*auto*/); 778 false /*auto*/);
781 EXPECT_EQ(default_galleries_count() + 1UL, id); 779 EXPECT_EQ(default_galleries_count() + 1UL, id);
782 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 780 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
783 MediaGalleryPrefInfo::kAutoDetected); 781 MediaGalleryPrefInfo::kAutoDetected);
784 Verify(); 782 Verify();
785 783
786 // Update the device id. 784 // Update the device id.
787 MockGalleryChangeObserver observer(gallery_prefs()); 785 MockGalleryChangeObserver observer(gallery_prefs());
788 gallery_prefs()->AddGalleryChangeObserver(&observer); 786 gallery_prefs()->AddGalleryChangeObserver(&observer);
789 787
790 path = MakePath("updated_path"); 788 path = MakePath("updated_path");
791 std::string updated_device_id = 789 std::string updated_device_id =
792 StorageInfo::MakeDeviceId(StorageInfo::ITUNES, path.AsUTF8Unsafe()); 790 StorageInfo::MakeDeviceId(StorageInfo::ITUNES, path.AsUTF8Unsafe());
793 EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id)); 791 EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id));
794 AddGalleryExpectation(id, info.name(), updated_device_id, relative_path, 792 AddGalleryExpectation(id, gallery_name, updated_device_id, relative_path,
795 MediaGalleryPrefInfo::kAutoDetected); 793 MediaGalleryPrefInfo::kAutoDetected);
796 expected_device_map[info.device_id()].erase(id); 794 expected_device_map[info.device_id()].erase(id);
797 expected_device_map[updated_device_id].insert(id); 795 expected_device_map[updated_device_id].insert(id);
798 Verify(); 796 Verify();
799 EXPECT_EQ(1, observer.notifications()); 797 EXPECT_EQ(1, observer.notifications());
800 798
801 // No gallery for type. 799 // No gallery for type.
802 std::string new_device_id = 800 std::string new_device_id =
803 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe()); 801 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe());
804 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id)); 802 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id));
(...skipping 23 matching lines...) Expand all
828 info.GetGalleryAdditionalDetails()); 826 info.GetGalleryAdditionalDetails());
829 EXPECT_NE(l10n_util::GetStringUTF16( 827 EXPECT_NE(l10n_util::GetStringUTF16(
830 IDS_MEDIA_GALLERIES_DIALOG_DEVICE_ATTACHED), 828 IDS_MEDIA_GALLERIES_DIALOG_DEVICE_ATTACHED),
831 info.GetGalleryAdditionalDetails()); 829 info.GetGalleryAdditionalDetails());
832 830
833 info.volume_label = ASCIIToUTF16("vol"); 831 info.volume_label = ASCIIToUTF16("vol");
834 info.vendor_name = ASCIIToUTF16("vendor"); 832 info.vendor_name = ASCIIToUTF16("vendor");
835 info.model_name = ASCIIToUTF16("model"); 833 info.model_name = ASCIIToUTF16("model");
836 EXPECT_EQ(ASCIIToUTF16("o2"), info.GetGalleryDisplayName()); 834 EXPECT_EQ(ASCIIToUTF16("o2"), info.GetGalleryDisplayName());
837 835
838 info.display_name = string16(); 836 info.display_name = base::string16();
839 EXPECT_EQ(ASCIIToUTF16("vol"), info.GetGalleryDisplayName()); 837 EXPECT_EQ(ASCIIToUTF16("vol"), info.GetGalleryDisplayName());
840 info.volume_label = string16(); 838 info.volume_label = base::string16();
841 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName()); 839 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName());
842 840
843 info.device_id = StorageInfo::MakeDeviceId( 841 info.device_id = StorageInfo::MakeDeviceId(
844 StorageInfo::FIXED_MASS_STORAGE, "unique"); 842 StorageInfo::FIXED_MASS_STORAGE, "unique");
845 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(), 843 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(),
846 UTF16ToUTF8(info.GetGalleryTooltip())); 844 UTF16ToUTF8(info.GetGalleryTooltip()));
847 } 845 }
848 846
849 } // namespace chrome 847 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698