OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_manager/path_util.h" | 5 #include "chrome/browser/chromeos/file_manager/path_util.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "chrome/browser/chromeos/drive/file_system_util.h" | 8 #include "chrome/browser/download/download_prefs.h" |
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
10 #include "chrome/test/base/testing_browser_process.h" | |
11 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
12 #include "chrome/test/base/testing_profile_manager.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
14 | 11 |
15 namespace file_manager { | 12 namespace file_manager { |
16 namespace util { | 13 namespace util { |
17 namespace { | 14 namespace { |
18 | 15 |
19 class ProfileRelatedTest : public testing::Test { | |
20 protected: | |
21 ProfileRelatedTest() | |
22 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) { | |
23 } | |
24 | |
25 virtual void SetUp() override { | |
26 ASSERT_TRUE(testing_profile_manager_.SetUp()); | |
27 } | |
28 | |
29 Profile* CreateProfileWithName(const std::string& name) { | |
30 return testing_profile_manager_.CreateTestingProfile(name); | |
31 } | |
32 | |
33 private: | |
34 TestingProfileManager testing_profile_manager_; | |
35 }; | |
36 | |
37 TEST(FileManagerPathUtilTest, MultiProfileDownloadsFolderMigration) { | 16 TEST(FileManagerPathUtilTest, MultiProfileDownloadsFolderMigration) { |
38 TestingProfile profile; | 17 TestingProfile profile; |
39 | 18 |
40 // This looks like "/home/chronos/u-hash/Downloads" in the production | 19 // This looks like "/home/chronos/u-hash/Downloads" in the production |
41 // environment. | 20 // environment. |
42 const base::FilePath kDownloads = GetDownloadsFolderForProfile(&profile); | 21 const base::FilePath kDownloads = GetDownloadsFolderForProfile(&profile); |
| 22 const base::FilePath kOldDownloads = |
| 23 DownloadPrefs::GetDefaultDownloadDirectory(); |
43 | 24 |
44 base::FilePath path; | 25 base::FilePath path; |
45 | 26 |
46 EXPECT_TRUE(MigratePathFromOldFormat( | 27 EXPECT_TRUE(MigratePathFromOldFormat(&profile, kOldDownloads, &path)); |
47 &profile, | |
48 base::FilePath::FromUTF8Unsafe("/home/chronos/user/Downloads"), | |
49 &path)); | |
50 EXPECT_EQ(kDownloads, path); | 28 EXPECT_EQ(kDownloads, path); |
51 | 29 |
52 EXPECT_TRUE(MigratePathFromOldFormat( | 30 EXPECT_TRUE(MigratePathFromOldFormat( |
53 &profile, | 31 &profile, |
54 base::FilePath::FromUTF8Unsafe("/home/chronos/user/Downloads/a/b"), | 32 kOldDownloads.AppendASCII("a/b"), |
55 &path)); | 33 &path)); |
56 EXPECT_EQ(kDownloads.AppendASCII("a/b"), path); | 34 EXPECT_EQ(kDownloads.AppendASCII("a/b"), path); |
57 | 35 |
58 // Path already in the new format is not converted. | 36 // Path already in the new format is not converted. |
59 EXPECT_FALSE(MigratePathFromOldFormat( | 37 EXPECT_FALSE(MigratePathFromOldFormat( |
60 &profile, | 38 &profile, |
61 kDownloads.AppendASCII("a/b"), | 39 kDownloads.AppendASCII("a/b"), |
62 &path)); | 40 &path)); |
63 | 41 |
64 // Only the "Downloads" path is converted. | 42 // Only the "Downloads" path is converted. |
65 EXPECT_FALSE(MigratePathFromOldFormat( | 43 EXPECT_FALSE(MigratePathFromOldFormat( |
66 &profile, | 44 &profile, |
67 base::FilePath::FromUTF8Unsafe("/home/chronos/user/dl"), | 45 base::FilePath::FromUTF8Unsafe("/home/chronos/user/dl"), |
68 &path)); | 46 &path)); |
69 } | 47 } |
70 | 48 |
71 TEST_F(ProfileRelatedTest, MultiProfileDriveFolderMigration) { | |
72 Profile* profile = CreateProfileWithName("user1"); | |
73 | |
74 const base::FilePath kDrive = drive::util::GetDriveMountPointPath(profile); | |
75 const std::string user_id_hash = | |
76 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting("user1"); | |
77 ASSERT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive-" + user_id_hash), | |
78 kDrive); | |
79 | |
80 base::FilePath path; | |
81 | |
82 EXPECT_TRUE(MigratePathFromOldFormat( | |
83 profile, | |
84 base::FilePath::FromUTF8Unsafe("/special/drive"), | |
85 &path)); | |
86 EXPECT_EQ(kDrive, path); | |
87 | |
88 EXPECT_TRUE(MigratePathFromOldFormat( | |
89 profile, | |
90 base::FilePath::FromUTF8Unsafe("/special/drive/a/b"), | |
91 &path)); | |
92 EXPECT_EQ(kDrive.AppendASCII("a/b"), path); | |
93 | |
94 // Path already in the new format is not converted. | |
95 EXPECT_FALSE(MigratePathFromOldFormat( | |
96 profile, | |
97 kDrive.AppendASCII("a/b"), | |
98 &path)); | |
99 | |
100 // Only the "/special/drive" path is converted. | |
101 EXPECT_FALSE(MigratePathFromOldFormat( | |
102 profile, | |
103 base::FilePath::FromUTF8Unsafe("/special/notdrive"), | |
104 &path)); | |
105 } | |
106 | |
107 } // namespace | 49 } // namespace |
108 } // namespace util | 50 } // namespace util |
109 } // namespace file_manager | 51 } // namespace file_manager |
OLD | NEW |