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 "testing/gtest/include/gtest/gtest.h"
20 static const char kActiveUserHash[] = "01234567890";
23 // The boolean parameter, retrieved by GetParam(), is true if testing with
24 // multi-profiles enabled.
25 class ProfileHelperTest : public InProcessBrowserTest,
26 public testing::WithParamInterface<bool> {
32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
34 command_line->AppendSwitch(::switches::kMultiProfiles);
37 void ActiveUserChanged(ProfileHelper* profile_helper,
38 const std::string& hash) {
39 profile_helper->ActiveUserHashChanged(hash);
43 IN_PROC_BROWSER_TEST_P(ProfileHelperTest, ActiveUserProfileDir) {
44 ProfileHelper profile_helper;
45 ActiveUserChanged(&profile_helper, kActiveUserHash);
46 base::FilePath profile_dir = profile_helper.GetActiveUserProfileDir();
47 std::string expected_dir;
48 expected_dir.append(chrome::kProfileDirPrefix);
49 expected_dir.append(kActiveUserHash);
50 EXPECT_EQ(expected_dir, profile_dir.BaseName().value());
53 IN_PROC_BROWSER_TEST_P(ProfileHelperTest, GetProfilePathByUserIdHash) {
54 ProfileHelper profile_helper;
55 base::FilePath profile_path =
56 profile_helper.GetProfilePathByUserIdHash(kActiveUserHash);
57 base::FilePath expected_path = g_browser_process->profile_manager()->
58 user_data_dir().Append(
59 std::string(chrome::kProfileDirPrefix) + kActiveUserHash);
60 EXPECT_EQ(expected_path, profile_path);
63 INSTANTIATE_TEST_CASE_P(ProfileHelperTestInstantiation,
67 } // namespace chromeos