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.h" | 5 #include "chrome/test/base/testing_profile.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 using base::Time; | 126 using base::Time; |
127 using bookmarks::BookmarkModel; | 127 using bookmarks::BookmarkModel; |
128 using content::BrowserThread; | 128 using content::BrowserThread; |
129 using content::DownloadManagerDelegate; | 129 using content::DownloadManagerDelegate; |
130 using testing::NiceMock; | 130 using testing::NiceMock; |
131 using testing::Return; | 131 using testing::Return; |
132 | 132 |
133 namespace { | 133 namespace { |
134 | 134 |
| 135 // Default profile name |
| 136 const char kTestingProfile[] = "testing_profile"; |
| 137 |
135 // Task used to make sure history has finished processing a request. Intended | 138 // Task used to make sure history has finished processing a request. Intended |
136 // for use with BlockUntilHistoryProcessesPendingRequests. | 139 // for use with BlockUntilHistoryProcessesPendingRequests. |
137 | 140 |
138 class QuittingHistoryDBTask : public history::HistoryDBTask { | 141 class QuittingHistoryDBTask : public history::HistoryDBTask { |
139 public: | 142 public: |
140 QuittingHistoryDBTask() {} | 143 QuittingHistoryDBTask() {} |
141 | 144 |
142 bool RunOnDBThread(history::HistoryBackend* backend, | 145 bool RunOnDBThread(history::HistoryBackend* backend, |
143 history::HistoryDatabase* db) override { | 146 history::HistoryDatabase* db) override { |
144 return true; | 147 return true; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 TestingProfile::TestingProfile() | 254 TestingProfile::TestingProfile() |
252 : start_time_(Time::Now()), | 255 : start_time_(Time::Now()), |
253 testing_prefs_(NULL), | 256 testing_prefs_(NULL), |
254 force_incognito_(false), | 257 force_incognito_(false), |
255 original_profile_(NULL), | 258 original_profile_(NULL), |
256 guest_session_(false), | 259 guest_session_(false), |
257 last_session_exited_cleanly_(true), | 260 last_session_exited_cleanly_(true), |
258 browser_context_dependency_manager_( | 261 browser_context_dependency_manager_( |
259 BrowserContextDependencyManager::GetInstance()), | 262 BrowserContextDependencyManager::GetInstance()), |
260 resource_context_(NULL), | 263 resource_context_(NULL), |
261 delegate_(NULL) { | 264 delegate_(NULL), |
| 265 profile_name_(kTestingProfile) { |
262 CreateTempProfileDir(); | 266 CreateTempProfileDir(); |
263 profile_path_ = temp_dir_.path(); | 267 profile_path_ = temp_dir_.path(); |
264 | 268 |
265 Init(); | 269 Init(); |
266 FinishInit(); | 270 FinishInit(); |
267 } | 271 } |
268 | 272 |
269 TestingProfile::TestingProfile(const base::FilePath& path) | 273 TestingProfile::TestingProfile(const base::FilePath& path) |
270 : start_time_(Time::Now()), | 274 : start_time_(Time::Now()), |
271 testing_prefs_(NULL), | 275 testing_prefs_(NULL), |
272 force_incognito_(false), | 276 force_incognito_(false), |
273 original_profile_(NULL), | 277 original_profile_(NULL), |
274 guest_session_(false), | 278 guest_session_(false), |
275 last_session_exited_cleanly_(true), | 279 last_session_exited_cleanly_(true), |
276 profile_path_(path), | 280 profile_path_(path), |
277 browser_context_dependency_manager_( | 281 browser_context_dependency_manager_( |
278 BrowserContextDependencyManager::GetInstance()), | 282 BrowserContextDependencyManager::GetInstance()), |
279 resource_context_(NULL), | 283 resource_context_(NULL), |
280 delegate_(NULL) { | 284 delegate_(NULL), |
| 285 profile_name_(kTestingProfile) { |
281 Init(); | 286 Init(); |
282 FinishInit(); | 287 FinishInit(); |
283 } | 288 } |
284 | 289 |
285 TestingProfile::TestingProfile(const base::FilePath& path, | 290 TestingProfile::TestingProfile(const base::FilePath& path, Delegate* delegate) |
286 Delegate* delegate) | |
287 : start_time_(Time::Now()), | 291 : start_time_(Time::Now()), |
288 testing_prefs_(NULL), | 292 testing_prefs_(NULL), |
289 force_incognito_(false), | 293 force_incognito_(false), |
290 original_profile_(NULL), | 294 original_profile_(NULL), |
291 guest_session_(false), | 295 guest_session_(false), |
292 last_session_exited_cleanly_(true), | 296 last_session_exited_cleanly_(true), |
293 profile_path_(path), | 297 profile_path_(path), |
294 browser_context_dependency_manager_( | 298 browser_context_dependency_manager_( |
295 BrowserContextDependencyManager::GetInstance()), | 299 BrowserContextDependencyManager::GetInstance()), |
296 resource_context_(NULL), | 300 resource_context_(NULL), |
297 delegate_(delegate) { | 301 delegate_(delegate), |
| 302 profile_name_(kTestingProfile) { |
298 Init(); | 303 Init(); |
299 if (delegate_) { | 304 if (delegate_) { |
300 base::ThreadTaskRunnerHandle::Get()->PostTask( | 305 base::ThreadTaskRunnerHandle::Get()->PostTask( |
301 FROM_HERE, | 306 FROM_HERE, |
302 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); | 307 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); |
303 } else { | 308 } else { |
304 FinishInit(); | 309 FinishInit(); |
305 } | 310 } |
306 } | 311 } |
307 | 312 |
308 TestingProfile::TestingProfile( | 313 TestingProfile::TestingProfile( |
309 const base::FilePath& path, | 314 const base::FilePath& path, |
310 Delegate* delegate, | 315 Delegate* delegate, |
311 #if defined(ENABLE_EXTENSIONS) | 316 #if defined(ENABLE_EXTENSIONS) |
312 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 317 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
313 #endif | 318 #endif |
314 scoped_ptr<syncable_prefs::PrefServiceSyncable> prefs, | 319 scoped_ptr<syncable_prefs::PrefServiceSyncable> prefs, |
315 TestingProfile* parent, | 320 TestingProfile* parent, |
316 bool guest_session, | 321 bool guest_session, |
317 const std::string& supervised_user_id, | 322 const std::string& supervised_user_id, |
318 scoped_ptr<policy::PolicyService> policy_service, | 323 scoped_ptr<policy::PolicyService> policy_service, |
319 const TestingFactories& factories) | 324 const TestingFactories& factories, |
| 325 const std::string& profile_name) |
320 : start_time_(Time::Now()), | 326 : start_time_(Time::Now()), |
321 prefs_(prefs.release()), | 327 prefs_(prefs.release()), |
322 testing_prefs_(NULL), | 328 testing_prefs_(NULL), |
323 force_incognito_(false), | 329 force_incognito_(false), |
324 original_profile_(parent), | 330 original_profile_(parent), |
325 guest_session_(guest_session), | 331 guest_session_(guest_session), |
326 last_session_exited_cleanly_(true), | 332 last_session_exited_cleanly_(true), |
327 #if defined(ENABLE_EXTENSIONS) | 333 #if defined(ENABLE_EXTENSIONS) |
328 extension_special_storage_policy_(extension_policy), | 334 extension_special_storage_policy_(extension_policy), |
329 #endif | 335 #endif |
330 profile_path_(path), | 336 profile_path_(path), |
331 browser_context_dependency_manager_( | 337 browser_context_dependency_manager_( |
332 BrowserContextDependencyManager::GetInstance()), | 338 BrowserContextDependencyManager::GetInstance()), |
333 resource_context_(NULL), | 339 resource_context_(NULL), |
334 delegate_(delegate), | 340 delegate_(delegate), |
| 341 profile_name_(profile_name), |
335 policy_service_(policy_service.release()) { | 342 policy_service_(policy_service.release()) { |
336 if (parent) | 343 if (parent) |
337 parent->SetOffTheRecordProfile(scoped_ptr<Profile>(this)); | 344 parent->SetOffTheRecordProfile(scoped_ptr<Profile>(this)); |
338 | 345 |
339 // If no profile path was supplied, create one. | 346 // If no profile path was supplied, create one. |
340 if (profile_path_.empty()) { | 347 if (profile_path_.empty()) { |
341 CreateTempProfileDir(); | 348 CreateTempProfileDir(); |
342 profile_path_ = temp_dir_.path(); | 349 profile_path_ = temp_dir_.path(); |
343 } | 350 } |
344 | 351 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 475 |
469 #if defined(ENABLE_SUPERVISED_USERS) | 476 #if defined(ENABLE_SUPERVISED_USERS) |
470 if (!IsOffTheRecord()) { | 477 if (!IsOffTheRecord()) { |
471 SupervisedUserSettingsService* settings_service = | 478 SupervisedUserSettingsService* settings_service = |
472 SupervisedUserSettingsServiceFactory::GetForProfile(this); | 479 SupervisedUserSettingsServiceFactory::GetForProfile(this); |
473 TestingPrefStore* store = new TestingPrefStore(); | 480 TestingPrefStore* store = new TestingPrefStore(); |
474 settings_service->Init(store); | 481 settings_service->Init(store); |
475 store->SetInitializationCompleted(); | 482 store->SetInitializationCompleted(); |
476 } | 483 } |
477 #endif | 484 #endif |
478 | |
479 profile_name_ = "testing_profile"; | |
480 } | 485 } |
481 | 486 |
482 void TestingProfile::FinishInit() { | 487 void TestingProfile::FinishInit() { |
483 DCHECK(content::NotificationService::current()); | 488 DCHECK(content::NotificationService::current()); |
484 content::NotificationService::current()->Notify( | 489 content::NotificationService::current()->Notify( |
485 chrome::NOTIFICATION_PROFILE_CREATED, | 490 chrome::NOTIFICATION_PROFILE_CREATED, |
486 content::Source<Profile>(static_cast<Profile*>(this)), | 491 content::Source<Profile>(static_cast<Profile*>(this)), |
487 content::NotificationService::NoDetails()); | 492 content::NotificationService::NoDetails()); |
488 | 493 |
489 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 494 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 return guest_session_; | 973 return guest_session_; |
969 } | 974 } |
970 | 975 |
971 Profile::ExitType TestingProfile::GetLastSessionExitType() { | 976 Profile::ExitType TestingProfile::GetLastSessionExitType() { |
972 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; | 977 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; |
973 } | 978 } |
974 | 979 |
975 TestingProfile::Builder::Builder() | 980 TestingProfile::Builder::Builder() |
976 : build_called_(false), | 981 : build_called_(false), |
977 delegate_(NULL), | 982 delegate_(NULL), |
978 guest_session_(false) { | 983 guest_session_(false), |
979 } | 984 profile_name_(kTestingProfile) {} |
980 | 985 |
981 TestingProfile::Builder::~Builder() { | 986 TestingProfile::Builder::~Builder() { |
982 } | 987 } |
983 | 988 |
984 void TestingProfile::Builder::SetPath(const base::FilePath& path) { | 989 void TestingProfile::Builder::SetPath(const base::FilePath& path) { |
985 path_ = path; | 990 path_ = path; |
986 } | 991 } |
987 | 992 |
988 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { | 993 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { |
989 delegate_ = delegate; | 994 delegate_ = delegate; |
(...skipping 18 matching lines...) Expand all Loading... |
1008 void TestingProfile::Builder::SetSupervisedUserId( | 1013 void TestingProfile::Builder::SetSupervisedUserId( |
1009 const std::string& supervised_user_id) { | 1014 const std::string& supervised_user_id) { |
1010 supervised_user_id_ = supervised_user_id; | 1015 supervised_user_id_ = supervised_user_id; |
1011 } | 1016 } |
1012 | 1017 |
1013 void TestingProfile::Builder::SetPolicyService( | 1018 void TestingProfile::Builder::SetPolicyService( |
1014 scoped_ptr<policy::PolicyService> policy_service) { | 1019 scoped_ptr<policy::PolicyService> policy_service) { |
1015 policy_service_ = std::move(policy_service); | 1020 policy_service_ = std::move(policy_service); |
1016 } | 1021 } |
1017 | 1022 |
| 1023 void TestingProfile::Builder::SetProfileName(const std::string& profile_name) { |
| 1024 profile_name_ = profile_name; |
| 1025 } |
| 1026 |
1018 void TestingProfile::Builder::AddTestingFactory( | 1027 void TestingProfile::Builder::AddTestingFactory( |
1019 BrowserContextKeyedServiceFactory* service_factory, | 1028 BrowserContextKeyedServiceFactory* service_factory, |
1020 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { | 1029 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { |
1021 testing_factories_.push_back(std::make_pair(service_factory, callback)); | 1030 testing_factories_.push_back(std::make_pair(service_factory, callback)); |
1022 } | 1031 } |
1023 | 1032 |
1024 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 1033 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
1025 DCHECK(!build_called_); | 1034 DCHECK(!build_called_); |
1026 build_called_ = true; | 1035 build_called_ = true; |
1027 | 1036 |
1028 return scoped_ptr<TestingProfile>(new TestingProfile( | 1037 return scoped_ptr<TestingProfile>(new TestingProfile( |
1029 path_, delegate_, | 1038 path_, delegate_, |
1030 #if defined(ENABLE_EXTENSIONS) | 1039 #if defined(ENABLE_EXTENSIONS) |
1031 extension_policy_, | 1040 extension_policy_, |
1032 #endif | 1041 #endif |
1033 std::move(pref_service_), NULL, guest_session_, supervised_user_id_, | 1042 std::move(pref_service_), NULL, guest_session_, supervised_user_id_, |
1034 std::move(policy_service_), testing_factories_)); | 1043 std::move(policy_service_), testing_factories_, profile_name_)); |
1035 } | 1044 } |
1036 | 1045 |
1037 TestingProfile* TestingProfile::Builder::BuildIncognito( | 1046 TestingProfile* TestingProfile::Builder::BuildIncognito( |
1038 TestingProfile* original_profile) { | 1047 TestingProfile* original_profile) { |
1039 DCHECK(!build_called_); | 1048 DCHECK(!build_called_); |
1040 DCHECK(original_profile); | 1049 DCHECK(original_profile); |
1041 build_called_ = true; | 1050 build_called_ = true; |
1042 | 1051 |
1043 // Note: Owned by |original_profile|. | 1052 // Note: Owned by |original_profile|. |
1044 return new TestingProfile(path_, delegate_, | 1053 return new TestingProfile(path_, delegate_, |
1045 #if defined(ENABLE_EXTENSIONS) | 1054 #if defined(ENABLE_EXTENSIONS) |
1046 extension_policy_, | 1055 extension_policy_, |
1047 #endif | 1056 #endif |
1048 std::move(pref_service_), original_profile, | 1057 std::move(pref_service_), original_profile, |
1049 guest_session_, supervised_user_id_, | 1058 guest_session_, supervised_user_id_, |
1050 std::move(policy_service_), testing_factories_); | 1059 std::move(policy_service_), testing_factories_, |
| 1060 profile_name_); |
1051 } | 1061 } |
OLD | NEW |