chromium/chrome/test/base/testing_profile.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/test/base/testing_profile.h"

#include <memory>
#include <utility>

#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/test_file_util.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/autocomplete/in_memory_url_index_factory.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/background_fetch/background_fetch_delegate_factory.h"
#include "chrome/browser/background_fetch/background_fetch_delegate_impl.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/origin_trials/origin_trials_factory.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/schema_registry_service.h"
#include "chrome/browser/policy/schema_registry_service_builder.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/pref_service_syncable_util.h"
#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/storage_partition_descriptor.h"
#include "chrome/browser/reading_list/reading_list_model_factory.h"
#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ssl/stateful_ssl_host_state_delegate_factory.h"
#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
#include "chrome/browser/transition_manager/full_browser_transition_manager.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile_key.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/test/history_service_test_util.h"
#include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/keyed_service/core/simple_factory_key.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/in_memory_url_index.h"
#include "components/policy/core/common/cloud/cloud_external_data_manager.h"
#include "components/policy/core/common/cloud/mock_user_cloud_policy_store.h"
#include "components/policy/core/common/cloud/profile_cloud_policy_manager.h"
#include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
#include "components/policy/core/common/configuration_policy_provider.h"
#include "components/policy/core/common/policy_service.h"
#include "components/policy/core/common/policy_service_impl.h"
#include "components/policy/core/common/schema.h"
#include "components/prefs/pref_notifier_impl.h"
#include "components/prefs/testing_pref_store.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/security_interstitials/content/stateful_ssl_host_state_delegate.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/supervised_user/core/browser/supervised_user_settings_service.h"
#include "components/supervised_user/core/common/pref_names.h"
#include "components/supervised_user/core/common/supervised_user_constants.h"
#include "components/sync/base/features.h"
#include "components/sync/test/fake_sync_change_processor.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cookie_store_factory.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/zoom_level_delegate.h"
#include "content/public/test/test_utils.h"
#include "extensions/buildflags/buildflags.h"
#include "extensions/common/constants.h"
#include "net/cookies/cookie_store.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "services/service_manager/public/cpp/service.h"
#include "testing/gmock/include/gmock/gmock.h"

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
#include "chrome/browser/web_applications/web_app_provider_factory.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "extensions/browser/extension_pref_value_map.h"
#include "extensions/browser/extension_pref_value_map_factory.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_prefs_factory.h"
#include "extensions/browser/extension_prefs_observer.h"
#include "extensions/browser/extension_system.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/arc/session/arc_service_launcher.h"
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/ash/net/delay_network_call.h"
#include "chrome/browser/ash/policy/core/user_cloud_policy_manager_ash.h"
#include "chrome/browser/ash/system_web_apps/system_web_app_manager_factory.h"
#include "chrome/browser/ash/system_web_apps/test_support/test_system_web_app_manager.h"
#include "chromeos/ash/components/account_manager/account_manager_factory.h"
#include "chromeos/ash/components/settings/cros_settings.h"
#include "components/account_manager_core/chromeos/account_manager.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/lacros/lacros_service.h"
#include "chromeos/lacros/lacros_test_helper.h"
#endif

Time;
BrowserThread;
DownloadManagerDelegate;
NiceMock;
Return;

TestingProfile::TestingFactory::TestingFactory(
    BrowserContextKeyedServiceFactory* service_factory,
    BrowserContextKeyedServiceFactory::TestingFactory testing_factory)
    :{}

TestingProfile::TestingFactory::TestingFactory(
    RefcountedBrowserContextKeyedServiceFactory* service_factory,
    RefcountedBrowserContextKeyedServiceFactory::TestingFactory testing_factory)
    :{}

TestingProfile::TestingFactory::TestingFactory(TestingFactory&&) = default;

TestingProfile::TestingFactory& TestingProfile::TestingFactory::operator=(
    TestingFactory&&) = default;

TestingProfile::TestingFactory::~TestingFactory() = default;

