OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "storage/browser/fileapi/external_mount_points.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/files/file_path.h" | |
12 #include "base/macros.h" | |
13 #include "storage/browser/fileapi/file_system_url.h" | |
14 #include "storage/common/fileapi/file_system_mount_option.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 #define FPL FILE_PATH_LITERAL | |
18 | |
19 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | |
20 #define DRIVE FPL("C:") | |
21 #else | |
22 #define DRIVE | |
23 #endif | |
24 | |
25 using storage::FileSystemURL; | |
26 | |
27 namespace content { | |
28 | |
29 TEST(ExternalMountPointsTest, AddMountPoint) { | |
30 scoped_refptr<storage::ExternalMountPoints> mount_points( | |
31 storage::ExternalMountPoints::CreateRefCounted()); | |
32 | |
33 struct TestCase { | |
34 // The mount point's name. | |
35 const char* const name; | |
36 // The mount point's path. | |
37 const base::FilePath::CharType* const path; | |
38 // Whether the mount point registration should succeed. | |
39 bool success; | |
40 // Path returned by GetRegisteredPath. NULL if the method is expected to | |
41 // fail. | |
42 const base::FilePath::CharType* const registered_path; | |
43 }; | |
44 | |
45 const TestCase kTestCases[] = { | |
46 // Valid mount point. | |
47 { "test", DRIVE FPL("/foo/test"), true, DRIVE FPL("/foo/test") }, | |
48 // Valid mount point with only one path component. | |
49 { "bbb", DRIVE FPL("/bbb"), true, DRIVE FPL("/bbb") }, | |
50 // Existing mount point path is substring of the mount points path. | |
51 { "test11", DRIVE FPL("/foo/test11"), true, DRIVE FPL("/foo/test11") }, | |
52 // Path substring of an existing path. | |
53 { "test1", DRIVE FPL("/foo/test1"), true, DRIVE FPL("/foo/test1") }, | |
54 // Empty mount point name and path. | |
55 { "", DRIVE FPL(""), false, NULL }, | |
56 // Empty mount point name. | |
57 { "", DRIVE FPL("/ddd"), false, NULL }, | |
58 // Empty mount point path. | |
59 { "empty_path", FPL(""), true, FPL("") }, | |
60 // Name different from path's base name. | |
61 { "not_base_name", DRIVE FPL("/x/y/z"), true, DRIVE FPL("/x/y/z") }, | |
62 // References parent. | |
63 { "invalid", DRIVE FPL("../foo/invalid"), false, NULL }, | |
64 // Relative path. | |
65 { "relative", DRIVE FPL("foo/relative"), false, NULL }, | |
66 // Existing mount point path. | |
67 { "path_exists", DRIVE FPL("/foo/test"), false, NULL }, | |
68 // Mount point with the same name exists. | |
69 { "test", DRIVE FPL("/foo/a/test_name_exists"), false, | |
70 DRIVE FPL("/foo/test") }, | |
71 // Child of an existing mount point. | |
72 { "a1", DRIVE FPL("/foo/test/a"), false, NULL }, | |
73 // Parent of an existing mount point. | |
74 { "foo1", DRIVE FPL("/foo"), false, NULL }, | |
75 // Bit bigger depth. | |
76 { "g", DRIVE FPL("/foo/a/b/c/d/e/f/g"), true, | |
77 DRIVE FPL("/foo/a/b/c/d/e/f/g") }, | |
78 // Sibling mount point (with similar name) exists. | |
79 { "ff", DRIVE FPL("/foo/a/b/c/d/e/ff"), true, | |
80 DRIVE FPL("/foo/a/b/c/d/e/ff") }, | |
81 // Lexicographically last among existing mount points. | |
82 { "yyy", DRIVE FPL("/zzz/yyy"), true, DRIVE FPL("/zzz/yyy") }, | |
83 // Parent of the lexicographically last mount point. | |
84 { "zzz1", DRIVE FPL("/zzz"), false, NULL }, | |
85 // Child of the lexicographically last mount point. | |
86 { "xxx1", DRIVE FPL("/zzz/yyy/xxx"), false, NULL }, | |
87 // Lexicographically first among existing mount points. | |
88 { "b", DRIVE FPL("/a/b"), true, DRIVE FPL("/a/b") }, | |
89 // Parent of lexicographically first mount point. | |
90 { "a2", DRIVE FPL("/a"), false, NULL }, | |
91 // Child of lexicographically last mount point. | |
92 { "c1", DRIVE FPL("/a/b/c"), false, NULL }, | |
93 // Parent to all of the mount points. | |
94 { "root", DRIVE FPL("/"), false, NULL }, | |
95 // Path contains .. component. | |
96 { "funky", DRIVE FPL("/tt/fun/../funky"), false, NULL }, | |
97 // Windows separators. | |
98 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | |
99 { "win", DRIVE FPL("\\try\\separators\\win"), true, | |
100 DRIVE FPL("\\try\\separators\\win") }, | |
101 { "win1", DRIVE FPL("\\try/separators\\win1"), true, | |
102 DRIVE FPL("\\try/separators\\win1") }, | |
103 { "win2", DRIVE FPL("\\try/separators\\win"), false, NULL }, | |
104 #else | |
105 { "win", DRIVE FPL("\\separators\\win"), false, NULL }, | |
106 { "win1", DRIVE FPL("\\try/separators\\win1"), false, NULL }, | |
107 #endif | |
108 // Win separators, but relative path. | |
109 { "win2", DRIVE FPL("try\\separators\\win2"), false, NULL }, | |
110 }; | |
111 | |
112 // Test adding mount points. | |
113 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
114 EXPECT_EQ( | |
115 kTestCases[i].success, | |
116 mount_points->RegisterFileSystem(kTestCases[i].name, | |
117 storage::kFileSystemTypeNativeLocal, | |
118 storage::FileSystemMountOption(), | |
119 base::FilePath(kTestCases[i].path))) | |
120 << "Adding mount point: " << kTestCases[i].name << " with path " | |
121 << kTestCases[i].path; | |
122 } | |
123 | |
124 // Test that final mount point presence state is as expected. | |
125 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
126 base::FilePath found_path; | |
127 EXPECT_EQ(kTestCases[i].registered_path != NULL, | |
128 mount_points->GetRegisteredPath(kTestCases[i].name, &found_path)) | |
129 << "Test case: " << i; | |
130 | |
131 if (kTestCases[i].registered_path) { | |
132 base::FilePath expected_path(kTestCases[i].registered_path); | |
133 EXPECT_EQ(expected_path.NormalizePathSeparators(), found_path); | |
134 } | |
135 } | |
136 } | |
137 | |
138 TEST(ExternalMountPointsTest, GetVirtualPath) { | |
139 scoped_refptr<storage::ExternalMountPoints> mount_points( | |
140 storage::ExternalMountPoints::CreateRefCounted()); | |
141 | |
142 mount_points->RegisterFileSystem("c", | |
143 storage::kFileSystemTypeNativeLocal, | |
144 storage::FileSystemMountOption(), | |
145 base::FilePath(DRIVE FPL("/a/b/c"))); | |
146 // Note that "/a/b/c" < "/a/b/c(1)" < "/a/b/c/". | |
147 mount_points->RegisterFileSystem("c(1)", | |
148 storage::kFileSystemTypeNativeLocal, | |
149 storage::FileSystemMountOption(), | |
150 base::FilePath(DRIVE FPL("/a/b/c(1)"))); | |
151 mount_points->RegisterFileSystem("x", | |
152 storage::kFileSystemTypeNativeLocal, | |
153 storage::FileSystemMountOption(), | |
154 base::FilePath(DRIVE FPL("/z/y/x"))); | |
155 mount_points->RegisterFileSystem("o", | |
156 storage::kFileSystemTypeNativeLocal, | |
157 storage::FileSystemMountOption(), | |
158 base::FilePath(DRIVE FPL("/m/n/o"))); | |
159 // A mount point whose name does not match its path base name. | |
160 mount_points->RegisterFileSystem("mount", | |
161 storage::kFileSystemTypeNativeLocal, | |
162 storage::FileSystemMountOption(), | |
163 base::FilePath(DRIVE FPL("/root/foo"))); | |
164 // A mount point with an empty path. | |
165 mount_points->RegisterFileSystem("empty_path", | |
166 storage::kFileSystemTypeNativeLocal, | |
167 storage::FileSystemMountOption(), | |
168 base::FilePath()); | |
169 | |
170 struct TestCase { | |
171 const base::FilePath::CharType* const local_path; | |
172 bool success; | |
173 const base::FilePath::CharType* const virtual_path; | |
174 }; | |
175 | |
176 const TestCase kTestCases[] = { | |
177 // Empty path. | |
178 { FPL(""), false, FPL("") }, | |
179 // No registered mount point (but is parent to a mount point). | |
180 { DRIVE FPL("/a/b"), false, FPL("") }, | |
181 // No registered mount point (but is parent to a mount point). | |
182 { DRIVE FPL("/z/y"), false, FPL("") }, | |
183 // No registered mount point (but is parent to a mount point). | |
184 { DRIVE FPL("/m/n"), false, FPL("") }, | |
185 // No registered mount point. | |
186 { DRIVE FPL("/foo/mount"), false, FPL("") }, | |
187 // An existing mount point path is substring. | |
188 { DRIVE FPL("/a/b/c1"), false, FPL("") }, | |
189 // No leading /. | |
190 { DRIVE FPL("a/b/c"), false, FPL("") }, | |
191 // Sibling to a root path. | |
192 { DRIVE FPL("/a/b/d/e"), false, FPL("") }, | |
193 // Sibling to a root path. | |
194 { DRIVE FPL("/z/y/v/u"), false, FPL("") }, | |
195 // Sibling to a root path. | |
196 { DRIVE FPL("/m/n/p/q"), false, FPL("") }, | |
197 // Mount point root path. | |
198 { DRIVE FPL("/a/b/c"), true, FPL("c") }, | |
199 // Mount point root path. | |
200 { DRIVE FPL("/z/y/x"), true, FPL("x") }, | |
201 // Mount point root path. | |
202 { DRIVE FPL("/m/n/o"), true, FPL("o") }, | |
203 // Mount point child path. | |
204 { DRIVE FPL("/a/b/c/d/e"), true, FPL("c/d/e") }, | |
205 // Mount point child path. | |
206 { DRIVE FPL("/z/y/x/v/u"), true, FPL("x/v/u") }, | |
207 // Mount point child path. | |
208 { DRIVE FPL("/m/n/o/p/q"), true, FPL("o/p/q") }, | |
209 // Name doesn't match mount point path base name. | |
210 { DRIVE FPL("/root/foo/a/b/c"), true, FPL("mount/a/b/c") }, | |
211 { DRIVE FPL("/root/foo"), true, FPL("mount") }, | |
212 // Mount point contains character whose ASCII code is smaller than file path | |
213 // separator's. | |
214 { DRIVE FPL("/a/b/c(1)/d/e"), true, FPL("c(1)/d/e") }, | |
215 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | |
216 // Path with win separators mixed in. | |
217 { DRIVE FPL("/a\\b\\c/d"), true, FPL("c/d") }, | |
218 #endif | |
219 }; | |
220 | |
221 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
222 // Initialize virtual path with a value. | |
223 base::FilePath virtual_path(DRIVE FPL("/mount")); | |
224 base::FilePath local_path(kTestCases[i].local_path); | |
225 EXPECT_EQ(kTestCases[i].success, | |
226 mount_points->GetVirtualPath(local_path, &virtual_path)) | |
227 << "Resolving " << kTestCases[i].local_path; | |
228 | |
229 // There are no guarantees for |virtual_path| value if |GetVirtualPath| | |
230 // fails. | |
231 if (!kTestCases[i].success) | |
232 continue; | |
233 | |
234 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); | |
235 EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path) | |
236 << "Resolving " << kTestCases[i].local_path; | |
237 } | |
238 } | |
239 | |
240 TEST(ExternalMountPointsTest, HandlesFileSystemMountType) { | |
241 scoped_refptr<storage::ExternalMountPoints> mount_points( | |
242 storage::ExternalMountPoints::CreateRefCounted()); | |
243 | |
244 const GURL test_origin("http://chromium.org"); | |
245 const base::FilePath test_path(FPL("/mount")); | |
246 | |
247 // Should handle External File System. | |
248 EXPECT_TRUE(mount_points->HandlesFileSystemMountType( | |
249 storage::kFileSystemTypeExternal)); | |
250 | |
251 // Shouldn't handle the rest. | |
252 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( | |
253 storage::kFileSystemTypeIsolated)); | |
254 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( | |
255 storage::kFileSystemTypeTemporary)); | |
256 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( | |
257 storage::kFileSystemTypePersistent)); | |
258 EXPECT_FALSE( | |
259 mount_points->HandlesFileSystemMountType(storage::kFileSystemTypeTest)); | |
260 // Not even if it's external subtype. | |
261 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( | |
262 storage::kFileSystemTypeNativeLocal)); | |
263 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( | |
264 storage::kFileSystemTypeRestrictedNativeLocal)); | |
265 EXPECT_FALSE( | |
266 mount_points->HandlesFileSystemMountType(storage::kFileSystemTypeDrive)); | |
267 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( | |
268 storage::kFileSystemTypeSyncable)); | |
269 } | |
270 | |
271 TEST(ExternalMountPointsTest, CreateCrackedFileSystemURL) { | |
272 scoped_refptr<storage::ExternalMountPoints> mount_points( | |
273 storage::ExternalMountPoints::CreateRefCounted()); | |
274 | |
275 const GURL kTestOrigin("http://chromium.org"); | |
276 | |
277 mount_points->RegisterFileSystem("c", | |
278 storage::kFileSystemTypeNativeLocal, | |
279 storage::FileSystemMountOption(), | |
280 base::FilePath(DRIVE FPL("/a/b/c"))); | |
281 mount_points->RegisterFileSystem("c(1)", | |
282 storage::kFileSystemTypeDrive, | |
283 storage::FileSystemMountOption(), | |
284 base::FilePath(DRIVE FPL("/a/b/c(1)"))); | |
285 mount_points->RegisterFileSystem("empty_path", | |
286 storage::kFileSystemTypeSyncable, | |
287 storage::FileSystemMountOption(), | |
288 base::FilePath()); | |
289 mount_points->RegisterFileSystem("mount", | |
290 storage::kFileSystemTypeDrive, | |
291 storage::FileSystemMountOption(), | |
292 base::FilePath(DRIVE FPL("/root"))); | |
293 | |
294 // Try cracking invalid GURL. | |
295 FileSystemURL invalid = mount_points->CrackURL(GURL("http://chromium.og")); | |
296 EXPECT_FALSE(invalid.is_valid()); | |
297 | |
298 // Try cracking isolated path. | |
299 FileSystemURL isolated = mount_points->CreateCrackedFileSystemURL( | |
300 kTestOrigin, storage::kFileSystemTypeIsolated, base::FilePath(FPL("c"))); | |
301 EXPECT_FALSE(isolated.is_valid()); | |
302 | |
303 // Try native local which is not cracked. | |
304 FileSystemURL native_local = mount_points->CreateCrackedFileSystemURL( | |
305 kTestOrigin, | |
306 storage::kFileSystemTypeNativeLocal, | |
307 base::FilePath(FPL("c"))); | |
308 EXPECT_FALSE(native_local.is_valid()); | |
309 | |
310 struct TestCase { | |
311 const base::FilePath::CharType* const path; | |
312 bool expect_valid; | |
313 storage::FileSystemType expect_type; | |
314 const base::FilePath::CharType* const expect_path; | |
315 const char* const expect_fs_id; | |
316 }; | |
317 | |
318 const TestCase kTestCases[] = { | |
319 {FPL("c/d/e"), true, storage::kFileSystemTypeNativeLocal, | |
320 DRIVE FPL("/a/b/c/d/e"), "c"}, | |
321 {FPL("c(1)/d/e"), true, storage::kFileSystemTypeDrive, | |
322 DRIVE FPL("/a/b/c(1)/d/e"), "c(1)"}, | |
323 {FPL("c(1)"), true, storage::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), | |
324 "c(1)"}, | |
325 {FPL("empty_path/a"), true, storage::kFileSystemTypeSyncable, FPL("a"), | |
326 "empty_path"}, | |
327 {FPL("empty_path"), true, storage::kFileSystemTypeSyncable, FPL(""), | |
328 "empty_path"}, | |
329 {FPL("mount/a/b"), true, storage::kFileSystemTypeDrive, | |
330 DRIVE FPL("/root/a/b"), "mount"}, | |
331 {FPL("mount"), true, storage::kFileSystemTypeDrive, DRIVE FPL("/root"), | |
332 "mount"}, | |
333 {FPL("cc"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
334 {FPL(""), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
335 {FPL(".."), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
336 // Absolte paths. | |
337 {FPL("/c/d/e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
338 {FPL("/c(1)/d/e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
339 {FPL("/empty_path"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
340 // PAth references parent. | |
341 {FPL("c/d/../e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
342 {FPL("/empty_path/a/../b"), false, storage::kFileSystemTypeUnknown, FPL(""), | |
343 ""}, | |
344 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | |
345 {FPL("c/d\\e"), true, storage::kFileSystemTypeNativeLocal, | |
346 DRIVE FPL("/a/b/c/d/e"), "c"}, | |
347 {FPL("mount\\a\\b"), true, storage::kFileSystemTypeDrive, | |
348 DRIVE FPL("/root/a/b"), "mount"}, | |
349 #endif | |
350 }; | |
351 | |
352 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
353 FileSystemURL cracked = mount_points->CreateCrackedFileSystemURL( | |
354 kTestOrigin, | |
355 storage::kFileSystemTypeExternal, | |
356 base::FilePath(kTestCases[i].path)); | |
357 | |
358 EXPECT_EQ(kTestCases[i].expect_valid, cracked.is_valid()) | |
359 << "Test case index: " << i; | |
360 | |
361 if (!kTestCases[i].expect_valid) | |
362 continue; | |
363 | |
364 EXPECT_EQ(kTestOrigin, cracked.origin()) | |
365 << "Test case index: " << i; | |
366 EXPECT_EQ(kTestCases[i].expect_type, cracked.type()) | |
367 << "Test case index: " << i; | |
368 EXPECT_EQ(base::FilePath( | |
369 kTestCases[i].expect_path).NormalizePathSeparators(), cracked.path()) | |
370 << "Test case index: " << i; | |
371 EXPECT_EQ(base::FilePath(kTestCases[i].path).NormalizePathSeparators(), | |
372 cracked.virtual_path()) | |
373 << "Test case index: " << i; | |
374 EXPECT_EQ(kTestCases[i].expect_fs_id, cracked.filesystem_id()) | |
375 << "Test case index: " << i; | |
376 EXPECT_EQ(storage::kFileSystemTypeExternal, cracked.mount_type()) | |
377 << "Test case index: " << i; | |
378 } | |
379 } | |
380 | |
381 TEST(ExternalMountPointsTest, CrackVirtualPath) { | |
382 scoped_refptr<storage::ExternalMountPoints> mount_points( | |
383 storage::ExternalMountPoints::CreateRefCounted()); | |
384 | |
385 const GURL kTestOrigin("http://chromium.org"); | |
386 | |
387 mount_points->RegisterFileSystem("c", | |
388 storage::kFileSystemTypeNativeLocal, | |
389 storage::FileSystemMountOption(), | |
390 base::FilePath(DRIVE FPL("/a/b/c"))); | |
391 mount_points->RegisterFileSystem("c(1)", | |
392 storage::kFileSystemTypeDrive, | |
393 storage::FileSystemMountOption(), | |
394 base::FilePath(DRIVE FPL("/a/b/c(1)"))); | |
395 mount_points->RegisterFileSystem("empty_path", | |
396 storage::kFileSystemTypeSyncable, | |
397 storage::FileSystemMountOption(), | |
398 base::FilePath()); | |
399 mount_points->RegisterFileSystem("mount", | |
400 storage::kFileSystemTypeDrive, | |
401 storage::FileSystemMountOption(), | |
402 base::FilePath(DRIVE FPL("/root"))); | |
403 | |
404 struct TestCase { | |
405 const base::FilePath::CharType* const path; | |
406 bool expect_valid; | |
407 storage::FileSystemType expect_type; | |
408 const base::FilePath::CharType* const expect_path; | |
409 const char* const expect_name; | |
410 }; | |
411 | |
412 const TestCase kTestCases[] = { | |
413 {FPL("c/d/e"), true, storage::kFileSystemTypeNativeLocal, | |
414 DRIVE FPL("/a/b/c/d/e"), "c"}, | |
415 {FPL("c(1)/d/e"), true, storage::kFileSystemTypeDrive, | |
416 DRIVE FPL("/a/b/c(1)/d/e"), "c(1)"}, | |
417 {FPL("c(1)"), true, storage::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), | |
418 "c(1)"}, | |
419 {FPL("empty_path/a"), true, storage::kFileSystemTypeSyncable, FPL("a"), | |
420 "empty_path"}, | |
421 {FPL("empty_path"), true, storage::kFileSystemTypeSyncable, FPL(""), | |
422 "empty_path"}, | |
423 {FPL("mount/a/b"), true, storage::kFileSystemTypeDrive, | |
424 DRIVE FPL("/root/a/b"), "mount"}, | |
425 {FPL("mount"), true, storage::kFileSystemTypeDrive, DRIVE FPL("/root"), | |
426 "mount"}, | |
427 {FPL("cc"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
428 {FPL(""), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
429 {FPL(".."), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
430 // Absolte paths. | |
431 {FPL("/c/d/e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
432 {FPL("/c(1)/d/e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
433 {FPL("/empty_path"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
434 // PAth references parent. | |
435 {FPL("c/d/../e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""}, | |
436 {FPL("/empty_path/a/../b"), false, storage::kFileSystemTypeUnknown, FPL(""), | |
437 ""}, | |
438 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | |
439 {FPL("c/d\\e"), true, storage::kFileSystemTypeNativeLocal, | |
440 DRIVE FPL("/a/b/c/d/e"), "c"}, | |
441 {FPL("mount\\a\\b"), true, storage::kFileSystemTypeDrive, | |
442 DRIVE FPL("/root/a/b"), "mount"}, | |
443 #endif | |
444 }; | |
445 | |
446 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
447 std::string cracked_name; | |
448 storage::FileSystemType cracked_type; | |
449 std::string cracked_id; | |
450 base::FilePath cracked_path; | |
451 storage::FileSystemMountOption cracked_option; | |
452 EXPECT_EQ(kTestCases[i].expect_valid, | |
453 mount_points->CrackVirtualPath(base::FilePath(kTestCases[i].path), | |
454 &cracked_name, &cracked_type, &cracked_id, &cracked_path, | |
455 &cracked_option)) | |
456 << "Test case index: " << i; | |
457 | |
458 if (!kTestCases[i].expect_valid) | |
459 continue; | |
460 | |
461 EXPECT_EQ(kTestCases[i].expect_type, cracked_type) | |
462 << "Test case index: " << i; | |
463 EXPECT_EQ(base::FilePath( | |
464 kTestCases[i].expect_path).NormalizePathSeparators(), cracked_path) | |
465 << "Test case index: " << i; | |
466 EXPECT_EQ(kTestCases[i].expect_name, cracked_name) | |
467 << "Test case index: " << i; | |
468 // As of now we don't mount other filesystems with non-empty filesystem_id | |
469 // onto external mount points. | |
470 EXPECT_TRUE(cracked_id.empty()) << "Test case index: " << i; | |
471 } | |
472 } | |
473 | |
474 TEST(ExternalMountPointsTest, MountOption) { | |
475 scoped_refptr<storage::ExternalMountPoints> mount_points( | |
476 storage::ExternalMountPoints::CreateRefCounted()); | |
477 | |
478 mount_points->RegisterFileSystem( | |
479 "nosync", storage::kFileSystemTypeNativeLocal, | |
480 storage::FileSystemMountOption( | |
481 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION), | |
482 base::FilePath(DRIVE FPL("/nosync"))); | |
483 mount_points->RegisterFileSystem( | |
484 "sync", storage::kFileSystemTypeNativeLocal, | |
485 storage::FileSystemMountOption(storage::FlushPolicy::FLUSH_ON_COMPLETION), | |
486 base::FilePath(DRIVE FPL("/sync"))); | |
487 | |
488 std::string name; | |
489 storage::FileSystemType type; | |
490 std::string cracked_id; | |
491 storage::FileSystemMountOption option; | |
492 base::FilePath path; | |
493 EXPECT_TRUE(mount_points->CrackVirtualPath( | |
494 base::FilePath(FPL("nosync/file")), &name, &type, &cracked_id, &path, | |
495 &option)); | |
496 EXPECT_EQ(storage::FlushPolicy::NO_FLUSH_ON_COMPLETION, | |
497 option.flush_policy()); | |
498 EXPECT_TRUE(mount_points->CrackVirtualPath( | |
499 base::FilePath(FPL("sync/file")), &name, &type, &cracked_id, &path, | |
500 &option)); | |
501 EXPECT_EQ(storage::FlushPolicy::FLUSH_ON_COMPLETION, option.flush_policy()); | |
502 } | |
503 | |
504 } // namespace content | |
505 | |
OLD | NEW |