- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / profiles / profile_helper_browsertest.cc
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 "testing/gtest/include/gtest/gtest.h"
16
17 namespace chromeos {
18
19 namespace {
20 static const char kActiveUserHash[] = "01234567890";
21 } // namespace
22
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> {
27  public:
28   ProfileHelperTest() {
29   }
30
31  protected:
32   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
33     if (GetParam())
34       command_line->AppendSwitch(::switches::kMultiProfiles);
35   }
36
37   void ActiveUserChanged(ProfileHelper* profile_helper,
38                          const std::string& hash) {
39     profile_helper->ActiveUserHashChanged(hash);
40   }
41 };
42
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());
51 }
52
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);
61 }
62
63 INSTANTIATE_TEST_CASE_P(ProfileHelperTestInstantiation,
64                         ProfileHelperTest,
65                         testing::Bool());
66
67 }  // namespace chromeos