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