1b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// found in the LICENSE file.
4b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
5b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include <string>
6b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/command_line.h"
8b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "base/files/file_path.h"
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/browser_process.h"
10b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/browser/chromeos/profiles/profile_helper.h"
1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/common/chrome_constants.h"
13b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chromeos/chromeos_switches.h"
15b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
16b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
17b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace chromeos {
18b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
19b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace {
20b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)static const char kActiveUserHash[] = "01234567890";
21b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} // namespace
22b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// The boolean parameter, retrieved by GetParam(), is true if testing with
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// multi-profiles enabled.
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class ProfileHelperTest : public InProcessBrowserTest {
26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) public:
27b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ProfileHelperTest() {
28b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
29b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
30b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) protected:
31b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  void ActiveUserChanged(ProfileHelper* profile_helper,
32b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                         const std::string& hash) {
33b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    profile_helper->ActiveUserHashChanged(hash);
34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)};
36b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ProfileHelperTest, ActiveUserProfileDir) {
38b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ProfileHelper profile_helper;
39b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ActiveUserChanged(&profile_helper, kActiveUserHash);
40b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  base::FilePath profile_dir = profile_helper.GetActiveUserProfileDir();
41b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  std::string expected_dir;
4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  expected_dir.append(chrome::kProfileDirPrefix);
43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  expected_dir.append(kActiveUserHash);
44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  EXPECT_EQ(expected_dir, profile_dir.BaseName().value());
45b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
46b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ProfileHelperTest,
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                       GetProfileDirByLegacyLoginProfileSwitch) {
49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  CommandLine::ForCurrentProcess()->
50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      AppendSwitchASCII(chromeos::switches::kLoginProfile,
51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                        chrome::kLegacyProfileDir);
52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(chrome::kLegacyProfileDir,
53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch().value());
54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  CommandLine::ForCurrentProcess()->
55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      AppendSwitchASCII(chromeos::switches::kLoginProfile,
56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                        chrome::kTestUserProfileDir);
57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(chrome::kTestUserProfileDir,
58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch().value());
59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  CommandLine::ForCurrentProcess()->
60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        AppendSwitchASCII(chromeos::switches::kLoginProfile,
61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                          kActiveUserHash);
62a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(std::string(chrome::kProfileDirPrefix) + kActiveUserHash,
63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch().value());
64a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
66cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ProfileHelperTest, GetProfilePathByUserIdHash) {
6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ProfileHelper profile_helper;
6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::FilePath profile_path =
6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      profile_helper.GetProfilePathByUserIdHash(kActiveUserHash);
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::FilePath expected_path = g_browser_process->profile_manager()->
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      user_data_dir().Append(
7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)          std::string(chrome::kProfileDirPrefix) + kActiveUserHash);
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(expected_path, profile_path);
7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
76b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}  // namespace chromeos
77