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

Side by Side Diff: content/browser/fileapi/external_mount_points_unittest.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 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 "webkit/browser/fileapi/external_mount_points.h" 5 #include "storage/browser/fileapi/external_mount_points.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/browser/fileapi/file_system_url.h" 11 #include "storage/browser/fileapi/file_system_url.h"
12 12
13 #define FPL FILE_PATH_LITERAL 13 #define FPL FILE_PATH_LITERAL
14 14
15 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 15 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
16 #define DRIVE FPL("C:") 16 #define DRIVE FPL("C:")
17 #else 17 #else
18 #define DRIVE 18 #define DRIVE
19 #endif 19 #endif
20 20
21 using fileapi::FileSystemURL; 21 using storage::FileSystemURL;
22 22
23 namespace content { 23 namespace content {
24 24
25 TEST(ExternalMountPointsTest, AddMountPoint) { 25 TEST(ExternalMountPointsTest, AddMountPoint) {
26 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 26 scoped_refptr<storage::ExternalMountPoints> mount_points(
27 fileapi::ExternalMountPoints::CreateRefCounted()); 27 storage::ExternalMountPoints::CreateRefCounted());
28 28
29 struct TestCase { 29 struct TestCase {
30 // The mount point's name. 30 // The mount point's name.
31 const char* const name; 31 const char* const name;
32 // The mount point's path. 32 // The mount point's path.
33 const base::FilePath::CharType* const path; 33 const base::FilePath::CharType* const path;
34 // Whether the mount point registration should succeed. 34 // Whether the mount point registration should succeed.
35 bool success; 35 bool success;
36 // Path returned by GetRegisteredPath. NULL if the method is expected to 36 // Path returned by GetRegisteredPath. NULL if the method is expected to
37 // fail. 37 // fail.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 #else 100 #else
101 { "win", DRIVE FPL("\\separators\\win"), false, NULL }, 101 { "win", DRIVE FPL("\\separators\\win"), false, NULL },
102 { "win1", DRIVE FPL("\\try/separators\\win1"), false, NULL }, 102 { "win1", DRIVE FPL("\\try/separators\\win1"), false, NULL },
103 #endif 103 #endif
104 // Win separators, but relative path. 104 // Win separators, but relative path.
105 { "win2", DRIVE FPL("try\\separators\\win2"), false, NULL }, 105 { "win2", DRIVE FPL("try\\separators\\win2"), false, NULL },
106 }; 106 };
107 107
108 // Test adding mount points. 108 // Test adding mount points.
109 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 109 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
110 EXPECT_EQ(kTestCases[i].success, 110 EXPECT_EQ(
111 mount_points->RegisterFileSystem( 111 kTestCases[i].success,
112 kTestCases[i].name, 112 mount_points->RegisterFileSystem(kTestCases[i].name,
113 fileapi::kFileSystemTypeNativeLocal, 113 storage::kFileSystemTypeNativeLocal,
114 fileapi::FileSystemMountOption(), 114 storage::FileSystemMountOption(),
115 base::FilePath(kTestCases[i].path))) 115 base::FilePath(kTestCases[i].path)))
116 << "Adding mount point: " << kTestCases[i].name << " with path " 116 << "Adding mount point: " << kTestCases[i].name << " with path "
117 << kTestCases[i].path; 117 << kTestCases[i].path;
118 } 118 }
119 119
120 // Test that final mount point presence state is as expected. 120 // Test that final mount point presence state is as expected.
121 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 121 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
122 base::FilePath found_path; 122 base::FilePath found_path;
123 EXPECT_EQ(kTestCases[i].registered_path != NULL, 123 EXPECT_EQ(kTestCases[i].registered_path != NULL,
124 mount_points->GetRegisteredPath(kTestCases[i].name, &found_path)) 124 mount_points->GetRegisteredPath(kTestCases[i].name, &found_path))
125 << "Test case: " << i; 125 << "Test case: " << i;
126 126
127 if (kTestCases[i].registered_path) { 127 if (kTestCases[i].registered_path) {
128 base::FilePath expected_path(kTestCases[i].registered_path); 128 base::FilePath expected_path(kTestCases[i].registered_path);
129 EXPECT_EQ(expected_path.NormalizePathSeparators(), found_path); 129 EXPECT_EQ(expected_path.NormalizePathSeparators(), found_path);
130 } 130 }
131 } 131 }
132 } 132 }
133 133
134 TEST(ExternalMountPointsTest, GetVirtualPath) { 134 TEST(ExternalMountPointsTest, GetVirtualPath) {
135 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 135 scoped_refptr<storage::ExternalMountPoints> mount_points(
136 fileapi::ExternalMountPoints::CreateRefCounted()); 136 storage::ExternalMountPoints::CreateRefCounted());
137 137
138 mount_points->RegisterFileSystem("c", 138 mount_points->RegisterFileSystem("c",
139 fileapi::kFileSystemTypeNativeLocal, 139 storage::kFileSystemTypeNativeLocal,
140 fileapi::FileSystemMountOption(), 140 storage::FileSystemMountOption(),
141 base::FilePath(DRIVE FPL("/a/b/c"))); 141 base::FilePath(DRIVE FPL("/a/b/c")));
142 // Note that "/a/b/c" < "/a/b/c(1)" < "/a/b/c/". 142 // Note that "/a/b/c" < "/a/b/c(1)" < "/a/b/c/".
143 mount_points->RegisterFileSystem("c(1)", 143 mount_points->RegisterFileSystem("c(1)",
144 fileapi::kFileSystemTypeNativeLocal, 144 storage::kFileSystemTypeNativeLocal,
145 fileapi::FileSystemMountOption(), 145 storage::FileSystemMountOption(),
146 base::FilePath(DRIVE FPL("/a/b/c(1)"))); 146 base::FilePath(DRIVE FPL("/a/b/c(1)")));
147 mount_points->RegisterFileSystem("x", 147 mount_points->RegisterFileSystem("x",
148 fileapi::kFileSystemTypeNativeLocal, 148 storage::kFileSystemTypeNativeLocal,
149 fileapi::FileSystemMountOption(), 149 storage::FileSystemMountOption(),
150 base::FilePath(DRIVE FPL("/z/y/x"))); 150 base::FilePath(DRIVE FPL("/z/y/x")));
151 mount_points->RegisterFileSystem("o", 151 mount_points->RegisterFileSystem("o",
152 fileapi::kFileSystemTypeNativeLocal, 152 storage::kFileSystemTypeNativeLocal,
153 fileapi::FileSystemMountOption(), 153 storage::FileSystemMountOption(),
154 base::FilePath(DRIVE FPL("/m/n/o"))); 154 base::FilePath(DRIVE FPL("/m/n/o")));
155 // A mount point whose name does not match its path base name. 155 // A mount point whose name does not match its path base name.
156 mount_points->RegisterFileSystem("mount", 156 mount_points->RegisterFileSystem("mount",
157 fileapi::kFileSystemTypeNativeLocal, 157 storage::kFileSystemTypeNativeLocal,
158 fileapi::FileSystemMountOption(), 158 storage::FileSystemMountOption(),
159 base::FilePath(DRIVE FPL("/root/foo"))); 159 base::FilePath(DRIVE FPL("/root/foo")));
160 // A mount point with an empty path. 160 // A mount point with an empty path.
161 mount_points->RegisterFileSystem("empty_path", 161 mount_points->RegisterFileSystem("empty_path",
162 fileapi::kFileSystemTypeNativeLocal, 162 storage::kFileSystemTypeNativeLocal,
163 fileapi::FileSystemMountOption(), 163 storage::FileSystemMountOption(),
164 base::FilePath()); 164 base::FilePath());
165 165
166 struct TestCase { 166 struct TestCase {
167 const base::FilePath::CharType* const local_path; 167 const base::FilePath::CharType* const local_path;
168 bool success; 168 bool success;
169 const base::FilePath::CharType* const virtual_path; 169 const base::FilePath::CharType* const virtual_path;
170 }; 170 };
171 171
172 const TestCase kTestCases[] = { 172 const TestCase kTestCases[] = {
173 // Empty path. 173 // Empty path.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (!kTestCases[i].success) 227 if (!kTestCases[i].success)
228 continue; 228 continue;
229 229
230 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); 230 base::FilePath expected_virtual_path(kTestCases[i].virtual_path);
231 EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path) 231 EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path)
232 << "Resolving " << kTestCases[i].local_path; 232 << "Resolving " << kTestCases[i].local_path;
233 } 233 }
234 } 234 }
235 235
236 TEST(ExternalMountPointsTest, HandlesFileSystemMountType) { 236 TEST(ExternalMountPointsTest, HandlesFileSystemMountType) {
237 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 237 scoped_refptr<storage::ExternalMountPoints> mount_points(
238 fileapi::ExternalMountPoints::CreateRefCounted()); 238 storage::ExternalMountPoints::CreateRefCounted());
239 239
240 const GURL test_origin("http://chromium.org"); 240 const GURL test_origin("http://chromium.org");
241 const base::FilePath test_path(FPL("/mount")); 241 const base::FilePath test_path(FPL("/mount"));
242 242
243 // Should handle External File System. 243 // Should handle External File System.
244 EXPECT_TRUE(mount_points->HandlesFileSystemMountType( 244 EXPECT_TRUE(mount_points->HandlesFileSystemMountType(
245 fileapi::kFileSystemTypeExternal)); 245 storage::kFileSystemTypeExternal));
246 246
247 // Shouldn't handle the rest. 247 // Shouldn't handle the rest.
248 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( 248 EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
249 fileapi::kFileSystemTypeIsolated)); 249 storage::kFileSystemTypeIsolated));
250 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( 250 EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
251 fileapi::kFileSystemTypeTemporary)); 251 storage::kFileSystemTypeTemporary));
252 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( 252 EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
253 fileapi::kFileSystemTypePersistent)); 253 storage::kFileSystemTypePersistent));
254 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( 254 EXPECT_FALSE(
255 fileapi::kFileSystemTypeTest)); 255 mount_points->HandlesFileSystemMountType(storage::kFileSystemTypeTest));
256 // Not even if it's external subtype. 256 // Not even if it's external subtype.
257 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( 257 EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
258 fileapi::kFileSystemTypeNativeLocal)); 258 storage::kFileSystemTypeNativeLocal));
259 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( 259 EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
260 fileapi::kFileSystemTypeRestrictedNativeLocal)); 260 storage::kFileSystemTypeRestrictedNativeLocal));
261 EXPECT_FALSE(
262 mount_points->HandlesFileSystemMountType(storage::kFileSystemTypeDrive));
261 EXPECT_FALSE(mount_points->HandlesFileSystemMountType( 263 EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
262 fileapi::kFileSystemTypeDrive)); 264 storage::kFileSystemTypeSyncable));
263 EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
264 fileapi::kFileSystemTypeSyncable));
265 } 265 }
266 266
267 TEST(ExternalMountPointsTest, CreateCrackedFileSystemURL) { 267 TEST(ExternalMountPointsTest, CreateCrackedFileSystemURL) {
268 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 268 scoped_refptr<storage::ExternalMountPoints> mount_points(
269 fileapi::ExternalMountPoints::CreateRefCounted()); 269 storage::ExternalMountPoints::CreateRefCounted());
270 270
271 const GURL kTestOrigin("http://chromium.org"); 271 const GURL kTestOrigin("http://chromium.org");
272 272
273 mount_points->RegisterFileSystem("c", 273 mount_points->RegisterFileSystem("c",
274 fileapi::kFileSystemTypeNativeLocal, 274 storage::kFileSystemTypeNativeLocal,
275 fileapi::FileSystemMountOption(), 275 storage::FileSystemMountOption(),
276 base::FilePath(DRIVE FPL("/a/b/c"))); 276 base::FilePath(DRIVE FPL("/a/b/c")));
277 mount_points->RegisterFileSystem("c(1)", 277 mount_points->RegisterFileSystem("c(1)",
278 fileapi::kFileSystemTypeDrive, 278 storage::kFileSystemTypeDrive,
279 fileapi::FileSystemMountOption(), 279 storage::FileSystemMountOption(),
280 base::FilePath(DRIVE FPL("/a/b/c(1)"))); 280 base::FilePath(DRIVE FPL("/a/b/c(1)")));
281 mount_points->RegisterFileSystem("empty_path", 281 mount_points->RegisterFileSystem("empty_path",
282 fileapi::kFileSystemTypeSyncable, 282 storage::kFileSystemTypeSyncable,
283 fileapi::FileSystemMountOption(), 283 storage::FileSystemMountOption(),
284 base::FilePath()); 284 base::FilePath());
285 mount_points->RegisterFileSystem("mount", 285 mount_points->RegisterFileSystem("mount",
286 fileapi::kFileSystemTypeDrive, 286 storage::kFileSystemTypeDrive,
287 fileapi::FileSystemMountOption(), 287 storage::FileSystemMountOption(),
288 base::FilePath(DRIVE FPL("/root"))); 288 base::FilePath(DRIVE FPL("/root")));
289 289
290 // Try cracking invalid GURL. 290 // Try cracking invalid GURL.
291 FileSystemURL invalid = mount_points->CrackURL(GURL("http://chromium.og")); 291 FileSystemURL invalid = mount_points->CrackURL(GURL("http://chromium.og"));
292 EXPECT_FALSE(invalid.is_valid()); 292 EXPECT_FALSE(invalid.is_valid());
293 293
294 // Try cracking isolated path. 294 // Try cracking isolated path.
295 FileSystemURL isolated = mount_points->CreateCrackedFileSystemURL( 295 FileSystemURL isolated = mount_points->CreateCrackedFileSystemURL(
296 kTestOrigin, fileapi::kFileSystemTypeIsolated, base::FilePath(FPL("c"))); 296 kTestOrigin, storage::kFileSystemTypeIsolated, base::FilePath(FPL("c")));
297 EXPECT_FALSE(isolated.is_valid()); 297 EXPECT_FALSE(isolated.is_valid());
298 298
299 // Try native local which is not cracked. 299 // Try native local which is not cracked.
300 FileSystemURL native_local = mount_points->CreateCrackedFileSystemURL( 300 FileSystemURL native_local = mount_points->CreateCrackedFileSystemURL(
301 kTestOrigin, 301 kTestOrigin,
302 fileapi::kFileSystemTypeNativeLocal, 302 storage::kFileSystemTypeNativeLocal,
303 base::FilePath(FPL("c"))); 303 base::FilePath(FPL("c")));
304 EXPECT_FALSE(native_local.is_valid()); 304 EXPECT_FALSE(native_local.is_valid());
305 305
306 struct TestCase { 306 struct TestCase {
307 const base::FilePath::CharType* const path; 307 const base::FilePath::CharType* const path;
308 bool expect_valid; 308 bool expect_valid;
309 fileapi::FileSystemType expect_type; 309 storage::FileSystemType expect_type;
310 const base::FilePath::CharType* const expect_path; 310 const base::FilePath::CharType* const expect_path;
311 const char* const expect_fs_id; 311 const char* const expect_fs_id;
312 }; 312 };
313 313
314 const TestCase kTestCases[] = { 314 const TestCase kTestCases[] = {
315 { FPL("c/d/e"), 315 {FPL("c/d/e"), true, storage::kFileSystemTypeNativeLocal,
316 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" }, 316 DRIVE FPL("/a/b/c/d/e"), "c"},
317 { FPL("c(1)/d/e"), 317 {FPL("c(1)/d/e"), true, storage::kFileSystemTypeDrive,
318 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)/d/e"), "c(1)" }, 318 DRIVE FPL("/a/b/c(1)/d/e"), "c(1)"},
319 { FPL("c(1)"), 319 {FPL("c(1)"), true, storage::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"),
320 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), "c(1)" }, 320 "c(1)"},
321 { FPL("empty_path/a"), 321 {FPL("empty_path/a"), true, storage::kFileSystemTypeSyncable, FPL("a"),
322 true, fileapi::kFileSystemTypeSyncable, FPL("a"), "empty_path" }, 322 "empty_path"},
323 { FPL("empty_path"), 323 {FPL("empty_path"), true, storage::kFileSystemTypeSyncable, FPL(""),
324 true, fileapi::kFileSystemTypeSyncable, FPL(""), "empty_path" }, 324 "empty_path"},
325 { FPL("mount/a/b"), 325 {FPL("mount/a/b"), true, storage::kFileSystemTypeDrive,
326 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" }, 326 DRIVE FPL("/root/a/b"), "mount"},
327 { FPL("mount"), 327 {FPL("mount"), true, storage::kFileSystemTypeDrive, DRIVE FPL("/root"),
328 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root"), "mount" }, 328 "mount"},
329 { FPL("cc"), 329 {FPL("cc"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
330 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" }, 330 {FPL(""), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
331 { FPL(""), 331 {FPL(".."), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
332 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
333 { FPL(".."),
334 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
335 // Absolte paths. 332 // Absolte paths.
336 { FPL("/c/d/e"), 333 {FPL("/c/d/e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
337 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" }, 334 {FPL("/c(1)/d/e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
338 { FPL("/c(1)/d/e"), 335 {FPL("/empty_path"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
339 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
340 { FPL("/empty_path"),
341 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
342 // PAth references parent. 336 // PAth references parent.
343 { FPL("c/d/../e"), 337 {FPL("c/d/../e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
344 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" }, 338 {FPL("/empty_path/a/../b"), false, storage::kFileSystemTypeUnknown, FPL(""),
345 { FPL("/empty_path/a/../b"), 339 ""},
346 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
347 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 340 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
348 { FPL("c/d\\e"), 341 {FPL("c/d\\e"), true, storage::kFileSystemTypeNativeLocal,
349 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" }, 342 DRIVE FPL("/a/b/c/d/e"), "c"},
350 { FPL("mount\\a\\b"), 343 {FPL("mount\\a\\b"), true, storage::kFileSystemTypeDrive,
351 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" }, 344 DRIVE FPL("/root/a/b"), "mount"},
352 #endif 345 #endif
353 }; 346 };
354 347
355 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 348 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
356 FileSystemURL cracked = mount_points->CreateCrackedFileSystemURL( 349 FileSystemURL cracked = mount_points->CreateCrackedFileSystemURL(
357 kTestOrigin, 350 kTestOrigin,
358 fileapi::kFileSystemTypeExternal, 351 storage::kFileSystemTypeExternal,
359 base::FilePath(kTestCases[i].path)); 352 base::FilePath(kTestCases[i].path));
360 353
361 EXPECT_EQ(kTestCases[i].expect_valid, cracked.is_valid()) 354 EXPECT_EQ(kTestCases[i].expect_valid, cracked.is_valid())
362 << "Test case index: " << i; 355 << "Test case index: " << i;
363 356
364 if (!kTestCases[i].expect_valid) 357 if (!kTestCases[i].expect_valid)
365 continue; 358 continue;
366 359
367 EXPECT_EQ(kTestOrigin, cracked.origin()) 360 EXPECT_EQ(kTestOrigin, cracked.origin())
368 << "Test case index: " << i; 361 << "Test case index: " << i;
369 EXPECT_EQ(kTestCases[i].expect_type, cracked.type()) 362 EXPECT_EQ(kTestCases[i].expect_type, cracked.type())
370 << "Test case index: " << i; 363 << "Test case index: " << i;
371 EXPECT_EQ(base::FilePath( 364 EXPECT_EQ(base::FilePath(
372 kTestCases[i].expect_path).NormalizePathSeparators(), cracked.path()) 365 kTestCases[i].expect_path).NormalizePathSeparators(), cracked.path())
373 << "Test case index: " << i; 366 << "Test case index: " << i;
374 EXPECT_EQ(base::FilePath(kTestCases[i].path).NormalizePathSeparators(), 367 EXPECT_EQ(base::FilePath(kTestCases[i].path).NormalizePathSeparators(),
375 cracked.virtual_path()) 368 cracked.virtual_path())
376 << "Test case index: " << i; 369 << "Test case index: " << i;
377 EXPECT_EQ(kTestCases[i].expect_fs_id, cracked.filesystem_id()) 370 EXPECT_EQ(kTestCases[i].expect_fs_id, cracked.filesystem_id())
378 << "Test case index: " << i; 371 << "Test case index: " << i;
379 EXPECT_EQ(fileapi::kFileSystemTypeExternal, cracked.mount_type()) 372 EXPECT_EQ(storage::kFileSystemTypeExternal, cracked.mount_type())
380 << "Test case index: " << i; 373 << "Test case index: " << i;
381 } 374 }
382 } 375 }
383 376
384 TEST(ExternalMountPointsTest, CrackVirtualPath) { 377 TEST(ExternalMountPointsTest, CrackVirtualPath) {
385 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 378 scoped_refptr<storage::ExternalMountPoints> mount_points(
386 fileapi::ExternalMountPoints::CreateRefCounted()); 379 storage::ExternalMountPoints::CreateRefCounted());
387 380
388 const GURL kTestOrigin("http://chromium.org"); 381 const GURL kTestOrigin("http://chromium.org");
389 382
390 mount_points->RegisterFileSystem("c", 383 mount_points->RegisterFileSystem("c",
391 fileapi::kFileSystemTypeNativeLocal, 384 storage::kFileSystemTypeNativeLocal,
392 fileapi::FileSystemMountOption(), 385 storage::FileSystemMountOption(),
393 base::FilePath(DRIVE FPL("/a/b/c"))); 386 base::FilePath(DRIVE FPL("/a/b/c")));
394 mount_points->RegisterFileSystem("c(1)", 387 mount_points->RegisterFileSystem("c(1)",
395 fileapi::kFileSystemTypeDrive, 388 storage::kFileSystemTypeDrive,
396 fileapi::FileSystemMountOption(), 389 storage::FileSystemMountOption(),
397 base::FilePath(DRIVE FPL("/a/b/c(1)"))); 390 base::FilePath(DRIVE FPL("/a/b/c(1)")));
398 mount_points->RegisterFileSystem("empty_path", 391 mount_points->RegisterFileSystem("empty_path",
399 fileapi::kFileSystemTypeSyncable, 392 storage::kFileSystemTypeSyncable,
400 fileapi::FileSystemMountOption(), 393 storage::FileSystemMountOption(),
401 base::FilePath()); 394 base::FilePath());
402 mount_points->RegisterFileSystem("mount", 395 mount_points->RegisterFileSystem("mount",
403 fileapi::kFileSystemTypeDrive, 396 storage::kFileSystemTypeDrive,
404 fileapi::FileSystemMountOption(), 397 storage::FileSystemMountOption(),
405 base::FilePath(DRIVE FPL("/root"))); 398 base::FilePath(DRIVE FPL("/root")));
406 399
407 struct TestCase { 400 struct TestCase {
408 const base::FilePath::CharType* const path; 401 const base::FilePath::CharType* const path;
409 bool expect_valid; 402 bool expect_valid;
410 fileapi::FileSystemType expect_type; 403 storage::FileSystemType expect_type;
411 const base::FilePath::CharType* const expect_path; 404 const base::FilePath::CharType* const expect_path;
412 const char* const expect_name; 405 const char* const expect_name;
413 }; 406 };
414 407
415 const TestCase kTestCases[] = { 408 const TestCase kTestCases[] = {
416 { FPL("c/d/e"), 409 {FPL("c/d/e"), true, storage::kFileSystemTypeNativeLocal,
417 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" }, 410 DRIVE FPL("/a/b/c/d/e"), "c"},
418 { FPL("c(1)/d/e"), 411 {FPL("c(1)/d/e"), true, storage::kFileSystemTypeDrive,
419 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)/d/e"), "c(1)" }, 412 DRIVE FPL("/a/b/c(1)/d/e"), "c(1)"},
420 { FPL("c(1)"), 413 {FPL("c(1)"), true, storage::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"),
421 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), "c(1)" }, 414 "c(1)"},
422 { FPL("empty_path/a"), 415 {FPL("empty_path/a"), true, storage::kFileSystemTypeSyncable, FPL("a"),
423 true, fileapi::kFileSystemTypeSyncable, FPL("a"), "empty_path" }, 416 "empty_path"},
424 { FPL("empty_path"), 417 {FPL("empty_path"), true, storage::kFileSystemTypeSyncable, FPL(""),
425 true, fileapi::kFileSystemTypeSyncable, FPL(""), "empty_path" }, 418 "empty_path"},
426 { FPL("mount/a/b"), 419 {FPL("mount/a/b"), true, storage::kFileSystemTypeDrive,
427 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" }, 420 DRIVE FPL("/root/a/b"), "mount"},
428 { FPL("mount"), 421 {FPL("mount"), true, storage::kFileSystemTypeDrive, DRIVE FPL("/root"),
429 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root"), "mount" }, 422 "mount"},
430 { FPL("cc"), 423 {FPL("cc"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
431 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" }, 424 {FPL(""), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
432 { FPL(""), 425 {FPL(".."), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
433 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
434 { FPL(".."),
435 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
436 // Absolte paths. 426 // Absolte paths.
437 { FPL("/c/d/e"), 427 {FPL("/c/d/e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
438 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" }, 428 {FPL("/c(1)/d/e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
439 { FPL("/c(1)/d/e"), 429 {FPL("/empty_path"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
440 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
441 { FPL("/empty_path"),
442 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
443 // PAth references parent. 430 // PAth references parent.
444 { FPL("c/d/../e"), 431 {FPL("c/d/../e"), false, storage::kFileSystemTypeUnknown, FPL(""), ""},
445 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" }, 432 {FPL("/empty_path/a/../b"), false, storage::kFileSystemTypeUnknown, FPL(""),
446 { FPL("/empty_path/a/../b"), 433 ""},
447 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
448 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 434 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
449 { FPL("c/d\\e"), 435 {FPL("c/d\\e"), true, storage::kFileSystemTypeNativeLocal,
450 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" }, 436 DRIVE FPL("/a/b/c/d/e"), "c"},
451 { FPL("mount\\a\\b"), 437 {FPL("mount\\a\\b"), true, storage::kFileSystemTypeDrive,
452 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" }, 438 DRIVE FPL("/root/a/b"), "mount"},
453 #endif 439 #endif
454 }; 440 };
455 441
456 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 442 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
457 std::string cracked_name; 443 std::string cracked_name;
458 fileapi::FileSystemType cracked_type; 444 storage::FileSystemType cracked_type;
459 std::string cracked_id; 445 std::string cracked_id;
460 base::FilePath cracked_path; 446 base::FilePath cracked_path;
461 fileapi::FileSystemMountOption cracked_option; 447 storage::FileSystemMountOption cracked_option;
462 EXPECT_EQ(kTestCases[i].expect_valid, 448 EXPECT_EQ(kTestCases[i].expect_valid,
463 mount_points->CrackVirtualPath(base::FilePath(kTestCases[i].path), 449 mount_points->CrackVirtualPath(base::FilePath(kTestCases[i].path),
464 &cracked_name, &cracked_type, &cracked_id, &cracked_path, 450 &cracked_name, &cracked_type, &cracked_id, &cracked_path,
465 &cracked_option)) 451 &cracked_option))
466 << "Test case index: " << i; 452 << "Test case index: " << i;
467 453
468 if (!kTestCases[i].expect_valid) 454 if (!kTestCases[i].expect_valid)
469 continue; 455 continue;
470 456
471 EXPECT_EQ(kTestCases[i].expect_type, cracked_type) 457 EXPECT_EQ(kTestCases[i].expect_type, cracked_type)
472 << "Test case index: " << i; 458 << "Test case index: " << i;
473 EXPECT_EQ(base::FilePath( 459 EXPECT_EQ(base::FilePath(
474 kTestCases[i].expect_path).NormalizePathSeparators(), cracked_path) 460 kTestCases[i].expect_path).NormalizePathSeparators(), cracked_path)
475 << "Test case index: " << i; 461 << "Test case index: " << i;
476 EXPECT_EQ(kTestCases[i].expect_name, cracked_name) 462 EXPECT_EQ(kTestCases[i].expect_name, cracked_name)
477 << "Test case index: " << i; 463 << "Test case index: " << i;
478 // As of now we don't mount other filesystems with non-empty filesystem_id 464 // As of now we don't mount other filesystems with non-empty filesystem_id
479 // onto external mount points. 465 // onto external mount points.
480 EXPECT_TRUE(cracked_id.empty()) << "Test case index: " << i; 466 EXPECT_TRUE(cracked_id.empty()) << "Test case index: " << i;
481 } 467 }
482 } 468 }
483 469
484 TEST(ExternalMountPointsTest, MountOption) { 470 TEST(ExternalMountPointsTest, MountOption) {
485 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 471 scoped_refptr<storage::ExternalMountPoints> mount_points(
486 fileapi::ExternalMountPoints::CreateRefCounted()); 472 storage::ExternalMountPoints::CreateRefCounted());
487 473
488 mount_points->RegisterFileSystem( 474 mount_points->RegisterFileSystem(
489 "nosync", 475 "nosync",
490 fileapi::kFileSystemTypeNativeLocal, 476 storage::kFileSystemTypeNativeLocal,
491 fileapi::FileSystemMountOption(fileapi::COPY_SYNC_OPTION_NO_SYNC), 477 storage::FileSystemMountOption(storage::COPY_SYNC_OPTION_NO_SYNC),
492 base::FilePath(DRIVE FPL("/nosync"))); 478 base::FilePath(DRIVE FPL("/nosync")));
493 mount_points->RegisterFileSystem( 479 mount_points->RegisterFileSystem(
494 "sync", 480 "sync",
495 fileapi::kFileSystemTypeNativeLocal, 481 storage::kFileSystemTypeNativeLocal,
496 fileapi::FileSystemMountOption(fileapi::COPY_SYNC_OPTION_SYNC), 482 storage::FileSystemMountOption(storage::COPY_SYNC_OPTION_SYNC),
497 base::FilePath(DRIVE FPL("/sync"))); 483 base::FilePath(DRIVE FPL("/sync")));
498 484
499 std::string name; 485 std::string name;
500 fileapi::FileSystemType type; 486 storage::FileSystemType type;
501 std::string cracked_id; 487 std::string cracked_id;
502 fileapi::FileSystemMountOption option; 488 storage::FileSystemMountOption option;
503 base::FilePath path; 489 base::FilePath path;
504 EXPECT_TRUE(mount_points->CrackVirtualPath( 490 EXPECT_TRUE(mount_points->CrackVirtualPath(
505 base::FilePath(FPL("nosync/file")), &name, &type, &cracked_id, &path, 491 base::FilePath(FPL("nosync/file")), &name, &type, &cracked_id, &path,
506 &option)); 492 &option));
507 EXPECT_EQ(fileapi::COPY_SYNC_OPTION_NO_SYNC, option.copy_sync_option()); 493 EXPECT_EQ(storage::COPY_SYNC_OPTION_NO_SYNC, option.copy_sync_option());
508 EXPECT_TRUE(mount_points->CrackVirtualPath( 494 EXPECT_TRUE(mount_points->CrackVirtualPath(
509 base::FilePath(FPL("sync/file")), &name, &type, &cracked_id, &path, 495 base::FilePath(FPL("sync/file")), &name, &type, &cracked_id, &path,
510 &option)); 496 &option));
511 EXPECT_EQ(fileapi::COPY_SYNC_OPTION_SYNC, option.copy_sync_option()); 497 EXPECT_EQ(storage::COPY_SYNC_OPTION_SYNC, option.copy_sync_option());
512 } 498 }
513 499
514 } // namespace content 500 } // namespace content
515 501
OLDNEW
« no previous file with comments | « content/browser/fileapi/dragged_file_util_unittest.cc ('k') | content/browser/fileapi/file_system_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698