#include "chrome/browser/chrome_content_browser_client.h"
#include <list>
#include <map>
#include <memory>
#include <string_view>
#include "ash/webui/camera_app_ui/url_constants.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/scoped_file.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
#include "chrome/browser/enterprise/reporting/prefs.h"
#include "chrome/browser/media/prefs/capture_device_ranking.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/webauthn/webauthn_pref_names.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/browsing_data/content/browsing_data_helper.h"
#include "components/captive_portal/core/buildflags.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/file_access/scoped_file_access.h"
#include "components/file_access/test/mock_scoped_file_access_delegate.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/privacy_sandbox/tracking_protection_prefs.h"
#include "components/search_engines/template_url_service.h"
#include "components/variations/variations_associated_data.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/site_isolation_policy.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/navigation_simulator.h"
#include "crypto/crypto_buildflags.h"
#include "media/media_buildflags.h"
#include "net/base/url_util.h"
#include "net/ssl/ssl_info.h"
#include "net/test/cert_test_util.h"
#include "net/test/test_data_directory.h"
#include "services/network/test/test_network_context.h"
#include "services/video_effects/public/mojom/video_effects_processor.mojom.h"
#include "services/video_effects/public/mojom/video_effects_service.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/switches.h"
#include "url/gurl.h"
#include "url/origin.h"
#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/test/web_app_test_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/search_test_utils.h"
#include "components/media_effects/media_effects_service.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "services/video_effects/test/fake_video_effects_service.h"
#include "third_party/blink/public/mojom/installedapp/related_application.mojom.h"
#include "ui/base/page_transition_types.h"
#else
#include "base/system/sys_info.h"
#endif
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
#include "components/captive_portal/content/captive_portal_tab_helper.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_features.h"
#include "ash/webui/help_app_ui/url_constants.h"
#include "ash/webui/media_app_ui/url_constants.h"
#include "ash/webui/print_management/url_constants.h"
#include "ash/webui/recorder_app_ui/url_constants.h"
#include "ash/webui/scanning/url_constants.h"
#include "ash/webui/shortcut_customization_ui/url_constants.h"
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/ash/system_web_apps/apps/help_app/help_app_untrusted_ui_config.h"
#include "chrome/browser/ash/system_web_apps/apps/media_app/media_app_guest_ui_config.h"
#include "chrome/browser/ash/system_web_apps/apps/terminal_ui.h"
#include "chrome/browser/ash/system_web_apps/test_support/test_system_web_app_manager.h"
#include "chrome/browser/policy/networking/policy_cert_service.h"
#include "chrome/browser/policy/networking/policy_cert_service_factory.h"
#include "chrome/common/webui_url_constants.h"
#include "chromeos/ash/components/browser_context_helper/browser_context_types.h"
#include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/scoped_web_ui_controller_factory_registration.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/policy/system_features_disable_list_policy_handler.h"
#include "chromeos/components/kiosk/kiosk_test_utils.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/browser/web_applications/web_app_utils.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/web_applications/web_app.h"
#include "content/public/browser/storage_partition_config.h"
#include "third_party/blink/public/common/features.h"
#endif
BrowsingDataFilterBuilder;
_;
IsFalse;
IsTrue;
NotNull;
class ChromeContentBrowserClientTest : public testing::Test { … };
TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { … }
#if !BUILDFLAG(IS_ANDROID)
ChromeContentBrowserClientWindowTest;
static void DidOpenURLForWindowTest(content::WebContents** target_contents,
content::WebContents* opened_contents) { … }
TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) { … }
TEST_F(ChromeContentBrowserClientWindowTest, ShouldStayInParentProcessForNTP) { … }
TEST_F(ChromeContentBrowserClientWindowTest, OverrideNavigationParams) { … }
TEST_F(ChromeContentBrowserClientWindowTest, AutomaticBeaconCredentials) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(ChromeContentBrowserClientWindowTest,
BackForwardCacheIsDisallowedForCacheControlNoStorePageWhenInKioskMode) {
#if BUILDFLAG(IS_CHROMEOS_ASH)
user_manager::ScopedUserManager user_manager(
std::make_unique<user_manager::FakeUserManager>());
#endif
chromeos::SetUpFakeKioskSession();
ChromeContentBrowserClient client;
ASSERT_FALSE(client.ShouldAllowBackForwardCacheForCacheControlNoStorePage(
browser()->profile()));
}
#endif
#if !BUILDFLAG(IS_ANDROID)
TEST_F(ChromeContentBrowserClientWindowTest,
QueryInstalledWebAppsByManifestIdFrameUrlInScope) { … }
TEST_F(ChromeContentBrowserClientWindowTest,
QueryInstalledWebAppsByManifestIdFrameUrlOutOfScope) { … }
#endif
class DisableWebRtcEncryptionFlagTest : public testing::Test { … };
TEST_F(DisableWebRtcEncryptionFlagTest, UnknownChannel) { … }
TEST_F(DisableWebRtcEncryptionFlagTest, CanaryChannel) { … }
TEST_F(DisableWebRtcEncryptionFlagTest, DevChannel) { … }
TEST_F(DisableWebRtcEncryptionFlagTest, BetaChannel) { … }
TEST_F(DisableWebRtcEncryptionFlagTest, StableChannel) { … }
class BlinkSettingsFieldTrialTest : public testing::Test { … };
const char BlinkSettingsFieldTrialTest::kDisallowFetchFieldTrialName[] = …;
const char BlinkSettingsFieldTrialTest::kFakeGroupName[] = …;
TEST_F(BlinkSettingsFieldTrialTest, NoFieldTrial) { … }
TEST_F(BlinkSettingsFieldTrialTest, FieldTrialWithoutParams) { … }
TEST_F(BlinkSettingsFieldTrialTest, BlinkSettingsSwitchAlreadySpecified) { … }
TEST_F(BlinkSettingsFieldTrialTest, FieldTrialEnabled) { … }
#if !BUILDFLAG(IS_ANDROID)
namespace content {
class InstantNTPURLRewriteTest : public BrowserWithTestWindowTest { … };
TEST_F(InstantNTPURLRewriteTest, UberURLHandler_InstantExtendedNewTabPage) { … }
}
#endif
class ChromeContentBrowserClientGetLoggingFileTest : public testing::Test { … };
TEST_F(ChromeContentBrowserClientGetLoggingFileTest, GetLoggingFile) { … }
#if BUILDFLAG(IS_WIN)
TEST_F(ChromeContentBrowserClientGetLoggingFileTest,
GetLoggingFileFromCommandLine) {
base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
cmd_line.AppendSwitchASCII(switches::kLogFile, "c:\\path\\test_log.txt");
ChromeContentBrowserClient client;
base::FilePath log_file_name;
EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("test_log.txt")).value(),
client.GetLoggingFileName(cmd_line).BaseName().value());
EXPECT_TRUE(client.GetLoggingFileName(cmd_line).IsAbsolute());
}
TEST_F(ChromeContentBrowserClientGetLoggingFileTest,
GetLoggingFileFromCommandLineFallback) {
base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
cmd_line.AppendSwitchASCII(switches::kLogFile, "test_log.txt");
ChromeContentBrowserClient client;
base::FilePath log_file_name;
EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("chrome_debug.log")).value(),
client.GetLoggingFileName(cmd_line).BaseName().value());
EXPECT_TRUE(client.GetLoggingFileName(cmd_line).IsAbsolute());
}
#else
TEST_F(ChromeContentBrowserClientGetLoggingFileTest,
GetLoggingFileFromCommandLine) { … }
#endif
class TestChromeContentBrowserClient : public ChromeContentBrowserClient { … };
TEST_F(ChromeContentBrowserClientTest, HandleWebUI) { … }
TEST_F(ChromeContentBrowserClientTest, HandleWebUIReverse) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(ChromeContentBrowserClientTest, BindVideoEffectsManager) { … }
TEST_F(ChromeContentBrowserClientTest, BindVideoEffectsProcessor) { … }
#endif
TEST_F(ChromeContentBrowserClientTest, PreferenceRankAudioDeviceInfos) { … }
TEST_F(ChromeContentBrowserClientTest, PreferenceRankVideoDeviceInfos) { … }
#if BUILDFLAG(CHROME_ROOT_STORE_CERT_MANAGEMENT_UI)
#if BUILDFLAG(USE_NSS_CERTS)
TEST_F(ChromeContentBrowserClientTest, RedirectCertManagerFeatureOff) { … }
#endif
TEST_F(ChromeContentBrowserClientTest, RedirectCertManagerFeatureOn) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS)
class ChromeContentSettingsRedirectTest
: public ChromeContentBrowserClientTest {
public:
ChromeContentSettingsRedirectTest()
: testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
protected:
ScopedTestingLocalState testing_local_state_;
};
TEST_F(ChromeContentSettingsRedirectTest, RedirectSettingsURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL settings_url(chrome::kChromeUISettingsURL);
GURL dest_url = settings_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(settings_url, dest_url);
base::Value::List list;
list.Append(static_cast<int>(policy::SystemFeature::kBrowserSettings));
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
dest_url = settings_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ChromeContentSettingsRedirectTest, RedirectExploreURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL help_url(ash::kChromeUIHelpAppURL);
GURL dest_url = help_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(help_url, dest_url);
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList,
base::Value::List().Append(
static_cast<int>(policy::SystemFeature::kExplore)));
dest_url = help_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectGuestExploreURL) {
content::ScopedWebUIConfigRegistration registration(
std::make_unique<ash::HelpAppUntrustedUIConfig>());
TestChromeContentBrowserClient test_content_browser_client;
const GURL help_url(ash::kChromeUIHelpAppUntrustedURL);
GURL dest_url = help_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(help_url, dest_url);
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList,
base::Value::List().Append(
static_cast<int>(policy::SystemFeature::kExplore)));
dest_url = help_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectGalleryURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL gallery_url(ash::kChromeUIMediaAppURL);
GURL dest_url = gallery_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(gallery_url, dest_url);
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList,
base::Value::List().Append(
static_cast<int>(policy::SystemFeature::kGallery)));
dest_url = gallery_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectGuestGalleryURL) {
content::ScopedWebUIConfigRegistration registration(
std::make_unique<MediaAppGuestUIConfig>());
TestChromeContentBrowserClient test_content_browser_client;
const GURL gallery_url(ash::kChromeUIMediaAppGuestURL);
GURL dest_url = gallery_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(gallery_url, dest_url);
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList,
base::Value::List().Append(
static_cast<int>(policy::SystemFeature::kGallery)));
dest_url = gallery_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectTerminalURL) {
content::ScopedWebUIConfigRegistration registration(
std::make_unique<TerminalUIConfig>());
TestChromeContentBrowserClient test_content_browser_client;
const GURL terminal_url(chrome::kChromeUIUntrustedTerminalURL);
GURL dest_url = terminal_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(terminal_url, dest_url);
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList,
base::Value::List().Append(
static_cast<int>(policy::SystemFeature::kTerminal)));
dest_url = terminal_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectPrintJobsURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL print_jobs_url(ash::kChromeUIPrintManagementAppUrl);
GURL dest_url = print_jobs_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(print_jobs_url, dest_url);
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList,
base::Value::List().Append(
static_cast<int>(policy::SystemFeature::kPrintJobs)));
dest_url = print_jobs_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectKeyShortcutsURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL key_shortcuts_url(ash::kChromeUIShortcutCustomizationAppURL);
GURL dest_url = key_shortcuts_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(key_shortcuts_url, dest_url);
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList,
base::Value::List().Append(
static_cast<int>(policy::SystemFeature::kKeyShortcuts)));
dest_url = key_shortcuts_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectOSSettingsURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL os_settings_url(chrome::kChromeUIOSSettingsURL);
GURL dest_url = os_settings_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(os_settings_url, dest_url);
base::Value::List list;
list.Append(static_cast<int>(policy::SystemFeature::kOsSettings));
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
dest_url = os_settings_url;
EXPECT_TRUE(test_content_browser_client.HandleWebUI(&dest_url, &profile_));
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
GURL os_settings_pwa_url =
GURL(chrome::kChromeUIOSSettingsURL).Resolve("pwa.html");
dest_url = os_settings_pwa_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(os_settings_pwa_url, dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectRecorderURL) {
TestChromeContentBrowserClient test_content_browser_client;
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(ash::features::kConch);
const GURL recorder_url(ash::kChromeUIRecorderAppURL);
GURL dest_url = recorder_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(recorder_url, dest_url);
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList,
base::Value::List().Append(
static_cast<int>(policy::SystemFeature::kRecorder)));
dest_url = recorder_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectScanningAppURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL scanning_app_url(ash::kChromeUIScanningAppUrl);
GURL dest_url = scanning_app_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(scanning_app_url, dest_url);
base::Value::List list;
list.Append(static_cast<int>(policy::SystemFeature::kScanning));
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
dest_url = scanning_app_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectCameraAppURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL camera_app_url(ash::kChromeUICameraAppMainURL);
GURL dest_url = camera_app_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(camera_app_url, dest_url);
base::Value::List list;
list.Append(static_cast<int>(policy::SystemFeature::kCamera));
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
dest_url = camera_app_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
TEST_F(ChromeContentSettingsRedirectTest, RedirectHelpURL) {
TestChromeContentBrowserClient test_content_browser_client;
const GURL help_url(chrome::kChromeUIHelpURL);
GURL dest_url = help_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL("chrome://settings/help"), dest_url);
base::Value::List list;
list.Append(static_cast<int>(policy::SystemFeature::kBrowserSettings));
testing_local_state_.Get()->SetUserPref(
policy::policy_prefs::kSystemFeaturesDisableList, std::move(list));
dest_url = help_url;
test_content_browser_client.HandleWebUI(&dest_url, &profile_);
EXPECT_EQ(GURL(chrome::kChromeUIAppDisabledURL), dest_url);
}
namespace {
constexpr char kEmail[] = "[email protected]";
std::unique_ptr<KeyedService> CreateTestPolicyCertService(
content::BrowserContext* context) {
return policy::PolicyCertService::CreateForTesting(
Profile::FromBrowserContext(context));
}
}
class ChromeContentSettingsPolicyTrustAnchor
: public ChromeContentBrowserClientTest {
public:
ChromeContentSettingsPolicyTrustAnchor()
: testing_local_state_(TestingBrowserProcess::GetGlobal()) {}
void SetUp() override {
auto fake_user_manager = std::make_unique<ash::FakeChromeUserManager>();
AccountId account_id = AccountId::FromUserEmailGaiaId(kEmail, "gaia_id");
user_manager::User* user =
fake_user_manager->AddUserWithAffiliationAndTypeAndProfile(
account_id, false ,
user_manager::UserType::kRegular, &profile_);
fake_user_manager->UserLoggedIn(account_id, user->username_hash(),
false ,
false );
scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>(
std::move(fake_user_manager));
ASSERT_TRUE(
policy::PolicyCertServiceFactory::GetInstance()
->SetTestingFactoryAndUse(
&profile_, base::BindRepeating(&CreateTestPolicyCertService)));
}
void TearDown() override { scoped_user_manager_.reset(); }
protected:
ScopedTestingLocalState testing_local_state_;
std::unique_ptr<user_manager::ScopedUserManager> scoped_user_manager_;
};
TEST_F(ChromeContentSettingsPolicyTrustAnchor, PolicyTrustAnchor) {
ChromeContentBrowserClient client;
EXPECT_FALSE(policy::PolicyCertServiceFactory::GetForProfile(&profile_)
->UsedPolicyCertificates());
client.OnTrustAnchorUsed(&profile_);
EXPECT_TRUE(policy::PolicyCertServiceFactory::GetForProfile(&profile_)
->UsedPolicyCertificates());
}
#endif
#endif
class CaptivePortalCheckNetworkContext final
: public network::TestNetworkContext { … };
class CaptivePortalCheckRenderProcessHostFactory
: public content::RenderProcessHostFactory { … };
class ChromeContentBrowserClientCaptivePortalBrowserTest
: public ChromeRenderViewHostTestHarness { … };
TEST_F(ChromeContentBrowserClientCaptivePortalBrowserTest,
NotCaptivePortalWindow) { … }
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
TEST_F(ChromeContentBrowserClientCaptivePortalBrowserTest,
CaptivePortalWindow) { … }
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
class ChromeContentBrowserClientStoragePartitionTest
: public ChromeContentBrowserClientTest { … };
constexpr char ChromeContentBrowserClientStoragePartitionTest::kAppId[];
constexpr char ChromeContentBrowserClientStoragePartitionTest::kHttpsScope[];
constexpr char
ChromeContentBrowserClientStoragePartitionTest::kIsolatedAppScope[];
TEST_F(ChromeContentBrowserClientStoragePartitionTest,
DefaultPartitionIsUsedForNormalSites) { … }
TEST_F(ChromeContentBrowserClientStoragePartitionTest,
DefaultPartitionIsUsedForNonIsolatedPWAs) { … }
TEST_F(ChromeContentBrowserClientStoragePartitionTest,
EnableIsolatedLevelForIsolatedAppSchemeWhenIsolatedAppFeatureIsEnabled) { … }
TEST_F(
ChromeContentBrowserClientStoragePartitionTest,
DoNotEnableIsolatedLevelForIsolatedAppSchemeWhenIsolatedAppFeatureIsDisabled) { … }
TEST_F(ChromeContentBrowserClientStoragePartitionTest,
DoNotEnableIsolatedLevelForNonIsolatedApp) { … }
TEST_F(ChromeContentBrowserClientStoragePartitionTest,
DefaultPartitionIsUsedWhenIsolationDisabled) { … }
TEST_F(ChromeContentBrowserClientStoragePartitionTest,
DedicatedPartitionIsUsedForIsolatedApps) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ChromeContentBrowserClientTest, IsolatedWebAppsDisabledOnSignInScreen) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kIsolatedWebApps);
std::unique_ptr<TestingProfile> sign_in_screen_profile =
TestingProfile::Builder()
.SetPath(base::FilePath(ash::kSigninBrowserContextBaseName))
.Build();
ChromeContentBrowserClient client;
EXPECT_TRUE(client.AreIsolatedWebAppsEnabled(&profile_));
EXPECT_FALSE(client.AreIsolatedWebAppsEnabled(sign_in_screen_profile.get()));
}
#endif
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(ChromeContentBrowserClientTest, RequestFileAccessAllow) {
file_access::MockScopedFileAccessDelegate scoped_file_access;
base::test::TestFuture<file_access::ScopedFileAccess> continuation_callback;
base::FilePath path = base::FilePath(FILE_PATH_LITERAL("/path/to/file"));
EXPECT_CALL(scoped_file_access,
RequestFilesAccess(testing::ElementsAre(path), GURL(), _))
.WillOnce(base::test::RunOnceCallback<2>(
file_access::ScopedFileAccess::Allowed()));
ChromeContentBrowserClient client;
client.RequestFilesAccess({path}, GURL(),
continuation_callback.GetCallback());
EXPECT_TRUE(continuation_callback.Take().is_allowed());
}
TEST_F(ChromeContentBrowserClientTest, RequestFileAccessDeny) {
file_access::MockScopedFileAccessDelegate scoped_file_access;
base::test::TestFuture<file_access::ScopedFileAccess> continuation_callback;
base::FilePath path = base::FilePath(FILE_PATH_LITERAL("/path/to/file"));
EXPECT_CALL(scoped_file_access,
RequestFilesAccess(testing::ElementsAre(path), GURL(), _))
.WillOnce(base::test::RunOnceCallback<2>(
file_access::ScopedFileAccess::Denied()));
ChromeContentBrowserClient client;
client.RequestFilesAccess({path}, GURL(),
continuation_callback.GetCallback());
EXPECT_FALSE(continuation_callback.Take().is_allowed());
}
#endif
class ChromeContentBrowserClientSwitchTest
: public ChromeRenderViewHostTestHarness { … };
TEST_F(ChromeContentBrowserClientSwitchTest, DataUrlInSvgDefault) { … }
TEST_F(ChromeContentBrowserClientSwitchTest, DataUrlInSvgDisabled) { … }
TEST_F(ChromeContentBrowserClientSwitchTest, DataUrlInSvgEnabled) { … }
TEST_F(ChromeContentBrowserClientSwitchTest, LegacyTechReportDisabled) { … }
TEST_F(ChromeContentBrowserClientSwitchTest, LegacyTechReportEnabled) { … }
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(ChromeContentBrowserClientSwitchTest,
ShouldSetForceAppModeSwitchInRendererProcessIfItIsSetInCurrentProcess) {
AppendSwitchInCurrentProcess(switches::kForceAppMode);
base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
EXPECT_TRUE(result.HasSwitch(switches::kForceAppMode));
}
TEST_F(
ChromeContentBrowserClientSwitchTest,
ShouldNotSetForceAppModeSwitchInRendererProcessIfItIsUnsetInCurrentProcess) {
base::CommandLine result = FetchCommandLineSwitchesForRendererProcess();
EXPECT_FALSE(result.HasSwitch(switches::kForceAppMode));
}
#endif
class DisableWebAuthnWithBrokenCertsTest
: public ChromeRenderViewHostTestHarness { … };
TEST_F(DisableWebAuthnWithBrokenCertsTest, SecurityLevelNotAcceptable) { … }
#if BUILDFLAG(ENABLE_EXTENSIONS)
TEST_F(DisableWebAuthnWithBrokenCertsTest, ExtensionSupported) { … }
#endif
TEST_F(DisableWebAuthnWithBrokenCertsTest, EnterpriseOverride) { … }
TEST_F(DisableWebAuthnWithBrokenCertsTest, Localhost) { … }
TEST_F(DisableWebAuthnWithBrokenCertsTest, SecurityLevelAcceptable) { … }
TEST_F(DisableWebAuthnWithBrokenCertsTest, IgnoreCertificateErrorsFlag) { … }
TEST_F(ChromeContentBrowserClientTest, ShouldUseSpareRenderProcessHost) { … }