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

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

Issue 6286038: Add initial code to do filename munging in the FileSystem.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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) 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool CheckValidFileSystemPath(FileSystemPathManager* manager, 205 bool CheckValidFileSystemPath(FileSystemPathManager* manager,
206 const FilePath& path) { 206 const FilePath& path) {
207 return manager->CrackFileSystemPath(path, NULL, NULL, NULL); 207 return manager->CrackFileSystemPath(path, NULL, NULL, NULL, NULL);
208 } 208 }
209 209
210 FilePath data_path() { return data_dir_->path(); } 210 FilePath data_path() { return data_dir_->path(); }
211 FilePath file_system_path() { 211 FilePath file_system_path() {
212 return data_dir_->path().Append( 212 return data_dir_->path().Append(
213 FileSystemPathManager::kFileSystemDirectory); 213 FileSystemPathManager::kFileSystemDirectory);
214 } 214 }
215 215
216 private: 216 private:
217 scoped_ptr<ScopedTempDir> data_dir_; 217 scoped_ptr<ScopedTempDir> data_dir_;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 fileapi::kFileSystemTypeTemporary, 348 fileapi::kFileSystemTypeTemporary,
349 true /* create */, &root_path)); 349 true /* create */, &root_path));
350 350
351 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPathToVirtualPathTestCases); ++i) { 351 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPathToVirtualPathTestCases); ++i) {
352 SCOPED_TRACE(testing::Message() << "PathToVirtualPath #" 352 SCOPED_TRACE(testing::Message() << "PathToVirtualPath #"
353 << i << " " << kPathToVirtualPathTestCases[i]); 353 << i << " " << kPathToVirtualPathTestCases[i]);
354 FilePath absolute_path = root_path.AppendASCII( 354 FilePath absolute_path = root_path.AppendASCII(
355 kPathToVirtualPathTestCases[i]); 355 kPathToVirtualPathTestCases[i]);
356 FilePath virtual_path; 356 FilePath virtual_path;
357 EXPECT_TRUE(manager->CrackFileSystemPath(absolute_path, NULL, NULL, 357 EXPECT_TRUE(manager->CrackFileSystemPath(absolute_path, NULL, NULL,
358 &virtual_path)); 358 NULL, &virtual_path));
359 359
360 FilePath test_case_path; 360 FilePath test_case_path;
361 test_case_path = test_case_path.AppendASCII( 361 test_case_path = test_case_path.AppendASCII(
362 kPathToVirtualPathTestCases[i]); 362 kPathToVirtualPathTestCases[i]);
363 EXPECT_EQ(test_case_path.value(), virtual_path.value()); 363 EXPECT_EQ(test_case_path.value(), virtual_path.value());
364 } 364 }
365 } 365 }
366 366
367 TEST_F(FileSystemPathManagerTest, TypeFromFileSystemPathTest) { 367 TEST_F(FileSystemPathManagerTest, TypeFromFileSystemPathTest) {
368 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); 368 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
369 369
370 FilePath root_path; 370 FilePath root_path;
371 fileapi::FileSystemType type; 371 fileapi::FileSystemType type;
372 372
373 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), 373 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"),
374 fileapi::kFileSystemTypeTemporary, 374 fileapi::kFileSystemTypeTemporary,
375 true /* create */, &root_path)); 375 true /* create */, &root_path));
376 FilePath path = root_path.AppendASCII("test"); 376 FilePath path = root_path.AppendASCII("test");
377 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL)); 377 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL, NULL));
378 EXPECT_EQ(fileapi::kFileSystemTypeTemporary, type); 378 EXPECT_EQ(fileapi::kFileSystemTypeTemporary, type);
379 379
380 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), 380 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"),
381 fileapi::kFileSystemTypePersistent, 381 fileapi::kFileSystemTypePersistent,
382 true /* create */, &root_path)); 382 true /* create */, &root_path));
383 path = root_path.AppendASCII("test"); 383 path = root_path.AppendASCII("test");
384 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL)); 384 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL, NULL));
385 EXPECT_EQ(fileapi::kFileSystemTypePersistent, type); 385 EXPECT_EQ(fileapi::kFileSystemTypePersistent, type);
386 } 386 }
387 387
388 TEST_F(FileSystemPathManagerTest, CheckValidPath) { 388 TEST_F(FileSystemPathManagerTest, CheckValidPath) {
389 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); 389 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
390 FilePath root_path; 390 FilePath root_path;
391 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), 391 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"),
392 kFileSystemTypePersistent, true, &root_path)); 392 kFileSystemTypePersistent, true, &root_path));
393 393
394 // The root path must be valid, but upper directories or directories 394 // The root path must be valid, but upper directories or directories
(...skipping 22 matching lines...) Expand all
417 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { 417 TEST_F(FileSystemPathManagerTest, IsRestrictedName) {
418 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); 418 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
419 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { 419 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) {
420 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " 420 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " "
421 << kIsRestrictedNameTestCases[i].name); 421 << kIsRestrictedNameTestCases[i].name);
422 FilePath name(kIsRestrictedNameTestCases[i].name); 422 FilePath name(kIsRestrictedNameTestCases[i].name);
423 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, 423 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous,
424 manager->IsRestrictedFileName(name)); 424 manager->IsRestrictedFileName(name));
425 } 425 }
426 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698