| 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 "chrome/browser/media_galleries/media_file_system_registry.h" | 7 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 bool TestMediaFileSystemContext::RegisterFileSystem( | 127 bool TestMediaFileSystemContext::RegisterFileSystem( |
| 128 const std::string& device_id, | 128 const std::string& device_id, |
| 129 const std::string& fs_name, | 129 const std::string& fs_name, |
| 130 const base::FilePath& path) { | 130 const base::FilePath& path) { |
| 131 AddFSEntry(device_id, path, fs_name); | 131 AddFSEntry(device_id, path, fs_name); |
| 132 return true; | 132 return true; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void TestMediaFileSystemContext::RevokeFileSystem(const std::string& fs_name) { | 135 void TestMediaFileSystemContext::RevokeFileSystem(const std::string& fs_name) { |
| 136 if (!ContainsKey(file_systems_by_name_, fs_name)) | 136 if (!base::ContainsKey(file_systems_by_name_, fs_name)) |
| 137 return; | 137 return; |
| 138 EXPECT_EQ(1U, file_systems_by_name_.erase(fs_name)); | 138 EXPECT_EQ(1U, file_systems_by_name_.erase(fs_name)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 base::FilePath TestMediaFileSystemContext::GetRegisteredPath( | 141 base::FilePath TestMediaFileSystemContext::GetRegisteredPath( |
| 142 const std::string& fs_name) const { | 142 const std::string& fs_name) const { |
| 143 std::map<std::string /*fs_name*/, FSInfo>::const_iterator it = | 143 std::map<std::string /*fs_name*/, FSInfo>::const_iterator it = |
| 144 file_systems_by_name_.find(fs_name); | 144 file_systems_by_name_.find(fs_name); |
| 145 if (it == file_systems_by_name_.end()) | 145 if (it == file_systems_by_name_.end()) |
| 146 return base::FilePath(); | 146 return base::FilePath(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 159 } | 159 } |
| 160 | 160 |
| 161 namespace { | 161 namespace { |
| 162 | 162 |
| 163 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> FSInfoMap; | 163 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> FSInfoMap; |
| 164 | 164 |
| 165 void GetGalleryInfoCallback( | 165 void GetGalleryInfoCallback( |
| 166 FSInfoMap* results, | 166 FSInfoMap* results, |
| 167 const std::vector<MediaFileSystemInfo>& file_systems) { | 167 const std::vector<MediaFileSystemInfo>& file_systems) { |
| 168 for (size_t i = 0; i < file_systems.size(); ++i) { | 168 for (size_t i = 0; i < file_systems.size(); ++i) { |
| 169 ASSERT_FALSE(ContainsKey(*results, file_systems[i].pref_id)); | 169 ASSERT_FALSE(base::ContainsKey(*results, file_systems[i].pref_id)); |
| 170 (*results)[file_systems[i].pref_id] = file_systems[i]; | 170 (*results)[file_systems[i].pref_id] = file_systems[i]; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 void CheckGalleryInfo(const MediaFileSystemInfo& info, | 174 void CheckGalleryInfo(const MediaFileSystemInfo& info, |
| 175 TestMediaFileSystemContext* fs_context, | 175 TestMediaFileSystemContext* fs_context, |
| 176 const base::FilePath& path, | 176 const base::FilePath& path, |
| 177 bool removable, | 177 bool removable, |
| 178 bool media_device) { | 178 bool media_device) { |
| 179 EXPECT_EQ(path, info.path); | 179 EXPECT_EQ(path, info.path); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 CHECK_NE(a.name, b.name); // Name must be unique. | 390 CHECK_NE(a.name, b.name); // Name must be unique. |
| 391 return a.name < b.name; | 391 return a.name < b.name; |
| 392 } | 392 } |
| 393 | 393 |
| 394 /////////////////////////////////////////////// | 394 /////////////////////////////////////////////// |
| 395 // MockProfileSharedRenderProcessHostFactory // | 395 // MockProfileSharedRenderProcessHostFactory // |
| 396 /////////////////////////////////////////////// | 396 /////////////////////////////////////////////// |
| 397 | 397 |
| 398 MockProfileSharedRenderProcessHostFactory:: | 398 MockProfileSharedRenderProcessHostFactory:: |
| 399 ~MockProfileSharedRenderProcessHostFactory() { | 399 ~MockProfileSharedRenderProcessHostFactory() { |
| 400 STLDeleteValues(&rph_map_); | 400 base::STLDeleteValues(&rph_map_); |
| 401 } | 401 } |
| 402 | 402 |
| 403 content::MockRenderProcessHost* | 403 content::MockRenderProcessHost* |
| 404 MockProfileSharedRenderProcessHostFactory::ReleaseRPH( | 404 MockProfileSharedRenderProcessHostFactory::ReleaseRPH( |
| 405 content::BrowserContext* browser_context) { | 405 content::BrowserContext* browser_context) { |
| 406 ProfileRPHMap::iterator existing = rph_map_.find(browser_context); | 406 ProfileRPHMap::iterator existing = rph_map_.find(browser_context); |
| 407 if (existing == rph_map_.end()) | 407 if (existing == rph_map_.end()) |
| 408 return NULL; | 408 return NULL; |
| 409 content::MockRenderProcessHost* result = existing->second; | 409 content::MockRenderProcessHost* result = existing->second; |
| 410 rph_map_.erase(existing); | 410 rph_map_.erase(existing); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 bool media_device) { | 711 bool media_device) { |
| 712 // Get new galleries. | 712 // Get new galleries. |
| 713 FSInfoMap new_galleries_info = profile_state->GetGalleriesInfo( | 713 FSInfoMap new_galleries_info = profile_state->GetGalleriesInfo( |
| 714 profile_state->all_permission_extension()); | 714 profile_state->all_permission_extension()); |
| 715 ASSERT_EQ(galleries_info.size() + 1U, new_galleries_info.size()); | 715 ASSERT_EQ(galleries_info.size() + 1U, new_galleries_info.size()); |
| 716 | 716 |
| 717 bool found_new = false; | 717 bool found_new = false; |
| 718 for (FSInfoMap::const_iterator it = new_galleries_info.begin(); | 718 for (FSInfoMap::const_iterator it = new_galleries_info.begin(); |
| 719 it != new_galleries_info.end(); | 719 it != new_galleries_info.end(); |
| 720 ++it) { | 720 ++it) { |
| 721 if (ContainsKey(galleries_info, it->first)) | 721 if (base::ContainsKey(galleries_info, it->first)) |
| 722 continue; | 722 continue; |
| 723 | 723 |
| 724 ASSERT_FALSE(found_new); | 724 ASSERT_FALSE(found_new); |
| 725 CheckGalleryInfo(it->second, test_file_system_context_, location, | 725 CheckGalleryInfo(it->second, test_file_system_context_, location, |
| 726 removable, media_device); | 726 removable, media_device); |
| 727 found_new = true; | 727 found_new = true; |
| 728 } | 728 } |
| 729 ASSERT_TRUE(found_new); | 729 ASSERT_TRUE(found_new); |
| 730 } | 730 } |
| 731 | 731 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 fs_info.begin()->second.fsid).empty()); | 1071 fs_info.begin()->second.fsid).empty()); |
| 1072 | 1072 |
| 1073 // Revoke permission and ensure that the file system is revoked. | 1073 // Revoke permission and ensure that the file system is revoked. |
| 1074 SetGalleryPermission(profile_state, | 1074 SetGalleryPermission(profile_state, |
| 1075 profile_state->regular_permission_extension(), | 1075 profile_state->regular_permission_extension(), |
| 1076 device_id, | 1076 device_id, |
| 1077 false /*has access*/); | 1077 false /*has access*/); |
| 1078 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath( | 1078 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath( |
| 1079 fs_info.begin()->second.fsid).empty()); | 1079 fs_info.begin()->second.fsid).empty()); |
| 1080 } | 1080 } |
| OLD | NEW |