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 "chrome/browser/chromeos/drive/drive_file_system_util.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/message_loop.h" | |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "webkit/fileapi/external_mount_points.h" | |
12 #include "webkit/fileapi/file_system_context.h" | |
13 #include "webkit/fileapi/file_system_task_runners.h" | |
14 #include "webkit/fileapi/file_system_url.h" | |
15 #include "webkit/fileapi/isolated_context.h" | |
16 #include "webkit/fileapi/mock_file_system_options.h" | |
10 | 17 |
11 namespace drive { | 18 namespace drive { |
12 namespace util { | 19 namespace util { |
13 | 20 |
14 TEST(DriveFileSystemUtilTest, FilePathToDriveURL) { | 21 TEST(DriveFileSystemUtilTest, FilePathToDriveURL) { |
15 base::FilePath path; | 22 base::FilePath path; |
16 | 23 |
17 // Path with alphabets and numbers. | 24 // Path with alphabets and numbers. |
18 path = GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); | 25 path = GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); |
19 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); | 26 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 ExtractDrivePath( | 76 ExtractDrivePath( |
70 base::FilePath::FromUTF8Unsafe("/special/drive"))); | 77 base::FilePath::FromUTF8Unsafe("/special/drive"))); |
71 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), | 78 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), |
72 ExtractDrivePath( | 79 ExtractDrivePath( |
73 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); | 80 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); |
74 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"), | 81 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"), |
75 ExtractDrivePath(base::FilePath::FromUTF8Unsafe( | 82 ExtractDrivePath(base::FilePath::FromUTF8Unsafe( |
76 "/special/drive/subdir/foo.txt"))); | 83 "/special/drive/subdir/foo.txt"))); |
77 } | 84 } |
78 | 85 |
86 TEST(DriveFileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) { | |
87 // Set up file system context for testing. | |
88 MessageLoop message_loop; | |
89 scoped_refptr<fileapi::ExternalMountPoints> mount_points = | |
90 fileapi::ExternalMountPoints::CreateRefCounted(); | |
91 scoped_refptr<fileapi::FileSystemContext> context( | |
92 new fileapi::FileSystemContext( | |
93 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), | |
94 mount_points, | |
95 NULL, // special_storage_policy | |
96 NULL, // quota_manager_proxy, | |
97 base::FilePath::FromUTF8Unsafe("/tmp"), // partition_path | |
hashimoto
2013/04/08 06:03:49
Using "/tmp" seems not multi platform friendly.
Ho
kinaba
2013/04/08 06:43:41
Done.
| |
98 fileapi::CreateAllowFileAccessOptions())); | |
99 | |
100 // Type:"external" + virtual_path:"drive/foo/bar" resolves to "drive/foo/bar". | |
101 mount_points->RegisterRemoteFileSystem( | |
102 "drive", | |
103 fileapi::kFileSystemTypeDrive, | |
104 NULL, // RemoteFileSystemProxyInterface | |
105 base::FilePath::FromUTF8Unsafe("/special/drive")); | |
hashimoto
2013/04/08 06:03:49
How about using drive::util::GetDriveMountPointPat
kinaba
2013/04/08 06:43:41
Done (and added a test for the case "drive" is not
| |
106 EXPECT_EQ( | |
107 base::FilePath::FromUTF8Unsafe("drive/foo/bar"), | |
108 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( | |
109 "filesystem:chrome-extension://dummy-id/external/drive/foo/bar")))); | |
110 | |
111 // Type:"external" + virtual_path:"Downloads/foo" is not a Drive path. | |
112 mount_points->RegisterFileSystem( | |
113 "Downloads", | |
114 fileapi::kFileSystemTypeNativeLocal, | |
115 base::FilePath::FromUTF8Unsafe("/tmp")); | |
116 EXPECT_EQ( | |
117 base::FilePath(), | |
118 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( | |
119 "filesystem:chrome-extension://dummy-id/external/Downloads/foo")))); | |
120 | |
121 // Type:"isolated" + virtual_path:"isolated_id/name" mapped on a Drive path. | |
122 std::string isolated_name; | |
123 std::string isolated_id = | |
124 fileapi::IsolatedContext::GetInstance()->RegisterFileSystemForPath( | |
125 fileapi::kFileSystemTypeNativeForPlatformApp, | |
126 base::FilePath::FromUTF8Unsafe("/special/drive/bar/buz"), | |
hashimoto
2013/04/08 06:03:49
How about using GetDriveMountPointPath()?
kinaba
2013/04/08 06:43:41
Done.
| |
127 &isolated_name); | |
128 EXPECT_EQ( | |
129 base::FilePath::FromUTF8Unsafe("drive/bar/buz"), | |
130 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( | |
131 "filesystem:chrome-extension://dummy-id/isolated/" + | |
132 isolated_id + "/" + isolated_name)))); | |
133 } | |
134 | |
79 TEST(DriveFileSystemUtilTest, EscapeUnescapeCacheFileName) { | 135 TEST(DriveFileSystemUtilTest, EscapeUnescapeCacheFileName) { |
80 const std::string kUnescapedFileName( | 136 const std::string kUnescapedFileName( |
81 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); | 137 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); |
82 const std::string kEscapedFileName( | 138 const std::string kEscapedFileName( |
83 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); | 139 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); |
84 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); | 140 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); |
85 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); | 141 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); |
86 } | 142 } |
87 | 143 |
88 TEST(DriveFileSystemUtilTest, EscapeUtf8FileName) { | 144 TEST(DriveFileSystemUtilTest, EscapeUtf8FileName) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 EXPECT_FALSE(util::IsSpecialResourceId("file:123")); | 242 EXPECT_FALSE(util::IsSpecialResourceId("file:123")); |
187 EXPECT_FALSE(util::IsSpecialResourceId("folder:root")); | 243 EXPECT_FALSE(util::IsSpecialResourceId("folder:root")); |
188 EXPECT_FALSE(util::IsSpecialResourceId("folder:xyz")); | 244 EXPECT_FALSE(util::IsSpecialResourceId("folder:xyz")); |
189 | 245 |
190 EXPECT_TRUE(util::IsSpecialResourceId("<drive>")); | 246 EXPECT_TRUE(util::IsSpecialResourceId("<drive>")); |
191 EXPECT_TRUE(util::IsSpecialResourceId("<other>")); | 247 EXPECT_TRUE(util::IsSpecialResourceId("<other>")); |
192 } | 248 } |
193 | 249 |
194 } // namespace util | 250 } // namespace util |
195 } // namespace drive | 251 } // namespace drive |
OLD | NEW |