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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/file_manager/path_util.h"
7 #include "base/files/file_path.h"
8 #include "chrome/browser/chromeos/drive/file_system_util.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"
12 #include "chrome/test/base/testing_profile_manager.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace file_manager {
19 class ProfileRelatedTest : public testing::Test {
22 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {
25 virtual void SetUp() OVERRIDE {
26 ASSERT_TRUE(testing_profile_manager_.SetUp());
29 Profile* CreateProfileWithName(const std::string& name) {
30 return testing_profile_manager_.CreateTestingProfile(name);
34 TestingProfileManager testing_profile_manager_;
37 TEST(FileManagerPathUtilTest, MultiProfileDownloadsFolderMigration) {
38 TestingProfile profile;
40 // This looks like "/home/chronos/u-hash/Downloads" in the production
42 const base::FilePath kDownloads = GetDownloadsFolderForProfile(&profile);
46 EXPECT_TRUE(MigratePathFromOldFormat(
48 base::FilePath::FromUTF8Unsafe("/home/chronos/user/Downloads"),
50 EXPECT_EQ(kDownloads, path);
52 EXPECT_TRUE(MigratePathFromOldFormat(
54 base::FilePath::FromUTF8Unsafe("/home/chronos/user/Downloads/a/b"),
56 EXPECT_EQ(kDownloads.AppendASCII("a/b"), path);
58 // Path already in the new format is not converted.
59 EXPECT_FALSE(MigratePathFromOldFormat(
61 kDownloads.AppendASCII("a/b"),
64 // Only the "Downloads" path is converted.
65 EXPECT_FALSE(MigratePathFromOldFormat(
67 base::FilePath::FromUTF8Unsafe("/home/chronos/user/dl"),
71 TEST_F(ProfileRelatedTest, MultiProfileDriveFolderMigration) {
72 Profile* profile = CreateProfileWithName("user1");
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),
82 EXPECT_TRUE(MigratePathFromOldFormat(
84 base::FilePath::FromUTF8Unsafe("/special/drive"),
86 EXPECT_EQ(kDrive, path);
88 EXPECT_TRUE(MigratePathFromOldFormat(
90 base::FilePath::FromUTF8Unsafe("/special/drive/a/b"),
92 EXPECT_EQ(kDrive.AppendASCII("a/b"), path);
94 // Path already in the new format is not converted.
95 EXPECT_FALSE(MigratePathFromOldFormat(
97 kDrive.AppendASCII("a/b"),
100 // Only the "/special/drive" path is converted.
101 EXPECT_FALSE(MigratePathFromOldFormat(
103 base::FilePath::FromUTF8Unsafe("/special/notdrive"),
109 } // namespace file_manager