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/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop.h" |
8 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "webkit/fileapi/external_mount_points.h" |
| 13 #include "webkit/fileapi/file_system_context.h" |
| 14 #include "webkit/fileapi/file_system_task_runners.h" |
| 15 #include "webkit/fileapi/file_system_url.h" |
| 16 #include "webkit/fileapi/isolated_context.h" |
| 17 #include "webkit/fileapi/mock_file_system_options.h" |
10 | 18 |
11 namespace drive { | 19 namespace drive { |
12 namespace util { | 20 namespace util { |
13 | 21 |
14 TEST(DriveFileSystemUtilTest, FilePathToDriveURL) { | 22 TEST(DriveFileSystemUtilTest, FilePathToDriveURL) { |
15 base::FilePath path; | 23 base::FilePath path; |
16 | 24 |
17 // Path with alphabets and numbers. | 25 // Path with alphabets and numbers. |
18 path = GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); | 26 path = GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); |
19 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); | 27 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 ExtractDrivePath( | 77 ExtractDrivePath( |
70 base::FilePath::FromUTF8Unsafe("/special/drive"))); | 78 base::FilePath::FromUTF8Unsafe("/special/drive"))); |
71 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), | 79 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), |
72 ExtractDrivePath( | 80 ExtractDrivePath( |
73 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); | 81 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); |
74 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"), | 82 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"), |
75 ExtractDrivePath(base::FilePath::FromUTF8Unsafe( | 83 ExtractDrivePath(base::FilePath::FromUTF8Unsafe( |
76 "/special/drive/subdir/foo.txt"))); | 84 "/special/drive/subdir/foo.txt"))); |
77 } | 85 } |
78 | 86 |
| 87 TEST(DriveFileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) { |
| 88 // Set up file system context for testing. |
| 89 base::ScopedTempDir temp_dir_; |
| 90 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 91 |
| 92 MessageLoop message_loop; |
| 93 scoped_refptr<fileapi::ExternalMountPoints> mount_points = |
| 94 fileapi::ExternalMountPoints::CreateRefCounted(); |
| 95 scoped_refptr<fileapi::FileSystemContext> context( |
| 96 new fileapi::FileSystemContext( |
| 97 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), |
| 98 mount_points, |
| 99 NULL, // special_storage_policy |
| 100 NULL, // quota_manager_proxy, |
| 101 temp_dir_.path(), // partition_path |
| 102 fileapi::CreateAllowFileAccessOptions())); |
| 103 |
| 104 // Type:"external" + virtual_path:"drive/foo/bar" resolves to "drive/foo/bar". |
| 105 const std::string& drive_mount_name = |
| 106 GetDriveMountPointPath().BaseName().AsUTF8Unsafe(); |
| 107 mount_points->RegisterRemoteFileSystem( |
| 108 drive_mount_name, |
| 109 fileapi::kFileSystemTypeDrive, |
| 110 NULL, // RemoteFileSystemProxyInterface |
| 111 GetDriveMountPointPath()); |
| 112 EXPECT_EQ( |
| 113 base::FilePath::FromUTF8Unsafe(drive_mount_name + "/foo/bar"), |
| 114 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( |
| 115 "filesystem:chrome-extension://dummy-id/external/" + |
| 116 drive_mount_name + "/foo/bar")))); |
| 117 |
| 118 // Virtual mount name should not affect the extracted path. |
| 119 mount_points->RevokeFileSystem(drive_mount_name); |
| 120 mount_points->RegisterRemoteFileSystem( |
| 121 "drive2", |
| 122 fileapi::kFileSystemTypeDrive, |
| 123 NULL, // RemoteFileSystemProxyInterface |
| 124 GetDriveMountPointPath()); |
| 125 EXPECT_EQ( |
| 126 base::FilePath::FromUTF8Unsafe(drive_mount_name + "/foo/bar"), |
| 127 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( |
| 128 "filesystem:chrome-extension://dummy-id/external/drive2/foo/bar")))); |
| 129 |
| 130 // Type:"external" + virtual_path:"Downloads/foo" is not a Drive path. |
| 131 mount_points->RegisterFileSystem( |
| 132 "Downloads", |
| 133 fileapi::kFileSystemTypeNativeLocal, |
| 134 temp_dir_.path()); |
| 135 EXPECT_EQ( |
| 136 base::FilePath(), |
| 137 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( |
| 138 "filesystem:chrome-extension://dummy-id/external/Downloads/foo")))); |
| 139 |
| 140 // Type:"isolated" + virtual_path:"isolated_id/name" mapped on a Drive path. |
| 141 std::string isolated_name; |
| 142 std::string isolated_id = |
| 143 fileapi::IsolatedContext::GetInstance()->RegisterFileSystemForPath( |
| 144 fileapi::kFileSystemTypeNativeForPlatformApp, |
| 145 GetDriveMountPointPath().AppendASCII("bar/buz"), |
| 146 &isolated_name); |
| 147 EXPECT_EQ( |
| 148 base::FilePath::FromUTF8Unsafe(drive_mount_name + "/bar/buz"), |
| 149 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( |
| 150 "filesystem:chrome-extension://dummy-id/isolated/" + |
| 151 isolated_id + "/" + isolated_name)))); |
| 152 } |
| 153 |
79 TEST(DriveFileSystemUtilTest, EscapeUnescapeCacheFileName) { | 154 TEST(DriveFileSystemUtilTest, EscapeUnescapeCacheFileName) { |
80 const std::string kUnescapedFileName( | 155 const std::string kUnescapedFileName( |
81 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); | 156 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); |
82 const std::string kEscapedFileName( | 157 const std::string kEscapedFileName( |
83 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); | 158 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); |
84 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); | 159 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); |
85 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); | 160 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); |
86 } | 161 } |
87 | 162 |
88 TEST(DriveFileSystemUtilTest, EscapeUtf8FileName) { | 163 TEST(DriveFileSystemUtilTest, EscapeUtf8FileName) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 EXPECT_FALSE(util::IsSpecialResourceId("file:123")); | 261 EXPECT_FALSE(util::IsSpecialResourceId("file:123")); |
187 EXPECT_FALSE(util::IsSpecialResourceId("folder:root")); | 262 EXPECT_FALSE(util::IsSpecialResourceId("folder:root")); |
188 EXPECT_FALSE(util::IsSpecialResourceId("folder:xyz")); | 263 EXPECT_FALSE(util::IsSpecialResourceId("folder:xyz")); |
189 | 264 |
190 EXPECT_TRUE(util::IsSpecialResourceId("<drive>")); | 265 EXPECT_TRUE(util::IsSpecialResourceId("<drive>")); |
191 EXPECT_TRUE(util::IsSpecialResourceId("<other>")); | 266 EXPECT_TRUE(util::IsSpecialResourceId("<other>")); |
192 } | 267 } |
193 | 268 |
194 } // namespace util | 269 } // namespace util |
195 } // namespace drive | 270 } // namespace drive |
OLD | NEW |