Chromium Code Reviews| Index: chrome/browser/media_gallery/media_file_system_registry_unittest.cc |
| =================================================================== |
| --- chrome/browser/media_gallery/media_file_system_registry_unittest.cc (revision 172539) |
| +++ chrome/browser/media_gallery/media_file_system_registry_unittest.cc (working copy) |
| @@ -4,9 +4,12 @@ |
| // MediaFileSystemRegistry unit tests. |
| +#include <set> |
| + |
| #include "base/command_line.h" |
| #include "base/file_util.h" |
| #include "base/files/scoped_temp_dir.h" |
| +#include "base/json/json_reader.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/scoped_vector.h" |
| @@ -149,6 +152,18 @@ |
| namespace { |
| +const char kIsRemovableKey[] = "isRemovable"; |
| + |
| +void GetGalleryNamesCB(std::set<std::string>* results, |
| + const std::vector<MediaFileSystemInfo>& file_systems) { |
| + for (size_t i = 0; i < file_systems.size(); i++) { |
|
kmadhusu
2012/12/12 17:45:02
nit: ++i
Lei Zhang
2012/12/12 20:15:15
The rest of the file had i++, so I was being consi
|
| + std::set<std::string>::const_iterator it = |
| + results->find(file_systems[i].name); |
| + ASSERT_EQ(it, results->end()); |
| + results->insert(file_systems[i].name); |
| + } |
| +} |
| + |
| class TestMediaStorageUtil : public MediaStorageUtil { |
| public: |
| static void SetTestingMode(); |
| @@ -194,6 +209,8 @@ |
| const std::vector<MediaFileSystemInfo>& regular_extension_galleries, |
| const std::vector<MediaFileSystemInfo>& all_extension_galleries); |
| + std::set<std::string> GetGalleryNames(extensions::Extension* extension); |
| + |
| extensions::Extension* all_permission_extension(); |
| extensions::Extension* regular_permission_extension(); |
| @@ -448,6 +465,19 @@ |
| EXPECT_EQ(1, GetAndClearComparisonCount()); |
| } |
| +std::set<std::string> ProfileState::GetGalleryNames( |
| + extensions::Extension* extension) { |
| + content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost(); |
| + std::set<std::string> results; |
| + MediaFileSystemRegistry* registry = |
| + g_browser_process->media_file_system_registry(); |
| + registry->GetMediaFileSystemsForExtension( |
| + rvh, extension, |
| + base::Bind(&GetGalleryNamesCB, base::Unretained(&results))); |
| + MessageLoop::current()->RunUntilIdle(); |
| + return results; |
| +} |
| + |
| extensions::Extension* ProfileState::all_permission_extension() { |
| return all_permission_extension_.get(); |
| } |
| @@ -666,6 +696,75 @@ |
| auto_galleries); |
| } |
| +TEST_F(MediaFileSystemRegistryTest, GalleryName) { |
| + CreateProfileState(1); |
| + AssertAllAutoAddedGalleries(); |
| + const size_t kProfileId = 0U; |
| + |
| + // Get all existing gallery names. |
| + ProfileState* profile_state = GetProfileState(kProfileId); |
| + std::set<std::string> gallery_names = |
| + profile_state->GetGalleryNames(profile_state->all_permission_extension()); |
| + ASSERT_EQ(3U, gallery_names.size()); |
| + |
| + // Add a couple new galleries. |
| + FilePath mtp_bogus_location(FILE_PATH_LITERAL("/mtp_bogus_location")); |
| + std::string mtp_device_id = AttachDevice(MediaStorageUtil::MTP_OR_PTP, |
| + "mtp_fake_id", |
|
kmadhusu
2012/12/12 17:45:02
style nit: Fix indentation.
Lei Zhang
2012/12/12 20:15:15
Done.
|
| + mtp_bogus_location); |
| + SetGalleryPermission(kProfileId, |
| + profile_state->all_permission_extension(), |
| + mtp_device_id, |
| + true /*has access*/); |
| + |
| + FilePath removable_bogus_location( |
| + FILE_PATH_LITERAL("/removable_bogus_location")); |
| + std::string removable_device_id = |
| + AttachDevice(MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, |
| + "removable_fake_id", |
| + removable_bogus_location); |
| + SetGalleryPermission(kProfileId, |
| + profile_state->all_permission_extension(), |
| + removable_device_id, |
| + true /*has access*/); |
| + |
| + // Get new list of all gallery names. |
| + std::set<std::string> new_gallery_names = |
| + profile_state->GetGalleryNames(profile_state->all_permission_extension()); |
| + ASSERT_EQ(5U, new_gallery_names.size()); |
| + |
| + // Check the intersection. |
| + std::vector<std::string> intersection_names; |
| + std::set_intersection(gallery_names.begin(), gallery_names.end(), |
| + new_gallery_names.begin(), new_gallery_names.end(), |
| + std::back_inserter(intersection_names)); |
| + EXPECT_EQ(3U, intersection_names.size()); |
| + for (size_t i = 0; i < intersection_names.size(); i++) { |
|
kmadhusu
2012/12/12 17:45:02
nit: ++i
|
| + scoped_ptr<DictionaryValue> dict_value(static_cast<DictionaryValue*>( |
| + base::JSONReader::Read(intersection_names[i]))); |
| + ASSERT_TRUE(dict_value); |
| + bool is_removable; |
| + ASSERT_TRUE(dict_value->GetBoolean(kIsRemovableKey, &is_removable)); |
| + EXPECT_FALSE(is_removable); |
| + } |
| + |
| + // Check the difference. |
| + std::vector<std::string> difference_names; |
| + std::set_symmetric_difference( |
| + gallery_names.begin(), gallery_names.end(), |
| + new_gallery_names.begin(), new_gallery_names.end(), |
| + std::back_inserter(difference_names)); |
| + EXPECT_EQ(2U, difference_names.size()); |
| + for (size_t i = 0; i < difference_names.size(); i++) { |
| + scoped_ptr<DictionaryValue> dict_value(static_cast<DictionaryValue*>( |
| + base::JSONReader::Read(difference_names[i]))); |
| + ASSERT_TRUE(dict_value); |
| + bool is_removable; |
| + ASSERT_TRUE(dict_value->GetBoolean(kIsRemovableKey, &is_removable)); |
| + EXPECT_TRUE(is_removable); |
| + } |
| +} |
| + |
| } // namespace |
| } // namespace chrome |