#include <optional>
#include "base/base64.h"
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
#include "chrome/browser/ssl/cert_verifier_browser_test.h"
#include "chrome/browser/ssl/chrome_security_state_tab_helper.h"
#include "chrome/browser/ssl/https_upgrades_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/browser/password_protection/password_protection_request_content.h"
#include "components/safe_browsing/content/browser/password_protection/password_protection_test_util.h"
#include "components/safe_browsing/core/browser/password_protection/metrics_util.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "components/security_interstitials/content/security_interstitial_tab_helper.h"
#include "components/security_interstitials/content/ssl_blocking_page.h"
#include "components/security_interstitials/core/pref_names.h"
#include "components/security_state/core/security_state.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/reload_type.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/content_features.h"
#include "content/public/common/page_type.h"
#include "content/public/common/referrer.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/navigation_handle_observer.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/signed_exchange_browser_test_helper.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/url_loader_interceptor.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "net/base/features.h"
#include "net/base/net_errors.h"
#include "net/cert/cert_database.h"
#include "net/cert/cert_status_flags.h"
#include "net/cert/cert_verify_result.h"
#include "net/cert/ct_policy_status.h"
#include "net/cert/mock_cert_verifier.h"
#include "net/cert/x509_certificate.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/transport_security_state_test_util.h"
#include "net/ssl/ssl_cipher_suite_names.h"
#include "net/ssl/ssl_connection_status_flags.h"
#include "net/test/cert_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "net/test/test_data_directory.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/boringssl/src/include/openssl/ssl.h"
namespace {
PasswordType;
LoginReputationClientResponse;
RequestOutcome;
const char kCreateFilesystemUrlJavascript[] = …;
const char kCreateBlobUrlJavascript[] = …;
enum CertificateStatus { … };
bool IsShowingInterstitial(content::WebContents* tab) { … }
void InjectScript(content::WebContents* contents) { … }
class SecurityStyleTestObserver : public content::WebContentsObserver { … };
void CheckSecurityInfoForSecure(
content::WebContents* contents,
security_state::SecurityLevel expect_security_level,
bool expect_sha1_in_chain,
bool expect_displayed_mixed_content,
bool expect_ran_mixed_content,
bool expect_cert_error) { … }
void CheckSecurityInfoForNonCommitted(content::WebContents* contents) { … }
void ProceedThroughInterstitial(content::WebContents* tab) { … }
std::string GetFilePathWithHostAndPortReplacement(
const std::string& original_file_path,
const net::HostPortPair& host_port_pair) { … }
GURL GetURLWithNonLocalHostname(net::EmbeddedTestServer* server,
const std::string& path) { … }
class SecurityStateTabHelperTest : public CertVerifierBrowserTest { … };
class SecurityStateTabHelperIncognitoTest : public SecurityStateTabHelperTest { … };
class DidChangeVisibleSecurityStateTest
: public InProcessBrowserTest,
public testing::WithParamInterface<bool> { … };
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpPage) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpsPage) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, DevToolsPage) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, UMALogsVisitsAfterWarning) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
UMALogsVisitsAfterRevocationCheckFailureWarning) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1CertificateBlocked) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SHA1CertificateWarning) { … }
class SecurityStateTabHelperTestWithAutoupgradesDisabled
: public SecurityStateTabHelperTest { … };
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithAutoupgradesDisabled,
MixedContent) { … }
class
SecurityStateTabHelperTestWithAutoupgradesDisabledAndMixedContentWarningEnabled
: public SecurityStateTabHelperTest { … };
IN_PROC_BROWSER_TEST_F(
SecurityStateTabHelperTestWithAutoupgradesDisabledAndMixedContentWarningEnabled,
PassiveMixedContentWarning) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
ActiveContentWithCertErrors) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
PassiveContentWithCertErrors) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
ActiveAndPassiveContentWithCertErrors) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithAutoupgradesDisabled,
MixedContentWithSHA1Cert) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithAutoupgradesDisabled,
MixedContentStrictBlocking) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithAutoupgradesDisabled,
BrokenHTTPS) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, SecurityLevelForHttpPage) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
SecurityLevelDowngradedOnDataUrl) { … }
IN_PROC_BROWSER_TEST_F(
SecurityStateTabHelperTest,
VerifySignInPasswordReuseMaliciousContentAndSecurityLevel) { … }
IN_PROC_BROWSER_TEST_F(
SecurityStateTabHelperTest,
VerifyEnterprisePasswordReuseMaliciousContentAndSecurityLevel) { … }
class PKPModelClientTest : public SecurityStateTabHelperTest { … };
IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPBypass) { … }
IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) { … }
class SecurityStateLoadingTest : public SecurityStateTabHelperTest { … };
IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
DefaultSecurityLevelOnBlobUrl) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
DefaultSecurityLevelOnFilesystemUrl) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
DefaultSecurityLevelOnSecureBlobUrl) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
DefaultSecurityLevelOnSecureFilesystemUrl) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, AddedTab) { … }
class DidChangeVisibleSecurityStateTestWithAutoupgradesDisabled
: public DidChangeVisibleSecurityStateTest { … };
IN_PROC_BROWSER_TEST_F(
DidChangeVisibleSecurityStateTestWithAutoupgradesDisabled,
DidChangeVisibleSecurityStateObserver) { … }
IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
DidChangeVisibleSecurityStateObserverGoBack) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest, HttpErrorPage) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, FormSecurityLevelHistogram) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
MixedFormsShowLockIfWarningsAreEnabled) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
MixedFormsDontShowLockIfWarningsAreDisabledByPolicy) { … }
class SignedExchangeSecurityStateTest : public CertVerifierBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SignedExchangeSecurityStateTest, SecurityLevelIsSecure) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_SecurityLevelIsSecureAfterPrefetch …
#else
#define MAYBE_SecurityLevelIsSecureAfterPrefetch …
#endif
IN_PROC_BROWSER_TEST_F(SignedExchangeSecurityStateTest,
MAYBE_SecurityLevelIsSecureAfterPrefetch) { … }
class SecurityStateTabHelperPrerenderTest : public SecurityStateTabHelperTest { … };
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperPrerenderTest, InvalidPrerender) { … }
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperPrerenderTest,
PrerenderedMixedContent) { … }
class SecurityStateTabHelperFencedFrameTest
: public SecurityStateTabHelperTest,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(SecurityStateTabHelperFencedFrameTest,
ChangeSecurityStateWhenLoadingInsecureContent) { … }
IN_PROC_BROWSER_TEST_P(SecurityStateTabHelperFencedFrameTest,
LoadFencedFrameViaInsecureURL) { … }
}