blob: bcc844e2c8b9a94f143d179025ece6a789bc21f1 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commit09911bf2008-07-26 23:55:294
5#include "base/file_util.h"
6#include "base/path_service.h"
7#include "chrome/browser/profile.h"
8#include "chrome/browser/profile_manager.h"
9#include "chrome/common/chrome_paths.h"
10#include "chrome/common/pref_names.h"
11#include "chrome/common/pref_service.h"
12#include "testing/gtest/include/gtest/gtest.h"
13
14namespace {
15
16class ProfileManagerTest : public testing::Test {
17protected:
18 virtual void SetUp() {
19 // Name a subdirectory of the temp directory.
20 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
21 file_util::AppendToPath(&test_dir_, L"ProfileManagerTest");
22
23 // Create a fresh, empty copy of this directory.
24 file_util::Delete(test_dir_, true);
25 CreateDirectory(test_dir_.c_str(), NULL);
26 }
27 virtual void TearDown() {
28 // Clean up test directory
29 ASSERT_TRUE(file_util::Delete(test_dir_, true));
30 ASSERT_FALSE(file_util::PathExists(test_dir_));
31 }
32
33 // the path to temporary directory used to contain the test operations
34 std::wstring test_dir_;
35};
36
37};
38
39TEST_F(ProfileManagerTest, CopyProfileData) {
40 std::wstring source_path;
41 PathService::Get(chrome::DIR_TEST_DATA, &source_path);
42 file_util::AppendToPath(&source_path, L"profiles");
43
44 ASSERT_FALSE(ProfileManager::IsProfile(source_path));
45 file_util::AppendToPath(&source_path, L"sample");
46 ASSERT_TRUE(ProfileManager::IsProfile(source_path));
47
48 std::wstring dest_path = test_dir_;
49 file_util::AppendToPath(&dest_path, L"profile_copy");
50 ASSERT_FALSE(ProfileManager::IsProfile(dest_path));
51 ASSERT_TRUE(ProfileManager::CopyProfileData(source_path, dest_path));
52 ASSERT_TRUE(ProfileManager::IsProfile(dest_path));
53}
54
55TEST_F(ProfileManagerTest, CreateProfile) {
56 std::wstring source_path;
57 PathService::Get(chrome::DIR_TEST_DATA, &source_path);
58 file_util::AppendToPath(&source_path, L"profiles");
59 file_util::AppendToPath(&source_path, L"sample");
60
61 std::wstring dest_path = test_dir_;
62 file_util::AppendToPath(&dest_path, L"New Profile");
63
64 scoped_ptr<Profile> profile;
65
66 // Successfully create a profile.
67 profile.reset(ProfileManager::CreateProfile(dest_path, L"New Profile", L"",
68 L"new-profile"));
69 ASSERT_TRUE(profile.get());
70
71 PrefService* prefs = profile->GetPrefs();
72 ASSERT_EQ(L"New Profile", prefs->GetString(prefs::kProfileName));
73 ASSERT_EQ(L"new-profile", prefs->GetString(prefs::kProfileID));
74 profile.reset();
75
76#ifdef NDEBUG
77 // In Release mode, we always try to always return a profile. In debug,
78 // these cases would trigger DCHECKs.
79
80 // The profile already exists when we call CreateProfile. Just load it.
81 profile.reset(ProfileManager::CreateProfile(dest_path, L"New Profile", L"",
82 L"new-profile"));
83 ASSERT_TRUE(profile.get());
84 prefs = profile->GetPrefs();
85 ASSERT_EQ(L"New Profile", prefs->GetString(prefs::kProfileName));
86 ASSERT_EQ(L"new-profile", prefs->GetString(prefs::kProfileID));
87#endif
88}
license.botbf09a502008-08-24 00:55:5589