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