| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 FilePath* root_path) { | 195 FilePath* root_path) { |
| 196 manager->GetFileSystemRootPath(origin_url, type, create, | 196 manager->GetFileSystemRootPath(origin_url, type, create, |
| 197 callback_factory_.NewCallback( | 197 callback_factory_.NewCallback( |
| 198 &FileSystemPathManagerTest::OnGetRootPath)); | 198 &FileSystemPathManagerTest::OnGetRootPath)); |
| 199 MessageLoop::current()->RunAllPending(); | 199 MessageLoop::current()->RunAllPending(); |
| 200 if (root_path) | 200 if (root_path) |
| 201 *root_path = root_path_; | 201 *root_path = root_path_; |
| 202 return root_path_callback_status_; | 202 return root_path_callback_status_; |
| 203 } | 203 } |
| 204 | 204 |
| 205 // TODO(ericu): Add a test for the new parameter. |
| 205 bool CheckValidFileSystemPath(FileSystemPathManager* manager, | 206 bool CheckValidFileSystemPath(FileSystemPathManager* manager, |
| 206 const FilePath& path) { | 207 const FilePath& path) { |
| 207 return manager->CrackFileSystemPath(path, NULL, NULL, NULL); | 208 return manager->CrackFileSystemPath(path, NULL, NULL, NULL, NULL); |
| 208 } | 209 } |
| 209 | 210 |
| 210 FilePath data_path() { return data_dir_->path(); } | 211 FilePath data_path() { return data_dir_->path(); } |
| 211 FilePath file_system_path() { | 212 FilePath file_system_path() { |
| 212 return data_dir_->path().Append( | 213 return data_dir_->path().Append( |
| 213 FileSystemPathManager::kFileSystemDirectory); | 214 FileSystemPathManager::kFileSystemDirectory); |
| 214 } | 215 } |
| 215 | 216 |
| 216 private: | 217 private: |
| 217 scoped_ptr<ScopedTempDir> data_dir_; | 218 scoped_ptr<ScopedTempDir> data_dir_; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 fileapi::kFileSystemTypeTemporary, | 349 fileapi::kFileSystemTypeTemporary, |
| 349 true /* create */, &root_path)); | 350 true /* create */, &root_path)); |
| 350 | 351 |
| 351 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPathToVirtualPathTestCases); ++i) { | 352 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPathToVirtualPathTestCases); ++i) { |
| 352 SCOPED_TRACE(testing::Message() << "PathToVirtualPath #" | 353 SCOPED_TRACE(testing::Message() << "PathToVirtualPath #" |
| 353 << i << " " << kPathToVirtualPathTestCases[i]); | 354 << i << " " << kPathToVirtualPathTestCases[i]); |
| 354 FilePath absolute_path = root_path.AppendASCII( | 355 FilePath absolute_path = root_path.AppendASCII( |
| 355 kPathToVirtualPathTestCases[i]); | 356 kPathToVirtualPathTestCases[i]); |
| 356 FilePath virtual_path; | 357 FilePath virtual_path; |
| 357 EXPECT_TRUE(manager->CrackFileSystemPath(absolute_path, NULL, NULL, | 358 EXPECT_TRUE(manager->CrackFileSystemPath(absolute_path, NULL, NULL, |
| 358 &virtual_path)); | 359 NULL, &virtual_path)); |
| 359 | 360 |
| 360 FilePath test_case_path; | 361 FilePath test_case_path; |
| 361 test_case_path = test_case_path.AppendASCII( | 362 test_case_path = test_case_path.AppendASCII( |
| 362 kPathToVirtualPathTestCases[i]); | 363 kPathToVirtualPathTestCases[i]); |
| 363 EXPECT_EQ(test_case_path.value(), virtual_path.value()); | 364 EXPECT_EQ(test_case_path.value(), virtual_path.value()); |
| 364 } | 365 } |
| 365 } | 366 } |
| 366 | 367 |
| 367 TEST_F(FileSystemPathManagerTest, TypeFromFileSystemPathTest) { | 368 TEST_F(FileSystemPathManagerTest, TypeFromFileSystemPathTest) { |
| 368 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | 369 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); |
| 369 | 370 |
| 370 FilePath root_path; | 371 FilePath root_path; |
| 371 fileapi::FileSystemType type; | 372 fileapi::FileSystemType type; |
| 372 | 373 |
| 373 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), | 374 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), |
| 374 fileapi::kFileSystemTypeTemporary, | 375 fileapi::kFileSystemTypeTemporary, |
| 375 true /* create */, &root_path)); | 376 true /* create */, &root_path)); |
| 376 FilePath path = root_path.AppendASCII("test"); | 377 FilePath path = root_path.AppendASCII("test"); |
| 377 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL)); | 378 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL, NULL)); |
| 378 EXPECT_EQ(fileapi::kFileSystemTypeTemporary, type); | 379 EXPECT_EQ(fileapi::kFileSystemTypeTemporary, type); |
| 379 | 380 |
| 380 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), | 381 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), |
| 381 fileapi::kFileSystemTypePersistent, | 382 fileapi::kFileSystemTypePersistent, |
| 382 true /* create */, &root_path)); | 383 true /* create */, &root_path)); |
| 383 path = root_path.AppendASCII("test"); | 384 path = root_path.AppendASCII("test"); |
| 384 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL)); | 385 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL, NULL)); |
| 385 EXPECT_EQ(fileapi::kFileSystemTypePersistent, type); | 386 EXPECT_EQ(fileapi::kFileSystemTypePersistent, type); |
| 386 } | 387 } |
| 387 | 388 |
| 388 TEST_F(FileSystemPathManagerTest, CheckValidPath) { | 389 TEST_F(FileSystemPathManagerTest, CheckValidPath) { |
| 389 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | 390 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); |
| 390 FilePath root_path; | 391 FilePath root_path; |
| 391 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), | 392 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), |
| 392 kFileSystemTypePersistent, true, &root_path)); | 393 kFileSystemTypePersistent, true, &root_path)); |
| 393 | 394 |
| 394 // The root path must be valid, but upper directories or directories | 395 // The root path must be valid, but upper directories or directories |
| (...skipping 22 matching lines...) Expand all Loading... |
| 417 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { | 418 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { |
| 418 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | 419 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); |
| 419 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { | 420 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { |
| 420 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " | 421 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " |
| 421 << kIsRestrictedNameTestCases[i].name); | 422 << kIsRestrictedNameTestCases[i].name); |
| 422 FilePath name(kIsRestrictedNameTestCases[i].name); | 423 FilePath name(kIsRestrictedNameTestCases[i].name); |
| 423 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, | 424 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, |
| 424 manager->IsRestrictedFileName(name)); | 425 manager->IsRestrictedFileName(name)); |
| 425 } | 426 } |
| 426 } | 427 } |
| OLD | NEW |