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

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

Issue 185393012: Change media galleries to external file system type to add toURL support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 9 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 // 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/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 using storage_monitor::StorageInfo; 58 using storage_monitor::StorageInfo;
59 using storage_monitor::StorageMonitor; 59 using storage_monitor::StorageMonitor;
60 using storage_monitor::TestStorageMonitor; 60 using storage_monitor::TestStorageMonitor;
61 61
62 // Not anonymous so it can be friends with MediaFileSystemRegistry. 62 // Not anonymous so it can be friends with MediaFileSystemRegistry.
63 class TestMediaFileSystemContext : public MediaFileSystemContext { 63 class TestMediaFileSystemContext : public MediaFileSystemContext {
64 public: 64 public:
65 struct FSInfo { 65 struct FSInfo {
66 FSInfo() {} 66 FSInfo() {}
67 FSInfo(const std::string& device_id, const base::FilePath& path, 67 FSInfo(const std::string& device_id, const base::FilePath& path,
68 const std::string& fsid); 68 const std::string& fs_name);
69 69
70 bool operator<(const FSInfo& other) const; 70 bool operator<(const FSInfo& other) const;
71 71
72 std::string device_id; 72 std::string device_id;
73 base::FilePath path; 73 base::FilePath path;
74 std::string fsid; 74 std::string fs_name;
75 }; 75 };
76 76
77 explicit TestMediaFileSystemContext(MediaFileSystemRegistry* registry); 77 explicit TestMediaFileSystemContext(MediaFileSystemRegistry* registry);
78 virtual ~TestMediaFileSystemContext() {} 78 virtual ~TestMediaFileSystemContext() {}
79 79
80 // MediaFileSystemContext implementation. 80 // MediaFileSystemContext implementation.
81 virtual std::string RegisterFileSystem( 81 virtual bool RegisterFileSystem(const std::string& device_id,
82 const std::string& device_id, const base::FilePath& path) OVERRIDE; 82 const std::string& fs_name,
83 const base::FilePath& path) OVERRIDE;
83 84
84 virtual void RevokeFileSystem(const std::string& fsid) OVERRIDE; 85 virtual void RevokeFileSystem(const std::string& fs_name) OVERRIDE;
85 86
86 base::FilePath GetPathForId(const std::string& fsid) const; 87 virtual base::FilePath GetRegisteredPath(
88 const std::string& fs_name) const OVERRIDE;
87 89
88 MediaFileSystemRegistry* registry() { return registry_; } 90 MediaFileSystemRegistry* registry() { return registry_; }
89 91
90 private: 92 private:
91 std::string AddFSEntry(const std::string& device_id, 93 void AddFSEntry(const std::string& device_id,
92 const base::FilePath& path); 94 const base::FilePath& path,
95 const std::string& fs_name);
93 96
94 MediaFileSystemRegistry* registry_; 97 MediaFileSystemRegistry* registry_;
95 98
96 // A counter used to construct mock FSIDs.
97 int fsid_;
98
99 // The currently allocated mock file systems. 99 // The currently allocated mock file systems.
100 std::map<std::string /*fsid*/, FSInfo> file_systems_by_id_; 100 std::map<std::string /*fs_name*/, FSInfo> file_systems_by_name_;
101 }; 101 };
102 102
103 TestMediaFileSystemContext::FSInfo::FSInfo(const std::string& device_id, 103 TestMediaFileSystemContext::FSInfo::FSInfo(const std::string& device_id,
104 const base::FilePath& path, 104 const base::FilePath& path,
105 const std::string& fsid) 105 const std::string& fs_name)
106 : device_id(device_id), 106 : device_id(device_id),
107 path(path), 107 path(path),
108 fsid(fsid) { 108 fs_name(fs_name) {
109 } 109 }
110 110
111 bool TestMediaFileSystemContext::FSInfo::operator<(const FSInfo& other) const { 111 bool TestMediaFileSystemContext::FSInfo::operator<(const FSInfo& other) const {
112 if (device_id != other.device_id) 112 if (device_id != other.device_id)
113 return device_id < other.device_id; 113 return device_id < other.device_id;
114 if (path.value() != other.path.value()) 114 if (path.value() != other.path.value())
115 return path.value() < other.path.value(); 115 return path.value() < other.path.value();
116 return fsid < other.fsid; 116 return fs_name < other.fs_name;
117 } 117 }
118 118
119 TestMediaFileSystemContext::TestMediaFileSystemContext( 119 TestMediaFileSystemContext::TestMediaFileSystemContext(
120 MediaFileSystemRegistry* registry) 120 MediaFileSystemRegistry* registry)
121 : registry_(registry), 121 : registry_(registry) {
122 fsid_(0) {
123 registry_->file_system_context_.reset(this); 122 registry_->file_system_context_.reset(this);
124 } 123 }
125 124
126 std::string TestMediaFileSystemContext::RegisterFileSystem( 125 bool TestMediaFileSystemContext::RegisterFileSystem(
127 const std::string& device_id, const base::FilePath& path) { 126 const std::string& device_id,
128 std::string fsid = AddFSEntry(device_id, path); 127 const std::string& fs_name,
129 return fsid; 128 const base::FilePath& path) {
129 AddFSEntry(device_id, path, fs_name);
130 return true;
130 } 131 }
131 132
132 void TestMediaFileSystemContext::RevokeFileSystem(const std::string& fsid) { 133 void TestMediaFileSystemContext::RevokeFileSystem(const std::string& fs_name) {
133 if (!ContainsKey(file_systems_by_id_, fsid)) 134 if (!ContainsKey(file_systems_by_name_, fs_name))
134 return; 135 return;
135 EXPECT_EQ(1U, file_systems_by_id_.erase(fsid)); 136 EXPECT_EQ(1U, file_systems_by_name_.erase(fs_name));
136 } 137 }
137 138
138 base::FilePath TestMediaFileSystemContext::GetPathForId( 139 base::FilePath TestMediaFileSystemContext::GetRegisteredPath(
139 const std::string& fsid) const { 140 const std::string& fs_name) const {
140 std::map<std::string /*fsid*/, FSInfo>::const_iterator it = 141 std::map<std::string /*fs_name*/, FSInfo>::const_iterator it =
141 file_systems_by_id_.find(fsid); 142 file_systems_by_name_.find(fs_name);
142 if (it == file_systems_by_id_.end()) 143 if (it == file_systems_by_name_.end())
143 return base::FilePath(); 144 return base::FilePath();
144 return it->second.path; 145 return it->second.path;
145 } 146 }
146 147
147 std::string TestMediaFileSystemContext::AddFSEntry(const std::string& device_id, 148 void TestMediaFileSystemContext::AddFSEntry(const std::string& device_id,
148 const base::FilePath& path) { 149 const base::FilePath& path,
150 const std::string& fs_name) {
149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
150 DCHECK(path.IsAbsolute()); 152 DCHECK(path.IsAbsolute());
151 DCHECK(!path.ReferencesParent()); 153 DCHECK(!path.ReferencesParent());
152 154
153 std::string fsid = base::StringPrintf("FSID:%d", ++fsid_); 155 FSInfo info(device_id, path, fs_name);
154 FSInfo info(device_id, path, fsid); 156 file_systems_by_name_[fs_name] = info;
155 file_systems_by_id_[fsid] = info;
156 return fsid;
157 } 157 }
158 158
159 namespace { 159 namespace {
160 160
161 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> FSInfoMap; 161 typedef std::map<MediaGalleryPrefId, MediaFileSystemInfo> FSInfoMap;
162 162
163 void GetGalleryInfoCallback( 163 void GetGalleryInfoCallback(
164 FSInfoMap* results, 164 FSInfoMap* results,
165 const std::vector<MediaFileSystemInfo>& file_systems) { 165 const std::vector<MediaFileSystemInfo>& file_systems) {
166 for (size_t i = 0; i < file_systems.size(); ++i) { 166 for (size_t i = 0; i < file_systems.size(); ++i) {
(...skipping 10 matching lines...) Expand all
177 EXPECT_EQ(path, info.path); 177 EXPECT_EQ(path, info.path);
178 EXPECT_EQ(removable, info.removable); 178 EXPECT_EQ(removable, info.removable);
179 EXPECT_EQ(media_device, info.media_device); 179 EXPECT_EQ(media_device, info.media_device);
180 EXPECT_NE(0UL, info.pref_id); 180 EXPECT_NE(0UL, info.pref_id);
181 181
182 if (removable) 182 if (removable)
183 EXPECT_NE(0UL, info.transient_device_id.size()); 183 EXPECT_NE(0UL, info.transient_device_id.size());
184 else 184 else
185 EXPECT_EQ(0UL, info.transient_device_id.size()); 185 EXPECT_EQ(0UL, info.transient_device_id.size());
186 186
187 base::FilePath fsid_path = fs_context->GetPathForId(info.fsid); 187 base::FilePath fsid_path = fs_context->GetRegisteredPath(info.fsid);
188 EXPECT_EQ(path, fsid_path); 188 EXPECT_EQ(path, fsid_path);
189 } 189 }
190 190
191 class MockProfileSharedRenderProcessHostFactory 191 class MockProfileSharedRenderProcessHostFactory
192 : public content::RenderProcessHostFactory { 192 : public content::RenderProcessHostFactory {
193 public: 193 public:
194 MockProfileSharedRenderProcessHostFactory() {} 194 MockProfileSharedRenderProcessHostFactory() {}
195 virtual ~MockProfileSharedRenderProcessHostFactory(); 195 virtual ~MockProfileSharedRenderProcessHostFactory();
196 196
197 // RPH created with this factory are owned by it. If the RPH is destroyed 197 // RPH created with this factory are owned by it. If the RPH is destroyed
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 empty_dir()); 1060 empty_dir());
1061 ProfileState* profile_state = GetProfileState(0); 1061 ProfileState* profile_state = GetProfileState(0);
1062 SetGalleryPermission(profile_state, 1062 SetGalleryPermission(profile_state,
1063 profile_state->regular_permission_extension(), 1063 profile_state->regular_permission_extension(),
1064 device_id, 1064 device_id,
1065 true /*has access*/); 1065 true /*has access*/);
1066 1066
1067 FSInfoMap fs_info = profile_state->GetGalleriesInfo( 1067 FSInfoMap fs_info = profile_state->GetGalleriesInfo(
1068 profile_state->regular_permission_extension()); 1068 profile_state->regular_permission_extension());
1069 ASSERT_EQ(1U, fs_info.size()); 1069 ASSERT_EQ(1U, fs_info.size());
1070 EXPECT_FALSE(test_file_system_context()->GetPathForId( 1070 EXPECT_FALSE(test_file_system_context()->GetRegisteredPath(
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()->GetPathForId( 1078 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath(
1079 fs_info.begin()->second.fsid).empty()); 1079 fs_info.begin()->second.fsid).empty());
1080 } 1080 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698