Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: chrome/browser/chromeos/drive/file_system_util_unittest.cc

Issue 14755002: drive: Drop "Drive" from FakeDriveFileSystem and MockDriveFileSystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some more cleanup Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_system_util.h" 5 #include "chrome/browser/chromeos/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" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/fileapi/external_mount_points.h" 12 #include "webkit/fileapi/external_mount_points.h"
13 #include "webkit/fileapi/file_system_context.h" 13 #include "webkit/fileapi/file_system_context.h"
14 #include "webkit/fileapi/file_system_mount_point_provider.h" 14 #include "webkit/fileapi/file_system_mount_point_provider.h"
15 #include "webkit/fileapi/file_system_task_runners.h" 15 #include "webkit/fileapi/file_system_task_runners.h"
16 #include "webkit/fileapi/file_system_url.h" 16 #include "webkit/fileapi/file_system_url.h"
17 #include "webkit/fileapi/isolated_context.h" 17 #include "webkit/fileapi/isolated_context.h"
18 #include "webkit/fileapi/mock_file_system_options.h" 18 #include "webkit/fileapi/mock_file_system_options.h"
19 19
20 namespace drive { 20 namespace drive {
21 namespace util { 21 namespace util {
22 22
23 TEST(DriveFileSystemUtilTest, FilePathToDriveURL) { 23 TEST(FileSystemUtilTest, FilePathToDriveURL) {
24 base::FilePath path; 24 base::FilePath path;
25 25
26 // Path with alphabets and numbers. 26 // Path with alphabets and numbers.
27 path = GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); 27 path = GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt");
28 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); 28 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path)));
29 29
30 // Path with symbols. 30 // Path with symbols.
31 path = GetDriveMyDriveRootPath().AppendASCII( 31 path = GetDriveMyDriveRootPath().AppendASCII(
32 " !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~"); 32 " !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~");
33 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); 33 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path)));
34 34
35 // Path with '%'. 35 // Path with '%'.
36 path = GetDriveMyDriveRootPath().AppendASCII("%19%20%21.txt"); 36 path = GetDriveMyDriveRootPath().AppendASCII("%19%20%21.txt");
37 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); 37 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path)));
38 38
39 // Path with multi byte characters. 39 // Path with multi byte characters.
40 string16 utf16_string; 40 string16 utf16_string;
41 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO 41 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO
42 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE 42 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE
43 path = GetDriveMyDriveRootPath().Append( 43 path = GetDriveMyDriveRootPath().Append(
44 base::FilePath::FromUTF8Unsafe(UTF16ToUTF8(utf16_string) + ".txt")); 44 base::FilePath::FromUTF8Unsafe(UTF16ToUTF8(utf16_string) + ".txt"));
45 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); 45 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path)));
46 } 46 }
47 47
48 TEST(DriveFileSystemUtilTest, IsUnderDriveMountPoint) { 48 TEST(FileSystemUtilTest, IsUnderDriveMountPoint) {
49 EXPECT_FALSE(IsUnderDriveMountPoint( 49 EXPECT_FALSE(IsUnderDriveMountPoint(
50 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); 50 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt")));
51 EXPECT_FALSE(IsUnderDriveMountPoint( 51 EXPECT_FALSE(IsUnderDriveMountPoint(
52 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); 52 base::FilePath::FromUTF8Unsafe("/special/foo.txt")));
53 EXPECT_FALSE(IsUnderDriveMountPoint( 53 EXPECT_FALSE(IsUnderDriveMountPoint(
54 base::FilePath::FromUTF8Unsafe("/special/drivex/foo.txt"))); 54 base::FilePath::FromUTF8Unsafe("/special/drivex/foo.txt")));
55 EXPECT_FALSE(IsUnderDriveMountPoint( 55 EXPECT_FALSE(IsUnderDriveMountPoint(
56 base::FilePath::FromUTF8Unsafe("special/drivex/foo.txt"))); 56 base::FilePath::FromUTF8Unsafe("special/drivex/foo.txt")));
57 57
58 EXPECT_TRUE(IsUnderDriveMountPoint( 58 EXPECT_TRUE(IsUnderDriveMountPoint(
59 base::FilePath::FromUTF8Unsafe("/special/drive"))); 59 base::FilePath::FromUTF8Unsafe("/special/drive")));
60 EXPECT_TRUE(IsUnderDriveMountPoint( 60 EXPECT_TRUE(IsUnderDriveMountPoint(
61 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); 61 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt")));
62 EXPECT_TRUE(IsUnderDriveMountPoint( 62 EXPECT_TRUE(IsUnderDriveMountPoint(
63 base::FilePath::FromUTF8Unsafe("/special/drive/subdir/foo.txt"))); 63 base::FilePath::FromUTF8Unsafe("/special/drive/subdir/foo.txt")));
64 } 64 }
65 65
66 TEST(DriveFileSystemUtilTest, ExtractDrivePath) { 66 TEST(FileSystemUtilTest, ExtractDrivePath) {
67 EXPECT_EQ(base::FilePath(), 67 EXPECT_EQ(base::FilePath(),
68 ExtractDrivePath( 68 ExtractDrivePath(
69 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); 69 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt")));
70 EXPECT_EQ(base::FilePath(), 70 EXPECT_EQ(base::FilePath(),
71 ExtractDrivePath( 71 ExtractDrivePath(
72 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); 72 base::FilePath::FromUTF8Unsafe("/special/foo.txt")));
73 EXPECT_EQ(base::FilePath(), 73 EXPECT_EQ(base::FilePath(),
74 ExtractDrivePath( 74 ExtractDrivePath(
75 base::FilePath::FromUTF8Unsafe("/special/drivex/foo.txt"))); 75 base::FilePath::FromUTF8Unsafe("/special/drivex/foo.txt")));
76 76
77 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), 77 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"),
78 ExtractDrivePath( 78 ExtractDrivePath(
79 base::FilePath::FromUTF8Unsafe("/special/drive"))); 79 base::FilePath::FromUTF8Unsafe("/special/drive")));
80 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), 80 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"),
81 ExtractDrivePath( 81 ExtractDrivePath(
82 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); 82 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt")));
83 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"), 83 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"),
84 ExtractDrivePath(base::FilePath::FromUTF8Unsafe( 84 ExtractDrivePath(base::FilePath::FromUTF8Unsafe(
85 "/special/drive/subdir/foo.txt"))); 85 "/special/drive/subdir/foo.txt")));
86 } 86 }
87 87
88 TEST(DriveFileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) { 88 TEST(FileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) {
89 // Set up file system context for testing. 89 // Set up file system context for testing.
90 base::ScopedTempDir temp_dir_; 90 base::ScopedTempDir temp_dir_;
91 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 91 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
92 92
93 MessageLoop message_loop; 93 MessageLoop message_loop;
94 scoped_refptr<fileapi::ExternalMountPoints> mount_points = 94 scoped_refptr<fileapi::ExternalMountPoints> mount_points =
95 fileapi::ExternalMountPoints::CreateRefCounted(); 95 fileapi::ExternalMountPoints::CreateRefCounted();
96 scoped_refptr<fileapi::FileSystemContext> context( 96 scoped_refptr<fileapi::FileSystemContext> context(
97 new fileapi::FileSystemContext( 97 new fileapi::FileSystemContext(
98 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), 98 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 fileapi::kFileSystemTypeNativeForPlatformApp, 146 fileapi::kFileSystemTypeNativeForPlatformApp,
147 GetDriveMountPointPath().AppendASCII("bar/buz"), 147 GetDriveMountPointPath().AppendASCII("bar/buz"),
148 &isolated_name); 148 &isolated_name);
149 EXPECT_EQ( 149 EXPECT_EQ(
150 base::FilePath::FromUTF8Unsafe(drive_mount_name + "/bar/buz"), 150 base::FilePath::FromUTF8Unsafe(drive_mount_name + "/bar/buz"),
151 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( 151 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL(
152 "filesystem:chrome-extension://dummy-id/isolated/" + 152 "filesystem:chrome-extension://dummy-id/isolated/" +
153 isolated_id + "/" + isolated_name)))); 153 isolated_id + "/" + isolated_name))));
154 } 154 }
155 155
156 TEST(DriveFileSystemUtilTest, EscapeUnescapeCacheFileName) { 156 TEST(FileSystemUtilTest, EscapeUnescapeCacheFileName) {
157 const std::string kUnescapedFileName( 157 const std::string kUnescapedFileName(
158 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); 158 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?");
159 const std::string kEscapedFileName( 159 const std::string kEscapedFileName(
160 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); 160 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?");
161 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); 161 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName));
162 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); 162 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName));
163 } 163 }
164 164
165 TEST(DriveFileSystemUtilTest, EscapeUtf8FileName) { 165 TEST(FileSystemUtilTest, EscapeUtf8FileName) {
166 EXPECT_EQ("", EscapeUtf8FileName("")); 166 EXPECT_EQ("", EscapeUtf8FileName(""));
167 EXPECT_EQ("foo", EscapeUtf8FileName("foo")); 167 EXPECT_EQ("foo", EscapeUtf8FileName("foo"));
168 EXPECT_EQ("foo\xE2\x88\x95zzz", EscapeUtf8FileName("foo/zzz")); 168 EXPECT_EQ("foo\xE2\x88\x95zzz", EscapeUtf8FileName("foo/zzz"));
169 EXPECT_EQ("\xE2\x88\x95\xE2\x88\x95\xE2\x88\x95", EscapeUtf8FileName("///")); 169 EXPECT_EQ("\xE2\x88\x95\xE2\x88\x95\xE2\x88\x95", EscapeUtf8FileName("///"));
170 } 170 }
171 171
172 TEST(DriveFileSystemUtilTest, ExtractResourceIdFromUrl) { 172 TEST(FileSystemUtilTest, ExtractResourceIdFromUrl) {
173 EXPECT_EQ("file:2_file_resource_id", ExtractResourceIdFromUrl( 173 EXPECT_EQ("file:2_file_resource_id", ExtractResourceIdFromUrl(
174 GURL("https://file1_link_self/file:2_file_resource_id"))); 174 GURL("https://file1_link_self/file:2_file_resource_id")));
175 // %3A should be unescaped. 175 // %3A should be unescaped.
176 EXPECT_EQ("file:2_file_resource_id", ExtractResourceIdFromUrl( 176 EXPECT_EQ("file:2_file_resource_id", ExtractResourceIdFromUrl(
177 GURL("https://file1_link_self/file%3A2_file_resource_id"))); 177 GURL("https://file1_link_self/file%3A2_file_resource_id")));
178 178
179 // The resource ID cannot be extracted, hence empty. 179 // The resource ID cannot be extracted, hence empty.
180 EXPECT_EQ("", ExtractResourceIdFromUrl(GURL("https://www.example.com/"))); 180 EXPECT_EQ("", ExtractResourceIdFromUrl(GURL("https://www.example.com/")));
181 } 181 }
182 182
183 TEST(DriveFileSystemUtilTest, ParseCacheFilePath) { 183 TEST(FileSystemUtilTest, ParseCacheFilePath) {
184 std::string resource_id, md5, extra_extension; 184 std::string resource_id, md5, extra_extension;
185 ParseCacheFilePath( 185 ParseCacheFilePath(
186 base::FilePath::FromUTF8Unsafe( 186 base::FilePath::FromUTF8Unsafe(
187 "/home/user/GCache/v1/persistent/pdf:a1b2.0123456789abcdef.mounted"), 187 "/home/user/GCache/v1/persistent/pdf:a1b2.0123456789abcdef.mounted"),
188 &resource_id, 188 &resource_id,
189 &md5, 189 &md5,
190 &extra_extension); 190 &extra_extension);
191 EXPECT_EQ(resource_id, "pdf:a1b2"); 191 EXPECT_EQ(resource_id, "pdf:a1b2");
192 EXPECT_EQ(md5, "0123456789abcdef"); 192 EXPECT_EQ(md5, "0123456789abcdef");
193 EXPECT_EQ(extra_extension, "mounted"); 193 EXPECT_EQ(extra_extension, "mounted");
(...skipping 12 matching lines...) Expand all
206 base::FilePath::FromUTF8Unsafe( 206 base::FilePath::FromUTF8Unsafe(
207 "/home/user/GCache/v1/pinned/pdf:a1b2"), 207 "/home/user/GCache/v1/pinned/pdf:a1b2"),
208 &resource_id, 208 &resource_id,
209 &md5, 209 &md5,
210 &extra_extension); 210 &extra_extension);
211 EXPECT_EQ(resource_id, "pdf:a1b2"); 211 EXPECT_EQ(resource_id, "pdf:a1b2");
212 EXPECT_EQ(md5, ""); 212 EXPECT_EQ(md5, "");
213 EXPECT_EQ(extra_extension, ""); 213 EXPECT_EQ(extra_extension, "");
214 } 214 }
215 215
216 TEST(DriveFileSystemUtilTest, NeedsNamespaceMigration) { 216 TEST(FileSystemUtilTest, NeedsNamespaceMigration) {
217 // Not Drive cases. 217 // Not Drive cases.
218 EXPECT_FALSE(NeedsNamespaceMigration( 218 EXPECT_FALSE(NeedsNamespaceMigration(
219 base::FilePath::FromUTF8Unsafe("/Downloads"))); 219 base::FilePath::FromUTF8Unsafe("/Downloads")));
220 EXPECT_FALSE(NeedsNamespaceMigration( 220 EXPECT_FALSE(NeedsNamespaceMigration(
221 base::FilePath::FromUTF8Unsafe("/Downloads/x"))); 221 base::FilePath::FromUTF8Unsafe("/Downloads/x")));
222 EXPECT_FALSE(NeedsNamespaceMigration( 222 EXPECT_FALSE(NeedsNamespaceMigration(
223 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); 223 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt")));
224 EXPECT_FALSE(NeedsNamespaceMigration( 224 EXPECT_FALSE(NeedsNamespaceMigration(
225 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); 225 base::FilePath::FromUTF8Unsafe("/special/foo.txt")));
226 EXPECT_FALSE(NeedsNamespaceMigration( 226 EXPECT_FALSE(NeedsNamespaceMigration(
(...skipping 13 matching lines...) Expand all
240 EXPECT_FALSE(NeedsNamespaceMigration( 240 EXPECT_FALSE(NeedsNamespaceMigration(
241 base::FilePath::FromUTF8Unsafe("/special/drive/root"))); 241 base::FilePath::FromUTF8Unsafe("/special/drive/root")));
242 EXPECT_FALSE(NeedsNamespaceMigration( 242 EXPECT_FALSE(NeedsNamespaceMigration(
243 base::FilePath::FromUTF8Unsafe("/special/drive/root/dir1"))); 243 base::FilePath::FromUTF8Unsafe("/special/drive/root/dir1")));
244 EXPECT_FALSE(NeedsNamespaceMigration( 244 EXPECT_FALSE(NeedsNamespaceMigration(
245 base::FilePath::FromUTF8Unsafe("/special/drive/root/root"))); 245 base::FilePath::FromUTF8Unsafe("/special/drive/root/root")));
246 EXPECT_FALSE(NeedsNamespaceMigration( 246 EXPECT_FALSE(NeedsNamespaceMigration(
247 base::FilePath::FromUTF8Unsafe("/special/drive/root/root/dir1"))); 247 base::FilePath::FromUTF8Unsafe("/special/drive/root/root/dir1")));
248 } 248 }
249 249
250 TEST(DriveFileSystemUtilTest, ConvertToMyDriveNamespace) { 250 TEST(FileSystemUtilTest, ConvertToMyDriveNamespace) {
251 // Migration cases. 251 // Migration cases.
252 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive/root"), 252 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive/root"),
253 drive::util::ConvertToMyDriveNamespace( 253 drive::util::ConvertToMyDriveNamespace(
254 base::FilePath::FromUTF8Unsafe("/special/drive"))); 254 base::FilePath::FromUTF8Unsafe("/special/drive")));
255 255
256 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive/root/dir1"), 256 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive/root/dir1"),
257 drive::util::ConvertToMyDriveNamespace( 257 drive::util::ConvertToMyDriveNamespace(
258 base::FilePath::FromUTF8Unsafe("/special/drive/dir1"))); 258 base::FilePath::FromUTF8Unsafe("/special/drive/dir1")));
259 } 259 }
260 260
261 TEST(DriveFileSystemUtilTest, IsSpecialResourceId) { 261 TEST(FileSystemUtilTest, IsSpecialResourceId) {
262 EXPECT_FALSE(util::IsSpecialResourceId("abc")); 262 EXPECT_FALSE(util::IsSpecialResourceId("abc"));
263 EXPECT_FALSE(util::IsSpecialResourceId("file:123")); 263 EXPECT_FALSE(util::IsSpecialResourceId("file:123"));
264 EXPECT_FALSE(util::IsSpecialResourceId("folder:root")); 264 EXPECT_FALSE(util::IsSpecialResourceId("folder:root"));
265 EXPECT_FALSE(util::IsSpecialResourceId("folder:xyz")); 265 EXPECT_FALSE(util::IsSpecialResourceId("folder:xyz"));
266 266
267 EXPECT_TRUE(util::IsSpecialResourceId("<drive>")); 267 EXPECT_TRUE(util::IsSpecialResourceId("<drive>"));
268 EXPECT_TRUE(util::IsSpecialResourceId("<other>")); 268 EXPECT_TRUE(util::IsSpecialResourceId("<other>"));
269 } 269 }
270 270
271 } // namespace util 271 } // namespace util
272 } // namespace drive 272 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_util.cc ('k') | chrome/browser/chromeos/drive/file_write_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698