| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/message_loop/message_loop.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 17 #include "chrome/test/base/testing_profile_manager.h" | 16 #include "chrome/test/base/testing_profile_manager.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "content/public/test/test_file_system_options.h" | 18 #include "content/public/test/test_file_system_options.h" |
| 20 #include "google_apis/drive/test_util.h" | 19 #include "google_apis/drive/test_util.h" |
| 21 #include "storage/browser/fileapi/external_mount_points.h" | 20 #include "storage/browser/fileapi/external_mount_points.h" |
| 22 #include "storage/browser/fileapi/file_system_backend.h" | 21 #include "storage/browser/fileapi/file_system_backend.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 EXPECT_EQ(profile1, | 69 EXPECT_EQ(profile1, |
| 71 ExtractProfileFromPath(base::FilePath::FromUTF8Unsafe( | 70 ExtractProfileFromPath(base::FilePath::FromUTF8Unsafe( |
| 72 "/special/drive-" + user1_id_hash))); | 71 "/special/drive-" + user1_id_hash))); |
| 73 EXPECT_EQ(profile2, | 72 EXPECT_EQ(profile2, |
| 74 ExtractProfileFromPath(base::FilePath::FromUTF8Unsafe( | 73 ExtractProfileFromPath(base::FilePath::FromUTF8Unsafe( |
| 75 "/special/drive-" + user2_id_hash + "/root/xxx"))); | 74 "/special/drive-" + user2_id_hash + "/root/xxx"))); |
| 76 EXPECT_EQ(NULL, ExtractProfileFromPath( | 75 EXPECT_EQ(NULL, ExtractProfileFromPath( |
| 77 base::FilePath::FromUTF8Unsafe("/special/non-drive-path"))); | 76 base::FilePath::FromUTF8Unsafe("/special/non-drive-path"))); |
| 78 } | 77 } |
| 79 | 78 |
| 80 TEST(FileSystemUtilTest, IsUnderDriveMountPoint) { | 79 class FileSystemUtilTest : public testing::Test { |
| 80 content::TestBrowserThreadBundle thread_bundle_; |
| 81 }; |
| 82 |
| 83 TEST_F(FileSystemUtilTest, IsUnderDriveMountPoint) { |
| 81 EXPECT_FALSE(IsUnderDriveMountPoint( | 84 EXPECT_FALSE(IsUnderDriveMountPoint( |
| 82 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); | 85 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); |
| 83 EXPECT_FALSE(IsUnderDriveMountPoint( | 86 EXPECT_FALSE(IsUnderDriveMountPoint( |
| 84 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); | 87 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); |
| 85 EXPECT_FALSE(IsUnderDriveMountPoint( | 88 EXPECT_FALSE(IsUnderDriveMountPoint( |
| 86 base::FilePath::FromUTF8Unsafe("special/drive/foo.txt"))); | 89 base::FilePath::FromUTF8Unsafe("special/drive/foo.txt"))); |
| 87 | 90 |
| 88 EXPECT_TRUE(IsUnderDriveMountPoint( | 91 EXPECT_TRUE(IsUnderDriveMountPoint( |
| 89 base::FilePath::FromUTF8Unsafe("/special/drive"))); | 92 base::FilePath::FromUTF8Unsafe("/special/drive"))); |
| 90 EXPECT_TRUE(IsUnderDriveMountPoint( | 93 EXPECT_TRUE(IsUnderDriveMountPoint( |
| 91 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); | 94 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); |
| 92 EXPECT_TRUE(IsUnderDriveMountPoint( | 95 EXPECT_TRUE(IsUnderDriveMountPoint( |
| 93 base::FilePath::FromUTF8Unsafe("/special/drive/subdir/foo.txt"))); | 96 base::FilePath::FromUTF8Unsafe("/special/drive/subdir/foo.txt"))); |
| 94 EXPECT_TRUE(IsUnderDriveMountPoint( | 97 EXPECT_TRUE(IsUnderDriveMountPoint( |
| 95 base::FilePath::FromUTF8Unsafe("/special/drive-xxx/foo.txt"))); | 98 base::FilePath::FromUTF8Unsafe("/special/drive-xxx/foo.txt"))); |
| 96 } | 99 } |
| 97 | 100 |
| 98 TEST(FileSystemUtilTest, ExtractDrivePath) { | 101 TEST_F(FileSystemUtilTest, ExtractDrivePath) { |
| 99 EXPECT_EQ(base::FilePath(), | 102 EXPECT_EQ(base::FilePath(), |
| 100 ExtractDrivePath( | 103 ExtractDrivePath( |
| 101 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); | 104 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); |
| 102 EXPECT_EQ(base::FilePath(), | 105 EXPECT_EQ(base::FilePath(), |
| 103 ExtractDrivePath( | 106 ExtractDrivePath( |
| 104 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); | 107 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); |
| 105 | 108 |
| 106 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), | 109 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), |
| 107 ExtractDrivePath( | 110 ExtractDrivePath( |
| 108 base::FilePath::FromUTF8Unsafe("/special/drive"))); | 111 base::FilePath::FromUTF8Unsafe("/special/drive"))); |
| 109 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), | 112 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), |
| 110 ExtractDrivePath( | 113 ExtractDrivePath( |
| 111 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); | 114 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); |
| 112 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"), | 115 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"), |
| 113 ExtractDrivePath(base::FilePath::FromUTF8Unsafe( | 116 ExtractDrivePath(base::FilePath::FromUTF8Unsafe( |
| 114 "/special/drive/subdir/foo.txt"))); | 117 "/special/drive/subdir/foo.txt"))); |
| 115 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), | 118 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), |
| 116 ExtractDrivePath( | 119 ExtractDrivePath( |
| 117 base::FilePath::FromUTF8Unsafe("/special/drive-xxx/foo.txt"))); | 120 base::FilePath::FromUTF8Unsafe("/special/drive-xxx/foo.txt"))); |
| 118 } | 121 } |
| 119 | 122 |
| 120 TEST(FileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) { | 123 TEST_F(FileSystemUtilTest, ExtractDrivePathFromFileSystemUrl) { |
| 121 TestingProfile profile; | 124 TestingProfile profile; |
| 122 | 125 |
| 123 // Set up file system context for testing. | 126 // Set up file system context for testing. |
| 124 base::ScopedTempDir temp_dir_; | 127 base::ScopedTempDir temp_dir_; |
| 125 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 128 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 126 | 129 |
| 127 base::MessageLoop message_loop; | |
| 128 scoped_refptr<storage::ExternalMountPoints> mount_points = | 130 scoped_refptr<storage::ExternalMountPoints> mount_points = |
| 129 storage::ExternalMountPoints::CreateRefCounted(); | 131 storage::ExternalMountPoints::CreateRefCounted(); |
| 130 scoped_refptr<storage::FileSystemContext> context( | 132 scoped_refptr<storage::FileSystemContext> context( |
| 131 new storage::FileSystemContext( | 133 new storage::FileSystemContext( |
| 132 base::MessageLoopProxy::current().get(), | 134 base::MessageLoopProxy::current().get(), |
| 133 base::MessageLoopProxy::current().get(), | 135 base::MessageLoopProxy::current().get(), |
| 134 mount_points.get(), | 136 mount_points.get(), |
| 135 NULL, // special_storage_policy | 137 NULL, // special_storage_policy |
| 136 NULL, // quota_manager_proxy, | 138 NULL, // quota_manager_proxy, |
| 137 ScopedVector<storage::FileSystemBackend>(), | 139 ScopedVector<storage::FileSystemBackend>(), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 std::string(), | 183 std::string(), |
| 182 GetDriveMountPointPath(&profile).AppendASCII("bar/buz"), | 184 GetDriveMountPointPath(&profile).AppendASCII("bar/buz"), |
| 183 &isolated_name); | 185 &isolated_name); |
| 184 EXPECT_EQ( | 186 EXPECT_EQ( |
| 185 base::FilePath::FromUTF8Unsafe("drive/bar/buz"), | 187 base::FilePath::FromUTF8Unsafe("drive/bar/buz"), |
| 186 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( | 188 ExtractDrivePathFromFileSystemUrl(context->CrackURL(GURL( |
| 187 "filesystem:chrome-extension://dummy-id/isolated/" + | 189 "filesystem:chrome-extension://dummy-id/isolated/" + |
| 188 isolated_id + "/" + isolated_name)))); | 190 isolated_id + "/" + isolated_name)))); |
| 189 } | 191 } |
| 190 | 192 |
| 191 TEST(FileSystemUtilTest, EscapeUnescapeCacheFileName) { | 193 TEST_F(FileSystemUtilTest, EscapeUnescapeCacheFileName) { |
| 192 const std::string kUnescapedFileName( | 194 const std::string kUnescapedFileName( |
| 193 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); | 195 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); |
| 194 const std::string kEscapedFileName( | 196 const std::string kEscapedFileName( |
| 195 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); | 197 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); |
| 196 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); | 198 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); |
| 197 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); | 199 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); |
| 198 } | 200 } |
| 199 | 201 |
| 200 TEST(FileSystemUtilTest, NormalizeFileName) { | 202 TEST_F(FileSystemUtilTest, NormalizeFileName) { |
| 201 EXPECT_EQ("", NormalizeFileName("")); | 203 EXPECT_EQ("", NormalizeFileName("")); |
| 202 EXPECT_EQ("foo", NormalizeFileName("foo")); | 204 EXPECT_EQ("foo", NormalizeFileName("foo")); |
| 203 // Slash | 205 // Slash |
| 204 EXPECT_EQ("foo_zzz", NormalizeFileName("foo/zzz")); | 206 EXPECT_EQ("foo_zzz", NormalizeFileName("foo/zzz")); |
| 205 EXPECT_EQ("___", NormalizeFileName("///")); | 207 EXPECT_EQ("___", NormalizeFileName("///")); |
| 206 // Japanese hiragana "hi" + semi-voiced-mark is normalized to "pi". | 208 // Japanese hiragana "hi" + semi-voiced-mark is normalized to "pi". |
| 207 EXPECT_EQ("\xE3\x81\xB4", NormalizeFileName("\xE3\x81\xB2\xE3\x82\x9A")); | 209 EXPECT_EQ("\xE3\x81\xB4", NormalizeFileName("\xE3\x81\xB2\xE3\x82\x9A")); |
| 208 // Dot | 210 // Dot |
| 209 EXPECT_EQ("_", NormalizeFileName(".")); | 211 EXPECT_EQ("_", NormalizeFileName(".")); |
| 210 EXPECT_EQ("_", NormalizeFileName("..")); | 212 EXPECT_EQ("_", NormalizeFileName("..")); |
| 211 EXPECT_EQ("_", NormalizeFileName("...")); | 213 EXPECT_EQ("_", NormalizeFileName("...")); |
| 212 EXPECT_EQ(".bashrc", NormalizeFileName(".bashrc")); | 214 EXPECT_EQ(".bashrc", NormalizeFileName(".bashrc")); |
| 213 EXPECT_EQ("._", NormalizeFileName("./")); | 215 EXPECT_EQ("._", NormalizeFileName("./")); |
| 214 } | 216 } |
| 215 | 217 |
| 216 TEST(FileSystemUtilTest, GetCacheRootPath) { | 218 TEST_F(FileSystemUtilTest, GetCacheRootPath) { |
| 217 TestingProfile profile; | 219 TestingProfile profile; |
| 218 base::FilePath profile_path = profile.GetPath(); | 220 base::FilePath profile_path = profile.GetPath(); |
| 219 EXPECT_EQ(profile_path.AppendASCII("GCache/v1"), | 221 EXPECT_EQ(profile_path.AppendASCII("GCache/v1"), |
| 220 util::GetCacheRootPath(&profile)); | 222 util::GetCacheRootPath(&profile)); |
| 221 } | 223 } |
| 222 | 224 |
| 223 TEST(FileSystemUtilTest, GDocFile) { | 225 TEST_F(FileSystemUtilTest, GDocFile) { |
| 224 base::ScopedTempDir temp_dir; | 226 base::ScopedTempDir temp_dir; |
| 225 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 227 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 226 | 228 |
| 227 GURL url("https://docs.google.com/document/d/" | 229 GURL url("https://docs.google.com/document/d/" |
| 228 "1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug/edit"); | 230 "1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug/edit"); |
| 229 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug"); | 231 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug"); |
| 230 | 232 |
| 231 // Read and write gdoc. | 233 // Read and write gdoc. |
| 232 base::FilePath file = temp_dir.path().AppendASCII("test.gdoc"); | 234 base::FilePath file = temp_dir.path().AppendASCII("test.gdoc"); |
| 233 EXPECT_TRUE(CreateGDocFile(file, url, resource_id)); | 235 EXPECT_TRUE(CreateGDocFile(file, url, resource_id)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 261 // Non GDoc file. | 263 // Non GDoc file. |
| 262 file = temp_dir.path().AppendASCII("test.txt"); | 264 file = temp_dir.path().AppendASCII("test.txt"); |
| 263 std::string data = "Hello world!"; | 265 std::string data = "Hello world!"; |
| 264 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data)); | 266 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data)); |
| 265 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty()); | 267 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty()); |
| 266 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty()); | 268 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty()); |
| 267 } | 269 } |
| 268 | 270 |
| 269 } // namespace util | 271 } // namespace util |
| 270 } // namespace drive | 272 } // namespace drive |
| OLD | NEW |