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

Side by Side Diff: webkit/fileapi/external_mount_points_unittest.cc

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: browser_tests compile Created 7 years, 11 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/fileapi/external_mount_points.h" 5 #include "webkit/fileapi/external_mount_points.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/fileapi/file_system_url.h"
11 12
12 #define FPL FILE_PATH_LITERAL 13 #define FPL FILE_PATH_LITERAL
13 14
14 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 15 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
15 #define DRIVE FPL("C:") 16 #define DRIVE FPL("C:")
16 #else 17 #else
17 #define DRIVE 18 #define DRIVE
18 #endif 19 #endif
19 20
21 using fileapi::FileSystemURL;
22
20 namespace { 23 namespace {
21 24
22 TEST(ExternalMountPointsTest, AddMountPoint) { 25 TEST(ExternalMountPointsTest, AddMountPoint) {
23 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 26 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
24 fileapi::ExternalMountPoints::CreateRefCounted()); 27 fileapi::ExternalMountPoints::CreateRefCounted());
25 28
26 struct TestCase { 29 struct TestCase {
27 // The mount point's name. 30 // The mount point's name.
28 const char* const name; 31 const char* const name;
29 // The mount point's path. 32 // The mount point's path.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // fails. 219 // fails.
217 if (!kTestCases[i].success) 220 if (!kTestCases[i].success)
218 continue; 221 continue;
219 222
220 FilePath expected_virtual_path(kTestCases[i].virtual_path); 223 FilePath expected_virtual_path(kTestCases[i].virtual_path);
221 EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path) 224 EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path)
222 << "Resolving " << kTestCases[i].local_path; 225 << "Resolving " << kTestCases[i].local_path;
223 } 226 }
224 } 227 }
225 228
229 TEST(ExternalMountPointsTest, CanHandleURL) {
230 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
231 fileapi::ExternalMountPoints::CreateRefCounted());
232
233 const GURL test_origin("http://chromium.org");
234 const FilePath test_path(FPL("/mount"));
235
236 // Shouldn't handle invalid URL.
237 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL()));
238
239 // Should handle External File System.
240 EXPECT_TRUE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
241 test_origin, fileapi::kFileSystemTypeExternal, test_path)));
242
243 // Shouldn't handle the rest.
244 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
245 test_origin, fileapi::kFileSystemTypeIsolated, test_path)));
246 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
247 test_origin, fileapi::kFileSystemTypeTemporary, test_path)));
248 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
249 test_origin, fileapi::kFileSystemTypePersistent, test_path)));
250 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
251 test_origin, fileapi::kFileSystemTypeTest, test_path)));
252 // Not even if it's external subtype.
253 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
254 test_origin, fileapi::kFileSystemTypeNativeLocal, test_path)));
255 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
256 test_origin, fileapi::kFileSystemTypeRestrictedNativeLocal, test_path)));
257 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
258 test_origin, fileapi::kFileSystemTypeDrive, test_path)));
259 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
260 test_origin, fileapi::kFileSystemTypeSyncable, test_path)));
261 }
262
263 TEST(ExternalMountPointsTest, CrackURL) {
264 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
265 fileapi::ExternalMountPoints::CreateRefCounted());
266
267 const GURL kTestOrigin("http://chromium.org");
268
269 mount_points->RegisterFileSystem("c",
270 fileapi::kFileSystemTypeNativeLocal,
271 FilePath(DRIVE FPL("/a/b/c")));
272 mount_points->RegisterFileSystem("c(1)",
273 fileapi::kFileSystemTypeDrive,
274 FilePath(DRIVE FPL("/a/b/c(1)")));
275 mount_points->RegisterFileSystem("empty_path",
276 fileapi::kFileSystemTypeSyncable,
277 FilePath(FPL("")));
278 mount_points->RegisterFileSystem("mount",
279 fileapi::kFileSystemTypeDrive,
280 FilePath(DRIVE FPL("/root")));
281
282 // Try cracking isolated path.
283 FileSystemURL isolated = mount_points->CrackFileSystemURL(
284 FileSystemURL::CreateForTest(kTestOrigin,
285 fileapi::kFileSystemTypeIsolated,
286 FilePath(FPL("c"))));
287 EXPECT_FALSE(isolated.is_valid());
288
289 // Try native local which is no tcracked.
290 FileSystemURL native_local = mount_points->CrackFileSystemURL(
291 FileSystemURL::CreateForTest(kTestOrigin,
292 fileapi::kFileSystemTypeNativeLocal,
293 FilePath(FPL("c"))));
294 EXPECT_FALSE(native_local.is_valid());
295
296 struct TestCase {
297 const FilePath::CharType* const path;
298 bool expect_valid;
299 fileapi::FileSystemType expect_type;
300 const FilePath::CharType* const expect_path;
301 const char* const expect_fs_id;
302 };
303
304 const TestCase kTestCases[] = {
305 { FPL("c/d/e"),
306 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
307 { FPL("c(1)/d/e"),
308 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)/d/e"), "c(1)" },
309 { FPL("c(1)"),
310 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), "c(1)" },
311 { FPL("empty_path/a"),
312 true, fileapi::kFileSystemTypeSyncable, FPL("a"), "empty_path" },
313 { FPL("empty_path"),
314 true, fileapi::kFileSystemTypeSyncable, FPL(""), "empty_path" },
315 { FPL("mount/a/b"),
316 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
317 { FPL("mount"),
318 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root"), "mount" },
319 { FPL("cc"),
320 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
321 { FPL(""),
322 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
323 { FPL(".."),
324 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
325 // Absolte paths.
326 { FPL("/c/d/e"),
327 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
328 { FPL("/c(1)/d/e"),
329 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
330 { FPL("/empty_path"),
331 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
332 // PAth references parent.
333 { FPL("c/d/../e"),
334 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
335 { FPL("/empty_path/a/../b"),
336 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
337 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
338 { FPL("c/d\\e"),
339 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
340 { FPL("mount\\a\\b"),
341 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
342 #endif
343 };
344
345 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
346 FileSystemURL cracked = mount_points->CrackFileSystemURL(
347 FileSystemURL::CreateForTest(kTestOrigin,
348 fileapi::kFileSystemTypeExternal,
349 FilePath(kTestCases[i].path)));
350
351 EXPECT_EQ(kTestCases[i].expect_valid, cracked.is_valid())
352 << "Test case index: " << i;
353 EXPECT_EQ(kTestCases[i].expect_valid, cracked.is_cracked())
354 << "Test case index: " << i;
355
356 if (!kTestCases[i].expect_valid)
357 continue;
358
359 EXPECT_EQ(kTestOrigin, cracked.origin())
360 << "Test case index: " << i;
361 EXPECT_EQ(kTestCases[i].expect_type, cracked.type())
362 << "Test case index: " << i;
363 EXPECT_EQ(FilePath(kTestCases[i].expect_path).NormalizePathSeparators(),
364 cracked.path())
365 << "Test case index: " << i;
366 EXPECT_EQ(FilePath(kTestCases[i].path).NormalizePathSeparators(),
367 cracked.virtual_path())
368 << "Test case index: " << i;
369 EXPECT_EQ(kTestCases[i].expect_fs_id, cracked.filesystem_id())
370 << "Test case index: " << i;
371 EXPECT_EQ(fileapi::kFileSystemTypeExternal, cracked.mount_type())
372 << "Test case index: " << i;
373 }
374 }
375
376 TEST(ExternalMountPointsTest, CrackVirtualPath) {
377 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
378 fileapi::ExternalMountPoints::CreateRefCounted());
379
380 const GURL kTestOrigin("http://chromium.org");
381
382 mount_points->RegisterFileSystem("c",
383 fileapi::kFileSystemTypeNativeLocal,
384 FilePath(DRIVE FPL("/a/b/c")));
385 mount_points->RegisterFileSystem("c(1)",
386 fileapi::kFileSystemTypeDrive,
387 FilePath(DRIVE FPL("/a/b/c(1)")));
388 mount_points->RegisterFileSystem("empty_path",
389 fileapi::kFileSystemTypeSyncable,
390 FilePath(FPL("")));
391 mount_points->RegisterFileSystem("mount",
392 fileapi::kFileSystemTypeDrive,
393 FilePath(DRIVE FPL("/root")));
394
395 struct TestCase {
396 const FilePath::CharType* const path;
397 bool expect_valid;
398 fileapi::FileSystemType expect_type;
399 const FilePath::CharType* const expect_path;
400 const char* const expect_name;
401 };
402
403 const TestCase kTestCases[] = {
404 { FPL("c/d/e"),
405 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
406 { FPL("c(1)/d/e"),
407 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)/d/e"), "c(1)" },
408 { FPL("c(1)"),
409 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), "c(1)" },
410 { FPL("empty_path/a"),
411 true, fileapi::kFileSystemTypeSyncable, FPL("a"), "empty_path" },
412 { FPL("empty_path"),
413 true, fileapi::kFileSystemTypeSyncable, FPL(""), "empty_path" },
414 { FPL("mount/a/b"),
415 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
416 { FPL("mount"),
417 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root"), "mount" },
418 { FPL("cc"),
419 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
420 { FPL(""),
421 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
422 { FPL(".."),
423 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
424 // Absolte paths.
425 { FPL("/c/d/e"),
426 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
427 { FPL("/c(1)/d/e"),
428 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
429 { FPL("/empty_path"),
430 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
431 // PAth references parent.
432 { FPL("c/d/../e"),
433 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
434 { FPL("/empty_path/a/../b"),
435 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
436 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
437 { FPL("c/d\\e"),
438 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
439 { FPL("mount\\a\\b"),
440 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
441 #endif
442 };
443
444 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
445 std::string cracked_name;
446 fileapi::FileSystemType cracked_type;
447 FilePath cracked_path;
448 EXPECT_EQ(kTestCases[i].expect_valid,
449 mount_points->CrackVirtualPath(FilePath(kTestCases[i].path),
450 &cracked_name, &cracked_type, &cracked_path))
451 << "Test case index: " << i;
452
453 if (!kTestCases[i].expect_valid)
454 continue;
455
456 EXPECT_EQ(kTestCases[i].expect_type, cracked_type)
457 << "Test case index: " << i;
458 EXPECT_EQ(FilePath(kTestCases[i].expect_path).NormalizePathSeparators(),
459 cracked_path)
460 << "Test case index: " << i;
461 EXPECT_EQ(kTestCases[i].expect_name, cracked_name)
462 << "Test case index: " << i;
463 }
464 }
465
226 } // namespace 466 } // namespace
227 467
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698