| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 #include "components/zoom/zoom_event_manager.h" | 86 #include "components/zoom/zoom_event_manager.h" |
| 87 #include "content/public/browser/browser_thread.h" | 87 #include "content/public/browser/browser_thread.h" |
| 88 #include "content/public/browser/cookie_store_factory.h" | 88 #include "content/public/browser/cookie_store_factory.h" |
| 89 #include "content/public/browser/notification_service.h" | 89 #include "content/public/browser/notification_service.h" |
| 90 #include "content/public/browser/render_process_host.h" | 90 #include "content/public/browser/render_process_host.h" |
| 91 #include "content/public/browser/storage_partition.h" | 91 #include "content/public/browser/storage_partition.h" |
| 92 #include "content/public/browser/zoom_level_delegate.h" | 92 #include "content/public/browser/zoom_level_delegate.h" |
| 93 #include "content/public/test/mock_resource_context.h" | 93 #include "content/public/test/mock_resource_context.h" |
| 94 #include "content/public/test/test_utils.h" | 94 #include "content/public/test/test_utils.h" |
| 95 #include "extensions/common/constants.h" | 95 #include "extensions/common/constants.h" |
| 96 #include "extensions/features/features.h" |
| 96 #include "net/cookies/cookie_store.h" | 97 #include "net/cookies/cookie_store.h" |
| 97 #include "net/url_request/url_request_context.h" | 98 #include "net/url_request/url_request_context.h" |
| 98 #include "net/url_request/url_request_context_getter.h" | 99 #include "net/url_request/url_request_context_getter.h" |
| 99 #include "net/url_request/url_request_test_util.h" | 100 #include "net/url_request/url_request_test_util.h" |
| 100 #include "testing/gmock/include/gmock/gmock.h" | 101 #include "testing/gmock/include/gmock/gmock.h" |
| 101 | 102 |
| 102 #if defined(ENABLE_EXTENSIONS) | 103 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 103 #include "chrome/browser/extensions/extension_service.h" | 104 #include "chrome/browser/extensions/extension_service.h" |
| 104 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 105 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 105 #include "chrome/browser/extensions/extension_system_factory.h" | 106 #include "chrome/browser/extensions/extension_system_factory.h" |
| 106 #include "chrome/browser/extensions/test_extension_system.h" | 107 #include "chrome/browser/extensions/test_extension_system.h" |
| 107 #include "components/guest_view/browser/guest_view_manager.h" | 108 #include "components/guest_view/browser/guest_view_manager.h" |
| 108 #include "extensions/browser/event_router_factory.h" | 109 #include "extensions/browser/event_router_factory.h" |
| 109 #include "extensions/browser/extension_pref_value_map.h" | 110 #include "extensions/browser/extension_pref_value_map.h" |
| 110 #include "extensions/browser/extension_pref_value_map_factory.h" | 111 #include "extensions/browser/extension_pref_value_map_factory.h" |
| 111 #include "extensions/browser/extension_prefs.h" | 112 #include "extensions/browser/extension_prefs.h" |
| 112 #include "extensions/browser/extension_prefs_factory.h" | 113 #include "extensions/browser/extension_prefs_factory.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 FROM_HERE, | 324 FROM_HERE, |
| 324 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); | 325 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); |
| 325 } else { | 326 } else { |
| 326 FinishInit(); | 327 FinishInit(); |
| 327 } | 328 } |
| 328 } | 329 } |
| 329 | 330 |
| 330 TestingProfile::TestingProfile( | 331 TestingProfile::TestingProfile( |
| 331 const base::FilePath& path, | 332 const base::FilePath& path, |
| 332 Delegate* delegate, | 333 Delegate* delegate, |
| 333 #if defined(ENABLE_EXTENSIONS) | 334 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 334 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 335 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
| 335 #endif | 336 #endif |
| 336 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs, | 337 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs, |
| 337 TestingProfile* parent, | 338 TestingProfile* parent, |
| 338 bool guest_session, | 339 bool guest_session, |
| 339 const std::string& supervised_user_id, | 340 const std::string& supervised_user_id, |
| 340 std::unique_ptr<policy::PolicyService> policy_service, | 341 std::unique_ptr<policy::PolicyService> policy_service, |
| 341 const TestingFactories& factories, | 342 const TestingFactories& factories, |
| 342 const std::string& profile_name) | 343 const std::string& profile_name) |
| 343 : start_time_(Time::Now()), | 344 : start_time_(Time::Now()), |
| 344 prefs_(prefs.release()), | 345 prefs_(prefs.release()), |
| 345 testing_prefs_(NULL), | 346 testing_prefs_(NULL), |
| 346 force_incognito_(false), | 347 force_incognito_(false), |
| 347 original_profile_(parent), | 348 original_profile_(parent), |
| 348 guest_session_(guest_session), | 349 guest_session_(guest_session), |
| 349 supervised_user_id_(supervised_user_id), | 350 supervised_user_id_(supervised_user_id), |
| 350 last_session_exited_cleanly_(true), | 351 last_session_exited_cleanly_(true), |
| 351 #if defined(ENABLE_EXTENSIONS) | 352 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 352 extension_special_storage_policy_(extension_policy), | 353 extension_special_storage_policy_(extension_policy), |
| 353 #endif | 354 #endif |
| 354 profile_path_(path), | 355 profile_path_(path), |
| 355 browser_context_dependency_manager_( | 356 browser_context_dependency_manager_( |
| 356 BrowserContextDependencyManager::GetInstance()), | 357 BrowserContextDependencyManager::GetInstance()), |
| 357 resource_context_(NULL), | 358 resource_context_(NULL), |
| 358 delegate_(delegate), | 359 delegate_(delegate), |
| 359 profile_name_(profile_name), | 360 profile_name_(profile_name), |
| 360 policy_service_(policy_service.release()) { | 361 policy_service_(policy_service.release()) { |
| 361 if (parent) | 362 if (parent) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 base::CreateDirectory(profile_path_); | 467 base::CreateDirectory(profile_path_); |
| 467 | 468 |
| 468 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl | 469 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl |
| 469 // anymore, after converting the PrefService to a PKS. Until then it must | 470 // anymore, after converting the PrefService to a PKS. Until then it must |
| 470 // be associated with a TestingProfile too. | 471 // be associated with a TestingProfile too. |
| 471 if (!IsOffTheRecord()) | 472 if (!IsOffTheRecord()) |
| 472 CreateProfilePolicyConnector(); | 473 CreateProfilePolicyConnector(); |
| 473 | 474 |
| 474 extensions_path_ = profile_path_.AppendASCII("Extensions"); | 475 extensions_path_ = profile_path_.AppendASCII("Extensions"); |
| 475 | 476 |
| 476 #if defined(ENABLE_EXTENSIONS) | 477 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 477 // Note that the GetPrefs() creates a TestingPrefService, therefore | 478 // Note that the GetPrefs() creates a TestingPrefService, therefore |
| 478 // the extension controlled pref values set in ExtensionPrefs | 479 // the extension controlled pref values set in ExtensionPrefs |
| 479 // are not reflected in the pref service. One would need to | 480 // are not reflected in the pref service. One would need to |
| 480 // inject a new ExtensionPrefStore(extension_pref_value_map, false). | 481 // inject a new ExtensionPrefStore(extension_pref_value_map, false). |
| 481 bool extensions_disabled = base::CommandLine::ForCurrentProcess()->HasSwitch( | 482 bool extensions_disabled = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 482 switches::kDisableExtensions); | 483 switches::kDisableExtensions); |
| 483 std::unique_ptr<extensions::ExtensionPrefs> extension_prefs( | 484 std::unique_ptr<extensions::ExtensionPrefs> extension_prefs( |
| 484 extensions::ExtensionPrefs::Create( | 485 extensions::ExtensionPrefs::Create( |
| 485 this, GetPrefs(), extensions_path_, | 486 this, GetPrefs(), extensions_path_, |
| 486 ExtensionPrefValueMapFactory::GetForBrowserContext(this), | 487 ExtensionPrefValueMapFactory::GetForBrowserContext(this), |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 return supervised_user_id_ == supervised_users::kChildAccountSUID; | 746 return supervised_user_id_ == supervised_users::kChildAccountSUID; |
| 746 #else | 747 #else |
| 747 return false; | 748 return false; |
| 748 #endif | 749 #endif |
| 749 } | 750 } |
| 750 | 751 |
| 751 bool TestingProfile::IsLegacySupervised() const { | 752 bool TestingProfile::IsLegacySupervised() const { |
| 752 return IsSupervised() && !IsChild(); | 753 return IsSupervised() && !IsChild(); |
| 753 } | 754 } |
| 754 | 755 |
| 755 #if defined(ENABLE_EXTENSIONS) | 756 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 756 void TestingProfile::SetExtensionSpecialStoragePolicy( | 757 void TestingProfile::SetExtensionSpecialStoragePolicy( |
| 757 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { | 758 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
| 758 extension_special_storage_policy_ = extension_special_storage_policy; | 759 extension_special_storage_policy_ = extension_special_storage_policy; |
| 759 } | 760 } |
| 760 #endif | 761 #endif |
| 761 | 762 |
| 762 ExtensionSpecialStoragePolicy* | 763 ExtensionSpecialStoragePolicy* |
| 763 TestingProfile::GetExtensionSpecialStoragePolicy() { | 764 TestingProfile::GetExtensionSpecialStoragePolicy() { |
| 764 #if defined(ENABLE_EXTENSIONS) | 765 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 765 if (!extension_special_storage_policy_.get()) | 766 if (!extension_special_storage_policy_.get()) |
| 766 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); | 767 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); |
| 767 return extension_special_storage_policy_.get(); | 768 return extension_special_storage_policy_.get(); |
| 768 #else | 769 #else |
| 769 return NULL; | 770 return NULL; |
| 770 #endif | 771 #endif |
| 771 } | 772 } |
| 772 | 773 |
| 773 net::CookieStore* TestingProfile::GetCookieStore() { | 774 net::CookieStore* TestingProfile::GetCookieStore() { |
| 774 if (!GetRequestContext()) | 775 if (!GetRequestContext()) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 return GetRequestContext()->GetURLRequestContext()->ssl_config_service(); | 868 return GetRequestContext()->GetURLRequestContext()->ssl_config_service(); |
| 868 } | 869 } |
| 869 | 870 |
| 870 content::ResourceContext* TestingProfile::GetResourceContext() { | 871 content::ResourceContext* TestingProfile::GetResourceContext() { |
| 871 if (!resource_context_) | 872 if (!resource_context_) |
| 872 resource_context_ = new content::MockResourceContext(); | 873 resource_context_ = new content::MockResourceContext(); |
| 873 return resource_context_; | 874 return resource_context_; |
| 874 } | 875 } |
| 875 | 876 |
| 876 content::BrowserPluginGuestManager* TestingProfile::GetGuestManager() { | 877 content::BrowserPluginGuestManager* TestingProfile::GetGuestManager() { |
| 877 #if defined(ENABLE_EXTENSIONS) | 878 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 878 return guest_view::GuestViewManager::FromBrowserContext(this); | 879 return guest_view::GuestViewManager::FromBrowserContext(this); |
| 879 #else | 880 #else |
| 880 return NULL; | 881 return NULL; |
| 881 #endif | 882 #endif |
| 882 } | 883 } |
| 883 | 884 |
| 884 content::PushMessagingService* TestingProfile::GetPushMessagingService() { | 885 content::PushMessagingService* TestingProfile::GetPushMessagingService() { |
| 885 return NULL; | 886 return NULL; |
| 886 } | 887 } |
| 887 | 888 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 | 948 |
| 948 GURL TestingProfile::GetHomePage() { | 949 GURL TestingProfile::GetHomePage() { |
| 949 return GURL(chrome::kChromeUINewTabURL); | 950 return GURL(chrome::kChromeUINewTabURL); |
| 950 } | 951 } |
| 951 | 952 |
| 952 PrefService* TestingProfile::GetOffTheRecordPrefs() { | 953 PrefService* TestingProfile::GetOffTheRecordPrefs() { |
| 953 return NULL; | 954 return NULL; |
| 954 } | 955 } |
| 955 | 956 |
| 956 storage::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { | 957 storage::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
| 957 #if defined(ENABLE_EXTENSIONS) | 958 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 958 return GetExtensionSpecialStoragePolicy(); | 959 return GetExtensionSpecialStoragePolicy(); |
| 959 #else | 960 #else |
| 960 return NULL; | 961 return NULL; |
| 961 #endif | 962 #endif |
| 962 } | 963 } |
| 963 | 964 |
| 964 content::SSLHostStateDelegate* TestingProfile::GetSSLHostStateDelegate() { | 965 content::SSLHostStateDelegate* TestingProfile::GetSSLHostStateDelegate() { |
| 965 return NULL; | 966 return NULL; |
| 966 } | 967 } |
| 967 | 968 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 } | 1026 } |
| 1026 | 1027 |
| 1027 void TestingProfile::Builder::SetPath(const base::FilePath& path) { | 1028 void TestingProfile::Builder::SetPath(const base::FilePath& path) { |
| 1028 path_ = path; | 1029 path_ = path; |
| 1029 } | 1030 } |
| 1030 | 1031 |
| 1031 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { | 1032 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { |
| 1032 delegate_ = delegate; | 1033 delegate_ = delegate; |
| 1033 } | 1034 } |
| 1034 | 1035 |
| 1035 #if defined(ENABLE_EXTENSIONS) | 1036 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1036 void TestingProfile::Builder::SetExtensionSpecialStoragePolicy( | 1037 void TestingProfile::Builder::SetExtensionSpecialStoragePolicy( |
| 1037 scoped_refptr<ExtensionSpecialStoragePolicy> policy) { | 1038 scoped_refptr<ExtensionSpecialStoragePolicy> policy) { |
| 1038 extension_policy_ = policy; | 1039 extension_policy_ = policy; |
| 1039 } | 1040 } |
| 1040 #endif | 1041 #endif |
| 1041 | 1042 |
| 1042 void TestingProfile::Builder::SetPrefService( | 1043 void TestingProfile::Builder::SetPrefService( |
| 1043 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs) { | 1044 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs) { |
| 1044 pref_service_ = std::move(prefs); | 1045 pref_service_ = std::move(prefs); |
| 1045 } | 1046 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1067 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { | 1068 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { |
| 1068 testing_factories_.push_back(std::make_pair(service_factory, callback)); | 1069 testing_factories_.push_back(std::make_pair(service_factory, callback)); |
| 1069 } | 1070 } |
| 1070 | 1071 |
| 1071 std::unique_ptr<TestingProfile> TestingProfile::Builder::Build() { | 1072 std::unique_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 1072 DCHECK(!build_called_); | 1073 DCHECK(!build_called_); |
| 1073 build_called_ = true; | 1074 build_called_ = true; |
| 1074 | 1075 |
| 1075 return std::unique_ptr<TestingProfile>(new TestingProfile( | 1076 return std::unique_ptr<TestingProfile>(new TestingProfile( |
| 1076 path_, delegate_, | 1077 path_, delegate_, |
| 1077 #if defined(ENABLE_EXTENSIONS) | 1078 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1078 extension_policy_, | 1079 extension_policy_, |
| 1079 #endif | 1080 #endif |
| 1080 std::move(pref_service_), NULL, guest_session_, supervised_user_id_, | 1081 std::move(pref_service_), NULL, guest_session_, supervised_user_id_, |
| 1081 std::move(policy_service_), testing_factories_, profile_name_)); | 1082 std::move(policy_service_), testing_factories_, profile_name_)); |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 TestingProfile* TestingProfile::Builder::BuildIncognito( | 1085 TestingProfile* TestingProfile::Builder::BuildIncognito( |
| 1085 TestingProfile* original_profile) { | 1086 TestingProfile* original_profile) { |
| 1086 DCHECK(!build_called_); | 1087 DCHECK(!build_called_); |
| 1087 DCHECK(original_profile); | 1088 DCHECK(original_profile); |
| 1088 build_called_ = true; | 1089 build_called_ = true; |
| 1089 | 1090 |
| 1090 // Note: Owned by |original_profile|. | 1091 // Note: Owned by |original_profile|. |
| 1091 return new TestingProfile(path_, delegate_, | 1092 return new TestingProfile(path_, delegate_, |
| 1092 #if defined(ENABLE_EXTENSIONS) | 1093 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1093 extension_policy_, | 1094 extension_policy_, |
| 1094 #endif | 1095 #endif |
| 1095 std::move(pref_service_), original_profile, | 1096 std::move(pref_service_), original_profile, |
| 1096 guest_session_, supervised_user_id_, | 1097 guest_session_, supervised_user_id_, |
| 1097 std::move(policy_service_), testing_factories_, | 1098 std::move(policy_service_), testing_factories_, |
| 1098 profile_name_); | 1099 profile_name_); |
| 1099 } | 1100 } |
| OLD | NEW |