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