1 // Copyright (c) 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.
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/profiles/profile_helper.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/common/chrome_constants.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chromeos/chromeos_switches.h"
16 #include "testing/gtest/include/gtest/gtest.h"
21 static const char kActiveUserHash
[] = "01234567890";
24 // The boolean parameter, retrieved by GetParam(), is true if testing with
25 // multi-profiles enabled.
26 class ProfileHelperTest
: public InProcessBrowserTest
,
27 public testing::WithParamInterface
<bool> {
33 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
35 command_line
->AppendSwitch(::switches::kMultiProfiles
);
38 void ActiveUserChanged(ProfileHelper
* profile_helper
,
39 const std::string
& hash
) {
40 profile_helper
->ActiveUserHashChanged(hash
);
44 IN_PROC_BROWSER_TEST_P(ProfileHelperTest
, ActiveUserProfileDir
) {
45 ProfileHelper profile_helper
;
46 ActiveUserChanged(&profile_helper
, kActiveUserHash
);
47 base::FilePath profile_dir
= profile_helper
.GetActiveUserProfileDir();
48 std::string expected_dir
;
49 expected_dir
.append(chrome::kProfileDirPrefix
);
50 expected_dir
.append(kActiveUserHash
);
51 EXPECT_EQ(expected_dir
, profile_dir
.BaseName().value());
54 IN_PROC_BROWSER_TEST_P(ProfileHelperTest
,
55 GetProfileDirByLegacyLoginProfileSwitch
) {
56 CommandLine::ForCurrentProcess()->
57 AppendSwitchASCII(chromeos::switches::kLoginProfile
,
58 chrome::kLegacyProfileDir
);
59 EXPECT_EQ(chrome::kLegacyProfileDir
,
60 ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch().value());
61 CommandLine::ForCurrentProcess()->
62 AppendSwitchASCII(chromeos::switches::kLoginProfile
,
63 chrome::kTestUserProfileDir
);
64 EXPECT_EQ(chrome::kTestUserProfileDir
,
65 ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch().value());
66 CommandLine::ForCurrentProcess()->
67 AppendSwitchASCII(chromeos::switches::kLoginProfile
,
69 EXPECT_EQ(std::string(chrome::kProfileDirPrefix
) + kActiveUserHash
,
70 ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch().value());
73 IN_PROC_BROWSER_TEST_P(ProfileHelperTest
, GetProfilePathByUserIdHash
) {
74 ProfileHelper profile_helper
;
75 base::FilePath profile_path
=
76 profile_helper
.GetProfilePathByUserIdHash(kActiveUserHash
);
77 base::FilePath expected_path
= g_browser_process
->profile_manager()->
78 user_data_dir().Append(
79 std::string(chrome::kProfileDirPrefix
) + kActiveUserHash
);
80 EXPECT_EQ(expected_path
, profile_path
);
83 INSTANTIATE_TEST_CASE_P(ProfileHelperTestInstantiation
,
87 } // namespace chromeos