| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/basictypes.h" | |
| 6 #include "base/file_path.h" | |
| 7 #include "base/scoped_ptr.h" | |
| 8 #include "chrome/browser/file_system/file_system_host_context.h" | |
| 9 #include "chrome/browser/file_system/file_system_host_context.h" | |
| 10 #include "googleurl/src/gurl.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // PS stands for path separator. | |
| 17 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | |
| 18 #define PS "\\" | |
| 19 #else | |
| 20 #define PS "/" | |
| 21 #endif | |
| 22 | |
| 23 const FilePath::CharType kTestDataPath[] = FILE_PATH_LITERAL( | |
| 24 "//tmp/TestingProfilePath"); | |
| 25 | |
| 26 const struct RootPathTest { | |
| 27 WebKit::WebFileSystem::Type type; | |
| 28 bool off_the_record; | |
| 29 const char* origin_url; | |
| 30 bool expect_root_path; | |
| 31 const char* expected_path; | |
| 32 } kRootPathTestCases[] = { | |
| 33 { WebKit::WebFileSystem::TypeTemporary, false, "http://host:1/", | |
| 34 true, "FileSystem" PS "http_host_1" PS "Temporary" }, | |
| 35 { WebKit::WebFileSystem::TypePersistent, false, "http://host:2/", | |
| 36 true, "FileSystem" PS "http_host_2" PS "Persistent" }, | |
| 37 { WebKit::WebFileSystem::TypeTemporary, true, "http://host:3/", | |
| 38 false, "" }, | |
| 39 { WebKit::WebFileSystem::TypePersistent, true, "http://host:4/", | |
| 40 false, "" }, | |
| 41 }; | |
| 42 | |
| 43 const struct CheckValidPathTest { | |
| 44 FilePath::StringType path; | |
| 45 bool expected_valid; | |
| 46 } kCheckValidPathTestCases[] = { | |
| 47 { FILE_PATH_LITERAL("//tmp/foo.txt"), false, }, | |
| 48 { FILE_PATH_LITERAL("//etc/hosts"), false, }, | |
| 49 { FILE_PATH_LITERAL("foo.txt"), true, }, | |
| 50 { FILE_PATH_LITERAL("a/b/c"), true, }, | |
| 51 // Any paths that includes parent references are considered invalid. | |
| 52 { FILE_PATH_LITERAL(".."), false, }, | |
| 53 { FILE_PATH_LITERAL("tmp/.."), false, }, | |
| 54 { FILE_PATH_LITERAL("a/b/../c/.."), false, }, | |
| 55 }; | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 59 TEST(FileSystemHostContextTest, GetRootPath) { | |
| 60 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | |
| 61 SCOPED_TRACE(testing::Message() << "RootPath #" << i << " " | |
| 62 << kRootPathTestCases[i].expected_path); | |
| 63 | |
| 64 scoped_refptr<FileSystemHostContext> context( | |
| 65 new FileSystemHostContext(FilePath(kTestDataPath), | |
| 66 kRootPathTestCases[i].off_the_record)); | |
| 67 | |
| 68 FilePath root_path; | |
| 69 bool result = context->GetFileSystemRootPath( | |
| 70 GURL(kRootPathTestCases[i].origin_url), | |
| 71 kRootPathTestCases[i].type, | |
| 72 &root_path, NULL); | |
| 73 EXPECT_EQ(kRootPathTestCases[i].expect_root_path, result); | |
| 74 if (result) { | |
| 75 FilePath expected = FilePath(kTestDataPath).AppendASCII( | |
| 76 kRootPathTestCases[i].expected_path); | |
| 77 EXPECT_EQ(expected.value(), root_path.value()); | |
| 78 } | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 TEST(FileSystemHostContextTest, CheckValidPath) { | |
| 83 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kCheckValidPathTestCases); ++i) { | |
| 84 SCOPED_TRACE(testing::Message() << "CheckValidPath #" << i << " " | |
| 85 << kCheckValidPathTestCases[i].path); | |
| 86 | |
| 87 scoped_refptr<FileSystemHostContext> context( | |
| 88 new FileSystemHostContext(FilePath(kTestDataPath), false)); | |
| 89 | |
| 90 FilePath root_path; | |
| 91 EXPECT_TRUE(context->GetFileSystemRootPath( | |
| 92 GURL("http://foo.com/"), WebKit::WebFileSystem::TypePersistent, | |
| 93 &root_path, NULL)); | |
| 94 FilePath path(kCheckValidPathTestCases[i].path); | |
| 95 if (!path.IsAbsolute()) | |
| 96 path = root_path.Append(path); | |
| 97 | |
| 98 EXPECT_EQ(kCheckValidPathTestCases[i].expected_valid, | |
| 99 context->CheckValidFileSystemPath(path)); | |
| 100 } | |
| 101 } | |
| OLD | NEW |