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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/mount_path_util_unittest.cc

Issue 624903002: [fsp] Group arguments for mounting into a struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a bug. Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 5 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 base::FilePath::FromUTF8Unsafe("provided/hello-world/test.txt"))); 121 base::FilePath::FromUTF8Unsafe("provided/hello-world/test.txt")));
122 EXPECT_FALSE(IsFileSystemProviderLocalPath( 122 EXPECT_FALSE(IsFileSystemProviderLocalPath(
123 base::FilePath::FromUTF8Unsafe("/provided"))); 123 base::FilePath::FromUTF8Unsafe("/provided")));
124 EXPECT_FALSE( 124 EXPECT_FALSE(
125 IsFileSystemProviderLocalPath(base::FilePath::FromUTF8Unsafe("/"))); 125 IsFileSystemProviderLocalPath(base::FilePath::FromUTF8Unsafe("/")));
126 EXPECT_FALSE(IsFileSystemProviderLocalPath(base::FilePath())); 126 EXPECT_FALSE(IsFileSystemProviderLocalPath(base::FilePath()));
127 } 127 }
128 128
129 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { 129 TEST_F(FileSystemProviderMountPathUtilTest, Parser) {
130 const bool result = file_system_provider_service_->MountFileSystem( 130 const bool result = file_system_provider_service_->MountFileSystem(
131 kExtensionId, 131 kExtensionId, MountOptions(kFileSystemId, kDisplayName));
132 kFileSystemId,
133 kDisplayName,
134 false /* writable */,
135 false /* supports_notify_tag */);
136 ASSERT_TRUE(result); 132 ASSERT_TRUE(result);
137 const ProvidedFileSystemInfo file_system_info = 133 const ProvidedFileSystemInfo file_system_info =
138 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, 134 file_system_provider_service_->GetProvidedFileSystem(kExtensionId,
139 kFileSystemId) 135 kFileSystemId)
140 ->GetFileSystemInfo(); 136 ->GetFileSystemInfo();
141 137
142 const base::FilePath kFilePath = 138 const base::FilePath kFilePath =
143 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); 139 base::FilePath::FromUTF8Unsafe("/hello/world.txt");
144 const storage::FileSystemURL url = 140 const storage::FileSystemURL url =
145 CreateFileSystemURL(profile_, file_system_info, kFilePath); 141 CreateFileSystemURL(profile_, file_system_info, kFilePath);
146 EXPECT_TRUE(url.is_valid()); 142 EXPECT_TRUE(url.is_valid());
147 143
148 FileSystemURLParser parser(url); 144 FileSystemURLParser parser(url);
149 EXPECT_TRUE(parser.Parse()); 145 EXPECT_TRUE(parser.Parse());
150 146
151 ProvidedFileSystemInterface* file_system = parser.file_system(); 147 ProvidedFileSystemInterface* file_system = parser.file_system();
152 ASSERT_TRUE(file_system); 148 ASSERT_TRUE(file_system);
153 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); 149 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id());
154 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); 150 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe());
155 } 151 }
156 152
157 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { 153 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) {
158 const bool result = file_system_provider_service_->MountFileSystem( 154 const bool result = file_system_provider_service_->MountFileSystem(
159 kExtensionId, 155 kExtensionId, MountOptions(kFileSystemId, kDisplayName));
160 kFileSystemId,
161 kDisplayName,
162 false /* writable */,
163 false /* supports_notify_tag */);
164 ASSERT_TRUE(result); 156 ASSERT_TRUE(result);
165 const ProvidedFileSystemInfo file_system_info = 157 const ProvidedFileSystemInfo file_system_info =
166 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, 158 file_system_provider_service_->GetProvidedFileSystem(kExtensionId,
167 kFileSystemId) 159 kFileSystemId)
168 ->GetFileSystemInfo(); 160 ->GetFileSystemInfo();
169 161
170 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); 162 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/");
171 const storage::FileSystemURL url = 163 const storage::FileSystemURL url =
172 CreateFileSystemURL(profile_, file_system_info, kFilePath); 164 CreateFileSystemURL(profile_, file_system_info, kFilePath);
173 EXPECT_TRUE(url.is_valid()); 165 EXPECT_TRUE(url.is_valid());
174 166
175 FileSystemURLParser parser(url); 167 FileSystemURLParser parser(url);
176 EXPECT_TRUE(parser.Parse()); 168 EXPECT_TRUE(parser.Parse());
177 169
178 ProvidedFileSystemInterface* file_system = parser.file_system(); 170 ProvidedFileSystemInterface* file_system = parser.file_system();
179 ASSERT_TRUE(file_system); 171 ASSERT_TRUE(file_system);
180 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); 172 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id());
181 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); 173 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe());
182 } 174 }
183 175
184 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { 176 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) {
185 const ProvidedFileSystemInfo file_system_info( 177 const ProvidedFileSystemInfo file_system_info(
186 kExtensionId, 178 kExtensionId,
187 kFileSystemId, 179 MountOptions(kFileSystemId, kDisplayName),
188 kDisplayName,
189 false /* writable */,
190 false /* supports_notify_tag */,
191 GetMountPath(profile_, kExtensionId, kFileSystemId)); 180 GetMountPath(profile_, kExtensionId, kFileSystemId));
192 181
193 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); 182 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello");
194 const storage::FileSystemURL url = 183 const storage::FileSystemURL url =
195 CreateFileSystemURL(profile_, file_system_info, kFilePath); 184 CreateFileSystemURL(profile_, file_system_info, kFilePath);
196 // It is impossible to create a cracked URL for a mount point which doesn't 185 // It is impossible to create a cracked URL for a mount point which doesn't
197 // exist, therefore is will always be invalid, and empty. 186 // exist, therefore is will always be invalid, and empty.
198 EXPECT_FALSE(url.is_valid()); 187 EXPECT_FALSE(url.is_valid());
199 188
200 FileSystemURLParser parser(url); 189 FileSystemURLParser parser(url);
201 EXPECT_FALSE(parser.Parse()); 190 EXPECT_FALSE(parser.Parse());
202 } 191 }
203 192
204 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { 193 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) {
205 const bool result = file_system_provider_service_->MountFileSystem( 194 const bool result = file_system_provider_service_->MountFileSystem(
206 kExtensionId, 195 kExtensionId, MountOptions(kFileSystemId, kDisplayName));
207 kFileSystemId,
208 kDisplayName,
209 false /* writable */,
210 false /* supports_notify_tag */);
211 ASSERT_TRUE(result); 196 ASSERT_TRUE(result);
212 const ProvidedFileSystemInfo file_system_info = 197 const ProvidedFileSystemInfo file_system_info =
213 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, 198 file_system_provider_service_->GetProvidedFileSystem(kExtensionId,
214 kFileSystemId) 199 kFileSystemId)
215 ->GetFileSystemInfo(); 200 ->GetFileSystemInfo();
216 201
217 const base::FilePath kFilePath = 202 const base::FilePath kFilePath =
218 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); 203 base::FilePath::FromUTF8Unsafe("/hello/world.txt");
219 const storage::FileSystemURL url = 204 const storage::FileSystemURL url =
220 CreateFileSystemURL(profile_, file_system_info, kFilePath); 205 CreateFileSystemURL(profile_, file_system_info, kFilePath);
(...skipping 25 matching lines...) Expand all
246 EXPECT_TRUE(parser.Parse()); 231 EXPECT_TRUE(parser.Parse());
247 232
248 ProvidedFileSystemInterface* file_system = parser.file_system(); 233 ProvidedFileSystemInterface* file_system = parser.file_system();
249 ASSERT_TRUE(file_system); 234 ASSERT_TRUE(file_system);
250 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); 235 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id());
251 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); 236 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe());
252 } 237 }
253 238
254 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) { 239 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) {
255 const bool result = file_system_provider_service_->MountFileSystem( 240 const bool result = file_system_provider_service_->MountFileSystem(
256 kExtensionId, 241 kExtensionId, MountOptions(kFileSystemId, kDisplayName));
257 kFileSystemId,
258 kDisplayName,
259 false /* writable */,
260 false /* supports_notify_tag */);
261 ASSERT_TRUE(result); 242 ASSERT_TRUE(result);
262 const ProvidedFileSystemInfo file_system_info = 243 const ProvidedFileSystemInfo file_system_info =
263 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, 244 file_system_provider_service_->GetProvidedFileSystem(kExtensionId,
264 kFileSystemId) 245 kFileSystemId)
265 ->GetFileSystemInfo(); 246 ->GetFileSystemInfo();
266 247
267 const base::FilePath kFilePath = 248 const base::FilePath kFilePath =
268 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); 249 base::FilePath::FromUTF8Unsafe("/hello/world.txt");
269 const base::FilePath kLocalFilePath = file_system_info.mount_path().Append( 250 const base::FilePath kLocalFilePath = file_system_info.mount_path().Append(
270 base::FilePath(kFilePath.value().substr(1))); 251 base::FilePath(kFilePath.value().substr(1)));
271 252
272 LOG(ERROR) << kLocalFilePath.value(); 253 LOG(ERROR) << kLocalFilePath.value();
273 LocalPathParser parser(profile_, kLocalFilePath); 254 LocalPathParser parser(profile_, kLocalFilePath);
274 EXPECT_TRUE(parser.Parse()); 255 EXPECT_TRUE(parser.Parse());
275 256
276 ProvidedFileSystemInterface* file_system = parser.file_system(); 257 ProvidedFileSystemInterface* file_system = parser.file_system();
277 ASSERT_TRUE(file_system); 258 ASSERT_TRUE(file_system);
278 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); 259 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id());
279 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); 260 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe());
280 } 261 }
281 262
282 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser_RootPath) { 263 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser_RootPath) {
283 const bool result = file_system_provider_service_->MountFileSystem( 264 const bool result = file_system_provider_service_->MountFileSystem(
284 kExtensionId, 265 kExtensionId, MountOptions(kFileSystemId, kDisplayName));
285 kFileSystemId,
286 kDisplayName,
287 false /* writable */,
288 false /* supports_notify_tag */);
289 ASSERT_TRUE(result); 266 ASSERT_TRUE(result);
290 const ProvidedFileSystemInfo file_system_info = 267 const ProvidedFileSystemInfo file_system_info =
291 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, 268 file_system_provider_service_->GetProvidedFileSystem(kExtensionId,
292 kFileSystemId) 269 kFileSystemId)
293 ->GetFileSystemInfo(); 270 ->GetFileSystemInfo();
294 271
295 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); 272 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/");
296 const base::FilePath kLocalFilePath = file_system_info.mount_path(); 273 const base::FilePath kLocalFilePath = file_system_info.mount_path();
297 274
298 LocalPathParser parser(profile_, kLocalFilePath); 275 LocalPathParser parser(profile_, kLocalFilePath);
(...skipping 23 matching lines...) Expand all
322 const base::FilePath kFilePath = 299 const base::FilePath kFilePath =
323 base::FilePath::FromUTF8Unsafe("provided/hello/world"); 300 base::FilePath::FromUTF8Unsafe("provided/hello/world");
324 LocalPathParser parser(profile_, kFilePath); 301 LocalPathParser parser(profile_, kFilePath);
325 EXPECT_FALSE(parser.Parse()); 302 EXPECT_FALSE(parser.Parse());
326 } 303 }
327 } 304 }
328 305
329 } // namespace util 306 } // namespace util
330 } // namespace file_system_provider 307 } // namespace file_system_provider
331 } // namespace chromeos 308 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698