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/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 9 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
10 #include "chrome/browser/prefs/pref_service_syncable.h" | 10 #include "chrome/browser/prefs/pref_service_syncable.h" |
11 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
14 #include "chrome/test/base/testing_profile.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace testing { | 16 namespace testing { |
18 | 17 |
19 class ProfileManager : public ::ProfileManagerWithoutInit { | 18 class ProfileManager : public ::ProfileManagerWithoutInit { |
20 public: | 19 public: |
21 explicit ProfileManager(const base::FilePath& user_data_dir) | 20 explicit ProfileManager(const base::FilePath& user_data_dir) |
22 : ::ProfileManagerWithoutInit(user_data_dir) {} | 21 : ::ProfileManagerWithoutInit(user_data_dir) {} |
23 | 22 |
24 protected: | 23 protected: |
(...skipping 17 matching lines...) Expand all Loading... |
42 bool TestingProfileManager::SetUp() { | 41 bool TestingProfileManager::SetUp() { |
43 SetUpInternal(); | 42 SetUpInternal(); |
44 return called_set_up_; | 43 return called_set_up_; |
45 } | 44 } |
46 | 45 |
47 TestingProfile* TestingProfileManager::CreateTestingProfile( | 46 TestingProfile* TestingProfileManager::CreateTestingProfile( |
48 const std::string& profile_name, | 47 const std::string& profile_name, |
49 scoped_ptr<PrefServiceSyncable> prefs, | 48 scoped_ptr<PrefServiceSyncable> prefs, |
50 const string16& user_name, | 49 const string16& user_name, |
51 int avatar_id, | 50 int avatar_id, |
52 const std::string& managed_user_id) { | 51 const std::string& managed_user_id, |
| 52 const TestingProfile::TestingFactories& factories) { |
53 DCHECK(called_set_up_); | 53 DCHECK(called_set_up_); |
54 | 54 |
55 // Create a path for the profile based on the name. | 55 // Create a path for the profile based on the name. |
56 base::FilePath profile_path(profiles_dir_.path()); | 56 base::FilePath profile_path(profiles_dir_.path()); |
57 profile_path = profile_path.AppendASCII(profile_name); | 57 profile_path = profile_path.AppendASCII(profile_name); |
58 | 58 |
59 // Create the profile and register it. | 59 // Create the profile and register it. |
60 TestingProfile::Builder builder; | 60 TestingProfile::Builder builder; |
61 builder.SetPath(profile_path); | 61 builder.SetPath(profile_path); |
62 builder.SetPrefService(prefs.Pass()); | 62 builder.SetPrefService(prefs.Pass()); |
63 builder.SetManagedUserId(managed_user_id); | 63 builder.SetManagedUserId(managed_user_id); |
64 | 64 |
| 65 for (TestingProfile::TestingFactories::const_iterator it = factories.begin(); |
| 66 it != factories.end(); ++it) { |
| 67 builder.AddTestingFactory(it->first, it->second); |
| 68 } |
| 69 |
65 TestingProfile* profile = builder.Build().release(); | 70 TestingProfile* profile = builder.Build().release(); |
66 profile->set_profile_name(profile_name); | 71 profile->set_profile_name(profile_name); |
67 profile_manager_->AddProfile(profile); // Takes ownership. | 72 profile_manager_->AddProfile(profile); // Takes ownership. |
68 | 73 |
69 // Update the user metadata. | 74 // Update the user metadata. |
70 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 75 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
71 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | 76 size_t index = cache.GetIndexOfProfileWithPath(profile_path); |
72 cache.SetAvatarIconOfProfileAtIndex(index, avatar_id); | 77 cache.SetAvatarIconOfProfileAtIndex(index, avatar_id); |
73 cache.SetManagedUserIdOfProfileAtIndex(index, managed_user_id); | 78 cache.SetManagedUserIdOfProfileAtIndex(index, managed_user_id); |
74 // SetNameOfProfileAtIndex may reshuffle the list of profiles, so we do it | 79 // SetNameOfProfileAtIndex may reshuffle the list of profiles, so we do it |
75 // last. | 80 // last. |
76 cache.SetNameOfProfileAtIndex(index, user_name); | 81 cache.SetNameOfProfileAtIndex(index, user_name); |
77 | 82 |
78 testing_profiles_.insert(std::make_pair(profile_name, profile)); | 83 testing_profiles_.insert(std::make_pair(profile_name, profile)); |
79 | 84 |
80 return profile; | 85 return profile; |
81 } | 86 } |
82 | 87 |
83 TestingProfile* TestingProfileManager::CreateTestingProfile( | 88 TestingProfile* TestingProfileManager::CreateTestingProfile( |
84 const std::string& name) { | 89 const std::string& name) { |
85 DCHECK(called_set_up_); | 90 DCHECK(called_set_up_); |
86 return CreateTestingProfile(name, scoped_ptr<PrefServiceSyncable>(), | 91 return CreateTestingProfile(name, scoped_ptr<PrefServiceSyncable>(), |
87 UTF8ToUTF16(name), 0, std::string()); | 92 UTF8ToUTF16(name), 0, std::string(), |
| 93 TestingProfile::TestingFactories()); |
88 } | 94 } |
89 | 95 |
90 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { | 96 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { |
91 DCHECK(called_set_up_); | 97 DCHECK(called_set_up_); |
92 | 98 |
93 TestingProfilesMap::iterator it = testing_profiles_.find(name); | 99 TestingProfilesMap::iterator it = testing_profiles_.find(name); |
94 DCHECK(it != testing_profiles_.end()); | 100 DCHECK(it != testing_profiles_.end()); |
95 | 101 |
96 TestingProfile* profile = it->second; | 102 TestingProfile* profile = it->second; |
97 | 103 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 << "ProfileManager already exists"; | 135 << "ProfileManager already exists"; |
130 | 136 |
131 // Set up the directory for profiles. | 137 // Set up the directory for profiles. |
132 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); | 138 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); |
133 | 139 |
134 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); | 140 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); |
135 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. | 141 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. |
136 | 142 |
137 called_set_up_ = true; | 143 called_set_up_ = true; |
138 } | 144 } |
OLD | NEW |