chromium/components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// The SubresourceFilterAgent with its dependencies on Blink mocked out.
//
// This approach is somewhat rudimentary, but appears to be the best compromise
// considering the alternatives:
//  -- Passing in a TestRenderFrame would itself require bringing up a
//     significant number of supporting classes.
//  -- Using a RenderViewTest would not allow having any non-filtered resource
//     loads due to not having a child thread and ResourceDispatcher.
// The real implementations of the mocked-out methods are exercised in:
//   chrome/browser/subresource_filter/subresource_filter_browsertest.cc.
class SubresourceFilterAgentUnderTest : public SubresourceFilterAgent {};

constexpr const char kTestFirstURL[] =;
constexpr const char kTestSecondURL[] =;
constexpr const char kTestFirstURLPathSuffix[] =;
constexpr const char kTestSecondURLPathSuffix[] =;
constexpr const char kTestBothURLsPathSuffix[] =;

// Histogram names.
constexpr const char kDocumentLoadRulesetIsAvailable[] =;

constexpr const char kMainFrameLoadRulesetIsAvailableAnyActivationLevel[] =;

}  // namespace

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) {}

// Never inject a filter for root frame about:blank loads, even though we do for
// child frame loads. Those are tested via browser tests.
// TODO(csharrison): Refactor these unit tests so it is easier to test with real
// backing RenderFrames.
TEST_F(SubresourceFilterAgentTest, EmptyDocumentLoad_NoFilterIsInjected) {}

TEST_F(SubresourceFilterAgentTest, Enabled_FilteringIsInEffectForOneLoad) {}

TEST_F(SubresourceFilterAgentTest, Enabled_HistogramSamplesOverTwoLoads) {}

TEST_F(SubresourceFilterAgentTest, Enabled_NewRulesetIsPickedUpAtNextLoad) {}

// Make sure that the activation decision does not outlive a failed provisional
// load (and affect the second next load).
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) {}

}  // namespace subresource_filter