#include "components/subresource_filter/content/renderer/subresource_filter_agent.h"
#include <memory>
#include <string_view>
#include <utility>
#include "base/files/file.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "components/subresource_filter/content/renderer/unverified_ruleset_dealer.h"
#include "components/subresource_filter/core/common/memory_mapped_ruleset.h"
#include "components/subresource_filter/core/common/scoped_timers.h"
#include "components/subresource_filter/core/common/test_ruleset_creator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_document_subresource_filter.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "url/gurl.h"
namespace subresource_filter {
namespace {
class SubresourceFilterAgentUnderTest : public SubresourceFilterAgent { … };
constexpr const char kTestFirstURL[] = …;
constexpr const char kTestSecondURL[] = …;
constexpr const char kTestFirstURLPathSuffix[] = …;
constexpr const char kTestSecondURLPathSuffix[] = …;
constexpr const char kTestBothURLsPathSuffix[] = …;
constexpr const char kDocumentLoadRulesetIsAvailable[] = …;
constexpr const char kMainFrameLoadRulesetIsAvailableAnyActivationLevel[] = …;
}
class SubresourceFilterAgentTest : public ::testing::Test { … };
TEST_F(SubresourceFilterAgentTest, RulesetUnset_RulesetNotAvailable) { … }
TEST_F(SubresourceFilterAgentTest, DisabledByDefault_NoFilterIsInjected) { … }
TEST_F(SubresourceFilterAgentTest, MmapFailure_FailsToInjectSubresourceFilter) { … }
TEST_F(SubresourceFilterAgentTest, Disabled_NoFilterIsInjected) { … }
TEST_F(SubresourceFilterAgentTest,
EnabledButRulesetUnavailable_NoFilterIsInjected) { … }
TEST_F(SubresourceFilterAgentTest, EmptyDocumentLoad_NoFilterIsInjected) { … }
TEST_F(SubresourceFilterAgentTest, Enabled_FilteringIsInEffectForOneLoad) { … }
TEST_F(SubresourceFilterAgentTest, Enabled_HistogramSamplesOverTwoLoads) { … }
TEST_F(SubresourceFilterAgentTest, Enabled_NewRulesetIsPickedUpAtNextLoad) { … }
TEST_F(SubresourceFilterAgentTest,
Enabled_FilteringNoLongerEffectAfterProvisionalLoadIsCancelled) { … }
TEST_F(SubresourceFilterAgentTest, DryRun_ResourcesAreEvaluatedButNotFiltered) { … }
TEST_F(SubresourceFilterAgentTest,
SignalFirstSubresourceDisallowed_OncePerDocumentLoad) { … }
TEST_F(SubresourceFilterAgentTest,
SignalFirstSubresourceDisallowed_ComesAfterAgentDestroyed) { … }
TEST_F(SubresourceFilterAgentTest,
FailedInitialLoad_FilterInjectedOnInitialDocumentCreation) { … }
TEST_F(SubresourceFilterAgentTest,
FailedInitialMainFrameLoad_FilterInjectedOnInitialDocumentCreation) { … }
TEST_F(SubresourceFilterAgentTest,
DryRun_IsAssociatedWithAdFrameforDocumentOrDedicatedWorker) { … }
TEST_F(SubresourceFilterAgentTest, DryRun_AdFrameIsUntaggedByBrowser) { … }
TEST_F(SubresourceFilterAgentTest, DryRun_SendsFrameIsAd) { … }
TEST_F(SubresourceFilterAgentTest,
DryRun_SendFrameIsAdNotSentFromProvisionalFrame) { … }
TEST_F(SubresourceFilterAgentTest, DryRun_SendFrameIsAdNotSentFromNonAdFrame) { … }
TEST_F(SubresourceFilterAgentTest, DryRun_SendFrameIsAdNotSentFromRootFrame) { … }
TEST_F(SubresourceFilterAgentTest,
DryRun_SendFrameIsAdNotSentFromNonAdSubFrame) { … }
TEST_F(SubresourceFilterAgentTest, DryRun_SendsFrameWasCreatedByAdScript) { … }
TEST_F(SubresourceFilterAgentTest,
DryRun_SendFrameWasCreatedByAdScriptNotSentFromProvisionalFrame) { … }
TEST_F(
SubresourceFilterAgentTest,
DryRun_SendFrameWasCreatedByAdScriptNotSentFromFrameNotCreatedByAdScript) { … }
}