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/file_system_util.h" | 5 #include "chrome/browser/chromeos/drive/file_system_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "chrome/test/base/testing_profile_manager.h" | 15 #include "chrome/test/base/testing_profile_manager.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "content/public/test/test_file_system_options.h" | 17 #include "content/public/test/test_file_system_options.h" |
18 #include "google_apis/drive/test_util.h" | 18 #include "google_apis/drive/test_util.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "webkit/browser/fileapi/external_mount_points.h" | 20 #include "webkit/browser/fileapi/external_mount_points.h" |
21 #include "webkit/browser/fileapi/file_system_backend.h" | 21 #include "webkit/browser/fileapi/file_system_backend.h" |
22 #include "webkit/browser/fileapi/file_system_context.h" | 22 #include "webkit/browser/fileapi/file_system_context.h" |
(...skipping 11 matching lines...) Expand all Loading... |
34 class ProfileRelatedFileSystemUtilTest : public testing::Test { | 34 class ProfileRelatedFileSystemUtilTest : public testing::Test { |
35 protected: | 35 protected: |
36 ProfileRelatedFileSystemUtilTest() | 36 ProfileRelatedFileSystemUtilTest() |
37 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) { | 37 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) { |
38 } | 38 } |
39 | 39 |
40 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() OVERRIDE { |
41 ASSERT_TRUE(testing_profile_manager_.SetUp()); | 41 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
42 } | 42 } |
43 | 43 |
44 Profile* CreateProfileWithName(const std::string& name) { | 44 TestingProfileManager& testing_profile_manager() { |
45 return testing_profile_manager_.CreateTestingProfile( | 45 return testing_profile_manager_; |
46 chrome::kProfileDirPrefix + name); | |
47 } | 46 } |
48 | 47 |
49 private: | 48 private: |
50 content::TestBrowserThreadBundle thread_bundle_; | 49 content::TestBrowserThreadBundle thread_bundle_; |
51 TestingProfileManager testing_profile_manager_; | 50 TestingProfileManager testing_profile_manager_; |
52 }; | 51 }; |
53 | 52 |
54 } // namespace | 53 } // namespace |
55 | 54 |
56 TEST(FileSystemUtilTest, FilePathToDriveURL) { | 55 TEST(FileSystemUtilTest, FilePathToDriveURL) { |
(...skipping 15 matching lines...) Expand all Loading... |
72 // Path with multi byte characters. | 71 // Path with multi byte characters. |
73 base::string16 utf16_string; | 72 base::string16 utf16_string; |
74 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO | 73 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO |
75 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE | 74 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE |
76 path = GetDriveMyDriveRootPath().Append( | 75 path = GetDriveMyDriveRootPath().Append( |
77 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt")); | 76 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt")); |
78 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); | 77 EXPECT_EQ(path, DriveURLToFilePath(FilePathToDriveURL(path))); |
79 } | 78 } |
80 | 79 |
81 TEST_F(ProfileRelatedFileSystemUtilTest, GetDriveMountPointPath) { | 80 TEST_F(ProfileRelatedFileSystemUtilTest, GetDriveMountPointPath) { |
82 Profile* profile = CreateProfileWithName("hash1"); | 81 Profile* profile = testing_profile_manager().CreateTestingProfile("user1"); |
83 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive-hash1"), | 82 const std::string user_id_hash = |
| 83 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting("user1"); |
| 84 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive-" + user_id_hash), |
84 GetDriveMountPointPath(profile)); | 85 GetDriveMountPointPath(profile)); |
85 } | 86 } |
86 | 87 |
87 TEST_F(ProfileRelatedFileSystemUtilTest, ExtractProfileFromPath) { | 88 TEST_F(ProfileRelatedFileSystemUtilTest, ExtractProfileFromPath) { |
88 Profile* profile1 = CreateProfileWithName("hash1"); | 89 Profile* profile1 = testing_profile_manager().CreateTestingProfile("user1"); |
89 Profile* profile2 = CreateProfileWithName("hash2"); | 90 Profile* profile2 = testing_profile_manager().CreateTestingProfile("user2"); |
90 EXPECT_EQ(profile1, ExtractProfileFromPath( | 91 const std::string user1_id_hash = |
91 base::FilePath::FromUTF8Unsafe("/special/drive-hash1"))); | 92 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting("user1"); |
92 EXPECT_EQ(profile2, ExtractProfileFromPath( | 93 const std::string user2_id_hash = |
93 base::FilePath::FromUTF8Unsafe("/special/drive-hash2/root/xxx"))); | 94 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting("user2"); |
| 95 EXPECT_EQ(profile1, |
| 96 ExtractProfileFromPath(base::FilePath::FromUTF8Unsafe( |
| 97 "/special/drive-" + user1_id_hash))); |
| 98 EXPECT_EQ(profile2, |
| 99 ExtractProfileFromPath(base::FilePath::FromUTF8Unsafe( |
| 100 "/special/drive-" + user2_id_hash + "/root/xxx"))); |
94 EXPECT_EQ(NULL, ExtractProfileFromPath( | 101 EXPECT_EQ(NULL, ExtractProfileFromPath( |
95 base::FilePath::FromUTF8Unsafe("/special/non-drive-path"))); | 102 base::FilePath::FromUTF8Unsafe("/special/non-drive-path"))); |
96 } | 103 } |
97 | 104 |
98 TEST(FileSystemUtilTest, IsUnderDriveMountPoint) { | 105 TEST(FileSystemUtilTest, IsUnderDriveMountPoint) { |
99 EXPECT_FALSE(IsUnderDriveMountPoint( | 106 EXPECT_FALSE(IsUnderDriveMountPoint( |
100 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); | 107 base::FilePath::FromUTF8Unsafe("/wherever/foo.txt"))); |
101 EXPECT_FALSE(IsUnderDriveMountPoint( | 108 EXPECT_FALSE(IsUnderDriveMountPoint( |
102 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); | 109 base::FilePath::FromUTF8Unsafe("/special/foo.txt"))); |
103 EXPECT_FALSE(IsUnderDriveMountPoint( | 110 EXPECT_FALSE(IsUnderDriveMountPoint( |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // Non GDoc file. | 286 // Non GDoc file. |
280 file = temp_dir.path().AppendASCII("test.txt"); | 287 file = temp_dir.path().AppendASCII("test.txt"); |
281 std::string data = "Hello world!"; | 288 std::string data = "Hello world!"; |
282 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data)); | 289 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data)); |
283 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty()); | 290 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty()); |
284 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty()); | 291 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty()); |
285 } | 292 } |
286 | 293 |
287 } // namespace util | 294 } // namespace util |
288 } // namespace drive | 295 } // namespace drive |
OLD | NEW |