• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include <string>
6 
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"
17 
18 namespace chromeos {
19 
20 namespace {
21 static const char kActiveUserHash[] = "01234567890";
22 } // namespace
23 
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> {
28  public:
ProfileHelperTest()29   ProfileHelperTest() {
30   }
31 
32  protected:
SetUpCommandLine(CommandLine * command_line)33   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
34     if (GetParam())
35       command_line->AppendSwitch(::switches::kMultiProfiles);
36   }
37 
ActiveUserChanged(ProfileHelper * profile_helper,const std::string & hash)38   void ActiveUserChanged(ProfileHelper* profile_helper,
39                          const std::string& hash) {
40     profile_helper->ActiveUserHashChanged(hash);
41   }
42 };
43 
IN_PROC_BROWSER_TEST_P(ProfileHelperTest,ActiveUserProfileDir)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());
52 }
53 
IN_PROC_BROWSER_TEST_P(ProfileHelperTest,GetProfileDirByLegacyLoginProfileSwitch)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,
68                           kActiveUserHash);
69   EXPECT_EQ(std::string(chrome::kProfileDirPrefix) + kActiveUserHash,
70             ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch().value());
71 }
72 
IN_PROC_BROWSER_TEST_P(ProfileHelperTest,GetProfilePathByUserIdHash)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);
81 }
82 
83 INSTANTIATE_TEST_CASE_P(ProfileHelperTestInstantiation,
84                         ProfileHelperTest,
85                         testing::Bool());
86 
87 }  // namespace chromeos
88