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(GURL(url_string)); |
| 30 switch (url.type()) { |
| 31 case kFileSystemTypeExternal: |
| 32 return ExternalMountPoints::GetSystemInstance()->CrackURL(url); |
| 33 case kFileSystemTypeIsolated: |
| 34 return IsolatedContext::GetInstance()->CrackURL(url); |
| 35 default: |
| 36 return url; |
| 37 } |
| 38 } |
| 39 |
| 40 FileSystemURL CreateExternalFileSystemURL(const GURL& origin, |
| 41 FileSystemType type, |
| 42 const FilePath& path) { |
| 43 FileSystemURL url(origin, type, path); |
| 44 return ExternalMountPoints::GetSystemInstance()->CrackURL(url); |
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 233 |
219 const FileSystemURL kURL1(kOrigin, kFileSystemTypeTemporary, kPath); | 234 const FileSystemURL kURL1(kOrigin, kFileSystemTypeTemporary, kPath); |
220 EXPECT_EQ("filesystem:http://example.com/temporary/" + | 235 EXPECT_EQ("filesystem:http://example.com/temporary/" + |
221 NormalizedUTF8Path(kPath), | 236 NormalizedUTF8Path(kPath), |
222 kURL1.DebugString()); | 237 kURL1.DebugString()); |
223 | 238 |
224 const FilePath kRoot(DRIVE FPL("/root")); | 239 const FilePath kRoot(DRIVE FPL("/root")); |
225 ScopedExternalFileSystem scoped_fs("foo", | 240 ScopedExternalFileSystem scoped_fs("foo", |
226 kFileSystemTypeNativeLocal, | 241 kFileSystemTypeNativeLocal, |
227 kRoot.NormalizePathSeparators()); | 242 kRoot.NormalizePathSeparators()); |
228 const FileSystemURL kURL2(kOrigin, kFileSystemTypeExternal, | 243 const FileSystemURL kURL2(CreateExternalFileSystemURL( |
229 scoped_fs.GetVirtualRootPath().Append(kPath)); | 244 kOrigin, |
| 245 kFileSystemTypeExternal, |
| 246 scoped_fs.GetVirtualRootPath().Append(kPath))); |
230 EXPECT_EQ("filesystem:http://example.com/external/" + | 247 EXPECT_EQ("filesystem:http://example.com/external/" + |
231 NormalizedUTF8Path(scoped_fs.GetVirtualRootPath().Append(kPath)) + | 248 NormalizedUTF8Path(scoped_fs.GetVirtualRootPath().Append(kPath)) + |
232 " (NativeLocal@foo:" + | 249 " (NativeLocal@foo:" + |
233 NormalizedUTF8Path(kRoot.Append(kPath)) + ")", | 250 NormalizedUTF8Path(kRoot.Append(kPath)) + ")", |
234 kURL2.DebugString()); | 251 kURL2.DebugString()); |
235 } | 252 } |
236 | 253 |
237 } // namespace fileapi | 254 } // namespace fileapi |
OLD | NEW |