#include "components/subresource_filter/content/browser/safe_browsing_page_activation_throttle.h"
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
#include "components/subresource_filter/content/browser/content_subresource_filter_web_contents_helper.h"
#include "components/subresource_filter/content/browser/devtools_interaction_tracker.h"
#include "components/subresource_filter/content/browser/fake_safe_browsing_database_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_observer_test_utils.h"
#include "components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h"
#include "components/subresource_filter/content/browser/subresource_filter_safe_browsing_client_request.h"
#include "components/subresource_filter/content/browser/throttle_manager_test_support.h"
#include "components/subresource_filter/content/shared/common/subresource_filter_utils.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h"
#include "components/subresource_filter/core/browser/subresource_filter_features_test_support.h"
#include "components/subresource_filter/core/browser/verified_ruleset_dealer.h"
#include "components/subresource_filter/core/common/activation_decision.h"
#include "components/subresource_filter/core/common/activation_list.h"
#include "components/subresource_filter/core/common/constants.h"
#include "components/subresource_filter/core/common/test_ruleset_creator.h"
#include "components/subresource_filter/core/common/test_ruleset_utils.h"
#include "components/subresource_filter/core/mojom/subresource_filter.mojom.h"
#include "components/ukm/content/source_url_recorder.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/url_pattern_index/proto/rules.pb.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_navigation_throttle.h"
#include "content/public/test/test_renderer_host.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_ANDROID)
#include "components/messages/android/mock_message_dispatcher_bridge.h"
#endif
namespace subresource_filter {
namespace {
const char kUrlA[] = …;
const char kUrlB[] = …;
const char kUrlC[] = …;
char kURL[] = …;
char kURLWithParams[] = …;
char kRedirectURL[] = …;
const char kSafeBrowsingNavigationDelay[] = …;
const char kSafeBrowsingCheckTime[] = …;
const char kActivationListHistogram[] = …;
const char kSubresourceFilterActionsHistogram[] = …;
class TestSafeBrowsingActivationThrottleDelegate
: public SafeBrowsingPageActivationThrottle::Delegate { … };
struct ActivationListTestData { … };
SBLevel;
SBType;
const ActivationListTestData kActivationListTestData[] = …;
}
class SafeBrowsingPageActivationThrottleTest
: public content::RenderViewHostTestHarness,
public content::WebContentsObserver { … };
class SafeBrowsingPageActivationThrottleInfoBarUiTest
: public SafeBrowsingPageActivationThrottleTest { … };
class SafeBrowsingPageActivationThrottleParamTest
: public SafeBrowsingPageActivationThrottleTest,
public ::testing::WithParamInterface<ActivationListTestData> { … };
class SafeBrowsingPageActivationThrottleTestWithCancelling
: public SafeBrowsingPageActivationThrottleTest,
public ::testing::WithParamInterface<
std::tuple<content::TestNavigationThrottle::ThrottleMethod,
content::TestNavigationThrottle::ResultSynchrony>> { … };
struct ActivationScopeTestData { … };
const ActivationScopeTestData kActivationScopeTestData[] = …;
class SafeBrowsingPageActivationThrottleScopeTest
: public SafeBrowsingPageActivationThrottleTest,
public ::testing::WithParamInterface<ActivationScopeTestData> { … };
TEST_F(SafeBrowsingPageActivationThrottleTest, NoConfigs) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
MultipleSimultaneousConfigs) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
ActivationLevelDisabled_NoActivation) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
AllSiteEnabled_Activates) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
NavigationFails_NoActivation) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
NotificationVisibility) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest, ActivationList) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
SynchronousResponse) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest, LogsUkm) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
LogsUkmNoActivation) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest, LogsUkmDryRun) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
ToggleForceActivation) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
ToggleOffForceActivation_AfterCommit) { … }
TEST_P(SafeBrowsingPageActivationThrottleScopeTest,
ActivateForScopeType) { … }
TEST_P(SafeBrowsingPageActivationThrottleScopeTest,
ActivateForSupportedUrlScheme) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
ListNotMatched_NoActivation) { … }
TEST_P(SafeBrowsingPageActivationThrottleParamTest,
ListMatched_Activation) { … }
TEST_P(SafeBrowsingPageActivationThrottleParamTest,
ListNotMatchedAfterRedirect_NoActivation) { … }
TEST_P(SafeBrowsingPageActivationThrottleParamTest,
ListMatchedAfterRedirect_Activation) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
ListNotMatchedAndTimeout_NoActivation) { … }
TEST_P(SafeBrowsingPageActivationThrottleParamTest,
ListMatchedOnStart_NoDelay) { … }
TEST_P(SafeBrowsingPageActivationThrottleParamTest,
ListMatchedOnRedirect_NoDelay) { … }
struct RedirectSamplesAndResults { … };
TEST_F(SafeBrowsingPageActivationThrottleTest,
RedirectPositionLogged) { … }
TEST_F(SafeBrowsingPageActivationThrottleTest,
ActivationTriggeredOnAbusiveSites) { … }
TEST_F(SafeBrowsingPageActivationThrottleInfoBarUiTest,
NotificationVisibility) { … }
TEST_P(SafeBrowsingPageActivationThrottleParamTest,
ListMatchedOnStartWithRedirect_NoActivation) { … }
TEST_P(SafeBrowsingPageActivationThrottleTestWithCancelling,
Cancel) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
}