OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_url.h" | 5 #include "webkit/fileapi/file_system_url.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "webkit/fileapi/external_mount_points.h" | 10 #include "webkit/fileapi/external_mount_points.h" |
11 #include "webkit/fileapi/file_system_types.h" | 11 #include "webkit/fileapi/file_system_types.h" |
12 #include "webkit/fileapi/file_system_util.h" | 12 #include "webkit/fileapi/file_system_util.h" |
13 #include "webkit/fileapi/isolated_context.h" | 13 #include "webkit/fileapi/isolated_context.h" |
14 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | 14 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
15 | 15 |
16 #define FPL FILE_PATH_LITERAL | 16 #define FPL FILE_PATH_LITERAL |
17 | 17 |
18 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 18 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
19 #define DRIVE FPL("C:") | 19 #define DRIVE FPL("C:") |
20 #else | 20 #else |
21 #define DRIVE FPL("/a/") | 21 #define DRIVE FPL("/a/") |
22 #endif | 22 #endif |
23 | 23 |
24 namespace fileapi { | 24 namespace fileapi { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 FileSystemURL CreateFileSystemURL(const std::string& url_string) { | 28 FileSystemURL CreateFileSystemURL(const std::string& url_string) { |
29 return FileSystemURL(GURL(url_string)); | 29 FileSystemURL url = FileSystemURL::CreateForTest(GURL(url_string)); |
| 30 switch (url.type()) { |
| 31 case kFileSystemTypeExternal: |
| 32 return ExternalMountPoints::GetSystemInstance()->CrackFileSystemURL(url); |
| 33 case kFileSystemTypeIsolated: |
| 34 return IsolatedContext::GetInstance()->CrackFileSystemURL(url); |
| 35 default: |
| 36 return url; |
| 37 } |
| 38 } |
| 39 |
| 40 FileSystemURL CreateExternalFileSystemURL(const GURL& origin, |
| 41 FileSystemType type, |
| 42 const FilePath& path) { |
| 43 return ExternalMountPoints::GetSystemInstance()->CreateCrackedFileSystemURL( |
| 44 origin, type, path); |
30 } | 45 } |
31 | 46 |
32 std::string NormalizedUTF8Path(const FilePath& path) { | 47 std::string NormalizedUTF8Path(const FilePath& path) { |
33 return path.NormalizePathSeparators().AsUTF8Unsafe(); | 48 return path.NormalizePathSeparators().AsUTF8Unsafe(); |
34 } | 49 } |
35 | 50 |
36 } // namespace | 51 } // namespace |
37 | 52 |
38 TEST(FileSystemURLTest, ParsePersistent) { | 53 TEST(FileSystemURLTest, ParsePersistent) { |
39 FileSystemURL url = CreateFileSystemURL( | 54 FileSystemURL url = CreateFileSystemURL( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 GURL("filesystem:http://chromium.org/temporary/dir aa/file b"), | 116 GURL("filesystem:http://chromium.org/temporary/dir aa/file b"), |
102 GURL("filesystem:http://chromium.com/temporary/dir a/file a"), | 117 GURL("filesystem:http://chromium.com/temporary/dir a/file a"), |
103 GURL("filesystem:https://chromium.org/temporary/dir a/file a") | 118 GURL("filesystem:https://chromium.org/temporary/dir a/file a") |
104 }; | 119 }; |
105 | 120 |
106 FileSystemURL::Comparator compare; | 121 FileSystemURL::Comparator compare; |
107 for (size_t i = 0; i < arraysize(urls); ++i) { | 122 for (size_t i = 0; i < arraysize(urls); ++i) { |
108 for (size_t j = 0; j < arraysize(urls); ++j) { | 123 for (size_t j = 0; j < arraysize(urls); ++j) { |
109 SCOPED_TRACE(testing::Message() << i << " < " << j); | 124 SCOPED_TRACE(testing::Message() << i << " < " << j); |
110 EXPECT_EQ(urls[i] < urls[j], | 125 EXPECT_EQ(urls[i] < urls[j], |
111 compare(FileSystemURL(urls[i]), FileSystemURL(urls[j]))); | 126 compare(FileSystemURL::CreateForTest(urls[i]), |
| 127 FileSystemURL::CreateForTest(urls[j]))); |
112 } | 128 } |
113 } | 129 } |
114 | 130 |
115 const FileSystemURL a = CreateFileSystemURL( | 131 const FileSystemURL a = CreateFileSystemURL( |
116 "filesystem:http://chromium.org/temporary/dir a/file a"); | 132 "filesystem:http://chromium.org/temporary/dir a/file a"); |
117 const FileSystemURL b = CreateFileSystemURL( | 133 const FileSystemURL b = CreateFileSystemURL( |
118 "filesystem:http://chromium.org/persistent/dir a/file a"); | 134 "filesystem:http://chromium.org/persistent/dir a/file a"); |
119 EXPECT_EQ(a.type() < b.type(), compare(a, b)); | 135 EXPECT_EQ(a.type() < b.type(), compare(a, b)); |
120 EXPECT_EQ(b.type() < a.type(), compare(b, a)); | 136 EXPECT_EQ(b.type() < a.type(), compare(b, a)); |
121 } | 137 } |
122 | 138 |
123 TEST(FileSystemURLTest, WithPath) { | 139 TEST(FileSystemURLTest, WithPath) { |
124 const GURL kURL("filesystem:http://chromium.org/temporary/dir"); | 140 const GURL kURL("filesystem:http://chromium.org/temporary/dir"); |
125 const FilePath::StringType paths[] = { | 141 const FilePath::StringType paths[] = { |
126 FPL("dir a"), | 142 FPL("dir a"), |
127 FPL("dir a/file 1"), | 143 FPL("dir a/file 1"), |
128 FPL("dir a/dir b"), | 144 FPL("dir a/dir b"), |
129 FPL("dir a/dir b/file 2"), | 145 FPL("dir a/dir b/file 2"), |
130 }; | 146 }; |
131 | 147 |
132 const FileSystemURL base = FileSystemURL(kURL); | 148 const FileSystemURL base = FileSystemURL::CreateForTest(kURL); |
133 for (size_t i = 0; i < arraysize(paths); ++i) { | 149 for (size_t i = 0; i < arraysize(paths); ++i) { |
134 const FileSystemURL url = base.WithPath(FilePath(paths[i])); | 150 const FileSystemURL url = base.WithPath(FilePath(paths[i])); |
135 EXPECT_EQ(paths[i], url.path().value()); | 151 EXPECT_EQ(paths[i], url.path().value()); |
136 EXPECT_EQ(base.origin().spec(), url.origin().spec()); | 152 EXPECT_EQ(base.origin().spec(), url.origin().spec()); |
137 EXPECT_EQ(base.type(), url.type()); | 153 EXPECT_EQ(base.type(), url.type()); |
138 EXPECT_EQ(base.mount_type(), url.mount_type()); | 154 EXPECT_EQ(base.mount_type(), url.mount_type()); |
139 EXPECT_EQ(base.filesystem_id(), url.filesystem_id()); | 155 EXPECT_EQ(base.filesystem_id(), url.filesystem_id()); |
140 } | 156 } |
141 } | 157 } |
142 | 158 |
143 TEST(FileSystemURLTest, WithPathForExternal) { | 159 TEST(FileSystemURLTest, WithPathForExternal) { |
144 const std::string kId = "foo"; | 160 const std::string kId = "foo"; |
145 ScopedExternalFileSystem scoped_fs(kId, kFileSystemTypeSyncable, FilePath()); | 161 ScopedExternalFileSystem scoped_fs(kId, kFileSystemTypeSyncable, FilePath()); |
146 const FilePath kVirtualRoot = scoped_fs.GetVirtualRootPath(); | 162 const FilePath kVirtualRoot = scoped_fs.GetVirtualRootPath(); |
147 | 163 |
148 const FilePath::CharType kBasePath[] = FPL("dir"); | 164 const FilePath::CharType kBasePath[] = FPL("dir"); |
149 const FilePath::StringType paths[] = { | 165 const FilePath::StringType paths[] = { |
150 FPL("dir a"), | 166 FPL("dir a"), |
151 FPL("dir a/file 1"), | 167 FPL("dir a/file 1"), |
152 FPL("dir a/dir b"), | 168 FPL("dir a/dir b"), |
153 FPL("dir a/dir b/file 2"), | 169 FPL("dir a/dir b/file 2"), |
154 }; | 170 }; |
155 | 171 |
156 const FileSystemURL base = FileSystemURL( | 172 const FileSystemURL base = FileSystemURL::CreateForTest( |
157 GURL("http://example.com/"), | 173 GURL("http://example.com/"), |
158 kFileSystemTypeExternal, | 174 kFileSystemTypeExternal, |
159 kVirtualRoot.Append(kBasePath)); | 175 kVirtualRoot.Append(kBasePath)); |
160 | 176 |
161 for (size_t i = 0; i < arraysize(paths); ++i) { | 177 for (size_t i = 0; i < arraysize(paths); ++i) { |
162 const FileSystemURL url = base.WithPath(FilePath(paths[i])); | 178 const FileSystemURL url = base.WithPath(FilePath(paths[i])); |
163 EXPECT_EQ(paths[i], url.path().value()); | 179 EXPECT_EQ(paths[i], url.path().value()); |
164 EXPECT_EQ(base.origin().spec(), url.origin().spec()); | 180 EXPECT_EQ(base.origin().spec(), url.origin().spec()); |
165 EXPECT_EQ(base.type(), url.type()); | 181 EXPECT_EQ(base.type(), url.type()); |
166 EXPECT_EQ(base.mount_type(), url.mount_type()); | 182 EXPECT_EQ(base.mount_type(), url.mount_type()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 225 |
210 // False case: different origins. | 226 // False case: different origins. |
211 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( | 227 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( |
212 CreateFileSystemURL(root4 + child))); | 228 CreateFileSystemURL(root4 + child))); |
213 } | 229 } |
214 | 230 |
215 TEST(FileSystemURLTest, DebugString) { | 231 TEST(FileSystemURLTest, DebugString) { |
216 const GURL kOrigin("http://example.com"); | 232 const GURL kOrigin("http://example.com"); |
217 const FilePath kPath(FPL("dir/file")); | 233 const FilePath kPath(FPL("dir/file")); |
218 | 234 |
219 const FileSystemURL kURL1(kOrigin, kFileSystemTypeTemporary, kPath); | 235 const FileSystemURL kURL1 = FileSystemURL::CreateForTest( |
| 236 kOrigin, kFileSystemTypeTemporary, kPath); |
220 EXPECT_EQ("filesystem:http://example.com/temporary/" + | 237 EXPECT_EQ("filesystem:http://example.com/temporary/" + |
221 NormalizedUTF8Path(kPath), | 238 NormalizedUTF8Path(kPath), |
222 kURL1.DebugString()); | 239 kURL1.DebugString()); |
223 | 240 |
224 const FilePath kRoot(DRIVE FPL("/root")); | 241 const FilePath kRoot(DRIVE FPL("/root")); |
225 ScopedExternalFileSystem scoped_fs("foo", | 242 ScopedExternalFileSystem scoped_fs("foo", |
226 kFileSystemTypeNativeLocal, | 243 kFileSystemTypeNativeLocal, |
227 kRoot.NormalizePathSeparators()); | 244 kRoot.NormalizePathSeparators()); |
228 const FileSystemURL kURL2(kOrigin, kFileSystemTypeExternal, | 245 const FileSystemURL kURL2(CreateExternalFileSystemURL( |
229 scoped_fs.GetVirtualRootPath().Append(kPath)); | 246 kOrigin, |
| 247 kFileSystemTypeExternal, |
| 248 scoped_fs.GetVirtualRootPath().Append(kPath))); |
230 EXPECT_EQ("filesystem:http://example.com/external/" + | 249 EXPECT_EQ("filesystem:http://example.com/external/" + |
231 NormalizedUTF8Path(scoped_fs.GetVirtualRootPath().Append(kPath)) + | 250 NormalizedUTF8Path(scoped_fs.GetVirtualRootPath().Append(kPath)) + |
232 " (NativeLocal@foo:" + | 251 " (NativeLocal@foo:" + |
233 NormalizedUTF8Path(kRoot.Append(kPath)) + ")", | 252 NormalizedUTF8Path(kRoot.Append(kPath)) + ")", |
234 kURL2.DebugString()); | 253 kURL2.DebugString()); |
235 } | 254 } |
236 | 255 |
237 } // namespace fileapi | 256 } // namespace fileapi |
OLD | NEW |