| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_core_util.h" | 5 #include "components/drive/file_system_core_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/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "chrome/browser/chromeos/drive/file_system_util.h" | |
| 16 #include "chrome/test/base/testing_profile.h" | |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "content/public/test/test_file_system_options.h" | |
| 19 #include "google_apis/drive/test_util.h" | 16 #include "google_apis/drive/test_util.h" |
| 20 #include "storage/browser/fileapi/external_mount_points.h" | |
| 21 #include "storage/browser/fileapi/file_system_backend.h" | |
| 22 #include "storage/browser/fileapi/file_system_context.h" | |
| 23 #include "storage/browser/fileapi/file_system_url.h" | |
| 24 #include "storage/browser/fileapi/isolated_context.h" | |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 18 |
| 27 namespace drive { | 19 namespace drive { |
| 28 namespace util { | 20 namespace util { |
| 29 | 21 |
| 30 class FileSystemUtilTest : public testing::Test { | 22 class FileSystemUtilTest : public testing::Test { |
| 31 content::TestBrowserThreadBundle thread_bundle_; | 23 content::TestBrowserThreadBundle thread_bundle_; |
| 32 }; | 24 }; |
| 33 | 25 |
| 34 TEST_F(FileSystemUtilTest, IsUnderDriveMountPoint) { | |
| 35 EXPECT_FALSE(IsUnderDriveMountPoint( | |
| 36 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); | |
| 37 EXPECT_FALSE(IsUnderDriveMountPoint( | |
| 38 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); | |
| 39 EXPECT_FALSE(IsUnderDriveMountPoint( | |
| 40 base::FilePath::FromUTF8Unsafe("special/drive/foo.txt"))); | |
| 41 | |
| 42 EXPECT_TRUE( | |
| 43 IsUnderDriveMountPoint(base::FilePath::FromUTF8Unsafe("/special/drive"))); | |
| 44 EXPECT_TRUE(IsUnderDriveMountPoint( | |
| 45 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); | |
| 46 EXPECT_TRUE(IsUnderDriveMountPoint( | |
| 47 base::FilePath::FromUTF8Unsafe("/special/drive/subdir/foo.txt"))); | |
| 48 EXPECT_TRUE(IsUnderDriveMountPoint( | |
| 49 base::FilePath::FromUTF8Unsafe("/special/drive-xxx/foo.txt"))); | |
| 50 } | |
| 51 | |
| 52 TEST_F(FileSystemUtilTest, ExtractDrivePath) { | |
| 53 EXPECT_EQ( | |
| 54 base::FilePath(), | |
| 55 ExtractDrivePath(base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); | |
| 56 EXPECT_EQ( | |
| 57 base::FilePath(), | |
| 58 ExtractDrivePath(base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); | |
| 59 | |
| 60 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive"), | |
| 61 ExtractDrivePath(base::FilePath::FromUTF8Unsafe("/special/drive"))); | |
| 62 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), | |
| 63 ExtractDrivePath( | |
| 64 base::FilePath::FromUTF8Unsafe("/special/drive/foo.txt"))); | |
| 65 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/subdir/foo.txt"), | |
| 66 ExtractDrivePath(base::FilePath::FromUTF8Unsafe( | |
| 67 "/special/drive/subdir/foo.txt"))); | |
| 68 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/foo.txt"), | |
| 69 ExtractDrivePath( | |
| 70 base::FilePath::FromUTF8Unsafe("/special/drive-xxx/foo.txt"))); | |
| 71 } | |
| 72 | |
| 73 TEST_F(FileSystemUtilTest, EscapeUnescapeCacheFileName) { | 26 TEST_F(FileSystemUtilTest, EscapeUnescapeCacheFileName) { |
| 74 const std::string kUnescapedFileName( | 27 const std::string kUnescapedFileName( |
| 75 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); | 28 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?"); |
| 76 const std::string kEscapedFileName( | 29 const std::string kEscapedFileName( |
| 77 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); | 30 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?"); |
| 78 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); | 31 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName)); |
| 79 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); | 32 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName)); |
| 80 } | 33 } |
| 81 | 34 |
| 82 TEST_F(FileSystemUtilTest, NormalizeFileName) { | 35 TEST_F(FileSystemUtilTest, NormalizeFileName) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // Non GDoc file. | 90 // Non GDoc file. |
| 138 file = temp_dir.path().AppendASCII("test.txt"); | 91 file = temp_dir.path().AppendASCII("test.txt"); |
| 139 std::string data = "Hello world!"; | 92 std::string data = "Hello world!"; |
| 140 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data)); | 93 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data)); |
| 141 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty()); | 94 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty()); |
| 142 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty()); | 95 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty()); |
| 143 } | 96 } |
| 144 | 97 |
| 145 } // namespace util | 98 } // namespace util |
| 146 } // namespace drive | 99 } // namespace drive |
| OLD | NEW |