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. 4 5 #include "chrome/browser/chromeos/file_manager/path_util.h" 6 7 #include "base/files/file_path.h" 8 #include "chrome/browser/chromeos/drive/file_system_util.h" 9 #include "chrome/common/chrome_constants.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" 14 15 namespace file_manager { 16 namespace util { 17 namespace { 18 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( 31 chrome::kProfileDirPrefix + name); 32 } 33 34 private: 35 TestingProfileManager testing_profile_manager_; 36 }; 37 38 TEST(FileManagerPathUtilTest, MultiProfileDownloadsFolderMigration) { 39 TestingProfile profile; 40 41 // This looks like "/home/chronos/u-hash/Downloads" in the production 42 // environment. 43 const base::FilePath kDownloads = GetDownloadsFolderForProfile(&profile); 44 45 base::FilePath path; 46 47 EXPECT_TRUE(MigratePathFromOldFormat( 48 &profile, 49 base::FilePath::FromUTF8Unsafe("/home/chronos/user/Downloads"), 50 &path)); 51 EXPECT_EQ(kDownloads, path); 52 53 EXPECT_TRUE(MigratePathFromOldFormat( 54 &profile, 55 base::FilePath::FromUTF8Unsafe("/home/chronos/user/Downloads/a/b"), 56 &path)); 57 EXPECT_EQ(kDownloads.AppendASCII("a/b"), path); 58 59 // Path already in the new format is not converted. 60 EXPECT_FALSE(MigratePathFromOldFormat( 61 &profile, 62 kDownloads.AppendASCII("a/b"), 63 &path)); 64 65 // Only the "Downloads" path is converted. 66 EXPECT_FALSE(MigratePathFromOldFormat( 67 &profile, 68 base::FilePath::FromUTF8Unsafe("/home/chronos/user/dl"), 69 &path)); 70 } 71 72 TEST_F(ProfileRelatedTest, MultiProfileDriveFolderMigration) { 73 Profile* profile = CreateProfileWithName("hash"); 74 75 const base::FilePath kDrive = drive::util::GetDriveMountPointPath(profile); 76 ASSERT_EQ(base::FilePath::FromUTF8Unsafe("/special/drive-hash"), kDrive); 77 78 base::FilePath path; 79 80 EXPECT_TRUE(MigratePathFromOldFormat( 81 profile, 82 base::FilePath::FromUTF8Unsafe("/special/drive"), 83 &path)); 84 EXPECT_EQ(kDrive, path); 85 86 EXPECT_TRUE(MigratePathFromOldFormat( 87 profile, 88 base::FilePath::FromUTF8Unsafe("/special/drive/a/b"), 89 &path)); 90 EXPECT_EQ(kDrive.AppendASCII("a/b"), path); 91 92 // Path already in the new format is not converted. 93 EXPECT_FALSE(MigratePathFromOldFormat( 94 profile, 95 kDrive.AppendASCII("a/b"), 96 &path)); 97 98 // Only the "/special/drive" path is converted. 99 EXPECT_FALSE(MigratePathFromOldFormat( 100 profile, 101 base::FilePath::FromUTF8Unsafe("/special/notdrive"), 102 &path)); 103 } 104 105 } // namespace 106 } // namespace util 107 } // namespace file_manager 108