OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/testing_profile_manager.h" | 5 #include "chrome/test/base/testing_profile_manager.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 11 #include "chrome/browser/prefs/pref_service_syncable.h" |
10 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
13 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 namespace testing { | 18 namespace testing { |
17 | 19 |
18 class ProfileManager : public ::ProfileManager { | 20 class ProfileManager : public ::ProfileManager { |
19 public: | 21 public: |
(...skipping 18 matching lines...) Expand all Loading... |
38 TestingProfileManager::~TestingProfileManager() { | 40 TestingProfileManager::~TestingProfileManager() { |
39 } | 41 } |
40 | 42 |
41 bool TestingProfileManager::SetUp() { | 43 bool TestingProfileManager::SetUp() { |
42 SetUpInternal(); | 44 SetUpInternal(); |
43 return called_set_up_; | 45 return called_set_up_; |
44 } | 46 } |
45 | 47 |
46 TestingProfile* TestingProfileManager::CreateTestingProfile( | 48 TestingProfile* TestingProfileManager::CreateTestingProfile( |
47 const std::string& profile_name, | 49 const std::string& profile_name, |
| 50 scoped_ptr<PrefServiceSyncable> prefs, |
48 const string16& user_name, | 51 const string16& user_name, |
49 int avatar_id) { | 52 int avatar_id) { |
50 DCHECK(called_set_up_); | 53 DCHECK(called_set_up_); |
51 | 54 |
52 // Create a path for the profile based on the name. | 55 // Create a path for the profile based on the name. |
53 base::FilePath profile_path(profiles_dir_.path()); | 56 base::FilePath profile_path(profiles_dir_.path()); |
54 profile_path = profile_path.AppendASCII(profile_name); | 57 profile_path = profile_path.AppendASCII(profile_name); |
55 | 58 |
56 // Create the profile and register it. | 59 // Create the profile and register it. |
57 TestingProfile* profile = new TestingProfile(profile_path); | 60 TestingProfile* profile = new TestingProfile( |
| 61 profile_path, |
| 62 NULL, |
| 63 scoped_refptr<ExtensionSpecialStoragePolicy>(), |
| 64 prefs.Pass()); |
58 profile_manager_->AddProfile(profile); // Takes ownership. | 65 profile_manager_->AddProfile(profile); // Takes ownership. |
59 | 66 |
60 // Update the user metadata. | 67 // Update the user metadata. |
61 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 68 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
62 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | 69 size_t index = cache.GetIndexOfProfileWithPath(profile_path); |
63 cache.SetNameOfProfileAtIndex(index, user_name); | 70 cache.SetNameOfProfileAtIndex(index, user_name); |
64 cache.SetAvatarIconOfProfileAtIndex(index, avatar_id); | 71 cache.SetAvatarIconOfProfileAtIndex(index, avatar_id); |
65 | 72 |
66 testing_profiles_.insert(std::make_pair(profile_name, profile)); | 73 testing_profiles_.insert(std::make_pair(profile_name, profile)); |
67 | 74 |
68 return profile; | 75 return profile; |
69 } | 76 } |
70 | 77 |
71 TestingProfile* TestingProfileManager::CreateTestingProfile( | 78 TestingProfile* TestingProfileManager::CreateTestingProfile( |
72 const std::string& name) { | 79 const std::string& name) { |
73 DCHECK(called_set_up_); | 80 DCHECK(called_set_up_); |
74 return CreateTestingProfile(name, UTF8ToUTF16(name), 0); | 81 return CreateTestingProfile(name, scoped_ptr<PrefServiceSyncable>(), |
| 82 UTF8ToUTF16(name), 0); |
75 } | 83 } |
76 | 84 |
77 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { | 85 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { |
78 DCHECK(called_set_up_); | 86 DCHECK(called_set_up_); |
79 | 87 |
80 TestingProfilesMap::iterator it = testing_profiles_.find(name); | 88 TestingProfilesMap::iterator it = testing_profiles_.find(name); |
81 DCHECK(it != testing_profiles_.end()); | 89 DCHECK(it != testing_profiles_.end()); |
82 | 90 |
83 TestingProfile* profile = it->second; | 91 TestingProfile* profile = it->second; |
84 | 92 |
(...skipping 26 matching lines...) Expand all Loading... |
111 << "ProfileManager already exists"; | 119 << "ProfileManager already exists"; |
112 | 120 |
113 // Set up the directory for profiles. | 121 // Set up the directory for profiles. |
114 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); | 122 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); |
115 | 123 |
116 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); | 124 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); |
117 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. | 125 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. |
118 | 126 |
119 called_set_up_ = true; | 127 called_set_up_ = true; |
120 } | 128 } |
OLD | NEW |