Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / file_manager / path_util_unittest.cc
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/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"
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(name);
31   }
32
33  private:
34   TestingProfileManager testing_profile_manager_;
35 };
36
37 TEST(FileManagerPathUtilTest, MultiProfileDownloadsFolderMigration) {
38   TestingProfile profile;
39
40   // This looks like "/home/chronos/u-hash/Downloads" in the production
41   // environment.
42   const base::FilePath kDownloads = GetDownloadsFolderForProfile(&profile);
43
44   base::FilePath path;
45
46   EXPECT_TRUE(MigratePathFromOldFormat(
47       &profile,
48       base::FilePath::FromUTF8Unsafe("/home/chronos/user/Downloads"),
49       &path));
50   EXPECT_EQ(kDownloads, path);
51
52   EXPECT_TRUE(MigratePathFromOldFormat(
53       &profile,
54       base::FilePath::FromUTF8Unsafe("/home/chronos/user/Downloads/a/b"),
55       &path));
56   EXPECT_EQ(kDownloads.AppendASCII("a/b"), path);
57
58   // Path already in the new format is not converted.
59   EXPECT_FALSE(MigratePathFromOldFormat(
60       &profile,
61       kDownloads.AppendASCII("a/b"),
62       &path));
63
64   // Only the "Downloads" path is converted.
65   EXPECT_FALSE(MigratePathFromOldFormat(
66       &profile,
67       base::FilePath::FromUTF8Unsafe("/home/chronos/user/dl"),
68       &path));
69 }
70
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
108 }  // namespace util
109 }  // namespace file_manager