OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_system_path_manager.h" | 5 #include "webkit/fileapi/file_system_path_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 FilePath* root_path) { | 221 FilePath* root_path) { |
222 manager->GetFileSystemRootPath(origin_url, type, create, | 222 manager->GetFileSystemRootPath(origin_url, type, create, |
223 callback_factory_.NewCallback( | 223 callback_factory_.NewCallback( |
224 &FileSystemPathManagerTest::OnGetRootPath)); | 224 &FileSystemPathManagerTest::OnGetRootPath)); |
225 MessageLoop::current()->RunAllPending(); | 225 MessageLoop::current()->RunAllPending(); |
226 if (root_path) | 226 if (root_path) |
227 *root_path = root_path_; | 227 *root_path = root_path_; |
228 return root_path_callback_status_; | 228 return root_path_callback_status_; |
229 } | 229 } |
230 | 230 |
231 bool CheckValidFileSystemPath(FileSystemPathManager* manager, | |
232 const FilePath& path) { | |
233 return manager->CrackFileSystemPath(path, NULL, NULL, NULL); | |
234 } | |
235 | |
236 FilePath data_path() { return data_dir_.path(); } | 231 FilePath data_path() { return data_dir_.path(); } |
237 FilePath file_system_path() { | 232 FilePath file_system_path() { |
238 return data_dir_.path().Append( | 233 return data_dir_.path().Append( |
239 SandboxMountPointProvider::kFileSystemDirectory); | 234 SandboxMountPointProvider::kFileSystemDirectory); |
240 } | 235 } |
241 | 236 |
242 private: | 237 private: |
243 ScopedTempDir data_dir_; | 238 ScopedTempDir data_dir_; |
244 base::ScopedCallbackFactory<FileSystemPathManagerTest> callback_factory_; | 239 base::ScopedCallbackFactory<FileSystemPathManagerTest> callback_factory_; |
245 | 240 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 GURL(kRootPathFileURITestCases[i].origin_url), | 355 GURL(kRootPathFileURITestCases[i].origin_url), |
361 kRootPathFileURITestCases[i].type, | 356 kRootPathFileURITestCases[i].type, |
362 true /* create */, &root_path)); | 357 true /* create */, &root_path)); |
363 FilePath expected = file_system_path().AppendASCII( | 358 FilePath expected = file_system_path().AppendASCII( |
364 kRootPathFileURITestCases[i].expected_path); | 359 kRootPathFileURITestCases[i].expected_path); |
365 EXPECT_EQ(expected.value(), root_path.DirName().value()); | 360 EXPECT_EQ(expected.value(), root_path.DirName().value()); |
366 EXPECT_TRUE(file_util::DirectoryExists(root_path)); | 361 EXPECT_TRUE(file_util::DirectoryExists(root_path)); |
367 } | 362 } |
368 } | 363 } |
369 | 364 |
370 TEST_F(FileSystemPathManagerTest, VirtualPathFromFileSystemPathTest) { | |
371 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
372 GURL root_url = GetFileSystemRootURI( | |
373 GURL("http://foo.com/"), fileapi::kFileSystemTypeTemporary); | |
374 FilePath root_path = FilePath().AppendASCII(root_url.spec()); | |
375 | |
376 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPathToVirtualPathTestCases); ++i) { | |
377 SCOPED_TRACE(testing::Message() << "PathToVirtualPath #" | |
378 << i << " " << kPathToVirtualPathTestCases[i]); | |
379 FilePath absolute_path; | |
380 // TODO(ericu): Clean this up when we've got more sane path-handling. | |
381 // This hack is necessary because root_path is actually a URL [ending with a | |
382 // forward slash], and AppendASCII("") on Windows will delete the trailing | |
383 // slash, making the path invalid as far as CrackFileSystemPath is | |
384 // concerned. | |
385 if (strlen(kPathToVirtualPathTestCases[i])) | |
386 absolute_path = root_path.AppendASCII( | |
387 kPathToVirtualPathTestCases[i]); | |
388 else | |
389 absolute_path = root_path; | |
390 FilePath virtual_path; | |
391 EXPECT_TRUE(manager->CrackFileSystemPath(absolute_path, NULL, NULL, | |
392 &virtual_path)); | |
393 | |
394 FilePath test_case_path; | |
395 test_case_path = test_case_path.AppendASCII( | |
396 kPathToVirtualPathTestCases[i]); | |
397 EXPECT_EQ(test_case_path.value(), virtual_path.value()); | |
398 } | |
399 } | |
400 | |
401 TEST_F(FileSystemPathManagerTest, TypeFromFileSystemPathTest) { | |
402 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
403 | |
404 fileapi::FileSystemType type; | |
405 | |
406 GURL root_url = GetFileSystemRootURI( | |
407 GURL("http://foo.com/"), fileapi::kFileSystemTypeTemporary); | |
408 FilePath root_path = FilePath().AppendASCII(root_url.spec()); | |
409 FilePath path = root_path.AppendASCII("test"); | |
410 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL)); | |
411 EXPECT_EQ(fileapi::kFileSystemTypeTemporary, type); | |
412 | |
413 root_url = GetFileSystemRootURI( | |
414 GURL("http://foo.com/"), fileapi::kFileSystemTypePersistent); | |
415 root_path = FilePath().AppendASCII(root_url.spec()); | |
416 path = root_path.AppendASCII("test"); | |
417 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL)); | |
418 EXPECT_EQ(fileapi::kFileSystemTypePersistent, type); | |
419 } | |
420 | |
421 TEST_F(FileSystemPathManagerTest, CheckValidPath) { | |
422 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
423 GURL root_url = GetFileSystemRootURI( | |
424 GURL("http://foo.com/"), fileapi::kFileSystemTypePersistent); | |
425 FilePath root_path = FilePath().AppendASCII(root_url.spec()); | |
426 | |
427 // The root path must be valid, but upper directories or directories | |
428 // that are not in our temporary or persistent directory must be | |
429 // evaluated invalid. | |
430 EXPECT_TRUE(CheckValidFileSystemPath(manager.get(), root_path)); | |
431 EXPECT_FALSE(CheckValidFileSystemPath(manager.get(), root_path.DirName())); | |
432 EXPECT_FALSE(CheckValidFileSystemPath(manager.get(), | |
433 root_path.DirName().DirName())); | |
434 EXPECT_FALSE(CheckValidFileSystemPath(manager.get(), | |
435 root_path.DirName().DirName() | |
436 .AppendASCII("ArbitraryName") | |
437 .AppendASCII("chrome-dummy"))); | |
438 | |
439 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kCheckValidPathTestCases); ++i) { | |
440 SCOPED_TRACE(testing::Message() << "CheckValidPath #" << i << " " | |
441 << kCheckValidPathTestCases[i].path); | |
442 FilePath path(kCheckValidPathTestCases[i].path); | |
443 #ifdef FILE_PATH_USES_WIN_SEPARATORS | |
444 path = path.NormalizeWindowsPathSeparators(); | |
445 #endif | |
446 if (!path.IsAbsolute()) | |
447 path = root_path.Append(path); | |
448 EXPECT_EQ(kCheckValidPathTestCases[i].expected_valid, | |
449 CheckValidFileSystemPath(manager.get(), path)); | |
450 } | |
451 } | |
452 | |
453 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { | 365 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { |
454 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | 366 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); |
455 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { | 367 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { |
456 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " | 368 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " |
457 << kIsRestrictedNameTestCases[i].name); | 369 << kIsRestrictedNameTestCases[i].name); |
458 FilePath name(kIsRestrictedNameTestCases[i].name); | 370 FilePath name(kIsRestrictedNameTestCases[i].name); |
459 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, | 371 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, |
460 manager->IsRestrictedFileName(kFileSystemTypeTemporary, name)); | 372 manager->IsRestrictedFileName(kFileSystemTypeTemporary, name)); |
461 } | 373 } |
462 } | 374 } |
OLD | NEW |