#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include <memory>
#include <set>
#include <string>
#include <utility>
#include "base/check_deref.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/enterprise/connectors/reporting/realtime_reporting_client.h"
#include "chrome/browser/enterprise/connectors/reporting/realtime_reporting_client_factory.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router_factory.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "chrome/browser/safe_browsing/test_extension_event_observer.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/safe_browsing_private.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/download/public/common/download_danger_type.h"
#include "components/enterprise/browser/enterprise_switches.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/enterprise/connectors/core/connectors_prefs.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "components/policy/core/common/cloud/realtime_reporting_job_configuration.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "content/public/test/browser_task_environment.h"
#include "extensions/browser/test_event_router.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/login/users/chrome_user_manager_impl.h"
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/ash/settings/scoped_cros_settings_test_helper.h"
#include "chromeos/ash/components/install_attributes/stub_install_attributes.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/scoped_user_manager.h"
#include "components/user_manager/user.h"
#else
#include "components/enterprise/browser/controller/fake_browser_dm_token_storage.h"
#endif
_;
Mock;
Return;
SaveArg;
namespace extensions {
namespace {
ACTION_P(CaptureArg, wrapper) { … }
constexpr char kConnectorsPrefValue[] = …;
constexpr char kUrl[] = …;
constexpr char kTabUrl[] = …;
constexpr char kSource[] = …;
constexpr char kDestination[] = …;
}
class SafeBrowsingEventObserver : public TestEventRouter::EventObserver { … };
class SafeBrowsingPrivateEventRouterTestBase : public testing::Test { … };
class SafeBrowsingPrivateEventRouterTest
: public SafeBrowsingPrivateEventRouterTestBase { … };
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnReuseDetected_Warned) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnReuseDetected_Allowed) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnPasswordChanged) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnDangerousDownloadOpened) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnSecurityInterstitialProceeded) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSecurityInterstitialShown) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnDangerousDownloadWarning) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnDangerousDownloadWarningBypass) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, PolicyControlOnToOffIsDynamic) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, PolicyControlOffToOnIsDynamic) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestUnauthorizedOnReuseDetected) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestUnauthorizedOnPasswordChanged) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestUnauthorizedOnDangerousDownloadOpened) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestUnauthorizedOnSecurityInterstitialProceeded) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestUnauthorizedOnSecurityInterstitialShown) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestUnauthorizedOnDangerousDownloadWarning) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestUnauthorizedOnDangerousDownloadWarningBypass) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnLoginEvent) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnLoginEventNoMatchingUrlPattern) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnLoginEventWithEmailAsLoginUsername) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnLoginEventFederated) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnPasswordBreach) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnPasswordBreachNoMatchingUrlPattern) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnPasswordBreachPartiallyMatchingUrlPatterns) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSensitiveDataEvent_Allowed) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSensitiveDataEvent_Blocked) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnUrlFilteringInterstitial_Blocked) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnUrlFilteringInterstitial_Warned) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnUrlFilteringInterstitial_Bypassed) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest,
TestOnUrlFilteringInterstitial_WatermarkAudit) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnUnscannedFileEvent_Allowed) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnUnscannedFileEvent_Blocked) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestProfileUsername) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestPasswordChangedEnabled) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestPasswordReuseEnabled) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestDangerousDownloadEnabled) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestInterstitialEnabled) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestSensitiveDataEnabled) { … }
TEST_F(SafeBrowsingPrivateEventRouterTest, TestUnscannedFileEnabled) { … }
#if BUILDFLAG(ENTERPRISE_DATA_CONTROLS)
TEST_F(SafeBrowsingPrivateEventRouterTest, TestDataControlsSensitiveDataEvent) { … }
#endif
class SafeBrowsingIsRealtimeReportingEnabledTest
: public SafeBrowsingPrivateEventRouterTestBase,
public testing::WithParamInterface<testing::tuple<bool, bool, bool>> { … };
TEST_P(SafeBrowsingIsRealtimeReportingEnabledTest, CheckRealtimeReport) { … }
INSTANTIATE_TEST_SUITE_P(…);
class SafeBrowsingIsRealtimeReportingEventDisabledTest
: public SafeBrowsingPrivateEventRouterTestBase,
public testing::WithParamInterface<testing::tuple<std::string, int>> { … };
TEST_P(SafeBrowsingIsRealtimeReportingEventDisabledTest,
TryAllButOnlyTriggerExpectedNumberOfTimesForGivenEvent) { … }
INSTANTIATE_TEST_SUITE_P(…);
}