| 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 // MediaFileSystemRegistry unit tests. | 5 // MediaFileSystemRegistry unit tests. |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 471 |
| 472 ProfileState::~ProfileState() { | 472 ProfileState::~ProfileState() { |
| 473 // TestExtensionSystem uses DeleteSoon, so we need to delete the profiles | 473 // TestExtensionSystem uses DeleteSoon, so we need to delete the profiles |
| 474 // and then run the message queue to clean up. But first we have to | 474 // and then run the message queue to clean up. But first we have to |
| 475 // delete everything that references the profile. | 475 // delete everything that references the profile. |
| 476 single_web_contents_.reset(); | 476 single_web_contents_.reset(); |
| 477 shared_web_contents1_.reset(); | 477 shared_web_contents1_.reset(); |
| 478 shared_web_contents2_.reset(); | 478 shared_web_contents2_.reset(); |
| 479 profile_.reset(); | 479 profile_.reset(); |
| 480 | 480 |
| 481 MessageLoop::current()->RunUntilIdle(); | 481 base::MessageLoop::current()->RunUntilIdle(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 MediaGalleriesPreferences* ProfileState::GetMediaGalleriesPrefs() { | 484 MediaGalleriesPreferences* ProfileState::GetMediaGalleriesPrefs() { |
| 485 return MediaGalleriesPreferencesFactory::GetForProfile(profile_.get()); | 485 return MediaGalleriesPreferencesFactory::GetForProfile(profile_.get()); |
| 486 } | 486 } |
| 487 | 487 |
| 488 void ProfileState::CheckGalleries( | 488 void ProfileState::CheckGalleries( |
| 489 const std::string& test, | 489 const std::string& test, |
| 490 const std::vector<MediaFileSystemInfo>& regular_extension_galleries, | 490 const std::vector<MediaFileSystemInfo>& regular_extension_galleries, |
| 491 const std::vector<MediaFileSystemInfo>& all_extension_galleries) { | 491 const std::vector<MediaFileSystemInfo>& all_extension_galleries) { |
| 492 content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost(); | 492 content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost(); |
| 493 MediaFileSystemRegistry* registry = | 493 MediaFileSystemRegistry* registry = |
| 494 g_browser_process->media_file_system_registry(); | 494 g_browser_process->media_file_system_registry(); |
| 495 | 495 |
| 496 // No Media Galleries permissions. | 496 // No Media Galleries permissions. |
| 497 std::vector<MediaFileSystemInfo> empty_expectation; | 497 std::vector<MediaFileSystemInfo> empty_expectation; |
| 498 registry->GetMediaFileSystemsForExtension( | 498 registry->GetMediaFileSystemsForExtension( |
| 499 rvh, no_permissions_extension_.get(), | 499 rvh, no_permissions_extension_.get(), |
| 500 base::Bind(&ProfileState::CompareResults, base::Unretained(this), | 500 base::Bind(&ProfileState::CompareResults, base::Unretained(this), |
| 501 base::StringPrintf("%s (no permission)", test.c_str()), | 501 base::StringPrintf("%s (no permission)", test.c_str()), |
| 502 base::ConstRef(empty_expectation))); | 502 base::ConstRef(empty_expectation))); |
| 503 MessageLoop::current()->RunUntilIdle(); | 503 base::MessageLoop::current()->RunUntilIdle(); |
| 504 EXPECT_EQ(1, GetAndClearComparisonCount()); | 504 EXPECT_EQ(1, GetAndClearComparisonCount()); |
| 505 | 505 |
| 506 // Read permission only. | 506 // Read permission only. |
| 507 registry->GetMediaFileSystemsForExtension( | 507 registry->GetMediaFileSystemsForExtension( |
| 508 rvh, regular_permission_extension_.get(), | 508 rvh, regular_permission_extension_.get(), |
| 509 base::Bind(&ProfileState::CompareResults, base::Unretained(this), | 509 base::Bind(&ProfileState::CompareResults, base::Unretained(this), |
| 510 base::StringPrintf("%s (regular permission)", test.c_str()), | 510 base::StringPrintf("%s (regular permission)", test.c_str()), |
| 511 base::ConstRef(regular_extension_galleries))); | 511 base::ConstRef(regular_extension_galleries))); |
| 512 MessageLoop::current()->RunUntilIdle(); | 512 base::MessageLoop::current()->RunUntilIdle(); |
| 513 EXPECT_EQ(1, GetAndClearComparisonCount()); | 513 EXPECT_EQ(1, GetAndClearComparisonCount()); |
| 514 | 514 |
| 515 // All galleries permission. | 515 // All galleries permission. |
| 516 registry->GetMediaFileSystemsForExtension( | 516 registry->GetMediaFileSystemsForExtension( |
| 517 rvh, all_permission_extension_.get(), | 517 rvh, all_permission_extension_.get(), |
| 518 base::Bind(&ProfileState::CompareResults, base::Unretained(this), | 518 base::Bind(&ProfileState::CompareResults, base::Unretained(this), |
| 519 base::StringPrintf("%s (all permission)", test.c_str()), | 519 base::StringPrintf("%s (all permission)", test.c_str()), |
| 520 base::ConstRef(all_extension_galleries))); | 520 base::ConstRef(all_extension_galleries))); |
| 521 MessageLoop::current()->RunUntilIdle(); | 521 base::MessageLoop::current()->RunUntilIdle(); |
| 522 EXPECT_EQ(1, GetAndClearComparisonCount()); | 522 EXPECT_EQ(1, GetAndClearComparisonCount()); |
| 523 } | 523 } |
| 524 | 524 |
| 525 FSInfoMap ProfileState::GetGalleriesInfo(extensions::Extension* extension) { | 525 FSInfoMap ProfileState::GetGalleriesInfo(extensions::Extension* extension) { |
| 526 content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost(); | 526 content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost(); |
| 527 FSInfoMap results; | 527 FSInfoMap results; |
| 528 MediaFileSystemRegistry* registry = | 528 MediaFileSystemRegistry* registry = |
| 529 g_browser_process->media_file_system_registry(); | 529 g_browser_process->media_file_system_registry(); |
| 530 registry->GetMediaFileSystemsForExtension( | 530 registry->GetMediaFileSystemsForExtension( |
| 531 rvh, extension, | 531 rvh, extension, |
| 532 base::Bind(&GetGalleryInfoCallback, base::Unretained(&results))); | 532 base::Bind(&GetGalleryInfoCallback, base::Unretained(&results))); |
| 533 MessageLoop::current()->RunUntilIdle(); | 533 base::MessageLoop::current()->RunUntilIdle(); |
| 534 return results; | 534 return results; |
| 535 } | 535 } |
| 536 | 536 |
| 537 extensions::Extension* ProfileState::all_permission_extension() { | 537 extensions::Extension* ProfileState::all_permission_extension() { |
| 538 return all_permission_extension_.get(); | 538 return all_permission_extension_.get(); |
| 539 } | 539 } |
| 540 | 540 |
| 541 extensions::Extension* ProfileState::regular_permission_extension() { | 541 extensions::Extension* ProfileState::regular_permission_extension() { |
| 542 return regular_permission_extension_.get(); | 542 return regular_permission_extension_.get(); |
| 543 } | 543 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 571 return result; | 571 return result; |
| 572 } | 572 } |
| 573 | 573 |
| 574 } // namespace | 574 } // namespace |
| 575 | 575 |
| 576 ///////////////////////////////// | 576 ///////////////////////////////// |
| 577 // MediaFileSystemRegistryTest // | 577 // MediaFileSystemRegistryTest // |
| 578 ///////////////////////////////// | 578 ///////////////////////////////// |
| 579 | 579 |
| 580 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() | 580 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() |
| 581 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), | 581 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), |
| 582 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { | 582 file_thread_(content::BrowserThread::FILE, base::MessageLoop::current()) { |
| 583 } | 583 } |
| 584 | 584 |
| 585 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { | 585 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { |
| 586 for (size_t i = 0; i < profile_count; ++i) { | 586 for (size_t i = 0; i < profile_count; ++i) { |
| 587 ProfileState* state = new ProfileState(&rph_factory_); | 587 ProfileState* state = new ProfileState(&rph_factory_); |
| 588 profile_states_.push_back(state); | 588 profile_states_.push_back(state); |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 | 591 |
| 592 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { | 592 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 609 } | 609 } |
| 610 | 610 |
| 611 std::string MediaFileSystemRegistryTest::AttachDevice( | 611 std::string MediaFileSystemRegistryTest::AttachDevice( |
| 612 StorageInfo::Type type, | 612 StorageInfo::Type type, |
| 613 const std::string& unique_id, | 613 const std::string& unique_id, |
| 614 const base::FilePath& location) { | 614 const base::FilePath& location) { |
| 615 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); | 615 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); |
| 616 DCHECK(StorageInfo::IsRemovableDevice(device_id)); | 616 DCHECK(StorageInfo::IsRemovableDevice(device_id)); |
| 617 string16 name = location.LossyDisplayName(); | 617 string16 name = location.LossyDisplayName(); |
| 618 ProcessAttach(device_id, name, location.value()); | 618 ProcessAttach(device_id, name, location.value()); |
| 619 MessageLoop::current()->RunUntilIdle(); | 619 base::MessageLoop::current()->RunUntilIdle(); |
| 620 return device_id; | 620 return device_id; |
| 621 } | 621 } |
| 622 | 622 |
| 623 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { | 623 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { |
| 624 DCHECK(StorageInfo::IsRemovableDevice(device_id)); | 624 DCHECK(StorageInfo::IsRemovableDevice(device_id)); |
| 625 ProcessDetach(device_id); | 625 ProcessDetach(device_id); |
| 626 MessageLoop::current()->RunUntilIdle(); | 626 base::MessageLoop::current()->RunUntilIdle(); |
| 627 } | 627 } |
| 628 | 628 |
| 629 void MediaFileSystemRegistryTest::SetGalleryPermission( | 629 void MediaFileSystemRegistryTest::SetGalleryPermission( |
| 630 ProfileState* profile_state, extensions::Extension* extension, | 630 ProfileState* profile_state, extensions::Extension* extension, |
| 631 const std::string& device_id, bool has_access) { | 631 const std::string& device_id, bool has_access) { |
| 632 MediaGalleriesPreferences* preferences = | 632 MediaGalleriesPreferences* preferences = |
| 633 profile_state->GetMediaGalleriesPrefs(); | 633 profile_state->GetMediaGalleriesPrefs(); |
| 634 MediaGalleryPrefIdSet pref_id = | 634 MediaGalleryPrefIdSet pref_id = |
| 635 preferences->LookUpGalleriesByDeviceId(device_id); | 635 preferences->LookUpGalleriesByDeviceId(device_id); |
| 636 ASSERT_EQ(1U, pref_id.size()); | 636 ASSERT_EQ(1U, pref_id.size()); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName))); | 753 ASSERT_TRUE(file_util::CreateDirectory(dcim_dir_.Append(kDCIMDirectoryName))); |
| 754 } | 754 } |
| 755 | 755 |
| 756 void MediaFileSystemRegistryTest::TearDown() { | 756 void MediaFileSystemRegistryTest::TearDown() { |
| 757 profile_states_.clear(); | 757 profile_states_.clear(); |
| 758 ChromeRenderViewHostTestHarness::TearDown(); | 758 ChromeRenderViewHostTestHarness::TearDown(); |
| 759 MediaFileSystemRegistry* registry = | 759 MediaFileSystemRegistry* registry = |
| 760 g_browser_process->media_file_system_registry(); | 760 g_browser_process->media_file_system_registry(); |
| 761 EXPECT_EQ(0U, registry->GetExtensionGalleriesHostCountForTests()); | 761 EXPECT_EQ(0U, registry->GetExtensionGalleriesHostCountForTests()); |
| 762 BrowserThread::GetBlockingPool()->FlushForTesting(); | 762 BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 763 MessageLoop::current()->RunUntilIdle(); | 763 base::MessageLoop::current()->RunUntilIdle(); |
| 764 } | 764 } |
| 765 | 765 |
| 766 /////////// | 766 /////////// |
| 767 // Tests // | 767 // Tests // |
| 768 /////////// | 768 /////////// |
| 769 | 769 |
| 770 TEST_F(MediaFileSystemRegistryTest, Basic) { | 770 TEST_F(MediaFileSystemRegistryTest, Basic) { |
| 771 CreateProfileState(1); | 771 CreateProfileState(1); |
| 772 AssertAllAutoAddedGalleries(); | 772 AssertAllAutoAddedGalleries(); |
| 773 | 773 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); | 854 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); |
| 855 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); | 855 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); |
| 856 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); | 856 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
| 857 it != galleries.end(); ++it) { | 857 it != galleries.end(); ++it) { |
| 858 if (it->second.device_id == device_id) { | 858 if (it->second.device_id == device_id) { |
| 859 prefs->ForgetGalleryById(it->first); | 859 prefs->ForgetGalleryById(it->first); |
| 860 forget_gallery = true; | 860 forget_gallery = true; |
| 861 break; | 861 break; |
| 862 } | 862 } |
| 863 } | 863 } |
| 864 MessageLoop::current()->RunUntilIdle(); | 864 base::MessageLoop::current()->RunUntilIdle(); |
| 865 EXPECT_TRUE(forget_gallery); | 865 EXPECT_TRUE(forget_gallery); |
| 866 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); | 866 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); |
| 867 | 867 |
| 868 // Call GetPreferences() and the gallery count should not change. | 868 // Call GetPreferences() and the gallery count should not change. |
| 869 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); | 869 GetMediaFileSystemRegistry()->GetPreferences(profile_state->profile()); |
| 870 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); | 870 EXPECT_EQ(gallery_count, GetAutoAddedGalleries(profile_state).size()); |
| 871 } | 871 } |
| 872 | 872 |
| 873 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) { | 873 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) { |
| 874 FSInfoMap galleries_info; | 874 FSInfoMap galleries_info; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 pref_info_with_relpath.device_id = device_id; | 970 pref_info_with_relpath.device_id = device_id; |
| 971 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), | 971 EXPECT_EQ(dcim_dir().Append(pref_info_with_relpath.path).value(), |
| 972 pref_info_with_relpath.AbsolutePath().value()); | 972 pref_info_with_relpath.AbsolutePath().value()); |
| 973 | 973 |
| 974 DetachDevice(device_id); | 974 DetachDevice(device_id); |
| 975 EXPECT_TRUE(pref_info.AbsolutePath().empty()); | 975 EXPECT_TRUE(pref_info.AbsolutePath().empty()); |
| 976 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); | 976 EXPECT_TRUE(pref_info_with_relpath.AbsolutePath().empty()); |
| 977 } | 977 } |
| 978 | 978 |
| 979 } // namespace chrome | 979 } // namespace chrome |
| OLD | NEW |