TestingProfile::TestingFactories::TestingFactories() = default;

TestingProfile::TestingFactories::TestingFactories(TestingFactories&&) =
    default;

TestingProfile::TestingFactories& TestingProfile::TestingFactories::operator=(
    TestingFactories&&) = default;

TestingProfile::TestingFactories::~TestingFactories() = default;

// static
const char TestingProfile::kDefaultProfileUserName[] =;

// static
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Must be kept in sync with
// `ChromeBrowserMainPartsAsh::PreEarlyInitialization`.
const char TestingProfile::kTestUserProfileDir[] = "test-user";
#else
const char TestingProfile::kTestUserProfileDir[] =;
#endif

TestingProfile::TestingProfile() :{}

TestingProfile::TestingProfile(const base::FilePath& path)
    :{}

TestingProfile::TestingProfile(const base::FilePath& path,
                               Delegate* delegate,
                               CreateMode create_mode)
    :{}

TestingProfile::TestingProfile(
    const base::FilePath& path,
    Delegate* delegate,
    CreateMode create_mode,
#if BUILDFLAG(ENABLE_EXTENSIONS)
    scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
#endif
    std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs,
    TestingProfile* parent,
    bool guest_session,
    bool allows_browser_windows,
    bool is_new_profile,
    bool is_supervised_profile,
#if BUILDFLAG(IS_CHROMEOS_LACROS)
    bool is_main_profile,
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
    std::unique_ptr<policy::UserCloudPolicyManagerAsh> policy_manager,
#else
    absl::variant<std::unique_ptr<policy::UserCloudPolicyManager>,
                  std::unique_ptr<policy::ProfileCloudPolicyManager>>
        policy_manager,
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
    std::unique_ptr<policy::PolicyService> policy_service,
    TestingFactories testing_factories,
    const std::string& profile_name,
    std::optional<bool> override_policy_connector_is_managed,
    const OTRProfileID* otr_profile_id,
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
    :{}

void TestingProfile::Init(bool is_supervised_profile, CreateMode create_mode) {}

void TestingProfile::InitializeProfileType() {}

void TestingProfile::FinishInit(CreateMode create_mode) {}

TestingProfile::~TestingProfile() {}

void TestingProfile::SetGuestSession(bool guest) {}

void TestingProfile::SetIsNewProfile(bool is_new_profile) {}

base::FilePath TestingProfile::GetPath() {}

base::FilePath TestingProfile::GetPath() const {}

base::Time TestingProfile::GetCreationTime() const {}

std::unique_ptr<content::ZoomLevelDelegate>
TestingProfile::CreateZoomLevelDelegate(const base::FilePath& partition_path) {}

scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {}

sync_preferences::TestingPrefServiceSyncable*
TestingProfile::GetTestingPrefService() {}

TestingProfile* TestingProfile::AsTestingProfile() {}

std::string TestingProfile::GetProfileUserName() const {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
bool TestingProfile::IsMainProfile() const {
  return is_main_profile_;
}

void TestingProfile::SetIsMainProfile(bool is_main_profile) {
  is_main_profile_ = is_main_profile;
}

#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

void TestingProfile::SetOffTheRecordProfile(
    std::unique_ptr<Profile> otr_profile) {}

Profile* TestingProfile::GetOffTheRecordProfile(
    const OTRProfileID& otr_profile_id,
    bool create_if_needed) {}

std::vector<Profile*> TestingProfile::GetAllOffTheRecordProfiles() {}

void TestingProfile::DestroyOffTheRecordProfile(Profile* otr_profile) {}

bool TestingProfile::HasOffTheRecordProfile(
    const OTRProfileID& otr_profile_id) {}

bool TestingProfile::HasAnyOffTheRecordProfile() {}

Profile* TestingProfile::GetOriginalProfile() {}

const Profile* TestingProfile::GetOriginalProfile() const {}

void TestingProfile::SetIsSupervisedProfile(bool is_supervised_profile) {}

bool TestingProfile::IsChild() const {}

bool TestingProfile::AllowsBrowserWindows() const {}

#if BUILDFLAG(ENABLE_EXTENSIONS)
void TestingProfile::SetExtensionSpecialStoragePolicy(
    scoped_refptr<ExtensionSpecialStoragePolicy>
        extension_special_storage_policy) {}
#endif

ExtensionSpecialStoragePolicy*
TestingProfile::GetExtensionSpecialStoragePolicy() {}

void TestingProfile::CreateTestingPrefService() {}

void TestingProfile::CreatePrefServiceForSupervisedUser() {}

void TestingProfile::CreateIncognitoPrefService() {}

void TestingProfile::CreateProfilePolicyConnector() {}

PrefService* TestingProfile::GetPrefs() {}

const PrefService* TestingProfile::GetPrefs() const {}

ChromeZoomLevelPrefs* TestingProfile::GetZoomLevelPrefs() {}

DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {}

scoped_refptr<network::SharedURLLoaderFactory>
TestingProfile::GetURLLoaderFactory() {}

content::BrowserPluginGuestManager* TestingProfile::GetGuestManager() {}

content::PlatformNotificationService*
TestingProfile::GetPlatformNotificationService() {}

content::PushMessagingService* TestingProfile::GetPushMessagingService() {}

content::StorageNotificationService*
TestingProfile::GetStorageNotificationService() {}

bool TestingProfile::IsSameOrParent(Profile* profile) {}

base::Time TestingProfile::GetStartTime() const {}

ProfileKey* TestingProfile::GetProfileKey() const {}

policy::SchemaRegistryService*
TestingProfile::GetPolicySchemaRegistryService() {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
void TestingProfile::SetUserCloudPolicyManagerAsh(
    std::unique_ptr<policy::UserCloudPolicyManagerAsh>
        user_cloud_policy_manager) {
  user_cloud_policy_manager_ = std::move(user_cloud_policy_manager);
}

policy::UserCloudPolicyManagerAsh*
TestingProfile::GetUserCloudPolicyManagerAsh() {
  return user_cloud_policy_manager_.get();
}
#else
policy::UserCloudPolicyManager* TestingProfile::GetUserCloudPolicyManager() {}

policy::ProfileCloudPolicyManager*
TestingProfile::GetProfileCloudPolicyManager() {}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

policy::CloudPolicyManager* TestingProfile::GetCloudPolicyManager() {}

policy::ProfilePolicyConnector* TestingProfile::GetProfilePolicyConnector() {}

const policy::ProfilePolicyConnector*
TestingProfile::GetProfilePolicyConnector() const {}

base::FilePath TestingProfile::last_selected_directory() {}

void TestingProfile::set_last_selected_directory(const base::FilePath& path) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
void TestingProfile::ChangeAppLocale(const std::string& locale,
                                     AppLocaleChangedVia via) {
  requested_locale_ = locale;
}

ash::ScopedCrosSettingsTestHelper*
TestingProfile::ScopedCrosSettingsTestHelper() {
  return scoped_cros_settings_test_helper_.get();
}
#endif

void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {}

GURL TestingProfile::GetHomePage() {}

void TestingProfile::SetCreationTimeForTesting(base::Time creation_time) {}

bool TestingProfile::IsSignedIn() {}

storage::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {}

content::SSLHostStateDelegate* TestingProfile::GetSSLHostStateDelegate() {}

content::PermissionControllerDelegate*
TestingProfile::GetPermissionControllerDelegate() {}

content::ClientHintsControllerDelegate*
TestingProfile::GetClientHintsControllerDelegate() {}

content::BackgroundFetchDelegate* TestingProfile::GetBackgroundFetchDelegate() {}

content::BackgroundSyncController*
TestingProfile::GetBackgroundSyncController() {}

content::BrowsingDataRemoverDelegate*
TestingProfile::GetBrowsingDataRemoverDelegate() {}

content::ReduceAcceptLanguageControllerDelegate*
TestingProfile::GetReduceAcceptLanguageControllerDelegate() {}

content::OriginTrialsControllerDelegate*
TestingProfile::GetOriginTrialsControllerDelegate() {}

bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {}

bool TestingProfile::IsGuestSession() const {}

bool TestingProfile::IsNewProfile() const {}

TestingProfile::Builder::Builder() = default;

TestingProfile::Builder::~Builder() = default;

TestingProfile::Builder& TestingProfile::Builder::SetPath(
    const base::FilePath& path) {}

TestingProfile::Builder& TestingProfile::Builder::SetDelegate(
    Delegate* delegate) {}

TestingProfile::Builder& TestingProfile::Builder::SetCreateMode(
    Profile::CreateMode create_mode) {}

#if BUILDFLAG(ENABLE_EXTENSIONS)
TestingProfile::Builder&
TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
    scoped_refptr<ExtensionSpecialStoragePolicy> policy) {}
#endif

TestingProfile::Builder& TestingProfile::Builder::SetPrefService(
    std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs) {}

TestingProfile::Builder& TestingProfile::Builder::SetGuestSession() {}

TestingProfile::Builder& TestingProfile::Builder::DisallowBrowserWindows() {}

TestingProfile::Builder& TestingProfile::Builder::SetIsNewProfile(
    bool is_new_profile) {}

TestingProfile::Builder& TestingProfile::Builder::SetIsSupervisedProfile() {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
TestingProfile::Builder& TestingProfile::Builder::SetIsMainProfile(
    bool is_main_profile) {
  is_main_profile_ = is_main_profile;
  return *this;
}
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

#if BUILDFLAG(IS_CHROMEOS_ASH)
TestingProfile::Builder& TestingProfile::Builder::SetUserCloudPolicyManagerAsh(
    std::unique_ptr<policy::UserCloudPolicyManagerAsh>
        user_cloud_policy_manager) {
  user_cloud_policy_manager_ = std::move(user_cloud_policy_manager);
  return *this;
}
#else
TestingProfile::Builder& TestingProfile::Builder::SetUserCloudPolicyManager(
    std::unique_ptr<policy::UserCloudPolicyManager> user_cloud_policy_manager) {}

TestingProfile::Builder& TestingProfile::Builder::SetProfileCloudPolicyManager(
    std::unique_ptr<policy::ProfileCloudPolicyManager>
        profile_cloud_policy_manager) {}
#endif

TestingProfile::Builder& TestingProfile::Builder::SetPolicyService(
    std::unique_ptr<policy::PolicyService> policy_service) {}

TestingProfile::Builder& TestingProfile::Builder::SetProfileName(
    const std::string& profile_name) {}

TestingProfile::Builder& TestingProfile::Builder::SetSharedURLLoaderFactory(
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {}

TestingProfile::Builder&
TestingProfile::Builder::OverridePolicyConnectorIsManagedForTesting(
    bool is_managed) {}

TestingProfile::Builder& TestingProfile::Builder::AddTestingFactory(
    BrowserContextKeyedServiceFactory* service_factory,
    BrowserContextKeyedServiceFactory::TestingFactory testing_factory) {}

TestingProfile::Builder& TestingProfile::Builder::AddTestingFactory(
    RefcountedBrowserContextKeyedServiceFactory* service_factory,
    RefcountedBrowserContextKeyedServiceFactory::TestingFactory
        testing_factory) {}

TestingProfile::Builder& TestingProfile::Builder::AddTestingFactories(
    TestingFactories testing_factories) {}

std::unique_ptr<TestingProfile> TestingProfile::Builder::Build() {}

TestingProfile* TestingProfile::Builder::BuildOffTheRecord(
    TestingProfile* original_profile,
    const OTRProfileID& otr_profile_id) {}

TestingProfile* TestingProfile::Builder::BuildIncognito(
    TestingProfile* original_profile) {}