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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "chrome/browser/file_system/file_system_host_context.h" | 8 #include "chrome/browser/file_system/file_system_host_context.h" |
9 #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" | 10 #include "googleurl/src/gurl.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" | |
13 | 12 |
14 namespace { | 13 namespace { |
15 | 14 |
16 // PS stands for path separator. | 15 // PS stands for path separator. |
17 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 16 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
18 #define PS "\\" | 17 #define PS "\\" |
19 #else | 18 #else |
20 #define PS "/" | 19 #define PS "/" |
21 #endif | 20 #endif |
22 | 21 |
23 const FilePath::CharType kTestDataPath[] = FILE_PATH_LITERAL( | 22 const FilePath::CharType kTestDataPath[] = FILE_PATH_LITERAL( |
24 "//tmp/TestingProfilePath"); | 23 "//tmp/TestingProfilePath"); |
25 | 24 |
26 const struct RootPathTest { | 25 const struct RootPathTest { |
27 WebKit::WebFileSystem::Type type; | 26 fileapi::FileSystemType type; |
28 bool off_the_record; | 27 bool off_the_record; |
29 const char* origin_url; | 28 const char* origin_url; |
30 bool expect_root_path; | 29 bool expect_root_path; |
31 const char* expected_path; | 30 const char* expected_path; |
32 } kRootPathTestCases[] = { | 31 } kRootPathTestCases[] = { |
33 { WebKit::WebFileSystem::TypeTemporary, false, "http://host:1/", | 32 { fileapi::kFileSystemTypeTemporary, false, "http://host:1/", |
34 true, "FileSystem" PS "http_host_1" PS "Temporary" }, | 33 true, "FileSystem" PS "http_host_1" PS "Temporary" }, |
35 { WebKit::WebFileSystem::TypePersistent, false, "http://host:2/", | 34 { fileapi::kFileSystemTypePersistent, false, "http://host:2/", |
36 true, "FileSystem" PS "http_host_2" PS "Persistent" }, | 35 true, "FileSystem" PS "http_host_2" PS "Persistent" }, |
37 { WebKit::WebFileSystem::TypeTemporary, true, "http://host:3/", | 36 { fileapi::kFileSystemTypeTemporary, true, "http://host:3/", |
38 false, "" }, | 37 false, "" }, |
39 { WebKit::WebFileSystem::TypePersistent, true, "http://host:4/", | 38 { fileapi::kFileSystemTypePersistent, true, "http://host:4/", |
40 false, "" }, | 39 false, "" }, |
41 }; | 40 }; |
42 | 41 |
43 const struct CheckValidPathTest { | 42 const struct CheckValidPathTest { |
44 FilePath::StringType path; | 43 FilePath::StringType path; |
45 bool expected_valid; | 44 bool expected_valid; |
46 } kCheckValidPathTestCases[] = { | 45 } kCheckValidPathTestCases[] = { |
47 { FILE_PATH_LITERAL("//tmp/foo.txt"), false, }, | 46 { FILE_PATH_LITERAL("//tmp/foo.txt"), false, }, |
48 { FILE_PATH_LITERAL("//etc/hosts"), false, }, | 47 { FILE_PATH_LITERAL("//etc/hosts"), false, }, |
49 { FILE_PATH_LITERAL("foo.txt"), true, }, | 48 { FILE_PATH_LITERAL("foo.txt"), true, }, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 TEST(FileSystemHostContextTest, CheckValidPath) { | 81 TEST(FileSystemHostContextTest, CheckValidPath) { |
83 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kCheckValidPathTestCases); ++i) { | 82 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kCheckValidPathTestCases); ++i) { |
84 SCOPED_TRACE(testing::Message() << "CheckValidPath #" << i << " " | 83 SCOPED_TRACE(testing::Message() << "CheckValidPath #" << i << " " |
85 << kCheckValidPathTestCases[i].path); | 84 << kCheckValidPathTestCases[i].path); |
86 | 85 |
87 scoped_refptr<FileSystemHostContext> context( | 86 scoped_refptr<FileSystemHostContext> context( |
88 new FileSystemHostContext(FilePath(kTestDataPath), false)); | 87 new FileSystemHostContext(FilePath(kTestDataPath), false)); |
89 | 88 |
90 FilePath root_path; | 89 FilePath root_path; |
91 EXPECT_TRUE(context->GetFileSystemRootPath( | 90 EXPECT_TRUE(context->GetFileSystemRootPath( |
92 GURL("http://foo.com/"), WebKit::WebFileSystem::TypePersistent, | 91 GURL("http://foo.com/"), fileapi::kFileSystemTypePersistent, |
93 &root_path, NULL)); | 92 &root_path, NULL)); |
94 FilePath path(kCheckValidPathTestCases[i].path); | 93 FilePath path(kCheckValidPathTestCases[i].path); |
95 if (!path.IsAbsolute()) | 94 if (!path.IsAbsolute()) |
96 path = root_path.Append(path); | 95 path = root_path.Append(path); |
97 | 96 |
98 EXPECT_EQ(kCheckValidPathTestCases[i].expected_valid, | 97 EXPECT_EQ(kCheckValidPathTestCases[i].expected_valid, |
99 context->CheckValidFileSystemPath(path)); | 98 context->CheckValidFileSystemPath(path)); |
100 } | 99 } |
101 } | 100 } |
OLD | NEW |